diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-01-25 22:28:58 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-01-25 22:28:58 -0500 |
| commit | 87f71ae2dd7471c1b4c94100be1f218e91dc64c3 (patch) | |
| tree | 75fe76250fa1cbba7d43a46da112b917e4486b8a | |
| parent | aaad641eadfd3e74b0fbb68fcf539b9cef0415d0 (diff) | |
| parent | 51fc6dc8f948047364f7d42a4ed89b416c6cc0a3 (diff) | |
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
| -rw-r--r-- | crypto/sha512_generic.c | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/crypto/sha512_generic.c b/crypto/sha512_generic.c index 9ed9f60316e5..88f160b77b1f 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)); |
| @@ -80,7 +78,7 @@ static inline void LOAD_OP(int I, u64 *W, const u8 *input) | |||
| 80 | 78 | ||
| 81 | static inline void BLEND_OP(int I, u64 *W) | 79 | static inline void BLEND_OP(int I, u64 *W) |
| 82 | { | 80 | { |
| 83 | W[I] = s1(W[I-2]) + W[I-7] + s0(W[I-15]) + W[I-16]; | 81 | W[I % 16] += s1(W[(I-2) % 16]) + W[(I-7) % 16] + s0(W[(I-15) % 16]); |
| 84 | } | 82 | } |
| 85 | 83 | ||
| 86 | static void | 84 | static void |
| @@ -89,38 +87,48 @@ 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[16]; |
| 93 | 91 | ||
| 94 | /* load the input */ | 92 | /* load the input */ |
| 95 | for (i = 0; i < 16; i++) | 93 | for (i = 0; i < 16; i++) |
| 96 | LOAD_OP(i, W, input); | 94 | LOAD_OP(i, W, input); |
| 97 | 95 | ||
| 98 | for (i = 16; i < 80; i++) { | ||
| 99 | BLEND_OP(i, W); | ||
| 100 | } | ||
| 101 | |||
| 102 | /* load the state into our registers */ | 96 | /* load the state into our registers */ |
| 103 | a=state[0]; b=state[1]; c=state[2]; d=state[3]; | 97 | a=state[0]; b=state[1]; c=state[2]; d=state[3]; |
| 104 | e=state[4]; f=state[5]; g=state[6]; h=state[7]; | 98 | e=state[4]; f=state[5]; g=state[6]; h=state[7]; |
| 105 | 99 | ||
| 106 | /* now iterate */ | 100 | #define SHA512_0_15(i, a, b, c, d, e, f, g, h) \ |
| 107 | for (i=0; i<80; i+=8) { | 101 | t1 = h + e1(e) + Ch(e, f, g) + sha512_K[i] + W[i]; \ |
| 108 | t1 = h + e1(e) + Ch(e,f,g) + sha512_K[i ] + W[i ]; | 102 | t2 = e0(a) + Maj(a, b, c); \ |
| 109 | t2 = e0(a) + Maj(a,b,c); d+=t1; h=t1+t2; | 103 | d += t1; \ |
| 110 | t1 = g + e1(d) + Ch(d,e,f) + sha512_K[i+1] + W[i+1]; | 104 | h = t1 + t2 |
| 111 | t2 = e0(h) + Maj(h,a,b); c+=t1; g=t1+t2; | 105 | |
| 112 | t1 = f + e1(c) + Ch(c,d,e) + sha512_K[i+2] + W[i+2]; | 106 | #define SHA512_16_79(i, a, b, c, d, e, f, g, h) \ |
| 113 | t2 = e0(g) + Maj(g,h,a); b+=t1; f=t1+t2; | 107 | BLEND_OP(i, W); \ |
| 114 | t1 = e + e1(b) + Ch(b,c,d) + sha512_K[i+3] + W[i+3]; | 108 | t1 = h + e1(e) + Ch(e, f, g) + sha512_K[i] + W[(i)%16]; \ |
| 115 | t2 = e0(f) + Maj(f,g,h); a+=t1; e=t1+t2; | 109 | t2 = e0(a) + Maj(a, b, c); \ |
| 116 | t1 = d + e1(a) + Ch(a,b,c) + sha512_K[i+4] + W[i+4]; | 110 | d += t1; \ |
| 117 | t2 = e0(e) + Maj(e,f,g); h+=t1; d=t1+t2; | 111 | h = t1 + t2 |
| 118 | t1 = c + e1(h) + Ch(h,a,b) + sha512_K[i+5] + W[i+5]; | 112 | |
| 119 | t2 = e0(d) + Maj(d,e,f); g+=t1; c=t1+t2; | 113 | for (i = 0; i < 16; i += 8) { |
| 120 | t1 = b + e1(g) + Ch(g,h,a) + sha512_K[i+6] + W[i+6]; | 114 | SHA512_0_15(i, a, b, c, d, e, f, g, h); |
| 121 | t2 = e0(c) + Maj(c,d,e); f+=t1; b=t1+t2; | 115 | SHA512_0_15(i + 1, h, a, b, c, d, e, f, g); |
| 122 | t1 = a + e1(f) + Ch(f,g,h) + sha512_K[i+7] + W[i+7]; | 116 | SHA512_0_15(i + 2, g, h, a, b, c, d, e, f); |
| 123 | t2 = e0(b) + Maj(b,c,d); e+=t1; a=t1+t2; | 117 | SHA512_0_15(i + 3, f, g, h, a, b, c, d, e); |
| 118 | SHA512_0_15(i + 4, e, f, g, h, a, b, c, d); | ||
| 119 | SHA512_0_15(i + 5, d, e, f, g, h, a, b, c); | ||
| 120 | SHA512_0_15(i + 6, c, d, e, f, g, h, a, b); | ||
| 121 | SHA512_0_15(i + 7, b, c, d, e, f, g, h, a); | ||
| 122 | } | ||
| 123 | for (i = 16; i < 80; i += 8) { | ||
| 124 | SHA512_16_79(i, a, b, c, d, e, f, g, h); | ||
| 125 | SHA512_16_79(i + 1, h, a, b, c, d, e, f, g); | ||
| 126 | SHA512_16_79(i + 2, g, h, a, b, c, d, e, f); | ||
| 127 | SHA512_16_79(i + 3, f, g, h, a, b, c, d, e); | ||
| 128 | SHA512_16_79(i + 4, e, f, g, h, a, b, c, d); | ||
| 129 | SHA512_16_79(i + 5, d, e, f, g, h, a, b, c); | ||
| 130 | SHA512_16_79(i + 6, c, d, e, f, g, h, a, b); | ||
| 131 | SHA512_16_79(i + 7, b, c, d, e, f, g, h, a); | ||
| 124 | } | 132 | } |
| 125 | 133 | ||
| 126 | state[0] += a; state[1] += b; state[2] += c; state[3] += d; | 134 | state[0] += a; state[1] += b; state[2] += c; state[3] += d; |
| @@ -128,8 +136,6 @@ sha512_transform(u64 *state, const u8 *input) | |||
| 128 | 136 | ||
| 129 | /* erase our data */ | 137 | /* erase our data */ |
| 130 | a = b = c = d = e = f = g = h = t1 = t2 = 0; | 138 | 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 | } | 139 | } |
| 134 | 140 | ||
| 135 | static int | 141 | static int |
