Skip to content

Add CB_ONLY mode for ML-KEM - #11212

Open
padelsbach wants to merge 4 commits into
wolfSSL:masterfrom
padelsbach:cbonly-mlkem
Open

padelsbach wants to merge 4 commits into
wolfSSL:masterfrom
padelsbach:cbonly-mlkem

Conversation

@padelsbach

Copy link
Copy Markdown
Contributor

Description

Saves approx 14kB when enabled/offloaded.

Testing

Added new tests

Checklist

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

@padelsbach

padelsbach commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor Author

jenkins retest this please

@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 #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.

@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 #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.

Comment thread wolfcrypt/src/wc_mlkem_poly.c
Comment thread wolfcrypt/test/test.c Outdated
Comment thread wolfcrypt/test/test.c
Comment thread wolfcrypt/src/wc_mlkem_poly.c
Comment thread wolfcrypt/test/test.c Outdated
Comment thread wolfcrypt/test/test.c
@philljj

philljj commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Retest this please.

(no logs)

@padelsbach
padelsbach force-pushed the cbonly-mlkem branch 2 times, most recently from c45c30d to 0d7ec0f Compare September 3, 2026 03:36

@philljj philljj 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.

merge conflict in wolfcrypt test.c

@philljj

philljj commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Retest this please.

(all green except one hang in ready config)

@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 #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.

Comment thread wolfcrypt/src/wc_mlkem_poly.c
Comment thread wolfcrypt/src/wc_mlkem_poly.c
Comment thread wolfcrypt/test/test.c Outdated
@padelsbach

Copy link
Copy Markdown
Contributor Author

jenkins retest this please

@philljj

philljj commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Retest this please.

(PRB config A openssl test timeout)

@padelsbach

Copy link
Copy Markdown
Contributor Author

retest this please

Copilot AI balanced review requested due to automatic review settings October 1, 2026 00:13

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.

Copilot review overview

🟡 Changes recommended

The option contract, callback-only tests, and Visual Studio ARM64 stripping have unresolved defects.

Review effort: Balanced
Findings: 3 Medium severity

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.

Comment thread configure.ac Outdated
Comment thread tests/api/test_mlkem.c
Comment thread wolfcrypt/src/port/arm/armv8-mlkem-asm.S
@philljj

philljj commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Retest this please.

(network interruption orsomething)

@philljj

philljj commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

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

@philljj philljj 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.

merge conflict from the shake cryptocb PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants