diff options
author | Harald Welte <laforge@gnumonks.org> | 2005-06-22 16:27:23 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2005-06-22 16:27:23 -0400 |
commit | ebfd9bcf16e4aaddcfe2d1b76b50e3dd6d3242e2 (patch) | |
tree | a82a4d627d339197846031e16e2de622c766fe5e /crypto | |
parent | 3cc3816f93e3f94f88503da8e6090302fa986bd6 (diff) |
[CRYPTO]: Add cipher speed tests
From: Reyk Floeter <reyk@vantronix.net>
I recently had the requirement to do some benchmarking on cryptoapi, and
I found reyk's very useful performance test patch [1].
However, I could not find any discussion on why that extension (or
something providing a similar feature but different implementation) was
not merged into mainline. If there was such a discussion, can someone
please point me to the archive[s]?
I've now merged the old patch into 2.6.12-rc1, the result can be found
attached to this email.
[1] http://lists.logix.cz/pipermail/padlock/2004/000010.html
Signed-off-by: Harald Welte <laforge@gnumonks.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/tcrypt.c | 134 | ||||
-rw-r--r-- | crypto/tcrypt.h | 92 |
2 files changed, 222 insertions, 4 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index 85a88a71ff5..414ef5e7117 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c | |||
@@ -12,8 +12,9 @@ | |||
12 | * Software Foundation; either version 2 of the License, or (at your option) | 12 | * Software Foundation; either version 2 of the License, or (at your option) |
13 | * any later version. | 13 | * any later version. |
14 | * | 14 | * |
15 | * 14 - 09 - 2003 | 15 | * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>) |
16 | * Rewritten by Kartikey Mahendra Bhatt | 16 | * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt |
17 | * | ||
17 | */ | 18 | */ |
18 | 19 | ||
19 | #include <linux/init.h> | 20 | #include <linux/init.h> |
@@ -25,12 +26,13 @@ | |||
25 | #include <linux/crypto.h> | 26 | #include <linux/crypto.h> |
26 | #include <linux/highmem.h> | 27 | #include <linux/highmem.h> |
27 | #include <linux/moduleparam.h> | 28 | #include <linux/moduleparam.h> |
29 | #include <linux/jiffies.h> | ||
28 | #include "tcrypt.h" | 30 | #include "tcrypt.h" |
29 | 31 | ||
30 | /* | 32 | /* |
31 | * Need to kmalloc() memory for testing kmap(). | 33 | * Need to kmalloc() memory for testing kmap(). |
32 | */ | 34 | */ |
33 | #define TVMEMSIZE 4096 | 35 | #define TVMEMSIZE 16384 |
34 | #define XBUFSIZE 32768 | 36 | #define XBUFSIZE 32768 |
35 | 37 | ||
36 | /* | 38 | /* |
@@ -55,6 +57,11 @@ | |||
55 | 57 | ||
56 | static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 }; | 58 | static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 }; |
57 | 59 | ||
60 | /* | ||
61 | * Used by test_cipher_speed() | ||
62 | */ | ||
63 | static unsigned int sec = 10; | ||
64 | |||
58 | static int mode; | 65 | static int mode; |
59 | static char *xbuf; | 66 | static char *xbuf; |
60 | static char *tvmem; | 67 | static char *tvmem; |
@@ -419,6 +426,90 @@ out: | |||
419 | crypto_free_tfm(tfm); | 426 | crypto_free_tfm(tfm); |
420 | } | 427 | } |
421 | 428 | ||
429 | static void test_cipher_speed(char *algo, int mode, int enc, unsigned int sec, | ||
430 | struct cipher_speed *speed) | ||
431 | { | ||
432 | unsigned int ret, i, iv_len; | ||
433 | unsigned char *key, *p, iv[128]; | ||
434 | struct crypto_tfm *tfm; | ||
435 | struct scatterlist sg[8]; | ||
436 | unsigned long start, bcount; | ||
437 | const char *e, *m; | ||
438 | |||
439 | if (enc == ENCRYPT) | ||
440 | e = "encryption"; | ||
441 | else | ||
442 | e = "decryption"; | ||
443 | if (mode == MODE_ECB) | ||
444 | m = "ECB"; | ||
445 | else | ||
446 | m = "CBC"; | ||
447 | |||
448 | printk("\ntesting speed of %s %s %s\n", algo, m, e); | ||
449 | |||
450 | if (mode) | ||
451 | tfm = crypto_alloc_tfm(algo, 0); | ||
452 | else | ||
453 | tfm = crypto_alloc_tfm(algo, CRYPTO_TFM_MODE_CBC); | ||
454 | |||
455 | if (tfm == NULL) { | ||
456 | printk("failed to load transform for %s %s\n", algo, m); | ||
457 | return; | ||
458 | } | ||
459 | |||
460 | for (i = 0; speed[i].klen != 0; i++) { | ||
461 | if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) { | ||
462 | printk("template (%u) too big for tvmem (%u)\n", | ||
463 | speed[i].blen + speed[i].klen, TVMEMSIZE); | ||
464 | goto out; | ||
465 | } | ||
466 | |||
467 | printk("test %u (%d bit key, %d byte blocks): ", i, | ||
468 | speed[i].klen * 8, speed[i].blen); | ||
469 | |||
470 | memset(tvmem, 0xff, speed[i].klen + speed[i].blen); | ||
471 | |||
472 | /* set key, plain text and IV */ | ||
473 | key = (unsigned char *)tvmem; | ||
474 | p = (unsigned char *)tvmem + speed[i].klen; | ||
475 | |||
476 | ret = crypto_cipher_setkey(tfm, key, speed[i].klen); | ||
477 | if (ret) { | ||
478 | printk("setkey() failed flags=%x\n", tfm->crt_flags); | ||
479 | goto out; | ||
480 | } | ||
481 | |||
482 | if (!mode) { | ||
483 | iv_len = crypto_tfm_alg_ivsize(tfm); | ||
484 | memset(&iv, 0xff, iv_len); | ||
485 | crypto_cipher_set_iv(tfm, iv, iv_len); | ||
486 | } | ||
487 | |||
488 | for (start = jiffies, bcount = 0; | ||
489 | ((jiffies - start) / HZ) < sec; bcount++) { | ||
490 | sg[0].page = virt_to_page(p); | ||
491 | sg[0].offset = offset_in_page(p); | ||
492 | sg[0].length = speed[i].blen; | ||
493 | |||
494 | if (enc) | ||
495 | ret = crypto_cipher_encrypt(tfm, sg, sg, speed[i].blen); | ||
496 | else | ||
497 | ret = crypto_cipher_decrypt(tfm, sg, sg, speed[i].blen); | ||
498 | |||
499 | if (ret) { | ||
500 | printk("%s () failed flags=%x\n", e, tfm->crt_flags); | ||
501 | goto out; | ||
502 | } | ||
503 | } | ||
504 | |||
505 | printk("%lu operations in %u seconds (%lu bytes)\n", | ||
506 | bcount, sec, bcount * speed[i].blen); | ||
507 | } | ||
508 | |||
509 | out: | ||
510 | crypto_free_tfm(tfm); | ||
511 | } | ||
512 | |||
422 | static void test_deflate(void) | 513 | static void test_deflate(void) |
423 | { | 514 | { |
424 | unsigned int i; | 515 | unsigned int i; |
@@ -861,6 +952,41 @@ static void do_test(void) | |||
861 | 952 | ||
862 | #endif | 953 | #endif |
863 | 954 | ||
955 | case 200: | ||
956 | test_cipher_speed("aes", MODE_ECB, ENCRYPT, sec, aes_speed_template); | ||
957 | test_cipher_speed("aes", MODE_ECB, DECRYPT, sec, aes_speed_template); | ||
958 | test_cipher_speed("aes", MODE_CBC, ENCRYPT, sec, aes_speed_template); | ||
959 | test_cipher_speed("aes", MODE_CBC, DECRYPT, sec, aes_speed_template); | ||
960 | break; | ||
961 | |||
962 | case 201: | ||
963 | test_cipher_speed("des3_ede", MODE_ECB, ENCRYPT, sec, des3_ede_speed_template); | ||
964 | test_cipher_speed("des3_ede", MODE_ECB, DECRYPT, sec, des3_ede_speed_template); | ||
965 | test_cipher_speed("des3_ede", MODE_CBC, ENCRYPT, sec, des3_ede_speed_template); | ||
966 | test_cipher_speed("des3_ede", MODE_CBC, DECRYPT, sec, des3_ede_speed_template); | ||
967 | break; | ||
968 | |||
969 | case 202: | ||
970 | test_cipher_speed("twofish", MODE_ECB, ENCRYPT, sec, twofish_speed_template); | ||
971 | test_cipher_speed("twofish", MODE_ECB, DECRYPT, sec, twofish_speed_template); | ||
972 | test_cipher_speed("twofish", MODE_CBC, ENCRYPT, sec, twofish_speed_template); | ||
973 | test_cipher_speed("twofish", MODE_CBC, DECRYPT, sec, twofish_speed_template); | ||
974 | break; | ||
975 | |||
976 | case 203: | ||
977 | test_cipher_speed("blowfish", MODE_ECB, ENCRYPT, sec, blowfish_speed_template); | ||
978 | test_cipher_speed("blowfish", MODE_ECB, DECRYPT, sec, blowfish_speed_template); | ||
979 | test_cipher_speed("blowfish", MODE_CBC, ENCRYPT, sec, blowfish_speed_template); | ||
980 | test_cipher_speed("blowfish", MODE_CBC, DECRYPT, sec, blowfish_speed_template); | ||
981 | break; | ||
982 | |||
983 | case 204: | ||
984 | test_cipher_speed("des", MODE_ECB, ENCRYPT, sec, des_speed_template); | ||
985 | test_cipher_speed("des", MODE_ECB, DECRYPT, sec, des_speed_template); | ||
986 | test_cipher_speed("des", MODE_CBC, ENCRYPT, sec, des_speed_template); | ||
987 | test_cipher_speed("des", MODE_CBC, DECRYPT, sec, des_speed_template); | ||
988 | break; | ||
989 | |||
864 | case 1000: | 990 | case 1000: |
865 | test_available(); | 991 | test_available(); |
866 | break; | 992 | break; |
@@ -901,6 +1027,8 @@ module_init(init); | |||
901 | module_exit(fini); | 1027 | module_exit(fini); |
902 | 1028 | ||
903 | module_param(mode, int, 0); | 1029 | module_param(mode, int, 0); |
1030 | module_param(sec, uint, 0); | ||
1031 | MODULE_PARM_DESC(sec, "Length in seconds of speed tests"); | ||
904 | 1032 | ||
905 | MODULE_LICENSE("GPL"); | 1033 | MODULE_LICENSE("GPL"); |
906 | MODULE_DESCRIPTION("Quick & dirty crypto testing module"); | 1034 | MODULE_DESCRIPTION("Quick & dirty crypto testing module"); |
diff --git a/crypto/tcrypt.h b/crypto/tcrypt.h index 72d40704042..c01a0ce9b40 100644 --- a/crypto/tcrypt.h +++ b/crypto/tcrypt.h | |||
@@ -12,7 +12,8 @@ | |||
12 | * Software Foundation; either version 2 of the License, or (at your option) | 12 | * Software Foundation; either version 2 of the License, or (at your option) |
13 | * any later version. | 13 | * any later version. |
14 | * | 14 | * |
15 | * 14 - 09 - 2003 Changes by Kartikey Mahendra Bhatt | 15 | * 2004-08-09 Cipher speed tests by Reyk Floeter <reyk@vantronix.net> |
16 | * 2003-09-14 Changes by Kartikey Mahendra Bhatt | ||
16 | * | 17 | * |
17 | */ | 18 | */ |
18 | #ifndef _CRYPTO_TCRYPT_H | 19 | #ifndef _CRYPTO_TCRYPT_H |
@@ -58,6 +59,11 @@ struct cipher_testvec { | |||
58 | unsigned char tap[MAX_TAP]; | 59 | unsigned char tap[MAX_TAP]; |
59 | }; | 60 | }; |
60 | 61 | ||
62 | struct cipher_speed { | ||
63 | unsigned char klen; | ||
64 | unsigned int blen; | ||
65 | }; | ||
66 | |||
61 | /* | 67 | /* |
62 | * MD4 test vectors from RFC1320 | 68 | * MD4 test vectors from RFC1320 |
63 | */ | 69 | */ |
@@ -2728,4 +2734,88 @@ static struct hash_testvec michael_mic_tv_template[] = { | |||
2728 | } | 2734 | } |
2729 | }; | 2735 | }; |
2730 | 2736 | ||
2737 | /* | ||
2738 | * Cipher speed tests | ||
2739 | */ | ||
2740 | static struct cipher_speed aes_speed_template[] = { | ||
2741 | { .klen = 16, .blen = 16, }, | ||
2742 | { .klen = 16, .blen = 64, }, | ||
2743 | { .klen = 16, .blen = 256, }, | ||
2744 | { .klen = 16, .blen = 1024, }, | ||
2745 | { .klen = 16, .blen = 8192, }, | ||
2746 | { .klen = 24, .blen = 16, }, | ||
2747 | { .klen = 24, .blen = 64, }, | ||
2748 | { .klen = 24, .blen = 256, }, | ||
2749 | { .klen = 24, .blen = 1024, }, | ||
2750 | { .klen = 24, .blen = 8192, }, | ||
2751 | { .klen = 32, .blen = 16, }, | ||
2752 | { .klen = 32, .blen = 64, }, | ||
2753 | { .klen = 32, .blen = 256, }, | ||
2754 | { .klen = 32, .blen = 1024, }, | ||
2755 | { .klen = 32, .blen = 8192, }, | ||
2756 | |||
2757 | /* End marker */ | ||
2758 | { .klen = 0, .blen = 0, } | ||
2759 | }; | ||
2760 | |||
2761 | static struct cipher_speed des3_ede_speed_template[] = { | ||
2762 | { .klen = 24, .blen = 16, }, | ||
2763 | { .klen = 24, .blen = 64, }, | ||
2764 | { .klen = 24, .blen = 256, }, | ||
2765 | { .klen = 24, .blen = 1024, }, | ||
2766 | { .klen = 24, .blen = 8192, }, | ||
2767 | |||
2768 | /* End marker */ | ||
2769 | { .klen = 0, .blen = 0, } | ||
2770 | }; | ||
2771 | |||
2772 | static struct cipher_speed twofish_speed_template[] = { | ||
2773 | { .klen = 16, .blen = 16, }, | ||
2774 | { .klen = 16, .blen = 64, }, | ||
2775 | { .klen = 16, .blen = 256, }, | ||
2776 | { .klen = 16, .blen = 1024, }, | ||
2777 | { .klen = 16, .blen = 8192, }, | ||
2778 | { .klen = 24, .blen = 16, }, | ||
2779 | { .klen = 24, .blen = 64, }, | ||
2780 | { .klen = 24, .blen = 256, }, | ||
2781 | { .klen = 24, .blen = 1024, }, | ||
2782 | { .klen = 24, .blen = 8192, }, | ||
2783 | { .klen = 32, .blen = 16, }, | ||
2784 | { .klen = 32, .blen = 64, }, | ||
2785 | { .klen = 32, .blen = 256, }, | ||
2786 | { .klen = 32, .blen = 1024, }, | ||
2787 | { .klen = 32, .blen = 8192, }, | ||
2788 | |||
2789 | /* End marker */ | ||
2790 | { .klen = 0, .blen = 0, } | ||
2791 | }; | ||
2792 | |||
2793 | static struct cipher_speed blowfish_speed_template[] = { | ||
2794 | /* Don't support blowfish keys > 256 bit in this test */ | ||
2795 | { .klen = 8, .blen = 16, }, | ||
2796 | { .klen = 8, .blen = 64, }, | ||
2797 | { .klen = 8, .blen = 256, }, | ||
2798 | { .klen = 8, .blen = 1024, }, | ||
2799 | { .klen = 8, .blen = 8192, }, | ||
2800 | { .klen = 32, .blen = 16, }, | ||
2801 | { .klen = 32, .blen = 64, }, | ||
2802 | { .klen = 32, .blen = 256, }, | ||
2803 | { .klen = 32, .blen = 1024, }, | ||
2804 | { .klen = 32, .blen = 8192, }, | ||
2805 | |||
2806 | /* End marker */ | ||
2807 | { .klen = 0, .blen = 0, } | ||
2808 | }; | ||
2809 | |||
2810 | static struct cipher_speed des_speed_template[] = { | ||
2811 | { .klen = 8, .blen = 16, }, | ||
2812 | { .klen = 8, .blen = 64, }, | ||
2813 | { .klen = 8, .blen = 256, }, | ||
2814 | { .klen = 8, .blen = 1024, }, | ||
2815 | { .klen = 8, .blen = 8192, }, | ||
2816 | |||
2817 | /* End marker */ | ||
2818 | { .klen = 0, .blen = 0, } | ||
2819 | }; | ||
2820 | |||
2731 | #endif /* _CRYPTO_TCRYPT_H */ | 2821 | #endif /* _CRYPTO_TCRYPT_H */ |