diff options
author | Alexey Dobriyan <adobriyan@gmail.com> | 2012-01-14 13:27:37 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2012-01-14 20:39:17 -0500 |
commit | 84e31fdb7c797a7303e0cc295cb9bc8b73fb872d (patch) | |
tree | 2faa3f9c8a36ad97da8de1f269b979158d51f11b | |
parent | 08c70fc3a239475122e20b7a21dfae4c264c24f7 (diff) |
crypto: sha512 - make it work, undo percpu message schedule
commit f9e2bca6c22d75a289a349f869701214d63b5060
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 <adobriyan@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | crypto/sha512_generic.c | 6 |
1 files changed, 1 insertions, 5 deletions
diff --git a/crypto/sha512_generic.c b/crypto/sha512_generic.c index 9ed9f60316e5..8b9035b0189c 100644 --- a/crypto/sha512_generic.c +++ b/crypto/sha512_generic.c | |||
@@ -21,8 +21,6 @@ | |||
21 | #include <linux/percpu.h> | 21 | #include <linux/percpu.h> |
22 | #include <asm/byteorder.h> | 22 | #include <asm/byteorder.h> |
23 | 23 | ||
24 | static DEFINE_PER_CPU(u64[80], msg_schedule); | ||
25 | |||
26 | static inline u64 Ch(u64 x, u64 y, u64 z) | 24 | static inline u64 Ch(u64 x, u64 y, u64 z) |
27 | { | 25 | { |
28 | return z ^ (x & (y ^ z)); | 26 | return z ^ (x & (y ^ z)); |
@@ -89,7 +87,7 @@ sha512_transform(u64 *state, const u8 *input) | |||
89 | u64 a, b, c, d, e, f, g, h, t1, t2; | 87 | u64 a, b, c, d, e, f, g, h, t1, t2; |
90 | 88 | ||
91 | int i; | 89 | int i; |
92 | u64 *W = get_cpu_var(msg_schedule); | 90 | u64 W[80]; |
93 | 91 | ||
94 | /* load the input */ | 92 | /* load the input */ |
95 | for (i = 0; i < 16; i++) | 93 | for (i = 0; i < 16; i++) |
@@ -128,8 +126,6 @@ sha512_transform(u64 *state, const u8 *input) | |||
128 | 126 | ||
129 | /* erase our data */ | 127 | /* erase our data */ |
130 | a = b = c = d = e = f = g = h = t1 = t2 = 0; | 128 | a = b = c = d = e = f = g = h = t1 = t2 = 0; |
131 | memset(W, 0, sizeof(__get_cpu_var(msg_schedule))); | ||
132 | put_cpu_var(msg_schedule); | ||
133 | } | 129 | } |
134 | 130 | ||
135 | static int | 131 | static int |