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/aead.h>
26 #include <crypto/hash.h>
27 #include <linux/err.h>
28 #include <linux/fips.h>
29 #include <linux/init.h>
30 #include <linux/gfp.h>
31 #include <linux/module.h>
32 #include <linux/scatterlist.h>
33 #include <linux/string.h>
34 #include <linux/moduleparam.h>
35 #include <linux/jiffies.h>
36 #include <linux/timex.h>
37 #include <linux/interrupt.h>
41 * Need slab memory for testing (size in number of pages).
46 * Used by test_cipher_speed()
51 #define MAX_DIGEST_SIZE 64
54 * return a string with the driver name
56 #define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm))
59 * Used by test_cipher_speed()
61 static unsigned int sec
;
63 static char *alg
= NULL
;
67 static char *tvmem
[TVMEMSIZE
];
69 static char *check
[] = {
70 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
71 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
72 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
73 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
74 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
75 "lzo", "cts", "zlib", NULL
78 struct tcrypt_result
{
79 struct completion completion
;
83 static void tcrypt_complete(struct crypto_async_request
*req
, int err
)
85 struct tcrypt_result
*res
= req
->data
;
87 if (err
== -EINPROGRESS
)
91 complete(&res
->completion
);
94 static int test_cipher_jiffies(struct blkcipher_desc
*desc
, int enc
,
95 struct scatterlist
*sg
, int blen
, int secs
)
97 unsigned long start
, end
;
101 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
102 time_before(jiffies
, end
); bcount
++) {
104 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
106 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
112 printk("%d operations in %d seconds (%ld bytes)\n",
113 bcount
, secs
, (long)bcount
* blen
);
117 static int test_cipher_cycles(struct blkcipher_desc
*desc
, int enc
,
118 struct scatterlist
*sg
, int blen
)
120 unsigned long cycles
= 0;
127 for (i
= 0; i
< 4; i
++) {
129 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
131 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
137 /* The real thing. */
138 for (i
= 0; i
< 8; i
++) {
141 start
= get_cycles();
143 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
145 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
151 cycles
+= end
- start
;
158 printk("1 operation in %lu cycles (%d bytes)\n",
159 (cycles
+ 4) / 8, blen
);
164 static inline int do_one_aead_op(struct aead_request
*req
, int ret
)
166 if (ret
== -EINPROGRESS
|| ret
== -EBUSY
) {
167 struct tcrypt_result
*tr
= req
->base
.data
;
169 ret
= wait_for_completion_interruptible(&tr
->completion
);
172 reinit_completion(&tr
->completion
);
178 static int test_aead_jiffies(struct aead_request
*req
, int enc
,
181 unsigned long start
, end
;
185 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
186 time_before(jiffies
, end
); bcount
++) {
188 ret
= do_one_aead_op(req
, crypto_aead_encrypt(req
));
190 ret
= do_one_aead_op(req
, crypto_aead_decrypt(req
));
196 printk("%d operations in %d seconds (%ld bytes)\n",
197 bcount
, secs
, (long)bcount
* blen
);
201 static int test_aead_cycles(struct aead_request
*req
, int enc
, int blen
)
203 unsigned long cycles
= 0;
210 for (i
= 0; i
< 4; i
++) {
212 ret
= do_one_aead_op(req
, crypto_aead_encrypt(req
));
214 ret
= do_one_aead_op(req
, crypto_aead_decrypt(req
));
220 /* The real thing. */
221 for (i
= 0; i
< 8; i
++) {
224 start
= get_cycles();
226 ret
= do_one_aead_op(req
, crypto_aead_encrypt(req
));
228 ret
= do_one_aead_op(req
, crypto_aead_decrypt(req
));
234 cycles
+= end
- start
;
241 printk("1 operation in %lu cycles (%d bytes)\n",
242 (cycles
+ 4) / 8, blen
);
247 static u32 block_sizes
[] = { 16, 64, 256, 1024, 8192, 0 };
248 static u32 aead_sizes
[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
253 static int testmgr_alloc_buf(char *buf
[XBUFSIZE
])
257 for (i
= 0; i
< XBUFSIZE
; i
++) {
258 buf
[i
] = (void *)__get_free_page(GFP_KERNEL
);
267 free_page((unsigned long)buf
[i
]);
272 static void testmgr_free_buf(char *buf
[XBUFSIZE
])
276 for (i
= 0; i
< XBUFSIZE
; i
++)
277 free_page((unsigned long)buf
[i
]);
280 static void sg_init_aead(struct scatterlist
*sg
, char *xbuf
[XBUFSIZE
],
283 int np
= (buflen
+ PAGE_SIZE
- 1)/PAGE_SIZE
;
290 rem
= buflen
% PAGE_SIZE
;
293 sg_init_table(sg
, np
+ 1);
295 for (k
= 0; k
< np
; k
++)
296 sg_set_buf(&sg
[k
+ 1], xbuf
[k
], PAGE_SIZE
);
298 sg_set_buf(&sg
[k
+ 1], xbuf
[k
], rem
);
301 static void test_aead_speed(const char *algo
, int enc
, unsigned int secs
,
302 struct aead_speed_template
*template,
303 unsigned int tcount
, u8 authsize
,
304 unsigned int aad_size
, u8
*keysize
)
307 struct crypto_aead
*tfm
;
310 struct aead_request
*req
;
311 struct scatterlist
*sg
;
312 struct scatterlist
*sgout
;
316 char *xbuf
[XBUFSIZE
];
317 char *xoutbuf
[XBUFSIZE
];
318 char *axbuf
[XBUFSIZE
];
319 unsigned int *b_size
;
321 struct tcrypt_result result
;
323 iv
= kzalloc(MAX_IVLEN
, GFP_KERNEL
);
327 if (aad_size
>= PAGE_SIZE
) {
328 pr_err("associate data length (%u) too big\n", aad_size
);
337 if (testmgr_alloc_buf(xbuf
))
339 if (testmgr_alloc_buf(axbuf
))
341 if (testmgr_alloc_buf(xoutbuf
))
344 sg
= kmalloc(sizeof(*sg
) * 9 * 2, GFP_KERNEL
);
349 tfm
= crypto_alloc_aead(algo
, 0, 0);
352 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo
,
357 init_completion(&result
.completion
);
358 printk(KERN_INFO
"\ntesting speed of %s (%s) %s\n", algo
,
359 get_driver_name(crypto_aead
, tfm
), e
);
361 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
363 pr_err("alg: aead: Failed to allocate request for %s\n",
368 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
369 tcrypt_complete
, &result
);
376 memset(assoc
, 0xff, aad_size
);
378 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
379 pr_err("template (%u) too big for tvmem (%lu)\n",
381 TVMEMSIZE
* PAGE_SIZE
);
386 for (j
= 0; j
< tcount
; j
++) {
387 if (template[j
].klen
== *keysize
) {
388 key
= template[j
].key
;
392 ret
= crypto_aead_setkey(tfm
, key
, *keysize
);
393 ret
= crypto_aead_setauthsize(tfm
, authsize
);
395 iv_len
= crypto_aead_ivsize(tfm
);
397 memset(iv
, 0xff, iv_len
);
399 crypto_aead_clear_flags(tfm
, ~0);
400 printk(KERN_INFO
"test %u (%d bit key, %d byte blocks): ",
401 i
, *keysize
* 8, *b_size
);
404 memset(tvmem
[0], 0xff, PAGE_SIZE
);
407 pr_err("setkey() failed flags=%x\n",
408 crypto_aead_get_flags(tfm
));
412 sg_init_aead(sg
, xbuf
,
413 *b_size
+ (enc
? authsize
: 0));
415 sg_init_aead(sgout
, xoutbuf
,
416 *b_size
+ (enc
? authsize
: 0));
418 sg_set_buf(&sg
[0], assoc
, aad_size
);
419 sg_set_buf(&sgout
[0], assoc
, aad_size
);
421 aead_request_set_crypt(req
, sg
, sgout
, *b_size
, iv
);
422 aead_request_set_ad(req
, aad_size
);
425 ret
= test_aead_jiffies(req
, enc
, *b_size
,
428 ret
= test_aead_cycles(req
, enc
, *b_size
);
431 pr_err("%s() failed return code=%d\n", e
, ret
);
441 aead_request_free(req
);
443 crypto_free_aead(tfm
);
447 testmgr_free_buf(xoutbuf
);
449 testmgr_free_buf(axbuf
);
451 testmgr_free_buf(xbuf
);
457 static void test_cipher_speed(const char *algo
, int enc
, unsigned int secs
,
458 struct cipher_speed_template
*template,
459 unsigned int tcount
, u8
*keysize
)
461 unsigned int ret
, i
, j
, iv_len
;
464 struct crypto_blkcipher
*tfm
;
465 struct blkcipher_desc desc
;
474 tfm
= crypto_alloc_blkcipher(algo
, 0, CRYPTO_ALG_ASYNC
);
477 printk("failed to load transform for %s: %ld\n", algo
,
484 printk(KERN_INFO
"\ntesting speed of %s (%s) %s\n", algo
,
485 get_driver_name(crypto_blkcipher
, tfm
), e
);
490 b_size
= block_sizes
;
492 struct scatterlist sg
[TVMEMSIZE
];
494 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
495 printk("template (%u) too big for "
496 "tvmem (%lu)\n", *keysize
+ *b_size
,
497 TVMEMSIZE
* PAGE_SIZE
);
501 printk("test %u (%d bit key, %d byte blocks): ", i
,
502 *keysize
* 8, *b_size
);
504 memset(tvmem
[0], 0xff, PAGE_SIZE
);
506 /* set key, plain text and IV */
508 for (j
= 0; j
< tcount
; j
++) {
509 if (template[j
].klen
== *keysize
) {
510 key
= template[j
].key
;
515 ret
= crypto_blkcipher_setkey(tfm
, key
, *keysize
);
517 printk("setkey() failed flags=%x\n",
518 crypto_blkcipher_get_flags(tfm
));
522 sg_init_table(sg
, TVMEMSIZE
);
523 sg_set_buf(sg
, tvmem
[0] + *keysize
,
524 PAGE_SIZE
- *keysize
);
525 for (j
= 1; j
< TVMEMSIZE
; j
++) {
526 sg_set_buf(sg
+ j
, tvmem
[j
], PAGE_SIZE
);
527 memset (tvmem
[j
], 0xff, PAGE_SIZE
);
530 iv_len
= crypto_blkcipher_ivsize(tfm
);
532 memset(&iv
, 0xff, iv_len
);
533 crypto_blkcipher_set_iv(tfm
, iv
, iv_len
);
537 ret
= test_cipher_jiffies(&desc
, enc
, sg
,
540 ret
= test_cipher_cycles(&desc
, enc
, sg
,
544 printk("%s() failed flags=%x\n", e
, desc
.flags
);
554 crypto_free_blkcipher(tfm
);
557 static void test_hash_sg_init(struct scatterlist
*sg
)
561 sg_init_table(sg
, TVMEMSIZE
);
562 for (i
= 0; i
< TVMEMSIZE
; i
++) {
563 sg_set_buf(sg
+ i
, tvmem
[i
], PAGE_SIZE
);
564 memset(tvmem
[i
], 0xff, PAGE_SIZE
);
568 static inline int do_one_ahash_op(struct ahash_request
*req
, int ret
)
570 if (ret
== -EINPROGRESS
|| ret
== -EBUSY
) {
571 struct tcrypt_result
*tr
= req
->base
.data
;
573 wait_for_completion(&tr
->completion
);
574 reinit_completion(&tr
->completion
);
580 static int test_ahash_jiffies_digest(struct ahash_request
*req
, int blen
,
583 unsigned long start
, end
;
587 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
588 time_before(jiffies
, end
); bcount
++) {
589 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
594 printk("%6u opers/sec, %9lu bytes/sec\n",
595 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
600 static int test_ahash_jiffies(struct ahash_request
*req
, int blen
,
601 int plen
, char *out
, int secs
)
603 unsigned long start
, end
;
608 return test_ahash_jiffies_digest(req
, blen
, out
, secs
);
610 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
611 time_before(jiffies
, end
); bcount
++) {
612 ret
= do_one_ahash_op(req
, crypto_ahash_init(req
));
615 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
616 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
620 /* we assume there is enough space in 'out' for the result */
621 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
626 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
627 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
632 static int test_ahash_cycles_digest(struct ahash_request
*req
, int blen
,
635 unsigned long cycles
= 0;
639 for (i
= 0; i
< 4; i
++) {
640 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
645 /* The real thing. */
646 for (i
= 0; i
< 8; i
++) {
649 start
= get_cycles();
651 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
657 cycles
+= end
- start
;
664 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
665 cycles
/ 8, cycles
/ (8 * blen
));
670 static int test_ahash_cycles(struct ahash_request
*req
, int blen
,
673 unsigned long cycles
= 0;
677 return test_ahash_cycles_digest(req
, blen
, out
);
680 for (i
= 0; i
< 4; i
++) {
681 ret
= do_one_ahash_op(req
, crypto_ahash_init(req
));
684 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
685 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
689 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
694 /* The real thing. */
695 for (i
= 0; i
< 8; i
++) {
698 start
= get_cycles();
700 ret
= do_one_ahash_op(req
, crypto_ahash_init(req
));
703 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
704 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
708 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
714 cycles
+= end
- start
;
721 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
722 cycles
/ 8, cycles
/ (8 * blen
));
727 static void test_ahash_speed_common(const char *algo
, unsigned int secs
,
728 struct hash_speed
*speed
, unsigned mask
)
730 struct scatterlist sg
[TVMEMSIZE
];
731 struct tcrypt_result tresult
;
732 struct ahash_request
*req
;
733 struct crypto_ahash
*tfm
;
737 tfm
= crypto_alloc_ahash(algo
, 0, mask
);
739 pr_err("failed to load transform for %s: %ld\n",
744 printk(KERN_INFO
"\ntesting speed of async %s (%s)\n", algo
,
745 get_driver_name(crypto_ahash
, tfm
));
747 if (crypto_ahash_digestsize(tfm
) > MAX_DIGEST_SIZE
) {
748 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm
),
753 test_hash_sg_init(sg
);
754 req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
756 pr_err("ahash request allocation failure\n");
760 init_completion(&tresult
.completion
);
761 ahash_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
762 tcrypt_complete
, &tresult
);
764 output
= kmalloc(MAX_DIGEST_SIZE
, GFP_KERNEL
);
768 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
769 if (speed
[i
].blen
> TVMEMSIZE
* PAGE_SIZE
) {
770 pr_err("template (%u) too big for tvmem (%lu)\n",
771 speed
[i
].blen
, TVMEMSIZE
* PAGE_SIZE
);
776 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
777 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
779 ahash_request_set_crypt(req
, sg
, output
, speed
[i
].plen
);
782 ret
= test_ahash_jiffies(req
, speed
[i
].blen
,
783 speed
[i
].plen
, output
, secs
);
785 ret
= test_ahash_cycles(req
, speed
[i
].blen
,
786 speed
[i
].plen
, output
);
789 pr_err("hashing failed ret=%d\n", ret
);
797 ahash_request_free(req
);
800 crypto_free_ahash(tfm
);
803 static void test_ahash_speed(const char *algo
, unsigned int secs
,
804 struct hash_speed
*speed
)
806 return test_ahash_speed_common(algo
, secs
, speed
, 0);
809 static void test_hash_speed(const char *algo
, unsigned int secs
,
810 struct hash_speed
*speed
)
812 return test_ahash_speed_common(algo
, secs
, speed
, CRYPTO_ALG_ASYNC
);
815 static inline int do_one_acipher_op(struct ablkcipher_request
*req
, int ret
)
817 if (ret
== -EINPROGRESS
|| ret
== -EBUSY
) {
818 struct tcrypt_result
*tr
= req
->base
.data
;
820 wait_for_completion(&tr
->completion
);
821 reinit_completion(&tr
->completion
);
828 static int test_acipher_jiffies(struct ablkcipher_request
*req
, int enc
,
831 unsigned long start
, end
;
835 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
836 time_before(jiffies
, end
); bcount
++) {
838 ret
= do_one_acipher_op(req
,
839 crypto_ablkcipher_encrypt(req
));
841 ret
= do_one_acipher_op(req
,
842 crypto_ablkcipher_decrypt(req
));
848 pr_cont("%d operations in %d seconds (%ld bytes)\n",
849 bcount
, secs
, (long)bcount
* blen
);
853 static int test_acipher_cycles(struct ablkcipher_request
*req
, int enc
,
856 unsigned long cycles
= 0;
861 for (i
= 0; i
< 4; i
++) {
863 ret
= do_one_acipher_op(req
,
864 crypto_ablkcipher_encrypt(req
));
866 ret
= do_one_acipher_op(req
,
867 crypto_ablkcipher_decrypt(req
));
873 /* The real thing. */
874 for (i
= 0; i
< 8; i
++) {
877 start
= get_cycles();
879 ret
= do_one_acipher_op(req
,
880 crypto_ablkcipher_encrypt(req
));
882 ret
= do_one_acipher_op(req
,
883 crypto_ablkcipher_decrypt(req
));
889 cycles
+= end
- start
;
894 pr_cont("1 operation in %lu cycles (%d bytes)\n",
895 (cycles
+ 4) / 8, blen
);
900 static void test_acipher_speed(const char *algo
, int enc
, unsigned int secs
,
901 struct cipher_speed_template
*template,
902 unsigned int tcount
, u8
*keysize
)
904 unsigned int ret
, i
, j
, k
, iv_len
;
905 struct tcrypt_result tresult
;
908 struct ablkcipher_request
*req
;
909 struct crypto_ablkcipher
*tfm
;
918 init_completion(&tresult
.completion
);
920 tfm
= crypto_alloc_ablkcipher(algo
, 0, 0);
923 pr_err("failed to load transform for %s: %ld\n", algo
,
928 pr_info("\ntesting speed of async %s (%s) %s\n", algo
,
929 get_driver_name(crypto_ablkcipher
, tfm
), e
);
931 req
= ablkcipher_request_alloc(tfm
, GFP_KERNEL
);
933 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
938 ablkcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
939 tcrypt_complete
, &tresult
);
943 b_size
= block_sizes
;
946 struct scatterlist sg
[TVMEMSIZE
];
948 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
949 pr_err("template (%u) too big for "
950 "tvmem (%lu)\n", *keysize
+ *b_size
,
951 TVMEMSIZE
* PAGE_SIZE
);
955 pr_info("test %u (%d bit key, %d byte blocks): ", i
,
956 *keysize
* 8, *b_size
);
958 memset(tvmem
[0], 0xff, PAGE_SIZE
);
960 /* set key, plain text and IV */
962 for (j
= 0; j
< tcount
; j
++) {
963 if (template[j
].klen
== *keysize
) {
964 key
= template[j
].key
;
969 crypto_ablkcipher_clear_flags(tfm
, ~0);
971 ret
= crypto_ablkcipher_setkey(tfm
, key
, *keysize
);
973 pr_err("setkey() failed flags=%x\n",
974 crypto_ablkcipher_get_flags(tfm
));
978 k
= *keysize
+ *b_size
;
979 sg_init_table(sg
, DIV_ROUND_UP(k
, PAGE_SIZE
));
982 sg_set_buf(sg
, tvmem
[0] + *keysize
,
983 PAGE_SIZE
- *keysize
);
986 while (k
> PAGE_SIZE
) {
987 sg_set_buf(sg
+ j
, tvmem
[j
], PAGE_SIZE
);
988 memset(tvmem
[j
], 0xff, PAGE_SIZE
);
992 sg_set_buf(sg
+ j
, tvmem
[j
], k
);
993 memset(tvmem
[j
], 0xff, k
);
995 sg_set_buf(sg
, tvmem
[0] + *keysize
, *b_size
);
998 iv_len
= crypto_ablkcipher_ivsize(tfm
);
1000 memset(&iv
, 0xff, iv_len
);
1002 ablkcipher_request_set_crypt(req
, sg
, sg
, *b_size
, iv
);
1005 ret
= test_acipher_jiffies(req
, enc
,
1008 ret
= test_acipher_cycles(req
, enc
,
1012 pr_err("%s() failed flags=%x\n", e
,
1013 crypto_ablkcipher_get_flags(tfm
));
1023 ablkcipher_request_free(req
);
1025 crypto_free_ablkcipher(tfm
);
1028 static void test_available(void)
1030 char **name
= check
;
1033 printk("alg %s ", *name
);
1034 printk(crypto_has_alg(*name
, 0, 0) ?
1035 "found\n" : "not found\n");
1040 static inline int tcrypt_test(const char *alg
)
1044 ret
= alg_test(alg
, alg
, 0, 0);
1045 /* non-fips algs return -EINVAL in fips mode */
1046 if (fips_enabled
&& ret
== -EINVAL
)
1051 static int do_test(const char *alg
, u32 type
, u32 mask
, int m
)
1059 if (!crypto_has_alg(alg
, type
,
1060 mask
?: CRYPTO_ALG_TYPE_MASK
))
1065 for (i
= 1; i
< 200; i
++)
1066 ret
+= do_test(NULL
, 0, 0, i
);
1070 ret
+= tcrypt_test("md5");
1074 ret
+= tcrypt_test("sha1");
1078 ret
+= tcrypt_test("ecb(des)");
1079 ret
+= tcrypt_test("cbc(des)");
1080 ret
+= tcrypt_test("ctr(des)");
1084 ret
+= tcrypt_test("ecb(des3_ede)");
1085 ret
+= tcrypt_test("cbc(des3_ede)");
1086 ret
+= tcrypt_test("ctr(des3_ede)");
1090 ret
+= tcrypt_test("md4");
1094 ret
+= tcrypt_test("sha256");
1098 ret
+= tcrypt_test("ecb(blowfish)");
1099 ret
+= tcrypt_test("cbc(blowfish)");
1100 ret
+= tcrypt_test("ctr(blowfish)");
1104 ret
+= tcrypt_test("ecb(twofish)");
1105 ret
+= tcrypt_test("cbc(twofish)");
1106 ret
+= tcrypt_test("ctr(twofish)");
1107 ret
+= tcrypt_test("lrw(twofish)");
1108 ret
+= tcrypt_test("xts(twofish)");
1112 ret
+= tcrypt_test("ecb(serpent)");
1113 ret
+= tcrypt_test("cbc(serpent)");
1114 ret
+= tcrypt_test("ctr(serpent)");
1115 ret
+= tcrypt_test("lrw(serpent)");
1116 ret
+= tcrypt_test("xts(serpent)");
1120 ret
+= tcrypt_test("ecb(aes)");
1121 ret
+= tcrypt_test("cbc(aes)");
1122 ret
+= tcrypt_test("lrw(aes)");
1123 ret
+= tcrypt_test("xts(aes)");
1124 ret
+= tcrypt_test("ctr(aes)");
1125 ret
+= tcrypt_test("rfc3686(ctr(aes))");
1129 ret
+= tcrypt_test("sha384");
1133 ret
+= tcrypt_test("sha512");
1137 ret
+= tcrypt_test("deflate");
1141 ret
+= tcrypt_test("ecb(cast5)");
1142 ret
+= tcrypt_test("cbc(cast5)");
1143 ret
+= tcrypt_test("ctr(cast5)");
1147 ret
+= tcrypt_test("ecb(cast6)");
1148 ret
+= tcrypt_test("cbc(cast6)");
1149 ret
+= tcrypt_test("ctr(cast6)");
1150 ret
+= tcrypt_test("lrw(cast6)");
1151 ret
+= tcrypt_test("xts(cast6)");
1155 ret
+= tcrypt_test("ecb(arc4)");
1159 ret
+= tcrypt_test("michael_mic");
1163 ret
+= tcrypt_test("crc32c");
1167 ret
+= tcrypt_test("ecb(tea)");
1171 ret
+= tcrypt_test("ecb(xtea)");
1175 ret
+= tcrypt_test("ecb(khazad)");
1179 ret
+= tcrypt_test("wp512");
1183 ret
+= tcrypt_test("wp384");
1187 ret
+= tcrypt_test("wp256");
1191 ret
+= tcrypt_test("ecb(tnepres)");
1195 ret
+= tcrypt_test("ecb(anubis)");
1196 ret
+= tcrypt_test("cbc(anubis)");
1200 ret
+= tcrypt_test("tgr192");
1204 ret
+= tcrypt_test("tgr160");
1208 ret
+= tcrypt_test("tgr128");
1212 ret
+= tcrypt_test("ecb(xeta)");
1216 ret
+= tcrypt_test("pcbc(fcrypt)");
1220 ret
+= tcrypt_test("ecb(camellia)");
1221 ret
+= tcrypt_test("cbc(camellia)");
1222 ret
+= tcrypt_test("ctr(camellia)");
1223 ret
+= tcrypt_test("lrw(camellia)");
1224 ret
+= tcrypt_test("xts(camellia)");
1228 ret
+= tcrypt_test("sha224");
1232 ret
+= tcrypt_test("salsa20");
1236 ret
+= tcrypt_test("gcm(aes)");
1240 ret
+= tcrypt_test("lzo");
1244 ret
+= tcrypt_test("ccm(aes)");
1248 ret
+= tcrypt_test("cts(cbc(aes))");
1252 ret
+= tcrypt_test("rmd128");
1256 ret
+= tcrypt_test("rmd160");
1260 ret
+= tcrypt_test("rmd256");
1264 ret
+= tcrypt_test("rmd320");
1268 ret
+= tcrypt_test("ecb(seed)");
1272 ret
+= tcrypt_test("zlib");
1276 ret
+= tcrypt_test("rfc4309(ccm(aes))");
1280 ret
+= tcrypt_test("ghash");
1284 ret
+= tcrypt_test("crct10dif");
1288 ret
+= tcrypt_test("hmac(md5)");
1292 ret
+= tcrypt_test("hmac(sha1)");
1296 ret
+= tcrypt_test("hmac(sha256)");
1300 ret
+= tcrypt_test("hmac(sha384)");
1304 ret
+= tcrypt_test("hmac(sha512)");
1308 ret
+= tcrypt_test("hmac(sha224)");
1312 ret
+= tcrypt_test("xcbc(aes)");
1316 ret
+= tcrypt_test("hmac(rmd128)");
1320 ret
+= tcrypt_test("hmac(rmd160)");
1324 ret
+= tcrypt_test("vmac(aes)");
1328 ret
+= tcrypt_test("hmac(crc32)");
1332 ret
+= tcrypt_test("ansi_cprng");
1336 ret
+= tcrypt_test("rfc4106(gcm(aes))");
1340 ret
+= tcrypt_test("rfc4543(gcm(aes))");
1344 ret
+= tcrypt_test("cmac(aes)");
1348 ret
+= tcrypt_test("cmac(des3_ede)");
1352 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1356 ret
+= tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1360 ret
+= tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1363 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(des))");
1366 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
1369 ret
+= tcrypt_test("authenc(hmac(sha224),cbc(des))");
1372 ret
+= tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
1375 ret
+= tcrypt_test("authenc(hmac(sha256),cbc(des))");
1378 ret
+= tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
1381 ret
+= tcrypt_test("authenc(hmac(sha384),cbc(des))");
1384 ret
+= tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
1387 ret
+= tcrypt_test("authenc(hmac(sha512),cbc(des))");
1390 ret
+= tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
1393 test_cipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1394 speed_template_16_24_32
);
1395 test_cipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1396 speed_template_16_24_32
);
1397 test_cipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1398 speed_template_16_24_32
);
1399 test_cipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1400 speed_template_16_24_32
);
1401 test_cipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1402 speed_template_32_40_48
);
1403 test_cipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1404 speed_template_32_40_48
);
1405 test_cipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1406 speed_template_32_48_64
);
1407 test_cipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1408 speed_template_32_48_64
);
1409 test_cipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
1410 speed_template_16_24_32
);
1411 test_cipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
1412 speed_template_16_24_32
);
1416 test_cipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1417 des3_speed_template
, DES3_SPEED_VECTORS
,
1419 test_cipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1420 des3_speed_template
, DES3_SPEED_VECTORS
,
1422 test_cipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1423 des3_speed_template
, DES3_SPEED_VECTORS
,
1425 test_cipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1426 des3_speed_template
, DES3_SPEED_VECTORS
,
1428 test_cipher_speed("ctr(des3_ede)", ENCRYPT
, sec
,
1429 des3_speed_template
, DES3_SPEED_VECTORS
,
1431 test_cipher_speed("ctr(des3_ede)", DECRYPT
, sec
,
1432 des3_speed_template
, DES3_SPEED_VECTORS
,
1437 test_cipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1438 speed_template_16_24_32
);
1439 test_cipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1440 speed_template_16_24_32
);
1441 test_cipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1442 speed_template_16_24_32
);
1443 test_cipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1444 speed_template_16_24_32
);
1445 test_cipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
1446 speed_template_16_24_32
);
1447 test_cipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
1448 speed_template_16_24_32
);
1449 test_cipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
1450 speed_template_32_40_48
);
1451 test_cipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
1452 speed_template_32_40_48
);
1453 test_cipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
1454 speed_template_32_48_64
);
1455 test_cipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
1456 speed_template_32_48_64
);
1460 test_cipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1461 speed_template_8_32
);
1462 test_cipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
1463 speed_template_8_32
);
1464 test_cipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1465 speed_template_8_32
);
1466 test_cipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
1467 speed_template_8_32
);
1468 test_cipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1469 speed_template_8_32
);
1470 test_cipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
1471 speed_template_8_32
);
1475 test_cipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1477 test_cipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1479 test_cipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1481 test_cipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1486 test_cipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
1487 speed_template_16_24_32
);
1488 test_cipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
1489 speed_template_16_24_32
);
1490 test_cipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
1491 speed_template_16_24_32
);
1492 test_cipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
1493 speed_template_16_24_32
);
1494 test_cipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
1495 speed_template_16_24_32
);
1496 test_cipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
1497 speed_template_16_24_32
);
1498 test_cipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
1499 speed_template_32_40_48
);
1500 test_cipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
1501 speed_template_32_40_48
);
1502 test_cipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
1503 speed_template_32_48_64
);
1504 test_cipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
1505 speed_template_32_48_64
);
1509 test_cipher_speed("salsa20", ENCRYPT
, sec
, NULL
, 0,
1510 speed_template_16_32
);
1514 test_cipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
1515 speed_template_16_32
);
1516 test_cipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
1517 speed_template_16_32
);
1518 test_cipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
1519 speed_template_16_32
);
1520 test_cipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
1521 speed_template_16_32
);
1522 test_cipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
1523 speed_template_16_32
);
1524 test_cipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
1525 speed_template_16_32
);
1526 test_cipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
1527 speed_template_32_48
);
1528 test_cipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
1529 speed_template_32_48
);
1530 test_cipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
1531 speed_template_32_64
);
1532 test_cipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
1533 speed_template_32_64
);
1537 test_cipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
1542 test_cipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
1543 speed_template_8_16
);
1544 test_cipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
1545 speed_template_8_16
);
1546 test_cipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
1547 speed_template_8_16
);
1548 test_cipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
1549 speed_template_8_16
);
1550 test_cipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
1551 speed_template_8_16
);
1552 test_cipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
1553 speed_template_8_16
);
1557 test_cipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
1558 speed_template_16_32
);
1559 test_cipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
1560 speed_template_16_32
);
1561 test_cipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
1562 speed_template_16_32
);
1563 test_cipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
1564 speed_template_16_32
);
1565 test_cipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
1566 speed_template_16_32
);
1567 test_cipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
1568 speed_template_16_32
);
1569 test_cipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
1570 speed_template_32_48
);
1571 test_cipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
1572 speed_template_32_48
);
1573 test_cipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
1574 speed_template_32_64
);
1575 test_cipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
1576 speed_template_32_64
);
1580 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT
, sec
,
1581 NULL
, 0, 16, 16, aead_speed_template_20
);
1582 test_aead_speed("gcm(aes)", ENCRYPT
, sec
,
1583 NULL
, 0, 16, 8, speed_template_16_24_32
);
1587 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT
, sec
,
1588 NULL
, 0, 16, 16, aead_speed_template_19
);
1592 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT
, sec
,
1593 NULL
, 0, 16, 8, aead_speed_template_36
);
1597 test_cipher_speed("chacha20", ENCRYPT
, sec
, NULL
, 0,
1604 test_hash_speed(alg
, sec
, generic_hash_speed_template
);
1611 test_hash_speed("md4", sec
, generic_hash_speed_template
);
1612 if (mode
> 300 && mode
< 400) break;
1615 test_hash_speed("md5", sec
, generic_hash_speed_template
);
1616 if (mode
> 300 && mode
< 400) break;
1619 test_hash_speed("sha1", sec
, generic_hash_speed_template
);
1620 if (mode
> 300 && mode
< 400) break;
1623 test_hash_speed("sha256", sec
, generic_hash_speed_template
);
1624 if (mode
> 300 && mode
< 400) break;
1627 test_hash_speed("sha384", sec
, generic_hash_speed_template
);
1628 if (mode
> 300 && mode
< 400) break;
1631 test_hash_speed("sha512", sec
, generic_hash_speed_template
);
1632 if (mode
> 300 && mode
< 400) break;
1635 test_hash_speed("wp256", sec
, generic_hash_speed_template
);
1636 if (mode
> 300 && mode
< 400) break;
1639 test_hash_speed("wp384", sec
, generic_hash_speed_template
);
1640 if (mode
> 300 && mode
< 400) break;
1643 test_hash_speed("wp512", sec
, generic_hash_speed_template
);
1644 if (mode
> 300 && mode
< 400) break;
1647 test_hash_speed("tgr128", sec
, generic_hash_speed_template
);
1648 if (mode
> 300 && mode
< 400) break;
1651 test_hash_speed("tgr160", sec
, generic_hash_speed_template
);
1652 if (mode
> 300 && mode
< 400) break;
1655 test_hash_speed("tgr192", sec
, generic_hash_speed_template
);
1656 if (mode
> 300 && mode
< 400) break;
1659 test_hash_speed("sha224", sec
, generic_hash_speed_template
);
1660 if (mode
> 300 && mode
< 400) break;
1663 test_hash_speed("rmd128", sec
, generic_hash_speed_template
);
1664 if (mode
> 300 && mode
< 400) break;
1667 test_hash_speed("rmd160", sec
, generic_hash_speed_template
);
1668 if (mode
> 300 && mode
< 400) break;
1671 test_hash_speed("rmd256", sec
, generic_hash_speed_template
);
1672 if (mode
> 300 && mode
< 400) break;
1675 test_hash_speed("rmd320", sec
, generic_hash_speed_template
);
1676 if (mode
> 300 && mode
< 400) break;
1679 test_hash_speed("ghash-generic", sec
, hash_speed_template_16
);
1680 if (mode
> 300 && mode
< 400) break;
1683 test_hash_speed("crc32c", sec
, generic_hash_speed_template
);
1684 if (mode
> 300 && mode
< 400) break;
1687 test_hash_speed("crct10dif", sec
, generic_hash_speed_template
);
1688 if (mode
> 300 && mode
< 400) break;
1691 test_hash_speed("poly1305", sec
, poly1305_speed_template
);
1692 if (mode
> 300 && mode
< 400) break;
1699 test_ahash_speed(alg
, sec
, generic_hash_speed_template
);
1706 test_ahash_speed("md4", sec
, generic_hash_speed_template
);
1707 if (mode
> 400 && mode
< 500) break;
1710 test_ahash_speed("md5", sec
, generic_hash_speed_template
);
1711 if (mode
> 400 && mode
< 500) break;
1714 test_ahash_speed("sha1", sec
, generic_hash_speed_template
);
1715 if (mode
> 400 && mode
< 500) break;
1718 test_ahash_speed("sha256", sec
, generic_hash_speed_template
);
1719 if (mode
> 400 && mode
< 500) break;
1722 test_ahash_speed("sha384", sec
, generic_hash_speed_template
);
1723 if (mode
> 400 && mode
< 500) break;
1726 test_ahash_speed("sha512", sec
, generic_hash_speed_template
);
1727 if (mode
> 400 && mode
< 500) break;
1730 test_ahash_speed("wp256", sec
, generic_hash_speed_template
);
1731 if (mode
> 400 && mode
< 500) break;
1734 test_ahash_speed("wp384", sec
, generic_hash_speed_template
);
1735 if (mode
> 400 && mode
< 500) break;
1738 test_ahash_speed("wp512", sec
, generic_hash_speed_template
);
1739 if (mode
> 400 && mode
< 500) break;
1742 test_ahash_speed("tgr128", sec
, generic_hash_speed_template
);
1743 if (mode
> 400 && mode
< 500) break;
1746 test_ahash_speed("tgr160", sec
, generic_hash_speed_template
);
1747 if (mode
> 400 && mode
< 500) break;
1750 test_ahash_speed("tgr192", sec
, generic_hash_speed_template
);
1751 if (mode
> 400 && mode
< 500) break;
1754 test_ahash_speed("sha224", sec
, generic_hash_speed_template
);
1755 if (mode
> 400 && mode
< 500) break;
1758 test_ahash_speed("rmd128", sec
, generic_hash_speed_template
);
1759 if (mode
> 400 && mode
< 500) break;
1762 test_ahash_speed("rmd160", sec
, generic_hash_speed_template
);
1763 if (mode
> 400 && mode
< 500) break;
1766 test_ahash_speed("rmd256", sec
, generic_hash_speed_template
);
1767 if (mode
> 400 && mode
< 500) break;
1770 test_ahash_speed("rmd320", sec
, generic_hash_speed_template
);
1771 if (mode
> 400 && mode
< 500) break;
1777 test_acipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1778 speed_template_16_24_32
);
1779 test_acipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1780 speed_template_16_24_32
);
1781 test_acipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1782 speed_template_16_24_32
);
1783 test_acipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1784 speed_template_16_24_32
);
1785 test_acipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1786 speed_template_32_40_48
);
1787 test_acipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1788 speed_template_32_40_48
);
1789 test_acipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1790 speed_template_32_48_64
);
1791 test_acipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1792 speed_template_32_48_64
);
1793 test_acipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
1794 speed_template_16_24_32
);
1795 test_acipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
1796 speed_template_16_24_32
);
1797 test_acipher_speed("cfb(aes)", ENCRYPT
, sec
, NULL
, 0,
1798 speed_template_16_24_32
);
1799 test_acipher_speed("cfb(aes)", DECRYPT
, sec
, NULL
, 0,
1800 speed_template_16_24_32
);
1801 test_acipher_speed("ofb(aes)", ENCRYPT
, sec
, NULL
, 0,
1802 speed_template_16_24_32
);
1803 test_acipher_speed("ofb(aes)", DECRYPT
, sec
, NULL
, 0,
1804 speed_template_16_24_32
);
1805 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT
, sec
, NULL
, 0,
1806 speed_template_20_28_36
);
1807 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT
, sec
, NULL
, 0,
1808 speed_template_20_28_36
);
1812 test_acipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1813 des3_speed_template
, DES3_SPEED_VECTORS
,
1815 test_acipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1816 des3_speed_template
, DES3_SPEED_VECTORS
,
1818 test_acipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1819 des3_speed_template
, DES3_SPEED_VECTORS
,
1821 test_acipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1822 des3_speed_template
, DES3_SPEED_VECTORS
,
1824 test_acipher_speed("cfb(des3_ede)", ENCRYPT
, sec
,
1825 des3_speed_template
, DES3_SPEED_VECTORS
,
1827 test_acipher_speed("cfb(des3_ede)", DECRYPT
, sec
,
1828 des3_speed_template
, DES3_SPEED_VECTORS
,
1830 test_acipher_speed("ofb(des3_ede)", ENCRYPT
, sec
,
1831 des3_speed_template
, DES3_SPEED_VECTORS
,
1833 test_acipher_speed("ofb(des3_ede)", DECRYPT
, sec
,
1834 des3_speed_template
, DES3_SPEED_VECTORS
,
1839 test_acipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1841 test_acipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1843 test_acipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1845 test_acipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1847 test_acipher_speed("cfb(des)", ENCRYPT
, sec
, NULL
, 0,
1849 test_acipher_speed("cfb(des)", DECRYPT
, sec
, NULL
, 0,
1851 test_acipher_speed("ofb(des)", ENCRYPT
, sec
, NULL
, 0,
1853 test_acipher_speed("ofb(des)", DECRYPT
, sec
, NULL
, 0,
1858 test_acipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
1859 speed_template_16_32
);
1860 test_acipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
1861 speed_template_16_32
);
1862 test_acipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
1863 speed_template_16_32
);
1864 test_acipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
1865 speed_template_16_32
);
1866 test_acipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
1867 speed_template_16_32
);
1868 test_acipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
1869 speed_template_16_32
);
1870 test_acipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
1871 speed_template_32_48
);
1872 test_acipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
1873 speed_template_32_48
);
1874 test_acipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
1875 speed_template_32_64
);
1876 test_acipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
1877 speed_template_32_64
);
1881 test_acipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1882 speed_template_16_24_32
);
1883 test_acipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1884 speed_template_16_24_32
);
1885 test_acipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1886 speed_template_16_24_32
);
1887 test_acipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1888 speed_template_16_24_32
);
1889 test_acipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
1890 speed_template_16_24_32
);
1891 test_acipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
1892 speed_template_16_24_32
);
1893 test_acipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
1894 speed_template_32_40_48
);
1895 test_acipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
1896 speed_template_32_40_48
);
1897 test_acipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
1898 speed_template_32_48_64
);
1899 test_acipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
1900 speed_template_32_48_64
);
1904 test_acipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
1909 test_acipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
1910 speed_template_8_16
);
1911 test_acipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
1912 speed_template_8_16
);
1913 test_acipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
1914 speed_template_8_16
);
1915 test_acipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
1916 speed_template_8_16
);
1917 test_acipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
1918 speed_template_8_16
);
1919 test_acipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
1920 speed_template_8_16
);
1924 test_acipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
1925 speed_template_16_32
);
1926 test_acipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
1927 speed_template_16_32
);
1928 test_acipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
1929 speed_template_16_32
);
1930 test_acipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
1931 speed_template_16_32
);
1932 test_acipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
1933 speed_template_16_32
);
1934 test_acipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
1935 speed_template_16_32
);
1936 test_acipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
1937 speed_template_32_48
);
1938 test_acipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
1939 speed_template_32_48
);
1940 test_acipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
1941 speed_template_32_64
);
1942 test_acipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
1943 speed_template_32_64
);
1947 test_acipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
1948 speed_template_16_32
);
1949 test_acipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
1950 speed_template_16_32
);
1951 test_acipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
1952 speed_template_16_32
);
1953 test_acipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
1954 speed_template_16_32
);
1955 test_acipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
1956 speed_template_16_32
);
1957 test_acipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
1958 speed_template_16_32
);
1959 test_acipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
1960 speed_template_32_48
);
1961 test_acipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
1962 speed_template_32_48
);
1963 test_acipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
1964 speed_template_32_64
);
1965 test_acipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
1966 speed_template_32_64
);
1970 test_acipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1971 speed_template_8_32
);
1972 test_acipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
1973 speed_template_8_32
);
1974 test_acipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1975 speed_template_8_32
);
1976 test_acipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
1977 speed_template_8_32
);
1978 test_acipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1979 speed_template_8_32
);
1980 test_acipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
1981 speed_template_8_32
);
1992 static int __init
tcrypt_mod_init(void)
1997 for (i
= 0; i
< TVMEMSIZE
; i
++) {
1998 tvmem
[i
] = (void *)__get_free_page(GFP_KERNEL
);
2003 err
= do_test(alg
, type
, mask
, mode
);
2006 printk(KERN_ERR
"tcrypt: one or more tests failed!\n");
2010 /* We intentionaly return -EAGAIN to prevent keeping the module,
2011 * unless we're running in fips mode. It does all its work from
2012 * init() and doesn't offer any runtime functionality, but in
2013 * the fips case, checking for a successful load is helpful.
2014 * => we don't need it in the memory, do we?
2021 for (i
= 0; i
< TVMEMSIZE
&& tvmem
[i
]; i
++)
2022 free_page((unsigned long)tvmem
[i
]);
2028 * If an init function is provided, an exit function must also be provided
2029 * to allow module unload.
2031 static void __exit
tcrypt_mod_fini(void) { }
2033 module_init(tcrypt_mod_init
);
2034 module_exit(tcrypt_mod_fini
);
2036 module_param(alg
, charp
, 0);
2037 module_param(type
, uint
, 0);
2038 module_param(mask
, uint
, 0);
2039 module_param(mode
, int, 0);
2040 module_param(sec
, uint
, 0);
2041 MODULE_PARM_DESC(sec
, "Length in seconds of speed tests "
2042 "(defaults to zero which uses CPU cycles instead)");
2044 MODULE_LICENSE("GPL");
2045 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2046 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");