Mlkem cryptocb sha3 hashtype not reset after final call#10211
Merged
dgarske merged 3 commits intowolfSSL:masterfrom Apr 14, 2026
Merged
Mlkem cryptocb sha3 hashtype not reset after final call#10211dgarske merged 3 commits intowolfSSL:masterfrom
dgarske merged 3 commits intowolfSSL:masterfrom
Conversation
… to surface mlkem SHA3 hashType latch bug
… cross sha3 reuse.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #10211
Scan targets checked: wolfcrypt-api_misuse, wolfcrypt-bugs, wolfcrypt-compliance, wolfcrypt-concurrency, wolfcrypt-consttime, wolfcrypt-defaults, wolfcrypt-mutation, wolfcrypt-portability, wolfcrypt-proptest, wolfcrypt-src, wolfcrypt-zeroize
No new issues found in the changed files. ✅
dgarske
approved these changes
Apr 14, 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.
Issue
wc_Sha3Updateandwc_Sha3Finalcachesha3->hashTypeon first use and pass it towc_CryptoCb_Sha3Hashfor dispatch. The state reset at the end ofwc_Sha3Final(viaInitSha3) only cleared the sponge bytes, leavinghashTypelatched. Any caller that legitimately reuses a singlewc_Sha3across SHA3 variants (mlkem reuseskey->hashfor SHA3-512MLKEM_HASH_Gin MakeKey, then SHA3-256MLKEM_HASH_Hin EncodePublicKey/DecodePrivateKey) would have the second op dispatched through the crypto callback as the first op's algorithm. That produces a wrongkey->h, failswc_MlKemKey_DecodePrivateKeywithMLKEM_PUB_HASH_E, and in the SHA3-512 over a 32 byte buffer case overwrites adjacent fields.The software path was unaffected because it keys off the
pblock count parameter every call. The callback path only stayed hidden because thedevId != INVALID_DEVIDguard usually kept it cold.-DWOLF_CRYPTO_CB_FINDremoves that guard and makes it reliably trigger.Fix
Clear
sha3->hashTypeinsideInitSha3andwc_Sha3Finalalready callsInitSha3for its end of op reset, so the the sha3 struct will reinit and subsequent Update/Final calls can determine the correct type fromp.Also fix -Wparentheses-equality error when WOLF_CRYPTO_CB_FIND is defined with clang
Test
New
--enable-cryptocb --enable-keygen -DWOLF_CRYPTO_CB_FINDentry in.github/workflows/os-check.ymlreproduces the failure on master and passes with this fix.