Commit 14b75ba7 authored by Adrian-Ken Rueegsegger's avatar Adrian-Ken Rueegsegger Committed by Herbert Xu

crypto: md5 - Switch to shash

This patch changes md5 to the new shash interface.
Signed-off-by: default avatarAdrian-Ken Rueegsegger <ken@codelabs.ch>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 808a1763
...@@ -282,7 +282,7 @@ config CRYPTO_MD4 ...@@ -282,7 +282,7 @@ config CRYPTO_MD4
config CRYPTO_MD5 config CRYPTO_MD5
tristate "MD5 digest algorithm" tristate "MD5 digest algorithm"
select CRYPTO_ALGAPI select CRYPTO_HASH
help help
MD5 message digest algorithm (RFC1321). MD5 message digest algorithm (RFC1321).
......
...@@ -15,10 +15,10 @@ ...@@ -15,10 +15,10 @@
* any later version. * any later version.
* *
*/ */
#include <crypto/internal/hash.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/crypto.h>
#include <linux/types.h> #include <linux/types.h>
#include <asm/byteorder.h> #include <asm/byteorder.h>
...@@ -147,20 +147,22 @@ static inline void md5_transform_helper(struct md5_ctx *ctx) ...@@ -147,20 +147,22 @@ static inline void md5_transform_helper(struct md5_ctx *ctx)
md5_transform(ctx->hash, ctx->block); md5_transform(ctx->hash, ctx->block);
} }
static void md5_init(struct crypto_tfm *tfm) static int md5_init(struct shash_desc *desc)
{ {
struct md5_ctx *mctx = crypto_tfm_ctx(tfm); struct md5_ctx *mctx = shash_desc_ctx(desc);
mctx->hash[0] = 0x67452301; mctx->hash[0] = 0x67452301;
mctx->hash[1] = 0xefcdab89; mctx->hash[1] = 0xefcdab89;
mctx->hash[2] = 0x98badcfe; mctx->hash[2] = 0x98badcfe;
mctx->hash[3] = 0x10325476; mctx->hash[3] = 0x10325476;
mctx->byte_count = 0; mctx->byte_count = 0;
return 0;
} }
static void md5_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len) static int md5_update(struct shash_desc *desc, const u8 *data, unsigned int len)
{ {
struct md5_ctx *mctx = crypto_tfm_ctx(tfm); struct md5_ctx *mctx = shash_desc_ctx(desc);
const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f); const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f);
mctx->byte_count += len; mctx->byte_count += len;
...@@ -168,7 +170,7 @@ static void md5_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len) ...@@ -168,7 +170,7 @@ static void md5_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len)
if (avail > len) { if (avail > len) {
memcpy((char *)mctx->block + (sizeof(mctx->block) - avail), memcpy((char *)mctx->block + (sizeof(mctx->block) - avail),
data, len); data, len);
return; return 0;
} }
memcpy((char *)mctx->block + (sizeof(mctx->block) - avail), 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,11 +188,13 @@ static void md5_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len)
} }
memcpy(mctx->block, data, len); memcpy(mctx->block, data, len);
return 0;
} }
static void md5_final(struct crypto_tfm *tfm, u8 *out) static int md5_final(struct shash_desc *desc, u8 *out)
{ {
struct md5_ctx *mctx = crypto_tfm_ctx(tfm); struct md5_ctx *mctx = shash_desc_ctx(desc);
const unsigned int offset = mctx->byte_count & 0x3f; const unsigned int offset = mctx->byte_count & 0x3f;
char *p = (char *)mctx->block + offset; char *p = (char *)mctx->block + offset;
int padding = 56 - (offset + 1); int padding = 56 - (offset + 1);
...@@ -212,30 +216,32 @@ static void md5_final(struct crypto_tfm *tfm, u8 *out) ...@@ -212,30 +216,32 @@ static void md5_final(struct crypto_tfm *tfm, u8 *out)
cpu_to_le32_array(mctx->hash, sizeof(mctx->hash) / sizeof(u32)); cpu_to_le32_array(mctx->hash, sizeof(mctx->hash) / sizeof(u32));
memcpy(out, mctx->hash, sizeof(mctx->hash)); memcpy(out, mctx->hash, sizeof(mctx->hash));
memset(mctx, 0, sizeof(*mctx)); memset(mctx, 0, sizeof(*mctx));
return 0;
} }
static struct crypto_alg alg = { static struct shash_alg alg = {
.cra_name = "md5", .digestsize = MD5_DIGEST_SIZE,
.cra_flags = CRYPTO_ALG_TYPE_DIGEST, .init = md5_init,
.cra_blocksize = MD5_HMAC_BLOCK_SIZE, .update = md5_update,
.cra_ctxsize = sizeof(struct md5_ctx), .final = md5_final,
.cra_module = THIS_MODULE, .descsize = sizeof(struct md5_ctx),
.cra_list = LIST_HEAD_INIT(alg.cra_list), .base = {
.cra_u = { .digest = { .cra_name = "md5",
.dia_digestsize = MD5_DIGEST_SIZE, .cra_flags = CRYPTO_ALG_TYPE_SHASH,
.dia_init = md5_init, .cra_blocksize = MD5_HMAC_BLOCK_SIZE,
.dia_update = md5_update, .cra_module = THIS_MODULE,
.dia_final = md5_final } } }
}; };
static int __init md5_mod_init(void) static int __init md5_mod_init(void)
{ {
return crypto_register_alg(&alg); return crypto_register_shash(&alg);
} }
static void __exit md5_mod_fini(void) static void __exit md5_mod_fini(void)
{ {
crypto_unregister_alg(&alg); crypto_unregister_shash(&alg);
} }
module_init(md5_mod_init); module_init(md5_mod_init);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment