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/chacha20.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/crypto/chacha20.c') diff --git a/src/crypto/chacha20.c b/src/crypto/chacha20.c index 815d777..c23928e 100644 --- a/src/crypto/chacha20.c +++ b/src/crypto/chacha20.c @@ -5,6 +5,7 @@ #include "chacha20.h" +#include #include #include @@ -210,9 +211,9 @@ static void hchacha20_generic(u8 derived_key[CHACHA20_KEY_SIZE], const u8 nonce[ __le32 *out = (__force __le32 *)derived_key; u32 x[] = { EXPAND_32_BYTE_K, - le32_to_cpup((__le32 *)(key + 0)), le32_to_cpup((__le32 *)(key + 4)), le32_to_cpup((__le32 *)(key + 8)), le32_to_cpup((__le32 *)(key + 12)), - le32_to_cpup((__le32 *)(key + 16)), le32_to_cpup((__le32 *)(key + 20)), le32_to_cpup((__le32 *)(key + 24)), le32_to_cpup((__le32 *)(key + 28)), - le32_to_cpup((__le32 *)(nonce + 0)), le32_to_cpup((__le32 *)(nonce + 4)), le32_to_cpup((__le32 *)(nonce + 8)), le32_to_cpup((__le32 *)(nonce + 12)) + get_unaligned_le32(key + 0), get_unaligned_le32(key + 4), get_unaligned_le32(key + 8), get_unaligned_le32(key + 12), + get_unaligned_le32(key + 16), get_unaligned_le32(key + 20), get_unaligned_le32(key + 24), get_unaligned_le32(key + 28), + get_unaligned_le32(nonce + 0), get_unaligned_le32(nonce + 4), get_unaligned_le32(nonce + 8), get_unaligned_le32(nonce + 12) }; TWENTY_ROUNDS(x); -- cgit v1.2.3