Skip to content

Add configure and CMake options for the PQC small memory paths - #12156

Open
Frauschi wants to merge 4 commits into
wolfSSL:masterfrom
Frauschi:pq-small-mem-build-options
Open

Frauschi wants to merge 4 commits into
wolfSSL:masterfrom
Frauschi:pq-small-mem-build-options

Conversation

@Frauschi

Copy link
Copy Markdown
Member

Description

The ML-KEM and ML-DSA small memory paths could only be selected through CFLAGS, and CMake had no small memory option for any PQC algorithm. This adds them to both build systems.

Stacked on #12146: the first commit is that PR's, rebased on current master. Review the last three, and merge after #12146.

  • --enable-mlkem=small-mem, --enable-mldsa=small-mem|smallest-mem; nonblock now selects these through the same switch
  • CMake WOLFSSL_MLKEM_SMALL_MEM, WOLFSSL_MLDSA_SMALL_MEM (yes/smallest), WOLFSSL_SLHDSA_SMALL_MEM, WOLFSSL_FALCON_SMALL_MEM (yes/smallest), each with options.h.in entries; warns when the algorithm is off
  • Fix: CMake Falcon builds never wrote HAVE_FALCON to options.h, so apps saw Falcon as disabled
  • ML-KEM small-mem or nonblock with Intel or AArch64 assembly used to stop at an #error in wc_mlkem.c; configure now adds WC_MLKEM_NO_ASM and warns

Follow-up

WC_MLKEM_NO_ASM turns off all ML-KEM assembly, decapsulation included, about 2.5x slower on AArch64. A follow-up PR will keep the assembly for decapsulation and the NTT under small-mem in wc_mlkem.c, as AArch32 already does, and drop the configure workaround.

Testing

  • pq-all: pq-small-mem-options (all four algorithms from configure options), mlkem-small-mem-intelasm, mlkem-aarch64-armasm-small-mem
  • cmake.yml: builds with all four options at smallest, checks every macro reaches options.h, then reconfigures with yes and builds again

@Frauschi Frauschi self-assigned this Nov 17, 2026
Copilot AI balanced review requested due to automatic review settings November 17, 2026 13:44
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

gcc-arm-cortex-m4-pq

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

gcc-arm-cortex-m7-pq

  • FLASH: .text +128 B (+0.0%, 321,184 B / 1,048,576 B, total: 31% used)

stm32-sim-stm32h753

  • FLASH: .text +64 B (+0.0%, 221,368 B / 2,097,152 B, total: 11% used)

zephyr-frdm_rw612

  • FLASH: rodata +32 B, text +584 B (+0.2%, 297,132 B / 67,108,864 B, total: 0% used)

No memory changes detected for:


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

CMake’s ML-KEM small-memory mode fails compilation with Intel speedups or AArch64 assembly enabled through compiler flags because it omits the required WC_MLKEM_NO_ASM fallback.

1 open issue
What changed in this PR

Exposes post-quantum small-memory modes through wolfSSL’s build systems, layered on #12146’s non-blocking TLS 1.3 support.

Changes:

  • Adds configure and CMake options for small-memory implementations.
  • Exports memory-mode and Falcon definitions to generated headers, and adds configure’s ML-KEM assembly fallback.
  • Expands build-option, reconfiguration, and handshake coverage.
File Description
wolfssl/​wolfcrypt/​wc_mlkem.h Adds async key state and usage documentation.
wolfssl/​wolfcrypt/​wc_mldsa.h Adds async key state and usage documentation.
wolfssl/​wolfcrypt/​async.h Defines ML-DSA and ML-KEM async operations.
wolfssl/​internal.h Declares ML-DSA handshake helpers and verification state.
wolfcrypt/​test/​test.c Tests software-async PQ operations.
wolfcrypt/​src/​wc_mlkem.c Integrates non-blocking ML-KEM with software async.
wolfcrypt/​src/​wc_mldsa.c Integrates non-blocking ML-DSA with software async.
wolfcrypt/​src/​async.c Dispatches PQ operations and resets completed state.
tests/​api/​test_tls13.h Registers the non-blocking PQ handshake test.
tests/​api/​test_tls13.c Tests handshakes, resumption, and pending-operation cleanup.
src/​tls13.c Uses async-aware ML-DSA handshake helpers.
src/​tls.c Preserves pending ML-KEM shares and fixes encapsulate-only servers.
src/​internal.c Manages ML-DSA handshake operations and cleanup.
configure.ac Adds memory modes, async prerequisites, and assembly fallback.
CMakeLists.txt Adds four PQ small-memory options.
cmake/​options.h.in Exports memory-mode and Falcon definitions.
.wolfssl_known_macro_extras Registers PQ async opt-out macros.
.github/​workflows/​mlkem-encap-server.yml Adds encapsulate-only server interoperability coverage.
.github/​workflows/​cmake.yml Checks memory-mode builds and reconfiguration.
.github/​configs/​pq-all.json Adds memory-option, assembly, and non-blocking test configurations.

Review effort: Balanced

Comment thread CMakeLists.txt Resolved
@Frauschi
Frauschi force-pushed the pq-small-mem-build-options branch from 34fdc1f to ead6a64 Compare November 17, 2026 16:56
@Frauschi

Copy link
Copy Markdown
Member Author

@claude review

@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 cmake/options.h.in Resolved
Comment thread CMakeLists.txt Resolved
Comment thread wolfcrypt/src/wc_mlkem.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 #12156

⚠️ An internal error occurred during the automated review. This error has been logged. Please contact the Fenrir team if you need assistance.

Error: TimeoutExpired

@Frauschi
Frauschi force-pushed the pq-small-mem-build-options branch from ead6a64 to c1e3041 Compare November 17, 2026 18:08
dgarske and others added 4 commits December 3, 2026 10:53
The ML-KEM and ML-DSA small memory paths could only be selected by passing
their macros in CFLAGS, while Falcon and SLH-DSA already had small-mem
configure options. Add:

- --enable-mlkem=small-mem: WOLFSSL_MLKEM_MAKEKEY_SMALL_MEM and
  WOLFSSL_MLKEM_ENCAPSULATE_SMALL_MEM.
- --enable-mldsa=small-mem: WOLFSSL_MLDSA_MAKE_KEY_SMALL_MEM,
  WOLFSSL_MLDSA_SIGN_SMALL_MEM and WOLFSSL_MLDSA_VERIFY_SMALL_MEM.
- --enable-mldsa=smallest-mem: small memory key generation with the
  smallest memory signer and verifier (WOLFSSL_MLDSA_SIGN_SMALLEST_MEM,
  WOLFSSL_MLDSA_VERIFY_SMALLEST_MEM). Like --enable-falcon, smallest-mem
  implies small-mem.

The existing small option is unchanged: it selects the code size reduction
(WOLFSSL_MLKEM_SMALL / WOLFSSL_MLDSA_SMALL), not the RAM reduction.

The nonblock options now select the small memory paths through the same
flag instead of setting the macros themselves, so nonblock,smallest-mem
runs the non-blocking state machine on the smallest memory signer and
verifier. Plain nonblock produces the same macros as before.

With --enable-intelasm, or --enable-armasm on AArch64, the ML-KEM small
memory paths also define WC_MLKEM_NO_ASM: wc_mlkem.c rejects them with that
assembly, so these builds failed with an #error. The nonblock option, which
selects the small memory paths, had the same failure. WC_MLKEM_NO_ASM
turns off the assembly for every ML-KEM operation, decapsulation included,
so configure warns when it adds it.

Add pq-all configs that build every PQC low-memory path from configure
options alone, and the ML-KEM small memory paths with Intel and AArch64
assembly.
WOLFSSL_FALCON put -DHAVE_FALCON on the library target, but
cmake/options.h.in had no entry for it, so wolfssl/options.h never
defined it. The unit tests and any application built against an
installed wolfSSL saw Falcon as disabled while the library had it
compiled in, a feature-define mismatch between library and application.

The entry is #ifndef-guarded rather than a bare #undef pair, so a
HAVE_FALCON passed through CMAKE_C_FLAGS is not undefined again for code
that includes options.h.
CMake had no way to select the low-memory implementations of any PQC
algorithm. Add options matching the configure ones:

- WOLFSSL_MLKEM_SMALL_MEM=yes        (--enable-mlkem=small-mem)
- WOLFSSL_MLDSA_SMALL_MEM=yes|smallest (--enable-mldsa=small-mem|smallest-mem)
- WOLFSSL_SLHDSA_SMALL_MEM=yes       (--enable-slhdsa=small-mem)
- WOLFSSL_FALCON_SMALL_MEM=yes|smallest (--enable-falcon=small-mem|smallest-mem)

The ML-DSA and Falcon options also accept the configure spellings
small-mem and smallest-mem. add_option reduces any other value to yes
or no.

Each takes effect only with its algorithm enabled; set without it, the
option is ignored with a warning. Every macro it sets has an options.h.in
entry so it reaches wolfssl/options.h as well as the library. The entries
are #ifndef-guarded like WOLFSSL_SLHDSA_VERIFY_ONLY: a bare #undef pair
would undefine a macro passed through CMAKE_C_FLAGS for code including
options.h while the library keeps it, and the ML-DSA verify macros change
the size of wc_MlDsaKey. A default build's options.h defines nothing new.

Like configure, ML-KEM small-mem adds WC_MLKEM_NO_ASM with a warning when
x86_64 or AArch64 assembly is enabled (WOLFSSL_INTEL_ASM, WOLFSSL_ARM_ASM
or the macros in CMAKE_C_FLAGS), since wc_mlkem.c has no assembly for the
small memory paths.

The CMake workflow gains a build with all four options at their smallest
setting that checks every macro reaches options.h, then reconfigures with
yes, checks the small variants replace the smallest ones and builds
again. It does not run ctest: the slow small-memory signers would
lengthen the sequential job, and the pq-all configs run their tests.
@Frauschi
Frauschi force-pushed the pq-small-mem-build-options branch from c1e3041 to 826737d Compare December 4, 2026 08:24
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