Skip to content

Commit dc57adc

Browse files
committed
Fix to increment IV for AES CTR with TSIP (allow encrypt to be called multiple times without having to manually reset the IV).
1 parent c7ff3b9 commit dc57adc

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

wolfcrypt/src/port/Renesas/renesas_tsip_aes.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,18 @@ int wc_tsip_AesCtr(struct Aes* aes, byte* out, const byte* in, word32 sz)
654654
#endif
655655
}
656656

657-
if (ret != TSIP_SUCCESS) {
657+
if (ret == TSIP_SUCCESS) {
658+
/* increment IV counter */
659+
int i, blocks = (int)(sz / WC_AES_BLOCK_SIZE);
660+
while (blocks--) {
661+
/* in network byte order so start at end and work back */
662+
for (i = WC_AES_BLOCK_SIZE - 1; i >= 0; i--) {
663+
if (++iv[i]) /* we're done unless we overflow */
664+
break;
665+
}
666+
}
667+
}
668+
else {
658669
WOLFSSL_ERROR(ret);
659670
WOLFSSL_MSG("TSIP AES CTR failed");
660671
ret = -1;

0 commit comments

Comments
 (0)