Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: 4dcf6caddaa0 ("lib/crypto: tests: Add KUnit tests for SHA-224 and SHA-256")
Fixes: 571eaeddb67d ("lib/crypto: tests: Add KUnit tests for SHA-384 and SHA-512")
Fixes: 6dd4d9f7919e ("lib/crypto: tests: Add KUnit tests for Poly1305")
Fixes: 66b130607908 ("lib/crypto: tests: Add KUnit tests for SHA-1 and HMAC-SHA1")
Fixes: d6b6aac0cdb4 ("lib/crypto: tests: Add KUnit tests for MD5 and HMAC-MD5")
Fixes: afc4e4a5f122 ("lib/crypto: tests: Migrate Curve25519 self-test to KUnit")
Fixes: 6401fd334ddf ("lib/crypto: tests: Add KUnit tests for BLAKE2b")
Fixes: 15c64c47e484 ("lib/crypto: tests: Add SHA3 kunit tests")
Fixes: b3aed551b3fc ("lib/crypto: tests: Add KUnit tests for POLYVAL")
Fixes: ed894faccb8d ("lib/crypto: tests: Add KUnit tests for ML-DSA verification")
Fixes: 7246fe6cd644 ("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>

+12 -23
+12 -23
lib/crypto/tests/Kconfig
··· 2 2 3 3 config CRYPTO_LIB_BLAKE2B_KUNIT_TEST 4 4 tristate "KUnit tests for BLAKE2b" if !KUNIT_ALL_TESTS 5 - depends on KUNIT 5 + depends on KUNIT && CRYPTO_LIB_BLAKE2B 6 6 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 7 7 select CRYPTO_LIB_BENCHMARK_VISIBLE 8 - select CRYPTO_LIB_BLAKE2B 9 8 help 10 9 KUnit tests for the BLAKE2b cryptographic hash function. 11 10 ··· 13 14 depends on KUNIT 14 15 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 15 16 select CRYPTO_LIB_BENCHMARK_VISIBLE 16 - # No need to select CRYPTO_LIB_BLAKE2S here, as that option doesn't 17 + # No need to depend on CRYPTO_LIB_BLAKE2S here, as that option doesn't 17 18 # exist; the BLAKE2s code is always built-in for the /dev/random driver. 18 19 help 19 20 KUnit tests for the BLAKE2s cryptographic hash function. 20 21 21 22 config CRYPTO_LIB_CURVE25519_KUNIT_TEST 22 23 tristate "KUnit tests for Curve25519" if !KUNIT_ALL_TESTS 23 - depends on KUNIT 24 + depends on KUNIT && CRYPTO_LIB_CURVE25519 24 25 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 25 26 select CRYPTO_LIB_BENCHMARK_VISIBLE 26 - select CRYPTO_LIB_CURVE25519 27 27 help 28 28 KUnit tests for the Curve25519 Diffie-Hellman function. 29 29 30 30 config CRYPTO_LIB_MD5_KUNIT_TEST 31 31 tristate "KUnit tests for MD5" if !KUNIT_ALL_TESTS 32 - depends on KUNIT 32 + depends on KUNIT && CRYPTO_LIB_MD5 33 33 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 34 34 select CRYPTO_LIB_BENCHMARK_VISIBLE 35 - select CRYPTO_LIB_MD5 36 35 help 37 36 KUnit tests for the MD5 cryptographic hash function and its 38 37 corresponding HMAC. 39 38 40 39 config CRYPTO_LIB_MLDSA_KUNIT_TEST 41 40 tristate "KUnit tests for ML-DSA" if !KUNIT_ALL_TESTS 42 - depends on KUNIT 41 + depends on KUNIT && CRYPTO_LIB_MLDSA 43 42 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 44 43 select CRYPTO_LIB_BENCHMARK_VISIBLE 45 - select CRYPTO_LIB_MLDSA 46 44 help 47 45 KUnit tests for the ML-DSA digital signature algorithm. 48 46 49 47 config CRYPTO_LIB_NH_KUNIT_TEST 50 48 tristate "KUnit tests for NH" if !KUNIT_ALL_TESTS 51 - depends on KUNIT 49 + depends on KUNIT && CRYPTO_LIB_NH 52 50 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 53 - select CRYPTO_LIB_NH 54 51 help 55 52 KUnit tests for the NH almost-universal hash function. 56 53 57 54 config CRYPTO_LIB_POLY1305_KUNIT_TEST 58 55 tristate "KUnit tests for Poly1305" if !KUNIT_ALL_TESTS 59 - depends on KUNIT 56 + depends on KUNIT && CRYPTO_LIB_POLY1305 60 57 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 61 58 select CRYPTO_LIB_BENCHMARK_VISIBLE 62 - select CRYPTO_LIB_POLY1305 63 59 help 64 60 KUnit tests for the Poly1305 library functions. 65 61 66 62 config CRYPTO_LIB_POLYVAL_KUNIT_TEST 67 63 tristate "KUnit tests for POLYVAL" if !KUNIT_ALL_TESTS 68 - depends on KUNIT 64 + depends on KUNIT && CRYPTO_LIB_POLYVAL 69 65 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 70 66 select CRYPTO_LIB_BENCHMARK_VISIBLE 71 - select CRYPTO_LIB_POLYVAL 72 67 help 73 68 KUnit tests for the POLYVAL library functions. 74 69 75 70 config CRYPTO_LIB_SHA1_KUNIT_TEST 76 71 tristate "KUnit tests for SHA-1" if !KUNIT_ALL_TESTS 77 - depends on KUNIT 72 + depends on KUNIT && CRYPTO_LIB_SHA1 78 73 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 79 74 select CRYPTO_LIB_BENCHMARK_VISIBLE 80 - select CRYPTO_LIB_SHA1 81 75 help 82 76 KUnit tests for the SHA-1 cryptographic hash function and its 83 77 corresponding HMAC. ··· 79 87 # included, for consistency with the naming used elsewhere (e.g. CRYPTO_SHA256). 80 88 config CRYPTO_LIB_SHA256_KUNIT_TEST 81 89 tristate "KUnit tests for SHA-224 and SHA-256" if !KUNIT_ALL_TESTS 82 - depends on KUNIT 90 + depends on KUNIT && CRYPTO_LIB_SHA256 83 91 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 84 92 select CRYPTO_LIB_BENCHMARK_VISIBLE 85 - select CRYPTO_LIB_SHA256 86 93 help 87 94 KUnit tests for the SHA-224 and SHA-256 cryptographic hash functions 88 95 and their corresponding HMACs. ··· 90 99 # included, for consistency with the naming used elsewhere (e.g. CRYPTO_SHA512). 91 100 config CRYPTO_LIB_SHA512_KUNIT_TEST 92 101 tristate "KUnit tests for SHA-384 and SHA-512" if !KUNIT_ALL_TESTS 93 - depends on KUNIT 102 + depends on KUNIT && CRYPTO_LIB_SHA512 94 103 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 95 104 select CRYPTO_LIB_BENCHMARK_VISIBLE 96 - select CRYPTO_LIB_SHA512 97 105 help 98 106 KUnit tests for the SHA-384 and SHA-512 cryptographic hash functions 99 107 and their corresponding HMACs. 100 108 101 109 config CRYPTO_LIB_SHA3_KUNIT_TEST 102 110 tristate "KUnit tests for SHA-3" if !KUNIT_ALL_TESTS 103 - depends on KUNIT 111 + depends on KUNIT && CRYPTO_LIB_SHA3 104 112 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 105 113 select CRYPTO_LIB_BENCHMARK_VISIBLE 106 - select CRYPTO_LIB_SHA3 107 114 help 108 115 KUnit tests for the SHA3 cryptographic hash and XOF functions, 109 116 including SHA3-224, SHA3-256, SHA3-384, SHA3-512, SHAKE128 and