Skip to content

Commit

Permalink
crypto: sha512 - make it work, undo percpu message schedule
Browse files Browse the repository at this point in the history
commit f9e2bca
aka "crypto: sha512 - Move message schedule W[80] to static percpu area"
created global message schedule area.

If sha512_update will ever be entered twice, hash will be silently
calculated incorrectly.

Probably the easiest way to notice incorrect hashes being calculated is
to run 2 ping floods over AH with hmac(sha512):

	#!/usr/sbin/setkey -f
	flush;
	spdflush;
	add IP1 IP2 ah 25 -A hmac-sha512 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000025;
	add IP2 IP1 ah 52 -A hmac-sha512 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000052;
	spdadd IP1 IP2 any -P out ipsec ah/transport//require;
	spdadd IP2 IP1 any -P in  ipsec ah/transport//require;

XfrmInStateProtoError will start ticking with -EBADMSG being returned
from ah_input(). This never happens with, say, hmac(sha1).

With patch applied (on BOTH sides), XfrmInStateProtoError does not tick
with multiple bidirectional ping flood streams like it doesn't tick
with SHA-1.

After this patch sha512_transform() will start using ~750 bytes of stack on x86_64.
This is OK for simple loads, for something more heavy, stack reduction will be done
separatedly.

Signed-off-by: Alexey Dobriyan <[email protected]>
Cc: [email protected]
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
Alexey Dobriyan authored and herbertx committed Jan 15, 2012
1 parent 08c70fc commit 84e31fd
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions crypto/sha512_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
#include <linux/percpu.h>
#include <asm/byteorder.h>

static DEFINE_PER_CPU(u64[80], msg_schedule);

static inline u64 Ch(u64 x, u64 y, u64 z)
{
return z ^ (x & (y ^ z));
Expand Down Expand Up @@ -89,7 +87,7 @@ sha512_transform(u64 *state, const u8 *input)
u64 a, b, c, d, e, f, g, h, t1, t2;

int i;
u64 *W = get_cpu_var(msg_schedule);
u64 W[80];

/* load the input */
for (i = 0; i < 16; i++)
Expand Down Expand Up @@ -128,8 +126,6 @@ sha512_transform(u64 *state, const u8 *input)

/* erase our data */
a = b = c = d = e = f = g = h = t1 = t2 = 0;
memset(W, 0, sizeof(__get_cpu_var(msg_schedule)));
put_cpu_var(msg_schedule);
}

static int
Expand Down

0 comments on commit 84e31fd

Please sign in to comment.