Skip to content

Commit

Permalink
crypto: sha - Handle unaligned input data in generic sha256 and sha512.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
davem330 authored and herbertx committed Oct 2, 2014
1 parent 5cfed7b commit be34c4e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion crypto/sha256_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <linux/types.h>
#include <crypto/sha.h>
#include <asm/byteorder.h>
#include <asm/unaligned.h>

static inline u32 Ch(u32 x, u32 y, u32 z)
{
Expand All @@ -42,7 +43,7 @@ static inline u32 Maj(u32 x, u32 y, u32 z)

static inline void LOAD_OP(int I, u32 *W, const u8 *input)
{
W[I] = __be32_to_cpu( ((__be32*)(input))[I] );
W[I] = get_unaligned_be32((__u32 *)input + I);
}

static inline void BLEND_OP(int I, u32 *W)
Expand Down
3 changes: 2 additions & 1 deletion crypto/sha512_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <crypto/sha.h>
#include <linux/percpu.h>
#include <asm/byteorder.h>
#include <asm/unaligned.h>

static inline u64 Ch(u64 x, u64 y, u64 z)
{
Expand Down Expand Up @@ -68,7 +69,7 @@ static const u64 sha512_K[80] = {

static inline void LOAD_OP(int I, u64 *W, const u8 *input)
{
W[I] = __be64_to_cpu( ((__be64*)(input))[I] );
W[I] = get_unaligned_be64((__u64 *)input + I);
}

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

0 comments on commit be34c4e

Please sign in to comment.