Repository navigation
Add a SHA-3 permutation override and route software ML-DSA and ML-KEM SHAKE to crypto callbacks - #12351
Add a SHA-3 permutation override and route software ML-DSA and ML-KEM SHAKE to crypto callbacks#12351dgarske wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Critical SHAKE callback ownership and copy-fallback flaws can produce incorrect digests, while mismatched reset guards can break supported builds.
4 open issues
What changed in this PR
Adds two hardware-integration paths for wolfCrypt SHA-3: a custom permutation hook and SHAKE callback routing for software ML-DSA and ML-KEM.
Changes:
- Introduces
WC_SHA3_USER_BLOCKwith configuration restrictions and CI coverage. - Adds SHAKE reset callbacks and stream-ownership tracking.
- Routes device-backed post-quantum hashing through SHAKE APIs, including assembly builds.
| File | Description |
|---|---|
| wolfssl/wolfcrypt/sha3.h | Adds device-stream state. |
| wolfssl/wolfcrypt/settings.h | Adds hook restrictions and callback defaults. |
| wolfssl/wolfcrypt/cryptocb.h | Adds reset operation and updates interface version. |
| wolfcrypt/test/test.c | Expands SHAKE and post-quantum callback tests. |
| wolfcrypt/src/wc_mlkem.c | Routes KDF and cleanup through device-aware APIs. |
| wolfcrypt/src/wc_mlkem_poly.c | Adds callback-aware polynomial hashing paths. |
| wolfcrypt/src/wc_mldsa.c | Adds callback-aware SHAKE paths and cleanup. |
| wolfcrypt/src/sha3.c | Implements permutation override and stream handling. |
| wolfcrypt/src/port/xilinx/versal_gen2_asu/asu_hash.c | Handles reset and declines sponge operations. |
| wolfcrypt/src/cryptocb.c | Documents updated callback options. |
| tests/swdev/swdev.c | Supports SHAKE reset in the software device. |
| tests/api/test_sha3.c | Limits the test callback to update/final. |
| doc/dox_comments/header_files/cryptocb.h | Documents SHAKE callback contracts. |
| .wolfssl_known_macro_extras | Registers new configuration macros. |
| .github/configs/os-check-linux.json | Adds permutation-hook CI coverage. |
Review effort: Balanced
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12351
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfcrypt-port-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): .github/configs/os-check-linux.json, .wolfssl_known_macro_extras, doc/dox_comments/header_files/cryptocb.h
Coverage: 11 of 12 in-scope changed file(s) opened by the reviewer; not opened: wolfcrypt/src/cryptocb.c
Findings: 3
3 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
There was a problem hiding this comment.
🔵 Needs a closer look
SHAKE ownership and reset changes require hardware-maintainer review and device-level validation because no SHAKE hardware was exercised and the modified Versal Gen2 ASU backend was not built.
No open issues 🎉
4 resolved since last review
Review effort: Balanced
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12351
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfcrypt-port-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): .github/configs/os-check-linux.json, .wolfssl_known_macro_extras, doc/dox_comments/header_files/cryptocb.h
Coverage: 2 of 4 in-scope changed file(s) opened by the reviewer; not opened: wolfssl/wolfcrypt/cryptocb.h, wolfssl/wolfcrypt/sha3.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: Lite
There was a problem hiding this comment.
🟡 Changes recommended
Clearing software ownership before Final succeeds can route retries to a device that never received the buffered input, risking incorrect results after a software finalization error.
1 open issue
4 resolved since last review
Review effort: Balanced
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12351
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfcrypt-port-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): .github/configs/os-check-linux.json, .wolfssl_known_macro_extras, doc/dox_comments/header_files/cryptocb.h
Coverage: 1 of 1 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: Lite
Fenrir's latest completed scan found no issues; clearing the prior automated change request.
|
Frauschi
left a comment
There was a problem hiding this comment.
Main concern: with XOF dispatch on by default and the new stream rule in every cryptocb build, existing SHAKE callbacks break; keeping both opt-in avoids that.
There was a problem hiding this comment.
🔵 Needs a closer look
SHAKE ownership/reset and architecture-specific dispatch changes need crypto maintainer validation of real-device lifecycle and fallback behavior because testing used device emulation without SHAKE hardware.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
|
retest this please |
|
@claude review |
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12351
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): .github/configs/os-check-linux.json, .wolfssl_known_macro_extras, doc/dox_comments/header_files/cryptocb.h
Coverage: 7 of 11 in-scope changed file(s) opened by the reviewer; not opened: wolfcrypt/src/cryptocb.c, wolfssl/wolfcrypt/cryptocb.h, wolfssl/wolfcrypt/settings.h, wolfssl/wolfcrypt/sha3.h
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

Description
Two ways to put SHA-3 hardware under software ML-DSA and ML-KEM.
WC_SHA3_USER_BLOCK=<function>-BlockSha3()calls the namedvoid f(word64* s)in place of the built-in Keccak-f[1600] permutation. Not available with FIPS, AArch64 assembly or PPC32 assembly.WC_SHAKE_OP_RESET- new SHAKE callback operation sent bywc_Shake128_Reset()/wc_Shake256_Reset().CRYPTO_CB_VERis now 6.WOLF_CRYPTO_CB_SHAKE_XOF(still opt-in), once a device has handled part of a SHAKE stream, a laterCRYPTOCB_UNAVAILABLEreturnsBAD_STATE_Einstead of continuing in software. The mid-stream decline case inshake_cb_xof_test(Add crypto callback for SHAKE absorb and squeeze ops #11548) now expects that. Builds without it dispatch SHAKE as before.struct wc_Sha3gains one byte inWOLF_CRYPTO_CB_SHAKE_XOFbuilds.SLH-DSA is not routed here.
Fixes ZD 22902, ZD 22701
Testing
make checkwith--enable-all, crypto callback builds with and withoutWOLF_CRYPTO_CB_SHAKE_XOF(C,--enable-intelasm,WOLF_CRYPTO_CB_FIND,WOLFSSL_HASH_KEEP) and thesha3-user-blockCI entry, now with LMS and XMSS.testwolfcryptfor AArch64 and ARM32 assembly under qemu. The test device inwolfcrypt/test/test.ckeeps its own sponge and counts each operation. Builds without crypto callbacks produce the same object code as master. No SHAKE hardware was available.Checklist