Skip to contentSkip to conversation

Add KUnit tests for curve25519

PATCH In review Enzo Bertoloti 2 participants 2 messages Dec 9, 2024 – Dec 10, 2024

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

PATCH 1/1 Add KUnit tests for curve25519

This test uses the curve25519-selftest data for testing the curve25519 arch, generic and the public key generation algorithms on a larger set using KUnit.
The comprises of normal, edge cases, valid, invalid results and others.

This is partially based on the existing curve25519 selftests in crypto/curve25519-selftest.c

---
Hi all,

We both are students starting out contributing with the Linux kernel. :) We noticed that the selftest is called in the curve25519.c implementation so we couldn't unify both files without changing it all, but the KUnit tests are working. We would love some suggestions on how to unify them.

---
 lib/crypto/.kunitconfig       |    3 +
 lib/crypto/Kconfig            |    8 +
 lib/crypto/Makefile           |    1 +
 lib/crypto/curve25519_kunit.c | 1356 +++++++++++++++++++++++++++++++++
 4 files changed, 1368 insertions(+)
 create mode 100644 lib/crypto/.kunitconfig
 create mode 100644 lib/crypto/curve25519_kunit.c
lib/crypto/.kunitconfig new file +3 -0
new file mode 100644
index 000000000000..fbdbdd1e8869
@@ -0,0 +1,3 @@
+CONFIG_KUNIT=y
+CONFIG_CRYPTO_LIB_CURVE25519=y
+CONFIG_CRYPTO_LIB_CURVE25519_KUNIT_TEST=y
lib/crypto/Kconfig +8 -0
index b01253cac70a..99bb8d0c3384 100644
@@ -93,6 +93,14 @@ config CRYPTO_LIB_CURVE25519
 	  fulfilled by either the generic implementation or an arch-specific
 	  one, if one is available and enabled.
 
+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_CURVE25519
+	help
+	  Enable this option to run KUnit tests for the curve25519 library.
+
 config CRYPTO_LIB_DES
 	tristate
 
lib/crypto/Makefile +1 -0
index 01fac1cd05a1..6ce6d0770f0c 100644
@@ -36,6 +36,7 @@ libcurve25519-generic-y				+= curve25519-generic.o
 
 obj-$(CONFIG_CRYPTO_LIB_CURVE25519)		+= libcurve25519.o
 libcurve25519-y					+= curve25519.o
+obj-$(CONFIG_CRYPTO_LIB_CURVE25519_KUNIT_TEST) += curve25519_kunit.o
 
 obj-$(CONFIG_CRYPTO_LIB_DES)			+= libdes.o
 libdes-y					:= des.o
lib/crypto/curve25519_kunit.c new file +1356 -0

1,356 lines not on this page · raw message

Signature · 1 line
2.47.1
maintainer
#1 lore raw
Quoted 7 lines · Enzo Bertoloti

This test uses the curve25519-selftest data for testing the curve25519 arch, generic and the public key generation algorithms on a larger set using KUnit.
The comprises of normal, edge cases, valid, invalid results and others.

This is partially based on the existing curve25519 selftests in crypto/curve25519-selftest.c

Please explain the difference between this and the existing selftest. Why do we need both of them?

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt