summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-07-14 13:30:53 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2017-07-20 03:37:39 +0200
commit06238bf0bb7f4e895edb78ab26cb2336dd06d06b (patch)
treed3ab6f8208f32019ef38cf2951fc09e39784e9e3 /src
parent86faeb83343b22e9a862b7f122a299b9d34f6779 (diff)
blake2s: fix up alignment issues
When it's unclear if block is aligned, we just assume unaligned, rather than branching. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src')
-rw-r--r--src/crypto/blake2s.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/crypto/blake2s.c b/src/crypto/blake2s.c
index 2337409..0115d44 100644
--- a/src/crypto/blake2s.c
+++ b/src/crypto/blake2s.c
@@ -8,6 +8,7 @@
#include <linux/types.h>
#include <linux/string.h>
#include <linux/kernel.h>
+#include <asm/unaligned.h>
typedef struct {
u8 digest_length;
@@ -68,12 +69,12 @@ static inline void blake2s_init_param(struct blake2s_state *state, const blake2s
p = (const u32 *)param;
/* IV XOR ParamBlock */
for (i = 0; i < 8; ++i)
- state->h[i] ^= le32_to_cpuvp(&p[i]);
+ state->h[i] ^= le32_to_cpu(p[i]);
}
void blake2s_init(struct blake2s_state *state, const u8 outlen)
{
- blake2s_param param = {
+ blake2s_param param __aligned(__alignof__(u32)) = {
.digest_length = outlen,
.fanout = 1,
.depth = 1
@@ -119,7 +120,7 @@ asmlinkage void blake2s_compress_avx(struct blake2s_state *state, const u8 * blo
void __init blake2s_fpu_init(void) { }
#endif
-static inline void blake2s_compress(struct blake2s_state *state, const u8 * block, size_t nblocks, u32 inc)
+static inline void blake2s_compress(struct blake2s_state *state, const u8 *block, size_t nblocks, u32 inc)
{
u32 m[16];
u32 v[16];
@@ -141,12 +142,13 @@ static inline void blake2s_compress(struct blake2s_state *state, const u8 * bloc
while (nblocks > 0) {
blake2s_increment_counter(state, inc);
- for (i = 0; i < 8; ++i)
- v[i] = state->h[i];
-
+#ifdef __LITTLE_ENDIAN
+ memcpy(m, block, BLAKE2S_BLOCKBYTES);
+#else
for (i = 0; i < 16; ++i)
- m[i] = le32_to_cpuvp(block + i * sizeof(m[i]));
-
+ m[i] = get_unaligned_le32(block + i * sizeof(m[i]));
+#endif
+ memcpy(v, state->h, 32);
v[ 8] = blake2s_iv[0];
v[ 9] = blake2s_iv[1];
v[10] = blake2s_iv[2];
@@ -224,7 +226,7 @@ void blake2s_update(struct blake2s_state *state, const u8 *in, u64 inlen)
void blake2s_final(struct blake2s_state *state, u8 *out, u8 outlen)
{
- u8 buffer[BLAKE2S_OUTBYTES] = { 0 };
+ u8 buffer[BLAKE2S_OUTBYTES] __aligned(__alignof__(u32)) = { 0 };
int i;
#ifdef DEBUG