summaryrefslogtreecommitdiff
path: root/lib/crypto/curve25519.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-12-16 19:53:26 +0100
committerHerbert Xu <herbert@gondor.apana.org.au>2019-12-27 18:18:03 +0800
commitaa127963f1cab2b93c74c9b128a84610203fb674 (patch)
tree6b74802608e87ded121f412c125d18cf82718728 /lib/crypto/curve25519.c
parentc782937e92826af464e65111e9f7a7a774b6c276 (diff)
crypto: lib/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. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'lib/crypto/curve25519.c')
-rw-r--r--lib/crypto/curve25519.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/crypto/curve25519.c b/lib/crypto/curve25519.c
index 0106bebe6900..c03ccdb99434 100644
--- a/lib/crypto/curve25519.c
+++ b/lib/crypto/curve25519.c
@@ -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 <Jason@zx2c4.com>");