Fix build for MLK_CONFIG_NO_RANDOMIZED_API - #1816
Draft
hanno-becker wants to merge 5 commits into
Draft
Conversation
hanno-becker
commented
Jul 26, 2026
Contributor
- Builds on Make tests and examples compatible with reduced-API configurations #1787
- Fixes Functional test (test_mlkem.c) fails to build for MLK_CONFIG_NO_RANDOMIZED_API #1815
Contributor
CBMC Results (ML-KEM-512)Full Results (191 proofs)
|
Contributor
CBMC Results (ML-KEM-768)Full Results (191 proofs)
|
Contributor
CBMC Results (ML-KEM-1024)Full Results (191 proofs)
|
hanno-becker
force-pushed
the
no-randomized
branch
3 times, most recently
from
July 27, 2026 06:30
e22e7c3 to
bae7641
Compare
Add MLK_CONFIG_NO_KEYPAIR_API, MLK_CONFIG_NO_ENCAPS_API and MLK_CONFIG_NO_DECAPS_API, and guard public and internal APIs accordingly. Generate deterministic KEM vectors so tests and examples can exercise each enabled operation independently. Adapt ACVP, Wycheproof, allocation, RNG failure and stack tests to reduced builds; stack analysis measures only enabled APIs. Cover all non-empty reduced API combinations in CI. Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
The previous encapDecap-file gate only loaded the file when all four sub-functions (encapsulation, decapsulation, encapsulationKeyCheck, decapsulationKeyCheck) were compiled in. Under encaps-only, decaps-only, keygen-encaps, and keygen-decaps configurations that skipped the entire prompt file, so ACVP reported OK while driving zero test cases through the binary. This commit intead loads the encapDecap file whenever _any_ of its sub-functions are supported, and drops unsupported test cases via a filter that mutates both the prompt and the expectedResults data consistently. This mirrors the filter_test_cases machinery introduced for the same reason in mldsa-native (PR #1140). Reduced-API runs also now emit a labelled stderr summary block after "ALL GOOD!" for both whole-prompt skips and per-test drops, so coverage gaps aren't buried in scrollback. Full-API runs stay silent. Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
The test vectors added in the last commit lead to a stack overflow on AVR for ML-KEM-1024. This commit ports the AVR setup from mldsa-native, including its increase in RAM to nearly 64K. This fixes the AVR test, and also makes future maintenance of the AVR backend across mlkem-native and mldsa-native simpler. - nix/avr: RAMEND 0x81FF -> 0xFFFF, EEPROM E2END 0x3FFF -> 0x7FFF - platform.mk: __stack=0x81FF -> __DATA_REGION_LENGTH__=0xFC00, so .data/.bss grow up from 0x0200 with the stack set at runtime - avr_wrapper.c / init7.S / exec_wrapper.py: place the argc/argv block at the top of RAM and set SP just below it, giving the largest possible stack Keeping this identical (modulo naming) to mldsa-native lets both projects share one AVR baremetal harness, so fixes port across as a prefix diff. Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
The reduced-API refactor guarded the randomized round-trip tests in test_mlkem.c on !NO_KEYPAIR_API && !NO_ENCAPS_API && !NO_DECAPS_API, but omitted !NO_RANDOMIZED_API. The public header only exposes crypto_kem_keypair() and crypto_kem_enc() when NO_RANDOMIZED_API is unset (nested inside the keypair/encaps API guards), so a plain CFLAGS="-DMLK_CONFIG_NO_RANDOMIZED_API" make failed to compile test_mlkem.c with implicit-declaration errors. Add the missing !NO_RANDOMIZED_API term to both guard blocks, matching the pattern already used in test_stack.c, test_rng_fail.c and test_alloc.c. The deterministic test_kem_expected_* vectors keep exercising keygen/encaps/decaps under NO_RANDOMIZED_API; only the randomized round-trip loop is compiled out. Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
The deterministic-only build (MLK_CONFIG_NO_RANDOMIZED_API) had no coverage in the config-variations matrix, which is how the test_mlkem.c build regression went unnoticed. Add a "no-randomized" variation that builds and runs func, kat, acvp, wycheproof, stack and rng_fail under the flag, mirroring the reduced-API entries. Examples are included except basic_deterministic, which already sets the flag in its own config and would otherwise trip -Wmacro-redefined. The alloc test is disabled: its exact high-watermark check assumes the randomized wrappers, whose coins buffer is absent from the deterministic-only allocation profile. Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
hanno-becker
force-pushed
the
no-randomized
branch
from
July 28, 2026 04:05
bae7641 to
579cce3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.