Commit 87f71ae2 authored by Linus Torvalds's avatar Linus Torvalds

Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6

* git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6:
  crypto: sha512 - reduce stack usage to safe number
  crypto: sha512 - make it work, undo percpu message schedule
parents aaad641e 51fc6dc8
...@@ -21,8 +21,6 @@ ...@@ -21,8 +21,6 @@
#include <linux/percpu.h> #include <linux/percpu.h>
#include <asm/byteorder.h> #include <asm/byteorder.h>
static DEFINE_PER_CPU(u64[80], msg_schedule);
static inline u64 Ch(u64 x, u64 y, u64 z) static inline u64 Ch(u64 x, u64 y, u64 z)
{ {
return z ^ (x & (y ^ z)); return z ^ (x & (y ^ z));
...@@ -80,7 +78,7 @@ static inline void LOAD_OP(int I, u64 *W, const u8 *input) ...@@ -80,7 +78,7 @@ static inline void LOAD_OP(int I, u64 *W, const u8 *input)
static inline void BLEND_OP(int I, u64 *W) static inline void BLEND_OP(int I, u64 *W)
{ {
W[I] = s1(W[I-2]) + W[I-7] + s0(W[I-15]) + W[I-16]; W[I % 16] += s1(W[(I-2) % 16]) + W[(I-7) % 16] + s0(W[(I-15) % 16]);
} }
static void static void
...@@ -89,38 +87,48 @@ sha512_transform(u64 *state, const u8 *input) ...@@ -89,38 +87,48 @@ sha512_transform(u64 *state, const u8 *input)
u64 a, b, c, d, e, f, g, h, t1, t2; u64 a, b, c, d, e, f, g, h, t1, t2;
int i; int i;
u64 *W = get_cpu_var(msg_schedule); u64 W[16];
/* load the input */ /* load the input */
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
LOAD_OP(i, W, input); LOAD_OP(i, W, input);
for (i = 16; i < 80; i++) {
BLEND_OP(i, W);
}
/* load the state into our registers */ /* load the state into our registers */
a=state[0]; b=state[1]; c=state[2]; d=state[3]; a=state[0]; b=state[1]; c=state[2]; d=state[3];
e=state[4]; f=state[5]; g=state[6]; h=state[7]; e=state[4]; f=state[5]; g=state[6]; h=state[7];
/* now iterate */ #define SHA512_0_15(i, a, b, c, d, e, f, g, h) \
for (i=0; i<80; i+=8) { t1 = h + e1(e) + Ch(e, f, g) + sha512_K[i] + W[i]; \
t1 = h + e1(e) + Ch(e,f,g) + sha512_K[i ] + W[i ]; t2 = e0(a) + Maj(a, b, c); \
t2 = e0(a) + Maj(a,b,c); d+=t1; h=t1+t2; d += t1; \
t1 = g + e1(d) + Ch(d,e,f) + sha512_K[i+1] + W[i+1]; h = t1 + t2
t2 = e0(h) + Maj(h,a,b); c+=t1; g=t1+t2;
t1 = f + e1(c) + Ch(c,d,e) + sha512_K[i+2] + W[i+2]; #define SHA512_16_79(i, a, b, c, d, e, f, g, h) \
t2 = e0(g) + Maj(g,h,a); b+=t1; f=t1+t2; BLEND_OP(i, W); \
t1 = e + e1(b) + Ch(b,c,d) + sha512_K[i+3] + W[i+3]; t1 = h + e1(e) + Ch(e, f, g) + sha512_K[i] + W[(i)%16]; \
t2 = e0(f) + Maj(f,g,h); a+=t1; e=t1+t2; t2 = e0(a) + Maj(a, b, c); \
t1 = d + e1(a) + Ch(a,b,c) + sha512_K[i+4] + W[i+4]; d += t1; \
t2 = e0(e) + Maj(e,f,g); h+=t1; d=t1+t2; h = t1 + t2
t1 = c + e1(h) + Ch(h,a,b) + sha512_K[i+5] + W[i+5];
t2 = e0(d) + Maj(d,e,f); g+=t1; c=t1+t2; for (i = 0; i < 16; i += 8) {
t1 = b + e1(g) + Ch(g,h,a) + sha512_K[i+6] + W[i+6]; SHA512_0_15(i, a, b, c, d, e, f, g, h);
t2 = e0(c) + Maj(c,d,e); f+=t1; b=t1+t2; SHA512_0_15(i + 1, h, a, b, c, d, e, f, g);
t1 = a + e1(f) + Ch(f,g,h) + sha512_K[i+7] + W[i+7]; SHA512_0_15(i + 2, g, h, a, b, c, d, e, f);
t2 = e0(b) + Maj(b,c,d); e+=t1; a=t1+t2; SHA512_0_15(i + 3, f, g, h, a, b, c, d, e);
SHA512_0_15(i + 4, e, f, g, h, a, b, c, d);
SHA512_0_15(i + 5, d, e, f, g, h, a, b, c);
SHA512_0_15(i + 6, c, d, e, f, g, h, a, b);
SHA512_0_15(i + 7, b, c, d, e, f, g, h, a);
}
for (i = 16; i < 80; i += 8) {
SHA512_16_79(i, a, b, c, d, e, f, g, h);
SHA512_16_79(i + 1, h, a, b, c, d, e, f, g);
SHA512_16_79(i + 2, g, h, a, b, c, d, e, f);
SHA512_16_79(i + 3, f, g, h, a, b, c, d, e);
SHA512_16_79(i + 4, e, f, g, h, a, b, c, d);
SHA512_16_79(i + 5, d, e, f, g, h, a, b, c);
SHA512_16_79(i + 6, c, d, e, f, g, h, a, b);
SHA512_16_79(i + 7, b, c, d, e, f, g, h, a);
} }
state[0] += a; state[1] += b; state[2] += c; state[3] += d; state[0] += a; state[1] += b; state[2] += c; state[3] += d;
...@@ -128,8 +136,6 @@ sha512_transform(u64 *state, const u8 *input) ...@@ -128,8 +136,6 @@ sha512_transform(u64 *state, const u8 *input)
/* erase our data */ /* erase our data */
a = b = c = d = e = f = g = h = t1 = t2 = 0; 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 static int
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment