Skip to content

Commit b85e500

Browse files
committed
Fix sz==0 buffer underflow in devcrypto AES-CBC
1 parent 8169780 commit b85e500

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

wolfcrypt/src/port/devcrypto/devcrypto_aes.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
4444
return BAD_FUNC_ARG;
4545
}
4646

47-
/* encrypt only up to AES block size of date */
47+
/* encrypt only up to AES block size of data */
4848
sz = sz - (sz % WC_AES_BLOCK_SIZE);
49+
if (sz == 0) {
50+
return 0;
51+
}
4952
if (aes->ctx.cfd == -1) {
5053
ret = wc_DevCryptoCreate(&aes->ctx, CRYPTO_AES_CBC,
5154
(byte*)aes->devKey, aes->keylen);
@@ -74,6 +77,9 @@ int wc_AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz)
7477
if (aes == NULL || out == NULL || in == NULL || sz % WC_AES_BLOCK_SIZE != 0) {
7578
return BAD_FUNC_ARG;
7679
}
80+
if (sz == 0) {
81+
return 0;
82+
}
7783

7884
XMEMCPY(aes->tmp, in + sz - WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE);
7985
if (aes->ctx.cfd == -1) {

0 commit comments

Comments
 (0)