提交 808a1763 编写于 作者: A Adrian-Ken Rueegsegger 提交者: Herbert Xu

crypto: md4 - Switch to shash

This patch changes md4 to the new shash interface.
Signed-off-by: NAdrian-Ken Rueegsegger <ken@codelabs.ch>
Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
上级 54ccb367
...@@ -276,7 +276,7 @@ config CRYPTO_CRC32C_INTEL ...@@ -276,7 +276,7 @@ config CRYPTO_CRC32C_INTEL
config CRYPTO_MD4 config CRYPTO_MD4
tristate "MD4 digest algorithm" tristate "MD4 digest algorithm"
select CRYPTO_ALGAPI select CRYPTO_HASH
help help
MD4 message digest algorithm (RFC1320). MD4 message digest algorithm (RFC1320).
......
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
* (at your option) any later version. * (at your option) any later version.
* *
*/ */
#include <crypto/internal/hash.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/crypto.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/types.h> #include <linux/types.h>
...@@ -58,7 +58,7 @@ static inline u32 H(u32 x, u32 y, u32 z) ...@@ -58,7 +58,7 @@ static inline u32 H(u32 x, u32 y, u32 z)
{ {
return x ^ y ^ z; return x ^ y ^ z;
} }
#define ROUND1(a,b,c,d,k,s) (a = lshift(a + F(b,c,d) + k, s)) #define ROUND1(a,b,c,d,k,s) (a = lshift(a + F(b,c,d) + k, s))
#define ROUND2(a,b,c,d,k,s) (a = lshift(a + G(b,c,d) + k + (u32)0x5A827999,s)) #define ROUND2(a,b,c,d,k,s) (a = lshift(a + G(b,c,d) + k + (u32)0x5A827999,s))
#define ROUND3(a,b,c,d,k,s) (a = lshift(a + H(b,c,d) + k + (u32)0x6ED9EBA1,s)) #define ROUND3(a,b,c,d,k,s) (a = lshift(a + H(b,c,d) + k + (u32)0x6ED9EBA1,s))
...@@ -152,20 +152,22 @@ static inline void md4_transform_helper(struct md4_ctx *ctx) ...@@ -152,20 +152,22 @@ static inline void md4_transform_helper(struct md4_ctx *ctx)
md4_transform(ctx->hash, ctx->block); md4_transform(ctx->hash, ctx->block);
} }
static void md4_init(struct crypto_tfm *tfm) static int md4_init(struct shash_desc *desc)
{ {
struct md4_ctx *mctx = crypto_tfm_ctx(tfm); struct md4_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 md4_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len) static int md4_update(struct shash_desc *desc, const u8 *data, unsigned int len)
{ {
struct md4_ctx *mctx = crypto_tfm_ctx(tfm); struct md4_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;
...@@ -173,7 +175,7 @@ static void md4_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len) ...@@ -173,7 +175,7 @@ static void md4_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),
...@@ -191,11 +193,13 @@ static void md4_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len) ...@@ -191,11 +193,13 @@ static void md4_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 md4_final(struct crypto_tfm *tfm, u8 *out) static int md4_final(struct shash_desc *desc, u8 *out)
{ {
struct md4_ctx *mctx = crypto_tfm_ctx(tfm); struct md4_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);
...@@ -217,30 +221,32 @@ static void md4_final(struct crypto_tfm *tfm, u8 *out) ...@@ -217,30 +221,32 @@ static void md4_final(struct crypto_tfm *tfm, u8 *out)
cpu_to_le32_array(mctx->hash, ARRAY_SIZE(mctx->hash)); cpu_to_le32_array(mctx->hash, ARRAY_SIZE(mctx->hash));
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 = "md4", .digestsize = MD4_DIGEST_SIZE,
.cra_flags = CRYPTO_ALG_TYPE_DIGEST, .init = md4_init,
.cra_blocksize = MD4_HMAC_BLOCK_SIZE, .update = md4_update,
.cra_ctxsize = sizeof(struct md4_ctx), .final = md4_final,
.cra_module = THIS_MODULE, .descsize = sizeof(struct md4_ctx),
.cra_list = LIST_HEAD_INIT(alg.cra_list), .base = {
.cra_u = { .digest = { .cra_name = "md4",
.dia_digestsize = MD4_DIGEST_SIZE, .cra_flags = CRYPTO_ALG_TYPE_SHASH,
.dia_init = md4_init, .cra_blocksize = MD4_HMAC_BLOCK_SIZE,
.dia_update = md4_update, .cra_module = THIS_MODULE,
.dia_final = md4_final } } }
}; };
static int __init md4_mod_init(void) static int __init md4_mod_init(void)
{ {
return crypto_register_alg(&alg); return crypto_register_shash(&alg);
} }
static void __exit md4_mod_fini(void) static void __exit md4_mod_fini(void)
{ {
crypto_unregister_alg(&alg); crypto_unregister_shash(&alg);
} }
module_init(md4_mod_init); module_init(md4_mod_init);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册