@@ -36,5 +36,9 @@ 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
+ifneq ($(CONFIG_CRYPTO_ARCH_HAVE_LIB_CURVE25519),)
+obj-$(CONFIG_CRYPTO_ARCH_HAVE_LIB_CURVE25519) += curve25519-selftest.o
+else
+obj-$(CONFIG_CRYPTO_LIB_CURVE25519_GENERIC) += curve25519-selftest.o
+endif
endif
@@ -4,6 +4,8 @@
*/
#include <crypto/curve25519.h>
+#include <linux/module.h>
+#include <linux/init.h>
struct curve25519_test_vector {
u8 private[CURVE25519_KEY_SIZE];
@@ -1280,7 +1282,7 @@ static const struct curve25519_test_vector curve25519_test_vectors[] __initconst
}
};
-bool __init curve25519_selftest(void)
+static bool __init curve25519_selftest(void)
{
bool success = true, ret, ret2;
size_t i = 0, j;
@@ -1319,3 +1321,22 @@ bool __init curve25519_selftest(void)
return success;
}
+
+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 selftest");
+MODULE_AUTHOR("Jason A. Donenfeld <Jason@zx2c4.com>");
@@ -13,8 +13,6 @@
#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 };
@@ -22,21 +20,6 @@ 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>");
If CRYPTO_CURVE25519 is y, CRYPTO_LIB_CURVE25519_GENERIC will be y, but CRYPTO_LIB_CURVE25519 may be set to m, cause build errors: lib/crypto/curve25519-selftest.o: In function `curve25519': curve25519-selftest.c:(.text.unlikely+0xc): undefined reference to `curve25519_arch' lib/crypto/curve25519-selftest.o: In function `curve25519_selftest': curve25519-selftest.c:(.init.text+0x17e): undefined reference to `curve25519_base_arch' This splits the curve25519 test code into its own source file. Reported-by: Hulk Robot <hulkci@huawei.com> Fixes: aa127963f1ca ("crypto: lib/curve25519 - re-add selftests") Signed-off-by: YueHaibing <yuehaibing@huawei.com> --- lib/crypto/Makefile | 6 +++++- lib/crypto/curve25519-selftest.c | 23 ++++++++++++++++++++++- lib/crypto/curve25519.c | 17 ----------------- 3 files changed, 27 insertions(+), 19 deletions(-)