Commit abfdabf
committed
Make tests and examples compatible with reduced-API configurations
The previous tests and examples assumed all APIs (keygen, encaps,
decaps) were always available: encaps tests generated a keypair as
setup, decaps tests generated a keypair and ciphertext as setup, and
the alloc test required keygen for every test function. This made them
incompatible with reduced-API configurations where some APIs are
disabled via MLK_CONFIG_NO_KEYPAIR_API, MLK_CONFIG_NO_ENCAPS_API, or
MLK_CONFIG_NO_DECAPS_API.
This commit introduces auto-generated test vectors and refactors all
tests and examples so that each operation (keygen, encaps, decaps) can
be tested independently using pre-computed test vectors.
scripts/notrandombytes:
- Add Python implementation of the SURF-based deterministic test PRNG,
matching the C version in test/notrandombytes/
- Used by autogen --test-vectors to generate reproducible randomness
for test vector generation
Test vector generation (scripts/autogen --test-vectors):
- Add --test-vectors flag to scripts/autogen that invokes the ACVP
binaries with randomness from scripts/notrandombytes to generate
test/test_vectors/expected_test_vectors.h and the multilevel variant
- Generate pk, sk, ct, ss vectors for all three parameter sets
(512, 768, 1024)
- Include z, d, m byte-arrays in the header so consumers don't need
to hardcode them
- Array dimensions are explicit in the generated header
Test changes (test_mlkem.c):
- The existing tests (test_keys, test_invalid_pk, etc.) require all
three APIs and are left unchanged, guarded by
!MLK_CONFIG_NO_KEYPAIR_API && !MLK_CONFIG_NO_ENCAPS_API &&
!MLK_CONFIG_NO_DECAPS_API
- Add test_kem_expected() as a new minimal test that works in
reduced-API configurations: each block (keygen, encaps, decaps) is
independently guarded and uses test vectors directly, so e.g. the
decaps block can run without keygen by using test_vector_sk
test_alloc.c and test_rng_fail.c:
- Both files exercise the same 7 API entry points (keypair_derand,
keypair, enc_derand, enc, check_pk, dec, check_sk), each
independently guarded by the minimal required API
- Encaps tests use test_vector_pk directly (no keygen dependency)
- Decaps tests use test_vector_sk/ct directly (no keygen or encaps
dependency)
- main() uses r |= pattern for error accumulation
test_stack.c:
- Guard each test function (keygen/encaps/decaps stack measurement)
by the matching API config; unavailable modes print SKIPPED
gen_KAT/wycheproof/acvp:
- KAT and Wycheproof stub out to a SKIPPED main() when any API is
disabled (they inherently need all three)
- ACVP guards each mode (keyGen / encapDecap encapsulation /
encapDecap decapsulation / encapsulationKeyCheck /
decapsulationKeyCheck) by the matching API config, so it builds
and works in any subset
Example refactoring:
- Hoist test logic into static example_xxx() functions with
#if/#else/#endif guards and SKIPPED stubs for disabled APIs
- main() is a flat sequence of r |= example_xxx() calls
- example_end_to_end runs the full keygen->encaps->decaps flow only
when all three APIs are enabled; example_expected_vectors runs
independent keygen/encaps/decaps KAT checks for whichever APIs are
enabled
- Multilevel examples use per-level static functions (test_expected_512,
test_expected_768, test_expected_1024) with the same per-API guards
- basic_deterministic uses test_vector_z/d/m from the header instead
of hardcoded byte arrays
- Add expected_test_vectors.h symlink (single- or multi-level) in each
example directory pointing to test/test_vectors/
CI (config-variations):
- Add keygen-only, encaps-only, decaps-only, keygen-encaps, keygen-decaps,
encaps-decaps test configurations, covering all 6 combinations of
1 or 2 enabled APIs from {keygen, encaps, decaps}
Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>1 parent 68cfb89 commit abfdabf
78 files changed
Lines changed: 5758 additions & 1398 deletions
File tree
- .github/actions/config-variations
- examples
- basic_deterministic
- mlkem_native
- basic
- bring_your_own_fips202_static
- mlkem_native
- bring_your_own_fips202
- mlkem_native
- custom_backend
- mlkem_native
- monolithic_build_multilevel_native
- mlkem_native
- monolithic_build_multilevel
- mlkem_native
- monolithic_build_native
- mlkem_native
- monolithic_build
- mlkem_native
- multilevel_build_native
- mlkem_native
- multilevel_build
- mlkem_native
- mlkem
- src
- proofs/cbmc
- scripts
- test
- acvp
- configs
- src
- test_vectors
- wycheproof
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
56 | | - | |
| 58 | + | |
57 | 59 | | |
58 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
59 | 68 | | |
60 | 69 | | |
61 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
| 9 | + | |
| 10 | + | |
14 | 11 | | |
15 | | - | |
16 | 12 | | |
17 | 13 | | |
18 | 14 | | |
| |||
27 | 23 | | |
28 | 24 | | |
29 | 25 | | |
30 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
31 | 29 | | |
32 | 30 | | |
33 | 31 | | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | 32 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
| 33 | + | |
66 | 34 | | |
67 | | - | |
| 35 | + | |
| 36 | + | |
68 | 37 | | |
69 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
70 | 47 | | |
71 | | - | |
72 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
73 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
74 | 58 | | |
75 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
76 | 68 | | |
77 | | - | |
78 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
79 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
80 | 77 | | |
81 | | - | |
82 | | - | |
83 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
84 | 87 | | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
94 | 91 | | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
103 | 101 | | |
104 | | - | |
105 | | - | |
| 102 | + | |
106 | 103 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
0 commit comments