Skip to contentSkip to conversation

crypto: curve25519 - re-add selftests

PATCH In review Jason A. Donenfeld 2 participants 2 messages Dec 16, 2019 – Dec 27, 2019

Subsystems (2)
lore
Share & tools
lore

Jason A. Donenfeld

author maintainer
#0 lore raw

PATCH 1/1 crypto: curve25519 - re-add selftests

Somehow these were dropped when Zinc was being integrated, which is problematic, because testing the library interface for Curve25519 is important.. This commit simply adds them back and wires them in in the same way that the blake2s selftests are wired in.

---
 lib/crypto/Makefile              |    1 +
 lib/crypto/curve25519-selftest.c | 1321 ++++++++++++++++++++++++++++++
 lib/crypto/curve25519.c          |   17 +
 3 files changed, 1339 insertions(+)
 create mode 100644 lib/crypto/curve25519-selftest.c
lib/crypto/Makefile +1 -0
index d19e5195569e..6ecaf83a5a9a 100644
@@ -38,4 +38,5 @@ libsha256-y					:= sha256.o
 ifneq ($(CONFIG_CRYPTO_MANAGER_DISABLE_TESTS),y)
 libblake2s-y					+= blake2s-selftest.o
 libchacha20poly1305-y				+= chacha20poly1305-selftest.o
+libcurve25519-y					+= curve25519-selftest.o
 endif
lib/crypto/curve25519-selftest.c new file +1321 -0

1,321 lines not on this page · raw message

lib/crypto/curve25519.c +17 -0
index 0106bebe6900..c03ccdb99434 100644
@@ -13,6 +13,8 @@
 #include <linux/module.h>
 #include <linux/init.h>
 
+bool curve25519_selftest(void);
+
 const u8 curve25519_null_point[CURVE25519_KEY_SIZE] __aligned(32) = { 0 };
 const u8 curve25519_base_point[CURVE25519_KEY_SIZE] __aligned(32) = { 9 };
 
@@ -20,6 +22,21 @@ EXPORT_SYMBOL(curve25519_null_point);
 EXPORT_SYMBOL(curve25519_base_point);
 EXPORT_SYMBOL(curve25519_generic);
 
+static int __init mod_init(void)
+{
+	if (!IS_ENABLED(CONFIG_CRYPTO_MANAGER_DISABLE_TESTS) &&
+	    WARN_ON(!curve25519_selftest()))
+		return -ENODEV;
+	return 0;
+}
+
+static void __exit mod_exit(void)
+{
+}
+
+module_init(mod_init);
+module_exit(mod_exit);
+
 MODULE_LICENSE("GPL v2");
 MODULE_DESCRIPTION("Curve25519 scalar multiplication");
 MODULE_AUTHOR("Jason A. Donenfeld <[email protected]>");
Signature · 1 line
2.24.1
maintainer
#1 lore raw
Quoted 5 lines · Jason A. Donenfeld

Somehow these were dropped when Zinc was being integrated, which is problematic, because testing the library interface for Curve25519 is important.. This commit simply adds them back and wires them in in the same way that the blake2s selftests are wired in.

Quoted 7 lines
---
 lib/crypto/Makefile              |    1 +
 lib/crypto/curve25519-selftest.c | 1321 ++++++++++++++++++++++++++++++
 lib/crypto/curve25519.c          |   17 +
 3 files changed, 1339 insertions(+)
 create mode 100644 lib/crypto/curve25519-selftest.c

Patch applied. 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