Repository navigation
sha2, sha3: refuse mixed variants, rates and SHAKE call order in FIPS v7 - #12213
kaleb-himes wants to merge 1 commit into
Conversation
|
There was a problem hiding this comment.
🔵 Needs a closer look
Changes to FIPS v7 hash-state enforcement and context layouts require maintainer validation against the licensed module and approved operating-environment matrix, neither of which is available in this checkout.
No open issues 🎉
2 resolved since last review
Review effort: Balanced
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12213
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): tests/api/test_sha256.h, tests/api/test_sha3.h, tests/api/test_sha512.h
Coverage: 10 of 12 in-scope changed file(s) opened by the reviewer; not opened: tests/api/test_sha256.c, wolfssl/wolfcrypt/settings.h
Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
Review tier: Max
| return BAD_FUNC_ARG; | ||
| } | ||
| #ifdef WC_HASH_CHECK_VARIANT | ||
| if (sha256->digestSz != WC_SHA256_DIGEST_SIZE) { |
There was a problem hiding this comment.
SHA-256 Final always fails on ESP32-HW and Freescale MMCAU builds: their init paths never set digestSz · Logic errors
Only the generic InitSha256() (sha256.c:309) sets digestSz. The ESP32-HW InitSha256() (sha256.c:1253) and MMCAU wc_InitSha256_ex() (sha256.c:988) don't, so with WC_HASH_CHECK_VARIANT every wc_Sha256Final/wc_Sha256FinalRaw on those builds returns BAD_STATE_E.
Suggested fix: Set digestSz = WC_SHA256_DIGEST_SIZE under WC_HASH_CHECK_VARIANT in the ESP32 InitSha256() and in the Freescale MMCAU wc_InitSha256_ex().
Basis: wolfCrypt invariant added by this PR: wc_Sha256Final and wc_Sha256FinalRaw (sha256.c:2531, 2569) accept a state only if its init path recorded digestSz.
Related known findings (similar but distinct; listed for context, not part of this finding)
- F-11173 (open): Only F-11173 is materially related, and it is not the same defect. (1) Location: the candidate is wc_Sha256Final's digestSz check (:2569), rooted in the ESP32 InitSha256 and MMCAU wc_InitSha256_ex init paths. F-11173 is the Freescale wc_InitSha256_ex (:824-877), so the two share only the Freescale init function. (2) Operation: the candidate has Final/FinalRaw reject a state whose digestSz was never recorded, returning BAD_STATE_E. F-11173 has the init dereference a NULL context. (3) Root cause: the

Description
Adds WC_HASH_CHECK_VARIANT. When it is set, a SHA-2 or SHA-3/SHAKE state
records the variant that initialized it, and later calls that do not match
that variant return BAD_STATE_E. settings.h turns it on for FIPS v7 builds
only. Other builds do not change unless they define it themselves.
Changes
that another variant initialized, for example SHA-256 Final on a SHA-224
state.
Sha512_Family_Final, Sha512FinalRaw, wc_Sha384Final and wc_Sha384FinalRaw.
6.2) and one domain (0x06 for SHA-3, 0x1f for SHAKE). This matters because
SHA3-256 and SHAKE256 share a rate. Update and Absorb are refused after
Absorb has padded the input (FIPS 202 Algorithm 8). SqueezeBlocks is
refused unless Absorb ran first at the same rate.
i was cleared even when the call failed.
USE_INTEL_SPEEDUP / MLDSA_SHAKE_DIRECT path, so it now marks that state
absorbed. Later refill squeezes still work.
Testing
Tests
and test_wc_Sha3_MixedRate. They cover mixed variants, mixed rates, mixed
SHA-3/SHAKE domains, Update after Absorb, and Squeeze before Absorb.
SHAKE256 block for s2[4] (FIPS 204 Alg 31, 33). This exercises the refill
path above. The expected bytes are the BitPack encoding (Alg 17, 24).
Testing
unit.test pass.
new tests fail at tests/api/test_sha256.c:462 and tests/api/test_sha3.c
lines 934, 1381, 1416 and 2665.
Checklist