Skip to contentSkip to conversation

lib/crypto: blake2s: Disable self test if CONFIG_CRYPTO isn't enabled

PATCH In review Daniel Palmer 2 participants 3 messages Apr 18, 2025 – Apr 20, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/crypto: blake2s: Disable self test if CONFIG_CRYPTO isn't enabled

From: Daniel Palmer <[email protected]>

Currently CONFIG_CRYPTO_MANAGER_DISABLE_TESTS is used to remove the self test code. CONFIG_CRYPTO_MANAGER_DISABLE_TESTS depends on CONFIG_CRYPTO so its impossible to disable the self test without enabling CONFIG_CRYPTO.

If you don't want CONFIG_CRYPTO you probably don't want self tests so remove the self tests in that case too.

Fixes 66d7fb94e4ff ("crypto: blake2s - generic C library implementation and selftest")
---
 lib/crypto/blake2s.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/crypto/blake2s.c +2 -1
index 71a316552cc5..89d54e462fb5 100644
@@ -60,7 +60,8 @@ EXPORT_SYMBOL(blake2s_final);
 
 static int __init blake2s_mod_init(void)
 {
-	if (!IS_ENABLED(CONFIG_CRYPTO_MANAGER_DISABLE_TESTS) &&
+	if (IS_ENABLED(CONFIG_CRYPTO) &&
+	    !IS_ENABLED(CONFIG_CRYPTO_MANAGER_DISABLE_TESTS) &&
 	    WARN_ON(!blake2s_selftest()))
 		return -ENODEV;
 	return 0;
Signature · 1 line
2.47.2
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Daniel Palmer

From: Daniel Palmer <[email protected]>

Currently CONFIG_CRYPTO_MANAGER_DISABLE_TESTS is used to remove the self test code. CONFIG_CRYPTO_MANAGER_DISABLE_TESTS depends on CONFIG_CRYPTO so its impossible to disable the self test without enabling CONFIG_CRYPTO.

If you don't want CONFIG_CRYPTO you probably don't want self tests so remove the self tests in that case too.

Quoted 6 lines
Fixes 66d7fb94e4ff ("crypto: blake2s - generic C library implementation and selftest")
---
 lib/crypto/blake2s.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

This is okay as a quick fix, but really the lib/crypto/ tests should be refactored into KUnit tests that aren't dependent on CRYPTO. FWIW, I recently fixed this for the CRC functions: lib/tests/crc_kunit.c.

- Eric

maintainer
#2 lore raw
Quoted 18 lines · Eric Biggers
Quoted 10 lines · Daniel Palmer

From: Daniel Palmer <[email protected]>

Currently CONFIG_CRYPTO_MANAGER_DISABLE_TESTS is used to remove the self test code. CONFIG_CRYPTO_MANAGER_DISABLE_TESTS depends on CONFIG_CRYPTO so its impossible to disable the self test without enabling CONFIG_CRYPTO.

If you don't want CONFIG_CRYPTO you probably don't want self tests so remove the self tests in that case too.

Quoted 6 lines
Fixes 66d7fb94e4ff ("crypto: blake2s - generic C library implementation and selftest")
---
 lib/crypto/blake2s.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 6 lines

This is okay as a quick fix, but really the lib/crypto/ tests should be refactored into KUnit tests that aren't dependent on CRYPTO. FWIW, I recently fixed this for the CRC functions: lib/tests/crc_kunit.c.

My series "[PATCH 0/9] Clean up the crypto testing options"
(https://lore.kernel.org/r/[email protected]/) also fixes this by replacing CRYPTO_MANAGER_DISABLE_TESTS with a non-negated option. (But we should still disentangle the library tests from CRYPTO at some point.)

- Eric