aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/tcrypt.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/tcrypt.c')
-rw-r--r--crypto/tcrypt.c170
1 files changed, 170 insertions, 0 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index 7bf93c5decfe..e52f56c5bd5e 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -570,6 +570,122 @@ out:
570 crypto_free_tfm(tfm); 570 crypto_free_tfm(tfm);
571} 571}
572 572
573static void test_digest_jiffies(struct crypto_tfm *tfm, char *p, int blen,
574 int plen, char *out, int sec)
575{
576 struct scatterlist sg[1];
577 unsigned long start, end;
578 int bcount, pcount;
579
580 for (start = jiffies, end = start + sec * HZ, bcount = 0;
581 time_before(jiffies, end); bcount++) {
582 crypto_digest_init(tfm);
583 for (pcount = 0; pcount < blen; pcount += plen) {
584 sg_set_buf(sg, p + pcount, plen);
585 crypto_digest_update(tfm, sg, 1);
586 }
587 /* we assume there is enough space in 'out' for the result */
588 crypto_digest_final(tfm, out);
589 }
590
591 printk("%6u opers/sec, %9lu bytes/sec\n",
592 bcount / sec, ((long)bcount * blen) / sec);
593
594 return;
595}
596
597static void test_digest_cycles(struct crypto_tfm *tfm, char *p, int blen,
598 int plen, char *out)
599{
600 struct scatterlist sg[1];
601 unsigned long cycles = 0;
602 int i, pcount;
603
604 local_bh_disable();
605 local_irq_disable();
606
607 /* Warm-up run. */
608 for (i = 0; i < 4; i++) {
609 crypto_digest_init(tfm);
610 for (pcount = 0; pcount < blen; pcount += plen) {
611 sg_set_buf(sg, p + pcount, plen);
612 crypto_digest_update(tfm, sg, 1);
613 }
614 crypto_digest_final(tfm, out);
615 }
616
617 /* The real thing. */
618 for (i = 0; i < 8; i++) {
619 cycles_t start, end;
620
621 crypto_digest_init(tfm);
622
623 start = get_cycles();
624
625 for (pcount = 0; pcount < blen; pcount += plen) {
626 sg_set_buf(sg, p + pcount, plen);
627 crypto_digest_update(tfm, sg, 1);
628 }
629 crypto_digest_final(tfm, out);
630
631 end = get_cycles();
632
633 cycles += end - start;
634 }
635
636 local_irq_enable();
637 local_bh_enable();
638
639 printk("%6lu cycles/operation, %4lu cycles/byte\n",
640 cycles / 8, cycles / (8 * blen));
641
642 return;
643}
644
645static void test_digest_speed(char *algo, unsigned int sec,
646 struct digest_speed *speed)
647{
648 struct crypto_tfm *tfm;
649 char output[1024];
650 int i;
651
652 printk("\ntesting speed of %s\n", algo);
653
654 tfm = crypto_alloc_tfm(algo, 0);
655
656 if (tfm == NULL) {
657 printk("failed to load transform for %s\n", algo);
658 return;
659 }
660
661 if (crypto_tfm_alg_digestsize(tfm) > sizeof(output)) {
662 printk("digestsize(%u) > outputbuffer(%zu)\n",
663 crypto_tfm_alg_digestsize(tfm), sizeof(output));
664 goto out;
665 }
666
667 for (i = 0; speed[i].blen != 0; i++) {
668 if (speed[i].blen > TVMEMSIZE) {
669 printk("template (%u) too big for tvmem (%u)\n",
670 speed[i].blen, TVMEMSIZE);
671 goto out;
672 }
673
674 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
675 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
676
677 memset(tvmem, 0xff, speed[i].blen);
678
679 if (sec)
680 test_digest_jiffies(tfm, tvmem, speed[i].blen, speed[i].plen, output, sec);
681 else
682 test_digest_cycles(tfm, tvmem, speed[i].blen, speed[i].plen, output);
683 }
684
685out:
686 crypto_free_tfm(tfm);
687}
688
573static void test_deflate(void) 689static void test_deflate(void)
574{ 690{
575 unsigned int i; 691 unsigned int i;
@@ -1086,6 +1202,60 @@ static void do_test(void)
1086 des_speed_template); 1202 des_speed_template);
1087 break; 1203 break;
1088 1204
1205 case 300:
1206 /* fall through */
1207
1208 case 301:
1209 test_digest_speed("md4", sec, generic_digest_speed_template);
1210 if (mode > 300 && mode < 400) break;
1211
1212 case 302:
1213 test_digest_speed("md5", sec, generic_digest_speed_template);
1214 if (mode > 300 && mode < 400) break;
1215
1216 case 303:
1217 test_digest_speed("sha1", sec, generic_digest_speed_template);
1218 if (mode > 300 && mode < 400) break;
1219
1220 case 304:
1221 test_digest_speed("sha256", sec, generic_digest_speed_template);
1222 if (mode > 300 && mode < 400) break;
1223
1224 case 305:
1225 test_digest_speed("sha384", sec, generic_digest_speed_template);
1226 if (mode > 300 && mode < 400) break;
1227
1228 case 306:
1229 test_digest_speed("sha512", sec, generic_digest_speed_template);
1230 if (mode > 300 && mode < 400) break;
1231
1232 case 307:
1233 test_digest_speed("wp256", sec, generic_digest_speed_template);
1234 if (mode > 300 && mode < 400) break;
1235
1236 case 308:
1237 test_digest_speed("wp384", sec, generic_digest_speed_template);
1238 if (mode > 300 && mode < 400) break;
1239
1240 case 309:
1241 test_digest_speed("wp512", sec, generic_digest_speed_template);
1242 if (mode > 300 && mode < 400) break;
1243
1244 case 310:
1245 test_digest_speed("tgr128", sec, generic_digest_speed_template);
1246 if (mode > 300 && mode < 400) break;
1247
1248 case 311:
1249 test_digest_speed("tgr160", sec, generic_digest_speed_template);
1250 if (mode > 300 && mode < 400) break;
1251
1252 case 312:
1253 test_digest_speed("tgr192", sec, generic_digest_speed_template);
1254 if (mode > 300 && mode < 400) break;
1255
1256 case 399:
1257 break;
1258
1089 case 1000: 1259 case 1000:
1090 test_available(); 1260 test_available();
1091 break; 1261 break;