2 * Quick & dirty crypto testing module.
4 * This will only exist until we have a better testing mechanism
5 * (e.g. a char device).
7 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
8 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
9 * Copyright (c) 2007 Nokia Siemens Networks
11 * Updated RFC4106 AES-GCM testing.
12 * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
13 * Adrian Hoban <adrian.hoban@intel.com>
14 * Gabriele Paoloni <gabriele.paoloni@intel.com>
15 * Tadeusz Struk (tadeusz.struk@intel.com)
16 * Copyright (c) 2010, Intel Corporation.
18 * This program is free software; you can redistribute it and/or modify it
19 * under the terms of the GNU General Public License as published by the Free
20 * Software Foundation; either version 2 of the License, or (at your option)
25 #include <crypto/hash.h>
26 #include <linux/err.h>
27 #include <linux/init.h>
28 #include <linux/gfp.h>
29 #include <linux/module.h>
30 #include <linux/scatterlist.h>
31 #include <linux/string.h>
32 #include <linux/moduleparam.h>
33 #include <linux/jiffies.h>
34 #include <linux/timex.h>
35 #include <linux/interrupt.h>
40 * Need slab memory for testing (size in number of pages).
45 * Used by test_cipher_speed()
51 * return a string with the driver name
53 #define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm))
56 * Used by test_cipher_speed()
58 static unsigned int sec
;
60 static char *alg
= NULL
;
64 static char *tvmem
[TVMEMSIZE
];
66 static char *check
[] = {
67 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
68 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
69 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
70 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
71 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
72 "lzo", "cts", "zlib", NULL
75 static int test_cipher_jiffies(struct blkcipher_desc
*desc
, int enc
,
76 struct scatterlist
*sg
, int blen
, int secs
)
78 unsigned long start
, end
;
82 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
83 time_before(jiffies
, end
); bcount
++) {
85 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
87 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
93 printk("%d operations in %d seconds (%ld bytes)\n",
94 bcount
, secs
, (long)bcount
* blen
);
98 static int test_cipher_cycles(struct blkcipher_desc
*desc
, int enc
,
99 struct scatterlist
*sg
, int blen
)
101 unsigned long cycles
= 0;
108 for (i
= 0; i
< 4; i
++) {
110 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
112 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
118 /* The real thing. */
119 for (i
= 0; i
< 8; i
++) {
122 start
= get_cycles();
124 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
126 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
132 cycles
+= end
- start
;
139 printk("1 operation in %lu cycles (%d bytes)\n",
140 (cycles
+ 4) / 8, blen
);
145 static int test_aead_jiffies(struct aead_request
*req
, int enc
,
148 unsigned long start
, end
;
152 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
153 time_before(jiffies
, end
); bcount
++) {
155 ret
= crypto_aead_encrypt(req
);
157 ret
= crypto_aead_decrypt(req
);
163 printk("%d operations in %d seconds (%ld bytes)\n",
164 bcount
, secs
, (long)bcount
* blen
);
168 static int test_aead_cycles(struct aead_request
*req
, int enc
, int blen
)
170 unsigned long cycles
= 0;
177 for (i
= 0; i
< 4; i
++) {
179 ret
= crypto_aead_encrypt(req
);
181 ret
= crypto_aead_decrypt(req
);
187 /* The real thing. */
188 for (i
= 0; i
< 8; i
++) {
191 start
= get_cycles();
193 ret
= crypto_aead_encrypt(req
);
195 ret
= crypto_aead_decrypt(req
);
201 cycles
+= end
- start
;
208 printk("1 operation in %lu cycles (%d bytes)\n",
209 (cycles
+ 4) / 8, blen
);
214 static u32 block_sizes
[] = { 16, 64, 256, 1024, 8192, 0 };
215 static u32 aead_sizes
[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
220 static int testmgr_alloc_buf(char *buf
[XBUFSIZE
])
224 for (i
= 0; i
< XBUFSIZE
; i
++) {
225 buf
[i
] = (void *)__get_free_page(GFP_KERNEL
);
234 free_page((unsigned long)buf
[i
]);
239 static void testmgr_free_buf(char *buf
[XBUFSIZE
])
243 for (i
= 0; i
< XBUFSIZE
; i
++)
244 free_page((unsigned long)buf
[i
]);
247 static void sg_init_aead(struct scatterlist
*sg
, char *xbuf
[XBUFSIZE
],
250 int np
= (buflen
+ PAGE_SIZE
- 1)/PAGE_SIZE
;
253 np
= (np
> XBUFSIZE
) ? XBUFSIZE
: np
;
254 rem
= buflen
% PAGE_SIZE
;
259 sg_init_table(sg
, np
);
260 for (k
= 0; k
< np
; ++k
) {
262 sg_set_buf(&sg
[k
], xbuf
[k
], rem
);
264 sg_set_buf(&sg
[k
], xbuf
[k
], PAGE_SIZE
);
268 static void test_aead_speed(const char *algo
, int enc
, unsigned int secs
,
269 struct aead_speed_template
*template,
270 unsigned int tcount
, u8 authsize
,
271 unsigned int aad_size
, u8
*keysize
)
274 struct crypto_aead
*tfm
;
277 struct aead_request
*req
;
278 struct scatterlist
*sg
;
279 struct scatterlist
*asg
;
280 struct scatterlist
*sgout
;
284 char *xbuf
[XBUFSIZE
];
285 char *xoutbuf
[XBUFSIZE
];
286 char *axbuf
[XBUFSIZE
];
287 unsigned int *b_size
;
290 if (aad_size
>= PAGE_SIZE
) {
291 pr_err("associate data length (%u) too big\n", aad_size
);
300 if (testmgr_alloc_buf(xbuf
))
302 if (testmgr_alloc_buf(axbuf
))
304 if (testmgr_alloc_buf(xoutbuf
))
307 sg
= kmalloc(sizeof(*sg
) * 8 * 3, GFP_KERNEL
);
313 tfm
= crypto_alloc_aead(algo
, 0, 0);
316 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo
,
321 printk(KERN_INFO
"\ntesting speed of %s (%s) %s\n", algo
,
322 get_driver_name(crypto_aead
, tfm
), e
);
324 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
326 pr_err("alg: aead: Failed to allocate request for %s\n",
336 memset(assoc
, 0xff, aad_size
);
337 sg_init_one(&asg
[0], assoc
, aad_size
);
339 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
340 pr_err("template (%u) too big for tvmem (%lu)\n",
342 TVMEMSIZE
* PAGE_SIZE
);
347 for (j
= 0; j
< tcount
; j
++) {
348 if (template[j
].klen
== *keysize
) {
349 key
= template[j
].key
;
353 ret
= crypto_aead_setkey(tfm
, key
, *keysize
);
354 ret
= crypto_aead_setauthsize(tfm
, authsize
);
356 iv_len
= crypto_aead_ivsize(tfm
);
358 memset(&iv
, 0xff, iv_len
);
360 crypto_aead_clear_flags(tfm
, ~0);
361 printk(KERN_INFO
"test %u (%d bit key, %d byte blocks): ",
362 i
, *keysize
* 8, *b_size
);
365 memset(tvmem
[0], 0xff, PAGE_SIZE
);
368 pr_err("setkey() failed flags=%x\n",
369 crypto_aead_get_flags(tfm
));
373 sg_init_aead(&sg
[0], xbuf
,
374 *b_size
+ (enc
? authsize
: 0));
376 sg_init_aead(&sgout
[0], xoutbuf
,
377 *b_size
+ (enc
? authsize
: 0));
379 aead_request_set_crypt(req
, sg
, sgout
, *b_size
, iv
);
380 aead_request_set_assoc(req
, asg
, aad_size
);
383 ret
= test_aead_jiffies(req
, enc
, *b_size
,
386 ret
= test_aead_cycles(req
, enc
, *b_size
);
389 pr_err("%s() failed return code=%d\n", e
, ret
);
399 aead_request_free(req
);
401 crypto_free_aead(tfm
);
405 testmgr_free_buf(xoutbuf
);
407 testmgr_free_buf(axbuf
);
409 testmgr_free_buf(xbuf
);
414 static void test_cipher_speed(const char *algo
, int enc
, unsigned int secs
,
415 struct cipher_speed_template
*template,
416 unsigned int tcount
, u8
*keysize
)
418 unsigned int ret
, i
, j
, iv_len
;
421 struct crypto_blkcipher
*tfm
;
422 struct blkcipher_desc desc
;
431 tfm
= crypto_alloc_blkcipher(algo
, 0, CRYPTO_ALG_ASYNC
);
434 printk("failed to load transform for %s: %ld\n", algo
,
441 printk(KERN_INFO
"\ntesting speed of %s (%s) %s\n", algo
,
442 get_driver_name(crypto_blkcipher
, tfm
), e
);
447 b_size
= block_sizes
;
449 struct scatterlist sg
[TVMEMSIZE
];
451 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
452 printk("template (%u) too big for "
453 "tvmem (%lu)\n", *keysize
+ *b_size
,
454 TVMEMSIZE
* PAGE_SIZE
);
458 printk("test %u (%d bit key, %d byte blocks): ", i
,
459 *keysize
* 8, *b_size
);
461 memset(tvmem
[0], 0xff, PAGE_SIZE
);
463 /* set key, plain text and IV */
465 for (j
= 0; j
< tcount
; j
++) {
466 if (template[j
].klen
== *keysize
) {
467 key
= template[j
].key
;
472 ret
= crypto_blkcipher_setkey(tfm
, key
, *keysize
);
474 printk("setkey() failed flags=%x\n",
475 crypto_blkcipher_get_flags(tfm
));
479 sg_init_table(sg
, TVMEMSIZE
);
480 sg_set_buf(sg
, tvmem
[0] + *keysize
,
481 PAGE_SIZE
- *keysize
);
482 for (j
= 1; j
< TVMEMSIZE
; j
++) {
483 sg_set_buf(sg
+ j
, tvmem
[j
], PAGE_SIZE
);
484 memset (tvmem
[j
], 0xff, PAGE_SIZE
);
487 iv_len
= crypto_blkcipher_ivsize(tfm
);
489 memset(&iv
, 0xff, iv_len
);
490 crypto_blkcipher_set_iv(tfm
, iv
, iv_len
);
494 ret
= test_cipher_jiffies(&desc
, enc
, sg
,
497 ret
= test_cipher_cycles(&desc
, enc
, sg
,
501 printk("%s() failed flags=%x\n", e
, desc
.flags
);
511 crypto_free_blkcipher(tfm
);
514 static int test_hash_jiffies_digest(struct hash_desc
*desc
,
515 struct scatterlist
*sg
, int blen
,
518 unsigned long start
, end
;
522 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
523 time_before(jiffies
, end
); bcount
++) {
524 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
529 printk("%6u opers/sec, %9lu bytes/sec\n",
530 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
535 static int test_hash_jiffies(struct hash_desc
*desc
, struct scatterlist
*sg
,
536 int blen
, int plen
, char *out
, int secs
)
538 unsigned long start
, end
;
543 return test_hash_jiffies_digest(desc
, sg
, blen
, out
, secs
);
545 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
546 time_before(jiffies
, end
); bcount
++) {
547 ret
= crypto_hash_init(desc
);
550 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
551 ret
= crypto_hash_update(desc
, sg
, plen
);
555 /* we assume there is enough space in 'out' for the result */
556 ret
= crypto_hash_final(desc
, out
);
561 printk("%6u opers/sec, %9lu bytes/sec\n",
562 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
567 static int test_hash_cycles_digest(struct hash_desc
*desc
,
568 struct scatterlist
*sg
, int blen
, char *out
)
570 unsigned long cycles
= 0;
577 for (i
= 0; i
< 4; i
++) {
578 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
583 /* The real thing. */
584 for (i
= 0; i
< 8; i
++) {
587 start
= get_cycles();
589 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
595 cycles
+= end
- start
;
604 printk("%6lu cycles/operation, %4lu cycles/byte\n",
605 cycles
/ 8, cycles
/ (8 * blen
));
610 static int test_hash_cycles(struct hash_desc
*desc
, struct scatterlist
*sg
,
611 int blen
, int plen
, char *out
)
613 unsigned long cycles
= 0;
618 return test_hash_cycles_digest(desc
, sg
, blen
, out
);
623 for (i
= 0; i
< 4; i
++) {
624 ret
= crypto_hash_init(desc
);
627 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
628 ret
= crypto_hash_update(desc
, sg
, plen
);
632 ret
= crypto_hash_final(desc
, out
);
637 /* The real thing. */
638 for (i
= 0; i
< 8; i
++) {
641 start
= get_cycles();
643 ret
= crypto_hash_init(desc
);
646 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
647 ret
= crypto_hash_update(desc
, sg
, plen
);
651 ret
= crypto_hash_final(desc
, out
);
657 cycles
+= end
- start
;
666 printk("%6lu cycles/operation, %4lu cycles/byte\n",
667 cycles
/ 8, cycles
/ (8 * blen
));
672 static void test_hash_sg_init(struct scatterlist
*sg
)
676 sg_init_table(sg
, TVMEMSIZE
);
677 for (i
= 0; i
< TVMEMSIZE
; i
++) {
678 sg_set_buf(sg
+ i
, tvmem
[i
], PAGE_SIZE
);
679 memset(tvmem
[i
], 0xff, PAGE_SIZE
);
683 static void test_hash_speed(const char *algo
, unsigned int secs
,
684 struct hash_speed
*speed
)
686 struct scatterlist sg
[TVMEMSIZE
];
687 struct crypto_hash
*tfm
;
688 struct hash_desc desc
;
689 static char output
[1024];
693 tfm
= crypto_alloc_hash(algo
, 0, CRYPTO_ALG_ASYNC
);
696 printk(KERN_ERR
"failed to load transform for %s: %ld\n", algo
,
701 printk(KERN_INFO
"\ntesting speed of %s (%s)\n", algo
,
702 get_driver_name(crypto_hash
, tfm
));
707 if (crypto_hash_digestsize(tfm
) > sizeof(output
)) {
708 printk(KERN_ERR
"digestsize(%u) > outputbuffer(%zu)\n",
709 crypto_hash_digestsize(tfm
), sizeof(output
));
713 test_hash_sg_init(sg
);
714 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
715 if (speed
[i
].blen
> TVMEMSIZE
* PAGE_SIZE
) {
717 "template (%u) too big for tvmem (%lu)\n",
718 speed
[i
].blen
, TVMEMSIZE
* PAGE_SIZE
);
723 crypto_hash_setkey(tfm
, tvmem
[0], speed
[i
].klen
);
725 printk(KERN_INFO
"test%3u "
726 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
727 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
730 ret
= test_hash_jiffies(&desc
, sg
, speed
[i
].blen
,
731 speed
[i
].plen
, output
, secs
);
733 ret
= test_hash_cycles(&desc
, sg
, speed
[i
].blen
,
734 speed
[i
].plen
, output
);
737 printk(KERN_ERR
"hashing failed ret=%d\n", ret
);
743 crypto_free_hash(tfm
);
746 struct tcrypt_result
{
747 struct completion completion
;
751 static void tcrypt_complete(struct crypto_async_request
*req
, int err
)
753 struct tcrypt_result
*res
= req
->data
;
755 if (err
== -EINPROGRESS
)
759 complete(&res
->completion
);
762 static inline int do_one_ahash_op(struct ahash_request
*req
, int ret
)
764 if (ret
== -EINPROGRESS
|| ret
== -EBUSY
) {
765 struct tcrypt_result
*tr
= req
->base
.data
;
767 ret
= wait_for_completion_interruptible(&tr
->completion
);
770 reinit_completion(&tr
->completion
);
775 static int test_ahash_jiffies_digest(struct ahash_request
*req
, int blen
,
778 unsigned long start
, end
;
782 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
783 time_before(jiffies
, end
); bcount
++) {
784 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
789 printk("%6u opers/sec, %9lu bytes/sec\n",
790 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
795 static int test_ahash_jiffies(struct ahash_request
*req
, int blen
,
796 int plen
, char *out
, int secs
)
798 unsigned long start
, end
;
803 return test_ahash_jiffies_digest(req
, blen
, out
, secs
);
805 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
806 time_before(jiffies
, end
); bcount
++) {
807 ret
= crypto_ahash_init(req
);
810 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
811 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
815 /* we assume there is enough space in 'out' for the result */
816 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
821 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
822 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
827 static int test_ahash_cycles_digest(struct ahash_request
*req
, int blen
,
830 unsigned long cycles
= 0;
834 for (i
= 0; i
< 4; i
++) {
835 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
840 /* The real thing. */
841 for (i
= 0; i
< 8; i
++) {
844 start
= get_cycles();
846 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
852 cycles
+= end
- start
;
859 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
860 cycles
/ 8, cycles
/ (8 * blen
));
865 static int test_ahash_cycles(struct ahash_request
*req
, int blen
,
868 unsigned long cycles
= 0;
872 return test_ahash_cycles_digest(req
, blen
, out
);
875 for (i
= 0; i
< 4; i
++) {
876 ret
= crypto_ahash_init(req
);
879 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
880 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
884 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
889 /* The real thing. */
890 for (i
= 0; i
< 8; i
++) {
893 start
= get_cycles();
895 ret
= crypto_ahash_init(req
);
898 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
899 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
903 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
909 cycles
+= end
- start
;
916 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
917 cycles
/ 8, cycles
/ (8 * blen
));
922 static void test_ahash_speed(const char *algo
, unsigned int secs
,
923 struct hash_speed
*speed
)
925 struct scatterlist sg
[TVMEMSIZE
];
926 struct tcrypt_result tresult
;
927 struct ahash_request
*req
;
928 struct crypto_ahash
*tfm
;
929 static char output
[1024];
932 tfm
= crypto_alloc_ahash(algo
, 0, 0);
934 pr_err("failed to load transform for %s: %ld\n",
939 printk(KERN_INFO
"\ntesting speed of async %s (%s)\n", algo
,
940 get_driver_name(crypto_ahash
, tfm
));
942 if (crypto_ahash_digestsize(tfm
) > sizeof(output
)) {
943 pr_err("digestsize(%u) > outputbuffer(%zu)\n",
944 crypto_ahash_digestsize(tfm
), sizeof(output
));
948 test_hash_sg_init(sg
);
949 req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
951 pr_err("ahash request allocation failure\n");
955 init_completion(&tresult
.completion
);
956 ahash_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
957 tcrypt_complete
, &tresult
);
959 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
960 if (speed
[i
].blen
> TVMEMSIZE
* PAGE_SIZE
) {
961 pr_err("template (%u) too big for tvmem (%lu)\n",
962 speed
[i
].blen
, TVMEMSIZE
* PAGE_SIZE
);
967 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
968 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
970 ahash_request_set_crypt(req
, sg
, output
, speed
[i
].plen
);
973 ret
= test_ahash_jiffies(req
, speed
[i
].blen
,
974 speed
[i
].plen
, output
, secs
);
976 ret
= test_ahash_cycles(req
, speed
[i
].blen
,
977 speed
[i
].plen
, output
);
980 pr_err("hashing failed ret=%d\n", ret
);
985 ahash_request_free(req
);
988 crypto_free_ahash(tfm
);
991 static inline int do_one_acipher_op(struct ablkcipher_request
*req
, int ret
)
993 if (ret
== -EINPROGRESS
|| ret
== -EBUSY
) {
994 struct tcrypt_result
*tr
= req
->base
.data
;
996 ret
= wait_for_completion_interruptible(&tr
->completion
);
999 reinit_completion(&tr
->completion
);
1005 static int test_acipher_jiffies(struct ablkcipher_request
*req
, int enc
,
1008 unsigned long start
, end
;
1012 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
1013 time_before(jiffies
, end
); bcount
++) {
1015 ret
= do_one_acipher_op(req
,
1016 crypto_ablkcipher_encrypt(req
));
1018 ret
= do_one_acipher_op(req
,
1019 crypto_ablkcipher_decrypt(req
));
1025 pr_cont("%d operations in %d seconds (%ld bytes)\n",
1026 bcount
, secs
, (long)bcount
* blen
);
1030 static int test_acipher_cycles(struct ablkcipher_request
*req
, int enc
,
1033 unsigned long cycles
= 0;
1038 for (i
= 0; i
< 4; i
++) {
1040 ret
= do_one_acipher_op(req
,
1041 crypto_ablkcipher_encrypt(req
));
1043 ret
= do_one_acipher_op(req
,
1044 crypto_ablkcipher_decrypt(req
));
1050 /* The real thing. */
1051 for (i
= 0; i
< 8; i
++) {
1052 cycles_t start
, end
;
1054 start
= get_cycles();
1056 ret
= do_one_acipher_op(req
,
1057 crypto_ablkcipher_encrypt(req
));
1059 ret
= do_one_acipher_op(req
,
1060 crypto_ablkcipher_decrypt(req
));
1066 cycles
+= end
- start
;
1071 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1072 (cycles
+ 4) / 8, blen
);
1077 static void test_acipher_speed(const char *algo
, int enc
, unsigned int secs
,
1078 struct cipher_speed_template
*template,
1079 unsigned int tcount
, u8
*keysize
)
1081 unsigned int ret
, i
, j
, k
, iv_len
;
1082 struct tcrypt_result tresult
;
1085 struct ablkcipher_request
*req
;
1086 struct crypto_ablkcipher
*tfm
;
1095 init_completion(&tresult
.completion
);
1097 tfm
= crypto_alloc_ablkcipher(algo
, 0, 0);
1100 pr_err("failed to load transform for %s: %ld\n", algo
,
1105 pr_info("\ntesting speed of async %s (%s) %s\n", algo
,
1106 get_driver_name(crypto_ablkcipher
, tfm
), e
);
1108 req
= ablkcipher_request_alloc(tfm
, GFP_KERNEL
);
1110 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1115 ablkcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
1116 tcrypt_complete
, &tresult
);
1120 b_size
= block_sizes
;
1123 struct scatterlist sg
[TVMEMSIZE
];
1125 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
1126 pr_err("template (%u) too big for "
1127 "tvmem (%lu)\n", *keysize
+ *b_size
,
1128 TVMEMSIZE
* PAGE_SIZE
);
1132 pr_info("test %u (%d bit key, %d byte blocks): ", i
,
1133 *keysize
* 8, *b_size
);
1135 memset(tvmem
[0], 0xff, PAGE_SIZE
);
1137 /* set key, plain text and IV */
1139 for (j
= 0; j
< tcount
; j
++) {
1140 if (template[j
].klen
== *keysize
) {
1141 key
= template[j
].key
;
1146 crypto_ablkcipher_clear_flags(tfm
, ~0);
1148 ret
= crypto_ablkcipher_setkey(tfm
, key
, *keysize
);
1150 pr_err("setkey() failed flags=%x\n",
1151 crypto_ablkcipher_get_flags(tfm
));
1155 sg_init_table(sg
, TVMEMSIZE
);
1157 k
= *keysize
+ *b_size
;
1158 if (k
> PAGE_SIZE
) {
1159 sg_set_buf(sg
, tvmem
[0] + *keysize
,
1160 PAGE_SIZE
- *keysize
);
1163 while (k
> PAGE_SIZE
) {
1164 sg_set_buf(sg
+ j
, tvmem
[j
], PAGE_SIZE
);
1165 memset(tvmem
[j
], 0xff, PAGE_SIZE
);
1169 sg_set_buf(sg
+ j
, tvmem
[j
], k
);
1170 memset(tvmem
[j
], 0xff, k
);
1172 sg_set_buf(sg
, tvmem
[0] + *keysize
, *b_size
);
1175 iv_len
= crypto_ablkcipher_ivsize(tfm
);
1177 memset(&iv
, 0xff, iv_len
);
1179 ablkcipher_request_set_crypt(req
, sg
, sg
, *b_size
, iv
);
1182 ret
= test_acipher_jiffies(req
, enc
,
1185 ret
= test_acipher_cycles(req
, enc
,
1189 pr_err("%s() failed flags=%x\n", e
,
1190 crypto_ablkcipher_get_flags(tfm
));
1200 ablkcipher_request_free(req
);
1202 crypto_free_ablkcipher(tfm
);
1205 static void test_available(void)
1207 char **name
= check
;
1210 printk("alg %s ", *name
);
1211 printk(crypto_has_alg(*name
, 0, 0) ?
1212 "found\n" : "not found\n");
1217 static inline int tcrypt_test(const char *alg
)
1221 ret
= alg_test(alg
, alg
, 0, 0);
1222 /* non-fips algs return -EINVAL in fips mode */
1223 if (fips_enabled
&& ret
== -EINVAL
)
1228 static int do_test(int m
)
1235 for (i
= 1; i
< 200; i
++)
1240 ret
+= tcrypt_test("md5");
1244 ret
+= tcrypt_test("sha1");
1248 ret
+= tcrypt_test("ecb(des)");
1249 ret
+= tcrypt_test("cbc(des)");
1250 ret
+= tcrypt_test("ctr(des)");
1254 ret
+= tcrypt_test("ecb(des3_ede)");
1255 ret
+= tcrypt_test("cbc(des3_ede)");
1256 ret
+= tcrypt_test("ctr(des3_ede)");
1260 ret
+= tcrypt_test("md4");
1264 ret
+= tcrypt_test("sha256");
1268 ret
+= tcrypt_test("ecb(blowfish)");
1269 ret
+= tcrypt_test("cbc(blowfish)");
1270 ret
+= tcrypt_test("ctr(blowfish)");
1274 ret
+= tcrypt_test("ecb(twofish)");
1275 ret
+= tcrypt_test("cbc(twofish)");
1276 ret
+= tcrypt_test("ctr(twofish)");
1277 ret
+= tcrypt_test("lrw(twofish)");
1278 ret
+= tcrypt_test("xts(twofish)");
1282 ret
+= tcrypt_test("ecb(serpent)");
1283 ret
+= tcrypt_test("cbc(serpent)");
1284 ret
+= tcrypt_test("ctr(serpent)");
1285 ret
+= tcrypt_test("lrw(serpent)");
1286 ret
+= tcrypt_test("xts(serpent)");
1290 ret
+= tcrypt_test("ecb(aes)");
1291 ret
+= tcrypt_test("cbc(aes)");
1292 ret
+= tcrypt_test("lrw(aes)");
1293 ret
+= tcrypt_test("xts(aes)");
1294 ret
+= tcrypt_test("ctr(aes)");
1295 ret
+= tcrypt_test("rfc3686(ctr(aes))");
1299 ret
+= tcrypt_test("sha384");
1303 ret
+= tcrypt_test("sha512");
1307 ret
+= tcrypt_test("deflate");
1311 ret
+= tcrypt_test("ecb(cast5)");
1312 ret
+= tcrypt_test("cbc(cast5)");
1313 ret
+= tcrypt_test("ctr(cast5)");
1317 ret
+= tcrypt_test("ecb(cast6)");
1318 ret
+= tcrypt_test("cbc(cast6)");
1319 ret
+= tcrypt_test("ctr(cast6)");
1320 ret
+= tcrypt_test("lrw(cast6)");
1321 ret
+= tcrypt_test("xts(cast6)");
1325 ret
+= tcrypt_test("ecb(arc4)");
1329 ret
+= tcrypt_test("michael_mic");
1333 ret
+= tcrypt_test("crc32c");
1337 ret
+= tcrypt_test("ecb(tea)");
1341 ret
+= tcrypt_test("ecb(xtea)");
1345 ret
+= tcrypt_test("ecb(khazad)");
1349 ret
+= tcrypt_test("wp512");
1353 ret
+= tcrypt_test("wp384");
1357 ret
+= tcrypt_test("wp256");
1361 ret
+= tcrypt_test("ecb(tnepres)");
1365 ret
+= tcrypt_test("ecb(anubis)");
1366 ret
+= tcrypt_test("cbc(anubis)");
1370 ret
+= tcrypt_test("tgr192");
1374 ret
+= tcrypt_test("tgr160");
1378 ret
+= tcrypt_test("tgr128");
1382 ret
+= tcrypt_test("ecb(xeta)");
1386 ret
+= tcrypt_test("pcbc(fcrypt)");
1390 ret
+= tcrypt_test("ecb(camellia)");
1391 ret
+= tcrypt_test("cbc(camellia)");
1392 ret
+= tcrypt_test("ctr(camellia)");
1393 ret
+= tcrypt_test("lrw(camellia)");
1394 ret
+= tcrypt_test("xts(camellia)");
1398 ret
+= tcrypt_test("sha224");
1402 ret
+= tcrypt_test("salsa20");
1406 ret
+= tcrypt_test("gcm(aes)");
1410 ret
+= tcrypt_test("lzo");
1414 ret
+= tcrypt_test("ccm(aes)");
1418 ret
+= tcrypt_test("cts(cbc(aes))");
1422 ret
+= tcrypt_test("rmd128");
1426 ret
+= tcrypt_test("rmd160");
1430 ret
+= tcrypt_test("rmd256");
1434 ret
+= tcrypt_test("rmd320");
1438 ret
+= tcrypt_test("ecb(seed)");
1442 ret
+= tcrypt_test("zlib");
1446 ret
+= tcrypt_test("rfc4309(ccm(aes))");
1450 ret
+= tcrypt_test("ghash");
1454 ret
+= tcrypt_test("crct10dif");
1458 ret
+= tcrypt_test("hmac(md5)");
1462 ret
+= tcrypt_test("hmac(sha1)");
1466 ret
+= tcrypt_test("hmac(sha256)");
1470 ret
+= tcrypt_test("hmac(sha384)");
1474 ret
+= tcrypt_test("hmac(sha512)");
1478 ret
+= tcrypt_test("hmac(sha224)");
1482 ret
+= tcrypt_test("xcbc(aes)");
1486 ret
+= tcrypt_test("hmac(rmd128)");
1490 ret
+= tcrypt_test("hmac(rmd160)");
1494 ret
+= tcrypt_test("vmac(aes)");
1498 ret
+= tcrypt_test("hmac(crc32)");
1502 ret
+= tcrypt_test("ansi_cprng");
1506 ret
+= tcrypt_test("rfc4106(gcm(aes))");
1510 ret
+= tcrypt_test("rfc4543(gcm(aes))");
1514 ret
+= tcrypt_test("cmac(aes)");
1518 ret
+= tcrypt_test("cmac(des3_ede)");
1522 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1526 ret
+= tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1530 ret
+= tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1533 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(des))");
1536 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
1539 ret
+= tcrypt_test("authenc(hmac(sha224),cbc(des))");
1542 ret
+= tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
1545 ret
+= tcrypt_test("authenc(hmac(sha256),cbc(des))");
1548 ret
+= tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
1551 ret
+= tcrypt_test("authenc(hmac(sha384),cbc(des))");
1554 ret
+= tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
1557 ret
+= tcrypt_test("authenc(hmac(sha512),cbc(des))");
1560 ret
+= tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
1563 test_cipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1564 speed_template_16_24_32
);
1565 test_cipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1566 speed_template_16_24_32
);
1567 test_cipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1568 speed_template_16_24_32
);
1569 test_cipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1570 speed_template_16_24_32
);
1571 test_cipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1572 speed_template_32_40_48
);
1573 test_cipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1574 speed_template_32_40_48
);
1575 test_cipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1576 speed_template_32_48_64
);
1577 test_cipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1578 speed_template_32_48_64
);
1579 test_cipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
1580 speed_template_16_24_32
);
1581 test_cipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
1582 speed_template_16_24_32
);
1586 test_cipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1587 des3_speed_template
, DES3_SPEED_VECTORS
,
1589 test_cipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1590 des3_speed_template
, DES3_SPEED_VECTORS
,
1592 test_cipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1593 des3_speed_template
, DES3_SPEED_VECTORS
,
1595 test_cipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1596 des3_speed_template
, DES3_SPEED_VECTORS
,
1598 test_cipher_speed("ctr(des3_ede)", ENCRYPT
, sec
,
1599 des3_speed_template
, DES3_SPEED_VECTORS
,
1601 test_cipher_speed("ctr(des3_ede)", DECRYPT
, sec
,
1602 des3_speed_template
, DES3_SPEED_VECTORS
,
1607 test_cipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1608 speed_template_16_24_32
);
1609 test_cipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1610 speed_template_16_24_32
);
1611 test_cipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1612 speed_template_16_24_32
);
1613 test_cipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1614 speed_template_16_24_32
);
1615 test_cipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
1616 speed_template_16_24_32
);
1617 test_cipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
1618 speed_template_16_24_32
);
1619 test_cipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
1620 speed_template_32_40_48
);
1621 test_cipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
1622 speed_template_32_40_48
);
1623 test_cipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
1624 speed_template_32_48_64
);
1625 test_cipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
1626 speed_template_32_48_64
);
1630 test_cipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1631 speed_template_8_32
);
1632 test_cipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
1633 speed_template_8_32
);
1634 test_cipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1635 speed_template_8_32
);
1636 test_cipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
1637 speed_template_8_32
);
1638 test_cipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1639 speed_template_8_32
);
1640 test_cipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
1641 speed_template_8_32
);
1645 test_cipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1647 test_cipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1649 test_cipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1651 test_cipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1656 test_cipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
1657 speed_template_16_24_32
);
1658 test_cipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
1659 speed_template_16_24_32
);
1660 test_cipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
1661 speed_template_16_24_32
);
1662 test_cipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
1663 speed_template_16_24_32
);
1664 test_cipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
1665 speed_template_16_24_32
);
1666 test_cipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
1667 speed_template_16_24_32
);
1668 test_cipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
1669 speed_template_32_40_48
);
1670 test_cipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
1671 speed_template_32_40_48
);
1672 test_cipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
1673 speed_template_32_48_64
);
1674 test_cipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
1675 speed_template_32_48_64
);
1679 test_cipher_speed("salsa20", ENCRYPT
, sec
, NULL
, 0,
1680 speed_template_16_32
);
1684 test_cipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
1685 speed_template_16_32
);
1686 test_cipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
1687 speed_template_16_32
);
1688 test_cipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
1689 speed_template_16_32
);
1690 test_cipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
1691 speed_template_16_32
);
1692 test_cipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
1693 speed_template_16_32
);
1694 test_cipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
1695 speed_template_16_32
);
1696 test_cipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
1697 speed_template_32_48
);
1698 test_cipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
1699 speed_template_32_48
);
1700 test_cipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
1701 speed_template_32_64
);
1702 test_cipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
1703 speed_template_32_64
);
1707 test_cipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
1712 test_cipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
1713 speed_template_8_16
);
1714 test_cipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
1715 speed_template_8_16
);
1716 test_cipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
1717 speed_template_8_16
);
1718 test_cipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
1719 speed_template_8_16
);
1720 test_cipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
1721 speed_template_8_16
);
1722 test_cipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
1723 speed_template_8_16
);
1727 test_cipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
1728 speed_template_16_32
);
1729 test_cipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
1730 speed_template_16_32
);
1731 test_cipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
1732 speed_template_16_32
);
1733 test_cipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
1734 speed_template_16_32
);
1735 test_cipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
1736 speed_template_16_32
);
1737 test_cipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
1738 speed_template_16_32
);
1739 test_cipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
1740 speed_template_32_48
);
1741 test_cipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
1742 speed_template_32_48
);
1743 test_cipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
1744 speed_template_32_64
);
1745 test_cipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
1746 speed_template_32_64
);
1750 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT
, sec
,
1751 NULL
, 0, 16, 8, aead_speed_template_20
);
1758 test_hash_speed("md4", sec
, generic_hash_speed_template
);
1759 if (mode
> 300 && mode
< 400) break;
1762 test_hash_speed("md5", sec
, generic_hash_speed_template
);
1763 if (mode
> 300 && mode
< 400) break;
1766 test_hash_speed("sha1", sec
, generic_hash_speed_template
);
1767 if (mode
> 300 && mode
< 400) break;
1770 test_hash_speed("sha256", sec
, generic_hash_speed_template
);
1771 if (mode
> 300 && mode
< 400) break;
1774 test_hash_speed("sha384", sec
, generic_hash_speed_template
);
1775 if (mode
> 300 && mode
< 400) break;
1778 test_hash_speed("sha512", sec
, generic_hash_speed_template
);
1779 if (mode
> 300 && mode
< 400) break;
1782 test_hash_speed("wp256", sec
, generic_hash_speed_template
);
1783 if (mode
> 300 && mode
< 400) break;
1786 test_hash_speed("wp384", sec
, generic_hash_speed_template
);
1787 if (mode
> 300 && mode
< 400) break;
1790 test_hash_speed("wp512", sec
, generic_hash_speed_template
);
1791 if (mode
> 300 && mode
< 400) break;
1794 test_hash_speed("tgr128", sec
, generic_hash_speed_template
);
1795 if (mode
> 300 && mode
< 400) break;
1798 test_hash_speed("tgr160", sec
, generic_hash_speed_template
);
1799 if (mode
> 300 && mode
< 400) break;
1802 test_hash_speed("tgr192", sec
, generic_hash_speed_template
);
1803 if (mode
> 300 && mode
< 400) break;
1806 test_hash_speed("sha224", sec
, generic_hash_speed_template
);
1807 if (mode
> 300 && mode
< 400) break;
1810 test_hash_speed("rmd128", sec
, generic_hash_speed_template
);
1811 if (mode
> 300 && mode
< 400) break;
1814 test_hash_speed("rmd160", sec
, generic_hash_speed_template
);
1815 if (mode
> 300 && mode
< 400) break;
1818 test_hash_speed("rmd256", sec
, generic_hash_speed_template
);
1819 if (mode
> 300 && mode
< 400) break;
1822 test_hash_speed("rmd320", sec
, generic_hash_speed_template
);
1823 if (mode
> 300 && mode
< 400) break;
1826 test_hash_speed("ghash-generic", sec
, hash_speed_template_16
);
1827 if (mode
> 300 && mode
< 400) break;
1830 test_hash_speed("crc32c", sec
, generic_hash_speed_template
);
1831 if (mode
> 300 && mode
< 400) break;
1834 test_hash_speed("crct10dif", sec
, generic_hash_speed_template
);
1835 if (mode
> 300 && mode
< 400) break;
1844 test_ahash_speed("md4", sec
, generic_hash_speed_template
);
1845 if (mode
> 400 && mode
< 500) break;
1848 test_ahash_speed("md5", sec
, generic_hash_speed_template
);
1849 if (mode
> 400 && mode
< 500) break;
1852 test_ahash_speed("sha1", sec
, generic_hash_speed_template
);
1853 if (mode
> 400 && mode
< 500) break;
1856 test_ahash_speed("sha256", sec
, generic_hash_speed_template
);
1857 if (mode
> 400 && mode
< 500) break;
1860 test_ahash_speed("sha384", sec
, generic_hash_speed_template
);
1861 if (mode
> 400 && mode
< 500) break;
1864 test_ahash_speed("sha512", sec
, generic_hash_speed_template
);
1865 if (mode
> 400 && mode
< 500) break;
1868 test_ahash_speed("wp256", sec
, generic_hash_speed_template
);
1869 if (mode
> 400 && mode
< 500) break;
1872 test_ahash_speed("wp384", sec
, generic_hash_speed_template
);
1873 if (mode
> 400 && mode
< 500) break;
1876 test_ahash_speed("wp512", sec
, generic_hash_speed_template
);
1877 if (mode
> 400 && mode
< 500) break;
1880 test_ahash_speed("tgr128", sec
, generic_hash_speed_template
);
1881 if (mode
> 400 && mode
< 500) break;
1884 test_ahash_speed("tgr160", sec
, generic_hash_speed_template
);
1885 if (mode
> 400 && mode
< 500) break;
1888 test_ahash_speed("tgr192", sec
, generic_hash_speed_template
);
1889 if (mode
> 400 && mode
< 500) break;
1892 test_ahash_speed("sha224", sec
, generic_hash_speed_template
);
1893 if (mode
> 400 && mode
< 500) break;
1896 test_ahash_speed("rmd128", sec
, generic_hash_speed_template
);
1897 if (mode
> 400 && mode
< 500) break;
1900 test_ahash_speed("rmd160", sec
, generic_hash_speed_template
);
1901 if (mode
> 400 && mode
< 500) break;
1904 test_ahash_speed("rmd256", sec
, generic_hash_speed_template
);
1905 if (mode
> 400 && mode
< 500) break;
1908 test_ahash_speed("rmd320", sec
, generic_hash_speed_template
);
1909 if (mode
> 400 && mode
< 500) break;
1915 test_acipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1916 speed_template_16_24_32
);
1917 test_acipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1918 speed_template_16_24_32
);
1919 test_acipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1920 speed_template_16_24_32
);
1921 test_acipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1922 speed_template_16_24_32
);
1923 test_acipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1924 speed_template_32_40_48
);
1925 test_acipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1926 speed_template_32_40_48
);
1927 test_acipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1928 speed_template_32_48_64
);
1929 test_acipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1930 speed_template_32_48_64
);
1931 test_acipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
1932 speed_template_16_24_32
);
1933 test_acipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
1934 speed_template_16_24_32
);
1935 test_acipher_speed("cfb(aes)", ENCRYPT
, sec
, NULL
, 0,
1936 speed_template_16_24_32
);
1937 test_acipher_speed("cfb(aes)", DECRYPT
, sec
, NULL
, 0,
1938 speed_template_16_24_32
);
1939 test_acipher_speed("ofb(aes)", ENCRYPT
, sec
, NULL
, 0,
1940 speed_template_16_24_32
);
1941 test_acipher_speed("ofb(aes)", DECRYPT
, sec
, NULL
, 0,
1942 speed_template_16_24_32
);
1943 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT
, sec
, NULL
, 0,
1944 speed_template_20_28_36
);
1945 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT
, sec
, NULL
, 0,
1946 speed_template_20_28_36
);
1950 test_acipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1951 des3_speed_template
, DES3_SPEED_VECTORS
,
1953 test_acipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1954 des3_speed_template
, DES3_SPEED_VECTORS
,
1956 test_acipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1957 des3_speed_template
, DES3_SPEED_VECTORS
,
1959 test_acipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1960 des3_speed_template
, DES3_SPEED_VECTORS
,
1962 test_acipher_speed("cfb(des3_ede)", ENCRYPT
, sec
,
1963 des3_speed_template
, DES3_SPEED_VECTORS
,
1965 test_acipher_speed("cfb(des3_ede)", DECRYPT
, sec
,
1966 des3_speed_template
, DES3_SPEED_VECTORS
,
1968 test_acipher_speed("ofb(des3_ede)", ENCRYPT
, sec
,
1969 des3_speed_template
, DES3_SPEED_VECTORS
,
1971 test_acipher_speed("ofb(des3_ede)", DECRYPT
, sec
,
1972 des3_speed_template
, DES3_SPEED_VECTORS
,
1977 test_acipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1979 test_acipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1981 test_acipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1983 test_acipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1985 test_acipher_speed("cfb(des)", ENCRYPT
, sec
, NULL
, 0,
1987 test_acipher_speed("cfb(des)", DECRYPT
, sec
, NULL
, 0,
1989 test_acipher_speed("ofb(des)", ENCRYPT
, sec
, NULL
, 0,
1991 test_acipher_speed("ofb(des)", DECRYPT
, sec
, NULL
, 0,
1996 test_acipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
1997 speed_template_16_32
);
1998 test_acipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
1999 speed_template_16_32
);
2000 test_acipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
2001 speed_template_16_32
);
2002 test_acipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
2003 speed_template_16_32
);
2004 test_acipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
2005 speed_template_16_32
);
2006 test_acipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
2007 speed_template_16_32
);
2008 test_acipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
2009 speed_template_32_48
);
2010 test_acipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
2011 speed_template_32_48
);
2012 test_acipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
2013 speed_template_32_64
);
2014 test_acipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
2015 speed_template_32_64
);
2019 test_acipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
2020 speed_template_16_24_32
);
2021 test_acipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
2022 speed_template_16_24_32
);
2023 test_acipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
2024 speed_template_16_24_32
);
2025 test_acipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
2026 speed_template_16_24_32
);
2027 test_acipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
2028 speed_template_16_24_32
);
2029 test_acipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
2030 speed_template_16_24_32
);
2031 test_acipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
2032 speed_template_32_40_48
);
2033 test_acipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
2034 speed_template_32_40_48
);
2035 test_acipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
2036 speed_template_32_48_64
);
2037 test_acipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
2038 speed_template_32_48_64
);
2042 test_acipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
2047 test_acipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
2048 speed_template_8_16
);
2049 test_acipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
2050 speed_template_8_16
);
2051 test_acipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
2052 speed_template_8_16
);
2053 test_acipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
2054 speed_template_8_16
);
2055 test_acipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
2056 speed_template_8_16
);
2057 test_acipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
2058 speed_template_8_16
);
2062 test_acipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
2063 speed_template_16_32
);
2064 test_acipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
2065 speed_template_16_32
);
2066 test_acipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
2067 speed_template_16_32
);
2068 test_acipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
2069 speed_template_16_32
);
2070 test_acipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
2071 speed_template_16_32
);
2072 test_acipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
2073 speed_template_16_32
);
2074 test_acipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
2075 speed_template_32_48
);
2076 test_acipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
2077 speed_template_32_48
);
2078 test_acipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
2079 speed_template_32_64
);
2080 test_acipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
2081 speed_template_32_64
);
2085 test_acipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
2086 speed_template_16_32
);
2087 test_acipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
2088 speed_template_16_32
);
2089 test_acipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
2090 speed_template_16_32
);
2091 test_acipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
2092 speed_template_16_32
);
2093 test_acipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
2094 speed_template_16_32
);
2095 test_acipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
2096 speed_template_16_32
);
2097 test_acipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
2098 speed_template_32_48
);
2099 test_acipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
2100 speed_template_32_48
);
2101 test_acipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
2102 speed_template_32_64
);
2103 test_acipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
2104 speed_template_32_64
);
2108 test_acipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2109 speed_template_8_32
);
2110 test_acipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
2111 speed_template_8_32
);
2112 test_acipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2113 speed_template_8_32
);
2114 test_acipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
2115 speed_template_8_32
);
2116 test_acipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2117 speed_template_8_32
);
2118 test_acipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
2119 speed_template_8_32
);
2130 static int do_alg_test(const char *alg
, u32 type
, u32 mask
)
2132 return crypto_has_alg(alg
, type
, mask
?: CRYPTO_ALG_TYPE_MASK
) ?
2136 static int __init
tcrypt_mod_init(void)
2141 for (i
= 0; i
< TVMEMSIZE
; i
++) {
2142 tvmem
[i
] = (void *)__get_free_page(GFP_KERNEL
);
2148 err
= do_alg_test(alg
, type
, mask
);
2150 err
= do_test(mode
);
2153 printk(KERN_ERR
"tcrypt: one or more tests failed!\n");
2157 /* We intentionaly return -EAGAIN to prevent keeping the module,
2158 * unless we're running in fips mode. It does all its work from
2159 * init() and doesn't offer any runtime functionality, but in
2160 * the fips case, checking for a successful load is helpful.
2161 * => we don't need it in the memory, do we?
2168 for (i
= 0; i
< TVMEMSIZE
&& tvmem
[i
]; i
++)
2169 free_page((unsigned long)tvmem
[i
]);
2175 * If an init function is provided, an exit function must also be provided
2176 * to allow module unload.
2178 static void __exit
tcrypt_mod_fini(void) { }
2180 module_init(tcrypt_mod_init
);
2181 module_exit(tcrypt_mod_fini
);
2183 module_param(alg
, charp
, 0);
2184 module_param(type
, uint
, 0);
2185 module_param(mask
, uint
, 0);
2186 module_param(mode
, int, 0);
2187 module_param(sec
, uint
, 0);
2188 MODULE_PARM_DESC(sec
, "Length in seconds of speed tests "
2189 "(defaults to zero which uses CPU cycles instead)");
2191 MODULE_LICENSE("GPL");
2192 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2193 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");