aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrian-Ken Rueegsegger <ken@codelabs.ch>2008-12-03 06:57:12 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2008-12-24 19:02:18 -0500
commit14b75ba70da925a9f040a7575cb46ad7d394b117 (patch)
tree57f0a020d0afd5260cdb7cda843d32858e55a5b8
parent808a1763cef93bf0f740d7e10dd9a2dfc4065b1a (diff)
crypto: md5 - Switch to shash
This patch changes md5 to the new shash interface. Signed-off-by: Adrian-Ken Rueegsegger <ken@codelabs.ch> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--crypto/Kconfig2
-rw-r--r--crypto/md5.c50
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
283config CRYPTO_MD5 283config 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
150static void md5_init(struct crypto_tfm *tfm) 150static 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
161static void md5_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len) 163static 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
191static void md5_final(struct crypto_tfm *tfm, u8 *out) 195static 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
217static struct crypto_alg alg = { 223static 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
231static int __init md5_mod_init(void) 237static int __init md5_mod_init(void)
232{ 238{
233 return crypto_register_alg(&alg); 239 return crypto_register_shash(&alg);
234} 240}
235 241
236static void __exit md5_mod_fini(void) 242static void __exit md5_mod_fini(void)
237{ 243{
238 crypto_unregister_alg(&alg); 244 crypto_unregister_shash(&alg);
239} 245}
240 246
241module_init(md5_mod_init); 247module_init(md5_mod_init);