Fixes for AES in Octeon and TI - #11148
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes correctness and safety issues in hardware-accelerated AES-GCM/CCM paths for Cavium Octeon and TI, aligning behavior with wolfSSL’s software expectations (fresh GHASH state, tag verification vs overwrite, correct handling of truncated tags, and correct buffer alignment/size handling for TI ROM APIs).
Changes:
- Octeon AES-GCM: initialize GHASH state before hashing non-12-byte IVs; use
aes->gcm.H; compute tags into a private buffer and verify tags on decrypt (zeroing plaintext on failure). - Octeon AES-GCM: thread
authTagSzthrough callback paths and only copytagSzbytes to the caller (fixing truncated-tag overflow). - TI AES auth modes: separate pointer-alignment checks from length (block-multiple) checks and bounce
in/out/authInindependently when needed.
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 | Fixes TI ROM authenticated AES buffer handling by correctly distinguishing alignment vs length constraints and bouncing buffers safely. |
| wolfcrypt/src/port/cavium/cavium_octeon_sync.c | Fixes Octeon AES-GCM GHASH initialization ordering and correct tag handling (no overwrite on decrypt, supports truncated tags safely). |
Suppressed comments (1)
wolfcrypt/src/port/cavium/cavium_octeon_sync.c:782
- Tag length validation here accepts any 1..16 bytes, but wolfSSL only permits specific AES-GCM tag sizes depending on WOLFSSL_MIN_AUTH_TAG_SZ (via wc_local_AesGcmCheckTagSz). This decrypt path should reject unsupported sizes consistently with the software implementation.
if (aes == NULL || tag == NULL || tagSz == 0 ||
tagSz > WC_AES_BLOCK_SIZE) {
ret = BAD_FUNC_ARG;
}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
dgarske
force-pushed
the
fenrir_aes_port_fixes
branch
from
August 12, 2026 16:46
3c212fe to
927779f
Compare
JacobBarthelmeh
approved these changes
Aug 13, 2026
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11148
Scan targets checked: wolfcrypt-port-bugs
No new issues found in the changed files. ✅
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.
F-8251 - Octeon non-12-byte GCM IV is hashed before GHASH initialization
Octeon_AesGcm_SetIV()fed a non-12-byte IV to the GFM unit beforeOcteon_GHASH_Init()loadedaes->gcm.Hand cleared the result registers, so J0 was derived against leftover hardware state from the previous operation. Now initializes GHASH before hashing the IV; the existing init after the IV hash still resets state for the AAD/ciphertext passes.Also folded in here:
aes->H->aes->gcm.H. That member moved into the nestedGcmsub-struct in e2424e6 (SM2/SM3/SM4) and the port has not compiled since.F-8237 - Octeon AES-GCM decryption overwrites rather than verifies the authentication tag
Octeon_AesGcm_Finalize()stored the computed tag straight through the caller'stagpointer, andOcteon_AesGcm_Decrypt()used that same path, somyCryptoDevCb()handed it the peer's tag and it got clobbered instead of checked. Any forged tag was accepted oncewc_CryptoCb_InitOcteon()was registered.Both directions now finalize into a private
ALIGN16block. Decrypt comparesauthTagSzbytes withConstantCompare(), returnsAES_GCM_AUTH_Eon mismatch,ForceZero()s the plaintext output, and never writes through the caller's tag pointer. Encrypt copies onlyauthTagSzbytes out, which also fixes an overflow: it previously wrote a full 16 bytes even thoughwc_local_AesGcmCheckTagSz()permits truncated tags.authTagSzis now threaded through both callback paths.F-8253 - TI authenticated AES checks lengths instead of pointer alignment
AesAuthEncrypt()/AesAuthDecrypt()appliedIS_ALIGN16()- an address test - toinSzandauthInSz. When a length happened to be a multiple of 16, the caller'sin,outandauthInpointers went toROM_AESDataProcessAuth()asunsigned int*at whatever byte alignment they actually had;outwas never checked or bounced on its own at all.Alignment and length are now separate concerns:
IS_ALIGN16()tests addresses (viawc_ptr_t, so it no longer truncates), and a newIS_MULT16()tests lengths.in,outandauthIneach get an independent bounce buffer when either their address is unaligned or the length is not a whole number of blocks. Theoutwrite-back is guarded so it is not a self-copy whenoutwas not bounced.