diff options
author | Adrian-Ken Rueegsegger <ken@codelabs.ch> | 2008-12-03 06:58:32 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2008-12-24 19:02:21 -0500 |
commit | f63fbd3d501b4283e1551e195cb74434a838064f (patch) | |
tree | d43019ed57263dc44f15c06a62c46107003dee1b | |
parent | 50e109b5b9c1f734e91a6e9b557bce48c9a88654 (diff) |
crypto: tgr192 - Switch to shash
This patch changes tgr192, tgr160 and tgr128 to the new shash interface.
Signed-off-by: Adrian-Ken Rueegsegger <ken@codelabs.ch>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | crypto/Kconfig | 2 | ||||
-rw-r--r-- | crypto/tgr192.c | 135 |
2 files changed, 72 insertions, 65 deletions
diff --git a/crypto/Kconfig b/crypto/Kconfig index 3d04fa880e44..a863d7e5f9e8 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig | |||
@@ -381,7 +381,7 @@ config CRYPTO_SHA512 | |||
381 | 381 | ||
382 | config CRYPTO_TGR192 | 382 | config CRYPTO_TGR192 |
383 | tristate "Tiger digest algorithms" | 383 | tristate "Tiger digest algorithms" |
384 | select CRYPTO_ALGAPI | 384 | select CRYPTO_HASH |
385 | help | 385 | help |
386 | Tiger hash algorithm 192, 160 and 128-bit hashes | 386 | Tiger hash algorithm 192, 160 and 128-bit hashes |
387 | 387 | ||
diff --git a/crypto/tgr192.c b/crypto/tgr192.c index a92414f24beb..cbca4f208c9f 100644 --- a/crypto/tgr192.c +++ b/crypto/tgr192.c | |||
@@ -21,11 +21,11 @@ | |||
21 | * (at your option) any later version. | 21 | * (at your option) any later version. |
22 | * | 22 | * |
23 | */ | 23 | */ |
24 | #include <crypto/internal/hash.h> | ||
24 | #include <linux/init.h> | 25 | #include <linux/init.h> |
25 | #include <linux/module.h> | 26 | #include <linux/module.h> |
26 | #include <linux/mm.h> | 27 | #include <linux/mm.h> |
27 | #include <asm/byteorder.h> | 28 | #include <asm/byteorder.h> |
28 | #include <linux/crypto.h> | ||
29 | #include <linux/types.h> | 29 | #include <linux/types.h> |
30 | 30 | ||
31 | #define TGR192_DIGEST_SIZE 24 | 31 | #define TGR192_DIGEST_SIZE 24 |
@@ -495,24 +495,26 @@ static void tgr192_transform(struct tgr192_ctx *tctx, const u8 * data) | |||
495 | tctx->c = c; | 495 | tctx->c = c; |
496 | } | 496 | } |
497 | 497 | ||
498 | static void tgr192_init(struct crypto_tfm *tfm) | 498 | static int tgr192_init(struct shash_desc *desc) |
499 | { | 499 | { |
500 | struct tgr192_ctx *tctx = crypto_tfm_ctx(tfm); | 500 | struct tgr192_ctx *tctx = shash_desc_ctx(desc); |
501 | 501 | ||
502 | tctx->a = 0x0123456789abcdefULL; | 502 | tctx->a = 0x0123456789abcdefULL; |
503 | tctx->b = 0xfedcba9876543210ULL; | 503 | tctx->b = 0xfedcba9876543210ULL; |
504 | tctx->c = 0xf096a5b4c3b2e187ULL; | 504 | tctx->c = 0xf096a5b4c3b2e187ULL; |
505 | tctx->nblocks = 0; | 505 | tctx->nblocks = 0; |
506 | tctx->count = 0; | 506 | tctx->count = 0; |
507 | |||
508 | return 0; | ||
507 | } | 509 | } |
508 | 510 | ||
509 | 511 | ||
510 | /* Update the message digest with the contents | 512 | /* Update the message digest with the contents |
511 | * of INBUF with length INLEN. */ | 513 | * of INBUF with length INLEN. */ |
512 | static void tgr192_update(struct crypto_tfm *tfm, const u8 *inbuf, | 514 | static int tgr192_update(struct shash_desc *desc, const u8 *inbuf, |
513 | unsigned int len) | 515 | unsigned int len) |
514 | { | 516 | { |
515 | struct tgr192_ctx *tctx = crypto_tfm_ctx(tfm); | 517 | struct tgr192_ctx *tctx = shash_desc_ctx(desc); |
516 | 518 | ||
517 | if (tctx->count == 64) { /* flush the buffer */ | 519 | if (tctx->count == 64) { /* flush the buffer */ |
518 | tgr192_transform(tctx, tctx->hash); | 520 | tgr192_transform(tctx, tctx->hash); |
@@ -520,15 +522,15 @@ static void tgr192_update(struct crypto_tfm *tfm, const u8 *inbuf, | |||
520 | tctx->nblocks++; | 522 | tctx->nblocks++; |
521 | } | 523 | } |
522 | if (!inbuf) { | 524 | if (!inbuf) { |
523 | return; | 525 | return 0; |
524 | } | 526 | } |
525 | if (tctx->count) { | 527 | if (tctx->count) { |
526 | for (; len && tctx->count < 64; len--) { | 528 | for (; len && tctx->count < 64; len--) { |
527 | tctx->hash[tctx->count++] = *inbuf++; | 529 | tctx->hash[tctx->count++] = *inbuf++; |
528 | } | 530 | } |
529 | tgr192_update(tfm, NULL, 0); | 531 | tgr192_update(desc, NULL, 0); |
530 | if (!len) { | 532 | if (!len) { |
531 | return; | 533 | return 0; |
532 | } | 534 | } |
533 | 535 | ||
534 | } | 536 | } |
@@ -543,20 +545,22 @@ static void tgr192_update(struct crypto_tfm *tfm, const u8 *inbuf, | |||
543 | for (; len && tctx->count < 64; len--) { | 545 | for (; len && tctx->count < 64; len--) { |
544 | tctx->hash[tctx->count++] = *inbuf++; | 546 | tctx->hash[tctx->count++] = *inbuf++; |
545 | } | 547 | } |
548 | |||
549 | return 0; | ||
546 | } | 550 | } |
547 | 551 | ||
548 | 552 | ||
549 | 553 | ||
550 | /* The routine terminates the computation */ | 554 | /* The routine terminates the computation */ |
551 | static void tgr192_final(struct crypto_tfm *tfm, u8 * out) | 555 | static int tgr192_final(struct shash_desc *desc, u8 * out) |
552 | { | 556 | { |
553 | struct tgr192_ctx *tctx = crypto_tfm_ctx(tfm); | 557 | struct tgr192_ctx *tctx = shash_desc_ctx(desc); |
554 | __be64 *dst = (__be64 *)out; | 558 | __be64 *dst = (__be64 *)out; |
555 | __be64 *be64p; | 559 | __be64 *be64p; |
556 | __le32 *le32p; | 560 | __le32 *le32p; |
557 | u32 t, msb, lsb; | 561 | u32 t, msb, lsb; |
558 | 562 | ||
559 | tgr192_update(tfm, NULL, 0); /* flush */ ; | 563 | tgr192_update(desc, NULL, 0); /* flush */ ; |
560 | 564 | ||
561 | msb = 0; | 565 | msb = 0; |
562 | t = tctx->nblocks; | 566 | t = tctx->nblocks; |
@@ -584,7 +588,7 @@ static void tgr192_final(struct crypto_tfm *tfm, u8 * out) | |||
584 | while (tctx->count < 64) { | 588 | while (tctx->count < 64) { |
585 | tctx->hash[tctx->count++] = 0; | 589 | tctx->hash[tctx->count++] = 0; |
586 | } | 590 | } |
587 | tgr192_update(tfm, NULL, 0); /* flush */ ; | 591 | tgr192_update(desc, NULL, 0); /* flush */ ; |
588 | memset(tctx->hash, 0, 56); /* fill next block with zeroes */ | 592 | memset(tctx->hash, 0, 56); /* fill next block with zeroes */ |
589 | } | 593 | } |
590 | /* append the 64 bit count */ | 594 | /* append the 64 bit count */ |
@@ -598,91 +602,94 @@ static void tgr192_final(struct crypto_tfm *tfm, u8 * out) | |||
598 | dst[0] = be64p[0] = cpu_to_be64(tctx->a); | 602 | dst[0] = be64p[0] = cpu_to_be64(tctx->a); |
599 | dst[1] = be64p[1] = cpu_to_be64(tctx->b); | 603 | dst[1] = be64p[1] = cpu_to_be64(tctx->b); |
600 | dst[2] = be64p[2] = cpu_to_be64(tctx->c); | 604 | dst[2] = be64p[2] = cpu_to_be64(tctx->c); |
605 | |||
606 | return 0; | ||
601 | } | 607 | } |
602 | 608 | ||
603 | static void tgr160_final(struct crypto_tfm *tfm, u8 * out) | 609 | static int tgr160_final(struct shash_desc *desc, u8 * out) |
604 | { | 610 | { |
605 | u8 D[64]; | 611 | u8 D[64]; |
606 | 612 | ||
607 | tgr192_final(tfm, D); | 613 | tgr192_final(desc, D); |
608 | memcpy(out, D, TGR160_DIGEST_SIZE); | 614 | memcpy(out, D, TGR160_DIGEST_SIZE); |
609 | memset(D, 0, TGR192_DIGEST_SIZE); | 615 | memset(D, 0, TGR192_DIGEST_SIZE); |
616 | |||
617 | return 0; | ||
610 | } | 618 | } |
611 | 619 | ||
612 | static void tgr128_final(struct crypto_tfm *tfm, u8 * out) | 620 | static int tgr128_final(struct shash_desc *desc, u8 * out) |
613 | { | 621 | { |
614 | u8 D[64]; | 622 | u8 D[64]; |
615 | 623 | ||
616 | tgr192_final(tfm, D); | 624 | tgr192_final(desc, D); |
617 | memcpy(out, D, TGR128_DIGEST_SIZE); | 625 | memcpy(out, D, TGR128_DIGEST_SIZE); |
618 | memset(D, 0, TGR192_DIGEST_SIZE); | 626 | memset(D, 0, TGR192_DIGEST_SIZE); |
627 | |||
628 | return 0; | ||
619 | } | 629 | } |
620 | 630 | ||
621 | static struct crypto_alg tgr192 = { | 631 | static struct shash_alg tgr192 = { |
622 | .cra_name = "tgr192", | 632 | .digestsize = TGR192_DIGEST_SIZE, |
623 | .cra_flags = CRYPTO_ALG_TYPE_DIGEST, | 633 | .init = tgr192_init, |
624 | .cra_blocksize = TGR192_BLOCK_SIZE, | 634 | .update = tgr192_update, |
625 | .cra_ctxsize = sizeof(struct tgr192_ctx), | 635 | .final = tgr192_final, |
626 | .cra_module = THIS_MODULE, | 636 | .descsize = sizeof(struct tgr192_ctx), |
627 | .cra_alignmask = 7, | 637 | .base = { |
628 | .cra_list = LIST_HEAD_INIT(tgr192.cra_list), | 638 | .cra_name = "tgr192", |
629 | .cra_u = {.digest = { | 639 | .cra_flags = CRYPTO_ALG_TYPE_SHASH, |
630 | .dia_digestsize = TGR192_DIGEST_SIZE, | 640 | .cra_blocksize = TGR192_BLOCK_SIZE, |
631 | .dia_init = tgr192_init, | 641 | .cra_module = THIS_MODULE, |
632 | .dia_update = tgr192_update, | 642 | } |
633 | .dia_final = tgr192_final}} | ||
634 | }; | 643 | }; |
635 | 644 | ||
636 | static struct crypto_alg tgr160 = { | 645 | static struct shash_alg tgr160 = { |
637 | .cra_name = "tgr160", | 646 | .digestsize = TGR160_DIGEST_SIZE, |
638 | .cra_flags = CRYPTO_ALG_TYPE_DIGEST, | 647 | .init = tgr192_init, |
639 | .cra_blocksize = TGR192_BLOCK_SIZE, | 648 | .update = tgr192_update, |
640 | .cra_ctxsize = sizeof(struct tgr192_ctx), | 649 | .final = tgr160_final, |
641 | .cra_module = THIS_MODULE, | 650 | .descsize = sizeof(struct tgr192_ctx), |
642 | .cra_alignmask = 7, | 651 | .base = { |
643 | .cra_list = LIST_HEAD_INIT(tgr160.cra_list), | 652 | .cra_name = "tgr160", |
644 | .cra_u = {.digest = { | 653 | .cra_flags = CRYPTO_ALG_TYPE_SHASH, |
645 | .dia_digestsize = TGR160_DIGEST_SIZE, | 654 | .cra_blocksize = TGR192_BLOCK_SIZE, |
646 | .dia_init = tgr192_init, | 655 | .cra_module = THIS_MODULE, |
647 | .dia_update = tgr192_update, | 656 | } |
648 | .dia_final = tgr160_final}} | ||
649 | }; | 657 | }; |
650 | 658 | ||
651 | static struct crypto_alg tgr128 = { | 659 | static struct shash_alg tgr128 = { |
652 | .cra_name = "tgr128", | 660 | .digestsize = TGR128_DIGEST_SIZE, |
653 | .cra_flags = CRYPTO_ALG_TYPE_DIGEST, | 661 | .init = tgr192_init, |
654 | .cra_blocksize = TGR192_BLOCK_SIZE, | 662 | .update = tgr192_update, |
655 | .cra_ctxsize = sizeof(struct tgr192_ctx), | 663 | .final = tgr128_final, |
656 | .cra_module = THIS_MODULE, | 664 | .descsize = sizeof(struct tgr192_ctx), |
657 | .cra_alignmask = 7, | 665 | .base = { |
658 | .cra_list = LIST_HEAD_INIT(tgr128.cra_list), | 666 | .cra_name = "tgr128", |
659 | .cra_u = {.digest = { | 667 | .cra_flags = CRYPTO_ALG_TYPE_SHASH, |
660 | .dia_digestsize = TGR128_DIGEST_SIZE, | 668 | .cra_blocksize = TGR192_BLOCK_SIZE, |
661 | .dia_init = tgr192_init, | 669 | .cra_module = THIS_MODULE, |
662 | .dia_update = tgr192_update, | 670 | } |
663 | .dia_final = tgr128_final}} | ||
664 | }; | 671 | }; |
665 | 672 | ||
666 | static int __init tgr192_mod_init(void) | 673 | static int __init tgr192_mod_init(void) |
667 | { | 674 | { |
668 | int ret = 0; | 675 | int ret = 0; |
669 | 676 | ||
670 | ret = crypto_register_alg(&tgr192); | 677 | ret = crypto_register_shash(&tgr192); |
671 | 678 | ||
672 | if (ret < 0) { | 679 | if (ret < 0) { |
673 | goto out; | 680 | goto out; |
674 | } | 681 | } |
675 | 682 | ||
676 | ret = crypto_register_alg(&tgr160); | 683 | ret = crypto_register_shash(&tgr160); |
677 | if (ret < 0) { | 684 | if (ret < 0) { |
678 | crypto_unregister_alg(&tgr192); | 685 | crypto_unregister_shash(&tgr192); |
679 | goto out; | 686 | goto out; |
680 | } | 687 | } |
681 | 688 | ||
682 | ret = crypto_register_alg(&tgr128); | 689 | ret = crypto_register_shash(&tgr128); |
683 | if (ret < 0) { | 690 | if (ret < 0) { |
684 | crypto_unregister_alg(&tgr192); | 691 | crypto_unregister_shash(&tgr192); |
685 | crypto_unregister_alg(&tgr160); | 692 | crypto_unregister_shash(&tgr160); |
686 | } | 693 | } |
687 | out: | 694 | out: |
688 | return ret; | 695 | return ret; |
@@ -690,9 +697,9 @@ static int __init tgr192_mod_init(void) | |||
690 | 697 | ||
691 | static void __exit tgr192_mod_fini(void) | 698 | static void __exit tgr192_mod_fini(void) |
692 | { | 699 | { |
693 | crypto_unregister_alg(&tgr192); | 700 | crypto_unregister_shash(&tgr192); |
694 | crypto_unregister_alg(&tgr160); | 701 | crypto_unregister_shash(&tgr160); |
695 | crypto_unregister_alg(&tgr128); | 702 | crypto_unregister_shash(&tgr128); |
696 | } | 703 | } |
697 | 704 | ||
698 | MODULE_ALIAS("tgr160"); | 705 | MODULE_ALIAS("tgr160"); |