Skip to content

Commit be34c4e

Browse files
davem330herbertx
authored andcommitted
crypto: sha - Handle unaligned input data in generic sha256 and sha512.
Like SHA1, use get_unaligned_be*() on the raw input data. Reported-by: Bob Picco <bob.picco@oracle.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 5cfed7b commit be34c4e

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

‎crypto/sha256_generic.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/types.h>
2525
#include <crypto/sha.h>
2626
#include <asm/byteorder.h>
27+
#include <asm/unaligned.h>
2728

2829
static inline u32 Ch(u32 x, u32 y, u32 z)
2930
{
@@ -42,7 +43,7 @@ static inline u32 Maj(u32 x, u32 y, u32 z)
4243

4344
static inline void LOAD_OP(int I, u32 *W, const u8 *input)
4445
{
45-
W[I] = __be32_to_cpu( ((__be32*)(input))[I] );
46+
W[I] = get_unaligned_be32((__u32 *)input + I);
4647
}
4748

4849
static inline void BLEND_OP(int I, u32 *W)

‎crypto/sha512_generic.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <crypto/sha.h>
2121
#include <linux/percpu.h>
2222
#include <asm/byteorder.h>
23+
#include <asm/unaligned.h>
2324

2425
static inline u64 Ch(u64 x, u64 y, u64 z)
2526
{
@@ -68,7 +69,7 @@ static const u64 sha512_K[80] = {
6869

6970
static inline void LOAD_OP(int I, u64 *W, const u8 *input)
7071
{
71-
W[I] = __be64_to_cpu( ((__be64*)(input))[I] );
72+
W[I] = get_unaligned_be64((__u64 *)input + I);
7273
}
7374

7475
static inline void BLEND_OP(int I, u64 *W)

0 commit comments

Comments
 (0)