2 * Quick & dirty crypto testing module.
4 * This will only exist until we have a better testing mechanism
5 * (e.g. a char device).
7 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
8 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
9 * Copyright (c) 2007 Nokia Siemens Networks
11 * Updated RFC4106 AES-GCM testing.
12 * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
13 * Adrian Hoban <adrian.hoban@intel.com>
14 * Gabriele Paoloni <gabriele.paoloni@intel.com>
15 * Tadeusz Struk (tadeusz.struk@intel.com)
16 * Copyright (c) 2010, Intel Corporation.
18 * This program is free software; you can redistribute it and/or modify it
19 * under the terms of the GNU General Public License as published by the Free
20 * Software Foundation; either version 2 of the License, or (at your option)
25 #include <crypto/hash.h>
26 #include <linux/err.h>
27 #include <linux/init.h>
28 #include <linux/gfp.h>
29 #include <linux/module.h>
30 #include <linux/scatterlist.h>
31 #include <linux/string.h>
32 #include <linux/moduleparam.h>
33 #include <linux/jiffies.h>
34 #include <linux/timex.h>
35 #include <linux/interrupt.h>
40 * Need slab memory for testing (size in number of pages).
45 * Used by test_cipher_speed()
51 * Used by test_cipher_speed()
53 static unsigned int sec
;
55 static char *alg
= NULL
;
59 static char *tvmem
[TVMEMSIZE
];
61 static char *check
[] = {
62 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
63 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
64 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
65 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
66 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
67 "lzo", "cts", "zlib", NULL
70 static int test_cipher_jiffies(struct blkcipher_desc
*desc
, int enc
,
71 struct scatterlist
*sg
, int blen
, int sec
)
73 unsigned long start
, end
;
77 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
78 time_before(jiffies
, end
); bcount
++) {
80 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
82 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
88 printk("%d operations in %d seconds (%ld bytes)\n",
89 bcount
, sec
, (long)bcount
* blen
);
93 static int test_cipher_cycles(struct blkcipher_desc
*desc
, int enc
,
94 struct scatterlist
*sg
, int blen
)
96 unsigned long cycles
= 0;
103 for (i
= 0; i
< 4; i
++) {
105 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
107 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
113 /* The real thing. */
114 for (i
= 0; i
< 8; i
++) {
117 start
= get_cycles();
119 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
121 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
127 cycles
+= end
- start
;
134 printk("1 operation in %lu cycles (%d bytes)\n",
135 (cycles
+ 4) / 8, blen
);
140 static int test_aead_jiffies(struct aead_request
*req
, int enc
,
143 unsigned long start
, end
;
147 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
148 time_before(jiffies
, end
); bcount
++) {
150 ret
= crypto_aead_encrypt(req
);
152 ret
= crypto_aead_decrypt(req
);
158 printk("%d operations in %d seconds (%ld bytes)\n",
159 bcount
, sec
, (long)bcount
* blen
);
163 static int test_aead_cycles(struct aead_request
*req
, int enc
, int blen
)
165 unsigned long cycles
= 0;
172 for (i
= 0; i
< 4; i
++) {
174 ret
= crypto_aead_encrypt(req
);
176 ret
= crypto_aead_decrypt(req
);
182 /* The real thing. */
183 for (i
= 0; i
< 8; i
++) {
186 start
= get_cycles();
188 ret
= crypto_aead_encrypt(req
);
190 ret
= crypto_aead_decrypt(req
);
196 cycles
+= end
- start
;
203 printk("1 operation in %lu cycles (%d bytes)\n",
204 (cycles
+ 4) / 8, blen
);
209 static u32 block_sizes
[] = { 16, 64, 256, 1024, 8192, 0 };
210 static u32 aead_sizes
[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
215 static int testmgr_alloc_buf(char *buf
[XBUFSIZE
])
219 for (i
= 0; i
< XBUFSIZE
; i
++) {
220 buf
[i
] = (void *)__get_free_page(GFP_KERNEL
);
229 free_page((unsigned long)buf
[i
]);
234 static void testmgr_free_buf(char *buf
[XBUFSIZE
])
238 for (i
= 0; i
< XBUFSIZE
; i
++)
239 free_page((unsigned long)buf
[i
]);
242 static void sg_init_aead(struct scatterlist
*sg
, char *xbuf
[XBUFSIZE
],
245 int np
= (buflen
+ PAGE_SIZE
- 1)/PAGE_SIZE
;
248 np
= (np
> XBUFSIZE
) ? XBUFSIZE
: np
;
249 rem
= buflen
% PAGE_SIZE
;
254 sg_init_table(sg
, np
);
255 for (k
= 0; k
< np
; ++k
) {
257 sg_set_buf(&sg
[k
], xbuf
[k
], rem
);
259 sg_set_buf(&sg
[k
], xbuf
[k
], PAGE_SIZE
);
263 static void test_aead_speed(const char *algo
, int enc
, unsigned int sec
,
264 struct aead_speed_template
*template,
265 unsigned int tcount
, u8 authsize
,
266 unsigned int aad_size
, u8
*keysize
)
269 struct crypto_aead
*tfm
;
272 struct aead_request
*req
;
273 struct scatterlist
*sg
;
274 struct scatterlist
*asg
;
275 struct scatterlist
*sgout
;
279 char *xbuf
[XBUFSIZE
];
280 char *xoutbuf
[XBUFSIZE
];
281 char *axbuf
[XBUFSIZE
];
282 unsigned int *b_size
;
285 if (aad_size
>= PAGE_SIZE
) {
286 pr_err("associate data length (%u) too big\n", aad_size
);
295 if (testmgr_alloc_buf(xbuf
))
297 if (testmgr_alloc_buf(axbuf
))
299 if (testmgr_alloc_buf(xoutbuf
))
302 sg
= kmalloc(sizeof(*sg
) * 8 * 3, GFP_KERNEL
);
309 printk(KERN_INFO
"\ntesting speed of %s %s\n", algo
, e
);
311 tfm
= crypto_alloc_aead(algo
, 0, 0);
314 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo
,
319 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
321 pr_err("alg: aead: Failed to allocate request for %s\n",
331 memset(assoc
, 0xff, aad_size
);
332 sg_init_one(&asg
[0], assoc
, aad_size
);
334 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
335 pr_err("template (%u) too big for tvmem (%lu)\n",
337 TVMEMSIZE
* PAGE_SIZE
);
342 for (j
= 0; j
< tcount
; j
++) {
343 if (template[j
].klen
== *keysize
) {
344 key
= template[j
].key
;
348 ret
= crypto_aead_setkey(tfm
, key
, *keysize
);
349 ret
= crypto_aead_setauthsize(tfm
, authsize
);
351 iv_len
= crypto_aead_ivsize(tfm
);
353 memset(&iv
, 0xff, iv_len
);
355 crypto_aead_clear_flags(tfm
, ~0);
356 printk(KERN_INFO
"test %u (%d bit key, %d byte blocks): ",
357 i
, *keysize
* 8, *b_size
);
360 memset(tvmem
[0], 0xff, PAGE_SIZE
);
363 pr_err("setkey() failed flags=%x\n",
364 crypto_aead_get_flags(tfm
));
368 sg_init_aead(&sg
[0], xbuf
,
369 *b_size
+ (enc
? authsize
: 0));
371 sg_init_aead(&sgout
[0], xoutbuf
,
372 *b_size
+ (enc
? authsize
: 0));
374 aead_request_set_crypt(req
, sg
, sgout
, *b_size
, iv
);
375 aead_request_set_assoc(req
, asg
, aad_size
);
378 ret
= test_aead_jiffies(req
, enc
, *b_size
, sec
);
380 ret
= test_aead_cycles(req
, enc
, *b_size
);
383 pr_err("%s() failed return code=%d\n", e
, ret
);
393 aead_request_free(req
);
395 crypto_free_aead(tfm
);
399 testmgr_free_buf(xoutbuf
);
401 testmgr_free_buf(axbuf
);
403 testmgr_free_buf(xbuf
);
408 static void test_cipher_speed(const char *algo
, int enc
, unsigned int sec
,
409 struct cipher_speed_template
*template,
410 unsigned int tcount
, u8
*keysize
)
412 unsigned int ret
, i
, j
, iv_len
;
415 struct crypto_blkcipher
*tfm
;
416 struct blkcipher_desc desc
;
425 printk("\ntesting speed of %s %s\n", algo
, e
);
427 tfm
= crypto_alloc_blkcipher(algo
, 0, CRYPTO_ALG_ASYNC
);
430 printk("failed to load transform for %s: %ld\n", algo
,
440 b_size
= block_sizes
;
442 struct scatterlist sg
[TVMEMSIZE
];
444 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
445 printk("template (%u) too big for "
446 "tvmem (%lu)\n", *keysize
+ *b_size
,
447 TVMEMSIZE
* PAGE_SIZE
);
451 printk("test %u (%d bit key, %d byte blocks): ", i
,
452 *keysize
* 8, *b_size
);
454 memset(tvmem
[0], 0xff, PAGE_SIZE
);
456 /* set key, plain text and IV */
458 for (j
= 0; j
< tcount
; j
++) {
459 if (template[j
].klen
== *keysize
) {
460 key
= template[j
].key
;
465 ret
= crypto_blkcipher_setkey(tfm
, key
, *keysize
);
467 printk("setkey() failed flags=%x\n",
468 crypto_blkcipher_get_flags(tfm
));
472 sg_init_table(sg
, TVMEMSIZE
);
473 sg_set_buf(sg
, tvmem
[0] + *keysize
,
474 PAGE_SIZE
- *keysize
);
475 for (j
= 1; j
< TVMEMSIZE
; j
++) {
476 sg_set_buf(sg
+ j
, tvmem
[j
], PAGE_SIZE
);
477 memset (tvmem
[j
], 0xff, PAGE_SIZE
);
480 iv_len
= crypto_blkcipher_ivsize(tfm
);
482 memset(&iv
, 0xff, iv_len
);
483 crypto_blkcipher_set_iv(tfm
, iv
, iv_len
);
487 ret
= test_cipher_jiffies(&desc
, enc
, sg
,
490 ret
= test_cipher_cycles(&desc
, enc
, sg
,
494 printk("%s() failed flags=%x\n", e
, desc
.flags
);
504 crypto_free_blkcipher(tfm
);
507 static int test_hash_jiffies_digest(struct hash_desc
*desc
,
508 struct scatterlist
*sg
, int blen
,
511 unsigned long start
, end
;
515 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
516 time_before(jiffies
, end
); bcount
++) {
517 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
522 printk("%6u opers/sec, %9lu bytes/sec\n",
523 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
528 static int test_hash_jiffies(struct hash_desc
*desc
, struct scatterlist
*sg
,
529 int blen
, int plen
, char *out
, int sec
)
531 unsigned long start
, end
;
536 return test_hash_jiffies_digest(desc
, sg
, blen
, out
, sec
);
538 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
539 time_before(jiffies
, end
); bcount
++) {
540 ret
= crypto_hash_init(desc
);
543 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
544 ret
= crypto_hash_update(desc
, sg
, plen
);
548 /* we assume there is enough space in 'out' for the result */
549 ret
= crypto_hash_final(desc
, out
);
554 printk("%6u opers/sec, %9lu bytes/sec\n",
555 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
560 static int test_hash_cycles_digest(struct hash_desc
*desc
,
561 struct scatterlist
*sg
, int blen
, char *out
)
563 unsigned long cycles
= 0;
570 for (i
= 0; i
< 4; i
++) {
571 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
576 /* The real thing. */
577 for (i
= 0; i
< 8; i
++) {
580 start
= get_cycles();
582 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
588 cycles
+= end
- start
;
597 printk("%6lu cycles/operation, %4lu cycles/byte\n",
598 cycles
/ 8, cycles
/ (8 * blen
));
603 static int test_hash_cycles(struct hash_desc
*desc
, struct scatterlist
*sg
,
604 int blen
, int plen
, char *out
)
606 unsigned long cycles
= 0;
611 return test_hash_cycles_digest(desc
, sg
, blen
, out
);
616 for (i
= 0; i
< 4; i
++) {
617 ret
= crypto_hash_init(desc
);
620 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
621 ret
= crypto_hash_update(desc
, sg
, plen
);
625 ret
= crypto_hash_final(desc
, out
);
630 /* The real thing. */
631 for (i
= 0; i
< 8; i
++) {
634 start
= get_cycles();
636 ret
= crypto_hash_init(desc
);
639 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
640 ret
= crypto_hash_update(desc
, sg
, plen
);
644 ret
= crypto_hash_final(desc
, out
);
650 cycles
+= end
- start
;
659 printk("%6lu cycles/operation, %4lu cycles/byte\n",
660 cycles
/ 8, cycles
/ (8 * blen
));
665 static void test_hash_sg_init(struct scatterlist
*sg
)
669 sg_init_table(sg
, TVMEMSIZE
);
670 for (i
= 0; i
< TVMEMSIZE
; i
++) {
671 sg_set_buf(sg
+ i
, tvmem
[i
], PAGE_SIZE
);
672 memset(tvmem
[i
], 0xff, PAGE_SIZE
);
676 static void test_hash_speed(const char *algo
, unsigned int sec
,
677 struct hash_speed
*speed
)
679 struct scatterlist sg
[TVMEMSIZE
];
680 struct crypto_hash
*tfm
;
681 struct hash_desc desc
;
682 static char output
[1024];
686 printk(KERN_INFO
"\ntesting speed of %s\n", algo
);
688 tfm
= crypto_alloc_hash(algo
, 0, CRYPTO_ALG_ASYNC
);
691 printk(KERN_ERR
"failed to load transform for %s: %ld\n", algo
,
699 if (crypto_hash_digestsize(tfm
) > sizeof(output
)) {
700 printk(KERN_ERR
"digestsize(%u) > outputbuffer(%zu)\n",
701 crypto_hash_digestsize(tfm
), sizeof(output
));
705 test_hash_sg_init(sg
);
706 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
707 if (speed
[i
].blen
> TVMEMSIZE
* PAGE_SIZE
) {
709 "template (%u) too big for tvmem (%lu)\n",
710 speed
[i
].blen
, TVMEMSIZE
* PAGE_SIZE
);
715 crypto_hash_setkey(tfm
, tvmem
[0], speed
[i
].klen
);
717 printk(KERN_INFO
"test%3u "
718 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
719 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
722 ret
= test_hash_jiffies(&desc
, sg
, speed
[i
].blen
,
723 speed
[i
].plen
, output
, sec
);
725 ret
= test_hash_cycles(&desc
, sg
, speed
[i
].blen
,
726 speed
[i
].plen
, output
);
729 printk(KERN_ERR
"hashing failed ret=%d\n", ret
);
735 crypto_free_hash(tfm
);
738 struct tcrypt_result
{
739 struct completion completion
;
743 static void tcrypt_complete(struct crypto_async_request
*req
, int err
)
745 struct tcrypt_result
*res
= req
->data
;
747 if (err
== -EINPROGRESS
)
751 complete(&res
->completion
);
754 static inline int do_one_ahash_op(struct ahash_request
*req
, int ret
)
756 if (ret
== -EINPROGRESS
|| ret
== -EBUSY
) {
757 struct tcrypt_result
*tr
= req
->base
.data
;
759 ret
= wait_for_completion_interruptible(&tr
->completion
);
762 reinit_completion(&tr
->completion
);
767 static int test_ahash_jiffies_digest(struct ahash_request
*req
, int blen
,
770 unsigned long start
, end
;
774 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
775 time_before(jiffies
, end
); bcount
++) {
776 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
781 printk("%6u opers/sec, %9lu bytes/sec\n",
782 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
787 static int test_ahash_jiffies(struct ahash_request
*req
, int blen
,
788 int plen
, char *out
, int sec
)
790 unsigned long start
, end
;
795 return test_ahash_jiffies_digest(req
, blen
, out
, sec
);
797 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
798 time_before(jiffies
, end
); bcount
++) {
799 ret
= crypto_ahash_init(req
);
802 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
803 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
807 /* we assume there is enough space in 'out' for the result */
808 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
813 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
814 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
819 static int test_ahash_cycles_digest(struct ahash_request
*req
, int blen
,
822 unsigned long cycles
= 0;
826 for (i
= 0; i
< 4; i
++) {
827 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
832 /* The real thing. */
833 for (i
= 0; i
< 8; i
++) {
836 start
= get_cycles();
838 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
844 cycles
+= end
- start
;
851 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
852 cycles
/ 8, cycles
/ (8 * blen
));
857 static int test_ahash_cycles(struct ahash_request
*req
, int blen
,
860 unsigned long cycles
= 0;
864 return test_ahash_cycles_digest(req
, blen
, out
);
867 for (i
= 0; i
< 4; i
++) {
868 ret
= crypto_ahash_init(req
);
871 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
872 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
876 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
881 /* The real thing. */
882 for (i
= 0; i
< 8; i
++) {
885 start
= get_cycles();
887 ret
= crypto_ahash_init(req
);
890 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
891 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
895 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
901 cycles
+= end
- start
;
908 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
909 cycles
/ 8, cycles
/ (8 * blen
));
914 static void test_ahash_speed(const char *algo
, unsigned int sec
,
915 struct hash_speed
*speed
)
917 struct scatterlist sg
[TVMEMSIZE
];
918 struct tcrypt_result tresult
;
919 struct ahash_request
*req
;
920 struct crypto_ahash
*tfm
;
921 static char output
[1024];
924 printk(KERN_INFO
"\ntesting speed of async %s\n", algo
);
926 tfm
= crypto_alloc_ahash(algo
, 0, 0);
928 pr_err("failed to load transform for %s: %ld\n",
933 if (crypto_ahash_digestsize(tfm
) > sizeof(output
)) {
934 pr_err("digestsize(%u) > outputbuffer(%zu)\n",
935 crypto_ahash_digestsize(tfm
), sizeof(output
));
939 test_hash_sg_init(sg
);
940 req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
942 pr_err("ahash request allocation failure\n");
946 init_completion(&tresult
.completion
);
947 ahash_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
948 tcrypt_complete
, &tresult
);
950 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
951 if (speed
[i
].blen
> TVMEMSIZE
* PAGE_SIZE
) {
952 pr_err("template (%u) too big for tvmem (%lu)\n",
953 speed
[i
].blen
, TVMEMSIZE
* PAGE_SIZE
);
958 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
959 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
961 ahash_request_set_crypt(req
, sg
, output
, speed
[i
].plen
);
964 ret
= test_ahash_jiffies(req
, speed
[i
].blen
,
965 speed
[i
].plen
, output
, sec
);
967 ret
= test_ahash_cycles(req
, speed
[i
].blen
,
968 speed
[i
].plen
, output
);
971 pr_err("hashing failed ret=%d\n", ret
);
976 ahash_request_free(req
);
979 crypto_free_ahash(tfm
);
982 static inline int do_one_acipher_op(struct ablkcipher_request
*req
, int ret
)
984 if (ret
== -EINPROGRESS
|| ret
== -EBUSY
) {
985 struct tcrypt_result
*tr
= req
->base
.data
;
987 ret
= wait_for_completion_interruptible(&tr
->completion
);
990 reinit_completion(&tr
->completion
);
996 static int test_acipher_jiffies(struct ablkcipher_request
*req
, int enc
,
999 unsigned long start
, end
;
1003 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
1004 time_before(jiffies
, end
); bcount
++) {
1006 ret
= do_one_acipher_op(req
,
1007 crypto_ablkcipher_encrypt(req
));
1009 ret
= do_one_acipher_op(req
,
1010 crypto_ablkcipher_decrypt(req
));
1016 pr_cont("%d operations in %d seconds (%ld bytes)\n",
1017 bcount
, sec
, (long)bcount
* blen
);
1021 static int test_acipher_cycles(struct ablkcipher_request
*req
, int enc
,
1024 unsigned long cycles
= 0;
1029 for (i
= 0; i
< 4; i
++) {
1031 ret
= do_one_acipher_op(req
,
1032 crypto_ablkcipher_encrypt(req
));
1034 ret
= do_one_acipher_op(req
,
1035 crypto_ablkcipher_decrypt(req
));
1041 /* The real thing. */
1042 for (i
= 0; i
< 8; i
++) {
1043 cycles_t start
, end
;
1045 start
= get_cycles();
1047 ret
= do_one_acipher_op(req
,
1048 crypto_ablkcipher_encrypt(req
));
1050 ret
= do_one_acipher_op(req
,
1051 crypto_ablkcipher_decrypt(req
));
1057 cycles
+= end
- start
;
1062 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1063 (cycles
+ 4) / 8, blen
);
1068 static void test_acipher_speed(const char *algo
, int enc
, unsigned int sec
,
1069 struct cipher_speed_template
*template,
1070 unsigned int tcount
, u8
*keysize
)
1072 unsigned int ret
, i
, j
, k
, iv_len
;
1073 struct tcrypt_result tresult
;
1076 struct ablkcipher_request
*req
;
1077 struct crypto_ablkcipher
*tfm
;
1086 pr_info("\ntesting speed of async %s %s\n", algo
, e
);
1088 init_completion(&tresult
.completion
);
1090 tfm
= crypto_alloc_ablkcipher(algo
, 0, 0);
1093 pr_err("failed to load transform for %s: %ld\n", algo
,
1098 req
= ablkcipher_request_alloc(tfm
, GFP_KERNEL
);
1100 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1105 ablkcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
1106 tcrypt_complete
, &tresult
);
1110 b_size
= block_sizes
;
1113 struct scatterlist sg
[TVMEMSIZE
];
1115 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
1116 pr_err("template (%u) too big for "
1117 "tvmem (%lu)\n", *keysize
+ *b_size
,
1118 TVMEMSIZE
* PAGE_SIZE
);
1122 pr_info("test %u (%d bit key, %d byte blocks): ", i
,
1123 *keysize
* 8, *b_size
);
1125 memset(tvmem
[0], 0xff, PAGE_SIZE
);
1127 /* set key, plain text and IV */
1129 for (j
= 0; j
< tcount
; j
++) {
1130 if (template[j
].klen
== *keysize
) {
1131 key
= template[j
].key
;
1136 crypto_ablkcipher_clear_flags(tfm
, ~0);
1138 ret
= crypto_ablkcipher_setkey(tfm
, key
, *keysize
);
1140 pr_err("setkey() failed flags=%x\n",
1141 crypto_ablkcipher_get_flags(tfm
));
1145 sg_init_table(sg
, TVMEMSIZE
);
1147 k
= *keysize
+ *b_size
;
1148 if (k
> PAGE_SIZE
) {
1149 sg_set_buf(sg
, tvmem
[0] + *keysize
,
1150 PAGE_SIZE
- *keysize
);
1153 while (k
> PAGE_SIZE
) {
1154 sg_set_buf(sg
+ j
, tvmem
[j
], PAGE_SIZE
);
1155 memset(tvmem
[j
], 0xff, PAGE_SIZE
);
1159 sg_set_buf(sg
+ j
, tvmem
[j
], k
);
1160 memset(tvmem
[j
], 0xff, k
);
1162 sg_set_buf(sg
, tvmem
[0] + *keysize
, *b_size
);
1165 iv_len
= crypto_ablkcipher_ivsize(tfm
);
1167 memset(&iv
, 0xff, iv_len
);
1169 ablkcipher_request_set_crypt(req
, sg
, sg
, *b_size
, iv
);
1172 ret
= test_acipher_jiffies(req
, enc
,
1175 ret
= test_acipher_cycles(req
, enc
,
1179 pr_err("%s() failed flags=%x\n", e
,
1180 crypto_ablkcipher_get_flags(tfm
));
1190 ablkcipher_request_free(req
);
1192 crypto_free_ablkcipher(tfm
);
1195 static void test_available(void)
1197 char **name
= check
;
1200 printk("alg %s ", *name
);
1201 printk(crypto_has_alg(*name
, 0, 0) ?
1202 "found\n" : "not found\n");
1207 static inline int tcrypt_test(const char *alg
)
1211 ret
= alg_test(alg
, alg
, 0, 0);
1212 /* non-fips algs return -EINVAL in fips mode */
1213 if (fips_enabled
&& ret
== -EINVAL
)
1218 static int do_test(int m
)
1225 for (i
= 1; i
< 200; i
++)
1230 ret
+= tcrypt_test("md5");
1234 ret
+= tcrypt_test("sha1");
1238 ret
+= tcrypt_test("ecb(des)");
1239 ret
+= tcrypt_test("cbc(des)");
1240 ret
+= tcrypt_test("ctr(des)");
1244 ret
+= tcrypt_test("ecb(des3_ede)");
1245 ret
+= tcrypt_test("cbc(des3_ede)");
1246 ret
+= tcrypt_test("ctr(des3_ede)");
1250 ret
+= tcrypt_test("md4");
1254 ret
+= tcrypt_test("sha256");
1258 ret
+= tcrypt_test("ecb(blowfish)");
1259 ret
+= tcrypt_test("cbc(blowfish)");
1260 ret
+= tcrypt_test("ctr(blowfish)");
1264 ret
+= tcrypt_test("ecb(twofish)");
1265 ret
+= tcrypt_test("cbc(twofish)");
1266 ret
+= tcrypt_test("ctr(twofish)");
1267 ret
+= tcrypt_test("lrw(twofish)");
1268 ret
+= tcrypt_test("xts(twofish)");
1272 ret
+= tcrypt_test("ecb(serpent)");
1273 ret
+= tcrypt_test("cbc(serpent)");
1274 ret
+= tcrypt_test("ctr(serpent)");
1275 ret
+= tcrypt_test("lrw(serpent)");
1276 ret
+= tcrypt_test("xts(serpent)");
1280 ret
+= tcrypt_test("ecb(aes)");
1281 ret
+= tcrypt_test("cbc(aes)");
1282 ret
+= tcrypt_test("lrw(aes)");
1283 ret
+= tcrypt_test("xts(aes)");
1284 ret
+= tcrypt_test("ctr(aes)");
1285 ret
+= tcrypt_test("rfc3686(ctr(aes))");
1289 ret
+= tcrypt_test("sha384");
1293 ret
+= tcrypt_test("sha512");
1297 ret
+= tcrypt_test("deflate");
1301 ret
+= tcrypt_test("ecb(cast5)");
1302 ret
+= tcrypt_test("cbc(cast5)");
1303 ret
+= tcrypt_test("ctr(cast5)");
1307 ret
+= tcrypt_test("ecb(cast6)");
1308 ret
+= tcrypt_test("cbc(cast6)");
1309 ret
+= tcrypt_test("ctr(cast6)");
1310 ret
+= tcrypt_test("lrw(cast6)");
1311 ret
+= tcrypt_test("xts(cast6)");
1315 ret
+= tcrypt_test("ecb(arc4)");
1319 ret
+= tcrypt_test("michael_mic");
1323 ret
+= tcrypt_test("crc32c");
1327 ret
+= tcrypt_test("ecb(tea)");
1331 ret
+= tcrypt_test("ecb(xtea)");
1335 ret
+= tcrypt_test("ecb(khazad)");
1339 ret
+= tcrypt_test("wp512");
1343 ret
+= tcrypt_test("wp384");
1347 ret
+= tcrypt_test("wp256");
1351 ret
+= tcrypt_test("ecb(tnepres)");
1355 ret
+= tcrypt_test("ecb(anubis)");
1356 ret
+= tcrypt_test("cbc(anubis)");
1360 ret
+= tcrypt_test("tgr192");
1364 ret
+= tcrypt_test("tgr160");
1368 ret
+= tcrypt_test("tgr128");
1372 ret
+= tcrypt_test("ecb(xeta)");
1376 ret
+= tcrypt_test("pcbc(fcrypt)");
1380 ret
+= tcrypt_test("ecb(camellia)");
1381 ret
+= tcrypt_test("cbc(camellia)");
1382 ret
+= tcrypt_test("ctr(camellia)");
1383 ret
+= tcrypt_test("lrw(camellia)");
1384 ret
+= tcrypt_test("xts(camellia)");
1388 ret
+= tcrypt_test("sha224");
1392 ret
+= tcrypt_test("salsa20");
1396 ret
+= tcrypt_test("gcm(aes)");
1400 ret
+= tcrypt_test("lzo");
1404 ret
+= tcrypt_test("ccm(aes)");
1408 ret
+= tcrypt_test("cts(cbc(aes))");
1412 ret
+= tcrypt_test("rmd128");
1416 ret
+= tcrypt_test("rmd160");
1420 ret
+= tcrypt_test("rmd256");
1424 ret
+= tcrypt_test("rmd320");
1428 ret
+= tcrypt_test("ecb(seed)");
1432 ret
+= tcrypt_test("zlib");
1436 ret
+= tcrypt_test("rfc4309(ccm(aes))");
1440 ret
+= tcrypt_test("ghash");
1444 ret
+= tcrypt_test("crct10dif");
1448 ret
+= tcrypt_test("hmac(md5)");
1452 ret
+= tcrypt_test("hmac(sha1)");
1456 ret
+= tcrypt_test("hmac(sha256)");
1460 ret
+= tcrypt_test("hmac(sha384)");
1464 ret
+= tcrypt_test("hmac(sha512)");
1468 ret
+= tcrypt_test("hmac(sha224)");
1472 ret
+= tcrypt_test("xcbc(aes)");
1476 ret
+= tcrypt_test("hmac(rmd128)");
1480 ret
+= tcrypt_test("hmac(rmd160)");
1484 ret
+= tcrypt_test("vmac(aes)");
1488 ret
+= tcrypt_test("hmac(crc32)");
1492 ret
+= tcrypt_test("ansi_cprng");
1496 ret
+= tcrypt_test("rfc4106(gcm(aes))");
1500 ret
+= tcrypt_test("rfc4543(gcm(aes))");
1504 ret
+= tcrypt_test("cmac(aes)");
1508 ret
+= tcrypt_test("cmac(des3_ede)");
1512 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1516 ret
+= tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1520 ret
+= tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1523 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(des))");
1526 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
1529 ret
+= tcrypt_test("authenc(hmac(sha224),cbc(des))");
1532 ret
+= tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
1535 ret
+= tcrypt_test("authenc(hmac(sha256),cbc(des))");
1538 ret
+= tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
1541 ret
+= tcrypt_test("authenc(hmac(sha384),cbc(des))");
1544 ret
+= tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
1547 ret
+= tcrypt_test("authenc(hmac(sha512),cbc(des))");
1550 ret
+= tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
1553 test_cipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1554 speed_template_16_24_32
);
1555 test_cipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1556 speed_template_16_24_32
);
1557 test_cipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1558 speed_template_16_24_32
);
1559 test_cipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1560 speed_template_16_24_32
);
1561 test_cipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1562 speed_template_32_40_48
);
1563 test_cipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1564 speed_template_32_40_48
);
1565 test_cipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1566 speed_template_32_48_64
);
1567 test_cipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1568 speed_template_32_48_64
);
1569 test_cipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
1570 speed_template_16_24_32
);
1571 test_cipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
1572 speed_template_16_24_32
);
1576 test_cipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1577 des3_speed_template
, DES3_SPEED_VECTORS
,
1579 test_cipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1580 des3_speed_template
, DES3_SPEED_VECTORS
,
1582 test_cipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1583 des3_speed_template
, DES3_SPEED_VECTORS
,
1585 test_cipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1586 des3_speed_template
, DES3_SPEED_VECTORS
,
1591 test_cipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1592 speed_template_16_24_32
);
1593 test_cipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1594 speed_template_16_24_32
);
1595 test_cipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1596 speed_template_16_24_32
);
1597 test_cipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1598 speed_template_16_24_32
);
1599 test_cipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
1600 speed_template_16_24_32
);
1601 test_cipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
1602 speed_template_16_24_32
);
1603 test_cipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
1604 speed_template_32_40_48
);
1605 test_cipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
1606 speed_template_32_40_48
);
1607 test_cipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
1608 speed_template_32_48_64
);
1609 test_cipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
1610 speed_template_32_48_64
);
1614 test_cipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1615 speed_template_8_32
);
1616 test_cipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
1617 speed_template_8_32
);
1618 test_cipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1619 speed_template_8_32
);
1620 test_cipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
1621 speed_template_8_32
);
1622 test_cipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1623 speed_template_8_32
);
1624 test_cipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
1625 speed_template_8_32
);
1629 test_cipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1631 test_cipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1633 test_cipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1635 test_cipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1640 test_cipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
1641 speed_template_16_24_32
);
1642 test_cipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
1643 speed_template_16_24_32
);
1644 test_cipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
1645 speed_template_16_24_32
);
1646 test_cipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
1647 speed_template_16_24_32
);
1648 test_cipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
1649 speed_template_16_24_32
);
1650 test_cipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
1651 speed_template_16_24_32
);
1652 test_cipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
1653 speed_template_32_40_48
);
1654 test_cipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
1655 speed_template_32_40_48
);
1656 test_cipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
1657 speed_template_32_48_64
);
1658 test_cipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
1659 speed_template_32_48_64
);
1663 test_cipher_speed("salsa20", ENCRYPT
, sec
, NULL
, 0,
1664 speed_template_16_32
);
1668 test_cipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
1669 speed_template_16_32
);
1670 test_cipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
1671 speed_template_16_32
);
1672 test_cipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
1673 speed_template_16_32
);
1674 test_cipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
1675 speed_template_16_32
);
1676 test_cipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
1677 speed_template_16_32
);
1678 test_cipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
1679 speed_template_16_32
);
1680 test_cipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
1681 speed_template_32_48
);
1682 test_cipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
1683 speed_template_32_48
);
1684 test_cipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
1685 speed_template_32_64
);
1686 test_cipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
1687 speed_template_32_64
);
1691 test_cipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
1696 test_cipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
1697 speed_template_8_16
);
1698 test_cipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
1699 speed_template_8_16
);
1700 test_cipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
1701 speed_template_8_16
);
1702 test_cipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
1703 speed_template_8_16
);
1704 test_cipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
1705 speed_template_8_16
);
1706 test_cipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
1707 speed_template_8_16
);
1711 test_cipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
1712 speed_template_16_32
);
1713 test_cipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
1714 speed_template_16_32
);
1715 test_cipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
1716 speed_template_16_32
);
1717 test_cipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
1718 speed_template_16_32
);
1719 test_cipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
1720 speed_template_16_32
);
1721 test_cipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
1722 speed_template_16_32
);
1723 test_cipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
1724 speed_template_32_48
);
1725 test_cipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
1726 speed_template_32_48
);
1727 test_cipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
1728 speed_template_32_64
);
1729 test_cipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
1730 speed_template_32_64
);
1734 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT
, sec
,
1735 NULL
, 0, 16, 8, aead_speed_template_20
);
1742 test_hash_speed("md4", sec
, generic_hash_speed_template
);
1743 if (mode
> 300 && mode
< 400) break;
1746 test_hash_speed("md5", sec
, generic_hash_speed_template
);
1747 if (mode
> 300 && mode
< 400) break;
1750 test_hash_speed("sha1", sec
, generic_hash_speed_template
);
1751 if (mode
> 300 && mode
< 400) break;
1754 test_hash_speed("sha256", sec
, generic_hash_speed_template
);
1755 if (mode
> 300 && mode
< 400) break;
1758 test_hash_speed("sha384", sec
, generic_hash_speed_template
);
1759 if (mode
> 300 && mode
< 400) break;
1762 test_hash_speed("sha512", sec
, generic_hash_speed_template
);
1763 if (mode
> 300 && mode
< 400) break;
1766 test_hash_speed("wp256", sec
, generic_hash_speed_template
);
1767 if (mode
> 300 && mode
< 400) break;
1770 test_hash_speed("wp384", sec
, generic_hash_speed_template
);
1771 if (mode
> 300 && mode
< 400) break;
1774 test_hash_speed("wp512", sec
, generic_hash_speed_template
);
1775 if (mode
> 300 && mode
< 400) break;
1778 test_hash_speed("tgr128", sec
, generic_hash_speed_template
);
1779 if (mode
> 300 && mode
< 400) break;
1782 test_hash_speed("tgr160", sec
, generic_hash_speed_template
);
1783 if (mode
> 300 && mode
< 400) break;
1786 test_hash_speed("tgr192", sec
, generic_hash_speed_template
);
1787 if (mode
> 300 && mode
< 400) break;
1790 test_hash_speed("sha224", sec
, generic_hash_speed_template
);
1791 if (mode
> 300 && mode
< 400) break;
1794 test_hash_speed("rmd128", sec
, generic_hash_speed_template
);
1795 if (mode
> 300 && mode
< 400) break;
1798 test_hash_speed("rmd160", sec
, generic_hash_speed_template
);
1799 if (mode
> 300 && mode
< 400) break;
1802 test_hash_speed("rmd256", sec
, generic_hash_speed_template
);
1803 if (mode
> 300 && mode
< 400) break;
1806 test_hash_speed("rmd320", sec
, generic_hash_speed_template
);
1807 if (mode
> 300 && mode
< 400) break;
1810 test_hash_speed("ghash-generic", sec
, hash_speed_template_16
);
1811 if (mode
> 300 && mode
< 400) break;
1814 test_hash_speed("crc32c", sec
, generic_hash_speed_template
);
1815 if (mode
> 300 && mode
< 400) break;
1818 test_hash_speed("crct10dif", sec
, generic_hash_speed_template
);
1819 if (mode
> 300 && mode
< 400) break;
1828 test_ahash_speed("md4", sec
, generic_hash_speed_template
);
1829 if (mode
> 400 && mode
< 500) break;
1832 test_ahash_speed("md5", sec
, generic_hash_speed_template
);
1833 if (mode
> 400 && mode
< 500) break;
1836 test_ahash_speed("sha1", sec
, generic_hash_speed_template
);
1837 if (mode
> 400 && mode
< 500) break;
1840 test_ahash_speed("sha256", sec
, generic_hash_speed_template
);
1841 if (mode
> 400 && mode
< 500) break;
1844 test_ahash_speed("sha384", sec
, generic_hash_speed_template
);
1845 if (mode
> 400 && mode
< 500) break;
1848 test_ahash_speed("sha512", sec
, generic_hash_speed_template
);
1849 if (mode
> 400 && mode
< 500) break;
1852 test_ahash_speed("wp256", sec
, generic_hash_speed_template
);
1853 if (mode
> 400 && mode
< 500) break;
1856 test_ahash_speed("wp384", sec
, generic_hash_speed_template
);
1857 if (mode
> 400 && mode
< 500) break;
1860 test_ahash_speed("wp512", sec
, generic_hash_speed_template
);
1861 if (mode
> 400 && mode
< 500) break;
1864 test_ahash_speed("tgr128", sec
, generic_hash_speed_template
);
1865 if (mode
> 400 && mode
< 500) break;
1868 test_ahash_speed("tgr160", sec
, generic_hash_speed_template
);
1869 if (mode
> 400 && mode
< 500) break;
1872 test_ahash_speed("tgr192", sec
, generic_hash_speed_template
);
1873 if (mode
> 400 && mode
< 500) break;
1876 test_ahash_speed("sha224", sec
, generic_hash_speed_template
);
1877 if (mode
> 400 && mode
< 500) break;
1880 test_ahash_speed("rmd128", sec
, generic_hash_speed_template
);
1881 if (mode
> 400 && mode
< 500) break;
1884 test_ahash_speed("rmd160", sec
, generic_hash_speed_template
);
1885 if (mode
> 400 && mode
< 500) break;
1888 test_ahash_speed("rmd256", sec
, generic_hash_speed_template
);
1889 if (mode
> 400 && mode
< 500) break;
1892 test_ahash_speed("rmd320", sec
, generic_hash_speed_template
);
1893 if (mode
> 400 && mode
< 500) break;
1899 test_acipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1900 speed_template_16_24_32
);
1901 test_acipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1902 speed_template_16_24_32
);
1903 test_acipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1904 speed_template_16_24_32
);
1905 test_acipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1906 speed_template_16_24_32
);
1907 test_acipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1908 speed_template_32_40_48
);
1909 test_acipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1910 speed_template_32_40_48
);
1911 test_acipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1912 speed_template_32_48_64
);
1913 test_acipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1914 speed_template_32_48_64
);
1915 test_acipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
1916 speed_template_16_24_32
);
1917 test_acipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
1918 speed_template_16_24_32
);
1919 test_acipher_speed("cfb(aes)", ENCRYPT
, sec
, NULL
, 0,
1920 speed_template_16_24_32
);
1921 test_acipher_speed("cfb(aes)", DECRYPT
, sec
, NULL
, 0,
1922 speed_template_16_24_32
);
1923 test_acipher_speed("ofb(aes)", ENCRYPT
, sec
, NULL
, 0,
1924 speed_template_16_24_32
);
1925 test_acipher_speed("ofb(aes)", DECRYPT
, sec
, NULL
, 0,
1926 speed_template_16_24_32
);
1927 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT
, sec
, NULL
, 0,
1928 speed_template_20_28_36
);
1929 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT
, sec
, NULL
, 0,
1930 speed_template_20_28_36
);
1934 test_acipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1935 des3_speed_template
, DES3_SPEED_VECTORS
,
1937 test_acipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1938 des3_speed_template
, DES3_SPEED_VECTORS
,
1940 test_acipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1941 des3_speed_template
, DES3_SPEED_VECTORS
,
1943 test_acipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1944 des3_speed_template
, DES3_SPEED_VECTORS
,
1946 test_acipher_speed("cfb(des3_ede)", ENCRYPT
, sec
,
1947 des3_speed_template
, DES3_SPEED_VECTORS
,
1949 test_acipher_speed("cfb(des3_ede)", DECRYPT
, sec
,
1950 des3_speed_template
, DES3_SPEED_VECTORS
,
1952 test_acipher_speed("ofb(des3_ede)", ENCRYPT
, sec
,
1953 des3_speed_template
, DES3_SPEED_VECTORS
,
1955 test_acipher_speed("ofb(des3_ede)", DECRYPT
, sec
,
1956 des3_speed_template
, DES3_SPEED_VECTORS
,
1961 test_acipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1963 test_acipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1965 test_acipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1967 test_acipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1969 test_acipher_speed("cfb(des)", ENCRYPT
, sec
, NULL
, 0,
1971 test_acipher_speed("cfb(des)", DECRYPT
, sec
, NULL
, 0,
1973 test_acipher_speed("ofb(des)", ENCRYPT
, sec
, NULL
, 0,
1975 test_acipher_speed("ofb(des)", DECRYPT
, sec
, NULL
, 0,
1980 test_acipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
1981 speed_template_16_32
);
1982 test_acipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
1983 speed_template_16_32
);
1984 test_acipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
1985 speed_template_16_32
);
1986 test_acipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
1987 speed_template_16_32
);
1988 test_acipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
1989 speed_template_16_32
);
1990 test_acipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
1991 speed_template_16_32
);
1992 test_acipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
1993 speed_template_32_48
);
1994 test_acipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
1995 speed_template_32_48
);
1996 test_acipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
1997 speed_template_32_64
);
1998 test_acipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
1999 speed_template_32_64
);
2003 test_acipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
2004 speed_template_16_24_32
);
2005 test_acipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
2006 speed_template_16_24_32
);
2007 test_acipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
2008 speed_template_16_24_32
);
2009 test_acipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
2010 speed_template_16_24_32
);
2011 test_acipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
2012 speed_template_16_24_32
);
2013 test_acipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
2014 speed_template_16_24_32
);
2015 test_acipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
2016 speed_template_32_40_48
);
2017 test_acipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
2018 speed_template_32_40_48
);
2019 test_acipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
2020 speed_template_32_48_64
);
2021 test_acipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
2022 speed_template_32_48_64
);
2026 test_acipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
2031 test_acipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
2032 speed_template_8_16
);
2033 test_acipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
2034 speed_template_8_16
);
2035 test_acipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
2036 speed_template_8_16
);
2037 test_acipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
2038 speed_template_8_16
);
2039 test_acipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
2040 speed_template_8_16
);
2041 test_acipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
2042 speed_template_8_16
);
2046 test_acipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
2047 speed_template_16_32
);
2048 test_acipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
2049 speed_template_16_32
);
2050 test_acipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
2051 speed_template_16_32
);
2052 test_acipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
2053 speed_template_16_32
);
2054 test_acipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
2055 speed_template_16_32
);
2056 test_acipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
2057 speed_template_16_32
);
2058 test_acipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
2059 speed_template_32_48
);
2060 test_acipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
2061 speed_template_32_48
);
2062 test_acipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
2063 speed_template_32_64
);
2064 test_acipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
2065 speed_template_32_64
);
2069 test_acipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
2070 speed_template_16_32
);
2071 test_acipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
2072 speed_template_16_32
);
2073 test_acipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
2074 speed_template_16_32
);
2075 test_acipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
2076 speed_template_16_32
);
2077 test_acipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
2078 speed_template_16_32
);
2079 test_acipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
2080 speed_template_16_32
);
2081 test_acipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
2082 speed_template_32_48
);
2083 test_acipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
2084 speed_template_32_48
);
2085 test_acipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
2086 speed_template_32_64
);
2087 test_acipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
2088 speed_template_32_64
);
2092 test_acipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2093 speed_template_8_32
);
2094 test_acipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
2095 speed_template_8_32
);
2096 test_acipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2097 speed_template_8_32
);
2098 test_acipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
2099 speed_template_8_32
);
2100 test_acipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2101 speed_template_8_32
);
2102 test_acipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
2103 speed_template_8_32
);
2114 static int do_alg_test(const char *alg
, u32 type
, u32 mask
)
2116 return crypto_has_alg(alg
, type
, mask
?: CRYPTO_ALG_TYPE_MASK
) ?
2120 static int __init
tcrypt_mod_init(void)
2125 for (i
= 0; i
< TVMEMSIZE
; i
++) {
2126 tvmem
[i
] = (void *)__get_free_page(GFP_KERNEL
);
2132 err
= do_alg_test(alg
, type
, mask
);
2134 err
= do_test(mode
);
2137 printk(KERN_ERR
"tcrypt: one or more tests failed!\n");
2141 /* We intentionaly return -EAGAIN to prevent keeping the module,
2142 * unless we're running in fips mode. It does all its work from
2143 * init() and doesn't offer any runtime functionality, but in
2144 * the fips case, checking for a successful load is helpful.
2145 * => we don't need it in the memory, do we?
2152 for (i
= 0; i
< TVMEMSIZE
&& tvmem
[i
]; i
++)
2153 free_page((unsigned long)tvmem
[i
]);
2159 * If an init function is provided, an exit function must also be provided
2160 * to allow module unload.
2162 static void __exit
tcrypt_mod_fini(void) { }
2164 module_init(tcrypt_mod_init
);
2165 module_exit(tcrypt_mod_fini
);
2167 module_param(alg
, charp
, 0);
2168 module_param(type
, uint
, 0);
2169 module_param(mask
, uint
, 0);
2170 module_param(mode
, int, 0);
2171 module_param(sec
, uint
, 0);
2172 MODULE_PARM_DESC(sec
, "Length in seconds of speed tests "
2173 "(defaults to zero which uses CPU cycles instead)");
2175 MODULE_LICENSE("GPL");
2176 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2177 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");