Skip to content

Fix TI port AES-CTR streaming and hashCopy correctness bugs - #10986

Merged
Frauschi merged 2 commits into
wolfSSL:masterfrom
dgarske:ti_port_fenrir_fixes
Aug 1, 2026
Merged

Fix TI port AES-CTR streaming and hashCopy correctness bugs#10986
Frauschi merged 2 commits into
wolfSSL:masterfrom
dgarske:ti_port_fenrir_fixes

Conversation

@dgarske

@dgarske dgarske commented Jul 23, 2026

Copy link
Copy Markdown
Member

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_AesCtrEncrypt drops 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 advanced aes->left. The caller saw uninitialized/stale output, and the next call overwrote the still-buffered bytes, silently losing plaintext. Fixed by adding the else path that mirrors the existing tail-handling block: encrypt the partial block with AES_CFG_MODE_CTR_NOCTR (no counter advance), emit the new bytes, and do aes->left += odd.

F-2646 - hashCopy discards accumulated message (wolfcrypt/src/port/ti/ti-hash.c)

hashCopy zeroed msg/used/len and copied only the never-populated hash field, so a copied context finalized to the hash of an empty message instead of the source data. Affects wc_Md5Copy, wc_ShaCopy, wc_Sha224Copy, and wc_Sha256Copy. Fixed by allocating a fresh dst->msg and copying src->len bytes (independent allocation preserves the original anti-double-free intent), matching the reference wc_Sha256Copy in devcrypto_hash.c.

@dgarske dgarske self-assigned this Jul 23, 2026
Copilot AI review requested due to automatic review settings July 23, 2026 20:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_AesCtrEncrypt streaming behavior when a follow-up chunk still doesn’t complete the buffered block (encrypt/emit bytes and advance aes->left without counter advance).
  • Fix TI hashCopy to 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 thread wolfcrypt/src/port/ti/ti-hash.c Outdated
@dgarske

dgarske commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

Jenkins retest this please. valgrind with openssl-all

@dgarske dgarske assigned wolfSSL-Bot and unassigned dgarske Jul 27, 2026

@Frauschi Frauschi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐺 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 failswolfcrypt/src/port/ti/ti-hash.c:132-138
  • [Medium] hashCopy overwrites a pre-existing dst->msg without freeing itwolfcrypt/src/port/ti/ti-hash.c:130
  • [Low] wc_AesCtrEncrypt(sz == 0) with buffered bytes now performs a pointless HW AES blockwolfcrypt/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

Comment thread wolfcrypt/src/port/ti/ti-hash.c Outdated
Comment thread wolfcrypt/src/port/ti/ti-hash.c Outdated
Comment thread wolfcrypt/src/port/ti/ti-aes.c Outdated
@Frauschi Frauschi assigned dgarske and unassigned wolfSSL-Bot Jul 31, 2026
@dgarske
dgarske force-pushed the ti_port_fenrir_fixes branch from 7aa2d93 to 82297bb Compare July 31, 2026 17:05
@dgarske
dgarske requested a review from Frauschi July 31, 2026 17:19
@dgarske dgarske assigned Frauschi and wolfSSL-Bot and unassigned dgarske Jul 31, 2026
@Frauschi
Frauschi merged commit 7a8aae3 into wolfSSL:master Aug 1, 2026
354 of 355 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants