Commit f63fbd3d501b4283e1551e195cb74434a838064f
Committed by
Herbert Xu
1 parent
50e109b5b9
Exists in
master
and in
4 other branches
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>
Showing 2 changed files with 72 additions and 65 deletions Side-by-side Diff
crypto/Kconfig
crypto/tgr192.c
... | ... | @@ -21,11 +21,11 @@ |
21 | 21 | * (at your option) any later version. |
22 | 22 | * |
23 | 23 | */ |
24 | +#include <crypto/internal/hash.h> | |
24 | 25 | #include <linux/init.h> |
25 | 26 | #include <linux/module.h> |
26 | 27 | #include <linux/mm.h> |
27 | 28 | #include <asm/byteorder.h> |
28 | -#include <linux/crypto.h> | |
29 | 29 | #include <linux/types.h> |
30 | 30 | |
31 | 31 | #define TGR192_DIGEST_SIZE 24 |
32 | 32 | |
33 | 33 | |
34 | 34 | |
35 | 35 | |
... | ... | @@ -495,24 +495,26 @@ |
495 | 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 | 502 | tctx->a = 0x0123456789abcdefULL; |
503 | 503 | tctx->b = 0xfedcba9876543210ULL; |
504 | 504 | tctx->c = 0xf096a5b4c3b2e187ULL; |
505 | 505 | tctx->nblocks = 0; |
506 | 506 | tctx->count = 0; |
507 | + | |
508 | + return 0; | |
507 | 509 | } |
508 | 510 | |
509 | 511 | |
510 | 512 | /* Update the message digest with the contents |
511 | 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 | 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 | 519 | if (tctx->count == 64) { /* flush the buffer */ |
518 | 520 | tgr192_transform(tctx, tctx->hash); |
519 | 521 | |
520 | 522 | |
... | ... | @@ -520,15 +522,15 @@ |
520 | 522 | tctx->nblocks++; |
521 | 523 | } |
522 | 524 | if (!inbuf) { |
523 | - return; | |
525 | + return 0; | |
524 | 526 | } |
525 | 527 | if (tctx->count) { |
526 | 528 | for (; len && tctx->count < 64; len--) { |
527 | 529 | tctx->hash[tctx->count++] = *inbuf++; |
528 | 530 | } |
529 | - tgr192_update(tfm, NULL, 0); | |
531 | + tgr192_update(desc, NULL, 0); | |
530 | 532 | if (!len) { |
531 | - return; | |
533 | + return 0; | |
532 | 534 | } |
533 | 535 | |
534 | 536 | } |
535 | 537 | |
536 | 538 | |
537 | 539 | |
... | ... | @@ -543,20 +545,22 @@ |
543 | 545 | for (; len && tctx->count < 64; len--) { |
544 | 546 | tctx->hash[tctx->count++] = *inbuf++; |
545 | 547 | } |
548 | + | |
549 | + return 0; | |
546 | 550 | } |
547 | 551 | |
548 | 552 | |
549 | 553 | |
550 | 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 | 558 | __be64 *dst = (__be64 *)out; |
555 | 559 | __be64 *be64p; |
556 | 560 | __le32 *le32p; |
557 | 561 | u32 t, msb, lsb; |
558 | 562 | |
559 | - tgr192_update(tfm, NULL, 0); /* flush */ ; | |
563 | + tgr192_update(desc, NULL, 0); /* flush */ ; | |
560 | 564 | |
561 | 565 | msb = 0; |
562 | 566 | t = tctx->nblocks; |
... | ... | @@ -584,7 +588,7 @@ |
584 | 588 | while (tctx->count < 64) { |
585 | 589 | tctx->hash[tctx->count++] = 0; |
586 | 590 | } |
587 | - tgr192_update(tfm, NULL, 0); /* flush */ ; | |
591 | + tgr192_update(desc, NULL, 0); /* flush */ ; | |
588 | 592 | memset(tctx->hash, 0, 56); /* fill next block with zeroes */ |
589 | 593 | } |
590 | 594 | /* append the 64 bit count */ |
591 | 595 | |
592 | 596 | |
593 | 597 | |
594 | 598 | |
595 | 599 | |
596 | 600 | |
597 | 601 | |
598 | 602 | |
599 | 603 | |
600 | 604 | |
601 | 605 | |
602 | 606 | |
603 | 607 | |
604 | 608 | |
... | ... | @@ -598,91 +602,94 @@ |
598 | 602 | dst[0] = be64p[0] = cpu_to_be64(tctx->a); |
599 | 603 | dst[1] = be64p[1] = cpu_to_be64(tctx->b); |
600 | 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 | 611 | u8 D[64]; |
606 | 612 | |
607 | - tgr192_final(tfm, D); | |
613 | + tgr192_final(desc, D); | |
608 | 614 | memcpy(out, D, TGR160_DIGEST_SIZE); |
609 | 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 | 622 | u8 D[64]; |
615 | 623 | |
616 | - tgr192_final(tfm, D); | |
624 | + tgr192_final(desc, D); | |
617 | 625 | memcpy(out, D, TGR128_DIGEST_SIZE); |
618 | 626 | memset(D, 0, TGR192_DIGEST_SIZE); |
627 | + | |
628 | + return 0; | |
619 | 629 | } |
620 | 630 | |
621 | -static struct crypto_alg tgr192 = { | |
622 | - .cra_name = "tgr192", | |
623 | - .cra_flags = CRYPTO_ALG_TYPE_DIGEST, | |
624 | - .cra_blocksize = TGR192_BLOCK_SIZE, | |
625 | - .cra_ctxsize = sizeof(struct tgr192_ctx), | |
626 | - .cra_module = THIS_MODULE, | |
627 | - .cra_alignmask = 7, | |
628 | - .cra_list = LIST_HEAD_INIT(tgr192.cra_list), | |
629 | - .cra_u = {.digest = { | |
630 | - .dia_digestsize = TGR192_DIGEST_SIZE, | |
631 | - .dia_init = tgr192_init, | |
632 | - .dia_update = tgr192_update, | |
633 | - .dia_final = tgr192_final}} | |
631 | +static struct shash_alg tgr192 = { | |
632 | + .digestsize = TGR192_DIGEST_SIZE, | |
633 | + .init = tgr192_init, | |
634 | + .update = tgr192_update, | |
635 | + .final = tgr192_final, | |
636 | + .descsize = sizeof(struct tgr192_ctx), | |
637 | + .base = { | |
638 | + .cra_name = "tgr192", | |
639 | + .cra_flags = CRYPTO_ALG_TYPE_SHASH, | |
640 | + .cra_blocksize = TGR192_BLOCK_SIZE, | |
641 | + .cra_module = THIS_MODULE, | |
642 | + } | |
634 | 643 | }; |
635 | 644 | |
636 | -static struct crypto_alg tgr160 = { | |
637 | - .cra_name = "tgr160", | |
638 | - .cra_flags = CRYPTO_ALG_TYPE_DIGEST, | |
639 | - .cra_blocksize = TGR192_BLOCK_SIZE, | |
640 | - .cra_ctxsize = sizeof(struct tgr192_ctx), | |
641 | - .cra_module = THIS_MODULE, | |
642 | - .cra_alignmask = 7, | |
643 | - .cra_list = LIST_HEAD_INIT(tgr160.cra_list), | |
644 | - .cra_u = {.digest = { | |
645 | - .dia_digestsize = TGR160_DIGEST_SIZE, | |
646 | - .dia_init = tgr192_init, | |
647 | - .dia_update = tgr192_update, | |
648 | - .dia_final = tgr160_final}} | |
645 | +static struct shash_alg tgr160 = { | |
646 | + .digestsize = TGR160_DIGEST_SIZE, | |
647 | + .init = tgr192_init, | |
648 | + .update = tgr192_update, | |
649 | + .final = tgr160_final, | |
650 | + .descsize = sizeof(struct tgr192_ctx), | |
651 | + .base = { | |
652 | + .cra_name = "tgr160", | |
653 | + .cra_flags = CRYPTO_ALG_TYPE_SHASH, | |
654 | + .cra_blocksize = TGR192_BLOCK_SIZE, | |
655 | + .cra_module = THIS_MODULE, | |
656 | + } | |
649 | 657 | }; |
650 | 658 | |
651 | -static struct crypto_alg tgr128 = { | |
652 | - .cra_name = "tgr128", | |
653 | - .cra_flags = CRYPTO_ALG_TYPE_DIGEST, | |
654 | - .cra_blocksize = TGR192_BLOCK_SIZE, | |
655 | - .cra_ctxsize = sizeof(struct tgr192_ctx), | |
656 | - .cra_module = THIS_MODULE, | |
657 | - .cra_alignmask = 7, | |
658 | - .cra_list = LIST_HEAD_INIT(tgr128.cra_list), | |
659 | - .cra_u = {.digest = { | |
660 | - .dia_digestsize = TGR128_DIGEST_SIZE, | |
661 | - .dia_init = tgr192_init, | |
662 | - .dia_update = tgr192_update, | |
663 | - .dia_final = tgr128_final}} | |
659 | +static struct shash_alg tgr128 = { | |
660 | + .digestsize = TGR128_DIGEST_SIZE, | |
661 | + .init = tgr192_init, | |
662 | + .update = tgr192_update, | |
663 | + .final = tgr128_final, | |
664 | + .descsize = sizeof(struct tgr192_ctx), | |
665 | + .base = { | |
666 | + .cra_name = "tgr128", | |
667 | + .cra_flags = CRYPTO_ALG_TYPE_SHASH, | |
668 | + .cra_blocksize = TGR192_BLOCK_SIZE, | |
669 | + .cra_module = THIS_MODULE, | |
670 | + } | |
664 | 671 | }; |
665 | 672 | |
666 | 673 | static int __init tgr192_mod_init(void) |
667 | 674 | { |
668 | 675 | int ret = 0; |
669 | 676 | |
670 | - ret = crypto_register_alg(&tgr192); | |
677 | + ret = crypto_register_shash(&tgr192); | |
671 | 678 | |
672 | 679 | if (ret < 0) { |
673 | 680 | goto out; |
674 | 681 | } |
675 | 682 | |
676 | - ret = crypto_register_alg(&tgr160); | |
683 | + ret = crypto_register_shash(&tgr160); | |
677 | 684 | if (ret < 0) { |
678 | - crypto_unregister_alg(&tgr192); | |
685 | + crypto_unregister_shash(&tgr192); | |
679 | 686 | goto out; |
680 | 687 | } |
681 | 688 | |
682 | - ret = crypto_register_alg(&tgr128); | |
689 | + ret = crypto_register_shash(&tgr128); | |
683 | 690 | if (ret < 0) { |
684 | - crypto_unregister_alg(&tgr192); | |
685 | - crypto_unregister_alg(&tgr160); | |
691 | + crypto_unregister_shash(&tgr192); | |
692 | + crypto_unregister_shash(&tgr160); | |
686 | 693 | } |
687 | 694 | out: |
688 | 695 | return ret; |
... | ... | @@ -690,9 +697,9 @@ |
690 | 697 | |
691 | 698 | static void __exit tgr192_mod_fini(void) |
692 | 699 | { |
693 | - crypto_unregister_alg(&tgr192); | |
694 | - crypto_unregister_alg(&tgr160); | |
695 | - crypto_unregister_alg(&tgr128); | |
700 | + crypto_unregister_shash(&tgr192); | |
701 | + crypto_unregister_shash(&tgr160); | |
702 | + crypto_unregister_shash(&tgr128); | |
696 | 703 | } |
697 | 704 | |
698 | 705 | MODULE_ALIAS("tgr160"); |