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);
296 for (k
= 0; k
< np
; k
++)
297 sg_set_buf(&sg
[k
+ 1], xbuf
[k
], PAGE_SIZE
);
300 sg_set_buf(&sg
[k
+ 1], xbuf
[k
], rem
);
303 static void test_aead_speed(const char *algo
, int enc
, unsigned int secs
,
304 struct aead_speed_template
*template,
305 unsigned int tcount
, u8 authsize
,
306 unsigned int aad_size
, u8
*keysize
)
309 struct crypto_aead
*tfm
;
312 struct aead_request
*req
;
313 struct scatterlist
*sg
;
314 struct scatterlist
*sgout
;
318 char *xbuf
[XBUFSIZE
];
319 char *xoutbuf
[XBUFSIZE
];
320 char *axbuf
[XBUFSIZE
];
321 unsigned int *b_size
;
323 struct tcrypt_result result
;
325 iv
= kzalloc(MAX_IVLEN
, GFP_KERNEL
);
329 if (aad_size
>= PAGE_SIZE
) {
330 pr_err("associate data length (%u) too big\n", aad_size
);
339 if (testmgr_alloc_buf(xbuf
))
341 if (testmgr_alloc_buf(axbuf
))
343 if (testmgr_alloc_buf(xoutbuf
))
346 sg
= kmalloc(sizeof(*sg
) * 9 * 2, GFP_KERNEL
);
351 tfm
= crypto_alloc_aead(algo
, 0, 0);
354 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo
,
359 init_completion(&result
.completion
);
360 printk(KERN_INFO
"\ntesting speed of %s (%s) %s\n", algo
,
361 get_driver_name(crypto_aead
, tfm
), e
);
363 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
365 pr_err("alg: aead: Failed to allocate request for %s\n",
370 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
371 tcrypt_complete
, &result
);
378 memset(assoc
, 0xff, aad_size
);
380 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
381 pr_err("template (%u) too big for tvmem (%lu)\n",
383 TVMEMSIZE
* PAGE_SIZE
);
388 for (j
= 0; j
< tcount
; j
++) {
389 if (template[j
].klen
== *keysize
) {
390 key
= template[j
].key
;
394 ret
= crypto_aead_setkey(tfm
, key
, *keysize
);
395 ret
= crypto_aead_setauthsize(tfm
, authsize
);
397 iv_len
= crypto_aead_ivsize(tfm
);
399 memset(iv
, 0xff, iv_len
);
401 crypto_aead_clear_flags(tfm
, ~0);
402 printk(KERN_INFO
"test %u (%d bit key, %d byte blocks): ",
403 i
, *keysize
* 8, *b_size
);
406 memset(tvmem
[0], 0xff, PAGE_SIZE
);
409 pr_err("setkey() failed flags=%x\n",
410 crypto_aead_get_flags(tfm
));
414 sg_init_aead(sg
, xbuf
,
415 *b_size
+ (enc
? 0 : authsize
));
417 sg_init_aead(sgout
, xoutbuf
,
418 *b_size
+ (enc
? authsize
: 0));
420 sg_set_buf(&sg
[0], assoc
, aad_size
);
421 sg_set_buf(&sgout
[0], assoc
, aad_size
);
423 aead_request_set_crypt(req
, sg
, sgout
,
424 *b_size
+ (enc
? 0 : authsize
),
426 aead_request_set_ad(req
, aad_size
);
429 ret
= test_aead_jiffies(req
, enc
, *b_size
,
432 ret
= test_aead_cycles(req
, enc
, *b_size
);
435 pr_err("%s() failed return code=%d\n", e
, ret
);
445 aead_request_free(req
);
447 crypto_free_aead(tfm
);
451 testmgr_free_buf(xoutbuf
);
453 testmgr_free_buf(axbuf
);
455 testmgr_free_buf(xbuf
);
461 static void test_cipher_speed(const char *algo
, int enc
, unsigned int secs
,
462 struct cipher_speed_template
*template,
463 unsigned int tcount
, u8
*keysize
)
465 unsigned int ret
, i
, j
, iv_len
;
468 struct crypto_blkcipher
*tfm
;
469 struct blkcipher_desc desc
;
478 tfm
= crypto_alloc_blkcipher(algo
, 0, CRYPTO_ALG_ASYNC
);
481 printk("failed to load transform for %s: %ld\n", algo
,
488 printk(KERN_INFO
"\ntesting speed of %s (%s) %s\n", algo
,
489 get_driver_name(crypto_blkcipher
, tfm
), e
);
494 b_size
= block_sizes
;
496 struct scatterlist sg
[TVMEMSIZE
];
498 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
499 printk("template (%u) too big for "
500 "tvmem (%lu)\n", *keysize
+ *b_size
,
501 TVMEMSIZE
* PAGE_SIZE
);
505 printk("test %u (%d bit key, %d byte blocks): ", i
,
506 *keysize
* 8, *b_size
);
508 memset(tvmem
[0], 0xff, PAGE_SIZE
);
510 /* set key, plain text and IV */
512 for (j
= 0; j
< tcount
; j
++) {
513 if (template[j
].klen
== *keysize
) {
514 key
= template[j
].key
;
519 ret
= crypto_blkcipher_setkey(tfm
, key
, *keysize
);
521 printk("setkey() failed flags=%x\n",
522 crypto_blkcipher_get_flags(tfm
));
526 sg_init_table(sg
, TVMEMSIZE
);
527 sg_set_buf(sg
, tvmem
[0] + *keysize
,
528 PAGE_SIZE
- *keysize
);
529 for (j
= 1; j
< TVMEMSIZE
; j
++) {
530 sg_set_buf(sg
+ j
, tvmem
[j
], PAGE_SIZE
);
531 memset (tvmem
[j
], 0xff, PAGE_SIZE
);
534 iv_len
= crypto_blkcipher_ivsize(tfm
);
536 memset(&iv
, 0xff, iv_len
);
537 crypto_blkcipher_set_iv(tfm
, iv
, iv_len
);
541 ret
= test_cipher_jiffies(&desc
, enc
, sg
,
544 ret
= test_cipher_cycles(&desc
, enc
, sg
,
548 printk("%s() failed flags=%x\n", e
, desc
.flags
);
558 crypto_free_blkcipher(tfm
);
561 static int test_hash_jiffies_digest(struct hash_desc
*desc
,
562 struct scatterlist
*sg
, int blen
,
565 unsigned long start
, end
;
569 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
570 time_before(jiffies
, end
); bcount
++) {
571 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
576 printk("%6u opers/sec, %9lu bytes/sec\n",
577 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
582 static int test_hash_jiffies(struct hash_desc
*desc
, struct scatterlist
*sg
,
583 int blen
, int plen
, char *out
, int secs
)
585 unsigned long start
, end
;
590 return test_hash_jiffies_digest(desc
, sg
, blen
, out
, secs
);
592 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
593 time_before(jiffies
, end
); bcount
++) {
594 ret
= crypto_hash_init(desc
);
597 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
598 ret
= crypto_hash_update(desc
, sg
, plen
);
602 /* we assume there is enough space in 'out' for the result */
603 ret
= crypto_hash_final(desc
, out
);
608 printk("%6u opers/sec, %9lu bytes/sec\n",
609 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
614 static int test_hash_cycles_digest(struct hash_desc
*desc
,
615 struct scatterlist
*sg
, int blen
, char *out
)
617 unsigned long cycles
= 0;
624 for (i
= 0; i
< 4; i
++) {
625 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
630 /* The real thing. */
631 for (i
= 0; i
< 8; i
++) {
634 start
= get_cycles();
636 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
642 cycles
+= end
- start
;
651 printk("%6lu cycles/operation, %4lu cycles/byte\n",
652 cycles
/ 8, cycles
/ (8 * blen
));
657 static int test_hash_cycles(struct hash_desc
*desc
, struct scatterlist
*sg
,
658 int blen
, int plen
, char *out
)
660 unsigned long cycles
= 0;
665 return test_hash_cycles_digest(desc
, sg
, blen
, out
);
670 for (i
= 0; i
< 4; i
++) {
671 ret
= crypto_hash_init(desc
);
674 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
675 ret
= crypto_hash_update(desc
, sg
, plen
);
679 ret
= crypto_hash_final(desc
, out
);
684 /* The real thing. */
685 for (i
= 0; i
< 8; i
++) {
688 start
= get_cycles();
690 ret
= crypto_hash_init(desc
);
693 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
694 ret
= crypto_hash_update(desc
, sg
, plen
);
698 ret
= crypto_hash_final(desc
, out
);
704 cycles
+= end
- start
;
713 printk("%6lu cycles/operation, %4lu cycles/byte\n",
714 cycles
/ 8, cycles
/ (8 * blen
));
719 static void test_hash_sg_init(struct scatterlist
*sg
)
723 sg_init_table(sg
, TVMEMSIZE
);
724 for (i
= 0; i
< TVMEMSIZE
; i
++) {
725 sg_set_buf(sg
+ i
, tvmem
[i
], PAGE_SIZE
);
726 memset(tvmem
[i
], 0xff, PAGE_SIZE
);
730 static void test_hash_speed(const char *algo
, unsigned int secs
,
731 struct hash_speed
*speed
)
733 struct scatterlist sg
[TVMEMSIZE
];
734 struct crypto_hash
*tfm
;
735 struct hash_desc desc
;
736 static char output
[1024];
740 tfm
= crypto_alloc_hash(algo
, 0, CRYPTO_ALG_ASYNC
);
743 printk(KERN_ERR
"failed to load transform for %s: %ld\n", algo
,
748 printk(KERN_INFO
"\ntesting speed of %s (%s)\n", algo
,
749 get_driver_name(crypto_hash
, tfm
));
754 if (crypto_hash_digestsize(tfm
) > sizeof(output
)) {
755 printk(KERN_ERR
"digestsize(%u) > outputbuffer(%zu)\n",
756 crypto_hash_digestsize(tfm
), sizeof(output
));
760 test_hash_sg_init(sg
);
761 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
762 if (speed
[i
].blen
> TVMEMSIZE
* PAGE_SIZE
) {
764 "template (%u) too big for tvmem (%lu)\n",
765 speed
[i
].blen
, TVMEMSIZE
* PAGE_SIZE
);
770 crypto_hash_setkey(tfm
, tvmem
[0], speed
[i
].klen
);
772 printk(KERN_INFO
"test%3u "
773 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
774 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
777 ret
= test_hash_jiffies(&desc
, sg
, speed
[i
].blen
,
778 speed
[i
].plen
, output
, secs
);
780 ret
= test_hash_cycles(&desc
, sg
, speed
[i
].blen
,
781 speed
[i
].plen
, output
);
784 printk(KERN_ERR
"hashing failed ret=%d\n", ret
);
790 crypto_free_hash(tfm
);
793 static inline int do_one_ahash_op(struct ahash_request
*req
, int ret
)
795 if (ret
== -EINPROGRESS
|| ret
== -EBUSY
) {
796 struct tcrypt_result
*tr
= req
->base
.data
;
798 wait_for_completion(&tr
->completion
);
799 reinit_completion(&tr
->completion
);
805 static int test_ahash_jiffies_digest(struct ahash_request
*req
, int blen
,
808 unsigned long start
, end
;
812 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
813 time_before(jiffies
, end
); bcount
++) {
814 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
819 printk("%6u opers/sec, %9lu bytes/sec\n",
820 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
825 static int test_ahash_jiffies(struct ahash_request
*req
, int blen
,
826 int plen
, char *out
, int secs
)
828 unsigned long start
, end
;
833 return test_ahash_jiffies_digest(req
, blen
, out
, secs
);
835 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
836 time_before(jiffies
, end
); bcount
++) {
837 ret
= do_one_ahash_op(req
, crypto_ahash_init(req
));
840 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
841 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
845 /* we assume there is enough space in 'out' for the result */
846 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
851 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
852 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
857 static int test_ahash_cycles_digest(struct ahash_request
*req
, int blen
,
860 unsigned long cycles
= 0;
864 for (i
= 0; i
< 4; i
++) {
865 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
870 /* The real thing. */
871 for (i
= 0; i
< 8; i
++) {
874 start
= get_cycles();
876 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
882 cycles
+= end
- start
;
889 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
890 cycles
/ 8, cycles
/ (8 * blen
));
895 static int test_ahash_cycles(struct ahash_request
*req
, int blen
,
898 unsigned long cycles
= 0;
902 return test_ahash_cycles_digest(req
, blen
, out
);
905 for (i
= 0; i
< 4; i
++) {
906 ret
= do_one_ahash_op(req
, crypto_ahash_init(req
));
909 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
910 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
914 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
919 /* The real thing. */
920 for (i
= 0; i
< 8; i
++) {
923 start
= get_cycles();
925 ret
= do_one_ahash_op(req
, crypto_ahash_init(req
));
928 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
929 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
933 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
939 cycles
+= end
- start
;
946 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
947 cycles
/ 8, cycles
/ (8 * blen
));
952 static void test_ahash_speed(const char *algo
, unsigned int secs
,
953 struct hash_speed
*speed
)
955 struct scatterlist sg
[TVMEMSIZE
];
956 struct tcrypt_result tresult
;
957 struct ahash_request
*req
;
958 struct crypto_ahash
*tfm
;
962 tfm
= crypto_alloc_ahash(algo
, 0, 0);
964 pr_err("failed to load transform for %s: %ld\n",
969 printk(KERN_INFO
"\ntesting speed of async %s (%s)\n", algo
,
970 get_driver_name(crypto_ahash
, tfm
));
972 if (crypto_ahash_digestsize(tfm
) > MAX_DIGEST_SIZE
) {
973 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm
),
978 test_hash_sg_init(sg
);
979 req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
981 pr_err("ahash request allocation failure\n");
985 init_completion(&tresult
.completion
);
986 ahash_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
987 tcrypt_complete
, &tresult
);
989 output
= kmalloc(MAX_DIGEST_SIZE
, GFP_KERNEL
);
993 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
994 if (speed
[i
].blen
> TVMEMSIZE
* PAGE_SIZE
) {
995 pr_err("template (%u) too big for tvmem (%lu)\n",
996 speed
[i
].blen
, TVMEMSIZE
* PAGE_SIZE
);
1001 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
1002 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
1004 ahash_request_set_crypt(req
, sg
, output
, speed
[i
].plen
);
1007 ret
= test_ahash_jiffies(req
, speed
[i
].blen
,
1008 speed
[i
].plen
, output
, secs
);
1010 ret
= test_ahash_cycles(req
, speed
[i
].blen
,
1011 speed
[i
].plen
, output
);
1014 pr_err("hashing failed ret=%d\n", ret
);
1022 ahash_request_free(req
);
1025 crypto_free_ahash(tfm
);
1028 static inline int do_one_acipher_op(struct ablkcipher_request
*req
, int ret
)
1030 if (ret
== -EINPROGRESS
|| ret
== -EBUSY
) {
1031 struct tcrypt_result
*tr
= req
->base
.data
;
1033 wait_for_completion(&tr
->completion
);
1034 reinit_completion(&tr
->completion
);
1041 static int test_acipher_jiffies(struct ablkcipher_request
*req
, int enc
,
1044 unsigned long start
, end
;
1048 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
1049 time_before(jiffies
, end
); bcount
++) {
1051 ret
= do_one_acipher_op(req
,
1052 crypto_ablkcipher_encrypt(req
));
1054 ret
= do_one_acipher_op(req
,
1055 crypto_ablkcipher_decrypt(req
));
1061 pr_cont("%d operations in %d seconds (%ld bytes)\n",
1062 bcount
, secs
, (long)bcount
* blen
);
1066 static int test_acipher_cycles(struct ablkcipher_request
*req
, int enc
,
1069 unsigned long cycles
= 0;
1074 for (i
= 0; i
< 4; i
++) {
1076 ret
= do_one_acipher_op(req
,
1077 crypto_ablkcipher_encrypt(req
));
1079 ret
= do_one_acipher_op(req
,
1080 crypto_ablkcipher_decrypt(req
));
1086 /* The real thing. */
1087 for (i
= 0; i
< 8; i
++) {
1088 cycles_t start
, end
;
1090 start
= get_cycles();
1092 ret
= do_one_acipher_op(req
,
1093 crypto_ablkcipher_encrypt(req
));
1095 ret
= do_one_acipher_op(req
,
1096 crypto_ablkcipher_decrypt(req
));
1102 cycles
+= end
- start
;
1107 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1108 (cycles
+ 4) / 8, blen
);
1113 static void test_acipher_speed(const char *algo
, int enc
, unsigned int secs
,
1114 struct cipher_speed_template
*template,
1115 unsigned int tcount
, u8
*keysize
)
1117 unsigned int ret
, i
, j
, k
, iv_len
;
1118 struct tcrypt_result tresult
;
1121 struct ablkcipher_request
*req
;
1122 struct crypto_ablkcipher
*tfm
;
1131 init_completion(&tresult
.completion
);
1133 tfm
= crypto_alloc_ablkcipher(algo
, 0, 0);
1136 pr_err("failed to load transform for %s: %ld\n", algo
,
1141 pr_info("\ntesting speed of async %s (%s) %s\n", algo
,
1142 get_driver_name(crypto_ablkcipher
, tfm
), e
);
1144 req
= ablkcipher_request_alloc(tfm
, GFP_KERNEL
);
1146 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1151 ablkcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
1152 tcrypt_complete
, &tresult
);
1156 b_size
= block_sizes
;
1159 struct scatterlist sg
[TVMEMSIZE
];
1161 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
1162 pr_err("template (%u) too big for "
1163 "tvmem (%lu)\n", *keysize
+ *b_size
,
1164 TVMEMSIZE
* PAGE_SIZE
);
1168 pr_info("test %u (%d bit key, %d byte blocks): ", i
,
1169 *keysize
* 8, *b_size
);
1171 memset(tvmem
[0], 0xff, PAGE_SIZE
);
1173 /* set key, plain text and IV */
1175 for (j
= 0; j
< tcount
; j
++) {
1176 if (template[j
].klen
== *keysize
) {
1177 key
= template[j
].key
;
1182 crypto_ablkcipher_clear_flags(tfm
, ~0);
1184 ret
= crypto_ablkcipher_setkey(tfm
, key
, *keysize
);
1186 pr_err("setkey() failed flags=%x\n",
1187 crypto_ablkcipher_get_flags(tfm
));
1191 k
= *keysize
+ *b_size
;
1192 sg_init_table(sg
, DIV_ROUND_UP(k
, PAGE_SIZE
));
1194 if (k
> PAGE_SIZE
) {
1195 sg_set_buf(sg
, tvmem
[0] + *keysize
,
1196 PAGE_SIZE
- *keysize
);
1199 while (k
> PAGE_SIZE
) {
1200 sg_set_buf(sg
+ j
, tvmem
[j
], PAGE_SIZE
);
1201 memset(tvmem
[j
], 0xff, PAGE_SIZE
);
1205 sg_set_buf(sg
+ j
, tvmem
[j
], k
);
1206 memset(tvmem
[j
], 0xff, k
);
1208 sg_set_buf(sg
, tvmem
[0] + *keysize
, *b_size
);
1211 iv_len
= crypto_ablkcipher_ivsize(tfm
);
1213 memset(&iv
, 0xff, iv_len
);
1215 ablkcipher_request_set_crypt(req
, sg
, sg
, *b_size
, iv
);
1218 ret
= test_acipher_jiffies(req
, enc
,
1221 ret
= test_acipher_cycles(req
, enc
,
1225 pr_err("%s() failed flags=%x\n", e
,
1226 crypto_ablkcipher_get_flags(tfm
));
1236 ablkcipher_request_free(req
);
1238 crypto_free_ablkcipher(tfm
);
1241 static void test_available(void)
1243 char **name
= check
;
1246 printk("alg %s ", *name
);
1247 printk(crypto_has_alg(*name
, 0, 0) ?
1248 "found\n" : "not found\n");
1253 static inline int tcrypt_test(const char *alg
)
1257 ret
= alg_test(alg
, alg
, 0, 0);
1258 /* non-fips algs return -EINVAL in fips mode */
1259 if (fips_enabled
&& ret
== -EINVAL
)
1264 static int do_test(const char *alg
, u32 type
, u32 mask
, int m
)
1272 if (!crypto_has_alg(alg
, type
,
1273 mask
?: CRYPTO_ALG_TYPE_MASK
))
1278 for (i
= 1; i
< 200; i
++)
1279 ret
+= do_test(NULL
, 0, 0, i
);
1283 ret
+= tcrypt_test("md5");
1287 ret
+= tcrypt_test("sha1");
1291 ret
+= tcrypt_test("ecb(des)");
1292 ret
+= tcrypt_test("cbc(des)");
1293 ret
+= tcrypt_test("ctr(des)");
1297 ret
+= tcrypt_test("ecb(des3_ede)");
1298 ret
+= tcrypt_test("cbc(des3_ede)");
1299 ret
+= tcrypt_test("ctr(des3_ede)");
1303 ret
+= tcrypt_test("md4");
1307 ret
+= tcrypt_test("sha256");
1311 ret
+= tcrypt_test("ecb(blowfish)");
1312 ret
+= tcrypt_test("cbc(blowfish)");
1313 ret
+= tcrypt_test("ctr(blowfish)");
1317 ret
+= tcrypt_test("ecb(twofish)");
1318 ret
+= tcrypt_test("cbc(twofish)");
1319 ret
+= tcrypt_test("ctr(twofish)");
1320 ret
+= tcrypt_test("lrw(twofish)");
1321 ret
+= tcrypt_test("xts(twofish)");
1325 ret
+= tcrypt_test("ecb(serpent)");
1326 ret
+= tcrypt_test("cbc(serpent)");
1327 ret
+= tcrypt_test("ctr(serpent)");
1328 ret
+= tcrypt_test("lrw(serpent)");
1329 ret
+= tcrypt_test("xts(serpent)");
1333 ret
+= tcrypt_test("ecb(aes)");
1334 ret
+= tcrypt_test("cbc(aes)");
1335 ret
+= tcrypt_test("lrw(aes)");
1336 ret
+= tcrypt_test("xts(aes)");
1337 ret
+= tcrypt_test("ctr(aes)");
1338 ret
+= tcrypt_test("rfc3686(ctr(aes))");
1342 ret
+= tcrypt_test("sha384");
1346 ret
+= tcrypt_test("sha512");
1350 ret
+= tcrypt_test("deflate");
1354 ret
+= tcrypt_test("ecb(cast5)");
1355 ret
+= tcrypt_test("cbc(cast5)");
1356 ret
+= tcrypt_test("ctr(cast5)");
1360 ret
+= tcrypt_test("ecb(cast6)");
1361 ret
+= tcrypt_test("cbc(cast6)");
1362 ret
+= tcrypt_test("ctr(cast6)");
1363 ret
+= tcrypt_test("lrw(cast6)");
1364 ret
+= tcrypt_test("xts(cast6)");
1368 ret
+= tcrypt_test("ecb(arc4)");
1372 ret
+= tcrypt_test("michael_mic");
1376 ret
+= tcrypt_test("crc32c");
1380 ret
+= tcrypt_test("ecb(tea)");
1384 ret
+= tcrypt_test("ecb(xtea)");
1388 ret
+= tcrypt_test("ecb(khazad)");
1392 ret
+= tcrypt_test("wp512");
1396 ret
+= tcrypt_test("wp384");
1400 ret
+= tcrypt_test("wp256");
1404 ret
+= tcrypt_test("ecb(tnepres)");
1408 ret
+= tcrypt_test("ecb(anubis)");
1409 ret
+= tcrypt_test("cbc(anubis)");
1413 ret
+= tcrypt_test("tgr192");
1417 ret
+= tcrypt_test("tgr160");
1421 ret
+= tcrypt_test("tgr128");
1425 ret
+= tcrypt_test("ecb(xeta)");
1429 ret
+= tcrypt_test("pcbc(fcrypt)");
1433 ret
+= tcrypt_test("ecb(camellia)");
1434 ret
+= tcrypt_test("cbc(camellia)");
1435 ret
+= tcrypt_test("ctr(camellia)");
1436 ret
+= tcrypt_test("lrw(camellia)");
1437 ret
+= tcrypt_test("xts(camellia)");
1441 ret
+= tcrypt_test("sha224");
1445 ret
+= tcrypt_test("salsa20");
1449 ret
+= tcrypt_test("gcm(aes)");
1453 ret
+= tcrypt_test("lzo");
1457 ret
+= tcrypt_test("ccm(aes)");
1461 ret
+= tcrypt_test("cts(cbc(aes))");
1465 ret
+= tcrypt_test("rmd128");
1469 ret
+= tcrypt_test("rmd160");
1473 ret
+= tcrypt_test("rmd256");
1477 ret
+= tcrypt_test("rmd320");
1481 ret
+= tcrypt_test("ecb(seed)");
1485 ret
+= tcrypt_test("zlib");
1489 ret
+= tcrypt_test("rfc4309(ccm(aes))");
1493 ret
+= tcrypt_test("ghash");
1497 ret
+= tcrypt_test("crct10dif");
1501 ret
+= tcrypt_test("hmac(md5)");
1505 ret
+= tcrypt_test("hmac(sha1)");
1509 ret
+= tcrypt_test("hmac(sha256)");
1513 ret
+= tcrypt_test("hmac(sha384)");
1517 ret
+= tcrypt_test("hmac(sha512)");
1521 ret
+= tcrypt_test("hmac(sha224)");
1525 ret
+= tcrypt_test("xcbc(aes)");
1529 ret
+= tcrypt_test("hmac(rmd128)");
1533 ret
+= tcrypt_test("hmac(rmd160)");
1537 ret
+= tcrypt_test("vmac(aes)");
1541 ret
+= tcrypt_test("hmac(crc32)");
1545 ret
+= tcrypt_test("ansi_cprng");
1549 ret
+= tcrypt_test("rfc4106(gcm(aes))");
1553 ret
+= tcrypt_test("rfc4543(gcm(aes))");
1557 ret
+= tcrypt_test("cmac(aes)");
1561 ret
+= tcrypt_test("cmac(des3_ede)");
1565 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1569 ret
+= tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1573 ret
+= tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1576 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(des))");
1579 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
1582 ret
+= tcrypt_test("authenc(hmac(sha224),cbc(des))");
1585 ret
+= tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
1588 ret
+= tcrypt_test("authenc(hmac(sha256),cbc(des))");
1591 ret
+= tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
1594 ret
+= tcrypt_test("authenc(hmac(sha384),cbc(des))");
1597 ret
+= tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
1600 ret
+= tcrypt_test("authenc(hmac(sha512),cbc(des))");
1603 ret
+= tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
1606 test_cipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1607 speed_template_16_24_32
);
1608 test_cipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1609 speed_template_16_24_32
);
1610 test_cipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1611 speed_template_16_24_32
);
1612 test_cipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1613 speed_template_16_24_32
);
1614 test_cipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1615 speed_template_32_40_48
);
1616 test_cipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1617 speed_template_32_40_48
);
1618 test_cipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1619 speed_template_32_48_64
);
1620 test_cipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1621 speed_template_32_48_64
);
1622 test_cipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
1623 speed_template_16_24_32
);
1624 test_cipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
1625 speed_template_16_24_32
);
1629 test_cipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1630 des3_speed_template
, DES3_SPEED_VECTORS
,
1632 test_cipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1633 des3_speed_template
, DES3_SPEED_VECTORS
,
1635 test_cipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1636 des3_speed_template
, DES3_SPEED_VECTORS
,
1638 test_cipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1639 des3_speed_template
, DES3_SPEED_VECTORS
,
1641 test_cipher_speed("ctr(des3_ede)", ENCRYPT
, sec
,
1642 des3_speed_template
, DES3_SPEED_VECTORS
,
1644 test_cipher_speed("ctr(des3_ede)", DECRYPT
, sec
,
1645 des3_speed_template
, DES3_SPEED_VECTORS
,
1650 test_cipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1651 speed_template_16_24_32
);
1652 test_cipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1653 speed_template_16_24_32
);
1654 test_cipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1655 speed_template_16_24_32
);
1656 test_cipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1657 speed_template_16_24_32
);
1658 test_cipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
1659 speed_template_16_24_32
);
1660 test_cipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
1661 speed_template_16_24_32
);
1662 test_cipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
1663 speed_template_32_40_48
);
1664 test_cipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
1665 speed_template_32_40_48
);
1666 test_cipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
1667 speed_template_32_48_64
);
1668 test_cipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
1669 speed_template_32_48_64
);
1673 test_cipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1674 speed_template_8_32
);
1675 test_cipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
1676 speed_template_8_32
);
1677 test_cipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1678 speed_template_8_32
);
1679 test_cipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
1680 speed_template_8_32
);
1681 test_cipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1682 speed_template_8_32
);
1683 test_cipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
1684 speed_template_8_32
);
1688 test_cipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1690 test_cipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1692 test_cipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1694 test_cipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1699 test_cipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
1700 speed_template_16_24_32
);
1701 test_cipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
1702 speed_template_16_24_32
);
1703 test_cipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
1704 speed_template_16_24_32
);
1705 test_cipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
1706 speed_template_16_24_32
);
1707 test_cipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
1708 speed_template_16_24_32
);
1709 test_cipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
1710 speed_template_16_24_32
);
1711 test_cipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
1712 speed_template_32_40_48
);
1713 test_cipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
1714 speed_template_32_40_48
);
1715 test_cipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
1716 speed_template_32_48_64
);
1717 test_cipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
1718 speed_template_32_48_64
);
1722 test_cipher_speed("salsa20", ENCRYPT
, sec
, NULL
, 0,
1723 speed_template_16_32
);
1727 test_cipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
1728 speed_template_16_32
);
1729 test_cipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
1730 speed_template_16_32
);
1731 test_cipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
1732 speed_template_16_32
);
1733 test_cipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
1734 speed_template_16_32
);
1735 test_cipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
1736 speed_template_16_32
);
1737 test_cipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
1738 speed_template_16_32
);
1739 test_cipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
1740 speed_template_32_48
);
1741 test_cipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
1742 speed_template_32_48
);
1743 test_cipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
1744 speed_template_32_64
);
1745 test_cipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
1746 speed_template_32_64
);
1750 test_cipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
1755 test_cipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
1756 speed_template_8_16
);
1757 test_cipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
1758 speed_template_8_16
);
1759 test_cipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
1760 speed_template_8_16
);
1761 test_cipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
1762 speed_template_8_16
);
1763 test_cipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
1764 speed_template_8_16
);
1765 test_cipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
1766 speed_template_8_16
);
1770 test_cipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
1771 speed_template_16_32
);
1772 test_cipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
1773 speed_template_16_32
);
1774 test_cipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
1775 speed_template_16_32
);
1776 test_cipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
1777 speed_template_16_32
);
1778 test_cipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
1779 speed_template_16_32
);
1780 test_cipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
1781 speed_template_16_32
);
1782 test_cipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
1783 speed_template_32_48
);
1784 test_cipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
1785 speed_template_32_48
);
1786 test_cipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
1787 speed_template_32_64
);
1788 test_cipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
1789 speed_template_32_64
);
1793 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT
, sec
,
1794 NULL
, 0, 16, 16, aead_speed_template_20
);
1795 test_aead_speed("gcm(aes)", ENCRYPT
, sec
,
1796 NULL
, 0, 16, 8, aead_speed_template_20
);
1800 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT
, sec
,
1801 NULL
, 0, 16, 16, aead_speed_template_19
);
1805 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT
, sec
,
1806 NULL
, 0, 16, 8, aead_speed_template_36
);
1810 test_cipher_speed("chacha20", ENCRYPT
, sec
, NULL
, 0,
1817 test_hash_speed(alg
, sec
, generic_hash_speed_template
);
1824 test_hash_speed("md4", sec
, generic_hash_speed_template
);
1825 if (mode
> 300 && mode
< 400) break;
1828 test_hash_speed("md5", sec
, generic_hash_speed_template
);
1829 if (mode
> 300 && mode
< 400) break;
1832 test_hash_speed("sha1", sec
, generic_hash_speed_template
);
1833 if (mode
> 300 && mode
< 400) break;
1836 test_hash_speed("sha256", sec
, generic_hash_speed_template
);
1837 if (mode
> 300 && mode
< 400) break;
1840 test_hash_speed("sha384", sec
, generic_hash_speed_template
);
1841 if (mode
> 300 && mode
< 400) break;
1844 test_hash_speed("sha512", sec
, generic_hash_speed_template
);
1845 if (mode
> 300 && mode
< 400) break;
1848 test_hash_speed("wp256", sec
, generic_hash_speed_template
);
1849 if (mode
> 300 && mode
< 400) break;
1852 test_hash_speed("wp384", sec
, generic_hash_speed_template
);
1853 if (mode
> 300 && mode
< 400) break;
1856 test_hash_speed("wp512", sec
, generic_hash_speed_template
);
1857 if (mode
> 300 && mode
< 400) break;
1860 test_hash_speed("tgr128", sec
, generic_hash_speed_template
);
1861 if (mode
> 300 && mode
< 400) break;
1864 test_hash_speed("tgr160", sec
, generic_hash_speed_template
);
1865 if (mode
> 300 && mode
< 400) break;
1868 test_hash_speed("tgr192", sec
, generic_hash_speed_template
);
1869 if (mode
> 300 && mode
< 400) break;
1872 test_hash_speed("sha224", sec
, generic_hash_speed_template
);
1873 if (mode
> 300 && mode
< 400) break;
1876 test_hash_speed("rmd128", sec
, generic_hash_speed_template
);
1877 if (mode
> 300 && mode
< 400) break;
1880 test_hash_speed("rmd160", sec
, generic_hash_speed_template
);
1881 if (mode
> 300 && mode
< 400) break;
1884 test_hash_speed("rmd256", sec
, generic_hash_speed_template
);
1885 if (mode
> 300 && mode
< 400) break;
1888 test_hash_speed("rmd320", sec
, generic_hash_speed_template
);
1889 if (mode
> 300 && mode
< 400) break;
1892 test_hash_speed("ghash-generic", sec
, hash_speed_template_16
);
1893 if (mode
> 300 && mode
< 400) break;
1896 test_hash_speed("crc32c", sec
, generic_hash_speed_template
);
1897 if (mode
> 300 && mode
< 400) break;
1900 test_hash_speed("crct10dif", sec
, generic_hash_speed_template
);
1901 if (mode
> 300 && mode
< 400) break;
1904 test_hash_speed("poly1305", sec
, poly1305_speed_template
);
1905 if (mode
> 300 && mode
< 400) break;
1912 test_ahash_speed(alg
, sec
, generic_hash_speed_template
);
1919 test_ahash_speed("md4", sec
, generic_hash_speed_template
);
1920 if (mode
> 400 && mode
< 500) break;
1923 test_ahash_speed("md5", sec
, generic_hash_speed_template
);
1924 if (mode
> 400 && mode
< 500) break;
1927 test_ahash_speed("sha1", sec
, generic_hash_speed_template
);
1928 if (mode
> 400 && mode
< 500) break;
1931 test_ahash_speed("sha256", sec
, generic_hash_speed_template
);
1932 if (mode
> 400 && mode
< 500) break;
1935 test_ahash_speed("sha384", sec
, generic_hash_speed_template
);
1936 if (mode
> 400 && mode
< 500) break;
1939 test_ahash_speed("sha512", sec
, generic_hash_speed_template
);
1940 if (mode
> 400 && mode
< 500) break;
1943 test_ahash_speed("wp256", sec
, generic_hash_speed_template
);
1944 if (mode
> 400 && mode
< 500) break;
1947 test_ahash_speed("wp384", sec
, generic_hash_speed_template
);
1948 if (mode
> 400 && mode
< 500) break;
1951 test_ahash_speed("wp512", sec
, generic_hash_speed_template
);
1952 if (mode
> 400 && mode
< 500) break;
1955 test_ahash_speed("tgr128", sec
, generic_hash_speed_template
);
1956 if (mode
> 400 && mode
< 500) break;
1959 test_ahash_speed("tgr160", sec
, generic_hash_speed_template
);
1960 if (mode
> 400 && mode
< 500) break;
1963 test_ahash_speed("tgr192", sec
, generic_hash_speed_template
);
1964 if (mode
> 400 && mode
< 500) break;
1967 test_ahash_speed("sha224", sec
, generic_hash_speed_template
);
1968 if (mode
> 400 && mode
< 500) break;
1971 test_ahash_speed("rmd128", sec
, generic_hash_speed_template
);
1972 if (mode
> 400 && mode
< 500) break;
1975 test_ahash_speed("rmd160", sec
, generic_hash_speed_template
);
1976 if (mode
> 400 && mode
< 500) break;
1979 test_ahash_speed("rmd256", sec
, generic_hash_speed_template
);
1980 if (mode
> 400 && mode
< 500) break;
1983 test_ahash_speed("rmd320", sec
, generic_hash_speed_template
);
1984 if (mode
> 400 && mode
< 500) break;
1990 test_acipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1991 speed_template_16_24_32
);
1992 test_acipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1993 speed_template_16_24_32
);
1994 test_acipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1995 speed_template_16_24_32
);
1996 test_acipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1997 speed_template_16_24_32
);
1998 test_acipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1999 speed_template_32_40_48
);
2000 test_acipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
2001 speed_template_32_40_48
);
2002 test_acipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
2003 speed_template_32_48_64
);
2004 test_acipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
2005 speed_template_32_48_64
);
2006 test_acipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
2007 speed_template_16_24_32
);
2008 test_acipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
2009 speed_template_16_24_32
);
2010 test_acipher_speed("cfb(aes)", ENCRYPT
, sec
, NULL
, 0,
2011 speed_template_16_24_32
);
2012 test_acipher_speed("cfb(aes)", DECRYPT
, sec
, NULL
, 0,
2013 speed_template_16_24_32
);
2014 test_acipher_speed("ofb(aes)", ENCRYPT
, sec
, NULL
, 0,
2015 speed_template_16_24_32
);
2016 test_acipher_speed("ofb(aes)", DECRYPT
, sec
, NULL
, 0,
2017 speed_template_16_24_32
);
2018 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT
, sec
, NULL
, 0,
2019 speed_template_20_28_36
);
2020 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT
, sec
, NULL
, 0,
2021 speed_template_20_28_36
);
2025 test_acipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
2026 des3_speed_template
, DES3_SPEED_VECTORS
,
2028 test_acipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
2029 des3_speed_template
, DES3_SPEED_VECTORS
,
2031 test_acipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
2032 des3_speed_template
, DES3_SPEED_VECTORS
,
2034 test_acipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
2035 des3_speed_template
, DES3_SPEED_VECTORS
,
2037 test_acipher_speed("cfb(des3_ede)", ENCRYPT
, sec
,
2038 des3_speed_template
, DES3_SPEED_VECTORS
,
2040 test_acipher_speed("cfb(des3_ede)", DECRYPT
, sec
,
2041 des3_speed_template
, DES3_SPEED_VECTORS
,
2043 test_acipher_speed("ofb(des3_ede)", ENCRYPT
, sec
,
2044 des3_speed_template
, DES3_SPEED_VECTORS
,
2046 test_acipher_speed("ofb(des3_ede)", DECRYPT
, sec
,
2047 des3_speed_template
, DES3_SPEED_VECTORS
,
2052 test_acipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
2054 test_acipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
2056 test_acipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
2058 test_acipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
2060 test_acipher_speed("cfb(des)", ENCRYPT
, sec
, NULL
, 0,
2062 test_acipher_speed("cfb(des)", DECRYPT
, sec
, NULL
, 0,
2064 test_acipher_speed("ofb(des)", ENCRYPT
, sec
, NULL
, 0,
2066 test_acipher_speed("ofb(des)", DECRYPT
, sec
, NULL
, 0,
2071 test_acipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
2072 speed_template_16_32
);
2073 test_acipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
2074 speed_template_16_32
);
2075 test_acipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
2076 speed_template_16_32
);
2077 test_acipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
2078 speed_template_16_32
);
2079 test_acipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
2080 speed_template_16_32
);
2081 test_acipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
2082 speed_template_16_32
);
2083 test_acipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
2084 speed_template_32_48
);
2085 test_acipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
2086 speed_template_32_48
);
2087 test_acipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
2088 speed_template_32_64
);
2089 test_acipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
2090 speed_template_32_64
);
2094 test_acipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
2095 speed_template_16_24_32
);
2096 test_acipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
2097 speed_template_16_24_32
);
2098 test_acipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
2099 speed_template_16_24_32
);
2100 test_acipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
2101 speed_template_16_24_32
);
2102 test_acipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
2103 speed_template_16_24_32
);
2104 test_acipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
2105 speed_template_16_24_32
);
2106 test_acipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
2107 speed_template_32_40_48
);
2108 test_acipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
2109 speed_template_32_40_48
);
2110 test_acipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
2111 speed_template_32_48_64
);
2112 test_acipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
2113 speed_template_32_48_64
);
2117 test_acipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
2122 test_acipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
2123 speed_template_8_16
);
2124 test_acipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
2125 speed_template_8_16
);
2126 test_acipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
2127 speed_template_8_16
);
2128 test_acipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
2129 speed_template_8_16
);
2130 test_acipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
2131 speed_template_8_16
);
2132 test_acipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
2133 speed_template_8_16
);
2137 test_acipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
2138 speed_template_16_32
);
2139 test_acipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
2140 speed_template_16_32
);
2141 test_acipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
2142 speed_template_16_32
);
2143 test_acipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
2144 speed_template_16_32
);
2145 test_acipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
2146 speed_template_16_32
);
2147 test_acipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
2148 speed_template_16_32
);
2149 test_acipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
2150 speed_template_32_48
);
2151 test_acipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
2152 speed_template_32_48
);
2153 test_acipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
2154 speed_template_32_64
);
2155 test_acipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
2156 speed_template_32_64
);
2160 test_acipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
2161 speed_template_16_32
);
2162 test_acipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
2163 speed_template_16_32
);
2164 test_acipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
2165 speed_template_16_32
);
2166 test_acipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
2167 speed_template_16_32
);
2168 test_acipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
2169 speed_template_16_32
);
2170 test_acipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
2171 speed_template_16_32
);
2172 test_acipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
2173 speed_template_32_48
);
2174 test_acipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
2175 speed_template_32_48
);
2176 test_acipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
2177 speed_template_32_64
);
2178 test_acipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
2179 speed_template_32_64
);
2183 test_acipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2184 speed_template_8_32
);
2185 test_acipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
2186 speed_template_8_32
);
2187 test_acipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2188 speed_template_8_32
);
2189 test_acipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
2190 speed_template_8_32
);
2191 test_acipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2192 speed_template_8_32
);
2193 test_acipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
2194 speed_template_8_32
);
2205 static int __init
tcrypt_mod_init(void)
2210 for (i
= 0; i
< TVMEMSIZE
; i
++) {
2211 tvmem
[i
] = (void *)__get_free_page(GFP_KERNEL
);
2216 err
= do_test(alg
, type
, mask
, mode
);
2219 printk(KERN_ERR
"tcrypt: one or more tests failed!\n");
2223 /* We intentionaly return -EAGAIN to prevent keeping the module,
2224 * unless we're running in fips mode. It does all its work from
2225 * init() and doesn't offer any runtime functionality, but in
2226 * the fips case, checking for a successful load is helpful.
2227 * => we don't need it in the memory, do we?
2234 for (i
= 0; i
< TVMEMSIZE
&& tvmem
[i
]; i
++)
2235 free_page((unsigned long)tvmem
[i
]);
2241 * If an init function is provided, an exit function must also be provided
2242 * to allow module unload.
2244 static void __exit
tcrypt_mod_fini(void) { }
2246 module_init(tcrypt_mod_init
);
2247 module_exit(tcrypt_mod_fini
);
2249 module_param(alg
, charp
, 0);
2250 module_param(type
, uint
, 0);
2251 module_param(mask
, uint
, 0);
2252 module_param(mode
, int, 0);
2253 module_param(sec
, uint
, 0);
2254 MODULE_PARM_DESC(sec
, "Length in seconds of speed tests "
2255 "(defaults to zero which uses CPU cycles instead)");
2257 MODULE_LICENSE("GPL");
2258 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2259 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");