diff options
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 |