mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-06-19 19:33:38 +08:00
Update sm4.c
Prevent sm4_cbc_decrypt_blocks in == out
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user