Fix TI port AES-CTR streaming and hashCopy correctness bugs#10986
Open
dgarske wants to merge 2 commits into
Open
Fix TI port AES-CTR streaming and hashCopy correctness bugs#10986dgarske wants to merge 2 commits into
dgarske wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes two correctness bugs in the TI (TM4C129/TivaWare) hardware-accelerated crypto port that could silently produce incorrect output: AES-CTR streaming with partial buffered blocks, and hash context copying losing the accumulated message.
Changes:
- Fix
wc_AesCtrEncryptstreaming behavior when a follow-up chunk still doesn’t complete the buffered block (encrypt/emit bytes and advanceaes->leftwithout counter advance). - Fix TI
hashCopyto deep-copy the accumulated message buffer so copied contexts finalize correctly.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
wolfcrypt/src/port/ti/ti-aes.c |
Adds missing handling for the “still not a full block” carry-over path in CTR streaming. |
wolfcrypt/src/port/ti/ti-hash.c |
Updates TI hash context copying to include buffered message data via independent allocation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+130
to
+142
| /* 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; | ||
| } |
Member
Author
|
Jenkins retest this please. valgrind with openssl-all |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes two bugs in the TI (TivaWare TM4C129 AES/SHA-MD5 hardware) port. Both silently produce wrong output rather than failing, and both trace to PR #7018.
F-3078 -
wc_AesCtrEncryptdrops partial streaming input (wolfcrypt/src/port/ti/ti-aes.c)When AES-CTR is called in streaming fashion and a follow-up chunk does not complete the buffered block (
aes->left + sz < WC_AES_BLOCK_SIZE), the leading carry-over branch buffered the new plaintext but never encrypted it, never wrote the caller's output, and never advancedaes->left. The caller saw uninitialized/stale output, and the next call overwrote the still-buffered bytes, silently losing plaintext. Fixed by adding theelsepath that mirrors the existing tail-handling block: encrypt the partial block withAES_CFG_MODE_CTR_NOCTR(no counter advance), emit the new bytes, and doaes->left += odd.F-2646 -
hashCopydiscards accumulated message (wolfcrypt/src/port/ti/ti-hash.c)hashCopyzeroedmsg/used/lenand copied only the never-populatedhashfield, so a copied context finalized to the hash of an empty message instead of the source data. Affectswc_Md5Copy,wc_ShaCopy,wc_Sha224Copy, andwc_Sha256Copy. Fixed by allocating a freshdst->msgand copyingsrc->lenbytes (independent allocation preserves the original anti-double-free intent), matching the referencewc_Sha256Copyindevcrypto_hash.c.