diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-08-23 18:08:03 -0700 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-08-28 23:20:13 -0600 |
commit | 470a0a36d579980431361f23e8f319d5c68aa4af (patch) | |
tree | 624317ee7c194f1a8ec61137726adb1215ff276a /src/crypto/chacha20poly1305.c | |
parent | 4e71a11616a7763219e23bd34708751a702c80c7 (diff) |
crypto: use unaligned helpers
This is not useful for WireGuard, but for the general use case we
probably want it this way, and the speed difference is mostly lost in
the noise.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/crypto/chacha20poly1305.c')
-rw-r--r-- | src/crypto/chacha20poly1305.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/crypto/chacha20poly1305.c b/src/crypto/chacha20poly1305.c index 30d5444..3e3af5b 100644 --- a/src/crypto/chacha20poly1305.c +++ b/src/crypto/chacha20poly1305.c @@ -7,6 +7,7 @@ #include "chacha20.h" #include "poly1305.h" +#include <asm/unaligned.h> #include <linux/kernel.h> #include <crypto/scatterwalk.h> @@ -256,7 +257,7 @@ void xchacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len, u8 derived_key[CHACHA20POLY1305_KEYLEN] __aligned(16); hchacha20(derived_key, nonce, key, simd_context); - __chacha20poly1305_encrypt(dst, src, src_len, ad, ad_len, le64_to_cpup((__le64 *)(nonce + 16)), derived_key, simd_context); + __chacha20poly1305_encrypt(dst, src, src_len, ad, ad_len, get_unaligned_le64(nonce + 16), derived_key, simd_context); memzero_explicit(derived_key, CHACHA20POLY1305_KEYLEN); simd_put(simd_context); } @@ -270,7 +271,7 @@ bool xchacha20poly1305_decrypt(u8 *dst, const u8 *src, const size_t src_len, u8 derived_key[CHACHA20POLY1305_KEYLEN] __aligned(16); hchacha20(derived_key, nonce, key, simd_context); - ret = __chacha20poly1305_decrypt(dst, src, src_len, ad, ad_len, le64_to_cpup((__le64 *)(nonce + 16)), derived_key, simd_context); + ret = __chacha20poly1305_decrypt(dst, src, src_len, ad, ad_len, get_unaligned_le64(nonce + 16), derived_key, simd_context); memzero_explicit(derived_key, CHACHA20POLY1305_KEYLEN); simd_put(simd_context); return ret; |