Commit 7c4468bc authored by Herbert Xu's avatar Herbert Xu

crypto: rmd128 - Switch to shash

This patch changes rmd128 to the new shash interface.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent d35d2454
...@@ -297,7 +297,7 @@ config CRYPTO_MICHAEL_MIC ...@@ -297,7 +297,7 @@ config CRYPTO_MICHAEL_MIC
config CRYPTO_RMD128 config CRYPTO_RMD128
tristate "RIPEMD-128 digest algorithm" tristate "RIPEMD-128 digest algorithm"
select CRYPTO_ALGAPI select CRYPTO_HASH
help help
RIPEMD-128 (ISO/IEC 10118-3:2004). RIPEMD-128 (ISO/IEC 10118-3:2004).
......
...@@ -13,11 +13,10 @@ ...@@ -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>
...@@ -218,9 +217,9 @@ static void rmd128_transform(u32 *state, const __le32 *in) ...@@ -218,9 +217,9 @@ static void rmd128_transform(u32 *state, const __le32 *in)
return; return;
} }
static void rmd128_init(struct crypto_tfm *tfm) static int rmd128_init(struct shash_desc *desc)
{ {
struct rmd128_ctx *rctx = crypto_tfm_ctx(tfm); struct rmd128_ctx *rctx = shash_desc_ctx(desc);
rctx->byte_count = 0; rctx->byte_count = 0;
...@@ -230,12 +229,14 @@ static void rmd128_init(struct crypto_tfm *tfm) ...@@ -230,12 +229,14 @@ static void rmd128_init(struct crypto_tfm *tfm)
rctx->state[3] = RMD_H3; rctx->state[3] = RMD_H3;
memset(rctx->buffer, 0, sizeof(rctx->buffer)); memset(rctx->buffer, 0, sizeof(rctx->buffer));
return 0;
} }
static void rmd128_update(struct crypto_tfm *tfm, const u8 *data, static int rmd128_update(struct shash_desc *desc, const u8 *data,
unsigned int len) unsigned int len)
{ {
struct rmd128_ctx *rctx = crypto_tfm_ctx(tfm); struct rmd128_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;
...@@ -244,7 +245,7 @@ static void rmd128_update(struct crypto_tfm *tfm, const u8 *data, ...@@ -244,7 +245,7 @@ static void rmd128_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),
...@@ -262,12 +263,15 @@ static void rmd128_update(struct crypto_tfm *tfm, const u8 *data, ...@@ -262,12 +263,15 @@ static void rmd128_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 rmd128_final(struct crypto_tfm *tfm, u8 *out) static int rmd128_final(struct shash_desc *desc, u8 *out)
{ {
struct rmd128_ctx *rctx = crypto_tfm_ctx(tfm); struct rmd128_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;
...@@ -278,10 +282,10 @@ static void rmd128_final(struct crypto_tfm *tfm, u8 *out) ...@@ -278,10 +282,10 @@ static void rmd128_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);
rmd128_update(tfm, padding, padlen); rmd128_update(desc, padding, padlen);
/* Append length */ /* Append length */
rmd128_update(tfm, (const u8 *)&bits, sizeof(bits)); rmd128_update(desc, (const u8 *)&bits, sizeof(bits));
/* Store state in digest */ /* Store state in digest */
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
...@@ -289,31 +293,32 @@ static void rmd128_final(struct crypto_tfm *tfm, u8 *out) ...@@ -289,31 +293,32 @@ static void rmd128_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 = "rmd128", .digestsize = RMD128_DIGEST_SIZE,
.cra_driver_name = "rmd128", .init = rmd128_init,
.cra_flags = CRYPTO_ALG_TYPE_DIGEST, .update = rmd128_update,
.cra_blocksize = RMD128_BLOCK_SIZE, .final = rmd128_final,
.cra_ctxsize = sizeof(struct rmd128_ctx), .descsize = sizeof(struct rmd128_ctx),
.cra_module = THIS_MODULE, .base = {
.cra_list = LIST_HEAD_INIT(alg.cra_list), .cra_name = "rmd128",
.cra_u = { .digest = { .cra_flags = CRYPTO_ALG_TYPE_SHASH,
.dia_digestsize = RMD128_DIGEST_SIZE, .cra_blocksize = RMD128_BLOCK_SIZE,
.dia_init = rmd128_init, .cra_module = THIS_MODULE,
.dia_update = rmd128_update, }
.dia_final = rmd128_final } }
}; };
static int __init rmd128_mod_init(void) static int __init rmd128_mod_init(void)
{ {
return crypto_register_alg(&alg); return crypto_register_shash(&alg);
} }
static void __exit rmd128_mod_fini(void) static void __exit rmd128_mod_fini(void)
{ {
crypto_unregister_alg(&alg); crypto_unregister_shash(&alg);
} }
module_init(rmd128_mod_init); module_init(rmd128_mod_init);
...@@ -321,5 +326,3 @@ module_exit(rmd128_mod_fini); ...@@ -321,5 +326,3 @@ module_exit(rmd128_mod_fini);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("RIPEMD-128 Message Digest"); MODULE_DESCRIPTION("RIPEMD-128 Message Digest");
MODULE_ALIAS("rmd128");
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