diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-02-01 16:21:51 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-03-09 13:47:23 +0100 |
commit | 186be2742c948351c27bc068102252e10a28959b (patch) | |
tree | 729fc328045a250e0f78a186455877a0bcff2ab1 /src/crypto/curve25519.c | |
parent | fd54417e41c13f021609bf4f328bd7b9b8411e30 (diff) |
curve25519: use precomp implementation instead of sandy2x
It's faster and doesn't use the FPU.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/crypto/curve25519.c')
-rw-r--r-- | src/crypto/curve25519.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/crypto/curve25519.c b/src/crypto/curve25519.c index eba94cd..8de8909 100644 --- a/src/crypto/curve25519.c +++ b/src/crypto/curve25519.c @@ -17,7 +17,7 @@ static __always_inline void normalize_secret(u8 secret[CURVE25519_POINT_SIZE]) secret[31] |= 64; } -#if defined(CONFIG_X86_64) && defined(CONFIG_AS_AVX) +#if defined(CONFIG_X86_64) #include "curve25519-x86_64.h" #elif IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && defined(CONFIG_ARM) #include "curve25519-arm.h" @@ -35,12 +35,12 @@ 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]) { -#if defined(CONFIG_X86_64) && defined(CONFIG_AS_AVX) - if (curve25519_use_avx && irq_fpu_usable()) { - kernel_fpu_begin(); - curve25519_sandy2x(mypublic, secret, basepoint); - kernel_fpu_end(); - } else +#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(); @@ -60,11 +60,13 @@ bool curve25519_generate_public(u8 pub[CURVE25519_POINT_SIZE], const u8 secret[C if (unlikely(!crypto_memneq(secret, null_point, CURVE25519_POINT_SIZE))) return false; -#if defined(CONFIG_X86_64) && defined(CONFIG_AS_AVX) - if (curve25519_use_avx && irq_fpu_usable()) { - kernel_fpu_begin(); - curve25519_sandy2x_base(pub, secret); - kernel_fpu_end(); +#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); return crypto_memneq(pub, null_point, CURVE25519_POINT_SIZE); } #endif |