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);
202 for (k
= 0; k
< np
; k
++)
203 sg_set_buf(&sg
[k
+ 1], xbuf
[k
], PAGE_SIZE
);
205 sg_set_buf(&sg
[k
+ 1], xbuf
[k
], rem
);
208 static void test_aead_speed(const char *algo
, int enc
, unsigned int secs
,
209 struct aead_speed_template
*template,
210 unsigned int tcount
, u8 authsize
,
211 unsigned int aad_size
, u8
*keysize
)
214 struct crypto_aead
*tfm
;
217 struct aead_request
*req
;
218 struct scatterlist
*sg
;
219 struct scatterlist
*sgout
;
223 char *xbuf
[XBUFSIZE
];
224 char *xoutbuf
[XBUFSIZE
];
225 char *axbuf
[XBUFSIZE
];
226 unsigned int *b_size
;
228 struct crypto_wait wait
;
230 iv
= kzalloc(MAX_IVLEN
, GFP_KERNEL
);
234 if (aad_size
>= PAGE_SIZE
) {
235 pr_err("associate data length (%u) too big\n", aad_size
);
244 if (testmgr_alloc_buf(xbuf
))
246 if (testmgr_alloc_buf(axbuf
))
248 if (testmgr_alloc_buf(xoutbuf
))
251 sg
= kmalloc(sizeof(*sg
) * 9 * 2, GFP_KERNEL
);
256 tfm
= crypto_alloc_aead(algo
, 0, 0);
259 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo
,
264 crypto_init_wait(&wait
);
265 printk(KERN_INFO
"\ntesting speed of %s (%s) %s\n", algo
,
266 get_driver_name(crypto_aead
, tfm
), e
);
268 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
270 pr_err("alg: aead: Failed to allocate request for %s\n",
275 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
276 crypto_req_done
, &wait
);
283 memset(assoc
, 0xff, aad_size
);
285 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
286 pr_err("template (%u) too big for tvmem (%lu)\n",
288 TVMEMSIZE
* PAGE_SIZE
);
293 for (j
= 0; j
< tcount
; j
++) {
294 if (template[j
].klen
== *keysize
) {
295 key
= template[j
].key
;
299 ret
= crypto_aead_setkey(tfm
, key
, *keysize
);
300 ret
= crypto_aead_setauthsize(tfm
, authsize
);
302 iv_len
= crypto_aead_ivsize(tfm
);
304 memset(iv
, 0xff, iv_len
);
306 crypto_aead_clear_flags(tfm
, ~0);
307 printk(KERN_INFO
"test %u (%d bit key, %d byte blocks): ",
308 i
, *keysize
* 8, *b_size
);
311 memset(tvmem
[0], 0xff, PAGE_SIZE
);
314 pr_err("setkey() failed flags=%x\n",
315 crypto_aead_get_flags(tfm
));
319 sg_init_aead(sg
, xbuf
,
320 *b_size
+ (enc
? 0 : authsize
));
322 sg_init_aead(sgout
, xoutbuf
,
323 *b_size
+ (enc
? authsize
: 0));
325 sg_set_buf(&sg
[0], assoc
, aad_size
);
326 sg_set_buf(&sgout
[0], assoc
, aad_size
);
328 aead_request_set_crypt(req
, sg
, sgout
,
329 *b_size
+ (enc
? 0 : authsize
),
331 aead_request_set_ad(req
, aad_size
);
334 ret
= test_aead_jiffies(req
, enc
, *b_size
,
337 ret
= test_aead_cycles(req
, enc
, *b_size
);
340 pr_err("%s() failed return code=%d\n", e
, ret
);
350 aead_request_free(req
);
352 crypto_free_aead(tfm
);
356 testmgr_free_buf(xoutbuf
);
358 testmgr_free_buf(axbuf
);
360 testmgr_free_buf(xbuf
);
365 static void test_hash_sg_init(struct scatterlist
*sg
)
369 sg_init_table(sg
, TVMEMSIZE
);
370 for (i
= 0; i
< TVMEMSIZE
; i
++) {
371 sg_set_buf(sg
+ i
, tvmem
[i
], PAGE_SIZE
);
372 memset(tvmem
[i
], 0xff, PAGE_SIZE
);
376 static inline int do_one_ahash_op(struct ahash_request
*req
, int ret
)
378 struct crypto_wait
*wait
= req
->base
.data
;
380 return crypto_wait_req(ret
, wait
);
383 struct test_mb_ahash_data
{
384 struct scatterlist sg
[TVMEMSIZE
];
386 struct ahash_request
*req
;
387 struct crypto_wait wait
;
388 char *xbuf
[XBUFSIZE
];
391 static void test_mb_ahash_speed(const char *algo
, unsigned int sec
,
392 struct hash_speed
*speed
)
394 struct test_mb_ahash_data
*data
;
395 struct crypto_ahash
*tfm
;
396 unsigned long start
, end
;
397 unsigned long cycles
;
398 unsigned int i
, j
, k
;
401 data
= kzalloc(sizeof(*data
) * 8, GFP_KERNEL
);
405 tfm
= crypto_alloc_ahash(algo
, 0, 0);
407 pr_err("failed to load transform for %s: %ld\n",
412 for (i
= 0; i
< 8; ++i
) {
413 if (testmgr_alloc_buf(data
[i
].xbuf
))
416 crypto_init_wait(&data
[i
].wait
);
418 data
[i
].req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
420 pr_err("alg: hash: Failed to allocate request for %s\n",
425 ahash_request_set_callback(data
[i
].req
, 0, crypto_req_done
,
427 test_hash_sg_init(data
[i
].sg
);
430 pr_info("\ntesting speed of multibuffer %s (%s)\n", algo
,
431 get_driver_name(crypto_ahash
, tfm
));
433 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
434 /* For some reason this only tests digests. */
435 if (speed
[i
].blen
!= speed
[i
].plen
)
438 if (speed
[i
].blen
> TVMEMSIZE
* PAGE_SIZE
) {
439 pr_err("template (%u) too big for tvmem (%lu)\n",
440 speed
[i
].blen
, TVMEMSIZE
* PAGE_SIZE
);
445 crypto_ahash_setkey(tfm
, tvmem
[0], speed
[i
].klen
);
447 for (k
= 0; k
< 8; k
++)
448 ahash_request_set_crypt(data
[k
].req
, data
[k
].sg
,
449 data
[k
].result
, speed
[i
].blen
);
452 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
453 i
, speed
[i
].blen
, speed
[i
].plen
,
454 speed
[i
].blen
/ speed
[i
].plen
);
456 start
= get_cycles();
458 for (k
= 0; k
< 8; k
++) {
459 ret
= crypto_ahash_digest(data
[k
].req
);
460 if (ret
== -EINPROGRESS
) {
468 crypto_req_done(&data
[k
].req
->base
, 0);
471 for (j
= 0; j
< k
; j
++) {
472 struct crypto_wait
*wait
= &data
[j
].wait
;
475 wait_ret
= crypto_wait_req(-EINPROGRESS
, wait
);
481 cycles
= end
- start
;
482 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
483 cycles
, cycles
/ (8 * speed
[i
].blen
));
486 pr_err("At least one hashing failed ret=%d\n", ret
);
492 for (k
= 0; k
< 8; ++k
)
493 ahash_request_free(data
[k
].req
);
495 for (k
= 0; k
< 8; ++k
)
496 testmgr_free_buf(data
[k
].xbuf
);
498 crypto_free_ahash(tfm
);
504 static int test_ahash_jiffies_digest(struct ahash_request
*req
, int blen
,
507 unsigned long start
, end
;
511 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
512 time_before(jiffies
, end
); bcount
++) {
513 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
518 printk("%6u opers/sec, %9lu bytes/sec\n",
519 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
524 static int test_ahash_jiffies(struct ahash_request
*req
, int blen
,
525 int plen
, char *out
, int secs
)
527 unsigned long start
, end
;
532 return test_ahash_jiffies_digest(req
, blen
, out
, secs
);
534 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
535 time_before(jiffies
, end
); bcount
++) {
536 ret
= do_one_ahash_op(req
, crypto_ahash_init(req
));
539 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
540 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
544 /* we assume there is enough space in 'out' for the result */
545 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
550 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
551 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
556 static int test_ahash_cycles_digest(struct ahash_request
*req
, int blen
,
559 unsigned long cycles
= 0;
563 for (i
= 0; i
< 4; i
++) {
564 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
569 /* The real thing. */
570 for (i
= 0; i
< 8; i
++) {
573 start
= get_cycles();
575 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
581 cycles
+= end
- start
;
588 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
589 cycles
/ 8, cycles
/ (8 * blen
));
594 static int test_ahash_cycles(struct ahash_request
*req
, int blen
,
597 unsigned long cycles
= 0;
601 return test_ahash_cycles_digest(req
, blen
, out
);
604 for (i
= 0; i
< 4; i
++) {
605 ret
= do_one_ahash_op(req
, crypto_ahash_init(req
));
608 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
609 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
613 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
618 /* The real thing. */
619 for (i
= 0; i
< 8; i
++) {
622 start
= get_cycles();
624 ret
= do_one_ahash_op(req
, crypto_ahash_init(req
));
627 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
628 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
632 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
638 cycles
+= end
- start
;
645 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
646 cycles
/ 8, cycles
/ (8 * blen
));
651 static void test_ahash_speed_common(const char *algo
, unsigned int secs
,
652 struct hash_speed
*speed
, unsigned mask
)
654 struct scatterlist sg
[TVMEMSIZE
];
655 struct crypto_wait wait
;
656 struct ahash_request
*req
;
657 struct crypto_ahash
*tfm
;
661 tfm
= crypto_alloc_ahash(algo
, 0, mask
);
663 pr_err("failed to load transform for %s: %ld\n",
668 printk(KERN_INFO
"\ntesting speed of async %s (%s)\n", algo
,
669 get_driver_name(crypto_ahash
, tfm
));
671 if (crypto_ahash_digestsize(tfm
) > MAX_DIGEST_SIZE
) {
672 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm
),
677 test_hash_sg_init(sg
);
678 req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
680 pr_err("ahash request allocation failure\n");
684 crypto_init_wait(&wait
);
685 ahash_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
686 crypto_req_done
, &wait
);
688 output
= kmalloc(MAX_DIGEST_SIZE
, GFP_KERNEL
);
692 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
693 if (speed
[i
].blen
> TVMEMSIZE
* PAGE_SIZE
) {
694 pr_err("template (%u) too big for tvmem (%lu)\n",
695 speed
[i
].blen
, TVMEMSIZE
* PAGE_SIZE
);
700 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
701 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
703 ahash_request_set_crypt(req
, sg
, output
, speed
[i
].plen
);
706 ret
= test_ahash_jiffies(req
, speed
[i
].blen
,
707 speed
[i
].plen
, output
, secs
);
709 ret
= test_ahash_cycles(req
, speed
[i
].blen
,
710 speed
[i
].plen
, output
);
713 pr_err("hashing failed ret=%d\n", ret
);
721 ahash_request_free(req
);
724 crypto_free_ahash(tfm
);
727 static void test_ahash_speed(const char *algo
, unsigned int secs
,
728 struct hash_speed
*speed
)
730 return test_ahash_speed_common(algo
, secs
, speed
, 0);
733 static void test_hash_speed(const char *algo
, unsigned int secs
,
734 struct hash_speed
*speed
)
736 return test_ahash_speed_common(algo
, secs
, speed
, CRYPTO_ALG_ASYNC
);
739 static inline int do_one_acipher_op(struct skcipher_request
*req
, int ret
)
741 struct crypto_wait
*wait
= req
->base
.data
;
743 return crypto_wait_req(ret
, wait
);
746 static int test_acipher_jiffies(struct skcipher_request
*req
, int enc
,
749 unsigned long start
, end
;
753 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
754 time_before(jiffies
, end
); bcount
++) {
756 ret
= do_one_acipher_op(req
,
757 crypto_skcipher_encrypt(req
));
759 ret
= do_one_acipher_op(req
,
760 crypto_skcipher_decrypt(req
));
766 pr_cont("%d operations in %d seconds (%ld bytes)\n",
767 bcount
, secs
, (long)bcount
* blen
);
771 static int test_acipher_cycles(struct skcipher_request
*req
, int enc
,
774 unsigned long cycles
= 0;
779 for (i
= 0; i
< 4; i
++) {
781 ret
= do_one_acipher_op(req
,
782 crypto_skcipher_encrypt(req
));
784 ret
= do_one_acipher_op(req
,
785 crypto_skcipher_decrypt(req
));
791 /* The real thing. */
792 for (i
= 0; i
< 8; i
++) {
795 start
= get_cycles();
797 ret
= do_one_acipher_op(req
,
798 crypto_skcipher_encrypt(req
));
800 ret
= do_one_acipher_op(req
,
801 crypto_skcipher_decrypt(req
));
807 cycles
+= end
- start
;
812 pr_cont("1 operation in %lu cycles (%d bytes)\n",
813 (cycles
+ 4) / 8, blen
);
818 static void test_skcipher_speed(const char *algo
, int enc
, unsigned int secs
,
819 struct cipher_speed_template
*template,
820 unsigned int tcount
, u8
*keysize
, bool async
)
822 unsigned int ret
, i
, j
, k
, iv_len
;
823 struct crypto_wait wait
;
826 struct skcipher_request
*req
;
827 struct crypto_skcipher
*tfm
;
836 crypto_init_wait(&wait
);
838 tfm
= crypto_alloc_skcipher(algo
, 0, async
? 0 : CRYPTO_ALG_ASYNC
);
841 pr_err("failed to load transform for %s: %ld\n", algo
,
846 pr_info("\ntesting speed of async %s (%s) %s\n", algo
,
847 get_driver_name(crypto_skcipher
, tfm
), e
);
849 req
= skcipher_request_alloc(tfm
, GFP_KERNEL
);
851 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
856 skcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
857 crypto_req_done
, &wait
);
861 b_size
= block_sizes
;
864 struct scatterlist sg
[TVMEMSIZE
];
866 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
867 pr_err("template (%u) too big for "
868 "tvmem (%lu)\n", *keysize
+ *b_size
,
869 TVMEMSIZE
* PAGE_SIZE
);
873 pr_info("test %u (%d bit key, %d byte blocks): ", i
,
874 *keysize
* 8, *b_size
);
876 memset(tvmem
[0], 0xff, PAGE_SIZE
);
878 /* set key, plain text and IV */
880 for (j
= 0; j
< tcount
; j
++) {
881 if (template[j
].klen
== *keysize
) {
882 key
= template[j
].key
;
887 crypto_skcipher_clear_flags(tfm
, ~0);
889 ret
= crypto_skcipher_setkey(tfm
, key
, *keysize
);
891 pr_err("setkey() failed flags=%x\n",
892 crypto_skcipher_get_flags(tfm
));
896 k
= *keysize
+ *b_size
;
897 sg_init_table(sg
, DIV_ROUND_UP(k
, PAGE_SIZE
));
900 sg_set_buf(sg
, tvmem
[0] + *keysize
,
901 PAGE_SIZE
- *keysize
);
904 while (k
> PAGE_SIZE
) {
905 sg_set_buf(sg
+ j
, tvmem
[j
], PAGE_SIZE
);
906 memset(tvmem
[j
], 0xff, PAGE_SIZE
);
910 sg_set_buf(sg
+ j
, tvmem
[j
], k
);
911 memset(tvmem
[j
], 0xff, k
);
913 sg_set_buf(sg
, tvmem
[0] + *keysize
, *b_size
);
916 iv_len
= crypto_skcipher_ivsize(tfm
);
918 memset(&iv
, 0xff, iv_len
);
920 skcipher_request_set_crypt(req
, sg
, sg
, *b_size
, iv
);
923 ret
= test_acipher_jiffies(req
, enc
,
926 ret
= test_acipher_cycles(req
, enc
,
930 pr_err("%s() failed flags=%x\n", e
,
931 crypto_skcipher_get_flags(tfm
));
941 skcipher_request_free(req
);
943 crypto_free_skcipher(tfm
);
946 static void test_acipher_speed(const char *algo
, int enc
, unsigned int secs
,
947 struct cipher_speed_template
*template,
948 unsigned int tcount
, u8
*keysize
)
950 return test_skcipher_speed(algo
, enc
, secs
, template, tcount
, keysize
,
954 static void test_cipher_speed(const char *algo
, int enc
, unsigned int secs
,
955 struct cipher_speed_template
*template,
956 unsigned int tcount
, u8
*keysize
)
958 return test_skcipher_speed(algo
, enc
, secs
, template, tcount
, keysize
,
962 static void test_available(void)
967 printk("alg %s ", *name
);
968 printk(crypto_has_alg(*name
, 0, 0) ?
969 "found\n" : "not found\n");
974 static inline int tcrypt_test(const char *alg
)
978 pr_debug("testing %s\n", alg
);
980 ret
= alg_test(alg
, alg
, 0, 0);
981 /* non-fips algs return -EINVAL in fips mode */
982 if (fips_enabled
&& ret
== -EINVAL
)
987 static int do_test(const char *alg
, u32 type
, u32 mask
, int m
)
995 if (!crypto_has_alg(alg
, type
,
996 mask
?: CRYPTO_ALG_TYPE_MASK
))
1001 for (i
= 1; i
< 200; i
++)
1002 ret
+= do_test(NULL
, 0, 0, i
);
1006 ret
+= tcrypt_test("md5");
1010 ret
+= tcrypt_test("sha1");
1014 ret
+= tcrypt_test("ecb(des)");
1015 ret
+= tcrypt_test("cbc(des)");
1016 ret
+= tcrypt_test("ctr(des)");
1020 ret
+= tcrypt_test("ecb(des3_ede)");
1021 ret
+= tcrypt_test("cbc(des3_ede)");
1022 ret
+= tcrypt_test("ctr(des3_ede)");
1026 ret
+= tcrypt_test("md4");
1030 ret
+= tcrypt_test("sha256");
1034 ret
+= tcrypt_test("ecb(blowfish)");
1035 ret
+= tcrypt_test("cbc(blowfish)");
1036 ret
+= tcrypt_test("ctr(blowfish)");
1040 ret
+= tcrypt_test("ecb(twofish)");
1041 ret
+= tcrypt_test("cbc(twofish)");
1042 ret
+= tcrypt_test("ctr(twofish)");
1043 ret
+= tcrypt_test("lrw(twofish)");
1044 ret
+= tcrypt_test("xts(twofish)");
1048 ret
+= tcrypt_test("ecb(serpent)");
1049 ret
+= tcrypt_test("cbc(serpent)");
1050 ret
+= tcrypt_test("ctr(serpent)");
1051 ret
+= tcrypt_test("lrw(serpent)");
1052 ret
+= tcrypt_test("xts(serpent)");
1056 ret
+= tcrypt_test("ecb(aes)");
1057 ret
+= tcrypt_test("cbc(aes)");
1058 ret
+= tcrypt_test("lrw(aes)");
1059 ret
+= tcrypt_test("xts(aes)");
1060 ret
+= tcrypt_test("ctr(aes)");
1061 ret
+= tcrypt_test("rfc3686(ctr(aes))");
1065 ret
+= tcrypt_test("sha384");
1069 ret
+= tcrypt_test("sha512");
1073 ret
+= tcrypt_test("deflate");
1077 ret
+= tcrypt_test("ecb(cast5)");
1078 ret
+= tcrypt_test("cbc(cast5)");
1079 ret
+= tcrypt_test("ctr(cast5)");
1083 ret
+= tcrypt_test("ecb(cast6)");
1084 ret
+= tcrypt_test("cbc(cast6)");
1085 ret
+= tcrypt_test("ctr(cast6)");
1086 ret
+= tcrypt_test("lrw(cast6)");
1087 ret
+= tcrypt_test("xts(cast6)");
1091 ret
+= tcrypt_test("ecb(arc4)");
1095 ret
+= tcrypt_test("michael_mic");
1099 ret
+= tcrypt_test("crc32c");
1103 ret
+= tcrypt_test("ecb(tea)");
1107 ret
+= tcrypt_test("ecb(xtea)");
1111 ret
+= tcrypt_test("ecb(khazad)");
1115 ret
+= tcrypt_test("wp512");
1119 ret
+= tcrypt_test("wp384");
1123 ret
+= tcrypt_test("wp256");
1127 ret
+= tcrypt_test("ecb(tnepres)");
1131 ret
+= tcrypt_test("ecb(anubis)");
1132 ret
+= tcrypt_test("cbc(anubis)");
1136 ret
+= tcrypt_test("tgr192");
1140 ret
+= tcrypt_test("tgr160");
1144 ret
+= tcrypt_test("tgr128");
1148 ret
+= tcrypt_test("ecb(xeta)");
1152 ret
+= tcrypt_test("pcbc(fcrypt)");
1156 ret
+= tcrypt_test("ecb(camellia)");
1157 ret
+= tcrypt_test("cbc(camellia)");
1158 ret
+= tcrypt_test("ctr(camellia)");
1159 ret
+= tcrypt_test("lrw(camellia)");
1160 ret
+= tcrypt_test("xts(camellia)");
1164 ret
+= tcrypt_test("sha224");
1168 ret
+= tcrypt_test("salsa20");
1172 ret
+= tcrypt_test("gcm(aes)");
1176 ret
+= tcrypt_test("lzo");
1180 ret
+= tcrypt_test("ccm(aes)");
1184 ret
+= tcrypt_test("cts(cbc(aes))");
1188 ret
+= tcrypt_test("rmd128");
1192 ret
+= tcrypt_test("rmd160");
1196 ret
+= tcrypt_test("rmd256");
1200 ret
+= tcrypt_test("rmd320");
1204 ret
+= tcrypt_test("ecb(seed)");
1208 ret
+= tcrypt_test("zlib");
1212 ret
+= tcrypt_test("rfc4309(ccm(aes))");
1216 ret
+= tcrypt_test("ghash");
1220 ret
+= tcrypt_test("crct10dif");
1224 ret
+= tcrypt_test("sha3-224");
1228 ret
+= tcrypt_test("sha3-256");
1232 ret
+= tcrypt_test("sha3-384");
1236 ret
+= tcrypt_test("sha3-512");
1240 ret
+= tcrypt_test("sm3");
1244 ret
+= tcrypt_test("hmac(md5)");
1248 ret
+= tcrypt_test("hmac(sha1)");
1252 ret
+= tcrypt_test("hmac(sha256)");
1256 ret
+= tcrypt_test("hmac(sha384)");
1260 ret
+= tcrypt_test("hmac(sha512)");
1264 ret
+= tcrypt_test("hmac(sha224)");
1268 ret
+= tcrypt_test("xcbc(aes)");
1272 ret
+= tcrypt_test("hmac(rmd128)");
1276 ret
+= tcrypt_test("hmac(rmd160)");
1280 ret
+= tcrypt_test("vmac(aes)");
1284 ret
+= tcrypt_test("hmac(crc32)");
1288 ret
+= tcrypt_test("hmac(sha3-224)");
1292 ret
+= tcrypt_test("hmac(sha3-256)");
1296 ret
+= tcrypt_test("hmac(sha3-384)");
1300 ret
+= tcrypt_test("hmac(sha3-512)");
1304 ret
+= tcrypt_test("ansi_cprng");
1308 ret
+= tcrypt_test("rfc4106(gcm(aes))");
1312 ret
+= tcrypt_test("rfc4543(gcm(aes))");
1316 ret
+= tcrypt_test("cmac(aes)");
1320 ret
+= tcrypt_test("cmac(des3_ede)");
1324 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1328 ret
+= tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1332 ret
+= tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1335 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(des))");
1338 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
1341 ret
+= tcrypt_test("authenc(hmac(sha224),cbc(des))");
1344 ret
+= tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
1347 ret
+= tcrypt_test("authenc(hmac(sha256),cbc(des))");
1350 ret
+= tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
1353 ret
+= tcrypt_test("authenc(hmac(sha384),cbc(des))");
1356 ret
+= tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
1359 ret
+= tcrypt_test("authenc(hmac(sha512),cbc(des))");
1362 ret
+= tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
1365 test_cipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1366 speed_template_16_24_32
);
1367 test_cipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1368 speed_template_16_24_32
);
1369 test_cipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1370 speed_template_16_24_32
);
1371 test_cipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1372 speed_template_16_24_32
);
1373 test_cipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1374 speed_template_32_40_48
);
1375 test_cipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1376 speed_template_32_40_48
);
1377 test_cipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1378 speed_template_32_64
);
1379 test_cipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1380 speed_template_32_64
);
1381 test_cipher_speed("cts(cbc(aes))", ENCRYPT
, sec
, NULL
, 0,
1382 speed_template_16_24_32
);
1383 test_cipher_speed("cts(cbc(aes))", DECRYPT
, sec
, NULL
, 0,
1384 speed_template_16_24_32
);
1385 test_cipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
1386 speed_template_16_24_32
);
1387 test_cipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
1388 speed_template_16_24_32
);
1392 test_cipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1393 des3_speed_template
, DES3_SPEED_VECTORS
,
1395 test_cipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1396 des3_speed_template
, DES3_SPEED_VECTORS
,
1398 test_cipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1399 des3_speed_template
, DES3_SPEED_VECTORS
,
1401 test_cipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1402 des3_speed_template
, DES3_SPEED_VECTORS
,
1404 test_cipher_speed("ctr(des3_ede)", ENCRYPT
, sec
,
1405 des3_speed_template
, DES3_SPEED_VECTORS
,
1407 test_cipher_speed("ctr(des3_ede)", DECRYPT
, sec
,
1408 des3_speed_template
, DES3_SPEED_VECTORS
,
1413 test_cipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1414 speed_template_16_24_32
);
1415 test_cipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1416 speed_template_16_24_32
);
1417 test_cipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1418 speed_template_16_24_32
);
1419 test_cipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1420 speed_template_16_24_32
);
1421 test_cipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
1422 speed_template_16_24_32
);
1423 test_cipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
1424 speed_template_16_24_32
);
1425 test_cipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
1426 speed_template_32_40_48
);
1427 test_cipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
1428 speed_template_32_40_48
);
1429 test_cipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
1430 speed_template_32_48_64
);
1431 test_cipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
1432 speed_template_32_48_64
);
1436 test_cipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1437 speed_template_8_32
);
1438 test_cipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
1439 speed_template_8_32
);
1440 test_cipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1441 speed_template_8_32
);
1442 test_cipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
1443 speed_template_8_32
);
1444 test_cipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1445 speed_template_8_32
);
1446 test_cipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
1447 speed_template_8_32
);
1451 test_cipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1453 test_cipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1455 test_cipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1457 test_cipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1462 test_cipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
1463 speed_template_16_24_32
);
1464 test_cipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
1465 speed_template_16_24_32
);
1466 test_cipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
1467 speed_template_16_24_32
);
1468 test_cipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
1469 speed_template_16_24_32
);
1470 test_cipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
1471 speed_template_16_24_32
);
1472 test_cipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
1473 speed_template_16_24_32
);
1474 test_cipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
1475 speed_template_32_40_48
);
1476 test_cipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
1477 speed_template_32_40_48
);
1478 test_cipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
1479 speed_template_32_48_64
);
1480 test_cipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
1481 speed_template_32_48_64
);
1485 test_cipher_speed("salsa20", ENCRYPT
, sec
, NULL
, 0,
1486 speed_template_16_32
);
1490 test_cipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
1491 speed_template_16_32
);
1492 test_cipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
1493 speed_template_16_32
);
1494 test_cipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
1495 speed_template_16_32
);
1496 test_cipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
1497 speed_template_16_32
);
1498 test_cipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
1499 speed_template_16_32
);
1500 test_cipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
1501 speed_template_16_32
);
1502 test_cipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
1503 speed_template_32_48
);
1504 test_cipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
1505 speed_template_32_48
);
1506 test_cipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
1507 speed_template_32_64
);
1508 test_cipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
1509 speed_template_32_64
);
1513 test_cipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
1518 test_cipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
1519 speed_template_8_16
);
1520 test_cipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
1521 speed_template_8_16
);
1522 test_cipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
1523 speed_template_8_16
);
1524 test_cipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
1525 speed_template_8_16
);
1526 test_cipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
1527 speed_template_8_16
);
1528 test_cipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
1529 speed_template_8_16
);
1533 test_cipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
1534 speed_template_16_32
);
1535 test_cipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
1536 speed_template_16_32
);
1537 test_cipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
1538 speed_template_16_32
);
1539 test_cipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
1540 speed_template_16_32
);
1541 test_cipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
1542 speed_template_16_32
);
1543 test_cipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
1544 speed_template_16_32
);
1545 test_cipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
1546 speed_template_32_48
);
1547 test_cipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
1548 speed_template_32_48
);
1549 test_cipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
1550 speed_template_32_64
);
1551 test_cipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
1552 speed_template_32_64
);
1556 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT
, sec
,
1557 NULL
, 0, 16, 16, aead_speed_template_20
);
1558 test_aead_speed("gcm(aes)", ENCRYPT
, sec
,
1559 NULL
, 0, 16, 8, speed_template_16_24_32
);
1563 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT
, sec
,
1564 NULL
, 0, 16, 16, aead_speed_template_19
);
1568 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT
, sec
,
1569 NULL
, 0, 16, 8, aead_speed_template_36
);
1573 test_cipher_speed("chacha20", ENCRYPT
, sec
, NULL
, 0,
1579 test_hash_speed(alg
, sec
, generic_hash_speed_template
);
1584 test_hash_speed("md4", sec
, generic_hash_speed_template
);
1585 if (mode
> 300 && mode
< 400) break;
1588 test_hash_speed("md5", sec
, generic_hash_speed_template
);
1589 if (mode
> 300 && mode
< 400) break;
1592 test_hash_speed("sha1", sec
, generic_hash_speed_template
);
1593 if (mode
> 300 && mode
< 400) break;
1596 test_hash_speed("sha256", sec
, generic_hash_speed_template
);
1597 if (mode
> 300 && mode
< 400) break;
1600 test_hash_speed("sha384", sec
, generic_hash_speed_template
);
1601 if (mode
> 300 && mode
< 400) break;
1604 test_hash_speed("sha512", sec
, generic_hash_speed_template
);
1605 if (mode
> 300 && mode
< 400) break;
1608 test_hash_speed("wp256", sec
, generic_hash_speed_template
);
1609 if (mode
> 300 && mode
< 400) break;
1612 test_hash_speed("wp384", sec
, generic_hash_speed_template
);
1613 if (mode
> 300 && mode
< 400) break;
1616 test_hash_speed("wp512", sec
, generic_hash_speed_template
);
1617 if (mode
> 300 && mode
< 400) break;
1620 test_hash_speed("tgr128", sec
, generic_hash_speed_template
);
1621 if (mode
> 300 && mode
< 400) break;
1624 test_hash_speed("tgr160", sec
, generic_hash_speed_template
);
1625 if (mode
> 300 && mode
< 400) break;
1628 test_hash_speed("tgr192", sec
, generic_hash_speed_template
);
1629 if (mode
> 300 && mode
< 400) break;
1632 test_hash_speed("sha224", sec
, generic_hash_speed_template
);
1633 if (mode
> 300 && mode
< 400) break;
1636 test_hash_speed("rmd128", sec
, generic_hash_speed_template
);
1637 if (mode
> 300 && mode
< 400) break;
1640 test_hash_speed("rmd160", sec
, generic_hash_speed_template
);
1641 if (mode
> 300 && mode
< 400) break;
1644 test_hash_speed("rmd256", sec
, generic_hash_speed_template
);
1645 if (mode
> 300 && mode
< 400) break;
1648 test_hash_speed("rmd320", sec
, generic_hash_speed_template
);
1649 if (mode
> 300 && mode
< 400) break;
1652 test_hash_speed("ghash-generic", sec
, hash_speed_template_16
);
1653 if (mode
> 300 && mode
< 400) break;
1656 test_hash_speed("crc32c", sec
, generic_hash_speed_template
);
1657 if (mode
> 300 && mode
< 400) break;
1660 test_hash_speed("crct10dif", sec
, generic_hash_speed_template
);
1661 if (mode
> 300 && mode
< 400) break;
1664 test_hash_speed("poly1305", sec
, poly1305_speed_template
);
1665 if (mode
> 300 && mode
< 400) break;
1668 test_hash_speed("sha3-224", sec
, generic_hash_speed_template
);
1669 if (mode
> 300 && mode
< 400) break;
1672 test_hash_speed("sha3-256", sec
, generic_hash_speed_template
);
1673 if (mode
> 300 && mode
< 400) break;
1676 test_hash_speed("sha3-384", sec
, generic_hash_speed_template
);
1677 if (mode
> 300 && mode
< 400) break;
1680 test_hash_speed("sha3-512", sec
, generic_hash_speed_template
);
1681 if (mode
> 300 && mode
< 400) break;
1684 test_hash_speed("sm3", sec
, generic_hash_speed_template
);
1685 if (mode
> 300 && mode
< 400) break;
1692 test_ahash_speed(alg
, sec
, generic_hash_speed_template
);
1697 test_ahash_speed("md4", sec
, generic_hash_speed_template
);
1698 if (mode
> 400 && mode
< 500) break;
1701 test_ahash_speed("md5", sec
, generic_hash_speed_template
);
1702 if (mode
> 400 && mode
< 500) break;
1705 test_ahash_speed("sha1", sec
, generic_hash_speed_template
);
1706 if (mode
> 400 && mode
< 500) break;
1709 test_ahash_speed("sha256", sec
, generic_hash_speed_template
);
1710 if (mode
> 400 && mode
< 500) break;
1713 test_ahash_speed("sha384", sec
, generic_hash_speed_template
);
1714 if (mode
> 400 && mode
< 500) break;
1717 test_ahash_speed("sha512", sec
, generic_hash_speed_template
);
1718 if (mode
> 400 && mode
< 500) break;
1721 test_ahash_speed("wp256", sec
, generic_hash_speed_template
);
1722 if (mode
> 400 && mode
< 500) break;
1725 test_ahash_speed("wp384", sec
, generic_hash_speed_template
);
1726 if (mode
> 400 && mode
< 500) break;
1729 test_ahash_speed("wp512", sec
, generic_hash_speed_template
);
1730 if (mode
> 400 && mode
< 500) break;
1733 test_ahash_speed("tgr128", sec
, generic_hash_speed_template
);
1734 if (mode
> 400 && mode
< 500) break;
1737 test_ahash_speed("tgr160", sec
, generic_hash_speed_template
);
1738 if (mode
> 400 && mode
< 500) break;
1741 test_ahash_speed("tgr192", sec
, generic_hash_speed_template
);
1742 if (mode
> 400 && mode
< 500) break;
1745 test_ahash_speed("sha224", sec
, generic_hash_speed_template
);
1746 if (mode
> 400 && mode
< 500) break;
1749 test_ahash_speed("rmd128", sec
, generic_hash_speed_template
);
1750 if (mode
> 400 && mode
< 500) break;
1753 test_ahash_speed("rmd160", sec
, generic_hash_speed_template
);
1754 if (mode
> 400 && mode
< 500) break;
1757 test_ahash_speed("rmd256", sec
, generic_hash_speed_template
);
1758 if (mode
> 400 && mode
< 500) break;
1761 test_ahash_speed("rmd320", sec
, generic_hash_speed_template
);
1762 if (mode
> 400 && mode
< 500) break;
1765 test_ahash_speed("sha3-224", sec
, generic_hash_speed_template
);
1766 if (mode
> 400 && mode
< 500) break;
1769 test_ahash_speed("sha3-256", sec
, generic_hash_speed_template
);
1770 if (mode
> 400 && mode
< 500) break;
1773 test_ahash_speed("sha3-384", sec
, generic_hash_speed_template
);
1774 if (mode
> 400 && mode
< 500) break;
1777 test_ahash_speed("sha3-512", sec
, generic_hash_speed_template
);
1778 if (mode
> 400 && mode
< 500) break;
1781 test_mb_ahash_speed("sha1", sec
, generic_hash_speed_template
);
1782 if (mode
> 400 && mode
< 500) break;
1785 test_mb_ahash_speed("sha256", sec
, generic_hash_speed_template
);
1786 if (mode
> 400 && mode
< 500) break;
1789 test_mb_ahash_speed("sha512", sec
, generic_hash_speed_template
);
1790 if (mode
> 400 && mode
< 500) break;
1793 test_mb_ahash_speed("sm3", sec
, generic_hash_speed_template
);
1794 if (mode
> 400 && mode
< 500) break;
1800 test_acipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1801 speed_template_16_24_32
);
1802 test_acipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1803 speed_template_16_24_32
);
1804 test_acipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1805 speed_template_16_24_32
);
1806 test_acipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1807 speed_template_16_24_32
);
1808 test_acipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1809 speed_template_32_40_48
);
1810 test_acipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1811 speed_template_32_40_48
);
1812 test_acipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1813 speed_template_32_64
);
1814 test_acipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1815 speed_template_32_64
);
1816 test_acipher_speed("cts(cbc(aes))", ENCRYPT
, sec
, NULL
, 0,
1817 speed_template_16_24_32
);
1818 test_acipher_speed("cts(cbc(aes))", DECRYPT
, sec
, NULL
, 0,
1819 speed_template_16_24_32
);
1820 test_acipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
1821 speed_template_16_24_32
);
1822 test_acipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
1823 speed_template_16_24_32
);
1824 test_acipher_speed("cfb(aes)", ENCRYPT
, sec
, NULL
, 0,
1825 speed_template_16_24_32
);
1826 test_acipher_speed("cfb(aes)", DECRYPT
, sec
, NULL
, 0,
1827 speed_template_16_24_32
);
1828 test_acipher_speed("ofb(aes)", ENCRYPT
, sec
, NULL
, 0,
1829 speed_template_16_24_32
);
1830 test_acipher_speed("ofb(aes)", DECRYPT
, sec
, NULL
, 0,
1831 speed_template_16_24_32
);
1832 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT
, sec
, NULL
, 0,
1833 speed_template_20_28_36
);
1834 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT
, sec
, NULL
, 0,
1835 speed_template_20_28_36
);
1839 test_acipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1840 des3_speed_template
, DES3_SPEED_VECTORS
,
1842 test_acipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1843 des3_speed_template
, DES3_SPEED_VECTORS
,
1845 test_acipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1846 des3_speed_template
, DES3_SPEED_VECTORS
,
1848 test_acipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1849 des3_speed_template
, DES3_SPEED_VECTORS
,
1851 test_acipher_speed("cfb(des3_ede)", ENCRYPT
, sec
,
1852 des3_speed_template
, DES3_SPEED_VECTORS
,
1854 test_acipher_speed("cfb(des3_ede)", DECRYPT
, sec
,
1855 des3_speed_template
, DES3_SPEED_VECTORS
,
1857 test_acipher_speed("ofb(des3_ede)", ENCRYPT
, sec
,
1858 des3_speed_template
, DES3_SPEED_VECTORS
,
1860 test_acipher_speed("ofb(des3_ede)", DECRYPT
, sec
,
1861 des3_speed_template
, DES3_SPEED_VECTORS
,
1866 test_acipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1868 test_acipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1870 test_acipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1872 test_acipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1874 test_acipher_speed("cfb(des)", ENCRYPT
, sec
, NULL
, 0,
1876 test_acipher_speed("cfb(des)", DECRYPT
, sec
, NULL
, 0,
1878 test_acipher_speed("ofb(des)", ENCRYPT
, sec
, NULL
, 0,
1880 test_acipher_speed("ofb(des)", DECRYPT
, sec
, NULL
, 0,
1885 test_acipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
1886 speed_template_16_32
);
1887 test_acipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
1888 speed_template_16_32
);
1889 test_acipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
1890 speed_template_16_32
);
1891 test_acipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
1892 speed_template_16_32
);
1893 test_acipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
1894 speed_template_16_32
);
1895 test_acipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
1896 speed_template_16_32
);
1897 test_acipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
1898 speed_template_32_48
);
1899 test_acipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
1900 speed_template_32_48
);
1901 test_acipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
1902 speed_template_32_64
);
1903 test_acipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
1904 speed_template_32_64
);
1908 test_acipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1909 speed_template_16_24_32
);
1910 test_acipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1911 speed_template_16_24_32
);
1912 test_acipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1913 speed_template_16_24_32
);
1914 test_acipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1915 speed_template_16_24_32
);
1916 test_acipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
1917 speed_template_16_24_32
);
1918 test_acipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
1919 speed_template_16_24_32
);
1920 test_acipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
1921 speed_template_32_40_48
);
1922 test_acipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
1923 speed_template_32_40_48
);
1924 test_acipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
1925 speed_template_32_48_64
);
1926 test_acipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
1927 speed_template_32_48_64
);
1931 test_acipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
1936 test_acipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
1937 speed_template_8_16
);
1938 test_acipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
1939 speed_template_8_16
);
1940 test_acipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
1941 speed_template_8_16
);
1942 test_acipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
1943 speed_template_8_16
);
1944 test_acipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
1945 speed_template_8_16
);
1946 test_acipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
1947 speed_template_8_16
);
1951 test_acipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
1952 speed_template_16_32
);
1953 test_acipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
1954 speed_template_16_32
);
1955 test_acipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
1956 speed_template_16_32
);
1957 test_acipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
1958 speed_template_16_32
);
1959 test_acipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
1960 speed_template_16_32
);
1961 test_acipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
1962 speed_template_16_32
);
1963 test_acipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
1964 speed_template_32_48
);
1965 test_acipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
1966 speed_template_32_48
);
1967 test_acipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
1968 speed_template_32_64
);
1969 test_acipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
1970 speed_template_32_64
);
1974 test_acipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
1975 speed_template_16_32
);
1976 test_acipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
1977 speed_template_16_32
);
1978 test_acipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
1979 speed_template_16_32
);
1980 test_acipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
1981 speed_template_16_32
);
1982 test_acipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
1983 speed_template_16_32
);
1984 test_acipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
1985 speed_template_16_32
);
1986 test_acipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
1987 speed_template_32_48
);
1988 test_acipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
1989 speed_template_32_48
);
1990 test_acipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
1991 speed_template_32_64
);
1992 test_acipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
1993 speed_template_32_64
);
1997 test_acipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1998 speed_template_8_32
);
1999 test_acipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
2000 speed_template_8_32
);
2001 test_acipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2002 speed_template_8_32
);
2003 test_acipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
2004 speed_template_8_32
);
2005 test_acipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2006 speed_template_8_32
);
2007 test_acipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
2008 speed_template_8_32
);
2019 static int __init
tcrypt_mod_init(void)
2024 for (i
= 0; i
< TVMEMSIZE
; i
++) {
2025 tvmem
[i
] = (void *)__get_free_page(GFP_KERNEL
);
2030 err
= do_test(alg
, type
, mask
, mode
);
2033 printk(KERN_ERR
"tcrypt: one or more tests failed!\n");
2036 pr_debug("all tests passed\n");
2039 /* We intentionaly return -EAGAIN to prevent keeping the module,
2040 * unless we're running in fips mode. It does all its work from
2041 * init() and doesn't offer any runtime functionality, but in
2042 * the fips case, checking for a successful load is helpful.
2043 * => we don't need it in the memory, do we?
2050 for (i
= 0; i
< TVMEMSIZE
&& tvmem
[i
]; i
++)
2051 free_page((unsigned long)tvmem
[i
]);
2057 * If an init function is provided, an exit function must also be provided
2058 * to allow module unload.
2060 static void __exit
tcrypt_mod_fini(void) { }
2062 module_init(tcrypt_mod_init
);
2063 module_exit(tcrypt_mod_fini
);
2065 module_param(alg
, charp
, 0);
2066 module_param(type
, uint
, 0);
2067 module_param(mask
, uint
, 0);
2068 module_param(mode
, int, 0);
2069 module_param(sec
, uint
, 0);
2070 MODULE_PARM_DESC(sec
, "Length in seconds of speed tests "
2071 "(defaults to zero which uses CPU cycles instead)");
2073 MODULE_LICENSE("GPL");
2074 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2075 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");