From 470a0a36d579980431361f23e8f319d5c68aa4af Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 23 Aug 2018 18:08:03 -0700 Subject: 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 --- src/crypto/chacha20poly1305.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/crypto/chacha20poly1305.c') 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 #include #include @@ -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; -- cgit v1.2.3