How to add new algorithm to opencrypto?

Hi,
I tried to replace opencrypto/xform_aes_cbc.c with xfrom_sm4_cbc to use the sm4_cbc algorithm in ipsec. It can encrypt successfully but will report an error when decrypting. Why is this?

1740075014716.png
 
without seeing your changes, it's hard to tell, but per the errors, it looks like you're not padding the result correctly for the cipher mode. this RFC has some test vectors, have you ensured that your code passes those?
 
without seeing your changes, it's hard to tell, but per the errors, it looks like you're not padding the result correctly for the cipher mode. this RFC has some test vectors, have you ensured that your code passes those?

I made the modifications directly in the `xform_aes_cbc.c` file. Is there any difference in padding between sm4-cbc and aes-cbc?
 
Ah, yeah, i would not expect that change to work well. you should probably make a new xform and wire it through, but we don't have any specific advice on doing so.
 
Back
Top