mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-07 00:46:17 +08:00
Let sm4_cbc_encrypt_blocks update iv
If in == out, then after encryptions the input (i.e. iv) is changed
This commit is contained in:
@@ -21,15 +21,19 @@
|
||||
static int test_sm4_cbc(void)
|
||||
{
|
||||
SM4_KEY sm4_key;
|
||||
uint8_t key[16] = {0};
|
||||
uint8_t iv[16] = {0};
|
||||
const uint8_t key[16] = {0};
|
||||
const uint8_t civ[16] = {0};
|
||||
uint8_t iv[16];
|
||||
uint8_t buf1[32] = {0};
|
||||
uint8_t buf2[32] = {0};
|
||||
uint8_t buf3[32] = {0};
|
||||
|
||||
sm4_set_encrypt_key(&sm4_key, key);
|
||||
memcpy(iv, civ, 16);
|
||||
sm4_cbc_encrypt_blocks(&sm4_key, iv, buf1, 2, buf2);
|
||||
|
||||
sm4_set_decrypt_key(&sm4_key, key);
|
||||
memcpy(iv, civ, 16);
|
||||
sm4_cbc_decrypt_blocks(&sm4_key, iv, buf2, 2, buf3);
|
||||
|
||||
if (memcmp(buf1, buf3, sizeof(buf3)) != 0) {
|
||||
@@ -107,6 +111,7 @@ static int test_sm4_cbc_test_vectors(void)
|
||||
}
|
||||
|
||||
sm4_set_encrypt_key(&sm4_key, key);
|
||||
hex_to_bytes(tests[i].iv, strlen(tests[i].iv), iv, &iv_len);
|
||||
sm4_cbc_encrypt_blocks(&sm4_key, iv, plaintext, plaintext_len/16, encrypted);
|
||||
|
||||
if (memcmp(encrypted, ciphertext, ciphertext_len) != 0) {
|
||||
|
||||
Reference in New Issue
Block a user