diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2009-07-10 01:00:27 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2009-07-11 06:23:34 -0400 |
commit | 9b2fda7b94a769af13c24582739e50664b0e27a8 (patch) | |
tree | 9569f151b19dec10a8b5d3741a5ad875a98a1a63 /crypto | |
parent | 3d4d277cf88e1980d905707b9c8ca61e8ad6bf0b (diff) |
crypto: sha256_generic - Add export/import support
This patch adds export/import support to sha256_generic. The exported
type is defined by struct sha256_state, which is basically the entire
descriptor state of sha256_generic.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-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", |