diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-09-18 02:18:47 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-09-18 04:21:16 +0200 |
commit | f0ea799b1b0e920e4fd00d977dffa240f527bbee (patch) | |
tree | f86425e432311c170a5d5daf76c52c514ec3c3ef /src/crypto | |
parent | 79d03265d419bf9021144ad32a40cae8991ced97 (diff) |
crypto: allow for disabling simd in zinc modules
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/crypto')
-rw-r--r-- | src/crypto/zinc/blake2s/blake2s.c | 6 | ||||
-rw-r--r-- | src/crypto/zinc/chacha20/chacha20-x86_64-glue.h | 3 | ||||
-rw-r--r-- | src/crypto/zinc/chacha20/chacha20.c | 6 | ||||
-rw-r--r-- | src/crypto/zinc/curve25519/curve25519.c | 6 | ||||
-rw-r--r-- | src/crypto/zinc/poly1305/poly1305-x86_64-glue.h | 15 | ||||
-rw-r--r-- | src/crypto/zinc/poly1305/poly1305.c | 6 |
6 files changed, 33 insertions, 9 deletions
diff --git a/src/crypto/zinc/blake2s/blake2s.c b/src/crypto/zinc/blake2s/blake2s.c index 8cbaa6f..69b2b4e 100644 --- a/src/crypto/zinc/blake2s/blake2s.c +++ b/src/crypto/zinc/blake2s/blake2s.c @@ -278,13 +278,16 @@ EXPORT_SYMBOL(blake2s_hmac); #include "../selftest/blake2s.h" +static bool nosimd __initdata = false; + #ifndef COMPAT_ZINC_IS_A_MODULE int __init blake2s_mod_init(void) #else static int __init mod_init(void) #endif { - blake2s_fpu_init(); + if (!nosimd) + blake2s_fpu_init(); #ifdef DEBUG if (!blake2s_selftest()) return -ENOTRECOVERABLE; @@ -297,6 +300,7 @@ static void __exit mod_exit(void) { } +module_param(nosimd, bool, 0); module_init(mod_init); module_exit(mod_exit); MODULE_LICENSE("GPL v2"); diff --git a/src/crypto/zinc/chacha20/chacha20-x86_64-glue.h b/src/crypto/zinc/chacha20/chacha20-x86_64-glue.h index f3a7456..912bded 100644 --- a/src/crypto/zinc/chacha20/chacha20-x86_64-glue.h +++ b/src/crypto/zinc/chacha20/chacha20-x86_64-glue.h @@ -60,7 +60,8 @@ static inline bool chacha20_arch(u8 *dst, const u8 *src, const size_t len, const u32 key[8], const u32 counter[4], simd_context_t *simd_context) { - if (len <= CHACHA20_BLOCK_SIZE || !simd_use(simd_context)) + if (!chacha20_use_ssse3 || len <= CHACHA20_BLOCK_SIZE || + !simd_use(simd_context)) return false; #ifdef CONFIG_AS_AVX512 diff --git a/src/crypto/zinc/chacha20/chacha20.c b/src/crypto/zinc/chacha20/chacha20.c index 2b3644f..ef2404f 100644 --- a/src/crypto/zinc/chacha20/chacha20.c +++ b/src/crypto/zinc/chacha20/chacha20.c @@ -172,13 +172,16 @@ void hchacha20(u8 derived_key[CHACHA20_KEY_SIZE], } EXPORT_SYMBOL(hchacha20); +static bool nosimd __initdata = false; + #ifndef COMPAT_ZINC_IS_A_MODULE int __init chacha20_mod_init(void) #else static int __init mod_init(void) #endif { - chacha20_fpu_init(); + if (!nosimd) + chacha20_fpu_init(); return 0; } @@ -187,6 +190,7 @@ static void __exit mod_exit(void) { } +module_param(nosimd, bool, 0); module_init(mod_init); module_exit(mod_exit); MODULE_LICENSE("GPL v2"); diff --git a/src/crypto/zinc/curve25519/curve25519.c b/src/crypto/zinc/curve25519/curve25519.c index fca327f..a02070e 100644 --- a/src/crypto/zinc/curve25519/curve25519.c +++ b/src/crypto/zinc/curve25519/curve25519.c @@ -88,13 +88,16 @@ EXPORT_SYMBOL(curve25519_generate_secret); #include "../selftest/curve25519.h" +static bool nosimd __initdata = false; + #ifndef COMPAT_ZINC_IS_A_MODULE int __init curve25519_mod_init(void) #else static int __init mod_init(void) #endif { - curve25519_fpu_init(); + if (!nosimd) + curve25519_fpu_init(); #ifdef DEBUG if (!curve25519_selftest()) return -ENOTRECOVERABLE; @@ -107,6 +110,7 @@ static void __exit mod_exit(void) { } +module_param(nosimd, bool, 0); module_init(mod_init); module_exit(mod_exit); MODULE_LICENSE("GPL v2"); diff --git a/src/crypto/zinc/poly1305/poly1305-x86_64-glue.h b/src/crypto/zinc/poly1305/poly1305-x86_64-glue.h index 0ca3485..2158863 100644 --- a/src/crypto/zinc/poly1305/poly1305-x86_64-glue.h +++ b/src/crypto/zinc/poly1305/poly1305-x86_64-glue.h @@ -71,7 +71,8 @@ static inline bool poly1305_blocks_arch(void *ctx, const u8 *inp, { struct poly1305_arch_internal *state = ctx; - if ((len < (POLY1305_BLOCK_SIZE * 18) && !state->simd_is_engaged) || + if (!poly1305_use_avx || + (len < (POLY1305_BLOCK_SIZE * 18) && !state->simd_is_engaged) || !simd_use(simd_context)) poly1305_blocks_x86_64(ctx, inp, len, padbit); else @@ -98,18 +99,24 @@ static inline bool poly1305_emit_arch(void *ctx, u8 mac[POLY1305_MAC_SIZE], const u32 nonce[4], simd_context_t *simd_context) { + struct poly1305_arch_internal *state = ctx; + + if (!poly1305_use_avx || !state->simd_is_engaged || + !simd_use(simd_context)) + poly1305_emit_x86_64(ctx, mac, nonce); + else #ifdef CONFIG_AS_AVX512 - if (poly1305_use_avx512 && simd_use(simd_context)) + if (poly1305_use_avx512) poly1305_emit_avx(ctx, mac, nonce); else #endif #ifdef CONFIG_AS_AVX2 - if (poly1305_use_avx2 && simd_use(simd_context)) + if (poly1305_use_avx2) poly1305_emit_avx(ctx, mac, nonce); else #endif #ifdef CONFIG_AS_AVX - if (poly1305_use_avx && simd_use(simd_context)) + if (poly1305_use_avx) poly1305_emit_avx(ctx, mac, nonce); else #endif diff --git a/src/crypto/zinc/poly1305/poly1305.c b/src/crypto/zinc/poly1305/poly1305.c index 5377721..2add7aa 100644 --- a/src/crypto/zinc/poly1305/poly1305.c +++ b/src/crypto/zinc/poly1305/poly1305.c @@ -136,13 +136,16 @@ EXPORT_SYMBOL(poly1305_final); #include "../selftest/poly1305.h" +static bool nosimd __initdata = false; + #ifndef COMPAT_ZINC_IS_A_MODULE int __init poly1305_mod_init(void) #else static int __init mod_init(void) #endif { - poly1305_fpu_init(); + if (!nosimd) + poly1305_fpu_init(); #ifdef DEBUG if (!poly1305_selftest()) return -ENOTRECOVERABLE; @@ -155,6 +158,7 @@ static void __exit mod_exit(void) { } +module_param(nosimd, bool, 0); module_init(mod_init); module_exit(mod_exit); MODULE_LICENSE("GPL v2"); |