aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/crypto/chacha20.h
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-08-23 18:08:03 -0700
committerJason A. Donenfeld <Jason@zx2c4.com>2018-08-28 23:20:13 -0600
commit1e7b209da908f815968f681d6ee4894a04399c97 (patch)
tree84c57fb3029513bfbe0313238b4563a8974af4c6 /src/crypto/chacha20.h
parentKconfig: use new-style help marker (diff)
downloadwireguard-monolithic-historical-1e7b209da908f815968f681d6ee4894a04399c97.tar.xz
wireguard-monolithic-historical-1e7b209da908f815968f681d6ee4894a04399c97.zip
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.
Diffstat (limited to 'src/crypto/chacha20.h')
-rw-r--r--src/crypto/chacha20.h18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/crypto/chacha20.h b/src/crypto/chacha20.h
index 86ea4e3..f3d408b 100644
--- a/src/crypto/chacha20.h
+++ b/src/crypto/chacha20.h
@@ -7,6 +7,7 @@
#define _WG_CHACHA20_H
#include "simd.h"
+#include <asm/unaligned.h>
#include <linux/kernel.h>
#include <linux/types.h>
@@ -27,15 +28,14 @@ void chacha20_fpu_init(void);
static inline void chacha20_init(struct chacha20_ctx *state, const u8 key[CHACHA20_KEY_SIZE], const u64 nonce)
{
- __le32 *le_key = (__le32 *)key;
- state->key[0] = le32_to_cpu(le_key[0]);
- state->key[1] = le32_to_cpu(le_key[1]);
- state->key[2] = le32_to_cpu(le_key[2]);
- state->key[3] = le32_to_cpu(le_key[3]);
- state->key[4] = le32_to_cpu(le_key[4]);
- state->key[5] = le32_to_cpu(le_key[5]);
- state->key[6] = le32_to_cpu(le_key[6]);
- state->key[7] = le32_to_cpu(le_key[7]);
+ state->key[0] = get_unaligned_le32(key + 0);
+ state->key[1] = get_unaligned_le32(key + 4);
+ state->key[2] = get_unaligned_le32(key + 8);
+ state->key[3] = get_unaligned_le32(key + 12);
+ state->key[4] = get_unaligned_le32(key + 16);
+ state->key[5] = get_unaligned_le32(key + 20);
+ state->key[6] = get_unaligned_le32(key + 24);
+ state->key[7] = get_unaligned_le32(key + 28);
state->counter[0] = state->counter[1] = 0;
state->counter[2] = nonce & U32_MAX;
state->counter[3] = nonce >> 32;