aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/rmd160.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2008-11-07 20:18:51 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2008-12-24 19:02:10 -0500
commite5835fba0206a331bdefdf5d805d1a384af37c44 (patch)
tree78df086f190348f29d9028e0ee76aa4d666618a0 /crypto/rmd160.c
parent7c4468bc011131e77d0a872d6d9942390f8217ea (diff)
crypto: rmd160 - Switch to shash
This patch changes rmd160 to the new shash interface. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/rmd160.c')
-rw-r--r--crypto/rmd160.c61
1 files changed, 32 insertions, 29 deletions
diff --git a/crypto/rmd160.c b/crypto/rmd160.c
index f001ec775e1f..472261fc913f 100644
--- a/crypto/rmd160.c
+++ b/crypto/rmd160.c
@@ -13,11 +13,10 @@
13 * any later version. 13 * any later version.
14 * 14 *
15 */ 15 */
16#include <crypto/internal/hash.h>
16#include <linux/init.h> 17#include <linux/init.h>
17#include <linux/module.h> 18#include <linux/module.h>
18#include <linux/mm.h> 19#include <linux/mm.h>
19#include <linux/crypto.h>
20#include <linux/cryptohash.h>
21#include <linux/types.h> 20#include <linux/types.h>
22#include <asm/byteorder.h> 21#include <asm/byteorder.h>
23 22
@@ -261,9 +260,9 @@ static void rmd160_transform(u32 *state, const __le32 *in)
261 return; 260 return;
262} 261}
263 262
264static void rmd160_init(struct crypto_tfm *tfm) 263static int rmd160_init(struct shash_desc *desc)
265{ 264{
266 struct rmd160_ctx *rctx = crypto_tfm_ctx(tfm); 265 struct rmd160_ctx *rctx = shash_desc_ctx(desc);
267 266
268 rctx->byte_count = 0; 267 rctx->byte_count = 0;
269 268
@@ -274,12 +273,14 @@ static void rmd160_init(struct crypto_tfm *tfm)
274 rctx->state[4] = RMD_H4; 273 rctx->state[4] = RMD_H4;
275 274
276 memset(rctx->buffer, 0, sizeof(rctx->buffer)); 275 memset(rctx->buffer, 0, sizeof(rctx->buffer));
276
277 return 0;
277} 278}
278 279
279static void rmd160_update(struct crypto_tfm *tfm, const u8 *data, 280static int rmd160_update(struct shash_desc *desc, const u8 *data,
280 unsigned int len) 281 unsigned int len)
281{ 282{
282 struct rmd160_ctx *rctx = crypto_tfm_ctx(tfm); 283 struct rmd160_ctx *rctx = shash_desc_ctx(desc);
283 const u32 avail = sizeof(rctx->buffer) - (rctx->byte_count & 0x3f); 284 const u32 avail = sizeof(rctx->buffer) - (rctx->byte_count & 0x3f);
284 285
285 rctx->byte_count += len; 286 rctx->byte_count += len;
@@ -288,7 +289,7 @@ static void rmd160_update(struct crypto_tfm *tfm, const u8 *data,
288 if (avail > len) { 289 if (avail > len) {
289 memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail), 290 memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail),
290 data, len); 291 data, len);
291 return; 292 goto out;
292 } 293 }
293 294
294 memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail), 295 memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail),
@@ -306,12 +307,15 @@ static void rmd160_update(struct crypto_tfm *tfm, const u8 *data,
306 } 307 }
307 308
308 memcpy(rctx->buffer, data, len); 309 memcpy(rctx->buffer, data, len);
310
311out:
312 return 0;
309} 313}
310 314
311/* Add padding and return the message digest. */ 315/* Add padding and return the message digest. */
312static void rmd160_final(struct crypto_tfm *tfm, u8 *out) 316static int rmd160_final(struct shash_desc *desc, u8 *out)
313{ 317{
314 struct rmd160_ctx *rctx = crypto_tfm_ctx(tfm); 318 struct rmd160_ctx *rctx = shash_desc_ctx(desc);
315 u32 i, index, padlen; 319 u32 i, index, padlen;
316 __le64 bits; 320 __le64 bits;
317 __le32 *dst = (__le32 *)out; 321 __le32 *dst = (__le32 *)out;
@@ -322,10 +326,10 @@ static void rmd160_final(struct crypto_tfm *tfm, u8 *out)
322 /* Pad out to 56 mod 64 */ 326 /* Pad out to 56 mod 64 */
323 index = rctx->byte_count & 0x3f; 327 index = rctx->byte_count & 0x3f;
324 padlen = (index < 56) ? (56 - index) : ((64+56) - index); 328 padlen = (index < 56) ? (56 - index) : ((64+56) - index);
325 rmd160_update(tfm, padding, padlen); 329 rmd160_update(desc, padding, padlen);
326 330
327 /* Append length */ 331 /* Append length */
328 rmd160_update(tfm, (const u8 *)&bits, sizeof(bits)); 332 rmd160_update(desc, (const u8 *)&bits, sizeof(bits));
329 333
330 /* Store state in digest */ 334 /* Store state in digest */
331 for (i = 0; i < 5; i++) 335 for (i = 0; i < 5; i++)
@@ -333,31 +337,32 @@ static void rmd160_final(struct crypto_tfm *tfm, u8 *out)
333 337
334 /* Wipe context */ 338 /* Wipe context */
335 memset(rctx, 0, sizeof(*rctx)); 339 memset(rctx, 0, sizeof(*rctx));
340
341 return 0;
336} 342}
337 343
338static struct crypto_alg alg = { 344static struct shash_alg alg = {
339 .cra_name = "rmd160", 345 .digestsize = RMD160_DIGEST_SIZE,
340 .cra_driver_name = "rmd160", 346 .init = rmd160_init,
341 .cra_flags = CRYPTO_ALG_TYPE_DIGEST, 347 .update = rmd160_update,
342 .cra_blocksize = RMD160_BLOCK_SIZE, 348 .final = rmd160_final,
343 .cra_ctxsize = sizeof(struct rmd160_ctx), 349 .descsize = sizeof(struct rmd160_ctx),
344 .cra_module = THIS_MODULE, 350 .base = {
345 .cra_list = LIST_HEAD_INIT(alg.cra_list), 351 .cra_name = "rmd160",
346 .cra_u = { .digest = { 352 .cra_flags = CRYPTO_ALG_TYPE_SHASH,
347 .dia_digestsize = RMD160_DIGEST_SIZE, 353 .cra_blocksize = RMD160_BLOCK_SIZE,
348 .dia_init = rmd160_init, 354 .cra_module = THIS_MODULE,
349 .dia_update = rmd160_update, 355 }
350 .dia_final = rmd160_final } }
351}; 356};
352 357
353static int __init rmd160_mod_init(void) 358static int __init rmd160_mod_init(void)
354{ 359{
355 return crypto_register_alg(&alg); 360 return crypto_register_shash(&alg);
356} 361}
357 362
358static void __exit rmd160_mod_fini(void) 363static void __exit rmd160_mod_fini(void)
359{ 364{
360 crypto_unregister_alg(&alg); 365 crypto_unregister_shash(&alg);
361} 366}
362 367
363module_init(rmd160_mod_init); 368module_init(rmd160_mod_init);
@@ -365,5 +370,3 @@ module_exit(rmd160_mod_fini);
365 370
366MODULE_LICENSE("GPL"); 371MODULE_LICENSE("GPL");
367MODULE_DESCRIPTION("RIPEMD-160 Message Digest"); 372MODULE_DESCRIPTION("RIPEMD-160 Message Digest");
368
369MODULE_ALIAS("rmd160");