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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27 #include <crypto/aead.h>
28 #include <crypto/hash.h>
29 #include <crypto/skcipher.h>
30 #include <linux/err.h>
31 #include <linux/fips.h>
32 #include <linux/init.h>
33 #include <linux/gfp.h>
34 #include <linux/module.h>
35 #include <linux/scatterlist.h>
36 #include <linux/string.h>
37 #include <linux/moduleparam.h>
38 #include <linux/jiffies.h>
39 #include <linux/timex.h>
40 #include <linux/interrupt.h>
44 * Need slab memory for testing (size in number of pages).
49 * Used by test_cipher_speed()
54 #define MAX_DIGEST_SIZE 64
57 * return a string with the driver name
59 #define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm))
62 * Used by test_cipher_speed()
64 static unsigned int sec
;
66 static char *alg
= NULL
;
70 static char *tvmem
[TVMEMSIZE
];
72 static char *check
[] = {
73 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", "sm3",
74 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
75 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
76 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
77 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
78 "lzo", "cts", "zlib", "sha3-224", "sha3-256", "sha3-384", "sha3-512",
82 static inline int do_one_aead_op(struct aead_request
*req
, int ret
)
84 struct crypto_wait
*wait
= req
->base
.data
;
86 return crypto_wait_req(ret
, wait
);
89 static int test_aead_jiffies(struct aead_request
*req
, int enc
,
92 unsigned long start
, end
;
96 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
97 time_before(jiffies
, end
); bcount
++) {
99 ret
= do_one_aead_op(req
, crypto_aead_encrypt(req
));
101 ret
= do_one_aead_op(req
, crypto_aead_decrypt(req
));
107 printk("%d operations in %d seconds (%ld bytes)\n",
108 bcount
, secs
, (long)bcount
* blen
);
112 static int test_aead_cycles(struct aead_request
*req
, int enc
, int blen
)
114 unsigned long cycles
= 0;
119 for (i
= 0; i
< 4; i
++) {
121 ret
= do_one_aead_op(req
, crypto_aead_encrypt(req
));
123 ret
= do_one_aead_op(req
, crypto_aead_decrypt(req
));
129 /* The real thing. */
130 for (i
= 0; i
< 8; i
++) {
133 start
= get_cycles();
135 ret
= do_one_aead_op(req
, crypto_aead_encrypt(req
));
137 ret
= do_one_aead_op(req
, crypto_aead_decrypt(req
));
143 cycles
+= end
- start
;
148 printk("1 operation in %lu cycles (%d bytes)\n",
149 (cycles
+ 4) / 8, blen
);
154 static u32 block_sizes
[] = { 16, 64, 256, 1024, 8192, 0 };
155 static u32 aead_sizes
[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
160 static int testmgr_alloc_buf(char *buf
[XBUFSIZE
])
164 for (i
= 0; i
< XBUFSIZE
; i
++) {
165 buf
[i
] = (void *)__get_free_page(GFP_KERNEL
);
174 free_page((unsigned long)buf
[i
]);
179 static void testmgr_free_buf(char *buf
[XBUFSIZE
])
183 for (i
= 0; i
< XBUFSIZE
; i
++)
184 free_page((unsigned long)buf
[i
]);
187 static void sg_init_aead(struct scatterlist
*sg
, char *xbuf
[XBUFSIZE
],
190 int np
= (buflen
+ PAGE_SIZE
- 1)/PAGE_SIZE
;
197 rem
= buflen
% PAGE_SIZE
;
200 sg_init_table(sg
, np
+ 1);
203 for (k
= 0; k
< np
; k
++)
204 sg_set_buf(&sg
[k
+ 1], xbuf
[k
], PAGE_SIZE
);
207 sg_set_buf(&sg
[k
+ 1], xbuf
[k
], rem
);
210 static void test_aead_speed(const char *algo
, int enc
, unsigned int secs
,
211 struct aead_speed_template
*template,
212 unsigned int tcount
, u8 authsize
,
213 unsigned int aad_size
, u8
*keysize
)
216 struct crypto_aead
*tfm
;
219 struct aead_request
*req
;
220 struct scatterlist
*sg
;
221 struct scatterlist
*sgout
;
225 char *xbuf
[XBUFSIZE
];
226 char *xoutbuf
[XBUFSIZE
];
227 char *axbuf
[XBUFSIZE
];
228 unsigned int *b_size
;
230 struct crypto_wait wait
;
232 iv
= kzalloc(MAX_IVLEN
, GFP_KERNEL
);
236 if (aad_size
>= PAGE_SIZE
) {
237 pr_err("associate data length (%u) too big\n", aad_size
);
246 if (testmgr_alloc_buf(xbuf
))
248 if (testmgr_alloc_buf(axbuf
))
250 if (testmgr_alloc_buf(xoutbuf
))
253 sg
= kmalloc(sizeof(*sg
) * 9 * 2, GFP_KERNEL
);
258 tfm
= crypto_alloc_aead(algo
, 0, 0);
261 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo
,
266 crypto_init_wait(&wait
);
267 printk(KERN_INFO
"\ntesting speed of %s (%s) %s\n", algo
,
268 get_driver_name(crypto_aead
, tfm
), e
);
270 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
272 pr_err("alg: aead: Failed to allocate request for %s\n",
277 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
278 crypto_req_done
, &wait
);
285 memset(assoc
, 0xff, aad_size
);
287 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
288 pr_err("template (%u) too big for tvmem (%lu)\n",
290 TVMEMSIZE
* PAGE_SIZE
);
295 for (j
= 0; j
< tcount
; j
++) {
296 if (template[j
].klen
== *keysize
) {
297 key
= template[j
].key
;
301 ret
= crypto_aead_setkey(tfm
, key
, *keysize
);
302 ret
= crypto_aead_setauthsize(tfm
, authsize
);
304 iv_len
= crypto_aead_ivsize(tfm
);
306 memset(iv
, 0xff, iv_len
);
308 crypto_aead_clear_flags(tfm
, ~0);
309 printk(KERN_INFO
"test %u (%d bit key, %d byte blocks): ",
310 i
, *keysize
* 8, *b_size
);
313 memset(tvmem
[0], 0xff, PAGE_SIZE
);
316 pr_err("setkey() failed flags=%x\n",
317 crypto_aead_get_flags(tfm
));
321 sg_init_aead(sg
, xbuf
,
322 *b_size
+ (enc
? 0 : authsize
));
324 sg_init_aead(sgout
, xoutbuf
,
325 *b_size
+ (enc
? authsize
: 0));
327 sg_set_buf(&sg
[0], assoc
, aad_size
);
328 sg_set_buf(&sgout
[0], assoc
, aad_size
);
330 aead_request_set_crypt(req
, sg
, sgout
,
331 *b_size
+ (enc
? 0 : authsize
),
333 aead_request_set_ad(req
, aad_size
);
336 ret
= test_aead_jiffies(req
, enc
, *b_size
,
339 ret
= test_aead_cycles(req
, enc
, *b_size
);
342 pr_err("%s() failed return code=%d\n", e
, ret
);
352 aead_request_free(req
);
354 crypto_free_aead(tfm
);
358 testmgr_free_buf(xoutbuf
);
360 testmgr_free_buf(axbuf
);
362 testmgr_free_buf(xbuf
);
367 static void test_hash_sg_init(struct scatterlist
*sg
)
371 sg_init_table(sg
, TVMEMSIZE
);
372 for (i
= 0; i
< TVMEMSIZE
; i
++) {
373 sg_set_buf(sg
+ i
, tvmem
[i
], PAGE_SIZE
);
374 memset(tvmem
[i
], 0xff, PAGE_SIZE
);
378 static inline int do_one_ahash_op(struct ahash_request
*req
, int ret
)
380 struct crypto_wait
*wait
= req
->base
.data
;
382 return crypto_wait_req(ret
, wait
);
385 struct test_mb_ahash_data
{
386 struct scatterlist sg
[TVMEMSIZE
];
388 struct ahash_request
*req
;
389 struct crypto_wait wait
;
390 char *xbuf
[XBUFSIZE
];
393 static void test_mb_ahash_speed(const char *algo
, unsigned int sec
,
394 struct hash_speed
*speed
)
396 struct test_mb_ahash_data
*data
;
397 struct crypto_ahash
*tfm
;
398 unsigned long start
, end
;
399 unsigned long cycles
;
400 unsigned int i
, j
, k
;
403 data
= kzalloc(sizeof(*data
) * 8, GFP_KERNEL
);
407 tfm
= crypto_alloc_ahash(algo
, 0, 0);
409 pr_err("failed to load transform for %s: %ld\n",
414 for (i
= 0; i
< 8; ++i
) {
415 if (testmgr_alloc_buf(data
[i
].xbuf
))
418 crypto_init_wait(&data
[i
].wait
);
420 data
[i
].req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
422 pr_err("alg: hash: Failed to allocate request for %s\n",
427 ahash_request_set_callback(data
[i
].req
, 0, crypto_req_done
,
429 test_hash_sg_init(data
[i
].sg
);
432 pr_info("\ntesting speed of multibuffer %s (%s)\n", algo
,
433 get_driver_name(crypto_ahash
, tfm
));
435 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
436 /* For some reason this only tests digests. */
437 if (speed
[i
].blen
!= speed
[i
].plen
)
440 if (speed
[i
].blen
> TVMEMSIZE
* PAGE_SIZE
) {
441 pr_err("template (%u) too big for tvmem (%lu)\n",
442 speed
[i
].blen
, TVMEMSIZE
* PAGE_SIZE
);
447 crypto_ahash_setkey(tfm
, tvmem
[0], speed
[i
].klen
);
449 for (k
= 0; k
< 8; k
++)
450 ahash_request_set_crypt(data
[k
].req
, data
[k
].sg
,
451 data
[k
].result
, speed
[i
].blen
);
454 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
455 i
, speed
[i
].blen
, speed
[i
].plen
,
456 speed
[i
].blen
/ speed
[i
].plen
);
458 start
= get_cycles();
460 for (k
= 0; k
< 8; k
++) {
461 ret
= crypto_ahash_digest(data
[k
].req
);
462 if (ret
== -EINPROGRESS
) {
470 crypto_req_done(&data
[k
].req
->base
, 0);
473 for (j
= 0; j
< k
; j
++) {
474 struct crypto_wait
*wait
= &data
[j
].wait
;
477 wait_ret
= crypto_wait_req(-EINPROGRESS
, wait
);
483 cycles
= end
- start
;
484 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
485 cycles
, cycles
/ (8 * speed
[i
].blen
));
488 pr_err("At least one hashing failed ret=%d\n", ret
);
494 for (k
= 0; k
< 8; ++k
)
495 ahash_request_free(data
[k
].req
);
497 for (k
= 0; k
< 8; ++k
)
498 testmgr_free_buf(data
[k
].xbuf
);
500 crypto_free_ahash(tfm
);
506 static int test_ahash_jiffies_digest(struct ahash_request
*req
, int blen
,
509 unsigned long start
, end
;
513 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
514 time_before(jiffies
, end
); bcount
++) {
515 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
520 printk("%6u opers/sec, %9lu bytes/sec\n",
521 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
526 static int test_ahash_jiffies(struct ahash_request
*req
, int blen
,
527 int plen
, char *out
, int secs
)
529 unsigned long start
, end
;
534 return test_ahash_jiffies_digest(req
, blen
, out
, secs
);
536 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
537 time_before(jiffies
, end
); bcount
++) {
538 ret
= do_one_ahash_op(req
, crypto_ahash_init(req
));
541 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
542 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
546 /* we assume there is enough space in 'out' for the result */
547 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
552 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
553 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
558 static int test_ahash_cycles_digest(struct ahash_request
*req
, int blen
,
561 unsigned long cycles
= 0;
565 for (i
= 0; i
< 4; i
++) {
566 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
571 /* The real thing. */
572 for (i
= 0; i
< 8; i
++) {
575 start
= get_cycles();
577 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
583 cycles
+= end
- start
;
590 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
591 cycles
/ 8, cycles
/ (8 * blen
));
596 static int test_ahash_cycles(struct ahash_request
*req
, int blen
,
599 unsigned long cycles
= 0;
603 return test_ahash_cycles_digest(req
, blen
, out
);
606 for (i
= 0; i
< 4; i
++) {
607 ret
= do_one_ahash_op(req
, crypto_ahash_init(req
));
610 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
611 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
615 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
620 /* The real thing. */
621 for (i
= 0; i
< 8; i
++) {
624 start
= get_cycles();
626 ret
= do_one_ahash_op(req
, crypto_ahash_init(req
));
629 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
630 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
634 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
640 cycles
+= end
- start
;
647 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
648 cycles
/ 8, cycles
/ (8 * blen
));
653 static void test_ahash_speed_common(const char *algo
, unsigned int secs
,
654 struct hash_speed
*speed
, unsigned mask
)
656 struct scatterlist sg
[TVMEMSIZE
];
657 struct crypto_wait wait
;
658 struct ahash_request
*req
;
659 struct crypto_ahash
*tfm
;
663 tfm
= crypto_alloc_ahash(algo
, 0, mask
);
665 pr_err("failed to load transform for %s: %ld\n",
670 printk(KERN_INFO
"\ntesting speed of async %s (%s)\n", algo
,
671 get_driver_name(crypto_ahash
, tfm
));
673 if (crypto_ahash_digestsize(tfm
) > MAX_DIGEST_SIZE
) {
674 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm
),
679 test_hash_sg_init(sg
);
680 req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
682 pr_err("ahash request allocation failure\n");
686 crypto_init_wait(&wait
);
687 ahash_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
688 crypto_req_done
, &wait
);
690 output
= kmalloc(MAX_DIGEST_SIZE
, GFP_KERNEL
);
694 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
695 if (speed
[i
].blen
> TVMEMSIZE
* PAGE_SIZE
) {
696 pr_err("template (%u) too big for tvmem (%lu)\n",
697 speed
[i
].blen
, TVMEMSIZE
* PAGE_SIZE
);
702 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
703 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
705 ahash_request_set_crypt(req
, sg
, output
, speed
[i
].plen
);
708 ret
= test_ahash_jiffies(req
, speed
[i
].blen
,
709 speed
[i
].plen
, output
, secs
);
711 ret
= test_ahash_cycles(req
, speed
[i
].blen
,
712 speed
[i
].plen
, output
);
715 pr_err("hashing failed ret=%d\n", ret
);
723 ahash_request_free(req
);
726 crypto_free_ahash(tfm
);
729 static void test_ahash_speed(const char *algo
, unsigned int secs
,
730 struct hash_speed
*speed
)
732 return test_ahash_speed_common(algo
, secs
, speed
, 0);
735 static void test_hash_speed(const char *algo
, unsigned int secs
,
736 struct hash_speed
*speed
)
738 return test_ahash_speed_common(algo
, secs
, speed
, CRYPTO_ALG_ASYNC
);
741 static inline int do_one_acipher_op(struct skcipher_request
*req
, int ret
)
743 struct crypto_wait
*wait
= req
->base
.data
;
745 return crypto_wait_req(ret
, wait
);
748 static int test_acipher_jiffies(struct skcipher_request
*req
, int enc
,
751 unsigned long start
, end
;
755 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
756 time_before(jiffies
, end
); bcount
++) {
758 ret
= do_one_acipher_op(req
,
759 crypto_skcipher_encrypt(req
));
761 ret
= do_one_acipher_op(req
,
762 crypto_skcipher_decrypt(req
));
768 pr_cont("%d operations in %d seconds (%ld bytes)\n",
769 bcount
, secs
, (long)bcount
* blen
);
773 static int test_acipher_cycles(struct skcipher_request
*req
, int enc
,
776 unsigned long cycles
= 0;
781 for (i
= 0; i
< 4; i
++) {
783 ret
= do_one_acipher_op(req
,
784 crypto_skcipher_encrypt(req
));
786 ret
= do_one_acipher_op(req
,
787 crypto_skcipher_decrypt(req
));
793 /* The real thing. */
794 for (i
= 0; i
< 8; i
++) {
797 start
= get_cycles();
799 ret
= do_one_acipher_op(req
,
800 crypto_skcipher_encrypt(req
));
802 ret
= do_one_acipher_op(req
,
803 crypto_skcipher_decrypt(req
));
809 cycles
+= end
- start
;
814 pr_cont("1 operation in %lu cycles (%d bytes)\n",
815 (cycles
+ 4) / 8, blen
);
820 static void test_skcipher_speed(const char *algo
, int enc
, unsigned int secs
,
821 struct cipher_speed_template
*template,
822 unsigned int tcount
, u8
*keysize
, bool async
)
824 unsigned int ret
, i
, j
, k
, iv_len
;
825 struct crypto_wait wait
;
828 struct skcipher_request
*req
;
829 struct crypto_skcipher
*tfm
;
838 crypto_init_wait(&wait
);
840 tfm
= crypto_alloc_skcipher(algo
, 0, async
? 0 : CRYPTO_ALG_ASYNC
);
843 pr_err("failed to load transform for %s: %ld\n", algo
,
848 pr_info("\ntesting speed of async %s (%s) %s\n", algo
,
849 get_driver_name(crypto_skcipher
, tfm
), e
);
851 req
= skcipher_request_alloc(tfm
, GFP_KERNEL
);
853 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
858 skcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
859 crypto_req_done
, &wait
);
863 b_size
= block_sizes
;
866 struct scatterlist sg
[TVMEMSIZE
];
868 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
869 pr_err("template (%u) too big for "
870 "tvmem (%lu)\n", *keysize
+ *b_size
,
871 TVMEMSIZE
* PAGE_SIZE
);
875 pr_info("test %u (%d bit key, %d byte blocks): ", i
,
876 *keysize
* 8, *b_size
);
878 memset(tvmem
[0], 0xff, PAGE_SIZE
);
880 /* set key, plain text and IV */
882 for (j
= 0; j
< tcount
; j
++) {
883 if (template[j
].klen
== *keysize
) {
884 key
= template[j
].key
;
889 crypto_skcipher_clear_flags(tfm
, ~0);
891 ret
= crypto_skcipher_setkey(tfm
, key
, *keysize
);
893 pr_err("setkey() failed flags=%x\n",
894 crypto_skcipher_get_flags(tfm
));
898 k
= *keysize
+ *b_size
;
899 sg_init_table(sg
, DIV_ROUND_UP(k
, PAGE_SIZE
));
902 sg_set_buf(sg
, tvmem
[0] + *keysize
,
903 PAGE_SIZE
- *keysize
);
906 while (k
> PAGE_SIZE
) {
907 sg_set_buf(sg
+ j
, tvmem
[j
], PAGE_SIZE
);
908 memset(tvmem
[j
], 0xff, PAGE_SIZE
);
912 sg_set_buf(sg
+ j
, tvmem
[j
], k
);
913 memset(tvmem
[j
], 0xff, k
);
915 sg_set_buf(sg
, tvmem
[0] + *keysize
, *b_size
);
918 iv_len
= crypto_skcipher_ivsize(tfm
);
920 memset(&iv
, 0xff, iv_len
);
922 skcipher_request_set_crypt(req
, sg
, sg
, *b_size
, iv
);
925 ret
= test_acipher_jiffies(req
, enc
,
928 ret
= test_acipher_cycles(req
, enc
,
932 pr_err("%s() failed flags=%x\n", e
,
933 crypto_skcipher_get_flags(tfm
));
943 skcipher_request_free(req
);
945 crypto_free_skcipher(tfm
);
948 static void test_acipher_speed(const char *algo
, int enc
, unsigned int secs
,
949 struct cipher_speed_template
*template,
950 unsigned int tcount
, u8
*keysize
)
952 return test_skcipher_speed(algo
, enc
, secs
, template, tcount
, keysize
,
956 static void test_cipher_speed(const char *algo
, int enc
, unsigned int secs
,
957 struct cipher_speed_template
*template,
958 unsigned int tcount
, u8
*keysize
)
960 return test_skcipher_speed(algo
, enc
, secs
, template, tcount
, keysize
,
964 static void test_available(void)
969 printk("alg %s ", *name
);
970 printk(crypto_has_alg(*name
, 0, 0) ?
971 "found\n" : "not found\n");
976 static inline int tcrypt_test(const char *alg
)
980 pr_debug("testing %s\n", alg
);
982 ret
= alg_test(alg
, alg
, 0, 0);
983 /* non-fips algs return -EINVAL in fips mode */
984 if (fips_enabled
&& ret
== -EINVAL
)
989 static int do_test(const char *alg
, u32 type
, u32 mask
, int m
)
997 if (!crypto_has_alg(alg
, type
,
998 mask
?: CRYPTO_ALG_TYPE_MASK
))
1003 for (i
= 1; i
< 200; i
++)
1004 ret
+= do_test(NULL
, 0, 0, i
);
1008 ret
+= tcrypt_test("md5");
1012 ret
+= tcrypt_test("sha1");
1016 ret
+= tcrypt_test("ecb(des)");
1017 ret
+= tcrypt_test("cbc(des)");
1018 ret
+= tcrypt_test("ctr(des)");
1022 ret
+= tcrypt_test("ecb(des3_ede)");
1023 ret
+= tcrypt_test("cbc(des3_ede)");
1024 ret
+= tcrypt_test("ctr(des3_ede)");
1028 ret
+= tcrypt_test("md4");
1032 ret
+= tcrypt_test("sha256");
1036 ret
+= tcrypt_test("ecb(blowfish)");
1037 ret
+= tcrypt_test("cbc(blowfish)");
1038 ret
+= tcrypt_test("ctr(blowfish)");
1042 ret
+= tcrypt_test("ecb(twofish)");
1043 ret
+= tcrypt_test("cbc(twofish)");
1044 ret
+= tcrypt_test("ctr(twofish)");
1045 ret
+= tcrypt_test("lrw(twofish)");
1046 ret
+= tcrypt_test("xts(twofish)");
1050 ret
+= tcrypt_test("ecb(serpent)");
1051 ret
+= tcrypt_test("cbc(serpent)");
1052 ret
+= tcrypt_test("ctr(serpent)");
1053 ret
+= tcrypt_test("lrw(serpent)");
1054 ret
+= tcrypt_test("xts(serpent)");
1058 ret
+= tcrypt_test("ecb(aes)");
1059 ret
+= tcrypt_test("cbc(aes)");
1060 ret
+= tcrypt_test("lrw(aes)");
1061 ret
+= tcrypt_test("xts(aes)");
1062 ret
+= tcrypt_test("ctr(aes)");
1063 ret
+= tcrypt_test("rfc3686(ctr(aes))");
1067 ret
+= tcrypt_test("sha384");
1071 ret
+= tcrypt_test("sha512");
1075 ret
+= tcrypt_test("deflate");
1079 ret
+= tcrypt_test("ecb(cast5)");
1080 ret
+= tcrypt_test("cbc(cast5)");
1081 ret
+= tcrypt_test("ctr(cast5)");
1085 ret
+= tcrypt_test("ecb(cast6)");
1086 ret
+= tcrypt_test("cbc(cast6)");
1087 ret
+= tcrypt_test("ctr(cast6)");
1088 ret
+= tcrypt_test("lrw(cast6)");
1089 ret
+= tcrypt_test("xts(cast6)");
1093 ret
+= tcrypt_test("ecb(arc4)");
1097 ret
+= tcrypt_test("michael_mic");
1101 ret
+= tcrypt_test("crc32c");
1105 ret
+= tcrypt_test("ecb(tea)");
1109 ret
+= tcrypt_test("ecb(xtea)");
1113 ret
+= tcrypt_test("ecb(khazad)");
1117 ret
+= tcrypt_test("wp512");
1121 ret
+= tcrypt_test("wp384");
1125 ret
+= tcrypt_test("wp256");
1129 ret
+= tcrypt_test("ecb(tnepres)");
1133 ret
+= tcrypt_test("ecb(anubis)");
1134 ret
+= tcrypt_test("cbc(anubis)");
1138 ret
+= tcrypt_test("tgr192");
1142 ret
+= tcrypt_test("tgr160");
1146 ret
+= tcrypt_test("tgr128");
1150 ret
+= tcrypt_test("ecb(xeta)");
1154 ret
+= tcrypt_test("pcbc(fcrypt)");
1158 ret
+= tcrypt_test("ecb(camellia)");
1159 ret
+= tcrypt_test("cbc(camellia)");
1160 ret
+= tcrypt_test("ctr(camellia)");
1161 ret
+= tcrypt_test("lrw(camellia)");
1162 ret
+= tcrypt_test("xts(camellia)");
1166 ret
+= tcrypt_test("sha224");
1170 ret
+= tcrypt_test("salsa20");
1174 ret
+= tcrypt_test("gcm(aes)");
1178 ret
+= tcrypt_test("lzo");
1182 ret
+= tcrypt_test("ccm(aes)");
1186 ret
+= tcrypt_test("cts(cbc(aes))");
1190 ret
+= tcrypt_test("rmd128");
1194 ret
+= tcrypt_test("rmd160");
1198 ret
+= tcrypt_test("rmd256");
1202 ret
+= tcrypt_test("rmd320");
1206 ret
+= tcrypt_test("ecb(seed)");
1210 ret
+= tcrypt_test("zlib");
1214 ret
+= tcrypt_test("rfc4309(ccm(aes))");
1218 ret
+= tcrypt_test("ghash");
1222 ret
+= tcrypt_test("crct10dif");
1226 ret
+= tcrypt_test("sha3-224");
1230 ret
+= tcrypt_test("sha3-256");
1234 ret
+= tcrypt_test("sha3-384");
1238 ret
+= tcrypt_test("sha3-512");
1242 ret
+= tcrypt_test("sm3");
1246 ret
+= tcrypt_test("hmac(md5)");
1250 ret
+= tcrypt_test("hmac(sha1)");
1254 ret
+= tcrypt_test("hmac(sha256)");
1258 ret
+= tcrypt_test("hmac(sha384)");
1262 ret
+= tcrypt_test("hmac(sha512)");
1266 ret
+= tcrypt_test("hmac(sha224)");
1270 ret
+= tcrypt_test("xcbc(aes)");
1274 ret
+= tcrypt_test("hmac(rmd128)");
1278 ret
+= tcrypt_test("hmac(rmd160)");
1282 ret
+= tcrypt_test("vmac(aes)");
1286 ret
+= tcrypt_test("hmac(crc32)");
1290 ret
+= tcrypt_test("hmac(sha3-224)");
1294 ret
+= tcrypt_test("hmac(sha3-256)");
1298 ret
+= tcrypt_test("hmac(sha3-384)");
1302 ret
+= tcrypt_test("hmac(sha3-512)");
1306 ret
+= tcrypt_test("ansi_cprng");
1310 ret
+= tcrypt_test("rfc4106(gcm(aes))");
1314 ret
+= tcrypt_test("rfc4543(gcm(aes))");
1318 ret
+= tcrypt_test("cmac(aes)");
1322 ret
+= tcrypt_test("cmac(des3_ede)");
1326 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1330 ret
+= tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1334 ret
+= tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1337 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(des))");
1340 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
1343 ret
+= tcrypt_test("authenc(hmac(sha224),cbc(des))");
1346 ret
+= tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
1349 ret
+= tcrypt_test("authenc(hmac(sha256),cbc(des))");
1352 ret
+= tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
1355 ret
+= tcrypt_test("authenc(hmac(sha384),cbc(des))");
1358 ret
+= tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
1361 ret
+= tcrypt_test("authenc(hmac(sha512),cbc(des))");
1364 ret
+= tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
1367 test_cipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1368 speed_template_16_24_32
);
1369 test_cipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1370 speed_template_16_24_32
);
1371 test_cipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1372 speed_template_16_24_32
);
1373 test_cipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1374 speed_template_16_24_32
);
1375 test_cipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1376 speed_template_32_40_48
);
1377 test_cipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1378 speed_template_32_40_48
);
1379 test_cipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1380 speed_template_32_64
);
1381 test_cipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1382 speed_template_32_64
);
1383 test_cipher_speed("cts(cbc(aes))", ENCRYPT
, sec
, NULL
, 0,
1384 speed_template_16_24_32
);
1385 test_cipher_speed("cts(cbc(aes))", DECRYPT
, sec
, NULL
, 0,
1386 speed_template_16_24_32
);
1387 test_cipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
1388 speed_template_16_24_32
);
1389 test_cipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
1390 speed_template_16_24_32
);
1394 test_cipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1395 des3_speed_template
, DES3_SPEED_VECTORS
,
1397 test_cipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1398 des3_speed_template
, DES3_SPEED_VECTORS
,
1400 test_cipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1401 des3_speed_template
, DES3_SPEED_VECTORS
,
1403 test_cipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1404 des3_speed_template
, DES3_SPEED_VECTORS
,
1406 test_cipher_speed("ctr(des3_ede)", ENCRYPT
, sec
,
1407 des3_speed_template
, DES3_SPEED_VECTORS
,
1409 test_cipher_speed("ctr(des3_ede)", DECRYPT
, sec
,
1410 des3_speed_template
, DES3_SPEED_VECTORS
,
1415 test_cipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1416 speed_template_16_24_32
);
1417 test_cipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1418 speed_template_16_24_32
);
1419 test_cipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1420 speed_template_16_24_32
);
1421 test_cipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1422 speed_template_16_24_32
);
1423 test_cipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
1424 speed_template_16_24_32
);
1425 test_cipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
1426 speed_template_16_24_32
);
1427 test_cipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
1428 speed_template_32_40_48
);
1429 test_cipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
1430 speed_template_32_40_48
);
1431 test_cipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
1432 speed_template_32_48_64
);
1433 test_cipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
1434 speed_template_32_48_64
);
1438 test_cipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1439 speed_template_8_32
);
1440 test_cipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
1441 speed_template_8_32
);
1442 test_cipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1443 speed_template_8_32
);
1444 test_cipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
1445 speed_template_8_32
);
1446 test_cipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1447 speed_template_8_32
);
1448 test_cipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
1449 speed_template_8_32
);
1453 test_cipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1455 test_cipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1457 test_cipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1459 test_cipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1464 test_cipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
1465 speed_template_16_24_32
);
1466 test_cipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
1467 speed_template_16_24_32
);
1468 test_cipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
1469 speed_template_16_24_32
);
1470 test_cipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
1471 speed_template_16_24_32
);
1472 test_cipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
1473 speed_template_16_24_32
);
1474 test_cipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
1475 speed_template_16_24_32
);
1476 test_cipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
1477 speed_template_32_40_48
);
1478 test_cipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
1479 speed_template_32_40_48
);
1480 test_cipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
1481 speed_template_32_48_64
);
1482 test_cipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
1483 speed_template_32_48_64
);
1487 test_cipher_speed("salsa20", ENCRYPT
, sec
, NULL
, 0,
1488 speed_template_16_32
);
1492 test_cipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
1493 speed_template_16_32
);
1494 test_cipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
1495 speed_template_16_32
);
1496 test_cipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
1497 speed_template_16_32
);
1498 test_cipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
1499 speed_template_16_32
);
1500 test_cipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
1501 speed_template_16_32
);
1502 test_cipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
1503 speed_template_16_32
);
1504 test_cipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
1505 speed_template_32_48
);
1506 test_cipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
1507 speed_template_32_48
);
1508 test_cipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
1509 speed_template_32_64
);
1510 test_cipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
1511 speed_template_32_64
);
1515 test_cipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
1520 test_cipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
1521 speed_template_8_16
);
1522 test_cipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
1523 speed_template_8_16
);
1524 test_cipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
1525 speed_template_8_16
);
1526 test_cipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
1527 speed_template_8_16
);
1528 test_cipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
1529 speed_template_8_16
);
1530 test_cipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
1531 speed_template_8_16
);
1535 test_cipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
1536 speed_template_16_32
);
1537 test_cipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
1538 speed_template_16_32
);
1539 test_cipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
1540 speed_template_16_32
);
1541 test_cipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
1542 speed_template_16_32
);
1543 test_cipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
1544 speed_template_16_32
);
1545 test_cipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
1546 speed_template_16_32
);
1547 test_cipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
1548 speed_template_32_48
);
1549 test_cipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
1550 speed_template_32_48
);
1551 test_cipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
1552 speed_template_32_64
);
1553 test_cipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
1554 speed_template_32_64
);
1558 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT
, sec
,
1559 NULL
, 0, 16, 16, aead_speed_template_20
);
1560 test_aead_speed("gcm(aes)", ENCRYPT
, sec
,
1561 NULL
, 0, 16, 8, speed_template_16_24_32
);
1565 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT
, sec
,
1566 NULL
, 0, 16, 16, aead_speed_template_19
);
1570 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT
, sec
,
1571 NULL
, 0, 16, 8, aead_speed_template_36
);
1575 test_cipher_speed("chacha20", ENCRYPT
, sec
, NULL
, 0,
1581 test_hash_speed(alg
, sec
, generic_hash_speed_template
);
1586 test_hash_speed("md4", sec
, generic_hash_speed_template
);
1587 if (mode
> 300 && mode
< 400) break;
1590 test_hash_speed("md5", sec
, generic_hash_speed_template
);
1591 if (mode
> 300 && mode
< 400) break;
1594 test_hash_speed("sha1", sec
, generic_hash_speed_template
);
1595 if (mode
> 300 && mode
< 400) break;
1598 test_hash_speed("sha256", sec
, generic_hash_speed_template
);
1599 if (mode
> 300 && mode
< 400) break;
1602 test_hash_speed("sha384", sec
, generic_hash_speed_template
);
1603 if (mode
> 300 && mode
< 400) break;
1606 test_hash_speed("sha512", sec
, generic_hash_speed_template
);
1607 if (mode
> 300 && mode
< 400) break;
1610 test_hash_speed("wp256", sec
, generic_hash_speed_template
);
1611 if (mode
> 300 && mode
< 400) break;
1614 test_hash_speed("wp384", sec
, generic_hash_speed_template
);
1615 if (mode
> 300 && mode
< 400) break;
1618 test_hash_speed("wp512", sec
, generic_hash_speed_template
);
1619 if (mode
> 300 && mode
< 400) break;
1622 test_hash_speed("tgr128", sec
, generic_hash_speed_template
);
1623 if (mode
> 300 && mode
< 400) break;
1626 test_hash_speed("tgr160", sec
, generic_hash_speed_template
);
1627 if (mode
> 300 && mode
< 400) break;
1630 test_hash_speed("tgr192", sec
, generic_hash_speed_template
);
1631 if (mode
> 300 && mode
< 400) break;
1634 test_hash_speed("sha224", sec
, generic_hash_speed_template
);
1635 if (mode
> 300 && mode
< 400) break;
1638 test_hash_speed("rmd128", sec
, generic_hash_speed_template
);
1639 if (mode
> 300 && mode
< 400) break;
1642 test_hash_speed("rmd160", sec
, generic_hash_speed_template
);
1643 if (mode
> 300 && mode
< 400) break;
1646 test_hash_speed("rmd256", sec
, generic_hash_speed_template
);
1647 if (mode
> 300 && mode
< 400) break;
1650 test_hash_speed("rmd320", sec
, generic_hash_speed_template
);
1651 if (mode
> 300 && mode
< 400) break;
1654 test_hash_speed("ghash-generic", sec
, hash_speed_template_16
);
1655 if (mode
> 300 && mode
< 400) break;
1658 test_hash_speed("crc32c", sec
, generic_hash_speed_template
);
1659 if (mode
> 300 && mode
< 400) break;
1662 test_hash_speed("crct10dif", sec
, generic_hash_speed_template
);
1663 if (mode
> 300 && mode
< 400) break;
1666 test_hash_speed("poly1305", sec
, poly1305_speed_template
);
1667 if (mode
> 300 && mode
< 400) break;
1670 test_hash_speed("sha3-224", sec
, generic_hash_speed_template
);
1671 if (mode
> 300 && mode
< 400) break;
1674 test_hash_speed("sha3-256", sec
, generic_hash_speed_template
);
1675 if (mode
> 300 && mode
< 400) break;
1678 test_hash_speed("sha3-384", sec
, generic_hash_speed_template
);
1679 if (mode
> 300 && mode
< 400) break;
1682 test_hash_speed("sha3-512", sec
, generic_hash_speed_template
);
1683 if (mode
> 300 && mode
< 400) break;
1686 test_hash_speed("sm3", sec
, generic_hash_speed_template
);
1687 if (mode
> 300 && mode
< 400) break;
1694 test_ahash_speed(alg
, sec
, generic_hash_speed_template
);
1699 test_ahash_speed("md4", sec
, generic_hash_speed_template
);
1700 if (mode
> 400 && mode
< 500) break;
1703 test_ahash_speed("md5", sec
, generic_hash_speed_template
);
1704 if (mode
> 400 && mode
< 500) break;
1707 test_ahash_speed("sha1", sec
, generic_hash_speed_template
);
1708 if (mode
> 400 && mode
< 500) break;
1711 test_ahash_speed("sha256", sec
, generic_hash_speed_template
);
1712 if (mode
> 400 && mode
< 500) break;
1715 test_ahash_speed("sha384", sec
, generic_hash_speed_template
);
1716 if (mode
> 400 && mode
< 500) break;
1719 test_ahash_speed("sha512", sec
, generic_hash_speed_template
);
1720 if (mode
> 400 && mode
< 500) break;
1723 test_ahash_speed("wp256", sec
, generic_hash_speed_template
);
1724 if (mode
> 400 && mode
< 500) break;
1727 test_ahash_speed("wp384", sec
, generic_hash_speed_template
);
1728 if (mode
> 400 && mode
< 500) break;
1731 test_ahash_speed("wp512", sec
, generic_hash_speed_template
);
1732 if (mode
> 400 && mode
< 500) break;
1735 test_ahash_speed("tgr128", sec
, generic_hash_speed_template
);
1736 if (mode
> 400 && mode
< 500) break;
1739 test_ahash_speed("tgr160", sec
, generic_hash_speed_template
);
1740 if (mode
> 400 && mode
< 500) break;
1743 test_ahash_speed("tgr192", sec
, generic_hash_speed_template
);
1744 if (mode
> 400 && mode
< 500) break;
1747 test_ahash_speed("sha224", sec
, generic_hash_speed_template
);
1748 if (mode
> 400 && mode
< 500) break;
1751 test_ahash_speed("rmd128", sec
, generic_hash_speed_template
);
1752 if (mode
> 400 && mode
< 500) break;
1755 test_ahash_speed("rmd160", sec
, generic_hash_speed_template
);
1756 if (mode
> 400 && mode
< 500) break;
1759 test_ahash_speed("rmd256", sec
, generic_hash_speed_template
);
1760 if (mode
> 400 && mode
< 500) break;
1763 test_ahash_speed("rmd320", sec
, generic_hash_speed_template
);
1764 if (mode
> 400 && mode
< 500) break;
1767 test_ahash_speed("sha3-224", sec
, generic_hash_speed_template
);
1768 if (mode
> 400 && mode
< 500) break;
1771 test_ahash_speed("sha3-256", sec
, generic_hash_speed_template
);
1772 if (mode
> 400 && mode
< 500) break;
1775 test_ahash_speed("sha3-384", sec
, generic_hash_speed_template
);
1776 if (mode
> 400 && mode
< 500) break;
1779 test_ahash_speed("sha3-512", sec
, generic_hash_speed_template
);
1780 if (mode
> 400 && mode
< 500) break;
1783 test_mb_ahash_speed("sha1", sec
, generic_hash_speed_template
);
1784 if (mode
> 400 && mode
< 500) break;
1787 test_mb_ahash_speed("sha256", sec
, generic_hash_speed_template
);
1788 if (mode
> 400 && mode
< 500) break;
1791 test_mb_ahash_speed("sha512", sec
, generic_hash_speed_template
);
1792 if (mode
> 400 && mode
< 500) break;
1795 test_mb_ahash_speed("sm3", sec
, generic_hash_speed_template
);
1796 if (mode
> 400 && mode
< 500) break;
1802 test_acipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1803 speed_template_16_24_32
);
1804 test_acipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1805 speed_template_16_24_32
);
1806 test_acipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1807 speed_template_16_24_32
);
1808 test_acipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1809 speed_template_16_24_32
);
1810 test_acipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1811 speed_template_32_40_48
);
1812 test_acipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1813 speed_template_32_40_48
);
1814 test_acipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1815 speed_template_32_64
);
1816 test_acipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1817 speed_template_32_64
);
1818 test_acipher_speed("cts(cbc(aes))", ENCRYPT
, sec
, NULL
, 0,
1819 speed_template_16_24_32
);
1820 test_acipher_speed("cts(cbc(aes))", DECRYPT
, sec
, NULL
, 0,
1821 speed_template_16_24_32
);
1822 test_acipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
1823 speed_template_16_24_32
);
1824 test_acipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
1825 speed_template_16_24_32
);
1826 test_acipher_speed("cfb(aes)", ENCRYPT
, sec
, NULL
, 0,
1827 speed_template_16_24_32
);
1828 test_acipher_speed("cfb(aes)", DECRYPT
, sec
, NULL
, 0,
1829 speed_template_16_24_32
);
1830 test_acipher_speed("ofb(aes)", ENCRYPT
, sec
, NULL
, 0,
1831 speed_template_16_24_32
);
1832 test_acipher_speed("ofb(aes)", DECRYPT
, sec
, NULL
, 0,
1833 speed_template_16_24_32
);
1834 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT
, sec
, NULL
, 0,
1835 speed_template_20_28_36
);
1836 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT
, sec
, NULL
, 0,
1837 speed_template_20_28_36
);
1841 test_acipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1842 des3_speed_template
, DES3_SPEED_VECTORS
,
1844 test_acipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1845 des3_speed_template
, DES3_SPEED_VECTORS
,
1847 test_acipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1848 des3_speed_template
, DES3_SPEED_VECTORS
,
1850 test_acipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1851 des3_speed_template
, DES3_SPEED_VECTORS
,
1853 test_acipher_speed("cfb(des3_ede)", ENCRYPT
, sec
,
1854 des3_speed_template
, DES3_SPEED_VECTORS
,
1856 test_acipher_speed("cfb(des3_ede)", DECRYPT
, sec
,
1857 des3_speed_template
, DES3_SPEED_VECTORS
,
1859 test_acipher_speed("ofb(des3_ede)", ENCRYPT
, sec
,
1860 des3_speed_template
, DES3_SPEED_VECTORS
,
1862 test_acipher_speed("ofb(des3_ede)", DECRYPT
, sec
,
1863 des3_speed_template
, DES3_SPEED_VECTORS
,
1868 test_acipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1870 test_acipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1872 test_acipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1874 test_acipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1876 test_acipher_speed("cfb(des)", ENCRYPT
, sec
, NULL
, 0,
1878 test_acipher_speed("cfb(des)", DECRYPT
, sec
, NULL
, 0,
1880 test_acipher_speed("ofb(des)", ENCRYPT
, sec
, NULL
, 0,
1882 test_acipher_speed("ofb(des)", DECRYPT
, sec
, NULL
, 0,
1887 test_acipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
1888 speed_template_16_32
);
1889 test_acipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
1890 speed_template_16_32
);
1891 test_acipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
1892 speed_template_16_32
);
1893 test_acipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
1894 speed_template_16_32
);
1895 test_acipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
1896 speed_template_16_32
);
1897 test_acipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
1898 speed_template_16_32
);
1899 test_acipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
1900 speed_template_32_48
);
1901 test_acipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
1902 speed_template_32_48
);
1903 test_acipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
1904 speed_template_32_64
);
1905 test_acipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
1906 speed_template_32_64
);
1910 test_acipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1911 speed_template_16_24_32
);
1912 test_acipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1913 speed_template_16_24_32
);
1914 test_acipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1915 speed_template_16_24_32
);
1916 test_acipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1917 speed_template_16_24_32
);
1918 test_acipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
1919 speed_template_16_24_32
);
1920 test_acipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
1921 speed_template_16_24_32
);
1922 test_acipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
1923 speed_template_32_40_48
);
1924 test_acipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
1925 speed_template_32_40_48
);
1926 test_acipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
1927 speed_template_32_48_64
);
1928 test_acipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
1929 speed_template_32_48_64
);
1933 test_acipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
1938 test_acipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
1939 speed_template_8_16
);
1940 test_acipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
1941 speed_template_8_16
);
1942 test_acipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
1943 speed_template_8_16
);
1944 test_acipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
1945 speed_template_8_16
);
1946 test_acipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
1947 speed_template_8_16
);
1948 test_acipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
1949 speed_template_8_16
);
1953 test_acipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
1954 speed_template_16_32
);
1955 test_acipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
1956 speed_template_16_32
);
1957 test_acipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
1958 speed_template_16_32
);
1959 test_acipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
1960 speed_template_16_32
);
1961 test_acipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
1962 speed_template_16_32
);
1963 test_acipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
1964 speed_template_16_32
);
1965 test_acipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
1966 speed_template_32_48
);
1967 test_acipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
1968 speed_template_32_48
);
1969 test_acipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
1970 speed_template_32_64
);
1971 test_acipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
1972 speed_template_32_64
);
1976 test_acipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
1977 speed_template_16_32
);
1978 test_acipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
1979 speed_template_16_32
);
1980 test_acipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
1981 speed_template_16_32
);
1982 test_acipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
1983 speed_template_16_32
);
1984 test_acipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
1985 speed_template_16_32
);
1986 test_acipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
1987 speed_template_16_32
);
1988 test_acipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
1989 speed_template_32_48
);
1990 test_acipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
1991 speed_template_32_48
);
1992 test_acipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
1993 speed_template_32_64
);
1994 test_acipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
1995 speed_template_32_64
);
1999 test_acipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2000 speed_template_8_32
);
2001 test_acipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
2002 speed_template_8_32
);
2003 test_acipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2004 speed_template_8_32
);
2005 test_acipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
2006 speed_template_8_32
);
2007 test_acipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2008 speed_template_8_32
);
2009 test_acipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
2010 speed_template_8_32
);
2021 static int __init
tcrypt_mod_init(void)
2026 for (i
= 0; i
< TVMEMSIZE
; i
++) {
2027 tvmem
[i
] = (void *)__get_free_page(GFP_KERNEL
);
2032 err
= do_test(alg
, type
, mask
, mode
);
2035 printk(KERN_ERR
"tcrypt: one or more tests failed!\n");
2038 pr_debug("all tests passed\n");
2041 /* We intentionaly return -EAGAIN to prevent keeping the module,
2042 * unless we're running in fips mode. It does all its work from
2043 * init() and doesn't offer any runtime functionality, but in
2044 * the fips case, checking for a successful load is helpful.
2045 * => we don't need it in the memory, do we?
2052 for (i
= 0; i
< TVMEMSIZE
&& tvmem
[i
]; i
++)
2053 free_page((unsigned long)tvmem
[i
]);
2059 * If an init function is provided, an exit function must also be provided
2060 * to allow module unload.
2062 static void __exit
tcrypt_mod_fini(void) { }
2064 module_init(tcrypt_mod_init
);
2065 module_exit(tcrypt_mod_fini
);
2067 module_param(alg
, charp
, 0);
2068 module_param(type
, uint
, 0);
2069 module_param(mask
, uint
, 0);
2070 module_param(mode
, int, 0);
2071 module_param(sec
, uint
, 0);
2072 MODULE_PARM_DESC(sec
, "Length in seconds of speed tests "
2073 "(defaults to zero which uses CPU cycles instead)");
2075 MODULE_LICENSE("GPL");
2076 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2077 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");