Add CB_ONLY mode for ML-KEM - #11212
padelsbach wants to merge 4 commits into
Conversation
|
jenkins retest this please |
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11212
Scan targets checked: wolfcrypt-bugs, wolfcrypt-port-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src
Findings: 10
10 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
6ee7ab0 to
1e0d76c
Compare
1e0d76c to
30b3da0
Compare
30b3da0 to
24c9732
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11212
Scan targets checked: wolfcrypt-bugs, wolfcrypt-port-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src
Findings: 6
4 finding(s) posted as inline comments (see file-level comments below)
Required changes (2)
CB_ONLY_MLKEM strips ML-KEM assembly that retained helpers still call, breaking the link
File: wolfcrypt/src/wc_mlkem_poly.c:7199
Function: mlkem_to_bytes
Category: Logic errors
WOLF_CRYPTO_CB_ONLY_MLKEM now compiles out all of wc_mlkem_asm.S and the ARM *-mlkem-asm* files, but wc_mlkem_poly.c keeps mlkem_to_bytes/mlkem_from_bytes/mlkem_cmp/mlkem_gen_matrix/mlkem_csubq_c, which reference mlkem_to_bytes_avx2, mlkem_csubq_neon, mlkem_arm32_csubq etc. Any asm-enabled build (--enable-intelasm, --enable-armasm) fails to link; wc_MlKemKey_EncodePublicKey needs mlkem_to_bytes.
Recommendation: Keep the still-referenced assembly helpers compiled under CB_ONLY_MLKEM, or disable the asm paths consistently in wc_mlkem_poly.c for that mode.
Referenced code: wolfcrypt/src/wc_mlkem_poly.c:7199-7201 (3 lines)
CB_ONLY_MLKEM strips ML-KEM assembly while wc_mlkem_poly.c still calls it
File: wolfcrypt/src/wc_mlkem_poly.c:7104
Function: mlkem_from_bytes
Category: Preprocessor-conditional security bypass
WOLF_CRYPTO_CB_ONLY_MLKEM disables the whole of wc_mlkem_asm.S (and the ARM ML-KEM asm), but the new gating in wc_mlkem_poly.c leaves mlkem_from_bytes, mlkem_to_bytes and mlkem_cmp compiled with their asm dispatch intact. With USE_INTEL_SPEEDUP (or aarch64 WOLFSSL_ARMASM) the library fails to link on mlkem_from_bytes_avx2, mlkem_to_bytes_avx2, mlkem_cmp_avx2/_avx512, mlkem_cmp_neon. No added CI config enables asm, so this is uncaught.
Recommendation: Keep the byte-packing/compare assembly routines compiled under WOLF_CRYPTO_CB_ONLY_MLKEM, or force WC_MLKEM_NO_ASM in that mode, and add an asm-enabled CB_ONLY_MLKEM CI entry.
Referenced code: wolfcrypt/src/wc_mlkem_poly.c:7104-7106 (3 lines)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
24c9732 to
3434b9d
Compare
|
Retest this please. (no logs) |
c45c30d to
0d7ec0f
Compare
philljj
left a comment
There was a problem hiding this comment.
merge conflict in wolfcrypt test.c
0d7ec0f to
643f207
Compare
|
Retest this please. (all green except one hang in ready config) |
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11212
Scan targets checked: wolfcrypt-bugs, wolfcrypt-port-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src
Findings: 4
3 finding(s) posted as inline comments (see file-level comments below)
Required changes (1)
ARM assembly builds with WOLF_CRYPTO_CB_ONLY_MLKEM lose mlkem_csubq while mlkem_to_bytes_c still calls it
File: wolfcrypt/src/wc_mlkem_poly.c:7337
Function: mlkem_to_bytes_c
Category: Preprocessor-conditional security bypass
mlkem_to_bytes_c is ungated and calls mlkem_csubq_c, which on WOLFSSL_ARMASM builds is a macro for mlkem_csubq_neon/mlkem_thumb2_csubq/mlkem_arm32_csubq (wc_mlkem.h:832/848/864). Those symbols now compile out with the ARM ML-KEM asm, so every ARM asm build with WOLF_CRYPTO_CB_ONLY_MLKEM fails to link wc_MlKemKey_EncodePrivateKey/EncodePublicKey. The Intel path was fixed at line 7365 but the ARM path was not.
Recommendation: Keep the C mlkem_csubq_c (or the ARM csubq asm) available when WOLF_CRYPTO_CB_ONLY_MLKEM is defined.
Referenced code: wolfcrypt/src/wc_mlkem_poly.c:7337-7339 (3 lines)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
643f207 to
1f6eb54
Compare
|
jenkins retest this please |
|
Retest this please. (PRB config A openssl test timeout) |
1f6eb54 to
ee45af2
Compare
ee45af2 to
a986297
Compare
|
retest this please |
a986297 to
e0487eb
Compare
e0487eb to
ed89d4a
Compare
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The option contract, callback-only tests, and Visual Studio ARM64 stripping have unresolved defects.
Review effort: Balanced
Findings: 3
Open (3)
What changed in this PR
Adds an ML-KEM crypto-callback-only mode to reduce binary size by removing native lattice operations and assembly implementations.
Changes:
- Routes ML-KEM operations exclusively through crypto callbacks.
- Excludes native polynomial and assembly implementations.
- Adds configuration validation, CI coverage, and callback-only tests.
| File | Description |
|---|---|
.github/workflows/cryptocb-only.yml |
Adds ML-KEM callback-only CI configurations. |
configure.ac |
Enables callback-only ML-KEM for selected builds. |
tests/api/test_mlkem.c |
Gates native-only API tests. |
wolfcrypt/src/cryptocb.c |
Documents the new build option. |
wolfcrypt/src/port/arm/armv8-32-mlkem-asm.S |
Excludes ARM32 assembly. |
wolfcrypt/src/port/arm/armv8-32-mlkem-asm_c.c |
Excludes inline ARM32 assembly. |
wolfcrypt/src/port/arm/armv8-mlkem-asm.S |
Excludes AArch64 assembly. |
wolfcrypt/src/port/arm/armv8-mlkem-asm_c.c |
Excludes inline AArch64 assembly. |
wolfcrypt/src/port/arm/thumb2-mlkem-asm.S |
Excludes Thumb-2 assembly. |
wolfcrypt/src/port/arm/thumb2-mlkem-asm_c.c |
Excludes inline Thumb-2 assembly. |
wolfcrypt/src/wc_mlkem.c |
Retains public dispatch APIs while removing native operations. |
wolfcrypt/src/wc_mlkem_asm.S |
Excludes x86 ML-KEM assembly. |
wolfcrypt/src/wc_mlkem_poly.c |
Removes native lattice math while retaining serialization helpers. |
wolfcrypt/test/test.c |
Adds callback-only dispatch and serialization tests. |
wolfssl/wolfcrypt/settings.h |
Validates callback-only configuration constraints. |
wolfssl/wolfcrypt/wc_mlkem.h |
Exposes native-implementation availability. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
8c58328 to
4f4d03d
Compare
|
Retest this please. (network interruption orsomething) |
|
cryptocb ci is angry: ../wolfcrypt/src/wc_mlkem.c: In function 'wc_MlKemKey_PrivateKeyDecode':
../wolfcrypt/src/wc_mlkem.c:3357:22: warning: implicit declaration of function 'mlkemkey_get_k'; did you mean 'mlkem_keygen'? [-Wimplicit-function-declaration]
3357 | int scrubK = mlkemkey_get_k(key);
| ^~~~~~~~~~~~~~
| mlkem_keygen |
4f4d03d to
3db50a4
Compare
philljj
left a comment
There was a problem hiding this comment.
merge conflict from the shake cryptocb PR
3db50a4 to
70bd595
Compare
70bd595 to
a988163
Compare

Description
Saves approx 14kB when enabled/offloaded.
Testing
Added new tests
Checklist