Repository navigation
Pq fs 2026 part4 lab prep sha512 fixes - #11983
kaleb-himes wants to merge 7 commits into
Conversation
|
0115bd2 to
e83e2f0
Compare
|
@claude review please |
|
@claude review again please. |
dd01fab to
c527857
Compare
|
Rebased on master to resolve CI issues that had landed in master. |
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11983
Scan targets checked: none
Unchanged since last review (not re-run): wolfcrypt-src, wolfcrypt-bugs, wolfssl-bugs
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Lite
| ByteReverseWords64(sha512->digest, sha512->digest, | ||
| WC_SHA512_DIGEST_SIZE); | ||
| XMEMCPY(hash, sha512->digest, digestSz); | ||
| ByteReverseWords64(sha512->digest, sha512->digest, |
There was a problem hiding this comment.
Would rather copy and reverse rather than have the digest in a reversed state.
There was a problem hiding this comment.
Absolutely! Yes this is the first solution I reached for (a temporary buffer to hold the temporary state so I didn't have to touch the live state but other feedback led me to see if it could be solved without using additional stack or heap. The stack implementation requires an extra ForceZero but I benchmarked both implementations and both were less than a fraction of a nanosecond different. I'll gladly go with the initial implementation. Thanks @SparkiDev. (Will include AVX512 test results in the PR summary once I finish fully vetting the stack approach too.)
c527857 to
5b8aa51
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11983
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-bugs
Coverage: 2 of 2 in-scope changed file(s) opened by the reviewer
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Max

Description
sha512: SHA-512/224 FinalRaw and Transform no longer modify state or input
Sha512FinalRaw: for SHA-512/224 (28-byte digest, not a multiple of 8) the little-endian path byte-reversed sha512->digest in place before copying it out and never reversed it back, so wc_Sha512_224FinalRaw() corrupted the running hash. Any Update after FinalRaw then produced the wrong digest. It now reverses into a local copy, copies digestSz bytes out and zeroes the copy, so sha512->digest is never modified. 5172ff7 (v5.8.0) removed an earlier local copy, citing a gcc SEGV on AVX-512 -march=native builds. That SEGV occurs only under AddressSanitizer with detect_stack_use_after_return=1 (a gcc code-generation issue, GCC Bugzilla 110027), never in a non-sanitizer build. ee2e634 later fixed the multiple-of-8 digest sizes but left SHA-512/224. The v5.2.1 and v6.0.0 FIPS modules predate it and are not affected.
wc_Sha512Transform: the input block is const, but on little-endian builds
without the Intel AVX path the function byte-reversed it in place. Each path
now leaves the caller's block and the hash state alone:
does, then restores sha->buffer.
as Sha512Update's bulk path does. On ppc64le this also fixes a wrong
digest: the block was reversed before PPC64 asm that already loads it
with ldbrx, so it was reversed twice. On big-endian the old code reversed
the block once, so Transform disagreed with Update.
(WOLFSSL_RISCV_VECTOR_CRYPTO_ASM): copy into the local aligned buffer
first, because the ARMv5 base asm loads words with LDR and the RISC-V
vector asm loads with vl8re64.v, which RVV 1.0 section 7.9 allows to trap
on a misaligned address.
C CPU step (Transform_Sha512_C) writes it. Before, Transform overwrote
input pending from an earlier Update.
No path reads or writes the caller's block through a word64 pointer.
Testing
Transform. Skipped for FIPS modules before v7.0.0: the frozen v5 and v6
sha512.c still reverse the caller's block when the Intel AVX path is not
used (seen on ARMv8 with --enable-fips=v5).
checks the result is SHA-512/224("abc") from the FIPS 180-4 examples.
Verified (--enable-opensslextra, master sha512.c as the control):
make check passes.
this passes.
Update("ab"), Transform, Final now matches the x86 and NEON builds;
master gives a different digest.
and Update of the same block now give the same state with both the NEON
asm and the C CPU step; before they differed.
Transform changes pass.
and base (--enable-riscv-asm): SHA-512 tests pass, and an aligned and a
misaligned Transform of the same block give the same digest.
SHA-512/224 and SHA-512/256 Transform tests got the wrong digest; this
passes.
gate and fails at test_sha512.c:278 without it.
Update("c"), Final against Transform, Update("abc"), Final, so Transform
must keep input pending from an earlier Update.
Fixes Fenrir:
place on little-endian builds.
caller's data pointer.
NOTE: Not changed here:
little-endian byte swap, so SHA-256 and SHA-512 KATs fail. The asm is
generated from wolfSSL/scripts, so the fix is in a separate pair: branch
PQ-FS-2026-Part4-LabPrep-ppc64-sha2-crypto-le (scripts a879f1dd, wolfssl
fb82943).
master; that is not addressed here.
Related PR's:
#11999
https://github.com/wolfSSL/scripts/pull/706
Checklist