summaryrefslogtreecommitdiffhomepage
path: root/src/crypto/zinc
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-09-17 06:42:50 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-09-17 23:40:54 +0200
commit61450db1388ad8ef0936c114da8cbd2192fc2dc6 (patch)
tree12abaf0b74fae84e08d76046cafe5abc0243477b /src/crypto/zinc
parent514841a83b3ffe17aecd62345659254891333218 (diff)
poly1305-x86_64: don't activate simd for small blocks
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/crypto/zinc')
-rw-r--r--src/crypto/zinc/poly1305/poly1305-x86_64-glue.h17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/crypto/zinc/poly1305/poly1305-x86_64-glue.h b/src/crypto/zinc/poly1305/poly1305-x86_64-glue.h
index 1afd1c5..a884d22 100644
--- a/src/crypto/zinc/poly1305/poly1305-x86_64-glue.h
+++ b/src/crypto/zinc/poly1305/poly1305-x86_64-glue.h
@@ -61,22 +61,33 @@ static inline bool poly1305_init_arch(void *ctx,
return true;
}
+struct poly1305_arch_internal {
+ u32 state[5];
+ u32 simd_is_engaged;
+};
+
static inline bool poly1305_blocks_arch(void *ctx, const u8 *inp,
const size_t len, const u32 padbit,
simd_context_t *simd_context)
{
+ struct poly1305_arch_internal *state = ctx;
+
+ if ((len < (POLY1305_BLOCK_SIZE * 18) && !state->simd_is_engaged) ||
+ !simd_use(simd_context))
+ poly1305_blocks_x86_64(ctx, inp, len, padbit);
+ else
#ifdef CONFIG_AS_AVX512
- if (poly1305_use_avx512 && simd_use(simd_context))
+ if (poly1305_use_avx512)
poly1305_blocks_avx512(ctx, inp, len, padbit);
else
#endif
#ifdef CONFIG_AS_AVX2
- if (poly1305_use_avx2 && simd_use(simd_context))
+ if (poly1305_use_avx2)
poly1305_blocks_avx2(ctx, inp, len, padbit);
else
#endif
#ifdef CONFIG_AS_AVX
- if (poly1305_use_avx && simd_use(simd_context))
+ if (poly1305_use_avx)
poly1305_blocks_avx(ctx, inp, len, padbit);
else
#endif