[cryptotest] Add ML-KEM tests using Wycheproof and ACVP test vectors #219
[cryptotest] Add ML-KEM tests using Wycheproof and ACVP test vectors #219mkannwischer merged 2 commits intomasterfrom
Conversation
f07eb40 to
dbddbb0
Compare
|
I have reworked this PR a bit making it easier to also accommodate ML-DSA in #223. |
7f6f49d to
7019f31
Compare
jadephilipoom
left a comment
There was a problem hiding this comment.
LGTM, thanks Matthias!
|
CI failure looks unrelated and perhaps like the FPGA may have gotten disconnected, I'd suggest just rerunning it to see if it works. |
Adds the NIST ACVP-Server v1.1.0.41 as an external dependency for ML-KEM (and future algorithm) test vectors. Signed-off-by: Matthias J. Kannwischer <matthias@zerorisc.com>
Adds ML-KEM to the cryptotest framework with support for all three
parameter sets (ML-KEM-512, ML-KEM-768, ML-KEM-1024) and four
test operations:
- keygen: deterministic key generation from seed (d||z)
- encaps: deterministic encapsulation with provided ek and
randomness m
- decaps: decapsulation with provided dk and ciphertext
- keygen_decaps: keygen followed by decapsulation (Wycheproof
mlkem_*_test.json provides seed + ciphertext, firmware generates
keys then decapsulates)
Test vector sources:
- Wycheproof (C2SP): keygen_seed_test, encaps_test,
semi_expanded_decaps_test, and the combined test.json
for all three parameter sets (1695 vectors)
- ACVP (NIST ACVP-Server v1.1.0.41): keyGen and encapDecap
internalProjection files (240 vectors)
All 1935 test vectors from both sources are covered.
ACVP encapsulationKeyCheck and decapsulationKeyCheck tests are
mapped to encaps and decaps operations respectively: the cryptolib
does not expose dedicated key validation functions, but
encapsulate_derand and decapsulate perform internal checks (FIPS 203
modulus check, hash consistency) that reject invalid keys. We test
this by calling the operations with the provided (possibly invalid)
key and dummy randomness/ciphertext, and verifying success/failure.
The biggest challenge here is that ML-KEM data structures are
large (ek up to 1568B, dk up to 3168B).
Naively serializing these as ujson output arrays results in a test
runtime of >2.5 hours - the vast majority of which appears to be
spent on JSON encoding in the firmware.
To address this, we instead compute the SHA3-256 hash of the
outputs in the firmware and the parses.
This brings down test time for everything to ~265s.
Note that the ML-KEM tests need work buffers that are too large
for the stack. This commit allocates them in firmware.c
already in preparation for also adding ML-DSA tests, so that
these buffers can be placed in a union.
Signed-off-by: Matthias J. Kannwischer <matthias@zerorisc.com>
7019f31 to
70d21d5
Compare
I have done that twice now, but it does not seem to help. |
|
Looks like a broader CI issue unfortunately :/ |
Adds ML-KEM to the cryptotest framework with support for all three
parameter sets (ML-KEM-512, ML-KEM-768, ML-KEM-1024) and four
test operations:
randomness m
mlkem_*_test.json provides seed + ciphertext, firmware generates
keys then decapsulates)
Test vector sources:
semi_expanded_decaps_test, and the combined test.json
for all three parameter sets (1695 vectors)
internalProjection files (240 vectors)
All 1935 test vectors from both sources are covered.
ACVP encapsulationKeyCheck and decapsulationKeyCheck tests are
mapped to encaps and decaps operations respectively: the cryptolib
does not expose dedicated key validation functions, but
encapsulate_derand and decapsulate perform internal checks (FIPS 203
modulus check, hash consistency) that reject invalid keys. We test
this by calling the operations with the provided (possibly invalid)
key and dummy randomness/ciphertext, and verifying success/failure.
The biggest challenge here is that ML-KEM data structures are
large (ek up to 1568B, dk up to 3168B).
Naively serializing these as ujson output arrays results in a test
runtime of >2.5 hours - the vast majority of which appears to be
spent on JSON encoding in the firmware.
To address this, we instead compute the SHA3-256 hash of the
outputs in the firmware and the parses.
This brings down test time for everything to ~265s.