Clear the leftover byte count in Aes struct when setting IV.

Setting the key already does this. The same needs to be done when setting the
IV.
This commit is contained in:
Hayden Roche
2022-06-25 15:26:34 +04:00
parent 55414290df
commit 10dfd8d129
2 changed files with 14 additions and 4 deletions

View File

@@ -24082,10 +24082,13 @@ void wolfSSL_AES_cfb128_encrypt(const unsigned char *in, unsigned char* out,
}
aes = (Aes*)key;
if (wc_AesSetIV(aes, (const byte*)iv) != 0) {
WOLFSSL_MSG("Error with setting iv");
return;
}
/*
* We copy the IV directly into reg here because using wc_AesSetIV will
* clear the leftover bytes field "left", and this function relies on the
* leftover bytes being preserved between calls.
*/
XMEMCPY(aes->reg, iv, AES_BLOCK_SIZE);
if (enc == AES_ENCRYPT) {
if (wc_AesCfbEncrypt(aes, out, in, (word32)len) != 0) {

View File

@@ -3212,6 +3212,13 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
XMEMCPY(aes->reg, iv, AES_BLOCK_SIZE);
else
XMEMSET(aes->reg, 0, AES_BLOCK_SIZE);
#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \
defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS)
/* Clear any unused bytes from last cipher op. */
aes->left = 0;
#endif
return 0;
}