aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
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
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')
-rw-r--r--crypto/tcrypt.c89
-rw-r--r--crypto/tcrypt.h129
2 files changed, 57 insertions, 161 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);
diff --git a/crypto/tcrypt.h b/crypto/tcrypt.h
index 4180a7463e4e..45e79b56fe96 100644
--- a/crypto/tcrypt.h
+++ b/crypto/tcrypt.h
@@ -72,11 +72,6 @@ struct aead_testvec {
72 unsigned short rlen; 72 unsigned short rlen;
73}; 73};
74 74
75struct cipher_speed {
76 unsigned char klen;
77 unsigned int blen;
78};
79
80struct hash_speed { 75struct hash_speed {
81 unsigned int blen; /* buffer length */ 76 unsigned int blen; /* buffer length */
82 unsigned int plen; /* per-update length */ 77 unsigned int plen; /* per-update length */
@@ -8032,123 +8027,13 @@ static struct hash_testvec crc32c_tv_template[] = {
8032/* 8027/*
8033 * Cipher speed tests 8028 * Cipher speed tests
8034 */ 8029 */
8035static struct cipher_speed speed_template_8[] = { 8030static u8 speed_template_8[] = {8, 0};
8036 { .klen = 8, .blen = 16, }, 8031static u8 speed_template_24[] = {24, 0};
8037 { .klen = 8, .blen = 64, }, 8032static u8 speed_template_8_32[] = {8, 32, 0};
8038 { .klen = 8, .blen = 256, }, 8033static u8 speed_template_16_32[] = {16, 32, 0};
8039 { .klen = 8, .blen = 1024, }, 8034static u8 speed_template_16_24_32[] = {16, 24, 32, 0};
8040 { .klen = 8, .blen = 8192, }, 8035static u8 speed_template_32_40_48[] = {32, 40, 48, 0};
8041 8036static u8 speed_template_32_48_64[] = {32, 48, 64, 0};
8042 /* End marker */
8043 { .klen = 0, .blen = 0, }
8044};
8045
8046static struct cipher_speed speed_template_24[] = {
8047 { .klen = 24, .blen = 16, },
8048 { .klen = 24, .blen = 64, },
8049 { .klen = 24, .blen = 256, },
8050 { .klen = 24, .blen = 1024, },
8051 { .klen = 24, .blen = 8192, },
8052
8053 /* End marker */
8054 { .klen = 0, .blen = 0, }
8055};
8056
8057static struct cipher_speed speed_template_8_32[] = {
8058 /* Don't support blowfish keys > 256 bit in this test */
8059 { .klen = 8, .blen = 16, },
8060 { .klen = 8, .blen = 64, },
8061 { .klen = 8, .blen = 256, },
8062 { .klen = 8, .blen = 1024, },
8063 { .klen = 8, .blen = 8192, },
8064 { .klen = 32, .blen = 16, },
8065 { .klen = 32, .blen = 64, },
8066 { .klen = 32, .blen = 256, },
8067 { .klen = 32, .blen = 1024, },
8068 { .klen = 32, .blen = 8192, },
8069
8070 /* End marker */
8071 { .klen = 0, .blen = 0, }
8072};
8073
8074static struct cipher_speed speed_template_16_32[] = {
8075 { .klen = 16, .blen = 16, },
8076 { .klen = 16, .blen = 64, },
8077 { .klen = 16, .blen = 256, },
8078 { .klen = 16, .blen = 1024, },
8079 { .klen = 16, .blen = 8192, },
8080 { .klen = 32, .blen = 16, },
8081 { .klen = 32, .blen = 64, },
8082 { .klen = 32, .blen = 256, },
8083 { .klen = 32, .blen = 1024, },
8084 { .klen = 32, .blen = 8192, },
8085
8086 /* End marker */
8087 { .klen = 0, .blen = 0, }
8088};
8089
8090static struct cipher_speed speed_template_16_24_32[] = {
8091 { .klen = 16, .blen = 16, },
8092 { .klen = 16, .blen = 64, },
8093 { .klen = 16, .blen = 256, },
8094 { .klen = 16, .blen = 1024, },
8095 { .klen = 16, .blen = 8192, },
8096 { .klen = 24, .blen = 16, },
8097 { .klen = 24, .blen = 64, },
8098 { .klen = 24, .blen = 256, },
8099 { .klen = 24, .blen = 1024, },
8100 { .klen = 24, .blen = 8192, },
8101 { .klen = 32, .blen = 16, },
8102 { .klen = 32, .blen = 64, },
8103 { .klen = 32, .blen = 256, },
8104 { .klen = 32, .blen = 1024, },
8105 { .klen = 32, .blen = 8192, },
8106
8107 /* End marker */
8108 { .klen = 0, .blen = 0, }
8109};
8110
8111static struct cipher_speed speed_template_32_40_48[] = {
8112 { .klen = 32, .blen = 16, },
8113 { .klen = 32, .blen = 64, },
8114 { .klen = 32, .blen = 256, },
8115 { .klen = 32, .blen = 1024, },
8116 { .klen = 32, .blen = 8192, },
8117 { .klen = 40, .blen = 16, },
8118 { .klen = 40, .blen = 64, },
8119 { .klen = 40, .blen = 256, },
8120 { .klen = 40, .blen = 1024, },
8121 { .klen = 40, .blen = 8192, },
8122 { .klen = 48, .blen = 16, },
8123 { .klen = 48, .blen = 64, },
8124 { .klen = 48, .blen = 256, },
8125 { .klen = 48, .blen = 1024, },
8126 { .klen = 48, .blen = 8192, },
8127
8128 /* End marker */
8129 { .klen = 0, .blen = 0, }
8130};
8131
8132static struct cipher_speed speed_template_32_48_64[] = {
8133 { .klen = 32, .blen = 16, },
8134 { .klen = 32, .blen = 64, },
8135 { .klen = 32, .blen = 256, },
8136 { .klen = 32, .blen = 1024, },
8137 { .klen = 32, .blen = 8192, },
8138 { .klen = 48, .blen = 16, },
8139 { .klen = 48, .blen = 64, },
8140 { .klen = 48, .blen = 256, },
8141 { .klen = 48, .blen = 1024, },
8142 { .klen = 48, .blen = 8192, },
8143 { .klen = 64, .blen = 16, },
8144 { .klen = 64, .blen = 64, },
8145 { .klen = 64, .blen = 256, },
8146 { .klen = 64, .blen = 1024, },
8147 { .klen = 64, .blen = 8192, },
8148
8149 /* End marker */
8150 { .klen = 0, .blen = 0, }
8151};
8152 8037
8153/* 8038/*
8154 * Digest speed tests 8039 * Digest speed tests