Skip to content

Add a SHA-3 permutation override and route software ML-DSA and ML-KEM SHAKE to crypto callbacks - #12351

Open
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:shake_cb_pqc
Open

dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:shake_cb_pqc

Conversation

@dgarske

@dgarske dgarske commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Description

Two ways to put SHA-3 hardware under software ML-DSA and ML-KEM.

  • WC_SHA3_USER_BLOCK=<function> - BlockSha3() calls the named void 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 by wc_Shake128_Reset() / wc_Shake256_Reset(). CRYPTO_CB_VER is now 6.
  • With WOLF_CRYPTO_CB_SHAKE_XOF (still opt-in), once a device has handled part of a SHAKE stream, a later CRYPTOCB_UNAVAILABLE returns BAD_STATE_E instead of continuing in software. The mid-stream decline case in shake_cb_xof_test (Add crypto callback for SHAKE absorb and squeeze ops #11548) now expects that. Builds without it dispatch SHAKE as before.
  • ML-DSA and ML-KEM assembly builds use the SHAKE API when the key has a device id, so the device sees all of the hashing.
  • struct wc_Sha3 gains one byte in WOLF_CRYPTO_CB_SHAKE_XOF builds.

SLH-DSA is not routed here.

Fixes ZD 22902, ZD 22701

Testing

make check with --enable-all, crypto callback builds with and without WOLF_CRYPTO_CB_SHAKE_XOF (C, --enable-intelasm, WOLF_CRYPTO_CB_FIND, WOLFSSL_HASH_KEEP) and the sha3-user-block CI entry, now with LMS and XMSS. testwolfcrypt for AArch64 and ARM32 assembly under qemu. The test device in wolfcrypt/test/test.c keeps its own sponge and counts each operation. Builds without crypto callbacks produce the same object code as master. No SHAKE hardware was available.

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

Copilot AI balanced review requested due to automatic review settings December 1, 2026 23:30
@dgarske dgarske self-assigned this Dec 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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_BLOCK with 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

Comment thread wolfcrypt/src/sha3.c Resolved
Comment thread wolfcrypt/src/sha3.c Resolved
Comment thread wolfcrypt/src/sha3.c Resolved
Comment thread wolfcrypt/src/sha3.c Resolved

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread wolfcrypt/src/sha3.c Resolved
Comment thread wolfcrypt/src/sha3.c Resolved
Comment thread wolfcrypt/src/sha3.c Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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 wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread wolfcrypt/test/test.c Resolved
@dgarske
dgarske requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot December 2, 2026 17:25
@dgarske
dgarske marked this pull request as ready for review December 2, 2026 17:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread wolfcrypt/src/sha3.c Resolved

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@wolfSSL-Fenrir-bot
wolfSSL-Fenrir-bot dismissed stale reviews from themself December 2, 2026 18:18

Fenrir's latest completed scan found no issues; clearing the prior automated change request.

@dgarske
dgarske requested a balanced review from Copilot December 2, 2026 19:17
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

gcc-arm-cortex-m0plus

  • FLASH: .text +124 B (+0.2%, 72,496 B / 262,144 B, total: 28% used)

gcc-arm-cortex-m3

  • FLASH: .text +124 B (+0.1%, 135,106 B / 262,144 B, total: 52% used)

gcc-arm-cortex-m4

  • FLASH: .text +128 B (+0.1%, 214,168 B / 262,144 B, total: 82% used)

gcc-arm-cortex-m4-baremetal

  • FLASH: .text +128 B (+0.2%, 75,316 B / 262,144 B, total: 29% used)

gcc-arm-cortex-m4-crypto-only

  • FLASH: .text +64 B (+0.0%, 184,955 B / 262,144 B, total: 71% used)

gcc-arm-cortex-m4-dtls13

  • FLASH: .text +128 B (+0.1%, 201,572 B / 1,048,576 B, total: 19% used)

gcc-arm-cortex-m4-min-ecc

  • FLASH: .text +128 B (+0.2%, 69,782 B / 262,144 B, total: 27% used)

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .text +128 B (+0.0%, 807,336 B / 1,048,576 B, total: 77% used)

gcc-arm-cortex-m4-pkcs7

  • FLASH: .text +128 B (+0.1%, 227,260 B / 262,144 B, total: 87% used)

gcc-arm-cortex-m4-pq

  • FLASH: .text +64 B (+0.0%, 320,160 B / 1,048,576 B, total: 31% used)

gcc-arm-cortex-m4-rsa-only

  • FLASH: .text +128 B (+0.0%, 349,912 B / 1,048,576 B, total: 33% used)

gcc-arm-cortex-m4-sp-math

  • FLASH: .text +128 B (+0.2%, 69,782 B / 262,144 B, total: 27% used)

gcc-arm-cortex-m4-tls12

  • FLASH: .text +128 B (+0.1%, 135,822 B / 262,144 B, total: 52% used)

gcc-arm-cortex-m4-tls13

  • FLASH: .text +128 B (+0.0%, 256,626 B / 262,144 B, total: 98% used)

gcc-arm-cortex-m7

  • FLASH: .text +64 B (+0.0%, 214,168 B / 262,144 B, total: 82% used)

gcc-arm-cortex-m7-pq

  • FLASH: .text +64 B (+0.0%, 320,992 B / 1,048,576 B, total: 31% used)

gcc-arm-cortex-m7-tls13

  • FLASH: .text +128 B (+0.0%, 256,626 B / 262,144 B, total: 98% used)

stm32-sim-stm32h753

  • FLASH: .text +128 B (+0.1%, 220,568 B / 2,097,152 B, total: 11% used)

zephyr-frdm_rw612

  • FLASH: datas +16 B, log_const_area -8 B, rodata +108 B, text +13,904 B (+5.0%, 296,484 B / 67,108,864 B, total: 0% used)
  • RAM: bss +49 B, datas +16 B (+0.1%, 58,423 B / 983,040 B, total: 6% used)

Catch memory regressions in CI with MemBrowse. Free for open source.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

ARM32 NEON builds with WOLF_CRYPTO_CB break because MLKEM_HASH_CB_SWITCH enables code that calls the excluded mlkem_rej_uniform_c() sampler.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread wolfcrypt/src/wc_mlkem_poly.c Resolved

@Frauschi Frauschi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread wolfssl/wolfcrypt/settings.h Resolved
Comment thread wolfcrypt/src/wc_mldsa.c Resolved
Comment thread wolfcrypt/src/sha3.c Resolved
Comment thread wolfssl/wolfcrypt/sha3.h Resolved
Comment thread wolfssl/wolfcrypt/settings.h Resolved
Comment thread wolfcrypt/src/wc_mlkem.c Resolved
Comment thread wolfcrypt/src/cryptocb.c Resolved
@Frauschi Frauschi removed their assignment Dec 3, 2026
@dgarske
dgarske requested review from Frauschi and a balanced review from Copilot December 3, 2026 18:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

Frauschi
Frauschi previously approved these changes Dec 3, 2026

@Frauschi Frauschi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Frauschi Frauschi assigned wolfSSL-Bot and unassigned dgarske Dec 3, 2026
@Frauschi
Frauschi requested a review from philljj December 3, 2026 19:25
@aidangarske aidangarske added the zd For prs that fix zendesk issues label Dec 3, 2026
@dgarske

dgarske commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

retest this please

@SparkiDev

Copy link
Copy Markdown
Contributor

@claude review

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findings marked 🟡 are optional suggestions and need no follow-up push.

Comment thread wolfcrypt/src/wc_mlkem_poly.c Resolved
Comment thread wolfcrypt/src/sha3.c Resolved
@dgarske dgarske assigned dgarske and unassigned SparkiDev Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

zd For prs that fix zendesk issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants