diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-09-24 22:02:13 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-09-25 03:01:21 +0200 |
commit | 28d8b7eafe49450ef1bd20939334baebbea0a367 (patch) | |
tree | 5404d3b10c4141d31f23bb2e21ef0c73814308d0 /src/crypto/zinc/curve25519 | |
parent | hchacha20: keep in native endian in words (diff) | |
download | wireguard-monolithic-historical-28d8b7eafe49450ef1bd20939334baebbea0a367.tar.xz wireguard-monolithic-historical-28d8b7eafe49450ef1bd20939334baebbea0a367.zip |
crypto: make constant naming scheme consistent
Diffstat (limited to 'src/crypto/zinc/curve25519')
-rw-r--r-- | src/crypto/zinc/curve25519/curve25519-arm-glue.h | 16 | ||||
-rw-r--r-- | src/crypto/zinc/curve25519/curve25519-fiat32.h | 6 | ||||
-rw-r--r-- | src/crypto/zinc/curve25519/curve25519-hacl64.h | 6 | ||||
-rw-r--r-- | src/crypto/zinc/curve25519/curve25519-x86_64-glue.h | 10 | ||||
-rw-r--r-- | src/crypto/zinc/curve25519/curve25519-x86_64.h | 38 | ||||
-rw-r--r-- | src/crypto/zinc/curve25519/curve25519.c | 36 |
6 files changed, 56 insertions, 56 deletions
diff --git a/src/crypto/zinc/curve25519/curve25519-arm-glue.h b/src/crypto/zinc/curve25519/curve25519-arm-glue.h index 6b20931..9211bca 100644 --- a/src/crypto/zinc/curve25519/curve25519-arm-glue.h +++ b/src/crypto/zinc/curve25519/curve25519-arm-glue.h @@ -8,9 +8,9 @@ #include <asm/simd.h> #if defined(CONFIG_KERNEL_MODE_NEON) -asmlinkage void curve25519_neon(u8 mypublic[CURVE25519_POINT_SIZE], - const u8 secret[CURVE25519_POINT_SIZE], - const u8 basepoint[CURVE25519_POINT_SIZE]); +asmlinkage void curve25519_neon(u8 mypublic[CURVE25519_KEY_SIZE], + const u8 secret[CURVE25519_KEY_SIZE], + const u8 basepoint[CURVE25519_KEY_SIZE]); #endif static bool curve25519_use_neon __ro_after_init; @@ -20,9 +20,9 @@ static void __init curve25519_fpu_init(void) curve25519_use_neon = elf_hwcap & HWCAP_NEON; } -static inline bool curve25519_arch(u8 mypublic[CURVE25519_POINT_SIZE], - const u8 secret[CURVE25519_POINT_SIZE], - const u8 basepoint[CURVE25519_POINT_SIZE]) +static inline bool curve25519_arch(u8 mypublic[CURVE25519_KEY_SIZE], + const u8 secret[CURVE25519_KEY_SIZE], + const u8 basepoint[CURVE25519_KEY_SIZE]) { #if defined(CONFIG_KERNEL_MODE_NEON) if (curve25519_use_neon && may_use_simd()) { @@ -35,8 +35,8 @@ static inline bool curve25519_arch(u8 mypublic[CURVE25519_POINT_SIZE], return false; } -static inline bool curve25519_base_arch(u8 pub[CURVE25519_POINT_SIZE], - const u8 secret[CURVE25519_POINT_SIZE]) +static inline bool curve25519_base_arch(u8 pub[CURVE25519_KEY_SIZE], + const u8 secret[CURVE25519_KEY_SIZE]) { return false; } diff --git a/src/crypto/zinc/curve25519/curve25519-fiat32.h b/src/crypto/zinc/curve25519/curve25519-fiat32.h index e9d00c6..32b5ec7 100644 --- a/src/crypto/zinc/curve25519/curve25519-fiat32.h +++ b/src/crypto/zinc/curve25519/curve25519-fiat32.h @@ -749,9 +749,9 @@ static __always_inline void fe_mul121666(fe *h, const fe_loose *f) fe_mul_121666_impl(h->v, f->v); } -static void curve25519_generic(u8 out[CURVE25519_POINT_SIZE], - const u8 scalar[CURVE25519_POINT_SIZE], - const u8 point[CURVE25519_POINT_SIZE]) +static void curve25519_generic(u8 out[CURVE25519_KEY_SIZE], + const u8 scalar[CURVE25519_KEY_SIZE], + const u8 point[CURVE25519_KEY_SIZE]) { fe x1, x2, z2, x3, z3; fe_loose x2l, z2l, x3l; diff --git a/src/crypto/zinc/curve25519/curve25519-hacl64.h b/src/crypto/zinc/curve25519/curve25519-hacl64.h index 547deac..c7b2924 100644 --- a/src/crypto/zinc/curve25519/curve25519-hacl64.h +++ b/src/crypto/zinc/curve25519/curve25519-hacl64.h @@ -753,9 +753,9 @@ static __always_inline void format_scalar_of_point(u8 *scalar, u64 *point) format_fcontract(scalar, sc); } -static void curve25519_generic(u8 mypublic[CURVE25519_POINT_SIZE], - const u8 secret[CURVE25519_POINT_SIZE], - const u8 basepoint[CURVE25519_POINT_SIZE]) +static void curve25519_generic(u8 mypublic[CURVE25519_KEY_SIZE], + const u8 secret[CURVE25519_KEY_SIZE], + const u8 basepoint[CURVE25519_KEY_SIZE]) { u64 buf0[10] __aligned(32) = { 0 }; u64 *x0 = buf0; diff --git a/src/crypto/zinc/curve25519/curve25519-x86_64-glue.h b/src/crypto/zinc/curve25519/curve25519-x86_64-glue.h index 00dbfde..142e467 100644 --- a/src/crypto/zinc/curve25519/curve25519-x86_64-glue.h +++ b/src/crypto/zinc/curve25519/curve25519-x86_64-glue.h @@ -18,9 +18,9 @@ static void __init curve25519_fpu_init(void) boot_cpu_has(X86_FEATURE_ADX); } -static inline bool curve25519_arch(u8 mypublic[CURVE25519_POINT_SIZE], - const u8 secret[CURVE25519_POINT_SIZE], - const u8 basepoint[CURVE25519_POINT_SIZE]) +static inline bool curve25519_arch(u8 mypublic[CURVE25519_KEY_SIZE], + const u8 secret[CURVE25519_KEY_SIZE], + const u8 basepoint[CURVE25519_KEY_SIZE]) { if (curve25519_use_adx) { curve25519_adx(mypublic, secret, basepoint); @@ -32,8 +32,8 @@ static inline bool curve25519_arch(u8 mypublic[CURVE25519_POINT_SIZE], return false; } -static inline bool curve25519_base_arch(u8 pub[CURVE25519_POINT_SIZE], - const u8 secret[CURVE25519_POINT_SIZE]) +static inline bool curve25519_base_arch(u8 pub[CURVE25519_KEY_SIZE], + const u8 secret[CURVE25519_KEY_SIZE]) { if (curve25519_use_adx) { curve25519_adx_base(pub, secret); diff --git a/src/crypto/zinc/curve25519/curve25519-x86_64.h b/src/crypto/zinc/curve25519/curve25519-x86_64.h index 6c895f7..258a30d 100644 --- a/src/crypto/zinc/curve25519/curve25519-x86_64.h +++ b/src/crypto/zinc/curve25519/curve25519-x86_64.h @@ -1935,23 +1935,23 @@ static __always_inline void cselect(u8 bit, u64 *const px, const u64 *const py) ); } -static __always_inline void clamp_secret(u8 secret[CURVE25519_POINT_SIZE]) +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_POINT_SIZE], - const u8 private_key[CURVE25519_POINT_SIZE], - const u8 session_key[CURVE25519_POINT_SIZE]) +static void curve25519_adx(u8 shared[CURVE25519_KEY_SIZE], + const u8 private_key[CURVE25519_KEY_SIZE], + const u8 session_key[CURVE25519_KEY_SIZE]) { struct { u64 buffer[4 * NUM_WORDS_ELTFP25519]; u64 coordinates[4 * NUM_WORDS_ELTFP25519]; u64 workspace[6 * NUM_WORDS_ELTFP25519]; - u8 session[CURVE25519_POINT_SIZE]; - u8 private[CURVE25519_POINT_SIZE]; + u8 session[CURVE25519_KEY_SIZE]; + u8 private[CURVE25519_KEY_SIZE]; } __aligned(32) m; int i = 0, j = 0; @@ -1991,7 +1991,7 @@ static void curve25519_adx(u8 shared[CURVE25519_POINT_SIZE], * reserve the sign bit for use in other protocols and to * increase resistance to implementation fingerprinting */ - m.session[CURVE25519_POINT_SIZE - 1] &= (1 << (255 % 8)) - 1; + m.session[CURVE25519_KEY_SIZE - 1] &= (1 << (255 % 8)) - 1; copy_eltfp25519_1w(Px, X1); setzero_eltfp25519_1w(Pz); @@ -2043,14 +2043,14 @@ static void curve25519_adx(u8 shared[CURVE25519_POINT_SIZE], memzero_explicit(&m, sizeof(m)); } -static void curve25519_adx_base(u8 session_key[CURVE25519_POINT_SIZE], - const u8 private_key[CURVE25519_POINT_SIZE]) +static void curve25519_adx_base(u8 session_key[CURVE25519_KEY_SIZE], + const u8 private_key[CURVE25519_KEY_SIZE]) { struct { u64 buffer[4 * NUM_WORDS_ELTFP25519]; u64 coordinates[4 * NUM_WORDS_ELTFP25519]; u64 workspace[4 * NUM_WORDS_ELTFP25519]; - u8 private[CURVE25519_POINT_SIZE]; + u8 private[CURVE25519_KEY_SIZE]; } __aligned(32) m; const int ite[4] = { 64, 64, 64, 63 }; @@ -2137,16 +2137,16 @@ static void curve25519_adx_base(u8 session_key[CURVE25519_POINT_SIZE], memzero_explicit(&m, sizeof(m)); } -static void curve25519_bmi2(u8 shared[CURVE25519_POINT_SIZE], - const u8 private_key[CURVE25519_POINT_SIZE], - const u8 session_key[CURVE25519_POINT_SIZE]) +static void curve25519_bmi2(u8 shared[CURVE25519_KEY_SIZE], + const u8 private_key[CURVE25519_KEY_SIZE], + const u8 session_key[CURVE25519_KEY_SIZE]) { struct { u64 buffer[4 * NUM_WORDS_ELTFP25519]; u64 coordinates[4 * NUM_WORDS_ELTFP25519]; u64 workspace[6 * NUM_WORDS_ELTFP25519]; - u8 session[CURVE25519_POINT_SIZE]; - u8 private[CURVE25519_POINT_SIZE]; + u8 session[CURVE25519_KEY_SIZE]; + u8 private[CURVE25519_KEY_SIZE]; } __aligned(32) m; int i = 0, j = 0; @@ -2186,7 +2186,7 @@ static void curve25519_bmi2(u8 shared[CURVE25519_POINT_SIZE], * reserve the sign bit for use in other protocols and to * increase resistance to implementation fingerprinting */ - m.session[CURVE25519_POINT_SIZE - 1] &= (1 << (255 % 8)) - 1; + m.session[CURVE25519_KEY_SIZE - 1] &= (1 << (255 % 8)) - 1; copy_eltfp25519_1w(Px, X1); setzero_eltfp25519_1w(Pz); @@ -2238,14 +2238,14 @@ static void curve25519_bmi2(u8 shared[CURVE25519_POINT_SIZE], memzero_explicit(&m, sizeof(m)); } -static void curve25519_bmi2_base(u8 session_key[CURVE25519_POINT_SIZE], - const u8 private_key[CURVE25519_POINT_SIZE]) +static void curve25519_bmi2_base(u8 session_key[CURVE25519_KEY_SIZE], + const u8 private_key[CURVE25519_KEY_SIZE]) { struct { u64 buffer[4 * NUM_WORDS_ELTFP25519]; u64 coordinates[4 * NUM_WORDS_ELTFP25519]; u64 workspace[4 * NUM_WORDS_ELTFP25519]; - u8 private[CURVE25519_POINT_SIZE]; + u8 private[CURVE25519_KEY_SIZE]; } __aligned(32) m; const int ite[4] = { 64, 64, 64, 63 }; diff --git a/src/crypto/zinc/curve25519/curve25519.c b/src/crypto/zinc/curve25519/curve25519.c index fd46b36..a1f35aa 100644 --- a/src/crypto/zinc/curve25519/curve25519.c +++ b/src/crypto/zinc/curve25519/curve25519.c @@ -27,20 +27,20 @@ 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]) +static inline bool curve25519_arch(u8 mypublic[CURVE25519_KEY_SIZE], + const u8 secret[CURVE25519_KEY_SIZE], + const u8 basepoint[CURVE25519_KEY_SIZE]) { return false; } -static inline bool curve25519_base_arch(u8 pub[CURVE25519_POINT_SIZE], - const u8 secret[CURVE25519_POINT_SIZE]) +static inline bool curve25519_base_arch(u8 pub[CURVE25519_KEY_SIZE], + const u8 secret[CURVE25519_KEY_SIZE]) { return false; } #endif -static __always_inline void normalize_secret(u8 secret[CURVE25519_POINT_SIZE]) +static __always_inline void normalize_secret(u8 secret[CURVE25519_KEY_SIZE]) { secret[0] &= 248; secret[31] &= 127; @@ -53,35 +53,35 @@ static __always_inline void normalize_secret(u8 secret[CURVE25519_POINT_SIZE]) #include "curve25519-fiat32.h" #endif -static const u8 null_point[CURVE25519_POINT_SIZE] = { 0 }; +static const u8 null_point[CURVE25519_KEY_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_KEY_SIZE], + const u8 secret[CURVE25519_KEY_SIZE], + const u8 basepoint[CURVE25519_KEY_SIZE]) { if (!curve25519_arch(mypublic, secret, basepoint)) curve25519_generic(mypublic, secret, basepoint); - return crypto_memneq(mypublic, null_point, CURVE25519_POINT_SIZE); + return crypto_memneq(mypublic, null_point, CURVE25519_KEY_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_KEY_SIZE], + const u8 secret[CURVE25519_KEY_SIZE]) { - static const u8 basepoint[CURVE25519_POINT_SIZE] __aligned(32) = { 9 }; + static const u8 basepoint[CURVE25519_KEY_SIZE] __aligned(32) = { 9 }; - if (unlikely(!crypto_memneq(secret, null_point, CURVE25519_POINT_SIZE))) + if (unlikely(!crypto_memneq(secret, null_point, CURVE25519_KEY_SIZE))) return false; if (curve25519_base_arch(pub, secret)) - return crypto_memneq(pub, null_point, CURVE25519_POINT_SIZE); + return crypto_memneq(pub, null_point, CURVE25519_KEY_SIZE); return curve25519(pub, secret, basepoint); } EXPORT_SYMBOL(curve25519_generate_public); -void curve25519_generate_secret(u8 secret[CURVE25519_POINT_SIZE]) +void curve25519_generate_secret(u8 secret[CURVE25519_KEY_SIZE]) { - get_random_bytes_wait(secret, CURVE25519_POINT_SIZE); + get_random_bytes_wait(secret, CURVE25519_KEY_SIZE); normalize_secret(secret); } EXPORT_SYMBOL(curve25519_generate_secret); |