]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
lib/crypto: tests: Add KUnit tests for ML-DSA verification
authorEric Biggers <ebiggers@kernel.org>
Sun, 14 Dec 2025 18:17:12 +0000 (10:17 -0800)
committerEric Biggers <ebiggers@kernel.org>
Mon, 12 Jan 2026 19:07:49 +0000 (11:07 -0800)
commited894faccb8de55cd755e093c4b0971f190d384d
tree6237348e651828c9bfe6f7a511d9a7c917efb94c
parent64edccea594cf7cb1e2975fdf44531e3377b32db
lib/crypto: tests: Add KUnit tests for ML-DSA verification

Add a KUnit test suite for ML-DSA verification, including the following
for each ML-DSA parameter set (ML-DSA-44, ML-DSA-65, and ML-DSA-87):

- Positive test (valid signature), using vector imported from leancrypto
- Various negative tests:
    - Wrong length for signature, message, or public key
    - Out-of-range coefficients in z vector
    - Invalid encoded hint vector
    - Any bit flipped in signature, message, or public key
- Unit test for the internal function use_hint()
- A benchmark

ML-DSA inputs and outputs are very large.  To keep the size of the tests
down, use just one valid test vector per parameter set, and generate the
negative tests at runtime by mutating the valid test vector.

I also considered importing the test vectors from Wycheproof.  I've
tested that mldsa_verify() indeed passes all of Wycheproof's ML-DSA test
vectors that use an empty context string.  However, importing these
permanently would add over 6 MB of source.  That's too much to be a
reasonable addition to the Linux kernel tree for one algorithm.  It also
wouldn't actually provide much better test coverage than this commit.
Another potential issue is that Wycheproof uses the Apache license.

Similarly, this also differs from the earlier proposal to import a long
list of test vectors from leancrypto.  I retained only one valid
signature for each algorithm, and I also added (runtime-generated)
negative tests which were missing.  I think this is a better tradeoff.

Reviewed-by: David Howells <dhowells@redhat.com>
Tested-by: David Howells <dhowells@redhat.com>
Link: https://lore.kernel.org/r/20251214181712.29132-3-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
lib/crypto/tests/Kconfig
lib/crypto/tests/Makefile
lib/crypto/tests/mldsa-testvecs.h [new file with mode: 0644]
lib/crypto/tests/mldsa_kunit.c [new file with mode: 0644]