diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-11-04 14:38:04 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-11-04 14:38:04 +0100 |
commit | 1be1f3d19318475865b9556e9f0b4535150e0bc6 (patch) | |
tree | e8d4d41ebe110d2deea45f70b6998ac9455d3979 /src/crypto/chacha20poly1305.h | |
parent | send: queue bundles on same CPU (diff) | |
download | wireguard-monolithic-historical-1be1f3d19318475865b9556e9f0b4535150e0bc6.tar.xz wireguard-monolithic-historical-1be1f3d19318475865b9556e9f0b4535150e0bc6.zip |
data: keep FPU on when possible
Diffstat (limited to 'src/crypto/chacha20poly1305.h')
-rw-r--r-- | src/crypto/chacha20poly1305.h | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/crypto/chacha20poly1305.h b/src/crypto/chacha20poly1305.h index e9ecaf8..57d3d23 100644 --- a/src/crypto/chacha20poly1305.h +++ b/src/crypto/chacha20poly1305.h @@ -20,7 +20,8 @@ bool chacha20poly1305_encrypt(uint8_t *dst, const uint8_t *src, const size_t src bool chacha20poly1305_encrypt_sg(struct scatterlist *dst, struct scatterlist *src, const size_t src_len, const uint8_t *ad, const size_t ad_len, - const uint64_t nonce, const uint8_t key[static CHACHA20POLY1305_KEYLEN]); + const uint64_t nonce, const uint8_t key[static CHACHA20POLY1305_KEYLEN], + bool have_simd); bool chacha20poly1305_decrypt(uint8_t *dst, const uint8_t *src, const size_t src_len, const uint8_t *ad, const size_t ad_len, @@ -30,6 +31,34 @@ bool chacha20poly1305_decrypt_sg(struct scatterlist *dst, struct scatterlist *sr const uint8_t *ad, const size_t ad_len, const uint64_t nonce, const uint8_t key[static CHACHA20POLY1305_KEYLEN]); +#ifdef CONFIG_X86_64 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0) +#include <asm/fpu/api.h> +#include <asm/simd.h> +#else +#include <asm/i387.h> +#endif +#endif + +static inline bool chacha20poly1305_init_simd(void) +{ + bool have_simd = false; +#ifdef CONFIG_X86_64 + have_simd = irq_fpu_usable(); + if (have_simd) + kernel_fpu_begin(); +#endif + return have_simd; +} + +static inline void chacha20poly1305_deinit_simd(bool was_on) +{ +#ifdef CONFIG_X86_64 + if (was_on) + kernel_fpu_end(); +#endif +} + #ifdef DEBUG bool chacha20poly1305_selftest(void); #endif |