diff options
Diffstat (limited to 'crypto/sha256_generic.c')
-rw-r--r-- | crypto/sha256_generic.c | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/crypto/sha256_generic.c b/crypto/sha256_generic.c index e58c71bdf333..c48459ebf05b 100644 --- a/crypto/sha256_generic.c +++ b/crypto/sha256_generic.c | |||
@@ -25,12 +25,6 @@ | |||
25 | #include <crypto/sha.h> | 25 | #include <crypto/sha.h> |
26 | #include <asm/byteorder.h> | 26 | #include <asm/byteorder.h> |
27 | 27 | ||
28 | struct sha256_ctx { | ||
29 | u64 count; | ||
30 | u32 state[8]; | ||
31 | u8 buf[128]; | ||
32 | }; | ||
33 | |||
34 | static inline u32 Ch(u32 x, u32 y, u32 z) | 28 | static inline u32 Ch(u32 x, u32 y, u32 z) |
35 | { | 29 | { |
36 | return z ^ (x & (y ^ z)); | 30 | return z ^ (x & (y ^ z)); |
@@ -222,7 +216,7 @@ static void sha256_transform(u32 *state, const u8 *input) | |||
222 | 216 | ||
223 | static int sha224_init(struct shash_desc *desc) | 217 | static int sha224_init(struct shash_desc *desc) |
224 | { | 218 | { |
225 | struct sha256_ctx *sctx = shash_desc_ctx(desc); | 219 | struct sha256_state *sctx = shash_desc_ctx(desc); |
226 | sctx->state[0] = SHA224_H0; | 220 | sctx->state[0] = SHA224_H0; |
227 | sctx->state[1] = SHA224_H1; | 221 | sctx->state[1] = SHA224_H1; |
228 | sctx->state[2] = SHA224_H2; | 222 | sctx->state[2] = SHA224_H2; |
@@ -238,7 +232,7 @@ static int sha224_init(struct shash_desc *desc) | |||
238 | 232 | ||
239 | static int sha256_init(struct shash_desc *desc) | 233 | static int sha256_init(struct shash_desc *desc) |
240 | { | 234 | { |
241 | struct sha256_ctx *sctx = shash_desc_ctx(desc); | 235 | struct sha256_state *sctx = shash_desc_ctx(desc); |
242 | sctx->state[0] = SHA256_H0; | 236 | sctx->state[0] = SHA256_H0; |
243 | sctx->state[1] = SHA256_H1; | 237 | sctx->state[1] = SHA256_H1; |
244 | sctx->state[2] = SHA256_H2; | 238 | sctx->state[2] = SHA256_H2; |
@@ -255,7 +249,7 @@ static int sha256_init(struct shash_desc *desc) | |||
255 | static int sha256_update(struct shash_desc *desc, const u8 *data, | 249 | static int sha256_update(struct shash_desc *desc, const u8 *data, |
256 | unsigned int len) | 250 | unsigned int len) |
257 | { | 251 | { |
258 | struct sha256_ctx *sctx = shash_desc_ctx(desc); | 252 | struct sha256_state *sctx = shash_desc_ctx(desc); |
259 | unsigned int partial, done; | 253 | unsigned int partial, done; |
260 | const u8 *src; | 254 | const u8 *src; |
261 | 255 | ||
@@ -286,7 +280,7 @@ static int sha256_update(struct shash_desc *desc, const u8 *data, | |||
286 | 280 | ||
287 | static int sha256_final(struct shash_desc *desc, u8 *out) | 281 | static int sha256_final(struct shash_desc *desc, u8 *out) |
288 | { | 282 | { |
289 | struct sha256_ctx *sctx = shash_desc_ctx(desc); | 283 | struct sha256_state *sctx = shash_desc_ctx(desc); |
290 | __be32 *dst = (__be32 *)out; | 284 | __be32 *dst = (__be32 *)out; |
291 | __be64 bits; | 285 | __be64 bits; |
292 | unsigned int index, pad_len; | 286 | unsigned int index, pad_len; |
@@ -326,12 +320,31 @@ static int sha224_final(struct shash_desc *desc, u8 *hash) | |||
326 | return 0; | 320 | return 0; |
327 | } | 321 | } |
328 | 322 | ||
323 | static int sha256_export(struct shash_desc *desc, void *out) | ||
324 | { | ||
325 | struct sha256_state *sctx = shash_desc_ctx(desc); | ||
326 | |||
327 | memcpy(out, sctx, sizeof(*sctx)); | ||
328 | return 0; | ||
329 | } | ||
330 | |||
331 | static int sha256_import(struct shash_desc *desc, const void *in) | ||
332 | { | ||
333 | struct sha256_state *sctx = shash_desc_ctx(desc); | ||
334 | |||
335 | memcpy(sctx, in, sizeof(*sctx)); | ||
336 | return 0; | ||
337 | } | ||
338 | |||
329 | static struct shash_alg sha256 = { | 339 | static struct shash_alg sha256 = { |
330 | .digestsize = SHA256_DIGEST_SIZE, | 340 | .digestsize = SHA256_DIGEST_SIZE, |
331 | .init = sha256_init, | 341 | .init = sha256_init, |
332 | .update = sha256_update, | 342 | .update = sha256_update, |
333 | .final = sha256_final, | 343 | .final = sha256_final, |
334 | .descsize = sizeof(struct sha256_ctx), | 344 | .export = sha256_export, |
345 | .import = sha256_import, | ||
346 | .descsize = sizeof(struct sha256_state), | ||
347 | .statesize = sizeof(struct sha256_state), | ||
335 | .base = { | 348 | .base = { |
336 | .cra_name = "sha256", | 349 | .cra_name = "sha256", |
337 | .cra_driver_name= "sha256-generic", | 350 | .cra_driver_name= "sha256-generic", |
@@ -346,7 +359,7 @@ static struct shash_alg sha224 = { | |||
346 | .init = sha224_init, | 359 | .init = sha224_init, |
347 | .update = sha256_update, | 360 | .update = sha256_update, |
348 | .final = sha224_final, | 361 | .final = sha224_final, |
349 | .descsize = sizeof(struct sha256_ctx), | 362 | .descsize = sizeof(struct sha256_state), |
350 | .base = { | 363 | .base = { |
351 | .cra_name = "sha224", | 364 | .cra_name = "sha224", |
352 | .cra_driver_name= "sha224-generic", | 365 | .cra_driver_name= "sha224-generic", |