lib/crypto: ML-DSA verification support
Subsystems (4)
Eric Biggers
maintainerv4 cover lib/crypto: ML-DSA verification support
This series can also be retrieved from:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git mldsa-v4
This series adds support for verifying ML-DSA signatures to lib/crypto/. Patch 1 is the ML-DSA implementation itself. See that for full details. Patch 2 adds the KUnit test suite.
The initial use case for this will be kernel module signature verification. For more details, see David Howells' patchset
https://lore.kernel.org/linux-crypto/[email protected]/
Note: I'm planning to apply this to libcrypto-next for 6.20.
Changed in v4:
- Added missing MODULE_IMPORT_NS() to fix build error when building the KUnit test suite as a loadable module
- Added David's Reviewed-by and Tested-by
- Clarified a comment slightly
- Rebased onto v6.19-rc1
Changed in v3:
- Moved SHAKE128 block buffer off the stack
- Reworked use_hint() again, simplifying it further
- Added unit test for use_hint()
- Moved some of the reduction logic into invntt_and_mul_2_32() and simplified it slightly
- Updated Zq_mult() to not rely on signed integer overflow having defined behavior, though this is unnecessary in the kernel
- Formatted the documented return values into a list
- Other minor tweaks
Changed in v2:
- Reworked the KUnit test suite
- Improved commit messages and comments
- Added missing MODULE_DESCRIPTION() and MODULE_LICENSE()
- Made the return values of mldsa_verify() differentiate between an input being malformed and the "real" signature check failing
- Refactored w1 encoding into a helper function
- Used kfree() instead of kfree_sensitive()
- Avoided unusal C syntax by accessing the hint vector via 'u8 *'
- Reworked use_hint() to be better optimized and documented
Eric Biggers (2):
lib/crypto: Add ML-DSA verification support lib/crypto: tests: Add KUnit tests for ML-DSA verification
include/crypto/mldsa.h | 60 + lib/crypto/Kconfig | 7 + lib/crypto/Makefile | 5 + lib/crypto/mldsa.c | 652 ++++++++++ lib/crypto/tests/Kconfig | 9 + lib/crypto/tests/Makefile | 1 + lib/crypto/tests/mldsa-testvecs.h | 1887 +++++++++++++++++++++++++++++ lib/crypto/tests/mldsa_kunit.c | 438 +++++++ 8 files changed, 3059 insertions(+) create mode 100644 include/crypto/mldsa.h create mode 100644 lib/crypto/mldsa.c create mode 100644 lib/crypto/tests/mldsa-testvecs.h create mode 100644 lib/crypto/tests/mldsa_kunit.c
base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8
Signature · 1 line
2.52.0
Eric Biggers
maintainerPATCH v4 1/2 lib/crypto: Add ML-DSA verification support
Add support for verifying ML-DSA signatures.
ML-DSA (Module-Lattice-Based Digital Signature Algorithm) is specified in FIPS 204 and is the standard version of Dilithium. Unlike RSA and elliptic-curve cryptography, ML-DSA is believed to be secure even against adversaries in possession of a large-scale quantum computer.
Compared to the earlier patch
(https://lore.kernel.org/r/[email protected]/)
that was based on "leancrypto", this implementation:
- Is about 700 lines of source code instead of 4800.
- Generates about 4 KB of object code instead of 28 KB.
- Uses 9-13 KB of memory to verify a signature instead of 31-84 KB.
- Is at least about the same speed, with a microbenchmark showing 3-5% improvements on one x86_64 CPU and -1% to 1% changes on another. When memory is a bottleneck, it's likely much faster.
- Correctly implements the RejNTTPoly step of the algorithm.
The API just consists of a single function mldsa_verify(), supporting pure ML-DSA with any standard parameter set (ML-DSA-44, ML-DSA-65, or ML-DSA-87) as selected by an enum. That's all that's actually needed.
The following four potential features are unneeded and aren't included. However, any that ever become needed could fairly easily be added later, as they only affect how the message representative mu is calculated:
- Nonempty context strings
- Incremental message hashing
- HashML-DSA
- External mu
Signing support would, of course, be a larger and more complex addition. However, the kernel doesn't, and shouldn't, need ML-DSA signing support.
Note that mldsa_verify() allocates memory, so it can sleep and can fail with ENOMEM. Unfortunately we don't have much choice about that, since ML-DSA needs a lot of memory. At least callers have to check for errors anyway, since the signature could be invalid.
Note that verification doesn't require constant-time code, and in fact some steps are inherently variable-time. I've used constant-time patterns in some places anyway, but technically they're not needed.
--- include/crypto/mldsa.h | 60 ++++ lib/crypto/Kconfig | 7 + lib/crypto/Makefile | 5 + lib/crypto/mldsa.c | 652 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 724 insertions(+) create mode 100644 include/crypto/mldsa.h create mode 100644 lib/crypto/mldsa.c
include/crypto/mldsa.h new file +60 -0
@@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Support for verifying ML-DSA signatures +* +* Copyright 2025 Google LLC +*/ +#ifndef _CRYPTO_MLDSA_H +#define _CRYPTO_MLDSA_H + +#include <linux/types.h> + +/* Identifier for an ML-DSA parameter set */ +enum mldsa_alg { +MLDSA44 ,/* ML-DSA-44 */ +MLDSA65 ,/* ML-DSA-65 */ +MLDSA87 ,/* ML-DSA-87 */ +}; + +/* Lengths of ML-DSA public keys and signatures in bytes */ +#define MLDSA44_PUBLIC_KEY_SIZE 1312 +#define MLDSA65_PUBLIC_KEY_SIZE 1952 +#define MLDSA87_PUBLIC_KEY_SIZE 2592 +#define MLDSA44_SIGNATURE_SIZE 2420 +#define MLDSA65_SIGNATURE_SIZE 3309 +#define MLDSA87_SIGNATURE_SIZE 4627 + +/** +* mldsa_verify() - Verify an ML-DSA signature +* @alg: The ML-DSA parameter set to use +* @sig: The signature +* @sig_len: Length of the signature in bytes. Should match the +* MLDSA*_SIGNATURE_SIZE constant associated with @alg, +* otherwise -EBADMSG will be returned. +* @msg: The message +* @msg_len: Length of the message in bytes +* @pk: The public key +* @pk_len: Length of the public key in bytes. Should match the +* MLDSA*_PUBLIC_KEY_SIZE constant associated with @alg, +* otherwise -EBADMSG will be returned. +* +* This verifies a signature using pure ML-DSA with the specified parameter set. +* The context string is assumed to be empty. +* +* Context: Might sleep +* +* Return: +* * 0 if the signature is valid +* * -EBADMSG if the signature and/or public key is malformed +* * -EKEYREJECTED if the signature is invalid but otherwise well-formed +* * -ENOMEM if out of memory so the validity of the signature is unknown +*/ +int mldsa_verify (enum mldsa_alg alg,const u8 *sig,size_t sig_len, +const u8 *msg,size_t msg_len,const u8 *pk,size_t pk_len); + +#if IS_ENABLED (CONFIG_CRYPTO_LIB_MLDSA_KUNIT_TEST ) +/* Internal function, exposed only for unit testing */ +s32 mldsa_use_hint (u8 h,s32 r,s32 gamma2); +#endif + +#endif /* _CRYPTO_MLDSA_H */
lib/crypto/Kconfig +7 -0
@@ -99,10 +99,17 @@ config CRYPTO_LIB_MD5_ARCH depends on CRYPTO_LIB_MD5 && !UML default y if MIPS && CPU_CAVIUM_OCTEON default y if PPC default y if SPARC64 +config CRYPTO_LIB_MLDSA + tristate + select CRYPTO_LIB_SHA3 + help + The ML-DSA library functions. Select this if your module uses any of + the functions from <crypto/mldsa.h>. + config CRYPTO_LIB_POLY1305 tristate help The Poly1305 library functions. Select this if your module uses any of the functions from <crypto/poly1305.h>.
lib/crypto/Makefile +5 -0
@@ -124,10 +124,15 @@ libmd5-$(CONFIG_PPC) += powerpc/md5-asm.o libmd5-$(CONFIG_SPARC) += sparc/md5_asm.o endif # CONFIG_CRYPTO_LIB_MD5_ARCH ################################################################################ +obj-$(CONFIG_CRYPTO_LIB_MLDSA) += libmldsa.o +libmldsa-y := mldsa.o + +################################################################################ + obj-$(CONFIG_CRYPTO_LIB_POLY1305) += libpoly1305.o libpoly1305-y := poly1305.o ifeq ($(CONFIG_ARCH_SUPPORTS_INT128),y) libpoly1305-$(CONFIG_CRYPTO_LIB_POLY1305_GENERIC) += poly1305-donna64.o else
lib/crypto/mldsa.c new file +652 -0
652 lines not on this page · raw message
Signature · 1 line
2.52.0
Eric Biggers
maintainerPATCH v4 2/2 lib/crypto: tests: Add KUnit tests for ML-DSA verification
In reply to Eric BiggersAdd 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.
--- lib/crypto/tests/Kconfig | 9 + lib/crypto/tests/Makefile | 1 + lib/crypto/tests/mldsa-testvecs.h | 1887 +++++++++++++++++++++++++++++ lib/crypto/tests/mldsa_kunit.c | 438 +++++++ 4 files changed, 2335 insertions(+) create mode 100644 lib/crypto/tests/mldsa-testvecs.h create mode 100644 lib/crypto/tests/mldsa_kunit.c
lib/crypto/tests/Kconfig +9 -0
@@ -36,10 +36,19 @@ config CRYPTO_LIB_MD5_KUNIT_TEST select CRYPTO_LIB_MD5 help KUnit tests for the MD5 cryptographic hash function and its corresponding HMAC. +config CRYPTO_LIB_MLDSA_KUNIT_TEST + tristate "KUnit tests for ML-DSA" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS + select CRYPTO_LIB_BENCHMARK_VISIBLE + select CRYPTO_LIB_MLDSA + help + KUnit tests for the ML-DSA digital signature algorithm. + config CRYPTO_LIB_POLY1305_KUNIT_TEST tristate "KUnit tests for Poly1305" if !KUNIT_ALL_TESTS depends on KUNIT default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS select CRYPTO_LIB_BENCHMARK_VISIBLE
lib/crypto/tests/Makefile +1 -0
@@ -2,10 +2,11 @@ obj-$(CONFIG_CRYPTO_LIB_BLAKE2B_KUNIT_TEST) += blake2b_kunit.o obj-$(CONFIG_CRYPTO_LIB_BLAKE2S_KUNIT_TEST) += blake2s_kunit.o obj-$(CONFIG_CRYPTO_LIB_CURVE25519_KUNIT_TEST) += curve25519_kunit.o obj-$(CONFIG_CRYPTO_LIB_MD5_KUNIT_TEST) += md5_kunit.o +obj-$(CONFIG_CRYPTO_LIB_MLDSA_KUNIT_TEST) += mldsa_kunit.o obj-$(CONFIG_CRYPTO_LIB_POLY1305_KUNIT_TEST) += poly1305_kunit.o obj-$(CONFIG_CRYPTO_LIB_POLYVAL_KUNIT_TEST) += polyval_kunit.o obj-$(CONFIG_CRYPTO_LIB_SHA1_KUNIT_TEST) += sha1_kunit.o obj-$(CONFIG_CRYPTO_LIB_SHA256_KUNIT_TEST) += sha224_kunit.o sha256_kunit.o obj-$(CONFIG_CRYPTO_LIB_SHA512_KUNIT_TEST) += sha384_kunit.o sha512_kunit.o
lib/crypto/tests/mldsa-testvecs.h new file +1887 -0
1,887 lines not on this page · raw message
lib/crypto/tests/mldsa_kunit.c new file +438 -0
438 lines not on this page · raw message
Signature · 1 line
2.52.0
Re: [PATCH v4 2/2] lib/crypto: tests: Add KUnit tests for ML-DSA verification
Hi Eric,
CC kunit
Quoted 24 lines · Eric Biggers
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 functionuse_hint()
- A benchmarkML-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.
Quoted 8 lines
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 <[email protected]>Tested-by David Howells <[email protected]>Signed-off-by Eric Biggers <[email protected]>
Thanks for your patch, which is now commit ed894faccb8de55c ("lib/crypto: tests: Add KUnit tests for ML-DSA verification") in v7.0-rc1.
Quoted 4 lines
lib/crypto/tests/Kconfig +0
-0@@ -36,10 +36,19 @@ config CRYPTO_LIB_MD5_KUNIT_TEST select CRYPTO_LIB_MD5
lib/crypto/tests/Kconfig config CRYPTO_LIB_MD5_KUNIT_TEST · line 46
Quoted 10 lines
lib/crypto/tests/Kconfig +6
-0help KUnit tests for the MD5 cryptographic hash function and its corresponding HMAC. +config CRYPTO_LIB_MLDSA_KUNIT_TEST + tristate "KUnit tests for ML-DSA" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS + select CRYPTO_LIB_BENCHMARK_VISIBLE + select CRYPTO_LIB_MLDSA
These two selects mean that enabling KUNIT_ALL_TESTS also enables extra functionality, which may not be desirable in a production system. Fortunately CRYPTO_LIB_MLDSA is tristate, so in the modular case the extra functionality is a module, too, and not part of the running system by default. Unfortunately CRYPTO_LIB_MLDSA is invisible, so this cannot just be changed from "select" to "depends on". But as CRYPTO_MLDSA also selects it, perhaps the test can be made dependent on CRYPTO_MLDSA?
lib/crypto/tests/Kconfig config CRYPTO_LIB_MD5_KUNIT_TEST · line 54
Quoted 8 lines
lib/crypto/tests/Kconfig +3
-0+ help + KUnit tests for the ML-DSA digital signature algorithm. + config CRYPTO_LIB_POLY1305_KUNIT_TEST tristate "KUnit tests for Poly1305" if !KUNIT_ALL_TESTS depends on KUNIT default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS select CRYPTO_LIB_BENCHMARK_VISIBLE
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Eric Biggers
maintainerRe: [PATCH v4 2/2] lib/crypto: tests: Add KUnit tests for ML-DSA verification
Quoted 46 lines · Geert Uytterhoeven
Quoted 24 lines · Eric Biggers
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 functionuse_hint()
- A benchmarkML-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.Quoted 8 lines
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 <[email protected]>Tested-by David Howells <[email protected]>Signed-off-by Eric Biggers <[email protected]>Thanks for your patch, which is now commit
ed894faccb8de55c("lib/crypto: tests: Add KUnit tests for ML-DSA verification") in v7.0-rc1.Quoted 8 lines
lib/crypto/tests/Kconfig +0
-0@@ -36,10 +36,19 @@ config CRYPTO_LIB_MD5_KUNIT_TEST select CRYPTO_LIB_MD5 help KUnit tests for the MD5 cryptographic hash function and its corresponding HMAC.
Quoted 14 lines
lib/crypto/tests/Kconfig config CRYPTO_LIB_MD5_KUNIT_TEST · line 46
Quoted 6 lines
lib/crypto/tests/Kconfig +6
-0+config CRYPTO_LIB_MLDSA_KUNIT_TEST + tristate "KUnit tests for ML-DSA" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS + select CRYPTO_LIB_BENCHMARK_VISIBLE + select CRYPTO_LIB_MLDSAThese two selects mean that enabling
KUNIT_ALL_TESTSalso enables extra functionality, which may not be desirable in a production system. FortunatelyCRYPTO_LIB_MLDSAis tristate, so in the modular case the extra functionality is a module, too, and not part of the running system by default. UnfortunatelyCRYPTO_LIB_MLDSAis invisible, so this cannot just be changed from "select" to "depends on". But asCRYPTO_MLDSAalso selects it, perhaps the test can be made dependent onCRYPTO_MLDSA?
"depends on CRYPTO_MLDSA" doesn't make sense, since the test is for the code in CRYPTO_LIB_MLDSA, not CRYPTO_MLDSA. CRYPTO_MLDSA just happens to be one of the users of CRYPTO_LIB_MLDSA. In this case the names happen to be similar, but consider e.g. CRYPTO_LIB_AESGCM which is selected by AMD_MEM_ENCRYPT. If we added a test for CRYPTO_LIB_AESGCM, it clearly shouldn't use "depends on AMD_MEM_ENCRYPT".
So, "depends on CRYPTO_LIB_MLDSA" would be the correct way to switch it from a selection to a dependency.
It's just a bit annoying to do this for hidden symbols, given that it makes it so that anyone who wants to unconditionally enable the test, like what I do to test all the crypto library code, has to find and enable some other random kconfig symbol that enables the code.
Also, the series that originally added CRYPTO_LIB_MLDSA and its test
(https://lore.kernel.org/linux-crypto/[email protected]/)
didn't add any user of CRYPTO_LIB_MLDSA besides the test, as the real user came a bit later. So if I had used "depends on CRYPTO_LIB_MLDSA", my series wouldn't have received any build bot coverage, and I'd have needed to temporarily carry local patches to build and test the code.
But if this is really the convention for KUnit, as it seems to be, I will follow it and work around it for my own testing. So I'll plan to change the crypto library and CRC tests to use "depends on".
But any thoughts from the KUnit maintainers would also be appreciated. Is it indeed intended that the tests for library modules depend on those modules rather than selecting them, despite their symbols being hidden?
- Eric
Eric Biggers
maintainerRe: [PATCH v4 2/2] lib/crypto: tests: Add KUnit tests for ML-DSA verification
Quoted 84 lines · Eric Biggers
Quoted 46 lines · Geert Uytterhoeven
Quoted 24 lines · Eric Biggers
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 functionuse_hint()
- A benchmarkML-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.Quoted 8 lines
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 <[email protected]>Tested-by David Howells <[email protected]>Signed-off-by Eric Biggers <[email protected]>Thanks for your patch, which is now commit
ed894faccb8de55c("lib/crypto: tests: Add KUnit tests for ML-DSA verification") in v7.0-rc1.Quoted 8 lines
lib/crypto/tests/Kconfig +0
-0@@ -36,10 +36,19 @@ config CRYPTO_LIB_MD5_KUNIT_TEST select CRYPTO_LIB_MD5 help KUnit tests for the MD5 cryptographic hash function and its corresponding HMAC.Quoted 14 lines
lib/crypto/tests/Kconfig config CRYPTO_LIB_MD5_KUNIT_TEST · line 46
Quoted 6 lines
lib/crypto/tests/Kconfig +6
-0+config CRYPTO_LIB_MLDSA_KUNIT_TEST + tristate "KUnit tests for ML-DSA" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS + select CRYPTO_LIB_BENCHMARK_VISIBLE + select CRYPTO_LIB_MLDSAThese two selects mean that enabling
KUNIT_ALL_TESTSalso enables extra functionality, which may not be desirable in a production system. FortunatelyCRYPTO_LIB_MLDSAis tristate, so in the modular case the extra functionality is a module, too, and not part of the running system by default. UnfortunatelyCRYPTO_LIB_MLDSAis invisible, so this cannot just be changed from "select" to "depends on". But asCRYPTO_MLDSAalso selects it, perhaps the test can be made dependent onCRYPTO_MLDSA?"depends on
CRYPTO_MLDSA" doesn't make sense, since the test is for the code inCRYPTO_LIB_MLDSA, notCRYPTO_MLDSA.CRYPTO_MLDSAjust happens to be one of the users ofCRYPTO_LIB_MLDSA. In this case the names happen to be similar, but consider e.g.CRYPTO_LIB_AESGCMwhich is selected byAMD_MEM_ENCRYPT. If we added a test forCRYPTO_LIB_AESGCM, it clearly shouldn't use "depends onAMD_MEM_ENCRYPT".So, "depends on
CRYPTO_LIB_MLDSA" would be the correct way to switch it from a selection to a dependency.It's just a bit annoying to do this for hidden symbols, given that it makes it so that anyone who wants to unconditionally enable the test, like what I do to test all the crypto library code, has to find and enable some other random kconfig symbol that enables the code.
Also, the series that originally added
CRYPTO_LIB_MLDSAand its test
(https://lore.kernel.org/linux-crypto/[email protected]/)
didn't add any user ofCRYPTO_LIB_MLDSAbesides the test, as the real user came a bit later. So if I had used "depends onCRYPTO_LIB_MLDSA", my series wouldn't have received any build bot coverage, and I'd have needed to temporarily carry local patches to build and test the code.
Quoted 7 lines
But if this is really the convention for KUnit, as it seems to be, I will follow it and work around it for my own testing. So I'll plan to change the crypto library and CRC tests to use "depends on".
But any thoughts from the KUnit maintainers would also be appreciated. Is it indeed intended that the tests for library modules depend on those modules rather than selecting them, despite their symbols being hidden?
I sent the following patch to consider:
https://lore.kernel.org/linux-crypto/[email protected]/
- Eric
Quoted 8 lines · Eric Biggers
This series can also be retrieved from:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git mldsa-v4
This series adds support for verifying ML-DSA signatures to
lib/crypto/. Patch 1 is the ML-DSA implementation itself. See that for full details. Patch 2 adds the KUnit test suite.
Quoted 5 lines
The initial use case for this will be kernel module signature verification. For more details, see David Howells' patchset
https://lore.kernel.org/linux-crypto/[email protected]/Note: I'm planning to apply this to libcrypto-next for 6.20.
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/log/?h=libcrypto-next
- Eric