aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/crypto/zinc/curve25519/curve25519.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/crypto/zinc/curve25519/curve25519.c (renamed from src/crypto/curve25519.c)69
1 files changed, 34 insertions, 35 deletions
diff --git a/src/crypto/curve25519.c b/src/crypto/zinc/curve25519/curve25519.c
index 9bf0a41..183eeb5 100644
--- a/src/crypto/curve25519.c
+++ b/src/crypto/zinc/curve25519/curve25519.c
@@ -1,9 +1,15 @@
/* SPDX-License-Identifier: GPL-2.0
*
* Copyright (C) 2015-2018 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 "curve25519.h"
+#include <zinc/curve25519.h>
#include <asm/unaligned.h>
#include <linux/version.h>
@@ -11,6 +17,23 @@
#include <linux/random.h>
#include <crypto/algapi.h>
+#ifndef HAVE_CURVE25519_ARCH_IMPLEMENTATION
+void __init curve25519_fpu_init(void)
+{
+}
+static inline bool curve25519_arch(u8 mypublic[CURVE25519_POINT_SIZE],
+ const u8 secret[CURVE25519_POINT_SIZE],
+ const u8 basepoint[CURVE25519_POINT_SIZE])
+{
+ return false;
+}
+static inline bool curve25519_base_arch(u8 pub[CURVE25519_POINT_SIZE],
+ const u8 secret[CURVE25519_POINT_SIZE])
+{
+ return false;
+}
+#endif
+
static __always_inline void normalize_secret(u8 secret[CURVE25519_POINT_SIZE])
{
secret[0] &= 248;
@@ -18,14 +41,6 @@ static __always_inline void normalize_secret(u8 secret[CURVE25519_POINT_SIZE])
secret[31] |= 64;
}
-#if defined(CONFIG_X86_64)
-#include "curve25519-x86_64.h"
-#elif IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && defined(CONFIG_ARM)
-#include "curve25519-arm.h"
-#else
-void __init curve25519_fpu_init(void) { }
-#endif
-
#if defined(CONFIG_ARCH_SUPPORTS_INT128) && defined(__SIZEOF_INT128__)
#include "curve25519-hacl64.h"
#else
@@ -34,51 +49,35 @@ void __init curve25519_fpu_init(void) { }
static const u8 null_point[CURVE25519_POINT_SIZE] = { 0 };
-bool curve25519(u8 mypublic[CURVE25519_POINT_SIZE], const u8 secret[CURVE25519_POINT_SIZE], const u8 basepoint[CURVE25519_POINT_SIZE])
+bool curve25519(u8 mypublic[CURVE25519_POINT_SIZE],
+ const u8 secret[CURVE25519_POINT_SIZE],
+ const u8 basepoint[CURVE25519_POINT_SIZE])
{
-#if defined(CONFIG_X86_64)
- if (curve25519_use_adx)
- curve25519_adx(mypublic, secret, basepoint);
- else if (curve25519_use_bmi2)
- curve25519_bmi2(mypublic, secret, basepoint);
- else
-#elif IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && defined(CONFIG_ARM)
- if (curve25519_use_neon && may_use_simd()) {
- kernel_neon_begin();
- curve25519_neon(mypublic, secret, basepoint);
- kernel_neon_end();
- } else
-#endif
+ if (!curve25519_arch(mypublic, secret, basepoint))
curve25519_generic(mypublic, secret, basepoint);
-
return crypto_memneq(mypublic, null_point, CURVE25519_POINT_SIZE);
}
+EXPORT_SYMBOL(curve25519);
-bool curve25519_generate_public(u8 pub[CURVE25519_POINT_SIZE], const u8 secret[CURVE25519_POINT_SIZE])
+bool curve25519_generate_public(u8 pub[CURVE25519_POINT_SIZE],
+ const u8 secret[CURVE25519_POINT_SIZE])
{
static const u8 basepoint[CURVE25519_POINT_SIZE] __aligned(32) = { 9 };
if (unlikely(!crypto_memneq(secret, null_point, CURVE25519_POINT_SIZE)))
return false;
-#if defined(CONFIG_X86_64)
- if (curve25519_use_adx) {
- curve25519_adx_base(pub, secret);
- return crypto_memneq(pub, null_point, CURVE25519_POINT_SIZE);
- }
- if (curve25519_use_bmi2) {
- curve25519_bmi2_base(pub, secret);
+ if (curve25519_base_arch(pub, secret))
return crypto_memneq(pub, null_point, CURVE25519_POINT_SIZE);
- }
-#endif
-
return curve25519(pub, secret, basepoint);
}
+EXPORT_SYMBOL(curve25519_generate_public);
void curve25519_generate_secret(u8 secret[CURVE25519_POINT_SIZE])
{
get_random_bytes_wait(secret, CURVE25519_POINT_SIZE);
normalize_secret(secret);
}
+EXPORT_SYMBOL(curve25519_generate_secret);
#include "../selftest/curve25519.h"