Commit afc4e4a5 authored by Eric Biggers's avatar Eric Biggers
Browse files

lib/crypto: tests: Migrate Curve25519 self-test to KUnit

Move the Curve25519 test from an ad-hoc self-test to a KUnit test.

Generally keep the same test logic for now, just translated to KUnit.
There's one exception, which is that I dropped the incomplete test of
curve25519_generic().  The approach I'm taking to cover the different
implementations with the KUnit tests is to just rely on booting kernels
in QEMU with different '-cpu' options, rather than try to make the tests
(incompletely) test multiple implementations on one CPU.  This way, both
the test and the library API are simpler.

This commit makes the file lib/crypto/curve25519.c no longer needed, as
its only purpose was to call the self-test.  However, keep it for now,
since a later commit will add code to it again.

Temporarily omit the default value of CRYPTO_SELFTESTS that the other
lib/crypto/ KUnit tests have.  It would cause a recursive kconfig
dependency, since the Curve25519 code is still entangled with CRYPTO.  A
later commit will fix that.

Link: https://lore.kernel.org/r/20250906213523.84915-8-ebiggers@kernel.org


Signed-off-by: default avatarEric Biggers <ebiggers@kernel.org>
parent 09e7652d
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -28,8 +28,6 @@ void curve25519_arch(u8 out[CURVE25519_KEY_SIZE],
void curve25519_base_arch(u8 pub[CURVE25519_KEY_SIZE],
			  const u8 secret[CURVE25519_KEY_SIZE]);

bool curve25519_selftest(void);

static inline
bool __must_check curve25519(u8 mypublic[CURVE25519_KEY_SIZE],
			     const u8 secret[CURVE25519_KEY_SIZE],
+0 −1
Original line number Diff line number Diff line
@@ -87,7 +87,6 @@ endif

obj-$(CONFIG_CRYPTO_LIB_CURVE25519)		+= libcurve25519.o
libcurve25519-y					+= curve25519.o
libcurve25519-$(CONFIG_CRYPTO_SELFTESTS)	+= curve25519-selftest.o

obj-$(CONFIG_CRYPTO_LIB_DES)			+= libdes.o
libdes-y					:= des.o
+0 −3
Original line number Diff line number Diff line
@@ -15,9 +15,6 @@

static int __init curve25519_init(void)
{
	if (IS_ENABLED(CONFIG_CRYPTO_SELFTESTS) &&
	    WARN_ON(!curve25519_selftest()))
		return -ENODEV;
	return 0;
}

+9 −0
Original line number Diff line number Diff line
@@ -10,6 +10,15 @@ config CRYPTO_LIB_BLAKE2S_KUNIT_TEST
	help
	  KUnit tests for the BLAKE2s cryptographic hash function.

config CRYPTO_LIB_CURVE25519_KUNIT_TEST
	tristate "KUnit tests for Curve25519" if !KUNIT_ALL_TESTS
	depends on KUNIT
	default KUNIT_ALL_TESTS
	select CRYPTO_LIB_BENCHMARK_VISIBLE
	select CRYPTO_LIB_CURVE25519
	help
	  KUnit tests for the Curve25519 Diffie-Hellman function.

config CRYPTO_LIB_MD5_KUNIT_TEST
	tristate "KUnit tests for MD5" if !KUNIT_ALL_TESTS
	depends on KUNIT
+1 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: GPL-2.0-or-later

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_POLY1305_KUNIT_TEST) += poly1305_kunit.o
obj-$(CONFIG_CRYPTO_LIB_SHA1_KUNIT_TEST) += sha1_kunit.o
Loading