aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/crypto/blake2s.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-03-16 19:38:59 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2017-03-19 23:11:31 +0100
commit74957884685c3c3df9ef9540d2ff517017497a89 (patch)
tree271fcd34a9b21471420f957249ff67cb5963b318 /src/crypto/blake2s.c
parentconfig: satisfy sparse (diff)
downloadwireguard-monolithic-historical-74957884685c3c3df9ef9540d2ff517017497a89.tar.xz
wireguard-monolithic-historical-74957884685c3c3df9ef9540d2ff517017497a89.zip
blake2s: add AVX implementation
Diffstat (limited to 'src/crypto/blake2s.c')
-rw-r--r--src/crypto/blake2s.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/crypto/blake2s.c b/src/crypto/blake2s.c
index 8b4aaab..9610135 100644
--- a/src/crypto/blake2s.c
+++ b/src/crypto/blake2s.c
@@ -104,12 +104,36 @@ void blake2s_init_key(struct blake2s_state *state, const u8 outlen, const void *
memzero_explicit(block, BLAKE2S_BLOCKBYTES);
}
+#ifdef CONFIG_X86_64
+#include <asm/cpufeature.h>
+#include <asm/processor.h>
+#include <asm/fpu/api.h>
+#include <asm/simd.h>
+static bool blake2s_use_avx __read_mostly = false;
+void blake2s_fpu_init(void)
+{
+ blake2s_use_avx = boot_cpu_has(X86_FEATURE_AVX);
+}
+asmlinkage void blake2s_compress_avx(struct blake2s_state *state, const u8 block[BLAKE2S_BLOCKBYTES]);
+#else
+void blake2s_fpu_init(void) { }
+#endif
+
static inline void blake2s_compress(struct blake2s_state *state, const u8 block[BLAKE2S_BLOCKBYTES])
{
u32 m[16];
u32 v[16];
int i;
+#ifdef CONFIG_X86_64
+ if (blake2s_use_avx && irq_fpu_usable()) {
+ kernel_fpu_begin();
+ blake2s_compress_avx(state, block);
+ kernel_fpu_end();
+ return;
+ }
+#endif
+
for (i = 0; i < 16; ++i)
m[i] = le32_to_cpuvp(block + i * sizeof(m[i]));