aboutsummaryrefslogtreecommitdiffstatshomepage
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
commit6f0fc6cb3e453b2082678cf6f59f4cc349f49b0e (patch)
tree91e160308241ade8cc55efc0d1295f5e438dfa89
parentkeygen-html: bring back pure javascript implementation (diff)
downloadWireGuard-6f0fc6cb3e453b2082678cf6f59f4cc349f49b0e.tar.xz
WireGuard-6f0fc6cb3e453b2082678cf6f59f4cc349f49b0e.zip
global: normalize -> clamp
-rw-r--r--contrib/examples/embeddable-wg-library/wireguard.c6
-rw-r--r--contrib/examples/keygen-html/wireguard.js6
-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
-rw-r--r--src/tools/curve25519.c2
-rw-r--r--src/tools/curve25519.h2
-rw-r--r--src/tools/genkey.c2
9 files changed, 19 insertions, 26 deletions
diff --git a/contrib/examples/embeddable-wg-library/wireguard.c b/contrib/examples/embeddable-wg-library/wireguard.c
index 1522c910..51da8ece 100644
--- a/contrib/examples/embeddable-wg-library/wireguard.c
+++ b/contrib/examples/embeddable-wg-library/wireguard.c
@@ -1688,7 +1688,7 @@ static void invert(fe o, const fe i)
memzero_explicit(c, sizeof(c));
}
-static void normalize_key(uint8_t *z)
+static void clamp_key(uint8_t *z)
{
z[31] = (z[31] & 127) | 64;
z[0] &= 248;
@@ -1701,7 +1701,7 @@ void wg_generate_public_key(wg_key public_key, const wg_key private_key)
fe a = { 1 }, b = { 9 }, c = { 0 }, d = { 1 }, e, f;
memcpy(z, private_key, sizeof(z));
- normalize_key(z);
+ clamp_key(z);
for (i = 254; i >= 0; --i) {
r = (z[i >> 3] >> (i & 7)) & 1;
@@ -1745,7 +1745,7 @@ void wg_generate_public_key(wg_key public_key, const wg_key private_key)
void wg_generate_private_key(wg_key private_key)
{
wg_generate_preshared_key(private_key);
- normalize_key(private_key);
+ clamp_key(private_key);
}
void wg_generate_preshared_key(wg_key preshared_key)
diff --git a/contrib/examples/keygen-html/wireguard.js b/contrib/examples/keygen-html/wireguard.js
index e96da3e0..e262459b 100644
--- a/contrib/examples/keygen-html/wireguard.js
+++ b/contrib/examples/keygen-html/wireguard.js
@@ -91,7 +91,7 @@
o[a] = c[a];
}
- function normalizeKey(z) {
+ function clamp(z) {
z[31] = (z[31] & 127) | 64;
z[0] &= 248;
}
@@ -108,7 +108,7 @@
_9 = gf([9]);
for (var i = 0; i < 32; ++i)
z[i] = privateKey[i];
- normalizeKey(z);
+ clamp(z);
for (var i = 254; i >= 0; --i) {
r = (z[i >>> 3] >>> (i & 7)) & 1;
cswap(a, b, r);
@@ -148,7 +148,7 @@
function generatePrivateKey() {
var privateKey = generatePresharedKey();
- normalizeKey(privateKey);
+ clamp(privateKey);
return privateKey;
}
diff --git a/src/crypto/zinc/curve25519/curve25519-fiat32.c b/src/crypto/zinc/curve25519/curve25519-fiat32.c
index 60a04e4d..7f4f01ce 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 91292393..ff22d3b3 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 239e3450..81ef5757 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 f1bfe86b..6b3f12a6 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);
diff --git a/src/tools/curve25519.c b/src/tools/curve25519.c
index 79499338..0d52bc87 100644
--- a/src/tools/curve25519.c
+++ b/src/tools/curve25519.c
@@ -68,7 +68,7 @@ static inline void put_unaligned_le64(u64 s, u8 *d)
#ifndef __force
#define __force
#endif
-#define normalize_secret(a) curve25519_normalize_secret(a)
+#define clamp_secret(a) curve25519_clamp_secret(a)
static noinline void memzero_explicit(void *s, size_t count)
{
diff --git a/src/tools/curve25519.h b/src/tools/curve25519.h
index a5c30663..badcda0c 100644
--- a/src/tools/curve25519.h
+++ b/src/tools/curve25519.h
@@ -15,7 +15,7 @@ enum curve25519_lengths {
void curve25519(uint8_t mypublic[static CURVE25519_KEY_SIZE], const uint8_t secret[static CURVE25519_KEY_SIZE], const uint8_t basepoint[static CURVE25519_KEY_SIZE]);
void curve25519_generate_public(uint8_t pub[static CURVE25519_KEY_SIZE], const uint8_t secret[static CURVE25519_KEY_SIZE]);
-static inline void curve25519_normalize_secret(uint8_t secret[static CURVE25519_KEY_SIZE])
+static inline void curve25519_clamp_secret(uint8_t secret[static CURVE25519_KEY_SIZE])
{
secret[0] &= 248;
secret[31] &= 127;
diff --git a/src/tools/genkey.c b/src/tools/genkey.c
index 65711e16..645f6149 100644
--- a/src/tools/genkey.c
+++ b/src/tools/genkey.c
@@ -71,7 +71,7 @@ int genkey_main(int argc, char *argv[])
return 1;
}
if (!strcmp(argv[0], "genkey"))
- curve25519_normalize_secret(key);
+ curve25519_clamp_secret(key);
key_to_base64(base64, key);
puts(base64);