summaryrefslogtreecommitdiffhomepage
path: root/src/crypto/zinc/chacha20poly1305.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/crypto/zinc/chacha20poly1305.c')
-rw-r--r--src/crypto/zinc/chacha20poly1305.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/crypto/zinc/chacha20poly1305.c b/src/crypto/zinc/chacha20poly1305.c
index 92a5b9c..7a8e03f 100644
--- a/src/crypto/zinc/chacha20poly1305.c
+++ b/src/crypto/zinc/chacha20poly1305.c
@@ -33,7 +33,7 @@ static inline void
__chacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
const u8 *ad, const size_t ad_len, const u64 nonce,
const u8 key[CHACHA20POLY1305_KEYLEN],
- simd_context_t simd_context)
+ simd_context_t *simd_context)
{
struct poly1305_ctx poly1305_state;
struct chacha20_ctx chacha20_state;
@@ -75,10 +75,10 @@ void chacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
{
simd_context_t simd_context;
- simd_context = simd_get();
+ simd_get(&simd_context);
__chacha20poly1305_encrypt(dst, src, src_len, ad, ad_len, nonce, key,
- simd_context);
- simd_put(simd_context);
+ &simd_context);
+ simd_put(&simd_context);
}
EXPORT_SYMBOL(chacha20poly1305_encrypt);
@@ -87,7 +87,7 @@ bool chacha20poly1305_encrypt_sg(struct scatterlist *dst,
const u8 *ad, const size_t ad_len,
const u64 nonce,
const u8 key[CHACHA20POLY1305_KEYLEN],
- simd_context_t simd_context)
+ simd_context_t *simd_context)
{
struct poly1305_ctx poly1305_state;
struct chacha20_ctx chacha20_state;
@@ -155,7 +155,7 @@ static inline bool
__chacha20poly1305_decrypt(u8 *dst, const u8 *src, const size_t src_len,
const u8 *ad, const size_t ad_len, const u64 nonce,
const u8 key[CHACHA20POLY1305_KEYLEN],
- simd_context_t simd_context)
+ simd_context_t *simd_context)
{
struct poly1305_ctx poly1305_state;
struct chacha20_ctx chacha20_state;
@@ -208,10 +208,10 @@ bool chacha20poly1305_decrypt(u8 *dst, const u8 *src, const size_t src_len,
{
simd_context_t simd_context, ret;
- simd_context = simd_get();
+ simd_get(&simd_context);
ret = __chacha20poly1305_decrypt(dst, src, src_len, ad, ad_len, nonce,
- key, simd_context);
- simd_put(simd_context);
+ key, &simd_context);
+ simd_put(&simd_context);
return ret;
}
EXPORT_SYMBOL(chacha20poly1305_decrypt);
@@ -221,7 +221,7 @@ bool chacha20poly1305_decrypt_sg(struct scatterlist *dst,
const u8 *ad, const size_t ad_len,
const u64 nonce,
const u8 key[CHACHA20POLY1305_KEYLEN],
- simd_context_t simd_context)
+ simd_context_t *simd_context)
{
struct poly1305_ctx poly1305_state;
struct chacha20_ctx chacha20_state;
@@ -300,15 +300,16 @@ void xchacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
const u8 nonce[XCHACHA20POLY1305_NONCELEN],
const u8 key[CHACHA20POLY1305_KEYLEN])
{
- simd_context_t simd_context = simd_get();
+ simd_context_t simd_context;
u8 derived_key[CHACHA20POLY1305_KEYLEN] __aligned(16);
- hchacha20(derived_key, nonce, key, simd_context);
+ simd_get(&simd_context);
+ hchacha20(derived_key, nonce, key, &simd_context);
__chacha20poly1305_encrypt(dst, src, src_len, ad, ad_len,
get_unaligned_le64(nonce + 16),
- derived_key, simd_context);
+ derived_key, &simd_context);
memzero_explicit(derived_key, CHACHA20POLY1305_KEYLEN);
- simd_put(simd_context);
+ simd_put(&simd_context);
}
EXPORT_SYMBOL(xchacha20poly1305_encrypt);
@@ -317,15 +318,17 @@ 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, simd_context = simd_get();
+ bool ret;
+ simd_context_t simd_context;
u8 derived_key[CHACHA20POLY1305_KEYLEN] __aligned(16);
- hchacha20(derived_key, nonce, key, simd_context);
+ simd_get(&simd_context);
+ hchacha20(derived_key, nonce, key, &simd_context);
ret = __chacha20poly1305_decrypt(dst, src, src_len, ad, ad_len,
get_unaligned_le64(nonce + 16),
- derived_key, simd_context);
+ derived_key, &simd_context);
memzero_explicit(derived_key, CHACHA20POLY1305_KEYLEN);
- simd_put(simd_context);
+ simd_put(&simd_context);
return ret;
}
EXPORT_SYMBOL(xchacha20poly1305_decrypt);