aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/tcrypt.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/tcrypt.c')
-rw-r--r--crypto/tcrypt.c134
1 files changed, 131 insertions, 3 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index 85a88a71ff53..414ef5e71171 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
56static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 }; 58static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
57 59
60/*
61 * Used by test_cipher_speed()
62 */
63static unsigned int sec = 10;
64
58static int mode; 65static int mode;
59static char *xbuf; 66static char *xbuf;
60static char *tvmem; 67static char *tvmem;
@@ -419,6 +426,90 @@ out:
419 crypto_free_tfm(tfm); 426 crypto_free_tfm(tfm);
420} 427}
421 428
429static 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
509out:
510 crypto_free_tfm(tfm);
511}
512
422static void test_deflate(void) 513static 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);
901module_exit(fini); 1027module_exit(fini);
902 1028
903module_param(mode, int, 0); 1029module_param(mode, int, 0);
1030module_param(sec, uint, 0);
1031MODULE_PARM_DESC(sec, "Length in seconds of speed tests");
904 1032
905MODULE_LICENSE("GPL"); 1033MODULE_LICENSE("GPL");
906MODULE_DESCRIPTION("Quick & dirty crypto testing module"); 1034MODULE_DESCRIPTION("Quick & dirty crypto testing module");