Skip to content

Commit 4478e8e

Browse files
author
Eric Biggers
committed
lib/crypto: tests: Depend on library options rather than selecting them
The convention for KUnit tests is to have the test kconfig options visible only when the code they depend on is already enabled. This way only the tests that are relevant to the particular kernel build can be enabled, either manually or via KUNIT_ALL_TESTS. Update lib/crypto/tests/Kconfig to follow that convention, i.e. depend on the corresponding library options rather than selecting them. This fixes an issue where enabling KUNIT_ALL_TESTS enabled non-test code. This does mean that it becomes a bit more difficult to enable *all* the crypto library tests (which is what I do as a maintainer of the code), since doing so will now require enabling other options that select the libraries. Regardless, we should follow the standard KUnit convention. I'll also add a .kunitconfig file that does enable all these options. Note: currently most of the crypto library options are selected by visible options in crypto/Kconfig, which can be used to enable them without too much trouble. If in the future we end up with more cases like CRYPTO_LIB_CURVE25519 which is selected only by WIREGUARD (thus making CRYPTO_LIB_CURVE25519_KUNIT_TEST effectively depend on WIREGUARD after this commit), we could consider adding a new kconfig option that enables all the library code specifically for testing. Reported-by: Geert Uytterhoeven <geert@linux-m68k.org> Closes: https://lore.kernel.org/r/CAMuHMdULzMdxuTVfg8_4jdgzbzjfx-PHkcgbGSthcUx_sHRNMg@mail.gmail.com Fixes: 4dcf6ca ("lib/crypto: tests: Add KUnit tests for SHA-224 and SHA-256") Fixes: 571eaed ("lib/crypto: tests: Add KUnit tests for SHA-384 and SHA-512") Fixes: 6dd4d9f ("lib/crypto: tests: Add KUnit tests for Poly1305") Fixes: 66b1306 ("lib/crypto: tests: Add KUnit tests for SHA-1 and HMAC-SHA1") Fixes: d6b6aac ("lib/crypto: tests: Add KUnit tests for MD5 and HMAC-MD5") Fixes: afc4e4a ("lib/crypto: tests: Migrate Curve25519 self-test to KUnit") Fixes: 6401fd3 ("lib/crypto: tests: Add KUnit tests for BLAKE2b") Fixes: 15c64c4 ("lib/crypto: tests: Add SHA3 kunit tests") Fixes: b3aed55 ("lib/crypto: tests: Add KUnit tests for POLYVAL") Fixes: ed894fa ("lib/crypto: tests: Add KUnit tests for ML-DSA verification") Fixes: 7246fe6 ("lib/crypto: tests: Add KUnit tests for NH") Cc: stable@vger.kernel.org Reviewed-by: David Gow <david@davidgow.net> Acked-by: Ard Biesheuvel <ardb@kernel.org> Link: https://lore.kernel.org/r/20260226191749.39397-1-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
1 parent 201ceb9 commit 4478e8e

1 file changed

Lines changed: 12 additions & 23 deletions

File tree

lib/crypto/tests/Kconfig

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
config CRYPTO_LIB_BLAKE2B_KUNIT_TEST
44
tristate "KUnit tests for BLAKE2b" if !KUNIT_ALL_TESTS
5-
depends on KUNIT
5+
depends on KUNIT && CRYPTO_LIB_BLAKE2B
66
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
77
select CRYPTO_LIB_BENCHMARK_VISIBLE
8-
select CRYPTO_LIB_BLAKE2B
98
help
109
KUnit tests for the BLAKE2b cryptographic hash function.
1110

@@ -14,71 +13,64 @@ config CRYPTO_LIB_BLAKE2S_KUNIT_TEST
1413
depends on KUNIT
1514
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
1615
select CRYPTO_LIB_BENCHMARK_VISIBLE
17-
# No need to select CRYPTO_LIB_BLAKE2S here, as that option doesn't
16+
# No need to depend on CRYPTO_LIB_BLAKE2S here, as that option doesn't
1817
# exist; the BLAKE2s code is always built-in for the /dev/random driver.
1918
help
2019
KUnit tests for the BLAKE2s cryptographic hash function.
2120

2221
config CRYPTO_LIB_CURVE25519_KUNIT_TEST
2322
tristate "KUnit tests for Curve25519" if !KUNIT_ALL_TESTS
24-
depends on KUNIT
23+
depends on KUNIT && CRYPTO_LIB_CURVE25519
2524
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
2625
select CRYPTO_LIB_BENCHMARK_VISIBLE
27-
select CRYPTO_LIB_CURVE25519
2826
help
2927
KUnit tests for the Curve25519 Diffie-Hellman function.
3028

3129
config CRYPTO_LIB_MD5_KUNIT_TEST
3230
tristate "KUnit tests for MD5" if !KUNIT_ALL_TESTS
33-
depends on KUNIT
31+
depends on KUNIT && CRYPTO_LIB_MD5
3432
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
3533
select CRYPTO_LIB_BENCHMARK_VISIBLE
36-
select CRYPTO_LIB_MD5
3734
help
3835
KUnit tests for the MD5 cryptographic hash function and its
3936
corresponding HMAC.
4037

4138
config CRYPTO_LIB_MLDSA_KUNIT_TEST
4239
tristate "KUnit tests for ML-DSA" if !KUNIT_ALL_TESTS
43-
depends on KUNIT
40+
depends on KUNIT && CRYPTO_LIB_MLDSA
4441
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
4542
select CRYPTO_LIB_BENCHMARK_VISIBLE
46-
select CRYPTO_LIB_MLDSA
4743
help
4844
KUnit tests for the ML-DSA digital signature algorithm.
4945

5046
config CRYPTO_LIB_NH_KUNIT_TEST
5147
tristate "KUnit tests for NH" if !KUNIT_ALL_TESTS
52-
depends on KUNIT
48+
depends on KUNIT && CRYPTO_LIB_NH
5349
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
54-
select CRYPTO_LIB_NH
5550
help
5651
KUnit tests for the NH almost-universal hash function.
5752

5853
config CRYPTO_LIB_POLY1305_KUNIT_TEST
5954
tristate "KUnit tests for Poly1305" if !KUNIT_ALL_TESTS
60-
depends on KUNIT
55+
depends on KUNIT && CRYPTO_LIB_POLY1305
6156
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
6257
select CRYPTO_LIB_BENCHMARK_VISIBLE
63-
select CRYPTO_LIB_POLY1305
6458
help
6559
KUnit tests for the Poly1305 library functions.
6660

6761
config CRYPTO_LIB_POLYVAL_KUNIT_TEST
6862
tristate "KUnit tests for POLYVAL" if !KUNIT_ALL_TESTS
69-
depends on KUNIT
63+
depends on KUNIT && CRYPTO_LIB_POLYVAL
7064
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
7165
select CRYPTO_LIB_BENCHMARK_VISIBLE
72-
select CRYPTO_LIB_POLYVAL
7366
help
7467
KUnit tests for the POLYVAL library functions.
7568

7669
config CRYPTO_LIB_SHA1_KUNIT_TEST
7770
tristate "KUnit tests for SHA-1" if !KUNIT_ALL_TESTS
78-
depends on KUNIT
71+
depends on KUNIT && CRYPTO_LIB_SHA1
7972
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
8073
select CRYPTO_LIB_BENCHMARK_VISIBLE
81-
select CRYPTO_LIB_SHA1
8274
help
8375
KUnit tests for the SHA-1 cryptographic hash function and its
8476
corresponding HMAC.
@@ -87,10 +79,9 @@ config CRYPTO_LIB_SHA1_KUNIT_TEST
8779
# included, for consistency with the naming used elsewhere (e.g. CRYPTO_SHA256).
8880
config CRYPTO_LIB_SHA256_KUNIT_TEST
8981
tristate "KUnit tests for SHA-224 and SHA-256" if !KUNIT_ALL_TESTS
90-
depends on KUNIT
82+
depends on KUNIT && CRYPTO_LIB_SHA256
9183
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
9284
select CRYPTO_LIB_BENCHMARK_VISIBLE
93-
select CRYPTO_LIB_SHA256
9485
help
9586
KUnit tests for the SHA-224 and SHA-256 cryptographic hash functions
9687
and their corresponding HMACs.
@@ -99,20 +90,18 @@ config CRYPTO_LIB_SHA256_KUNIT_TEST
9990
# included, for consistency with the naming used elsewhere (e.g. CRYPTO_SHA512).
10091
config CRYPTO_LIB_SHA512_KUNIT_TEST
10192
tristate "KUnit tests for SHA-384 and SHA-512" if !KUNIT_ALL_TESTS
102-
depends on KUNIT
93+
depends on KUNIT && CRYPTO_LIB_SHA512
10394
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
10495
select CRYPTO_LIB_BENCHMARK_VISIBLE
105-
select CRYPTO_LIB_SHA512
10696
help
10797
KUnit tests for the SHA-384 and SHA-512 cryptographic hash functions
10898
and their corresponding HMACs.
10999

110100
config CRYPTO_LIB_SHA3_KUNIT_TEST
111101
tristate "KUnit tests for SHA-3" if !KUNIT_ALL_TESTS
112-
depends on KUNIT
102+
depends on KUNIT && CRYPTO_LIB_SHA3
113103
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
114104
select CRYPTO_LIB_BENCHMARK_VISIBLE
115-
select CRYPTO_LIB_SHA3
116105
help
117106
KUnit tests for the SHA3 cryptographic hash and XOF functions,
118107
including SHA3-224, SHA3-256, SHA3-384, SHA3-512, SHAKE128 and

0 commit comments

Comments
 (0)