diff options
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/Kconfig | 2 | ||||
-rw-r--r-- | crypto/md5.c | 50 |
2 files changed, 29 insertions, 23 deletions
diff --git a/crypto/Kconfig b/crypto/Kconfig index 96f8154147a2..989304ca3eab 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig | |||
@@ -282,7 +282,7 @@ config CRYPTO_MD4 | |||
282 | 282 | ||
283 | config CRYPTO_MD5 | 283 | config CRYPTO_MD5 |
284 | tristate "MD5 digest algorithm" | 284 | tristate "MD5 digest algorithm" |
285 | select CRYPTO_ALGAPI | 285 | select CRYPTO_HASH |
286 | help | 286 | help |
287 | MD5 message digest algorithm (RFC1321). | 287 | MD5 message digest algorithm (RFC1321). |
288 | 288 | ||
diff --git a/crypto/md5.c b/crypto/md5.c index 39268f3d2f1d..83eb52961750 100644 --- a/crypto/md5.c +++ b/crypto/md5.c | |||
@@ -15,10 +15,10 @@ | |||
15 | * any later version. | 15 | * any later version. |
16 | * | 16 | * |
17 | */ | 17 | */ |
18 | #include <crypto/internal/hash.h> | ||
18 | #include <linux/init.h> | 19 | #include <linux/init.h> |
19 | #include <linux/module.h> | 20 | #include <linux/module.h> |
20 | #include <linux/string.h> | 21 | #include <linux/string.h> |
21 | #include <linux/crypto.h> | ||
22 | #include <linux/types.h> | 22 | #include <linux/types.h> |
23 | #include <asm/byteorder.h> | 23 | #include <asm/byteorder.h> |
24 | 24 | ||
@@ -147,20 +147,22 @@ static inline void md5_transform_helper(struct md5_ctx *ctx) | |||
147 | md5_transform(ctx->hash, ctx->block); | 147 | md5_transform(ctx->hash, ctx->block); |
148 | } | 148 | } |
149 | 149 | ||
150 | static void md5_init(struct crypto_tfm *tfm) | 150 | static int md5_init(struct shash_desc *desc) |
151 | { | 151 | { |
152 | struct md5_ctx *mctx = crypto_tfm_ctx(tfm); | 152 | struct md5_ctx *mctx = shash_desc_ctx(desc); |
153 | 153 | ||
154 | mctx->hash[0] = 0x67452301; | 154 | mctx->hash[0] = 0x67452301; |
155 | mctx->hash[1] = 0xefcdab89; | 155 | mctx->hash[1] = 0xefcdab89; |
156 | mctx->hash[2] = 0x98badcfe; | 156 | mctx->hash[2] = 0x98badcfe; |
157 | mctx->hash[3] = 0x10325476; | 157 | mctx->hash[3] = 0x10325476; |
158 | mctx->byte_count = 0; | 158 | mctx->byte_count = 0; |
159 | |||
160 | return 0; | ||
159 | } | 161 | } |
160 | 162 | ||
161 | static void md5_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len) | 163 | static int md5_update(struct shash_desc *desc, const u8 *data, unsigned int len) |
162 | { | 164 | { |
163 | struct md5_ctx *mctx = crypto_tfm_ctx(tfm); | 165 | struct md5_ctx *mctx = shash_desc_ctx(desc); |
164 | const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f); | 166 | const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f); |
165 | 167 | ||
166 | mctx->byte_count += len; | 168 | mctx->byte_count += len; |
@@ -168,7 +170,7 @@ static void md5_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len) | |||
168 | if (avail > len) { | 170 | if (avail > len) { |
169 | memcpy((char *)mctx->block + (sizeof(mctx->block) - avail), | 171 | memcpy((char *)mctx->block + (sizeof(mctx->block) - avail), |
170 | data, len); | 172 | data, len); |
171 | return; | 173 | return 0; |
172 | } | 174 | } |
173 | 175 | ||
174 | memcpy((char *)mctx->block + (sizeof(mctx->block) - avail), | 176 | memcpy((char *)mctx->block + (sizeof(mctx->block) - avail), |
@@ -186,11 +188,13 @@ static void md5_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len) | |||
186 | } | 188 | } |
187 | 189 | ||
188 | memcpy(mctx->block, data, len); | 190 | memcpy(mctx->block, data, len); |
191 | |||
192 | return 0; | ||
189 | } | 193 | } |
190 | 194 | ||
191 | static void md5_final(struct crypto_tfm *tfm, u8 *out) | 195 | static int md5_final(struct shash_desc *desc, u8 *out) |
192 | { | 196 | { |
193 | struct md5_ctx *mctx = crypto_tfm_ctx(tfm); | 197 | struct md5_ctx *mctx = shash_desc_ctx(desc); |
194 | const unsigned int offset = mctx->byte_count & 0x3f; | 198 | const unsigned int offset = mctx->byte_count & 0x3f; |
195 | char *p = (char *)mctx->block + offset; | 199 | char *p = (char *)mctx->block + offset; |
196 | int padding = 56 - (offset + 1); | 200 | int padding = 56 - (offset + 1); |
@@ -212,30 +216,32 @@ static void md5_final(struct crypto_tfm *tfm, u8 *out) | |||
212 | cpu_to_le32_array(mctx->hash, sizeof(mctx->hash) / sizeof(u32)); | 216 | cpu_to_le32_array(mctx->hash, sizeof(mctx->hash) / sizeof(u32)); |
213 | memcpy(out, mctx->hash, sizeof(mctx->hash)); | 217 | memcpy(out, mctx->hash, sizeof(mctx->hash)); |
214 | memset(mctx, 0, sizeof(*mctx)); | 218 | memset(mctx, 0, sizeof(*mctx)); |
219 | |||
220 | return 0; | ||
215 | } | 221 | } |
216 | 222 | ||
217 | static struct crypto_alg alg = { | 223 | static struct shash_alg alg = { |
218 | .cra_name = "md5", | 224 | .digestsize = MD5_DIGEST_SIZE, |
219 | .cra_flags = CRYPTO_ALG_TYPE_DIGEST, | 225 | .init = md5_init, |
220 | .cra_blocksize = MD5_HMAC_BLOCK_SIZE, | 226 | .update = md5_update, |
221 | .cra_ctxsize = sizeof(struct md5_ctx), | 227 | .final = md5_final, |
222 | .cra_module = THIS_MODULE, | 228 | .descsize = sizeof(struct md5_ctx), |
223 | .cra_list = LIST_HEAD_INIT(alg.cra_list), | 229 | .base = { |
224 | .cra_u = { .digest = { | 230 | .cra_name = "md5", |
225 | .dia_digestsize = MD5_DIGEST_SIZE, | 231 | .cra_flags = CRYPTO_ALG_TYPE_SHASH, |
226 | .dia_init = md5_init, | 232 | .cra_blocksize = MD5_HMAC_BLOCK_SIZE, |
227 | .dia_update = md5_update, | 233 | .cra_module = THIS_MODULE, |
228 | .dia_final = md5_final } } | 234 | } |
229 | }; | 235 | }; |
230 | 236 | ||
231 | static int __init md5_mod_init(void) | 237 | static int __init md5_mod_init(void) |
232 | { | 238 | { |
233 | return crypto_register_alg(&alg); | 239 | return crypto_register_shash(&alg); |
234 | } | 240 | } |
235 | 241 | ||
236 | static void __exit md5_mod_fini(void) | 242 | static void __exit md5_mod_fini(void) |
237 | { | 243 | { |
238 | crypto_unregister_alg(&alg); | 244 | crypto_unregister_shash(&alg); |
239 | } | 245 | } |
240 | 246 | ||
241 | module_init(md5_mod_init); | 247 | module_init(md5_mod_init); |