Skip to content

Commit c013cee

Browse files
Ard Biesheuvelherbertx
authored andcommitted
crypto: sha3-generic - fixes for alignment and big endian operation
Ensure that the input is byte swabbed before injecting it into the SHA3 transform. Use the get_unaligned() accessor for this so that we don't perform unaligned access inadvertently on architectures that do not support that. Cc: <stable@vger.kernel.org> Fixes: 53964b9 ("crypto: sha3 - Add SHA-3 hash algorithm") Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 9c674e1 commit c013cee

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

crypto/sha3_generic.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/types.h>
1919
#include <crypto/sha3.h>
2020
#include <asm/byteorder.h>
21+
#include <asm/unaligned.h>
2122

2223
#define KECCAK_ROUNDS 24
2324

@@ -149,7 +150,7 @@ static int sha3_update(struct shash_desc *desc, const u8 *data,
149150
unsigned int i;
150151

151152
for (i = 0; i < sctx->rsizw; i++)
152-
sctx->st[i] ^= ((u64 *) src)[i];
153+
sctx->st[i] ^= get_unaligned_le64(src + 8 * i);
153154
keccakf(sctx->st);
154155

155156
done += sctx->rsiz;
@@ -174,7 +175,7 @@ static int sha3_final(struct shash_desc *desc, u8 *out)
174175
sctx->buf[sctx->rsiz - 1] |= 0x80;
175176

176177
for (i = 0; i < sctx->rsizw; i++)
177-
sctx->st[i] ^= ((u64 *) sctx->buf)[i];
178+
sctx->st[i] ^= get_unaligned_le64(sctx->buf + 8 * i);
178179

179180
keccakf(sctx->st);
180181

0 commit comments

Comments
 (0)