aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2006-08-19 07:38:49 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2006-09-20 21:46:18 -0400
commite9d41164e2fdd897fe4520c2079ea0000f6e0ec3 (patch)
treeda56da7216ac1cc7abc040b93ed6a358d374ef71
parent0796ae061e6da5de7cfc1af57dfd42a73908b1bf (diff)
[CRYPTO] tcrypt: Use HMAC template and hash interface
This patch converts tcrypt to use the new HMAC template rather than the hard-coded version of HMAC. It also converts all digest users to use the new cipher interface. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--crypto/tcrypt.c355
-rw-r--r--crypto/tcrypt.h23
2 files changed, 213 insertions, 165 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index 5e2278069d22..840ab8be0b96 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -88,9 +88,11 @@ static void test_hash(char *algo, struct hash_testvec *template,
88 unsigned int i, j, k, temp; 88 unsigned int i, j, k, temp;
89 struct scatterlist sg[8]; 89 struct scatterlist sg[8];
90 char result[64]; 90 char result[64];
91 struct crypto_tfm *tfm; 91 struct crypto_hash *tfm;
92 struct hash_desc desc;
92 struct hash_testvec *hash_tv; 93 struct hash_testvec *hash_tv;
93 unsigned int tsize; 94 unsigned int tsize;
95 int ret;
94 96
95 printk("\ntesting %s\n", algo); 97 printk("\ntesting %s\n", algo);
96 98
@@ -104,27 +106,42 @@ static void test_hash(char *algo, struct hash_testvec *template,
104 106
105 memcpy(tvmem, template, tsize); 107 memcpy(tvmem, template, tsize);
106 hash_tv = (void *)tvmem; 108 hash_tv = (void *)tvmem;
107 tfm = crypto_alloc_tfm(algo, 0); 109
108 if (tfm == NULL) { 110 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
109 printk("failed to load transform for %s\n", algo); 111 if (IS_ERR(tfm)) {
112 printk("failed to load transform for %s: %ld\n", algo,
113 PTR_ERR(tfm));
110 return; 114 return;
111 } 115 }
112 116
117 desc.tfm = tfm;
118 desc.flags = 0;
119
113 for (i = 0; i < tcount; i++) { 120 for (i = 0; i < tcount; i++) {
114 printk("test %u:\n", i + 1); 121 printk("test %u:\n", i + 1);
115 memset(result, 0, 64); 122 memset(result, 0, 64);
116 123
117 sg_set_buf(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize); 124 sg_set_buf(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize);
118 125
119 crypto_digest_init(tfm); 126 if (hash_tv[i].ksize) {
120 crypto_digest_setkey(tfm, hash_tv[i].key, hash_tv[i].ksize); 127 ret = crypto_hash_setkey(tfm, hash_tv[i].key,
121 crypto_digest_update(tfm, sg, 1); 128 hash_tv[i].ksize);
122 crypto_digest_final(tfm, result); 129 if (ret) {
130 printk("setkey() failed ret=%d\n", ret);
131 goto out;
132 }
133 }
134
135 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize, result);
136 if (ret) {
137 printk("digest () failed ret=%d\n", ret);
138 goto out;
139 }
123 140
124 hexdump(result, crypto_tfm_alg_digestsize(tfm)); 141 hexdump(result, crypto_hash_digestsize(tfm));
125 printk("%s\n", 142 printk("%s\n",
126 memcmp(result, hash_tv[i].digest, 143 memcmp(result, hash_tv[i].digest,
127 crypto_tfm_alg_digestsize(tfm)) ? 144 crypto_hash_digestsize(tfm)) ?
128 "fail" : "pass"); 145 "fail" : "pass");
129 } 146 }
130 147
@@ -150,105 +167,35 @@ static void test_hash(char *algo, struct hash_testvec *template,
150 hash_tv[i].tap[k]); 167 hash_tv[i].tap[k]);
151 } 168 }
152 169
153 crypto_digest_digest(tfm, sg, hash_tv[i].np, result); 170 if (hash_tv[i].ksize) {
154 171 ret = crypto_hash_setkey(tfm, hash_tv[i].key,
155 hexdump(result, crypto_tfm_alg_digestsize(tfm)); 172 hash_tv[i].ksize);
156 printk("%s\n",
157 memcmp(result, hash_tv[i].digest,
158 crypto_tfm_alg_digestsize(tfm)) ?
159 "fail" : "pass");
160 }
161 }
162
163 crypto_free_tfm(tfm);
164}
165
166
167#ifdef CONFIG_CRYPTO_HMAC
168
169static void test_hmac(char *algo, struct hmac_testvec *template,
170 unsigned int tcount)
171{
172 unsigned int i, j, k, temp;
173 struct scatterlist sg[8];
174 char result[64];
175 struct crypto_tfm *tfm;
176 struct hmac_testvec *hmac_tv;
177 unsigned int tsize, klen;
178
179 tfm = crypto_alloc_tfm(algo, 0);
180 if (tfm == NULL) {
181 printk("failed to load transform for %s\n", algo);
182 return;
183 }
184
185 printk("\ntesting hmac_%s\n", algo);
186 173
187 tsize = sizeof(struct hmac_testvec); 174 if (ret) {
188 tsize *= tcount; 175 printk("setkey() failed ret=%d\n", ret);
189 if (tsize > TVMEMSIZE) { 176 goto out;
190 printk("template (%u) too big for tvmem (%u)\n", tsize, 177 }
191 TVMEMSIZE);
192 goto out;
193 }
194
195 memcpy(tvmem, template, tsize);
196 hmac_tv = (void *)tvmem;
197
198 for (i = 0; i < tcount; i++) {
199 printk("test %u:\n", i + 1);
200 memset(result, 0, sizeof (result));
201
202 klen = hmac_tv[i].ksize;
203 sg_set_buf(&sg[0], hmac_tv[i].plaintext, hmac_tv[i].psize);
204
205 crypto_hmac(tfm, hmac_tv[i].key, &klen, sg, 1, result);
206
207 hexdump(result, crypto_tfm_alg_digestsize(tfm));
208 printk("%s\n",
209 memcmp(result, hmac_tv[i].digest,
210 crypto_tfm_alg_digestsize(tfm)) ? "fail" :
211 "pass");
212 }
213
214 printk("\ntesting hmac_%s across pages\n", algo);
215
216 memset(xbuf, 0, XBUFSIZE);
217
218 j = 0;
219 for (i = 0; i < tcount; i++) {
220 if (hmac_tv[i].np) {
221 j++;
222 printk("test %u:\n",j);
223 memset(result, 0, 64);
224
225 temp = 0;
226 klen = hmac_tv[i].ksize;
227 for (k = 0; k < hmac_tv[i].np; k++) {
228 memcpy(&xbuf[IDX[k]],
229 hmac_tv[i].plaintext + temp,
230 hmac_tv[i].tap[k]);
231 temp += hmac_tv[i].tap[k];
232 sg_set_buf(&sg[k], &xbuf[IDX[k]],
233 hmac_tv[i].tap[k]);
234 } 178 }
235 179
236 crypto_hmac(tfm, hmac_tv[i].key, &klen, sg, 180 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize,
237 hmac_tv[i].np, result); 181 result);
238 hexdump(result, crypto_tfm_alg_digestsize(tfm)); 182 if (ret) {
183 printk("digest () failed ret=%d\n", ret);
184 goto out;
185 }
239 186
187 hexdump(result, crypto_hash_digestsize(tfm));
240 printk("%s\n", 188 printk("%s\n",
241 memcmp(result, hmac_tv[i].digest, 189 memcmp(result, hash_tv[i].digest,
242 crypto_tfm_alg_digestsize(tfm)) ? 190 crypto_hash_digestsize(tfm)) ?
243 "fail" : "pass"); 191 "fail" : "pass");
244 } 192 }
245 } 193 }
194
246out: 195out:
247 crypto_free_tfm(tfm); 196 crypto_free_hash(tfm);
248} 197}
249 198
250#endif /* CONFIG_CRYPTO_HMAC */
251
252static void test_cipher(char *algo, int enc, 199static void test_cipher(char *algo, int enc,
253 struct cipher_testvec *template, unsigned int tcount) 200 struct cipher_testvec *template, unsigned int tcount)
254{ 201{
@@ -570,97 +517,202 @@ out:
570 crypto_free_blkcipher(tfm); 517 crypto_free_blkcipher(tfm);
571} 518}
572 519
573static void test_digest_jiffies(struct crypto_tfm *tfm, char *p, int blen, 520static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen,
574 int plen, char *out, int sec) 521 char *out, int sec)
522{
523 struct scatterlist sg[1];
524 unsigned long start, end;
525 int bcount;
526 int ret;
527
528 for (start = jiffies, end = start + sec * HZ, bcount = 0;
529 time_before(jiffies, end); bcount++) {
530 sg_set_buf(sg, p, blen);
531 ret = crypto_hash_digest(desc, sg, blen, out);
532 if (ret)
533 return ret;
534 }
535
536 printk("%6u opers/sec, %9lu bytes/sec\n",
537 bcount / sec, ((long)bcount * blen) / sec);
538
539 return 0;
540}
541
542static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen,
543 int plen, char *out, int sec)
575{ 544{
576 struct scatterlist sg[1]; 545 struct scatterlist sg[1];
577 unsigned long start, end; 546 unsigned long start, end;
578 int bcount, pcount; 547 int bcount, pcount;
548 int ret;
549
550 if (plen == blen)
551 return test_hash_jiffies_digest(desc, p, blen, out, sec);
579 552
580 for (start = jiffies, end = start + sec * HZ, bcount = 0; 553 for (start = jiffies, end = start + sec * HZ, bcount = 0;
581 time_before(jiffies, end); bcount++) { 554 time_before(jiffies, end); bcount++) {
582 crypto_digest_init(tfm); 555 ret = crypto_hash_init(desc);
556 if (ret)
557 return ret;
583 for (pcount = 0; pcount < blen; pcount += plen) { 558 for (pcount = 0; pcount < blen; pcount += plen) {
584 sg_set_buf(sg, p + pcount, plen); 559 sg_set_buf(sg, p + pcount, plen);
585 crypto_digest_update(tfm, sg, 1); 560 ret = crypto_hash_update(desc, sg, plen);
561 if (ret)
562 return ret;
586 } 563 }
587 /* we assume there is enough space in 'out' for the result */ 564 /* we assume there is enough space in 'out' for the result */
588 crypto_digest_final(tfm, out); 565 ret = crypto_hash_final(desc, out);
566 if (ret)
567 return ret;
589 } 568 }
590 569
591 printk("%6u opers/sec, %9lu bytes/sec\n", 570 printk("%6u opers/sec, %9lu bytes/sec\n",
592 bcount / sec, ((long)bcount * blen) / sec); 571 bcount / sec, ((long)bcount * blen) / sec);
593 572
594 return; 573 return 0;
574}
575
576static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen,
577 char *out)
578{
579 struct scatterlist sg[1];
580 unsigned long cycles = 0;
581 int i;
582 int ret;
583
584 local_bh_disable();
585 local_irq_disable();
586
587 /* Warm-up run. */
588 for (i = 0; i < 4; i++) {
589 sg_set_buf(sg, p, blen);
590 ret = crypto_hash_digest(desc, sg, blen, out);
591 if (ret)
592 goto out;
593 }
594
595 /* The real thing. */
596 for (i = 0; i < 8; i++) {
597 cycles_t start, end;
598
599 start = get_cycles();
600
601 sg_set_buf(sg, p, blen);
602 ret = crypto_hash_digest(desc, sg, blen, out);
603 if (ret)
604 goto out;
605
606 end = get_cycles();
607
608 cycles += end - start;
609 }
610
611out:
612 local_irq_enable();
613 local_bh_enable();
614
615 if (ret)
616 return ret;
617
618 printk("%6lu cycles/operation, %4lu cycles/byte\n",
619 cycles / 8, cycles / (8 * blen));
620
621 return 0;
595} 622}
596 623
597static void test_digest_cycles(struct crypto_tfm *tfm, char *p, int blen, 624static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
598 int plen, char *out) 625 int plen, char *out)
599{ 626{
600 struct scatterlist sg[1]; 627 struct scatterlist sg[1];
601 unsigned long cycles = 0; 628 unsigned long cycles = 0;
602 int i, pcount; 629 int i, pcount;
630 int ret;
631
632 if (plen == blen)
633 return test_hash_cycles_digest(desc, p, blen, out);
603 634
604 local_bh_disable(); 635 local_bh_disable();
605 local_irq_disable(); 636 local_irq_disable();
606 637
607 /* Warm-up run. */ 638 /* Warm-up run. */
608 for (i = 0; i < 4; i++) { 639 for (i = 0; i < 4; i++) {
609 crypto_digest_init(tfm); 640 ret = crypto_hash_init(desc);
641 if (ret)
642 goto out;
610 for (pcount = 0; pcount < blen; pcount += plen) { 643 for (pcount = 0; pcount < blen; pcount += plen) {
611 sg_set_buf(sg, p + pcount, plen); 644 sg_set_buf(sg, p + pcount, plen);
612 crypto_digest_update(tfm, sg, 1); 645 ret = crypto_hash_update(desc, sg, plen);
646 if (ret)
647 goto out;
613 } 648 }
614 crypto_digest_final(tfm, out); 649 crypto_hash_final(desc, out);
650 if (ret)
651 goto out;
615 } 652 }
616 653
617 /* The real thing. */ 654 /* The real thing. */
618 for (i = 0; i < 8; i++) { 655 for (i = 0; i < 8; i++) {
619 cycles_t start, end; 656 cycles_t start, end;
620 657
621 crypto_digest_init(tfm);
622
623 start = get_cycles(); 658 start = get_cycles();
624 659
660 ret = crypto_hash_init(desc);
661 if (ret)
662 goto out;
625 for (pcount = 0; pcount < blen; pcount += plen) { 663 for (pcount = 0; pcount < blen; pcount += plen) {
626 sg_set_buf(sg, p + pcount, plen); 664 sg_set_buf(sg, p + pcount, plen);
627 crypto_digest_update(tfm, sg, 1); 665 ret = crypto_hash_update(desc, sg, plen);
666 if (ret)
667 goto out;
628 } 668 }
629 crypto_digest_final(tfm, out); 669 ret = crypto_hash_final(desc, out);
670 if (ret)
671 goto out;
630 672
631 end = get_cycles(); 673 end = get_cycles();
632 674
633 cycles += end - start; 675 cycles += end - start;
634 } 676 }
635 677
678out:
636 local_irq_enable(); 679 local_irq_enable();
637 local_bh_enable(); 680 local_bh_enable();
638 681
682 if (ret)
683 return ret;
684
639 printk("%6lu cycles/operation, %4lu cycles/byte\n", 685 printk("%6lu cycles/operation, %4lu cycles/byte\n",
640 cycles / 8, cycles / (8 * blen)); 686 cycles / 8, cycles / (8 * blen));
641 687
642 return; 688 return 0;
643} 689}
644 690
645static void test_digest_speed(char *algo, unsigned int sec, 691static void test_hash_speed(char *algo, unsigned int sec,
646 struct digest_speed *speed) 692 struct hash_speed *speed)
647{ 693{
648 struct crypto_tfm *tfm; 694 struct crypto_hash *tfm;
695 struct hash_desc desc;
649 char output[1024]; 696 char output[1024];
650 int i; 697 int i;
698 int ret;
651 699
652 printk("\ntesting speed of %s\n", algo); 700 printk("\ntesting speed of %s\n", algo);
653 701
654 tfm = crypto_alloc_tfm(algo, 0); 702 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
655 703
656 if (tfm == NULL) { 704 if (IS_ERR(tfm)) {
657 printk("failed to load transform for %s\n", algo); 705 printk("failed to load transform for %s: %ld\n", algo,
706 PTR_ERR(tfm));
658 return; 707 return;
659 } 708 }
660 709
661 if (crypto_tfm_alg_digestsize(tfm) > sizeof(output)) { 710 desc.tfm = tfm;
711 desc.flags = 0;
712
713 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
662 printk("digestsize(%u) > outputbuffer(%zu)\n", 714 printk("digestsize(%u) > outputbuffer(%zu)\n",
663 crypto_tfm_alg_digestsize(tfm), sizeof(output)); 715 crypto_hash_digestsize(tfm), sizeof(output));
664 goto out; 716 goto out;
665 } 717 }
666 718
@@ -677,13 +729,20 @@ static void test_digest_speed(char *algo, unsigned int sec,
677 memset(tvmem, 0xff, speed[i].blen); 729 memset(tvmem, 0xff, speed[i].blen);
678 730
679 if (sec) 731 if (sec)
680 test_digest_jiffies(tfm, tvmem, speed[i].blen, speed[i].plen, output, sec); 732 ret = test_hash_jiffies(&desc, tvmem, speed[i].blen,
733 speed[i].plen, output, sec);
681 else 734 else
682 test_digest_cycles(tfm, tvmem, speed[i].blen, speed[i].plen, output); 735 ret = test_hash_cycles(&desc, tvmem, speed[i].blen,
736 speed[i].plen, output);
737
738 if (ret) {
739 printk("hashing failed ret=%d\n", ret);
740 break;
741 }
683 } 742 }
684 743
685out: 744out:
686 crypto_free_tfm(tfm); 745 crypto_free_hash(tfm);
687} 746}
688 747
689static void test_deflate(void) 748static void test_deflate(void)
@@ -911,11 +970,12 @@ static void do_test(void)
911 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS); 970 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
912 test_deflate(); 971 test_deflate();
913 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS); 972 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
914#ifdef CONFIG_CRYPTO_HMAC 973 test_hash("hmac(md5)", hmac_md5_tv_template,
915 test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS); 974 HMAC_MD5_TEST_VECTORS);
916 test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS); 975 test_hash("hmac(sha1)", hmac_sha1_tv_template,
917 test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS); 976 HMAC_SHA1_TEST_VECTORS);
918#endif 977 test_hash("hmac(sha256)", hmac_sha256_tv_template,
978 HMAC_SHA256_TEST_VECTORS);
919 979
920 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS); 980 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
921 break; 981 break;
@@ -1106,20 +1166,21 @@ static void do_test(void)
1106 XETA_DEC_TEST_VECTORS); 1166 XETA_DEC_TEST_VECTORS);
1107 break; 1167 break;
1108 1168
1109#ifdef CONFIG_CRYPTO_HMAC
1110 case 100: 1169 case 100:
1111 test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS); 1170 test_hash("hmac(md5)", hmac_md5_tv_template,
1171 HMAC_MD5_TEST_VECTORS);
1112 break; 1172 break;
1113 1173
1114 case 101: 1174 case 101:
1115 test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS); 1175 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1176 HMAC_SHA1_TEST_VECTORS);
1116 break; 1177 break;
1117 1178
1118 case 102: 1179 case 102:
1119 test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS); 1180 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1181 HMAC_SHA256_TEST_VECTORS);
1120 break; 1182 break;
1121 1183
1122#endif
1123 1184
1124 case 200: 1185 case 200:
1125 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, 1186 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
@@ -1188,51 +1249,51 @@ static void do_test(void)
1188 /* fall through */ 1249 /* fall through */
1189 1250
1190 case 301: 1251 case 301:
1191 test_digest_speed("md4", sec, generic_digest_speed_template); 1252 test_hash_speed("md4", sec, generic_hash_speed_template);
1192 if (mode > 300 && mode < 400) break; 1253 if (mode > 300 && mode < 400) break;
1193 1254
1194 case 302: 1255 case 302:
1195 test_digest_speed("md5", sec, generic_digest_speed_template); 1256 test_hash_speed("md5", sec, generic_hash_speed_template);
1196 if (mode > 300 && mode < 400) break; 1257 if (mode > 300 && mode < 400) break;
1197 1258
1198 case 303: 1259 case 303:
1199 test_digest_speed("sha1", sec, generic_digest_speed_template); 1260 test_hash_speed("sha1", sec, generic_hash_speed_template);
1200 if (mode > 300 && mode < 400) break; 1261 if (mode > 300 && mode < 400) break;
1201 1262
1202 case 304: 1263 case 304:
1203 test_digest_speed("sha256", sec, generic_digest_speed_template); 1264 test_hash_speed("sha256", sec, generic_hash_speed_template);
1204 if (mode > 300 && mode < 400) break; 1265 if (mode > 300 && mode < 400) break;
1205 1266
1206 case 305: 1267 case 305:
1207 test_digest_speed("sha384", sec, generic_digest_speed_template); 1268 test_hash_speed("sha384", sec, generic_hash_speed_template);
1208 if (mode > 300 && mode < 400) break; 1269 if (mode > 300 && mode < 400) break;
1209 1270
1210 case 306: 1271 case 306:
1211 test_digest_speed("sha512", sec, generic_digest_speed_template); 1272 test_hash_speed("sha512", sec, generic_hash_speed_template);
1212 if (mode > 300 && mode < 400) break; 1273 if (mode > 300 && mode < 400) break;
1213 1274
1214 case 307: 1275 case 307:
1215 test_digest_speed("wp256", sec, generic_digest_speed_template); 1276 test_hash_speed("wp256", sec, generic_hash_speed_template);
1216 if (mode > 300 && mode < 400) break; 1277 if (mode > 300 && mode < 400) break;
1217 1278
1218 case 308: 1279 case 308:
1219 test_digest_speed("wp384", sec, generic_digest_speed_template); 1280 test_hash_speed("wp384", sec, generic_hash_speed_template);
1220 if (mode > 300 && mode < 400) break; 1281 if (mode > 300 && mode < 400) break;
1221 1282
1222 case 309: 1283 case 309:
1223 test_digest_speed("wp512", sec, generic_digest_speed_template); 1284 test_hash_speed("wp512", sec, generic_hash_speed_template);
1224 if (mode > 300 && mode < 400) break; 1285 if (mode > 300 && mode < 400) break;
1225 1286
1226 case 310: 1287 case 310:
1227 test_digest_speed("tgr128", sec, generic_digest_speed_template); 1288 test_hash_speed("tgr128", sec, generic_hash_speed_template);
1228 if (mode > 300 && mode < 400) break; 1289 if (mode > 300 && mode < 400) break;
1229 1290
1230 case 311: 1291 case 311:
1231 test_digest_speed("tgr160", sec, generic_digest_speed_template); 1292 test_hash_speed("tgr160", sec, generic_hash_speed_template);
1232 if (mode > 300 && mode < 400) break; 1293 if (mode > 300 && mode < 400) break;
1233 1294
1234 case 312: 1295 case 312:
1235 test_digest_speed("tgr192", sec, generic_digest_speed_template); 1296 test_hash_speed("tgr192", sec, generic_hash_speed_template);
1236 if (mode > 300 && mode < 400) break; 1297 if (mode > 300 && mode < 400) break;
1237 1298
1238 case 399: 1299 case 399:
diff --git a/crypto/tcrypt.h b/crypto/tcrypt.h
index 408d5aad5864..a40c4411729e 100644
--- a/crypto/tcrypt.h
+++ b/crypto/tcrypt.h
@@ -36,16 +36,6 @@ struct hash_testvec {
36 unsigned char ksize; 36 unsigned char ksize;
37}; 37};
38 38
39struct hmac_testvec {
40 char key[128];
41 char plaintext[128];
42 char digest[MAX_DIGEST_SIZE];
43 unsigned char tap[MAX_TAP];
44 unsigned char ksize;
45 unsigned char psize;
46 unsigned char np;
47};
48
49struct cipher_testvec { 39struct cipher_testvec {
50 char key[MAX_KEYLEN] __attribute__ ((__aligned__(4))); 40 char key[MAX_KEYLEN] __attribute__ ((__aligned__(4)));
51 char iv[MAX_IVLEN]; 41 char iv[MAX_IVLEN];
@@ -65,7 +55,7 @@ struct cipher_speed {
65 unsigned int blen; 55 unsigned int blen;
66}; 56};
67 57
68struct digest_speed { 58struct hash_speed {
69 unsigned int blen; /* buffer length */ 59 unsigned int blen; /* buffer length */
70 unsigned int plen; /* per-update length */ 60 unsigned int plen; /* per-update length */
71}; 61};
@@ -697,14 +687,13 @@ static struct hash_testvec tgr128_tv_template[] = {
697 }, 687 },
698}; 688};
699 689
700#ifdef CONFIG_CRYPTO_HMAC
701/* 690/*
702 * HMAC-MD5 test vectors from RFC2202 691 * HMAC-MD5 test vectors from RFC2202
703 * (These need to be fixed to not use strlen). 692 * (These need to be fixed to not use strlen).
704 */ 693 */
705#define HMAC_MD5_TEST_VECTORS 7 694#define HMAC_MD5_TEST_VECTORS 7
706 695
707static struct hmac_testvec hmac_md5_tv_template[] = 696static struct hash_testvec hmac_md5_tv_template[] =
708{ 697{
709 { 698 {
710 .key = { [0 ... 15] = 0x0b }, 699 .key = { [0 ... 15] = 0x0b },
@@ -768,7 +757,7 @@ static struct hmac_testvec hmac_md5_tv_template[] =
768 */ 757 */
769#define HMAC_SHA1_TEST_VECTORS 7 758#define HMAC_SHA1_TEST_VECTORS 7
770 759
771static struct hmac_testvec hmac_sha1_tv_template[] = { 760static struct hash_testvec hmac_sha1_tv_template[] = {
772 { 761 {
773 .key = { [0 ... 19] = 0x0b }, 762 .key = { [0 ... 19] = 0x0b },
774 .ksize = 20, 763 .ksize = 20,
@@ -833,7 +822,7 @@ static struct hmac_testvec hmac_sha1_tv_template[] = {
833 */ 822 */
834#define HMAC_SHA256_TEST_VECTORS 10 823#define HMAC_SHA256_TEST_VECTORS 10
835 824
836static struct hmac_testvec hmac_sha256_tv_template[] = { 825static struct hash_testvec hmac_sha256_tv_template[] = {
837 { 826 {
838 .key = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 827 .key = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
839 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 828 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
@@ -944,8 +933,6 @@ static struct hmac_testvec hmac_sha256_tv_template[] = {
944 }, 933 },
945}; 934};
946 935
947#endif /* CONFIG_CRYPTO_HMAC */
948
949/* 936/*
950 * DES test vectors. 937 * DES test vectors.
951 */ 938 */
@@ -3160,7 +3147,7 @@ static struct cipher_speed des_speed_template[] = {
3160/* 3147/*
3161 * Digest speed tests 3148 * Digest speed tests
3162 */ 3149 */
3163static struct digest_speed generic_digest_speed_template[] = { 3150static struct hash_speed generic_hash_speed_template[] = {
3164 { .blen = 16, .plen = 16, }, 3151 { .blen = 16, .plen = 16, },
3165 { .blen = 64, .plen = 16, }, 3152 { .blen = 64, .plen = 16, },
3166 { .blen = 64, .plen = 64, }, 3153 { .blen = 64, .plen = 64, },