aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/tcrypt.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2016-02-01 08:36:49 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2016-02-06 02:33:08 -0500
commit0660511c0beeccdc240479f29d5ecd8362115be3 (patch)
tree676b8c941385d86e7a2d732ae76367eaa8b3f0b6 /crypto/tcrypt.c
parent2b8b28fd232233c22fb61009dd8b0587390d2875 (diff)
crypto: tcrypt - Use ahash
This patch removes the last user of the obsolete crypto_hash interface, tcrypt, by simply switching it over to ahash. In fact it already has all the code there so it's just a matter of calling the ahash speed test code with the right mask. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/tcrypt.c')
-rw-r--r--crypto/tcrypt.c239
1 files changed, 15 insertions, 224 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index 270bc4b82bd9..579dce071463 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -554,164 +554,6 @@ out:
554 crypto_free_blkcipher(tfm); 554 crypto_free_blkcipher(tfm);
555} 555}
556 556
557static int test_hash_jiffies_digest(struct hash_desc *desc,
558 struct scatterlist *sg, int blen,
559 char *out, int secs)
560{
561 unsigned long start, end;
562 int bcount;
563 int ret;
564
565 for (start = jiffies, end = start + secs * HZ, bcount = 0;
566 time_before(jiffies, end); bcount++) {
567 ret = crypto_hash_digest(desc, sg, blen, out);
568 if (ret)
569 return ret;
570 }
571
572 printk("%6u opers/sec, %9lu bytes/sec\n",
573 bcount / secs, ((long)bcount * blen) / secs);
574
575 return 0;
576}
577
578static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg,
579 int blen, int plen, char *out, int secs)
580{
581 unsigned long start, end;
582 int bcount, pcount;
583 int ret;
584
585 if (plen == blen)
586 return test_hash_jiffies_digest(desc, sg, blen, out, secs);
587
588 for (start = jiffies, end = start + secs * HZ, bcount = 0;
589 time_before(jiffies, end); bcount++) {
590 ret = crypto_hash_init(desc);
591 if (ret)
592 return ret;
593 for (pcount = 0; pcount < blen; pcount += plen) {
594 ret = crypto_hash_update(desc, sg, plen);
595 if (ret)
596 return ret;
597 }
598 /* we assume there is enough space in 'out' for the result */
599 ret = crypto_hash_final(desc, out);
600 if (ret)
601 return ret;
602 }
603
604 printk("%6u opers/sec, %9lu bytes/sec\n",
605 bcount / secs, ((long)bcount * blen) / secs);
606
607 return 0;
608}
609
610static int test_hash_cycles_digest(struct hash_desc *desc,
611 struct scatterlist *sg, int blen, char *out)
612{
613 unsigned long cycles = 0;
614 int i;
615 int ret;
616
617 local_irq_disable();
618
619 /* Warm-up run. */
620 for (i = 0; i < 4; i++) {
621 ret = crypto_hash_digest(desc, sg, blen, out);
622 if (ret)
623 goto out;
624 }
625
626 /* The real thing. */
627 for (i = 0; i < 8; i++) {
628 cycles_t start, end;
629
630 start = get_cycles();
631
632 ret = crypto_hash_digest(desc, sg, blen, out);
633 if (ret)
634 goto out;
635
636 end = get_cycles();
637
638 cycles += end - start;
639 }
640
641out:
642 local_irq_enable();
643
644 if (ret)
645 return ret;
646
647 printk("%6lu cycles/operation, %4lu cycles/byte\n",
648 cycles / 8, cycles / (8 * blen));
649
650 return 0;
651}
652
653static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg,
654 int blen, int plen, char *out)
655{
656 unsigned long cycles = 0;
657 int i, pcount;
658 int ret;
659
660 if (plen == blen)
661 return test_hash_cycles_digest(desc, sg, blen, out);
662
663 local_irq_disable();
664
665 /* Warm-up run. */
666 for (i = 0; i < 4; i++) {
667 ret = crypto_hash_init(desc);
668 if (ret)
669 goto out;
670 for (pcount = 0; pcount < blen; pcount += plen) {
671 ret = crypto_hash_update(desc, sg, plen);
672 if (ret)
673 goto out;
674 }
675 ret = crypto_hash_final(desc, out);
676 if (ret)
677 goto out;
678 }
679
680 /* The real thing. */
681 for (i = 0; i < 8; i++) {
682 cycles_t start, end;
683
684 start = get_cycles();
685
686 ret = crypto_hash_init(desc);
687 if (ret)
688 goto out;
689 for (pcount = 0; pcount < blen; pcount += plen) {
690 ret = crypto_hash_update(desc, sg, plen);
691 if (ret)
692 goto out;
693 }
694 ret = crypto_hash_final(desc, out);
695 if (ret)
696 goto out;
697
698 end = get_cycles();
699
700 cycles += end - start;
701 }
702
703out:
704 local_irq_enable();
705
706 if (ret)
707 return ret;
708
709 printk("%6lu cycles/operation, %4lu cycles/byte\n",
710 cycles / 8, cycles / (8 * blen));
711
712 return 0;
713}
714
715static void test_hash_sg_init(struct scatterlist *sg) 557static void test_hash_sg_init(struct scatterlist *sg)
716{ 558{
717 int i; 559 int i;
@@ -723,69 +565,6 @@ static void test_hash_sg_init(struct scatterlist *sg)
723 } 565 }
724} 566}
725 567
726static void test_hash_speed(const char *algo, unsigned int secs,
727 struct hash_speed *speed)
728{
729 struct scatterlist sg[TVMEMSIZE];
730 struct crypto_hash *tfm;
731 struct hash_desc desc;
732 static char output[1024];
733 int i;
734 int ret;
735
736 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
737
738 if (IS_ERR(tfm)) {
739 printk(KERN_ERR "failed to load transform for %s: %ld\n", algo,
740 PTR_ERR(tfm));
741 return;
742 }
743
744 printk(KERN_INFO "\ntesting speed of %s (%s)\n", algo,
745 get_driver_name(crypto_hash, tfm));
746
747 desc.tfm = tfm;
748 desc.flags = 0;
749
750 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
751 printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n",
752 crypto_hash_digestsize(tfm), sizeof(output));
753 goto out;
754 }
755
756 test_hash_sg_init(sg);
757 for (i = 0; speed[i].blen != 0; i++) {
758 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
759 printk(KERN_ERR
760 "template (%u) too big for tvmem (%lu)\n",
761 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
762 goto out;
763 }
764
765 if (speed[i].klen)
766 crypto_hash_setkey(tfm, tvmem[0], speed[i].klen);
767
768 printk(KERN_INFO "test%3u "
769 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
770 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
771
772 if (secs)
773 ret = test_hash_jiffies(&desc, sg, speed[i].blen,
774 speed[i].plen, output, secs);
775 else
776 ret = test_hash_cycles(&desc, sg, speed[i].blen,
777 speed[i].plen, output);
778
779 if (ret) {
780 printk(KERN_ERR "hashing failed ret=%d\n", ret);
781 break;
782 }
783 }
784
785out:
786 crypto_free_hash(tfm);
787}
788
789static inline int do_one_ahash_op(struct ahash_request *req, int ret) 568static inline int do_one_ahash_op(struct ahash_request *req, int ret)
790{ 569{
791 if (ret == -EINPROGRESS || ret == -EBUSY) { 570 if (ret == -EINPROGRESS || ret == -EBUSY) {
@@ -945,8 +724,8 @@ out:
945 return 0; 724 return 0;
946} 725}
947 726
948static void test_ahash_speed(const char *algo, unsigned int secs, 727static void test_ahash_speed_common(const char *algo, unsigned int secs,
949 struct hash_speed *speed) 728 struct hash_speed *speed, unsigned mask)
950{ 729{
951 struct scatterlist sg[TVMEMSIZE]; 730 struct scatterlist sg[TVMEMSIZE];
952 struct tcrypt_result tresult; 731 struct tcrypt_result tresult;
@@ -955,7 +734,7 @@ static void test_ahash_speed(const char *algo, unsigned int secs,
955 char *output; 734 char *output;
956 int i, ret; 735 int i, ret;
957 736
958 tfm = crypto_alloc_ahash(algo, 0, 0); 737 tfm = crypto_alloc_ahash(algo, 0, mask);
959 if (IS_ERR(tfm)) { 738 if (IS_ERR(tfm)) {
960 pr_err("failed to load transform for %s: %ld\n", 739 pr_err("failed to load transform for %s: %ld\n",
961 algo, PTR_ERR(tfm)); 740 algo, PTR_ERR(tfm));
@@ -1021,6 +800,18 @@ out:
1021 crypto_free_ahash(tfm); 800 crypto_free_ahash(tfm);
1022} 801}
1023 802
803static void test_ahash_speed(const char *algo, unsigned int secs,
804 struct hash_speed *speed)
805{
806 return test_ahash_speed_common(algo, secs, speed, 0);
807}
808
809static void test_hash_speed(const char *algo, unsigned int secs,
810 struct hash_speed *speed)
811{
812 return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC);
813}
814
1024static inline int do_one_acipher_op(struct ablkcipher_request *req, int ret) 815static inline int do_one_acipher_op(struct ablkcipher_request *req, int ret)
1025{ 816{
1026 if (ret == -EINPROGRESS || ret == -EBUSY) { 817 if (ret == -EINPROGRESS || ret == -EBUSY) {