diff options
author | Adrian-Ken Rueegsegger <ken@codelabs.ch> | 2008-12-02 08:08:20 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2008-12-24 19:02:15 -0500 |
commit | 54ccb36776eb7e03b592bfab60393c7800851a0b (patch) | |
tree | 9f9c1ae359761d7748e1e9a967c7b98b13065561 /crypto/sha1_generic.c | |
parent | 3b8efb4c4147094652570d7791a516d07b7df8c2 (diff) |
crypto: sha1 - Switch to shash
This patch changes sha1 to the new shash interface.
Signed-off-by: Adrian-Ken Rueegsegger <ken@codelabs.ch>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/sha1_generic.c')
-rw-r--r-- | crypto/sha1_generic.c | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/crypto/sha1_generic.c b/crypto/sha1_generic.c index c7c6899e1fca..9efef20454cb 100644 --- a/crypto/sha1_generic.c +++ b/crypto/sha1_generic.c | |||
@@ -16,10 +16,10 @@ | |||
16 | * any later version. | 16 | * any later version. |
17 | * | 17 | * |
18 | */ | 18 | */ |
19 | #include <crypto/internal/hash.h> | ||
19 | #include <linux/init.h> | 20 | #include <linux/init.h> |
20 | #include <linux/module.h> | 21 | #include <linux/module.h> |
21 | #include <linux/mm.h> | 22 | #include <linux/mm.h> |
22 | #include <linux/crypto.h> | ||
23 | #include <linux/cryptohash.h> | 23 | #include <linux/cryptohash.h> |
24 | #include <linux/types.h> | 24 | #include <linux/types.h> |
25 | #include <crypto/sha.h> | 25 | #include <crypto/sha.h> |
@@ -31,9 +31,10 @@ struct sha1_ctx { | |||
31 | u8 buffer[64]; | 31 | u8 buffer[64]; |
32 | }; | 32 | }; |
33 | 33 | ||
34 | static void sha1_init(struct crypto_tfm *tfm) | 34 | static int sha1_init(struct shash_desc *desc) |
35 | { | 35 | { |
36 | struct sha1_ctx *sctx = crypto_tfm_ctx(tfm); | 36 | struct sha1_ctx *sctx = shash_desc_ctx(desc); |
37 | |||
37 | static const struct sha1_ctx initstate = { | 38 | static const struct sha1_ctx initstate = { |
38 | 0, | 39 | 0, |
39 | { SHA1_H0, SHA1_H1, SHA1_H2, SHA1_H3, SHA1_H4 }, | 40 | { SHA1_H0, SHA1_H1, SHA1_H2, SHA1_H3, SHA1_H4 }, |
@@ -41,12 +42,14 @@ static void sha1_init(struct crypto_tfm *tfm) | |||
41 | }; | 42 | }; |
42 | 43 | ||
43 | *sctx = initstate; | 44 | *sctx = initstate; |
45 | |||
46 | return 0; | ||
44 | } | 47 | } |
45 | 48 | ||
46 | static void sha1_update(struct crypto_tfm *tfm, const u8 *data, | 49 | static int sha1_update(struct shash_desc *desc, const u8 *data, |
47 | unsigned int len) | 50 | unsigned int len) |
48 | { | 51 | { |
49 | struct sha1_ctx *sctx = crypto_tfm_ctx(tfm); | 52 | struct sha1_ctx *sctx = shash_desc_ctx(desc); |
50 | unsigned int partial, done; | 53 | unsigned int partial, done; |
51 | const u8 *src; | 54 | const u8 *src; |
52 | 55 | ||
@@ -74,13 +77,15 @@ static void sha1_update(struct crypto_tfm *tfm, const u8 *data, | |||
74 | partial = 0; | 77 | partial = 0; |
75 | } | 78 | } |
76 | memcpy(sctx->buffer + partial, src, len - done); | 79 | memcpy(sctx->buffer + partial, src, len - done); |
80 | |||
81 | return 0; | ||
77 | } | 82 | } |
78 | 83 | ||
79 | 84 | ||
80 | /* Add padding and return the message digest. */ | 85 | /* Add padding and return the message digest. */ |
81 | static void sha1_final(struct crypto_tfm *tfm, u8 *out) | 86 | static int sha1_final(struct shash_desc *desc, u8 *out) |
82 | { | 87 | { |
83 | struct sha1_ctx *sctx = crypto_tfm_ctx(tfm); | 88 | struct sha1_ctx *sctx = shash_desc_ctx(desc); |
84 | __be32 *dst = (__be32 *)out; | 89 | __be32 *dst = (__be32 *)out; |
85 | u32 i, index, padlen; | 90 | u32 i, index, padlen; |
86 | __be64 bits; | 91 | __be64 bits; |
@@ -91,10 +96,10 @@ static void sha1_final(struct crypto_tfm *tfm, u8 *out) | |||
91 | /* Pad out to 56 mod 64 */ | 96 | /* Pad out to 56 mod 64 */ |
92 | index = sctx->count & 0x3f; | 97 | index = sctx->count & 0x3f; |
93 | padlen = (index < 56) ? (56 - index) : ((64+56) - index); | 98 | padlen = (index < 56) ? (56 - index) : ((64+56) - index); |
94 | sha1_update(tfm, padding, padlen); | 99 | sha1_update(desc, padding, padlen); |
95 | 100 | ||
96 | /* Append length */ | 101 | /* Append length */ |
97 | sha1_update(tfm, (const u8 *)&bits, sizeof(bits)); | 102 | sha1_update(desc, (const u8 *)&bits, sizeof(bits)); |
98 | 103 | ||
99 | /* Store state in digest */ | 104 | /* Store state in digest */ |
100 | for (i = 0; i < 5; i++) | 105 | for (i = 0; i < 5; i++) |
@@ -102,32 +107,33 @@ static void sha1_final(struct crypto_tfm *tfm, u8 *out) | |||
102 | 107 | ||
103 | /* Wipe context */ | 108 | /* Wipe context */ |
104 | memset(sctx, 0, sizeof *sctx); | 109 | memset(sctx, 0, sizeof *sctx); |
110 | |||
111 | return 0; | ||
105 | } | 112 | } |
106 | 113 | ||
107 | static struct crypto_alg alg = { | 114 | static struct shash_alg alg = { |
108 | .cra_name = "sha1", | 115 | .digestsize = SHA1_DIGEST_SIZE, |
109 | .cra_driver_name= "sha1-generic", | 116 | .init = sha1_init, |
110 | .cra_flags = CRYPTO_ALG_TYPE_DIGEST, | 117 | .update = sha1_update, |
111 | .cra_blocksize = SHA1_BLOCK_SIZE, | 118 | .final = sha1_final, |
112 | .cra_ctxsize = sizeof(struct sha1_ctx), | 119 | .descsize = sizeof(struct sha1_ctx), |
113 | .cra_module = THIS_MODULE, | 120 | .base = { |
114 | .cra_alignmask = 3, | 121 | .cra_name = "sha1", |
115 | .cra_list = LIST_HEAD_INIT(alg.cra_list), | 122 | .cra_driver_name= "sha1-generic", |
116 | .cra_u = { .digest = { | 123 | .cra_flags = CRYPTO_ALG_TYPE_SHASH, |
117 | .dia_digestsize = SHA1_DIGEST_SIZE, | 124 | .cra_blocksize = SHA1_BLOCK_SIZE, |
118 | .dia_init = sha1_init, | 125 | .cra_module = THIS_MODULE, |
119 | .dia_update = sha1_update, | 126 | } |
120 | .dia_final = sha1_final } } | ||
121 | }; | 127 | }; |
122 | 128 | ||
123 | static int __init sha1_generic_mod_init(void) | 129 | static int __init sha1_generic_mod_init(void) |
124 | { | 130 | { |
125 | return crypto_register_alg(&alg); | 131 | return crypto_register_shash(&alg); |
126 | } | 132 | } |
127 | 133 | ||
128 | static void __exit sha1_generic_mod_fini(void) | 134 | static void __exit sha1_generic_mod_fini(void) |
129 | { | 135 | { |
130 | crypto_unregister_alg(&alg); | 136 | crypto_unregister_shash(&alg); |
131 | } | 137 | } |
132 | 138 | ||
133 | module_init(sha1_generic_mod_init); | 139 | module_init(sha1_generic_mod_init); |