diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-09-11 12:38:37 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-09-11 12:38:37 -0400 |
commit | 332a3392188e0ad966543c87b8da2b9d246f301d (patch) | |
tree | ac0d570590bffdd1924426adc5b255857d2f3297 /crypto/sha512_generic.c | |
parent | a9c86d42599519f3d83b5f46bdab25046fe47b84 (diff) | |
parent | 81bd5f6c966cf2f137c2759dfc78abdffcff055e (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: (102 commits)
crypto: sha-s390 - Fix warnings in import function
crypto: vmac - New hash algorithm for intel_txt support
crypto: api - Do not displace newly registered algorithms
crypto: ansi_cprng - Fix module initialization
crypto: xcbc - Fix alignment calculation of xcbc_tfm_ctx
crypto: fips - Depend on ansi_cprng
crypto: blkcipher - Do not use eseqiv on stream ciphers
crypto: ctr - Use chainiv on raw counter mode
Revert crypto: fips - Select CPRNG
crypto: rng - Fix typo
crypto: talitos - add support for 36 bit addressing
crypto: talitos - align locks on cache lines
crypto: talitos - simplify hmac data size calculation
crypto: mv_cesa - Add support for Orion5X crypto engine
crypto: cryptd - Add support to access underlaying shash
crypto: gcm - Use GHASH digest algorithm
crypto: ghash - Add GHASH digest algorithm for GCM
crypto: authenc - Convert to ahash
crypto: api - Fix aligned ctx helper
crypto: hmac - Prehash ipad/opad
...
Diffstat (limited to 'crypto/sha512_generic.c')
-rw-r--r-- | crypto/sha512_generic.c | 48 |
1 files changed, 18 insertions, 30 deletions
diff --git a/crypto/sha512_generic.c b/crypto/sha512_generic.c index 3bea38d12242..9ed9f60316e5 100644 --- a/crypto/sha512_generic.c +++ b/crypto/sha512_generic.c | |||
@@ -21,12 +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 | struct sha512_ctx { | ||
25 | u64 state[8]; | ||
26 | u32 count[4]; | ||
27 | u8 buf[128]; | ||
28 | }; | ||
29 | |||
30 | static DEFINE_PER_CPU(u64[80], msg_schedule); | 24 | static DEFINE_PER_CPU(u64[80], msg_schedule); |
31 | 25 | ||
32 | static inline u64 Ch(u64 x, u64 y, u64 z) | 26 | static inline u64 Ch(u64 x, u64 y, u64 z) |
@@ -141,7 +135,7 @@ sha512_transform(u64 *state, const u8 *input) | |||
141 | static int | 135 | static int |
142 | sha512_init(struct shash_desc *desc) | 136 | sha512_init(struct shash_desc *desc) |
143 | { | 137 | { |
144 | struct sha512_ctx *sctx = shash_desc_ctx(desc); | 138 | struct sha512_state *sctx = shash_desc_ctx(desc); |
145 | sctx->state[0] = SHA512_H0; | 139 | sctx->state[0] = SHA512_H0; |
146 | sctx->state[1] = SHA512_H1; | 140 | sctx->state[1] = SHA512_H1; |
147 | sctx->state[2] = SHA512_H2; | 141 | sctx->state[2] = SHA512_H2; |
@@ -150,7 +144,7 @@ sha512_init(struct shash_desc *desc) | |||
150 | sctx->state[5] = SHA512_H5; | 144 | sctx->state[5] = SHA512_H5; |
151 | sctx->state[6] = SHA512_H6; | 145 | sctx->state[6] = SHA512_H6; |
152 | sctx->state[7] = SHA512_H7; | 146 | sctx->state[7] = SHA512_H7; |
153 | sctx->count[0] = sctx->count[1] = sctx->count[2] = sctx->count[3] = 0; | 147 | sctx->count[0] = sctx->count[1] = 0; |
154 | 148 | ||
155 | return 0; | 149 | return 0; |
156 | } | 150 | } |
@@ -158,7 +152,7 @@ sha512_init(struct shash_desc *desc) | |||
158 | static int | 152 | static int |
159 | sha384_init(struct shash_desc *desc) | 153 | sha384_init(struct shash_desc *desc) |
160 | { | 154 | { |
161 | struct sha512_ctx *sctx = shash_desc_ctx(desc); | 155 | struct sha512_state *sctx = shash_desc_ctx(desc); |
162 | sctx->state[0] = SHA384_H0; | 156 | sctx->state[0] = SHA384_H0; |
163 | sctx->state[1] = SHA384_H1; | 157 | sctx->state[1] = SHA384_H1; |
164 | sctx->state[2] = SHA384_H2; | 158 | sctx->state[2] = SHA384_H2; |
@@ -167,7 +161,7 @@ sha384_init(struct shash_desc *desc) | |||
167 | sctx->state[5] = SHA384_H5; | 161 | sctx->state[5] = SHA384_H5; |
168 | sctx->state[6] = SHA384_H6; | 162 | sctx->state[6] = SHA384_H6; |
169 | sctx->state[7] = SHA384_H7; | 163 | sctx->state[7] = SHA384_H7; |
170 | sctx->count[0] = sctx->count[1] = sctx->count[2] = sctx->count[3] = 0; | 164 | sctx->count[0] = sctx->count[1] = 0; |
171 | 165 | ||
172 | return 0; | 166 | return 0; |
173 | } | 167 | } |
@@ -175,20 +169,16 @@ sha384_init(struct shash_desc *desc) | |||
175 | static int | 169 | static int |
176 | sha512_update(struct shash_desc *desc, const u8 *data, unsigned int len) | 170 | sha512_update(struct shash_desc *desc, const u8 *data, unsigned int len) |
177 | { | 171 | { |
178 | struct sha512_ctx *sctx = shash_desc_ctx(desc); | 172 | struct sha512_state *sctx = shash_desc_ctx(desc); |
179 | 173 | ||
180 | unsigned int i, index, part_len; | 174 | unsigned int i, index, part_len; |
181 | 175 | ||
182 | /* Compute number of bytes mod 128 */ | 176 | /* Compute number of bytes mod 128 */ |
183 | index = (unsigned int)((sctx->count[0] >> 3) & 0x7F); | 177 | index = sctx->count[0] & 0x7f; |
184 | 178 | ||
185 | /* Update number of bits */ | 179 | /* Update number of bytes */ |
186 | if ((sctx->count[0] += (len << 3)) < (len << 3)) { | 180 | if (!(sctx->count[0] += len)) |
187 | if ((sctx->count[1] += 1) < 1) | 181 | sctx->count[1]++; |
188 | if ((sctx->count[2] += 1) < 1) | ||
189 | sctx->count[3]++; | ||
190 | sctx->count[1] += (len >> 29); | ||
191 | } | ||
192 | 182 | ||
193 | part_len = 128 - index; | 183 | part_len = 128 - index; |
194 | 184 | ||
@@ -214,21 +204,19 @@ sha512_update(struct shash_desc *desc, const u8 *data, unsigned int len) | |||
214 | static int | 204 | static int |
215 | sha512_final(struct shash_desc *desc, u8 *hash) | 205 | sha512_final(struct shash_desc *desc, u8 *hash) |
216 | { | 206 | { |
217 | struct sha512_ctx *sctx = shash_desc_ctx(desc); | 207 | struct sha512_state *sctx = shash_desc_ctx(desc); |
218 | static u8 padding[128] = { 0x80, }; | 208 | static u8 padding[128] = { 0x80, }; |
219 | __be64 *dst = (__be64 *)hash; | 209 | __be64 *dst = (__be64 *)hash; |
220 | __be32 bits[4]; | 210 | __be64 bits[2]; |
221 | unsigned int index, pad_len; | 211 | unsigned int index, pad_len; |
222 | int i; | 212 | int i; |
223 | 213 | ||
224 | /* Save number of bits */ | 214 | /* Save number of bits */ |
225 | bits[3] = cpu_to_be32(sctx->count[0]); | 215 | bits[1] = cpu_to_be64(sctx->count[0] << 3); |
226 | bits[2] = cpu_to_be32(sctx->count[1]); | 216 | bits[0] = cpu_to_be64(sctx->count[1] << 3 | sctx->count[0] >> 61); |
227 | bits[1] = cpu_to_be32(sctx->count[2]); | ||
228 | bits[0] = cpu_to_be32(sctx->count[3]); | ||
229 | 217 | ||
230 | /* Pad out to 112 mod 128. */ | 218 | /* Pad out to 112 mod 128. */ |
231 | index = (sctx->count[0] >> 3) & 0x7f; | 219 | index = sctx->count[0] & 0x7f; |
232 | pad_len = (index < 112) ? (112 - index) : ((128+112) - index); | 220 | pad_len = (index < 112) ? (112 - index) : ((128+112) - index); |
233 | sha512_update(desc, padding, pad_len); | 221 | sha512_update(desc, padding, pad_len); |
234 | 222 | ||
@@ -240,7 +228,7 @@ sha512_final(struct shash_desc *desc, u8 *hash) | |||
240 | dst[i] = cpu_to_be64(sctx->state[i]); | 228 | dst[i] = cpu_to_be64(sctx->state[i]); |
241 | 229 | ||
242 | /* Zeroize sensitive information. */ | 230 | /* Zeroize sensitive information. */ |
243 | memset(sctx, 0, sizeof(struct sha512_ctx)); | 231 | memset(sctx, 0, sizeof(struct sha512_state)); |
244 | 232 | ||
245 | return 0; | 233 | return 0; |
246 | } | 234 | } |
@@ -262,7 +250,7 @@ static struct shash_alg sha512 = { | |||
262 | .init = sha512_init, | 250 | .init = sha512_init, |
263 | .update = sha512_update, | 251 | .update = sha512_update, |
264 | .final = sha512_final, | 252 | .final = sha512_final, |
265 | .descsize = sizeof(struct sha512_ctx), | 253 | .descsize = sizeof(struct sha512_state), |
266 | .base = { | 254 | .base = { |
267 | .cra_name = "sha512", | 255 | .cra_name = "sha512", |
268 | .cra_flags = CRYPTO_ALG_TYPE_SHASH, | 256 | .cra_flags = CRYPTO_ALG_TYPE_SHASH, |
@@ -276,7 +264,7 @@ static struct shash_alg sha384 = { | |||
276 | .init = sha384_init, | 264 | .init = sha384_init, |
277 | .update = sha512_update, | 265 | .update = sha512_update, |
278 | .final = sha384_final, | 266 | .final = sha384_final, |
279 | .descsize = sizeof(struct sha512_ctx), | 267 | .descsize = sizeof(struct sha512_state), |
280 | .base = { | 268 | .base = { |
281 | .cra_name = "sha384", | 269 | .cra_name = "sha384", |
282 | .cra_flags = CRYPTO_ALG_TYPE_SHASH, | 270 | .cra_flags = CRYPTO_ALG_TYPE_SHASH, |