Skip to content

Commit d00e708

Browse files
atsushi-nemotoherbertx
authored andcommitted
[CRYPTO] khazad: Use 32-bit reads on key
On 64-bit platform, reading 64-bit keys (which is supposed to be 32-bit aligned) at a time will result in unaligned access. Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent fcc18e8 commit d00e708

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎crypto/khazad.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ static int khazad_setkey(void *ctx_arg, const u8 *in_key,
758758
unsigned int key_len, u32 *flags)
759759
{
760760
struct khazad_ctx *ctx = ctx_arg;
761-
const __be64 *key = (const __be64 *)in_key;
761+
const __be32 *key = (const __be32 *)in_key;
762762
int r;
763763
const u64 *S = T7;
764764
u64 K2, K1;
@@ -769,8 +769,9 @@ static int khazad_setkey(void *ctx_arg, const u8 *in_key,
769769
return -EINVAL;
770770
}
771771

772-
K2 = be64_to_cpu(key[0]);
773-
K1 = be64_to_cpu(key[1]);
772+
/* key is supposed to be 32-bit aligned */
773+
K2 = ((u64)be32_to_cpu(key[0]) << 32) | be32_to_cpu(key[1]);
774+
K1 = ((u64)be32_to_cpu(key[2]) << 32) | be32_to_cpu(key[3]);
774775

775776
/* setup the encrypt key */
776777
for (r = 0; r <= KHAZAD_ROUNDS; r++) {

0 commit comments

Comments
 (0)