aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/tcrypt.c
diff options
context:
space:
mode:
authorJussi Kivilinna <jussi.kivilinna@mbnet.fi>2011-10-17 17:02:58 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2011-11-08 22:42:59 -0500
commit3f3baf359dd3cc56fbaf9a2fb1a425ce7c18dbff (patch)
tree735dc01ad32c9a76f37fe7adfb4ba880f13d7147 /crypto/tcrypt.c
parent9d25917d49d986c417c173bfde50f41f96c5b202 (diff)
crypto: tcrypt - add test_acipher_speed
Add test_acipher_speed for testing async block ciphers. Also include tests for aes/des/des3/ede as these appear to have ablk_cipher implementations available. Signed-off-by: Jussi Kivilinna <jussi.kivilinna@mbnet.fi> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/tcrypt.c')
-rw-r--r--crypto/tcrypt.c250
1 files changed, 250 insertions, 0 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index ac9e4d2a63b..dd3a0f8a091 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -719,6 +719,207 @@ out:
719 crypto_free_ahash(tfm); 719 crypto_free_ahash(tfm);
720} 720}
721 721
722static inline int do_one_acipher_op(struct ablkcipher_request *req, int ret)
723{
724 if (ret == -EINPROGRESS || ret == -EBUSY) {
725 struct tcrypt_result *tr = req->base.data;
726
727 ret = wait_for_completion_interruptible(&tr->completion);
728 if (!ret)
729 ret = tr->err;
730 INIT_COMPLETION(tr->completion);
731 }
732
733 return ret;
734}
735
736static int test_acipher_jiffies(struct ablkcipher_request *req, int enc,
737 int blen, int sec)
738{
739 unsigned long start, end;
740 int bcount;
741 int ret;
742
743 for (start = jiffies, end = start + sec * HZ, bcount = 0;
744 time_before(jiffies, end); bcount++) {
745 if (enc)
746 ret = do_one_acipher_op(req,
747 crypto_ablkcipher_encrypt(req));
748 else
749 ret = do_one_acipher_op(req,
750 crypto_ablkcipher_decrypt(req));
751
752 if (ret)
753 return ret;
754 }
755
756 pr_cont("%d operations in %d seconds (%ld bytes)\n",
757 bcount, sec, (long)bcount * blen);
758 return 0;
759}
760
761static int test_acipher_cycles(struct ablkcipher_request *req, int enc,
762 int blen)
763{
764 unsigned long cycles = 0;
765 int ret = 0;
766 int i;
767
768 /* Warm-up run. */
769 for (i = 0; i < 4; i++) {
770 if (enc)
771 ret = do_one_acipher_op(req,
772 crypto_ablkcipher_encrypt(req));
773 else
774 ret = do_one_acipher_op(req,
775 crypto_ablkcipher_decrypt(req));
776
777 if (ret)
778 goto out;
779 }
780
781 /* The real thing. */
782 for (i = 0; i < 8; i++) {
783 cycles_t start, end;
784
785 start = get_cycles();
786 if (enc)
787 ret = do_one_acipher_op(req,
788 crypto_ablkcipher_encrypt(req));
789 else
790 ret = do_one_acipher_op(req,
791 crypto_ablkcipher_decrypt(req));
792 end = get_cycles();
793
794 if (ret)
795 goto out;
796
797 cycles += end - start;
798 }
799
800out:
801 if (ret == 0)
802 pr_cont("1 operation in %lu cycles (%d bytes)\n",
803 (cycles + 4) / 8, blen);
804
805 return ret;
806}
807
808static void test_acipher_speed(const char *algo, int enc, unsigned int sec,
809 struct cipher_speed_template *template,
810 unsigned int tcount, u8 *keysize)
811{
812 unsigned int ret, i, j, iv_len;
813 struct tcrypt_result tresult;
814 const char *key;
815 char iv[128];
816 struct ablkcipher_request *req;
817 struct crypto_ablkcipher *tfm;
818 const char *e;
819 u32 *b_size;
820
821 if (enc == ENCRYPT)
822 e = "encryption";
823 else
824 e = "decryption";
825
826 pr_info("\ntesting speed of async %s %s\n", algo, e);
827
828 init_completion(&tresult.completion);
829
830 tfm = crypto_alloc_ablkcipher(algo, 0, 0);
831
832 if (IS_ERR(tfm)) {
833 pr_err("failed to load transform for %s: %ld\n", algo,
834 PTR_ERR(tfm));
835 return;
836 }
837
838 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
839 if (!req) {
840 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
841 algo);
842 goto out;
843 }
844
845 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
846 tcrypt_complete, &tresult);
847
848 i = 0;
849 do {
850 b_size = block_sizes;
851
852 do {
853 struct scatterlist sg[TVMEMSIZE];
854
855 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
856 pr_err("template (%u) too big for "
857 "tvmem (%lu)\n", *keysize + *b_size,
858 TVMEMSIZE * PAGE_SIZE);
859 goto out_free_req;
860 }
861
862 pr_info("test %u (%d bit key, %d byte blocks): ", i,
863 *keysize * 8, *b_size);
864
865 memset(tvmem[0], 0xff, PAGE_SIZE);
866
867 /* set key, plain text and IV */
868 key = tvmem[0];
869 for (j = 0; j < tcount; j++) {
870 if (template[j].klen == *keysize) {
871 key = template[j].key;
872 break;
873 }
874 }
875
876 crypto_ablkcipher_clear_flags(tfm, ~0);
877
878 ret = crypto_ablkcipher_setkey(tfm, key, *keysize);
879 if (ret) {
880 pr_err("setkey() failed flags=%x\n",
881 crypto_ablkcipher_get_flags(tfm));
882 goto out_free_req;
883 }
884
885 sg_init_table(sg, TVMEMSIZE);
886 sg_set_buf(sg, tvmem[0] + *keysize,
887 PAGE_SIZE - *keysize);
888 for (j = 1; j < TVMEMSIZE; j++) {
889 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
890 memset(tvmem[j], 0xff, PAGE_SIZE);
891 }
892
893 iv_len = crypto_ablkcipher_ivsize(tfm);
894 if (iv_len)
895 memset(&iv, 0xff, iv_len);
896
897 ablkcipher_request_set_crypt(req, sg, sg, *b_size, iv);
898
899 if (sec)
900 ret = test_acipher_jiffies(req, enc,
901 *b_size, sec);
902 else
903 ret = test_acipher_cycles(req, enc,
904 *b_size);
905
906 if (ret) {
907 pr_err("%s() failed flags=%x\n", e,
908 crypto_ablkcipher_get_flags(tfm));
909 break;
910 }
911 b_size++;
912 i++;
913 } while (*b_size);
914 keysize++;
915 } while (*keysize);
916
917out_free_req:
918 ablkcipher_request_free(req);
919out:
920 crypto_free_ablkcipher(tfm);
921}
922
722static void test_available(void) 923static void test_available(void)
723{ 924{
724 char **name = check; 925 char **name = check;
@@ -1243,6 +1444,55 @@ static int do_test(int m)
1243 case 499: 1444 case 499:
1244 break; 1445 break;
1245 1446
1447 case 500:
1448 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1449 speed_template_16_24_32);
1450 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1451 speed_template_16_24_32);
1452 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1453 speed_template_16_24_32);
1454 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1455 speed_template_16_24_32);
1456 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1457 speed_template_32_40_48);
1458 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1459 speed_template_32_40_48);
1460 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1461 speed_template_32_48_64);
1462 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1463 speed_template_32_48_64);
1464 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1465 speed_template_16_24_32);
1466 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1467 speed_template_16_24_32);
1468 break;
1469
1470 case 501:
1471 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1472 des3_speed_template, DES3_SPEED_VECTORS,
1473 speed_template_24);
1474 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
1475 des3_speed_template, DES3_SPEED_VECTORS,
1476 speed_template_24);
1477 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1478 des3_speed_template, DES3_SPEED_VECTORS,
1479 speed_template_24);
1480 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
1481 des3_speed_template, DES3_SPEED_VECTORS,
1482 speed_template_24);
1483 break;
1484
1485 case 502:
1486 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1487 speed_template_8);
1488 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1489 speed_template_8);
1490 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1491 speed_template_8);
1492 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1493 speed_template_8);
1494 break;
1495
1246 case 1000: 1496 case 1000:
1247 test_available(); 1497 test_available();
1248 break; 1498 break;