crypto: rmd320 - Switch to shash

This patch changes rmd320 to the new shash interface.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
Herbert Xu 2008-11-08 10:11:09 +08:00
parent d8a5e2e9f4
commit 3b8efb4c41
2 changed files with 33 additions and 30 deletions

View file

@ -339,7 +339,7 @@ config CRYPTO_RMD256
config CRYPTO_RMD320 config CRYPTO_RMD320
tristate "RIPEMD-320 digest algorithm" tristate "RIPEMD-320 digest algorithm"
select CRYPTO_ALGAPI select CRYPTO_HASH
help help
RIPEMD-320 is an optional extension of RIPEMD-160 with a RIPEMD-320 is an optional extension of RIPEMD-160 with a
320 bit hash. It is intended for applications that require 320 bit hash. It is intended for applications that require

View file

@ -13,11 +13,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/mm.h> #include <linux/mm.h>
#include <linux/crypto.h>
#include <linux/cryptohash.h>
#include <linux/types.h> #include <linux/types.h>
#include <asm/byteorder.h> #include <asm/byteorder.h>
@ -280,9 +279,9 @@ static void rmd320_transform(u32 *state, const __le32 *in)
return; return;
} }
static void rmd320_init(struct crypto_tfm *tfm) static int rmd320_init(struct shash_desc *desc)
{ {
struct rmd320_ctx *rctx = crypto_tfm_ctx(tfm); struct rmd320_ctx *rctx = shash_desc_ctx(desc);
rctx->byte_count = 0; rctx->byte_count = 0;
@ -298,12 +297,14 @@ static void rmd320_init(struct crypto_tfm *tfm)
rctx->state[9] = RMD_H9; rctx->state[9] = RMD_H9;
memset(rctx->buffer, 0, sizeof(rctx->buffer)); memset(rctx->buffer, 0, sizeof(rctx->buffer));
return 0;
} }
static void rmd320_update(struct crypto_tfm *tfm, const u8 *data, static int rmd320_update(struct shash_desc *desc, const u8 *data,
unsigned int len) unsigned int len)
{ {
struct rmd320_ctx *rctx = crypto_tfm_ctx(tfm); struct rmd320_ctx *rctx = shash_desc_ctx(desc);
const u32 avail = sizeof(rctx->buffer) - (rctx->byte_count & 0x3f); const u32 avail = sizeof(rctx->buffer) - (rctx->byte_count & 0x3f);
rctx->byte_count += len; rctx->byte_count += len;
@ -312,7 +313,7 @@ static void rmd320_update(struct crypto_tfm *tfm, const u8 *data,
if (avail > len) { if (avail > len) {
memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail), memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail),
data, len); data, len);
return; goto out;
} }
memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail), memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail),
@ -330,12 +331,15 @@ static void rmd320_update(struct crypto_tfm *tfm, const u8 *data,
} }
memcpy(rctx->buffer, data, len); memcpy(rctx->buffer, data, len);
out:
return 0;
} }
/* Add padding and return the message digest. */ /* Add padding and return the message digest. */
static void rmd320_final(struct crypto_tfm *tfm, u8 *out) static int rmd320_final(struct shash_desc *desc, u8 *out)
{ {
struct rmd320_ctx *rctx = crypto_tfm_ctx(tfm); struct rmd320_ctx *rctx = shash_desc_ctx(desc);
u32 i, index, padlen; u32 i, index, padlen;
__le64 bits; __le64 bits;
__le32 *dst = (__le32 *)out; __le32 *dst = (__le32 *)out;
@ -346,10 +350,10 @@ static void rmd320_final(struct crypto_tfm *tfm, u8 *out)
/* Pad out to 56 mod 64 */ /* Pad out to 56 mod 64 */
index = rctx->byte_count & 0x3f; index = rctx->byte_count & 0x3f;
padlen = (index < 56) ? (56 - index) : ((64+56) - index); padlen = (index < 56) ? (56 - index) : ((64+56) - index);
rmd320_update(tfm, padding, padlen); rmd320_update(desc, padding, padlen);
/* Append length */ /* Append length */
rmd320_update(tfm, (const u8 *)&bits, sizeof(bits)); rmd320_update(desc, (const u8 *)&bits, sizeof(bits));
/* Store state in digest */ /* Store state in digest */
for (i = 0; i < 10; i++) for (i = 0; i < 10; i++)
@ -357,31 +361,32 @@ static void rmd320_final(struct crypto_tfm *tfm, u8 *out)
/* Wipe context */ /* Wipe context */
memset(rctx, 0, sizeof(*rctx)); memset(rctx, 0, sizeof(*rctx));
return 0;
} }
static struct crypto_alg alg = { static struct shash_alg alg = {
.cra_name = "rmd320", .digestsize = RMD320_DIGEST_SIZE,
.cra_driver_name = "rmd320", .init = rmd320_init,
.cra_flags = CRYPTO_ALG_TYPE_DIGEST, .update = rmd320_update,
.cra_blocksize = RMD320_BLOCK_SIZE, .final = rmd320_final,
.cra_ctxsize = sizeof(struct rmd320_ctx), .descsize = sizeof(struct rmd320_ctx),
.cra_module = THIS_MODULE, .base = {
.cra_list = LIST_HEAD_INIT(alg.cra_list), .cra_name = "rmd320",
.cra_u = { .digest = { .cra_flags = CRYPTO_ALG_TYPE_SHASH,
.dia_digestsize = RMD320_DIGEST_SIZE, .cra_blocksize = RMD320_BLOCK_SIZE,
.dia_init = rmd320_init, .cra_module = THIS_MODULE,
.dia_update = rmd320_update, }
.dia_final = rmd320_final } }
}; };
static int __init rmd320_mod_init(void) static int __init rmd320_mod_init(void)
{ {
return crypto_register_alg(&alg); return crypto_register_shash(&alg);
} }
static void __exit rmd320_mod_fini(void) static void __exit rmd320_mod_fini(void)
{ {
crypto_unregister_alg(&alg); crypto_unregister_shash(&alg);
} }
module_init(rmd320_mod_init); module_init(rmd320_mod_init);
@ -389,5 +394,3 @@ module_exit(rmd320_mod_fini);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("RIPEMD-320 Message Digest"); MODULE_DESCRIPTION("RIPEMD-320 Message Digest");
MODULE_ALIAS("rmd320");