From 7dd83b76e232e66f6873ac9ddac2c87e90c54ccd Mon Sep 17 00:00:00 2001 From: David Garske Date: Thu, 23 Jul 2026 11:25:15 -0700 Subject: [PATCH 1/2] Fix TI hashCopy to copy accumulated message buffer (F-2646) --- wolfcrypt/src/port/ti/ti-hash.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/wolfcrypt/src/port/ti/ti-hash.c b/wolfcrypt/src/port/ti/ti-hash.c index f239b18f646..a0b529ef2bc 100644 --- a/wolfcrypt/src/port/ti/ti-hash.c +++ b/wolfcrypt/src/port/ti/ti-hash.c @@ -127,10 +127,19 @@ static int hashCopy(wolfssl_TI_Hash *src, wolfssl_TI_Hash *dst) { if (src == NULL || dst == NULL) return BAD_FUNC_ARG; - /* only copy hash, zero the rest of the struct to avoid double-free */ - dst->msg = NULL; - dst->used = 0; - dst->len = 0; + /* copy the accumulated message into a fresh buffer so each descriptor + * owns its own allocation and can be freed independently */ + dst->used = src->used; + dst->len = src->len; + if ((src->msg != NULL) && (src->len > 0)) { + dst->msg = (byte*)XMALLOC(src->len, NULL, DYNAMIC_TYPE_TMP_BUFFER); + if (dst->msg == NULL) + return MEMORY_E; + XMEMCPY(dst->msg, src->msg, src->len); + } + else { + dst->msg = NULL; + } XMEMCPY(dst->hash, src->hash, sizeof(dst->hash)); return 0; } From 7aa2d93614d1edae475d2f721b4775cc554aaf60 Mon Sep 17 00:00:00 2001 From: David Garske Date: Thu, 23 Jul 2026 11:25:34 -0700 Subject: [PATCH 2/2] Fix TI AES-CTR partial carry-over block losing output and state (F-3078) --- wolfcrypt/src/port/ti/ti-aes.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/wolfcrypt/src/port/ti/ti-aes.c b/wolfcrypt/src/port/ti/ti-aes.c index 4d77dcfe16e..1a4ec640b5d 100644 --- a/wolfcrypt/src/port/ti/ti-aes.c +++ b/wolfcrypt/src/port/ti/ti-aes.c @@ -251,6 +251,17 @@ int wc_AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) aes->left = 0; XMEMSET(tmp, 0x0, WC_AES_BLOCK_SIZE); } + else { + /* buffered bytes do not fill a block: encrypt the partial block + * without advancing the counter, emit the new bytes, and keep + * the remaining buffered bytes for the next call */ + ret = AesProcess(aes, (byte*)out_block, (byte const *)tmp, WC_AES_BLOCK_SIZE, + AES_CFG_DIR_ENCRYPT, AES_CFG_MODE_CTR_NOCTR); + if (ret != 0) + return ret; + XMEMCPY(out, out_block+aes->left, odd); + aes->left += odd; + } in += odd; out+= odd; sz -= odd;