Update sm4.c

Prevent sm4_cbc_decrypt_blocks in == out
This commit is contained in:
Zhi Guan
2026-06-13 20:12:33 +08:00
parent 54d9cba0ec
commit 8fded4abc7
3 changed files with 5 additions and 3 deletions

View File

@@ -191,14 +191,16 @@ void sm4_cbc_decrypt_blocks(const SM4_KEY *key, uint8_t iv[16],
const uint8_t *in, size_t nblocks, uint8_t *out)
{
const uint8_t *piv = iv;
uint8_t next_iv[16];
while (nblocks--) {
size_t i;
memcpy(next_iv, in, 16);
sm4_encrypt(key, in, out);
for (i = 0; i < 16; i++) {
out[i] ^= piv[i];
}
piv = in;
piv = next_iv;
in += 16;
out += 16;
}