Skip to content

Add CB_ONLY mode for ML-KEM - #11212

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

Add CB_ONLY mode for ML-KEM#11212
padelsbach wants to merge 2 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)

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.

4 participants