aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2008-11-07 21:11:09 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2008-12-24 19:02:13 -0500
commit3b8efb4c4147094652570d7791a516d07b7df8c2 (patch)
treea770afe99c56bfe382598f2bd69442074d4dbf26
parentd8a5e2e9f4e70ade136c67ce8242f0db4c2cddc7 (diff)
crypto: rmd320 - Switch to shash
This patch changes rmd320 to the new shash interface. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--crypto/Kconfig2
-rw-r--r--crypto/rmd320.c61
2 files changed, 33 insertions, 30 deletions
diff --git a/crypto/Kconfig b/crypto/Kconfig
index 7f3d7954c929..edf6c71b576e 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -339,7 +339,7 @@ config CRYPTO_RMD256
339 339
340config CRYPTO_RMD320 340config CRYPTO_RMD320
341 tristate "RIPEMD-320 digest algorithm" 341 tristate "RIPEMD-320 digest algorithm"
342 select CRYPTO_ALGAPI 342 select CRYPTO_HASH
343 help 343 help
344 RIPEMD-320 is an optional extension of RIPEMD-160 with a 344 RIPEMD-320 is an optional extension of RIPEMD-160 with a
345 320 bit hash. It is intended for applications that require 345 320 bit hash. It is intended for applications that require
diff --git a/crypto/rmd320.c b/crypto/rmd320.c
index b143d66e42c8..86becaba2f05 100644
--- a/crypto/rmd320.c
+++ b/crypto/rmd320.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
@@ -280,9 +279,9 @@ static void rmd320_transform(u32 *state, const __le32 *in)
280 return; 279 return;
281} 280}
282 281
283static void rmd320_init(struct crypto_tfm *tfm) 282static int rmd320_init(struct shash_desc *desc)
284{ 283{
285 struct rmd320_ctx *rctx = crypto_tfm_ctx(tfm); 284 struct rmd320_ctx *rctx = shash_desc_ctx(desc);
286 285
287 rctx->byte_count = 0; 286 rctx->byte_count = 0;
288 287
@@ -298,12 +297,14 @@ static void rmd320_init(struct crypto_tfm *tfm)
298 rctx->state[9] = RMD_H9; 297 rctx->state[9] = RMD_H9;
299 298
300 memset(rctx->buffer, 0, sizeof(rctx->buffer)); 299 memset(rctx->buffer, 0, sizeof(rctx->buffer));
300
301 return 0;
301} 302}
302 303
303static void rmd320_update(struct crypto_tfm *tfm, const u8 *data, 304static int rmd320_update(struct shash_desc *desc, const u8 *data,
304 unsigned int len) 305 unsigned int len)
305{ 306{
306 struct rmd320_ctx *rctx = crypto_tfm_ctx(tfm); 307 struct rmd320_ctx *rctx = shash_desc_ctx(desc);
307 const u32 avail = sizeof(rctx->buffer) - (rctx->byte_count & 0x3f); 308 const u32 avail = sizeof(rctx->buffer) - (rctx->byte_count & 0x3f);
308 309
309 rctx->byte_count += len; 310 rctx->byte_count += len;
@@ -312,7 +313,7 @@ static void rmd320_update(struct crypto_tfm *tfm, const u8 *data,
312 if (avail > len) { 313 if (avail > len) {
313 memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail), 314 memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail),
314 data, len); 315 data, len);
315 return; 316 goto out;
316 } 317 }
317 318
318 memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail), 319 memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail),
@@ -330,12 +331,15 @@ static void rmd320_update(struct crypto_tfm *tfm, const u8 *data,
330 } 331 }
331 332
332 memcpy(rctx->buffer, data, len); 333 memcpy(rctx->buffer, data, len);
334
335out:
336 return 0;
333} 337}
334 338
335/* Add padding and return the message digest. */ 339/* Add padding and return the message digest. */
336static void rmd320_final(struct crypto_tfm *tfm, u8 *out) 340static int rmd320_final(struct shash_desc *desc, u8 *out)
337{ 341{
338 struct rmd320_ctx *rctx = crypto_tfm_ctx(tfm); 342 struct rmd320_ctx *rctx = shash_desc_ctx(desc);
339 u32 i, index, padlen; 343 u32 i, index, padlen;
340 __le64 bits; 344 __le64 bits;
341 __le32 *dst = (__le32 *)out; 345 __le32 *dst = (__le32 *)out;
@@ -346,10 +350,10 @@ static void rmd320_final(struct crypto_tfm *tfm, u8 *out)
346 /* Pad out to 56 mod 64 */ 350 /* Pad out to 56 mod 64 */
347 index = rctx->byte_count & 0x3f; 351 index = rctx->byte_count & 0x3f;
348 padlen = (index < 56) ? (56 - index) : ((64+56) - index); 352 padlen = (index < 56) ? (56 - index) : ((64+56) - index);
349 rmd320_update(tfm, padding, padlen); 353 rmd320_update(desc, padding, padlen);
350 354
351 /* Append length */ 355 /* Append length */
352 rmd320_update(tfm, (const u8 *)&bits, sizeof(bits)); 356 rmd320_update(desc, (const u8 *)&bits, sizeof(bits));
353 357
354 /* Store state in digest */ 358 /* Store state in digest */
355 for (i = 0; i < 10; i++) 359 for (i = 0; i < 10; i++)
@@ -357,31 +361,32 @@ static void rmd320_final(struct crypto_tfm *tfm, u8 *out)
357 361
358 /* Wipe context */ 362 /* Wipe context */
359 memset(rctx, 0, sizeof(*rctx)); 363 memset(rctx, 0, sizeof(*rctx));
364
365 return 0;
360} 366}
361 367
362static struct crypto_alg alg = { 368static struct shash_alg alg = {
363 .cra_name = "rmd320", 369 .digestsize = RMD320_DIGEST_SIZE,
364 .cra_driver_name = "rmd320", 370 .init = rmd320_init,
365 .cra_flags = CRYPTO_ALG_TYPE_DIGEST, 371 .update = rmd320_update,
366 .cra_blocksize = RMD320_BLOCK_SIZE, 372 .final = rmd320_final,
367 .cra_ctxsize = sizeof(struct rmd320_ctx), 373 .descsize = sizeof(struct rmd320_ctx),
368 .cra_module = THIS_MODULE, 374 .base = {
369 .cra_list = LIST_HEAD_INIT(alg.cra_list), 375 .cra_name = "rmd320",
370 .cra_u = { .digest = { 376 .cra_flags = CRYPTO_ALG_TYPE_SHASH,
371 .dia_digestsize = RMD320_DIGEST_SIZE, 377 .cra_blocksize = RMD320_BLOCK_SIZE,
372 .dia_init = rmd320_init, 378 .cra_module = THIS_MODULE,
373 .dia_update = rmd320_update, 379 }
374 .dia_final = rmd320_final } }
375}; 380};
376 381
377static int __init rmd320_mod_init(void) 382static int __init rmd320_mod_init(void)
378{ 383{
379 return crypto_register_alg(&alg); 384 return crypto_register_shash(&alg);
380} 385}
381 386
382static void __exit rmd320_mod_fini(void) 387static void __exit rmd320_mod_fini(void)
383{ 388{
384 crypto_unregister_alg(&alg); 389 crypto_unregister_shash(&alg);
385} 390}
386 391
387module_init(rmd320_mod_init); 392module_init(rmd320_mod_init);
@@ -389,5 +394,3 @@ module_exit(rmd320_mod_fini);
389 394
390MODULE_LICENSE("GPL"); 395MODULE_LICENSE("GPL");
391MODULE_DESCRIPTION("RIPEMD-320 Message Digest"); 396MODULE_DESCRIPTION("RIPEMD-320 Message Digest");
392
393MODULE_ALIAS("rmd320");