diff mbox series

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

Message ID 20250418120216.2968994-1-daniel@0x0f.com
State New
Headers show
Series lib/crypto: blake2s: Disable self test if CONFIG_CRYPTO isn't enabled | expand

Commit Message

Daniel Palmer April 18, 2025, 12:02 p.m. UTC
From: Daniel Palmer <daniel@thingy.jp>

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")

Signed-off-by: Daniel Palmer <daniel@thingy.jp>
---
 lib/crypto/blake2s.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Eric Biggers April 18, 2025, 2:59 p.m. UTC | #1
On Fri, Apr 18, 2025 at 09:02:16PM +0900, Daniel Palmer wrote:
> From: Daniel Palmer <daniel@thingy.jp>
> 
> 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")
> 
> Signed-off-by: Daniel Palmer <daniel@thingy.jp>
> ---
>  lib/crypto/blake2s.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Acked-by: Eric Biggers <ebiggers@kernel.org>

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
diff mbox series

Patch

diff --git a/lib/crypto/blake2s.c b/lib/crypto/blake2s.c
index 71a316552cc5..89d54e462fb5 100644
--- a/lib/crypto/blake2s.c
+++ b/lib/crypto/blake2s.c
@@ -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;