diff options
| author | Herbert Xu <herbert@gondor.apana.org.au> | 2009-07-09 09:27:13 -0400 |
|---|---|---|
| committer | Herbert Xu <herbert@gondor.apana.org.au> | 2009-07-11 06:23:33 -0400 |
| commit | e2a7ce4e185a94462698cc0e5192495ee3d22a2f (patch) | |
| tree | 33013f177e48a3b4b191bfccfdb969cf0eeb8dbb | |
| parent | 8267adab9433593adb09d94626475c2a5921f111 (diff) | |
crypto: sha1_generic - Add export/import support
This patch adds export/import support to sha1_generic. The exported
type is defined by struct sha1_state, which is basically the entire
descriptor state of sha1_generic.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
| -rw-r--r-- | crypto/sha1_generic.c | 41 | ||||
| -rw-r--r-- | include/crypto/sha.h | 8 |
2 files changed, 33 insertions, 16 deletions
diff --git a/crypto/sha1_generic.c b/crypto/sha1_generic.c index 9efef20454cb..0416091bf45a 100644 --- a/crypto/sha1_generic.c +++ b/crypto/sha1_generic.c | |||
| @@ -25,31 +25,21 @@ | |||
| 25 | #include <crypto/sha.h> | 25 | #include <crypto/sha.h> |
| 26 | #include <asm/byteorder.h> | 26 | #include <asm/byteorder.h> |
| 27 | 27 | ||
| 28 | struct sha1_ctx { | ||
| 29 | u64 count; | ||
| 30 | u32 state[5]; | ||
| 31 | u8 buffer[64]; | ||
| 32 | }; | ||
| 33 | |||
| 34 | static int sha1_init(struct shash_desc *desc) | 28 | static int sha1_init(struct shash_desc *desc) |
| 35 | { | 29 | { |
| 36 | struct sha1_ctx *sctx = shash_desc_ctx(desc); | 30 | struct sha1_state *sctx = shash_desc_ctx(desc); |
| 37 | 31 | ||
| 38 | static const struct sha1_ctx initstate = { | 32 | *sctx = (struct sha1_state){ |
| 39 | 0, | 33 | .state = { SHA1_H0, SHA1_H1, SHA1_H2, SHA1_H3, SHA1_H4 }, |
| 40 | { SHA1_H0, SHA1_H1, SHA1_H2, SHA1_H3, SHA1_H4 }, | ||
| 41 | { 0, } | ||
| 42 | }; | 34 | }; |
| 43 | 35 | ||
| 44 | *sctx = initstate; | ||
| 45 | |||
| 46 | return 0; | 36 | return 0; |
| 47 | } | 37 | } |
| 48 | 38 | ||
| 49 | static int sha1_update(struct shash_desc *desc, const u8 *data, | 39 | static int sha1_update(struct shash_desc *desc, const u8 *data, |
| 50 | unsigned int len) | 40 | unsigned int len) |
| 51 | { | 41 | { |
| 52 | struct sha1_ctx *sctx = shash_desc_ctx(desc); | 42 | struct sha1_state *sctx = shash_desc_ctx(desc); |
| 53 | unsigned int partial, done; | 43 | unsigned int partial, done; |
| 54 | const u8 *src; | 44 | const u8 *src; |
| 55 | 45 | ||
| @@ -85,7 +75,7 @@ static int sha1_update(struct shash_desc *desc, const u8 *data, | |||
| 85 | /* Add padding and return the message digest. */ | 75 | /* Add padding and return the message digest. */ |
| 86 | static int sha1_final(struct shash_desc *desc, u8 *out) | 76 | static int sha1_final(struct shash_desc *desc, u8 *out) |
| 87 | { | 77 | { |
| 88 | struct sha1_ctx *sctx = shash_desc_ctx(desc); | 78 | struct sha1_state *sctx = shash_desc_ctx(desc); |
| 89 | __be32 *dst = (__be32 *)out; | 79 | __be32 *dst = (__be32 *)out; |
| 90 | u32 i, index, padlen; | 80 | u32 i, index, padlen; |
| 91 | __be64 bits; | 81 | __be64 bits; |
| @@ -111,12 +101,31 @@ static int sha1_final(struct shash_desc *desc, u8 *out) | |||
| 111 | return 0; | 101 | return 0; |
| 112 | } | 102 | } |
| 113 | 103 | ||
| 104 | static int sha1_export(struct shash_desc *desc, void *out) | ||
| 105 | { | ||
| 106 | struct sha1_state *sctx = shash_desc_ctx(desc); | ||
| 107 | |||
| 108 | memcpy(out, sctx, sizeof(*sctx)); | ||
| 109 | return 0; | ||
| 110 | } | ||
| 111 | |||
| 112 | static int sha1_import(struct shash_desc *desc, const void *in) | ||
| 113 | { | ||
| 114 | struct sha1_state *sctx = shash_desc_ctx(desc); | ||
| 115 | |||
| 116 | memcpy(sctx, in, sizeof(*sctx)); | ||
| 117 | return 0; | ||
| 118 | } | ||
| 119 | |||
| 114 | static struct shash_alg alg = { | 120 | static struct shash_alg alg = { |
| 115 | .digestsize = SHA1_DIGEST_SIZE, | 121 | .digestsize = SHA1_DIGEST_SIZE, |
| 116 | .init = sha1_init, | 122 | .init = sha1_init, |
| 117 | .update = sha1_update, | 123 | .update = sha1_update, |
| 118 | .final = sha1_final, | 124 | .final = sha1_final, |
| 119 | .descsize = sizeof(struct sha1_ctx), | 125 | .export = sha1_export, |
| 126 | .import = sha1_import, | ||
| 127 | .descsize = sizeof(struct sha1_state), | ||
| 128 | .statesize = sizeof(struct sha1_state), | ||
| 120 | .base = { | 129 | .base = { |
| 121 | .cra_name = "sha1", | 130 | .cra_name = "sha1", |
| 122 | .cra_driver_name= "sha1-generic", | 131 | .cra_driver_name= "sha1-generic", |
diff --git a/include/crypto/sha.h b/include/crypto/sha.h index c0ccc2b1a2d8..922a248bd04d 100644 --- a/include/crypto/sha.h +++ b/include/crypto/sha.h | |||
| @@ -5,6 +5,8 @@ | |||
| 5 | #ifndef _CRYPTO_SHA_H | 5 | #ifndef _CRYPTO_SHA_H |
| 6 | #define _CRYPTO_SHA_H | 6 | #define _CRYPTO_SHA_H |
| 7 | 7 | ||
| 8 | #include <linux/types.h> | ||
| 9 | |||
| 8 | #define SHA1_DIGEST_SIZE 20 | 10 | #define SHA1_DIGEST_SIZE 20 |
| 9 | #define SHA1_BLOCK_SIZE 64 | 11 | #define SHA1_BLOCK_SIZE 64 |
| 10 | 12 | ||
| @@ -62,4 +64,10 @@ | |||
| 62 | #define SHA512_H6 0x1f83d9abfb41bd6bULL | 64 | #define SHA512_H6 0x1f83d9abfb41bd6bULL |
| 63 | #define SHA512_H7 0x5be0cd19137e2179ULL | 65 | #define SHA512_H7 0x5be0cd19137e2179ULL |
| 64 | 66 | ||
| 67 | struct sha1_state { | ||
| 68 | u64 count; | ||
| 69 | u32 state[SHA1_DIGEST_SIZE / 4]; | ||
| 70 | u8 buffer[SHA1_BLOCK_SIZE]; | ||
| 71 | }; | ||
| 72 | |||
| 65 | #endif | 73 | #endif |
