]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
lib/crypto: curve25519: Consolidate into single module
authorEric Biggers <ebiggers@kernel.org>
Sat, 6 Sep 2025 21:35:21 +0000 (14:35 -0700)
committerEric Biggers <ebiggers@kernel.org>
Sat, 6 Sep 2025 23:32:43 +0000 (16:32 -0700)
Reorganize the Curve25519 library code:

- Build a single libcurve25519 module, instead of up to three modules:
  libcurve25519, libcurve25519-generic, and an arch-specific module.

- Move the arch-specific Curve25519 code from arch/$(SRCARCH)/crypto/ to
  lib/crypto/$(SRCARCH)/.  Centralize the build rules into
  lib/crypto/Makefile and lib/crypto/Kconfig.

- Include the arch-specific code directly in lib/crypto/curve25519.c via
  a header, rather than using a separate .c file.

- Eliminate the entanglement with CRYPTO.  CRYPTO_LIB_CURVE25519 no
  longer selects CRYPTO, and the arch-specific Curve25519 code no longer
  depends on CRYPTO.

This brings Curve25519 in line with the latest conventions for
lib/crypto/, used by other algorithms.  The exception is that I kept the
generic code in separate translation units for now.  (Some of the
function names collide between the x86 and generic Curve25519 code.  And
the Curve25519 functions are very long anyway, so inlining doesn't
matter as much for Curve25519 as it does for some other algorithms.)

Link: https://lore.kernel.org/r/20250906213523.84915-11-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
16 files changed:
arch/arm/crypto/Kconfig
arch/arm/crypto/Makefile
arch/powerpc/crypto/Kconfig
arch/powerpc/crypto/Makefile
arch/x86/crypto/Kconfig
arch/x86/crypto/Makefile
include/crypto/curve25519.h
lib/crypto/Kconfig
lib/crypto/Makefile
lib/crypto/arm/curve25519-core.S [moved from arch/arm/crypto/curve25519-core.S with 100% similarity]
lib/crypto/arm/curve25519.h [moved from arch/arm/crypto/curve25519-glue.c with 58% similarity]
lib/crypto/curve25519-generic.c [deleted file]
lib/crypto/curve25519.c
lib/crypto/powerpc/curve25519-ppc64le_asm.S [moved from arch/powerpc/crypto/curve25519-ppc64le_asm.S with 100% similarity]
lib/crypto/powerpc/curve25519.h [moved from arch/powerpc/crypto/curve25519-ppc64le-core.c with 88% similarity]
lib/crypto/x86/curve25519.h [moved from arch/x86/crypto/curve25519-x86_64.c with 98% similarity]

index 97718d86f6007efacea01fb3ae9808b5c1783da4..c436eec22d86ca8873a9dce2ba5847691457bce1 100644 (file)
@@ -2,18 +2,6 @@
 
 menu "Accelerated Cryptographic Algorithms for CPU (arm)"
 
-config CRYPTO_CURVE25519_NEON
-       tristate
-       depends on KERNEL_MODE_NEON
-       select CRYPTO_LIB_CURVE25519_GENERIC
-       select CRYPTO_ARCH_HAVE_LIB_CURVE25519
-       default CRYPTO_LIB_CURVE25519_INTERNAL
-       help
-         Curve25519 algorithm
-
-         Architecture: arm with
-         - NEON (Advanced SIMD) extensions
-
 config CRYPTO_GHASH_ARM_CE
        tristate "Hash functions: GHASH (PMULL/NEON/ARMv8 Crypto Extensions)"
        depends on KERNEL_MODE_NEON
index 4f23999ae17dfe3d27626bb04bb9c19d453605b4..6346a73effc06a395ad87de161ea03523486c125 100644 (file)
@@ -7,7 +7,6 @@ obj-$(CONFIG_CRYPTO_AES_ARM) += aes-arm.o
 obj-$(CONFIG_CRYPTO_AES_ARM_BS) += aes-arm-bs.o
 obj-$(CONFIG_CRYPTO_BLAKE2B_NEON) += blake2b-neon.o
 obj-$(CONFIG_CRYPTO_NHPOLY1305_NEON) += nhpoly1305-neon.o
-obj-$(CONFIG_CRYPTO_CURVE25519_NEON) += curve25519-neon.o
 
 obj-$(CONFIG_CRYPTO_AES_ARM_CE) += aes-arm-ce.o
 obj-$(CONFIG_CRYPTO_GHASH_ARM_CE) += ghash-arm-ce.o
@@ -18,4 +17,3 @@ blake2b-neon-y  := blake2b-neon-core.o blake2b-neon-glue.o
 aes-arm-ce-y   := aes-ce-core.o aes-ce-glue.o
 ghash-arm-ce-y := ghash-ce-core.o ghash-ce-glue.o
 nhpoly1305-neon-y := nh-neon-core.o nhpoly1305-neon-glue.o
-curve25519-neon-y := curve25519-core.o curve25519-glue.o
index 6106a219da6afec41609980ec3a8dc404c5a031d..662aed46f9c795a28acc0ae19b8249c581eee62d 100644 (file)
@@ -2,18 +2,6 @@
 
 menu "Accelerated Cryptographic Algorithms for CPU (powerpc)"
 
-config CRYPTO_CURVE25519_PPC64
-       tristate
-       depends on PPC64 && CPU_LITTLE_ENDIAN
-       select CRYPTO_LIB_CURVE25519_GENERIC
-       select CRYPTO_ARCH_HAVE_LIB_CURVE25519
-       default CRYPTO_LIB_CURVE25519_INTERNAL
-       help
-         Curve25519 algorithm
-
-         Architecture: PowerPC64
-         - Little-endian
-
 config CRYPTO_AES_PPC_SPE
        tristate "Ciphers: AES, modes: ECB/CBC/CTR/XTS (SPE)"
        depends on SPE
index 9eb59dce67f3677f24db771b240c3d7a357649d5..5960e5300db71e315c21ca95f79cd8924f74affa 100644 (file)
@@ -8,12 +8,10 @@
 obj-$(CONFIG_CRYPTO_AES_PPC_SPE) += aes-ppc-spe.o
 obj-$(CONFIG_CRYPTO_AES_GCM_P10) += aes-gcm-p10-crypto.o
 obj-$(CONFIG_CRYPTO_DEV_VMX_ENCRYPT) += vmx-crypto.o
-obj-$(CONFIG_CRYPTO_CURVE25519_PPC64) += curve25519-ppc64le.o
 
 aes-ppc-spe-y := aes-spe-core.o aes-spe-keys.o aes-tab-4k.o aes-spe-modes.o aes-spe-glue.o
 aes-gcm-p10-crypto-y := aes-gcm-p10-glue.o aes-gcm-p10.o ghashp10-ppc.o aesp10-ppc.o
 vmx-crypto-objs := vmx.o aesp8-ppc.o ghashp8-ppc.o aes.o aes_cbc.o aes_ctr.o aes_xts.o ghash.o
-curve25519-ppc64le-y := curve25519-ppc64le-core.o curve25519-ppc64le_asm.o
 
 ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),y)
 override flavour := linux-ppc64le
index 6a895a571b00ebb2ec5fc0b5405e378bbcfb81c0..d9c6fc78cf332489fe862ccfa1f3773881b0ffb3 100644 (file)
@@ -2,18 +2,6 @@
 
 menu "Accelerated Cryptographic Algorithms for CPU (x86)"
 
-config CRYPTO_CURVE25519_X86
-       tristate
-       depends on 64BIT
-       select CRYPTO_LIB_CURVE25519_GENERIC
-       select CRYPTO_ARCH_HAVE_LIB_CURVE25519
-       default CRYPTO_LIB_CURVE25519_INTERNAL
-       help
-         Curve25519 algorithm
-
-         Architecture: x86_64 using:
-         - ADX (large integer arithmetic)
-
 config CRYPTO_AES_NI_INTEL
        tristate "Ciphers: AES, modes: ECB, CBC, CTS, CTR, XCTR, XTS, GCM (AES-NI/VAES)"
        select CRYPTO_AEAD
index d402963d6b579a8e3bb7169c57163e9536dc5bda..dfba7e5e88ea692859ce43f8839b221c1a7e0a45 100644 (file)
@@ -62,8 +62,6 @@ nhpoly1305-sse2-y := nh-sse2-x86_64.o nhpoly1305-sse2-glue.o
 obj-$(CONFIG_CRYPTO_NHPOLY1305_AVX2) += nhpoly1305-avx2.o
 nhpoly1305-avx2-y := nh-avx2-x86_64.o nhpoly1305-avx2-glue.o
 
-obj-$(CONFIG_CRYPTO_CURVE25519_X86) += curve25519-x86_64.o
-
 obj-$(CONFIG_CRYPTO_SM3_AVX_X86_64) += sm3-avx-x86_64.o
 sm3-avx-x86_64-y := sm3-avx-asm_64.o sm3_avx_glue.o
 
@@ -81,6 +79,3 @@ aria-aesni-avx2-x86_64-y := aria-aesni-avx2-asm_64.o aria_aesni_avx2_glue.o
 
 obj-$(CONFIG_CRYPTO_ARIA_GFNI_AVX512_X86_64) += aria-gfni-avx512-x86_64.o
 aria-gfni-avx512-x86_64-y := aria-gfni-avx512-asm_64.o aria_gfni_avx512_glue.o
-
-# Disable GCOV in odd or sensitive code
-GCOV_PROFILE_curve25519-x86_64.o := n
index 78aa5f28c847f27af1f3c0921e77be48973262a5..db63a5577c004511f0b9a97a569e1e501b89f083 100644 (file)
@@ -13,20 +13,10 @@ enum curve25519_lengths {
        CURVE25519_KEY_SIZE = 32
 };
 
-extern const u8 curve25519_null_point[];
-extern const u8 curve25519_base_point[];
-
 void curve25519_generic(u8 out[CURVE25519_KEY_SIZE],
                        const u8 scalar[CURVE25519_KEY_SIZE],
                        const u8 point[CURVE25519_KEY_SIZE]);
 
-void curve25519_arch(u8 out[CURVE25519_KEY_SIZE],
-                    const u8 scalar[CURVE25519_KEY_SIZE],
-                    const u8 point[CURVE25519_KEY_SIZE]);
-
-void curve25519_base_arch(u8 pub[CURVE25519_KEY_SIZE],
-                         const u8 secret[CURVE25519_KEY_SIZE]);
-
 bool __must_check curve25519(u8 mypublic[CURVE25519_KEY_SIZE],
                             const u8 secret[CURVE25519_KEY_SIZE],
                             const u8 basepoint[CURVE25519_KEY_SIZE]);
index 37d85e0c9b979beb25c85269e52e06641d42a518..eea17e36a22bedc081f98059c561c8800527be9c 100644 (file)
@@ -54,35 +54,24 @@ config CRYPTO_LIB_CHACHA_ARCH
        default y if S390
        default y if X86_64
 
-config CRYPTO_ARCH_HAVE_LIB_CURVE25519
-       bool
-       help
-         Declares whether the architecture provides an arch-specific
-         accelerated implementation of the Curve25519 library interface,
-         either builtin or as a module.
-
-config CRYPTO_LIB_CURVE25519_GENERIC
+config CRYPTO_LIB_CURVE25519
        tristate
        select CRYPTO_LIB_UTILS
        help
-         This symbol can be depended upon by arch implementations of the
-         Curve25519 library interface that require the generic code as a
-         fallback, e.g., for SIMD implementations. If no arch specific
-         implementation is enabled, this implementation serves the users
-         of CRYPTO_LIB_CURVE25519.
+         The Curve25519 library functions.  Select this if your module uses any
+         of the functions from <crypto/curve25519.h>.
 
-config CRYPTO_LIB_CURVE25519_INTERNAL
-       tristate
-       select CRYPTO_LIB_CURVE25519_GENERIC if CRYPTO_ARCH_HAVE_LIB_CURVE25519=n
+config CRYPTO_LIB_CURVE25519_ARCH
+       bool
+       depends on CRYPTO_LIB_CURVE25519 && !UML && !KMSAN
+       default y if ARM && KERNEL_MODE_NEON
+       default y if PPC64 && CPU_LITTLE_ENDIAN
+       default y if X86_64
 
-config CRYPTO_LIB_CURVE25519
-       tristate
-       select CRYPTO
-       select CRYPTO_LIB_CURVE25519_INTERNAL
-       help
-         Enable the Curve25519 library interface. This interface may be
-         fulfilled by either the generic implementation or an arch-specific
-         one, if one is available and enabled.
+config CRYPTO_LIB_CURVE25519_GENERIC
+       bool
+       depends on CRYPTO_LIB_CURVE25519
+       default y if !CRYPTO_LIB_CURVE25519_ARCH || ARM || X86_64
 
 config CRYPTO_LIB_DES
        tristate
index 6c3be971ace096a3cdc72d0dd688e1531121c97e..bded351aeacef2745d5e4d7c9d47edd188f79646 100644 (file)
@@ -76,17 +76,31 @@ obj-$(CONFIG_CRYPTO_LIB_CHACHA20POLY1305)   += libchacha20poly1305.o
 libchacha20poly1305-y                          += chacha20poly1305.o
 libchacha20poly1305-$(CONFIG_CRYPTO_SELFTESTS) += chacha20poly1305-selftest.o
 
-obj-$(CONFIG_CRYPTO_LIB_CURVE25519_GENERIC)    += libcurve25519-generic.o
-libcurve25519-generic-y                                := curve25519-fiat32.o
-libcurve25519-generic-$(CONFIG_ARCH_SUPPORTS_INT128)   := curve25519-hacl64.o
-libcurve25519-generic-y                                += curve25519-generic.o
+################################################################################
+
+obj-$(CONFIG_CRYPTO_LIB_CURVE25519) += libcurve25519.o
+libcurve25519-y := curve25519.o
+
+# Disable GCOV in odd or sensitive code
+GCOV_PROFILE_curve25519.o := n
+
+ifeq ($(CONFIG_ARCH_SUPPORTS_INT128),y)
+libcurve25519-$(CONFIG_CRYPTO_LIB_CURVE25519_GENERIC) += curve25519-hacl64.o
+else
+libcurve25519-$(CONFIG_CRYPTO_LIB_CURVE25519_GENERIC) += curve25519-fiat32.o
+endif
 # clang versions prior to 18 may blow out the stack with KASAN
 ifeq ($(call clang-min-version, 180000),)
 KASAN_SANITIZE_curve25519-hacl64.o := n
 endif
 
-obj-$(CONFIG_CRYPTO_LIB_CURVE25519)            += libcurve25519.o
-libcurve25519-y                                        += curve25519.o
+ifeq ($(CONFIG_CRYPTO_LIB_CURVE25519_ARCH),y)
+CFLAGS_curve25519.o += -I$(src)/$(SRCARCH)
+libcurve25519-$(CONFIG_ARM) += arm/curve25519-core.o
+libcurve25519-$(CONFIG_PPC) += powerpc/curve25519-ppc64le_asm.o
+endif
+
+################################################################################
 
 obj-$(CONFIG_CRYPTO_LIB_DES)                   += libdes.o
 libdes-y                                       := des.o
similarity index 58%
rename from arch/arm/crypto/curve25519-glue.c
rename to lib/crypto/arm/curve25519.h
index 3076020d8fbeb6c027f9d31572bb287cb9722c2e..f6d66494eb8f880b5384fee0a7b68fea16538087 100644 (file)
 #include <asm/simd.h>
 #include <crypto/internal/simd.h>
 #include <linux/types.h>
-#include <linux/module.h>
-#include <linux/init.h>
 #include <linux/jump_label.h>
-#include <crypto/curve25519.h>
 
 asmlinkage void curve25519_neon(u8 mypublic[CURVE25519_KEY_SIZE],
                                const u8 secret[CURVE25519_KEY_SIZE],
@@ -23,9 +20,9 @@ asmlinkage void curve25519_neon(u8 mypublic[CURVE25519_KEY_SIZE],
 
 static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon);
 
-void curve25519_arch(u8 out[CURVE25519_KEY_SIZE],
-                    const u8 scalar[CURVE25519_KEY_SIZE],
-                    const u8 point[CURVE25519_KEY_SIZE])
+static void curve25519_arch(u8 out[CURVE25519_KEY_SIZE],
+                           const u8 scalar[CURVE25519_KEY_SIZE],
+                           const u8 point[CURVE25519_KEY_SIZE])
 {
        if (static_branch_likely(&have_neon) && crypto_simd_usable()) {
                kernel_neon_begin();
@@ -35,28 +32,16 @@ void curve25519_arch(u8 out[CURVE25519_KEY_SIZE],
                curve25519_generic(out, scalar, point);
        }
 }
-EXPORT_SYMBOL(curve25519_arch);
 
-void curve25519_base_arch(u8 pub[CURVE25519_KEY_SIZE],
-                         const u8 secret[CURVE25519_KEY_SIZE])
+static void curve25519_base_arch(u8 pub[CURVE25519_KEY_SIZE],
+                                const u8 secret[CURVE25519_KEY_SIZE])
 {
-       return curve25519_arch(pub, secret, curve25519_base_point);
+       curve25519_arch(pub, secret, curve25519_base_point);
 }
-EXPORT_SYMBOL(curve25519_base_arch);
 
-static int __init arm_curve25519_init(void)
+#define curve25519_mod_init_arch curve25519_mod_init_arch
+static void curve25519_mod_init_arch(void)
 {
        if (elf_hwcap & HWCAP_NEON)
                static_branch_enable(&have_neon);
-       return 0;
 }
-
-static void __exit arm_curve25519_exit(void)
-{
-}
-
-module_init(arm_curve25519_init);
-module_exit(arm_curve25519_exit);
-
-MODULE_DESCRIPTION("Public key crypto: Curve25519 (NEON-accelerated)");
-MODULE_LICENSE("GPL v2");
diff --git a/lib/crypto/curve25519-generic.c b/lib/crypto/curve25519-generic.c
deleted file mode 100644 (file)
index f8aa70c..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0 OR MIT
-/*
- * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
- *
- * This is an implementation of the Curve25519 ECDH algorithm, using either
- * a 32-bit implementation or a 64-bit implementation with 128-bit integers,
- * depending on what is supported by the target compiler.
- *
- * Information: https://cr.yp.to/ecdh.html
- */
-
-#include <crypto/curve25519.h>
-#include <linux/export.h>
-#include <linux/module.h>
-
-const u8 curve25519_null_point[CURVE25519_KEY_SIZE] __aligned(32) = { 0 };
-const u8 curve25519_base_point[CURVE25519_KEY_SIZE] __aligned(32) = { 9 };
-
-EXPORT_SYMBOL(curve25519_null_point);
-EXPORT_SYMBOL(curve25519_base_point);
-EXPORT_SYMBOL(curve25519_generic);
-
-MODULE_LICENSE("GPL v2");
-MODULE_DESCRIPTION("Curve25519 scalar multiplication");
-MODULE_AUTHOR("Jason A. Donenfeld <Jason@zx2c4.com>");
index 1b786389d714a09a2aa7fb739d8ff8c1193627fb..01e265dfbcd90429b787dfa66cf6862dbec4eb63 100644 (file)
@@ -2,8 +2,9 @@
 /*
  * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
  *
- * This is an implementation of the Curve25519 ECDH algorithm, using either
- * a 32-bit implementation or a 64-bit implementation with 128-bit integers,
+ * This is an implementation of the Curve25519 ECDH algorithm, using either an
+ * architecture-optimized implementation or a generic implementation. The
+ * generic implementation is either 32-bit, or 64-bit with 128-bit integers,
  * depending on what is supported by the target compiler.
  *
  * Information: https://cr.yp.to/ecdh.html
 #include <linux/init.h>
 #include <linux/module.h>
 
+static const u8 curve25519_null_point[CURVE25519_KEY_SIZE] __aligned(32) = { 0 };
+static const u8 curve25519_base_point[CURVE25519_KEY_SIZE] __aligned(32) = { 9 };
+
+#ifdef CONFIG_CRYPTO_LIB_CURVE25519_ARCH
+#include "curve25519.h" /* $(SRCARCH)/curve25519.h */
+#else
+static void curve25519_arch(u8 mypublic[CURVE25519_KEY_SIZE],
+                           const u8 secret[CURVE25519_KEY_SIZE],
+                           const u8 basepoint[CURVE25519_KEY_SIZE])
+{
+       curve25519_generic(mypublic, secret, basepoint);
+}
+
+static void curve25519_base_arch(u8 pub[CURVE25519_KEY_SIZE],
+                                const u8 secret[CURVE25519_KEY_SIZE])
+{
+       curve25519_generic(pub, secret, curve25519_base_point);
+}
+#endif
+
 bool __must_check
 curve25519(u8 mypublic[CURVE25519_KEY_SIZE],
           const u8 secret[CURVE25519_KEY_SIZE],
           const u8 basepoint[CURVE25519_KEY_SIZE])
 {
-       if (IS_ENABLED(CONFIG_CRYPTO_ARCH_HAVE_LIB_CURVE25519))
-               curve25519_arch(mypublic, secret, basepoint);
-       else
-               curve25519_generic(mypublic, secret, basepoint);
+       curve25519_arch(mypublic, secret, basepoint);
        return crypto_memneq(mypublic, curve25519_null_point,
                             CURVE25519_KEY_SIZE);
 }
@@ -36,27 +54,25 @@ curve25519_generate_public(u8 pub[CURVE25519_KEY_SIZE],
        if (unlikely(!crypto_memneq(secret, curve25519_null_point,
                                    CURVE25519_KEY_SIZE)))
                return false;
-
-       if (IS_ENABLED(CONFIG_CRYPTO_ARCH_HAVE_LIB_CURVE25519))
-               curve25519_base_arch(pub, secret);
-       else
-               curve25519_generic(pub, secret, curve25519_base_point);
+       curve25519_base_arch(pub, secret);
        return crypto_memneq(pub, curve25519_null_point, CURVE25519_KEY_SIZE);
 }
 EXPORT_SYMBOL(curve25519_generate_public);
 
-static int __init curve25519_init(void)
+#ifdef curve25519_mod_init_arch
+static int __init curve25519_mod_init(void)
 {
+       curve25519_mod_init_arch();
        return 0;
 }
+subsys_initcall(curve25519_mod_init);
 
-static void __exit curve25519_exit(void)
+static void __exit curve25519_mod_exit(void)
 {
 }
-
-module_init(curve25519_init);
-module_exit(curve25519_exit);
+module_exit(curve25519_mod_exit);
+#endif
 
 MODULE_LICENSE("GPL v2");
-MODULE_DESCRIPTION("Curve25519 scalar multiplication");
+MODULE_DESCRIPTION("Curve25519 algorithm");
 MODULE_AUTHOR("Jason A. Donenfeld <Jason@zx2c4.com>");
similarity index 88%
rename from arch/powerpc/crypto/curve25519-ppc64le-core.c
rename to lib/crypto/powerpc/curve25519.h
index 6eb18ee19cad3b409ad916ab12a8c5a2a80f0c16..dee6234c48e92a58aa09f9ef372cd4ea4c2f33fc 100644 (file)
@@ -7,12 +7,9 @@
  *     - Algorithm 1 Scalar multiplication of a variable point
  */
 
-#include <crypto/curve25519.h>
-
 #include <linux/types.h>
 #include <linux/jump_label.h>
 #include <linux/kernel.h>
-#include <linux/module.h>
 
 #include <linux/cpufeature.h>
 #include <linux/processor.h>
@@ -175,21 +172,15 @@ static void curve25519_fe51(uint8_t out[32], const uint8_t scalar[32],
        fe51_tobytes(out, x2);
 }
 
-void curve25519_arch(u8 mypublic[CURVE25519_KEY_SIZE],
-                    const u8 secret[CURVE25519_KEY_SIZE],
-                    const u8 basepoint[CURVE25519_KEY_SIZE])
+static void curve25519_arch(u8 mypublic[CURVE25519_KEY_SIZE],
+                           const u8 secret[CURVE25519_KEY_SIZE],
+                           const u8 basepoint[CURVE25519_KEY_SIZE])
 {
        curve25519_fe51(mypublic, secret, basepoint);
 }
-EXPORT_SYMBOL(curve25519_arch);
 
-void curve25519_base_arch(u8 pub[CURVE25519_KEY_SIZE],
-                         const u8 secret[CURVE25519_KEY_SIZE])
+static void curve25519_base_arch(u8 pub[CURVE25519_KEY_SIZE],
+                                const u8 secret[CURVE25519_KEY_SIZE])
 {
        curve25519_fe51(pub, secret, curve25519_base_point);
 }
-EXPORT_SYMBOL(curve25519_base_arch);
-
-MODULE_DESCRIPTION("PPC64le Curve25519 scalar multiplication with 51 bits limbs");
-MODULE_LICENSE("GPL v2");
-MODULE_AUTHOR("Danny Tsen <dtsen@us.ibm.com>");
similarity index 98%
rename from arch/x86/crypto/curve25519-x86_64.c
rename to lib/crypto/x86/curve25519.h
index ab91368284a473fe37da454a2c1695951f4696c4..5c0b8408852dee14b5cf251a376f1328413fe1a2 100644 (file)
@@ -4,13 +4,9 @@
  * Copyright (c) 2016-2020 INRIA, CMU and Microsoft Corporation
  */
 
-#include <crypto/curve25519.h>
-
-#include <linux/export.h>
 #include <linux/types.h>
 #include <linux/jump_label.h>
 #include <linux/kernel.h>
-#include <linux/module.h>
 
 #include <asm/cpufeature.h>
 #include <asm/processor.h>
@@ -1590,41 +1586,28 @@ static void curve25519_ever64_base(u8 *out, const u8 *priv)
 
 static __ro_after_init DEFINE_STATIC_KEY_FALSE(curve25519_use_bmi2_adx);
 
-void curve25519_arch(u8 mypublic[CURVE25519_KEY_SIZE],
-                    const u8 secret[CURVE25519_KEY_SIZE],
-                    const u8 basepoint[CURVE25519_KEY_SIZE])
+static void curve25519_arch(u8 mypublic[CURVE25519_KEY_SIZE],
+                           const u8 secret[CURVE25519_KEY_SIZE],
+                           const u8 basepoint[CURVE25519_KEY_SIZE])
 {
        if (static_branch_likely(&curve25519_use_bmi2_adx))
                curve25519_ever64(mypublic, secret, basepoint);
        else
                curve25519_generic(mypublic, secret, basepoint);
 }
-EXPORT_SYMBOL(curve25519_arch);
 
-void curve25519_base_arch(u8 pub[CURVE25519_KEY_SIZE],
-                         const u8 secret[CURVE25519_KEY_SIZE])
+static void curve25519_base_arch(u8 pub[CURVE25519_KEY_SIZE],
+                                const u8 secret[CURVE25519_KEY_SIZE])
 {
        if (static_branch_likely(&curve25519_use_bmi2_adx))
                curve25519_ever64_base(pub, secret);
        else
                curve25519_generic(pub, secret, curve25519_base_point);
 }
-EXPORT_SYMBOL(curve25519_base_arch);
 
-static int __init curve25519_mod_init(void)
+#define curve25519_mod_init_arch curve25519_mod_init_arch
+static void curve25519_mod_init_arch(void)
 {
        if (boot_cpu_has(X86_FEATURE_BMI2) && boot_cpu_has(X86_FEATURE_ADX))
                static_branch_enable(&curve25519_use_bmi2_adx);
-       return 0;
-}
-
-static void __exit curve25519_mod_exit(void)
-{
 }
-
-module_init(curve25519_mod_init);
-module_exit(curve25519_mod_exit);
-
-MODULE_DESCRIPTION("Curve25519 algorithm, ADX optimized");
-MODULE_LICENSE("GPL v2");
-MODULE_AUTHOR("Jason A. Donenfeld <Jason@zx2c4.com>");