diff mbox series

[v2,1/3] crypto/generic: sha3 - fixes for alignment and big endian operation

Message ID 20180114164118.18330-2-ard.biesheuvel@linaro.org
State Superseded
Headers show
Series sha3 fixes and new implementation for arm64 | expand

Commit Message

Ard Biesheuvel Jan. 14, 2018, 4:41 p.m. UTC
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.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

---
 crypto/sha3_generic.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

-- 
2.11.0

Comments

Chris Moore Jan. 15, 2018, 5:53 a.m. UTC | #1
Hi,

Le 14/01/2018 à 17:41, Ard Biesheuvel a écrit :
> Ensure that the input is byte swabbed before injecting it into the


Nitpick : s/swabbed/swapped/

> 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.

>

> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>


Cheers,
Chris
Ard Biesheuvel Jan. 15, 2018, 8:44 a.m. UTC | #2
On 15 January 2018 at 05:53, Chris Moore <moore@free.fr> wrote:
> Hi,

>

> Le 14/01/2018 à 17:41, Ard Biesheuvel a écrit :

>>

>> Ensure that the input is byte swabbed before injecting it into the

>

>

> Nitpick : s/swabbed/swapped/

>


Thanks Chris - byte swapping is often referred to as swabbing, but I
guess 'byte swabbing' is redundant regardless.

>> 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.

>>

>> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

>

>

> Cheers,

> Chris

>
diff mbox series

Patch

diff --git a/crypto/sha3_generic.c b/crypto/sha3_generic.c
index 7e8ed96236ce..a68be626017c 100644
--- a/crypto/sha3_generic.c
+++ b/crypto/sha3_generic.c
@@ -18,6 +18,7 @@ 
 #include <linux/types.h>
 #include <crypto/sha3.h>
 #include <asm/byteorder.h>
+#include <asm/unaligned.h>
 
 #define KECCAK_ROUNDS 24
 
@@ -149,7 +150,7 @@  static int sha3_update(struct shash_desc *desc, const u8 *data,
 			unsigned int i;
 
 			for (i = 0; i < sctx->rsizw; i++)
-				sctx->st[i] ^= ((u64 *) src)[i];
+				sctx->st[i] ^= get_unaligned_le64(src + 8 * i);
 			keccakf(sctx->st);
 
 			done += sctx->rsiz;
@@ -174,7 +175,7 @@  static int sha3_final(struct shash_desc *desc, u8 *out)
 	sctx->buf[sctx->rsiz - 1] |= 0x80;
 
 	for (i = 0; i < sctx->rsizw; i++)
-		sctx->st[i] ^= ((u64 *) sctx->buf)[i];
+		sctx->st[i] ^= get_unaligned_le64(sctx->buf + 8 * i);
 
 	keccakf(sctx->st);