Skip to content

Commit

Permalink
Update sm4_cbc.c
Browse files Browse the repository at this point in the history
  • Loading branch information
guanzhi committed Apr 28, 2024
1 parent 0609300 commit 660b4cf
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/sm4_cbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ void sm4_cbc_encrypt(const SM4_KEY *key, const uint8_t iv[16],
void sm4_cbc_decrypt(const SM4_KEY *key, const uint8_t iv[16],
const uint8_t *in, size_t nblocks, uint8_t *out)
{
while (nblocks >= 8) {
uint8_t buf[16 * 8];

sm4_encrypt_blocks(key, in, 8, buf);

gmssl_memxor(out, buf, iv, 16);
gmssl_memxor(out + 16, buf + 16, in, 16 * (8 - 1));

iv = in + 16 * (8 - 1);
in += 16 * 8;
out += 16 * 8;
nblocks -= 8;
}

while (nblocks--) {
sm4_encrypt(key, in, out);
memxor(out, iv, 16);
Expand Down

0 comments on commit 660b4cf

Please sign in to comment.