Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+15 -224
+15 -224
crypto/tcrypt.c
··· 554 554 crypto_free_blkcipher(tfm); 555 555 } 556 556 557 - static 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 - 578 - static 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 - 610 - static 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 - 641 - out: 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 - 653 - static 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 - 703 - out: 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 - 715 557 static void test_hash_sg_init(struct scatterlist *sg) 716 558 { 717 559 int i; ··· 563 721 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE); 564 722 memset(tvmem[i], 0xff, PAGE_SIZE); 565 723 } 566 - } 567 - 568 - static void test_hash_speed(const char *algo, unsigned int secs, 569 - struct hash_speed *speed) 570 - { 571 - struct scatterlist sg[TVMEMSIZE]; 572 - struct crypto_hash *tfm; 573 - struct hash_desc desc; 574 - static char output[1024]; 575 - int i; 576 - int ret; 577 - 578 - tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC); 579 - 580 - if (IS_ERR(tfm)) { 581 - printk(KERN_ERR "failed to load transform for %s: %ld\n", algo, 582 - PTR_ERR(tfm)); 583 - return; 584 - } 585 - 586 - printk(KERN_INFO "\ntesting speed of %s (%s)\n", algo, 587 - get_driver_name(crypto_hash, tfm)); 588 - 589 - desc.tfm = tfm; 590 - desc.flags = 0; 591 - 592 - if (crypto_hash_digestsize(tfm) > sizeof(output)) { 593 - printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n", 594 - crypto_hash_digestsize(tfm), sizeof(output)); 595 - goto out; 596 - } 597 - 598 - test_hash_sg_init(sg); 599 - for (i = 0; speed[i].blen != 0; i++) { 600 - if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) { 601 - printk(KERN_ERR 602 - "template (%u) too big for tvmem (%lu)\n", 603 - speed[i].blen, TVMEMSIZE * PAGE_SIZE); 604 - goto out; 605 - } 606 - 607 - if (speed[i].klen) 608 - crypto_hash_setkey(tfm, tvmem[0], speed[i].klen); 609 - 610 - printk(KERN_INFO "test%3u " 611 - "(%5u byte blocks,%5u bytes per update,%4u updates): ", 612 - i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen); 613 - 614 - if (secs) 615 - ret = test_hash_jiffies(&desc, sg, speed[i].blen, 616 - speed[i].plen, output, secs); 617 - else 618 - ret = test_hash_cycles(&desc, sg, speed[i].blen, 619 - speed[i].plen, output); 620 - 621 - if (ret) { 622 - printk(KERN_ERR "hashing failed ret=%d\n", ret); 623 - break; 624 - } 625 - } 626 - 627 - out: 628 - crypto_free_hash(tfm); 629 724 } 630 725 631 726 static inline int do_one_ahash_op(struct ahash_request *req, int ret) ··· 724 945 return 0; 725 946 } 726 947 727 - static void test_ahash_speed(const char *algo, unsigned int secs, 728 - struct hash_speed *speed) 948 + static void test_ahash_speed_common(const char *algo, unsigned int secs, 949 + struct hash_speed *speed, unsigned mask) 729 950 { 730 951 struct scatterlist sg[TVMEMSIZE]; 731 952 struct tcrypt_result tresult; ··· 734 955 char *output; 735 956 int i, ret; 736 957 737 - tfm = crypto_alloc_ahash(algo, 0, 0); 958 + tfm = crypto_alloc_ahash(algo, 0, mask); 738 959 if (IS_ERR(tfm)) { 739 960 pr_err("failed to load transform for %s: %ld\n", 740 961 algo, PTR_ERR(tfm)); ··· 798 1019 799 1020 out: 800 1021 crypto_free_ahash(tfm); 1022 + } 1023 + 1024 + static void test_ahash_speed(const char *algo, unsigned int secs, 1025 + struct hash_speed *speed) 1026 + { 1027 + return test_ahash_speed_common(algo, secs, speed, 0); 1028 + } 1029 + 1030 + static void test_hash_speed(const char *algo, unsigned int secs, 1031 + struct hash_speed *speed) 1032 + { 1033 + return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC); 801 1034 } 802 1035 803 1036 static inline int do_one_acipher_op(struct ablkcipher_request *req, int ret)