aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-11-11 16:06:56 -0500
committerJason A. Donenfeld <Jason@zx2c4.com>2018-11-11 16:06:56 -0500
commit7a45413771553a372b8b1db7eb99260e778d4414 (patch)
tree2138cb2043051a750a4d289b3390d251324cd216
parentchacha20: import .pl for chacha20 (diff)
downloadWireGuard-jd/maybe-sse2.tar.xz
WireGuard-jd/maybe-sse2.zip
chacha20: enable sse2 pathjd/maybe-sse2
-rw-r--r--src/crypto/zinc/chacha20/chacha20-x86_64-glue.c9
-rw-r--r--src/crypto/zinc/chacha20/chacha20-x86_64.pl12
2 files changed, 12 insertions, 9 deletions
diff --git a/src/crypto/zinc/chacha20/chacha20-x86_64-glue.c b/src/crypto/zinc/chacha20/chacha20-x86_64-glue.c
index f5a9c21..49a7105 100644
--- a/src/crypto/zinc/chacha20/chacha20-x86_64-glue.c
+++ b/src/crypto/zinc/chacha20/chacha20-x86_64-glue.c
@@ -10,6 +10,8 @@
asmlinkage void hchacha20_ssse3(u32 *derived_key, const u8 *nonce,
const u8 *key);
+asmlinkage void chacha20_sse2(u8 *out, const u8 *in, const size_t len,
+ const u32 key[8], const u32 counter[4]);
asmlinkage void chacha20_ssse3(u8 *out, const u8 *in, const size_t len,
const u32 key[8], const u32 counter[4]);
asmlinkage void chacha20_avx2(u8 *out, const u8 *in, const size_t len,
@@ -61,8 +63,7 @@ static inline bool chacha20_arch(struct chacha20_ctx *ctx, u8 *dst,
BUILD_BUG_ON(PAGE_SIZE < CHACHA20_BLOCK_SIZE ||
PAGE_SIZE % CHACHA20_BLOCK_SIZE);
- if (!IS_ENABLED(CONFIG_AS_SSSE3) || !chacha20_use_ssse3 ||
- len <= CHACHA20_BLOCK_SIZE || !simd_use(simd_context))
+ if (len <= CHACHA20_BLOCK_SIZE || !simd_use(simd_context))
return false;
for (;;) {
@@ -77,8 +78,10 @@ static inline bool chacha20_arch(struct chacha20_ctx *ctx, u8 *dst,
else if (IS_ENABLED(CONFIG_AS_AVX2) && chacha20_use_avx2 &&
len >= CHACHA20_BLOCK_SIZE * 4)
chacha20_avx2(dst, src, bytes, ctx->key, ctx->counter);
- else
+ else if (IS_ENABLED(CONFIG_AS_SSSE3) && chacha20_use_ssse3)
chacha20_ssse3(dst, src, bytes, ctx->key, ctx->counter);
+ else
+ chacha20_sse2(dst, src, bytes, ctx->key, ctx->counter);
ctx->counter[0] += (bytes + 63) / 64;
len -= bytes;
if (!len)
diff --git a/src/crypto/zinc/chacha20/chacha20-x86_64.pl b/src/crypto/zinc/chacha20/chacha20-x86_64.pl
index 3471ad6..d6e7f8a 100644
--- a/src/crypto/zinc/chacha20/chacha20-x86_64.pl
+++ b/src/crypto/zinc/chacha20/chacha20-x86_64.pl
@@ -272,7 +272,7 @@ my @x=map("\"$_\"",@x);
########################################################################
# Generic code path that handles all lengths on pre-SSSE3 processors.
-&declare_function("ChaCha20_ctr32", 64);
+&declare_function("chacha20_sse2", 64);
$code.=<<___;
.cfi_startproc
cmp \$0,$len
@@ -465,7 +465,7 @@ $code.=<<___;
ret
.cfi_endproc
___
-&end_function("ChaCha20_ctr32");
+&end_function("chacha20_sse2");
########################################################################
# SSSE3 code path that handles shorter lengths
@@ -3967,9 +3967,9 @@ simd_handler:
.section .pdata
.align 4
- .rva .LSEH_begin_ChaCha20_ctr32
- .rva .LSEH_end_ChaCha20_ctr32
- .rva .LSEH_info_ChaCha20_ctr32
+ .rva .LSEH_begin_chacha20_sse2
+ .rva .LSEH_end_chacha20_sse2
+ .rva .LSEH_info_chacha20_sse2
.rva .LSEH_begin_ChaCha20_ssse3
.rva .LSEH_end_ChaCha20_ssse3
@@ -4013,7 +4013,7 @@ ___
$code.=<<___;
.section .xdata
.align 8
-.LSEH_info_ChaCha20_ctr32:
+.LSEH_info_chacha20_sse2:
.byte 9,0,0,0
.rva se_handler