Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions wolfcrypt/src/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -7358,9 +7358,9 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
xorbufout(out, in, ks, WC_AES_BLOCK_SIZE);
}
else {
/* The XTRANSFORM_AESCTRBLOCK macro discards this return; zero
* the block so a failed HW ECB does not leave stale/prior
* plaintext in the output. */
/* The CTR loop breaks on this non-zero return; zero the block
* so a failed HW ECB does not leave stale/prior plaintext in
* the output. */
ForceZero(out, WC_AES_BLOCK_SIZE);
}
ForceZero(ks, sizeof(ks));
Expand Down
18 changes: 16 additions & 2 deletions wolfcrypt/src/port/st/stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -3729,6 +3729,21 @@ static int Stm32Dhuk_Cipher(struct wc_CryptoInfo* info)
if (ret != 0) {
return ret;
}
/* CBC requires a non-zero, block-multiple length. Validate before the
* pre-decrypt last-block copy below so an invalid sz cannot read past
* the input buffer (mirrors the bare backend wc_Stm32_Aes_Cbc). */
if (info->cipher.aescbc.sz == 0 ||
(info->cipher.aescbc.sz % WC_AES_BLOCK_SIZE) != 0) {
return BAD_FUNC_ARG;
}
if (!info->cipher.enc) {
/* In-place decrypt overwrites the last ciphertext block, so
* capture it for the next chaining IV before the decrypt (mirrors
* the non-DHUK bare backend wc_Stm32_Aes_Cbc). */
XMEMCPY(info->cipher.aescbc.aes->tmp,
info->cipher.aescbc.in + info->cipher.aescbc.sz
- WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE);
}
ret = Stm32Dhuk_Aes(NULL, WC_DHUK_MODE_CBC, info->cipher.enc,
info->cipher.aescbc.in, info->cipher.aescbc.sz,
info->cipher.aescbc.out,
Expand All @@ -3743,8 +3758,7 @@ static int Stm32Dhuk_Cipher(struct wc_CryptoInfo* info)
}
else {
XMEMCPY(info->cipher.aescbc.aes->reg,
info->cipher.aescbc.in + info->cipher.aescbc.sz
- WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE);
info->cipher.aescbc.aes->tmp, WC_AES_BLOCK_SIZE);
}
}
return ret;
Expand Down
Loading