Fix TI port AES-CTR streaming and hashCopy correctness bugs - #10986
Merged
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.
Member
Author
|
Jenkins retest this please. valgrind with openssl-all |
Frauschi
reviewed
Jul 31, 2026
Frauschi
left a comment
Contributor
There was a problem hiding this comment.
🐺 Skoll Code Review
Overall recommendation: APPROVE
Findings: 9 total — 3 posted, 6 skipped
Posted findings
- [Medium] hashCopy leaves dst in an inconsistent state when XMALLOC fails —
wolfcrypt/src/port/ti/ti-hash.c:132-138 - [Medium] hashCopy overwrites a pre-existing dst->msg without freeing it —
wolfcrypt/src/port/ti/ti-hash.c:130 - [Low] wc_AesCtrEncrypt(sz == 0) with buffered bytes now performs a pointless HW AES block —
wolfcrypt/src/port/ti/ti-aes.c:254
Skipped findings
- [Medium] TI port fixes are not exercised by CI; confirm on-target validation
- [Low] Copying src->len instead of src->used couples the copy to the allocator's capacity
- [Low] New CTR carry-over branch duplicates the existing tail-fragment block
- [Low] hashCopy leaves dst in an inconsistent state when the new allocation fails
- [Info] Added lines exceed the 80-column limit
- [Info] New AES-CTR carry-over branch runs a hardware AES pass for a zero-length call
Review generated by Skoll via Claude/Codex
dgarske
force-pushed
the
ti_port_fenrir_fixes
branch
from
July 31, 2026 17:05
7aa2d93 to
82297bb
Compare
Frauschi
approved these changes
Aug 1, 2026
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.