aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/crypto/chacha20poly1305.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-06-16 04:52:35 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-06-17 19:36:37 +0200
commit6d7f0b0a746b06a903ec8e14fe14cd0605fb210f (patch)
treed5d8a55faba0202587877594622ec89e6cadcd04 /src/crypto/chacha20poly1305.c
parentqueueing: re-enable preemption periodically to lower latency (diff)
downloadwireguard-monolithic-historical-6d7f0b0a746b06a903ec8e14fe14cd0605fb210f.tar.xz
wireguard-monolithic-historical-6d7f0b0a746b06a903ec8e14fe14cd0605fb210f.zip
simd: encapsulate fpu amortization into nice functions
Diffstat (limited to 'src/crypto/chacha20poly1305.c')
-rw-r--r--src/crypto/chacha20poly1305.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/crypto/chacha20poly1305.c b/src/crypto/chacha20poly1305.c
index ccc6e1c..df1c5aa 100644
--- a/src/crypto/chacha20poly1305.c
+++ b/src/crypto/chacha20poly1305.c
@@ -6,6 +6,7 @@
#include "chacha20poly1305.h"
#include "chacha20.h"
#include "poly1305.h"
+#include "simd.h"
#include <linux/kernel.h>
#include <crypto/scatterwalk.h>
@@ -65,9 +66,9 @@ void chacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
{
bool have_simd;
- have_simd = chacha20poly1305_init_simd();
+ have_simd = simd_get();
__chacha20poly1305_encrypt(dst, src, src_len, ad, ad_len, nonce, key, have_simd);
- chacha20poly1305_deinit_simd(have_simd);
+ simd_put(have_simd);
}
bool chacha20poly1305_encrypt_sg(struct scatterlist *dst, struct scatterlist *src, const size_t src_len,
@@ -176,9 +177,9 @@ bool chacha20poly1305_decrypt(u8 *dst, const u8 *src, const size_t src_len,
{
bool have_simd, ret;
- have_simd = chacha20poly1305_init_simd();
+ have_simd = simd_get();
ret = __chacha20poly1305_decrypt(dst, src, src_len, ad, ad_len, nonce, key, have_simd);
- chacha20poly1305_deinit_simd(have_simd);
+ simd_put(have_simd);
return ret;
}
@@ -253,13 +254,13 @@ void xchacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
const u8 nonce[XCHACHA20POLY1305_NONCELEN],
const u8 key[CHACHA20POLY1305_KEYLEN])
{
- bool have_simd = chacha20poly1305_init_simd();
+ bool have_simd = simd_get();
u8 derived_key[CHACHA20POLY1305_KEYLEN] __aligned(16);
hchacha20(derived_key, nonce, key, have_simd);
__chacha20poly1305_encrypt(dst, src, src_len, ad, ad_len, le64_to_cpup((__le64 *)(nonce + 16)), derived_key, have_simd);
memzero_explicit(derived_key, CHACHA20POLY1305_KEYLEN);
- chacha20poly1305_deinit_simd(have_simd);
+ simd_put(have_simd);
}
bool xchacha20poly1305_decrypt(u8 *dst, const u8 *src, const size_t src_len,
@@ -267,13 +268,13 @@ bool xchacha20poly1305_decrypt(u8 *dst, const u8 *src, const size_t src_len,
const u8 nonce[XCHACHA20POLY1305_NONCELEN],
const u8 key[CHACHA20POLY1305_KEYLEN])
{
- bool ret, have_simd = chacha20poly1305_init_simd();
+ bool ret, have_simd = simd_get();
u8 derived_key[CHACHA20POLY1305_KEYLEN] __aligned(16);
hchacha20(derived_key, nonce, key, have_simd);
ret = __chacha20poly1305_decrypt(dst, src, src_len, ad, ad_len, le64_to_cpup((__le64 *)(nonce + 16)), derived_key, have_simd);
memzero_explicit(derived_key, CHACHA20POLY1305_KEYLEN);
- chacha20poly1305_deinit_simd(have_simd);
+ simd_put(have_simd);
return ret;
}