aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/tcrypt.c
diff options
context:
space:
mode:
authorSebastian Siewior <sebastian@breakpoint.cc>2008-03-11 09:27:11 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2008-04-20 22:19:21 -0400
commitd5dc392742a9818e2766a63f3533980543e18060 (patch)
tree2dcd8083cba1b1e22c4e01c50d479ca2502a1139 /crypto/tcrypt.c
parent477035c2abdcff7583369e5777cb7be1bb1dbea8 (diff)
[CRYPTO] tcrypt: Shrink speed templates
The speed templates as it look always the same. The key size is repeated for each block size and we test always the same block size. The addition of one inner loop makes it possible to get rid of the struct and it is possible to use a tiny u8 array :) Signed-off-by: Sebastian Siewior <sebastian@breakpoint.cc> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/tcrypt.c')
-rw-r--r--crypto/tcrypt.c89
1 files changed, 50 insertions, 39 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index cff18364fbc1..6b8315b6f2a5 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -721,15 +721,18 @@ out:
721 return ret; 721 return ret;
722} 722}
723 723
724static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
725
724static void test_cipher_speed(char *algo, int enc, unsigned int sec, 726static void test_cipher_speed(char *algo, int enc, unsigned int sec,
725 struct cipher_testvec *template, 727 struct cipher_testvec *template,
726 unsigned int tcount, struct cipher_speed *speed) 728 unsigned int tcount, u8 *keysize)
727{ 729{
728 unsigned int ret, i, j, iv_len; 730 unsigned int ret, i, j, iv_len;
729 unsigned char *key, *p, iv[128]; 731 unsigned char *key, *p, iv[128];
730 struct crypto_blkcipher *tfm; 732 struct crypto_blkcipher *tfm;
731 struct blkcipher_desc desc; 733 struct blkcipher_desc desc;
732 const char *e; 734 const char *e;
735 u32 *b_size;
733 736
734 if (enc == ENCRYPT) 737 if (enc == ENCRYPT)
735 e = "encryption"; 738 e = "encryption";
@@ -748,52 +751,60 @@ static void test_cipher_speed(char *algo, int enc, unsigned int sec,
748 desc.tfm = tfm; 751 desc.tfm = tfm;
749 desc.flags = 0; 752 desc.flags = 0;
750 753
751 for (i = 0; speed[i].klen != 0; i++) { 754 i = 0;
752 if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) { 755 do {
753 printk("template (%u) too big for tvmem (%u)\n",
754 speed[i].blen + speed[i].klen, TVMEMSIZE);
755 goto out;
756 }
757 756
758 printk("test %u (%d bit key, %d byte blocks): ", i, 757 b_size = block_sizes;
759 speed[i].klen * 8, speed[i].blen); 758 do {
760 759
761 memset(tvmem, 0xff, speed[i].klen + speed[i].blen); 760 if ((*keysize + *b_size) > TVMEMSIZE) {
761 printk("template (%u) too big for tvmem (%u)\n",
762 *keysize + *b_size, TVMEMSIZE);
763 goto out;
764 }
762 765
763 /* set key, plain text and IV */ 766 printk("test %u (%d bit key, %d byte blocks): ", i,
764 key = (unsigned char *)tvmem; 767 *keysize * 8, *b_size);
765 for (j = 0; j < tcount; j++) { 768
766 if (template[j].klen == speed[i].klen) { 769 memset(tvmem, 0xff, *keysize + *b_size);
767 key = template[j].key; 770
768 break; 771 /* set key, plain text and IV */
772 key = (unsigned char *)tvmem;
773 for (j = 0; j < tcount; j++) {
774 if (template[j].klen == *keysize) {
775 key = template[j].key;
776 break;
777 }
769 } 778 }
770 } 779 p = (unsigned char *)tvmem + *keysize;
771 p = (unsigned char *)tvmem + speed[i].klen;
772 780
773 ret = crypto_blkcipher_setkey(tfm, key, speed[i].klen); 781 ret = crypto_blkcipher_setkey(tfm, key, *keysize);
774 if (ret) { 782 if (ret) {
775 printk("setkey() failed flags=%x\n", 783 printk("setkey() failed flags=%x\n",
776 crypto_blkcipher_get_flags(tfm)); 784 crypto_blkcipher_get_flags(tfm));
777 goto out; 785 goto out;
778 } 786 }
779 787
780 iv_len = crypto_blkcipher_ivsize(tfm); 788 iv_len = crypto_blkcipher_ivsize(tfm);
781 if (iv_len) { 789 if (iv_len) {
782 memset(&iv, 0xff, iv_len); 790 memset(&iv, 0xff, iv_len);
783 crypto_blkcipher_set_iv(tfm, iv, iv_len); 791 crypto_blkcipher_set_iv(tfm, iv, iv_len);
784 } 792 }
785 793
786 if (sec) 794 if (sec)
787 ret = test_cipher_jiffies(&desc, enc, p, speed[i].blen, 795 ret = test_cipher_jiffies(&desc, enc, p, *b_size, sec);
788 sec); 796 else
789 else 797 ret = test_cipher_cycles(&desc, enc, p, *b_size);
790 ret = test_cipher_cycles(&desc, enc, p, speed[i].blen);
791 798
792 if (ret) { 799 if (ret) {
793 printk("%s() failed flags=%x\n", e, desc.flags); 800 printk("%s() failed flags=%x\n", e, desc.flags);
794 break; 801 break;
795 } 802 }
796 } 803 b_size++;
804 i++;
805 } while (*b_size);
806 keysize++;
807 } while (*keysize);
797 808
798out: 809out:
799 crypto_free_blkcipher(tfm); 810 crypto_free_blkcipher(tfm);