Fix to increment IV for AES CTR with TSIP (allow encrypt to be called multiple times without having to manually reset the IV).

This commit is contained in:
David Garske
2025-06-12 11:33:50 -07:00
parent c7ff3b99b7
commit dc57adcfed

View File

@@ -654,7 +654,18 @@ int wc_tsip_AesCtr(struct Aes* aes, byte* out, const byte* in, word32 sz)
#endif #endif
} }
if (ret != TSIP_SUCCESS) { if (ret == TSIP_SUCCESS) {
/* increment IV counter */
int i, blocks = (int)(sz / WC_AES_BLOCK_SIZE);
while (blocks--) {
/* in network byte order so start at end and work back */
for (i = WC_AES_BLOCK_SIZE - 1; i >= 0; i--) {
if (++iv[i]) /* we're done unless we overflow */
break;
}
}
}
else {
WOLFSSL_ERROR(ret); WOLFSSL_ERROR(ret);
WOLFSSL_MSG("TSIP AES CTR failed"); WOLFSSL_MSG("TSIP AES CTR failed");
ret = -1; ret = -1;