Skip to content

Commit 609bef4

Browse files
committed
openssl: Support sm4
SM4 is formed with <name>-<mode>, different from aes, etc. which is <name>-<key_bits>-<mode>. See 'openssl list --cipher-algorithms' under new version 3.5.X e.g.
1 parent 648e0e0 commit 609bef4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/crypto_backend/crypto_openssl.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,10 @@ static int _cipher_init(EVP_CIPHER_CTX **hd_enc, EVP_CIPHER_CTX **hd_dec, const
694694
if (!strcmp(mode, "xts"))
695695
key_bits /= 2;
696696

697-
r = snprintf(cipher_name, sizeof(cipher_name), "%s-%d-%s", name, key_bits, mode);
697+
if ((!strcmp(name, "sm4")) && key_bits == 128)
698+
r = snprintf(cipher_name, sizeof(cipher_name), "%s-%s", name, mode);
699+
else
700+
r = snprintf(cipher_name, sizeof(cipher_name), "%s-%d-%s", name, key_bits, mode);
698701
if (r < 0 || (size_t)r >= sizeof(cipher_name))
699702
return -EINVAL;
700703

0 commit comments

Comments
 (0)