summaryrefslogtreecommitdiffhomepage
path: root/src/crypto
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-01-11 01:13:35 -0800
committerJason A. Donenfeld <Jason@zx2c4.com>2019-01-23 14:29:44 +0100
commitf43eabd5616d5dd114b1818867e4c51d3c24dbd3 (patch)
tree001a46f2f2f53b9c997812e5275419a4313779c0 /src/crypto
parenta2fad76b15bf650942f373263cbfab43d12a3939 (diff)
global: normalize -> clamp
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/zinc/curve25519/curve25519-fiat32.c2
-rw-r--r--src/crypto/zinc/curve25519/curve25519-hacl64.c2
-rw-r--r--src/crypto/zinc/curve25519/curve25519-x86_64.c7
-rw-r--r--src/crypto/zinc/curve25519/curve25519.c16
4 files changed, 10 insertions, 17 deletions
diff --git a/src/crypto/zinc/curve25519/curve25519-fiat32.c b/src/crypto/zinc/curve25519/curve25519-fiat32.c
index 60a04e4..7f4f01c 100644
--- a/src/crypto/zinc/curve25519/curve25519-fiat32.c
+++ b/src/crypto/zinc/curve25519/curve25519-fiat32.c
@@ -760,7 +760,7 @@ static void curve25519_generic(u8 out[CURVE25519_KEY_SIZE],
u8 e[32];
memcpy(e, scalar, 32);
- normalize_secret(e);
+ clamp_secret(e);
/* The following implementation was transcribed to Coq and proven to
* correspond to unary scalar multiplication in affine coordinates given
diff --git a/src/crypto/zinc/curve25519/curve25519-hacl64.c b/src/crypto/zinc/curve25519/curve25519-hacl64.c
index 9129239..ff22d3b 100644
--- a/src/crypto/zinc/curve25519/curve25519-hacl64.c
+++ b/src/crypto/zinc/curve25519/curve25519-hacl64.c
@@ -767,7 +767,7 @@ static void curve25519_generic(u8 mypublic[CURVE25519_KEY_SIZE],
u8 e[32] __aligned(32) = { 0 };
u8 *scalar;
memcpy(e, secret, 32);
- normalize_secret(e);
+ clamp_secret(e);
scalar = e;
{
u64 buf[15] = { 0 };
diff --git a/src/crypto/zinc/curve25519/curve25519-x86_64.c b/src/crypto/zinc/curve25519/curve25519-x86_64.c
index 239e345..81ef575 100644
--- a/src/crypto/zinc/curve25519/curve25519-x86_64.c
+++ b/src/crypto/zinc/curve25519/curve25519-x86_64.c
@@ -1935,13 +1935,6 @@ static __always_inline void cselect(u8 bit, u64 *const px, const u64 *const py)
);
}
-static __always_inline void clamp_secret(u8 secret[CURVE25519_KEY_SIZE])
-{
- secret[0] &= 248;
- secret[31] &= 127;
- secret[31] |= 64;
-}
-
static void curve25519_adx(u8 shared[CURVE25519_KEY_SIZE],
const u8 private_key[CURVE25519_KEY_SIZE],
const u8 session_key[CURVE25519_KEY_SIZE])
diff --git a/src/crypto/zinc/curve25519/curve25519.c b/src/crypto/zinc/curve25519/curve25519.c
index f1bfe86..6b3f12a 100644
--- a/src/crypto/zinc/curve25519/curve25519.c
+++ b/src/crypto/zinc/curve25519/curve25519.c
@@ -20,6 +20,13 @@
#include <linux/init.h>
#include <crypto/algapi.h> // For crypto_memneq.
+static __always_inline void clamp_secret(u8 secret[CURVE25519_KEY_SIZE])
+{
+ secret[0] &= 248;
+ secret[31] &= 127;
+ secret[31] |= 64;
+}
+
#if defined(CONFIG_ZINC_ARCH_X86_64)
#include "curve25519-x86_64-glue.c"
#elif defined(CONFIG_ZINC_ARCH_ARM)
@@ -42,13 +49,6 @@ static inline bool curve25519_base_arch(u8 pub[CURVE25519_KEY_SIZE],
}
#endif
-static __always_inline void normalize_secret(u8 secret[CURVE25519_KEY_SIZE])
-{
- secret[0] &= 248;
- secret[31] &= 127;
- secret[31] |= 64;
-}
-
#if defined(CONFIG_ARCH_SUPPORTS_INT128) && defined(__SIZEOF_INT128__)
#include "curve25519-hacl64.c"
#else
@@ -84,7 +84,7 @@ EXPORT_SYMBOL(curve25519_generate_public);
void curve25519_generate_secret(u8 secret[CURVE25519_KEY_SIZE])
{
get_random_bytes_wait(secret, CURVE25519_KEY_SIZE);
- normalize_secret(secret);
+ clamp_secret(secret);
}
EXPORT_SYMBOL(curve25519_generate_secret);