Skip to content

Commit 7aa2d93

Browse files
committed
Fix TI AES-CTR partial carry-over block losing output and state (F-3078)
1 parent 7dd83b7 commit 7aa2d93

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

wolfcrypt/src/port/ti/ti-aes.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,17 @@ int wc_AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
251251
aes->left = 0;
252252
XMEMSET(tmp, 0x0, WC_AES_BLOCK_SIZE);
253253
}
254+
else {
255+
/* buffered bytes do not fill a block: encrypt the partial block
256+
* without advancing the counter, emit the new bytes, and keep
257+
* the remaining buffered bytes for the next call */
258+
ret = AesProcess(aes, (byte*)out_block, (byte const *)tmp, WC_AES_BLOCK_SIZE,
259+
AES_CFG_DIR_ENCRYPT, AES_CFG_MODE_CTR_NOCTR);
260+
if (ret != 0)
261+
return ret;
262+
XMEMCPY(out, out_block+aes->left, odd);
263+
aes->left += odd;
264+
}
254265
in += odd;
255266
out+= odd;
256267
sz -= odd;

0 commit comments

Comments
 (0)