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()
52 * return a string with the driver name
54 #define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm))
57 * Used by test_cipher_speed()
59 static unsigned int sec
;
61 static char *alg
= NULL
;
65 static char *tvmem
[TVMEMSIZE
];
67 static char *check
[] = {
68 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
69 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
70 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
71 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
72 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
73 "lzo", "cts", "zlib", NULL
76 static int test_cipher_jiffies(struct blkcipher_desc
*desc
, int enc
,
77 struct scatterlist
*sg
, int blen
, int secs
)
79 unsigned long start
, end
;
83 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
84 time_before(jiffies
, end
); bcount
++) {
86 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
88 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
94 printk("%d operations in %d seconds (%ld bytes)\n",
95 bcount
, secs
, (long)bcount
* blen
);
99 static int test_cipher_cycles(struct blkcipher_desc
*desc
, int enc
,
100 struct scatterlist
*sg
, int blen
)
102 unsigned long cycles
= 0;
109 for (i
= 0; i
< 4; i
++) {
111 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
113 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
119 /* The real thing. */
120 for (i
= 0; i
< 8; i
++) {
123 start
= get_cycles();
125 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
127 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
133 cycles
+= end
- start
;
140 printk("1 operation in %lu cycles (%d bytes)\n",
141 (cycles
+ 4) / 8, blen
);
146 static int test_aead_jiffies(struct aead_request
*req
, int enc
,
149 unsigned long start
, end
;
153 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
154 time_before(jiffies
, end
); bcount
++) {
156 ret
= crypto_aead_encrypt(req
);
158 ret
= crypto_aead_decrypt(req
);
164 printk("%d operations in %d seconds (%ld bytes)\n",
165 bcount
, secs
, (long)bcount
* blen
);
169 static int test_aead_cycles(struct aead_request
*req
, int enc
, int blen
)
171 unsigned long cycles
= 0;
178 for (i
= 0; i
< 4; i
++) {
180 ret
= crypto_aead_encrypt(req
);
182 ret
= crypto_aead_decrypt(req
);
188 /* The real thing. */
189 for (i
= 0; i
< 8; i
++) {
192 start
= get_cycles();
194 ret
= crypto_aead_encrypt(req
);
196 ret
= crypto_aead_decrypt(req
);
202 cycles
+= end
- start
;
209 printk("1 operation in %lu cycles (%d bytes)\n",
210 (cycles
+ 4) / 8, blen
);
215 static u32 block_sizes
[] = { 16, 64, 256, 1024, 8192, 0 };
216 static u32 aead_sizes
[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
221 static int testmgr_alloc_buf(char *buf
[XBUFSIZE
])
225 for (i
= 0; i
< XBUFSIZE
; i
++) {
226 buf
[i
] = (void *)__get_free_page(GFP_KERNEL
);
235 free_page((unsigned long)buf
[i
]);
240 static void testmgr_free_buf(char *buf
[XBUFSIZE
])
244 for (i
= 0; i
< XBUFSIZE
; i
++)
245 free_page((unsigned long)buf
[i
]);
248 static void sg_init_aead(struct scatterlist
*sg
, char *xbuf
[XBUFSIZE
],
251 int np
= (buflen
+ PAGE_SIZE
- 1)/PAGE_SIZE
;
258 rem
= buflen
% PAGE_SIZE
;
261 sg_init_table(sg
, np
+ 1);
263 for (k
= 0; k
< np
; k
++)
264 sg_set_buf(&sg
[k
+ 1], xbuf
[k
], PAGE_SIZE
);
266 sg_set_buf(&sg
[k
+ 1], xbuf
[k
], rem
);
269 static void test_aead_speed(const char *algo
, int enc
, unsigned int secs
,
270 struct aead_speed_template
*template,
271 unsigned int tcount
, u8 authsize
,
272 unsigned int aad_size
, u8
*keysize
)
275 struct crypto_aead
*tfm
;
278 struct aead_request
*req
;
279 struct scatterlist
*sg
;
280 struct scatterlist
*sgout
;
284 char *xbuf
[XBUFSIZE
];
285 char *xoutbuf
[XBUFSIZE
];
286 char *axbuf
[XBUFSIZE
];
287 unsigned int *b_size
;
290 iv
= kzalloc(MAX_IVLEN
, GFP_KERNEL
);
294 if (aad_size
>= PAGE_SIZE
) {
295 pr_err("associate data length (%u) too big\n", aad_size
);
304 if (testmgr_alloc_buf(xbuf
))
306 if (testmgr_alloc_buf(axbuf
))
308 if (testmgr_alloc_buf(xoutbuf
))
311 sg
= kmalloc(sizeof(*sg
) * 9 * 2, GFP_KERNEL
);
316 tfm
= crypto_alloc_aead(algo
, 0, 0);
319 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo
,
324 printk(KERN_INFO
"\ntesting speed of %s (%s) %s\n", algo
,
325 get_driver_name(crypto_aead
, tfm
), e
);
327 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
329 pr_err("alg: aead: Failed to allocate request for %s\n",
339 memset(assoc
, 0xff, aad_size
);
341 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
342 pr_err("template (%u) too big for tvmem (%lu)\n",
344 TVMEMSIZE
* PAGE_SIZE
);
349 for (j
= 0; j
< tcount
; j
++) {
350 if (template[j
].klen
== *keysize
) {
351 key
= template[j
].key
;
355 ret
= crypto_aead_setkey(tfm
, key
, *keysize
);
356 ret
= crypto_aead_setauthsize(tfm
, authsize
);
358 iv_len
= crypto_aead_ivsize(tfm
);
360 memset(iv
, 0xff, iv_len
);
362 crypto_aead_clear_flags(tfm
, ~0);
363 printk(KERN_INFO
"test %u (%d bit key, %d byte blocks): ",
364 i
, *keysize
* 8, *b_size
);
367 memset(tvmem
[0], 0xff, PAGE_SIZE
);
370 pr_err("setkey() failed flags=%x\n",
371 crypto_aead_get_flags(tfm
));
375 sg_init_aead(sg
, xbuf
,
376 *b_size
+ (enc
? authsize
: 0));
378 sg_init_aead(sgout
, xoutbuf
,
379 *b_size
+ (enc
? authsize
: 0));
381 sg_set_buf(&sg
[0], assoc
, aad_size
);
382 sg_set_buf(&sgout
[0], assoc
, aad_size
);
384 aead_request_set_crypt(req
, sg
, sgout
, *b_size
, iv
);
385 aead_request_set_ad(req
, aad_size
);
388 ret
= test_aead_jiffies(req
, enc
, *b_size
,
391 ret
= test_aead_cycles(req
, enc
, *b_size
);
394 pr_err("%s() failed return code=%d\n", e
, ret
);
404 aead_request_free(req
);
406 crypto_free_aead(tfm
);
410 testmgr_free_buf(xoutbuf
);
412 testmgr_free_buf(axbuf
);
414 testmgr_free_buf(xbuf
);
420 static void test_cipher_speed(const char *algo
, int enc
, unsigned int secs
,
421 struct cipher_speed_template
*template,
422 unsigned int tcount
, u8
*keysize
)
424 unsigned int ret
, i
, j
, iv_len
;
427 struct crypto_blkcipher
*tfm
;
428 struct blkcipher_desc desc
;
437 tfm
= crypto_alloc_blkcipher(algo
, 0, CRYPTO_ALG_ASYNC
);
440 printk("failed to load transform for %s: %ld\n", algo
,
447 printk(KERN_INFO
"\ntesting speed of %s (%s) %s\n", algo
,
448 get_driver_name(crypto_blkcipher
, tfm
), e
);
453 b_size
= block_sizes
;
455 struct scatterlist sg
[TVMEMSIZE
];
457 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
458 printk("template (%u) too big for "
459 "tvmem (%lu)\n", *keysize
+ *b_size
,
460 TVMEMSIZE
* PAGE_SIZE
);
464 printk("test %u (%d bit key, %d byte blocks): ", i
,
465 *keysize
* 8, *b_size
);
467 memset(tvmem
[0], 0xff, PAGE_SIZE
);
469 /* set key, plain text and IV */
471 for (j
= 0; j
< tcount
; j
++) {
472 if (template[j
].klen
== *keysize
) {
473 key
= template[j
].key
;
478 ret
= crypto_blkcipher_setkey(tfm
, key
, *keysize
);
480 printk("setkey() failed flags=%x\n",
481 crypto_blkcipher_get_flags(tfm
));
485 sg_init_table(sg
, TVMEMSIZE
);
486 sg_set_buf(sg
, tvmem
[0] + *keysize
,
487 PAGE_SIZE
- *keysize
);
488 for (j
= 1; j
< TVMEMSIZE
; j
++) {
489 sg_set_buf(sg
+ j
, tvmem
[j
], PAGE_SIZE
);
490 memset (tvmem
[j
], 0xff, PAGE_SIZE
);
493 iv_len
= crypto_blkcipher_ivsize(tfm
);
495 memset(&iv
, 0xff, iv_len
);
496 crypto_blkcipher_set_iv(tfm
, iv
, iv_len
);
500 ret
= test_cipher_jiffies(&desc
, enc
, sg
,
503 ret
= test_cipher_cycles(&desc
, enc
, sg
,
507 printk("%s() failed flags=%x\n", e
, desc
.flags
);
517 crypto_free_blkcipher(tfm
);
520 static int test_hash_jiffies_digest(struct hash_desc
*desc
,
521 struct scatterlist
*sg
, int blen
,
524 unsigned long start
, end
;
528 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
529 time_before(jiffies
, end
); bcount
++) {
530 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
535 printk("%6u opers/sec, %9lu bytes/sec\n",
536 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
541 static int test_hash_jiffies(struct hash_desc
*desc
, struct scatterlist
*sg
,
542 int blen
, int plen
, char *out
, int secs
)
544 unsigned long start
, end
;
549 return test_hash_jiffies_digest(desc
, sg
, blen
, out
, secs
);
551 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
552 time_before(jiffies
, end
); bcount
++) {
553 ret
= crypto_hash_init(desc
);
556 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
557 ret
= crypto_hash_update(desc
, sg
, plen
);
561 /* we assume there is enough space in 'out' for the result */
562 ret
= crypto_hash_final(desc
, out
);
567 printk("%6u opers/sec, %9lu bytes/sec\n",
568 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
573 static int test_hash_cycles_digest(struct hash_desc
*desc
,
574 struct scatterlist
*sg
, int blen
, char *out
)
576 unsigned long cycles
= 0;
583 for (i
= 0; i
< 4; i
++) {
584 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
589 /* The real thing. */
590 for (i
= 0; i
< 8; i
++) {
593 start
= get_cycles();
595 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
601 cycles
+= end
- start
;
610 printk("%6lu cycles/operation, %4lu cycles/byte\n",
611 cycles
/ 8, cycles
/ (8 * blen
));
616 static int test_hash_cycles(struct hash_desc
*desc
, struct scatterlist
*sg
,
617 int blen
, int plen
, char *out
)
619 unsigned long cycles
= 0;
624 return test_hash_cycles_digest(desc
, sg
, blen
, out
);
629 for (i
= 0; i
< 4; i
++) {
630 ret
= crypto_hash_init(desc
);
633 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
634 ret
= crypto_hash_update(desc
, sg
, plen
);
638 ret
= crypto_hash_final(desc
, out
);
643 /* The real thing. */
644 for (i
= 0; i
< 8; i
++) {
647 start
= get_cycles();
649 ret
= crypto_hash_init(desc
);
652 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
653 ret
= crypto_hash_update(desc
, sg
, plen
);
657 ret
= crypto_hash_final(desc
, out
);
663 cycles
+= end
- start
;
672 printk("%6lu cycles/operation, %4lu cycles/byte\n",
673 cycles
/ 8, cycles
/ (8 * blen
));
678 static void test_hash_sg_init(struct scatterlist
*sg
)
682 sg_init_table(sg
, TVMEMSIZE
);
683 for (i
= 0; i
< TVMEMSIZE
; i
++) {
684 sg_set_buf(sg
+ i
, tvmem
[i
], PAGE_SIZE
);
685 memset(tvmem
[i
], 0xff, PAGE_SIZE
);
689 static void test_hash_speed(const char *algo
, unsigned int secs
,
690 struct hash_speed
*speed
)
692 struct scatterlist sg
[TVMEMSIZE
];
693 struct crypto_hash
*tfm
;
694 struct hash_desc desc
;
695 static char output
[1024];
699 tfm
= crypto_alloc_hash(algo
, 0, CRYPTO_ALG_ASYNC
);
702 printk(KERN_ERR
"failed to load transform for %s: %ld\n", algo
,
707 printk(KERN_INFO
"\ntesting speed of %s (%s)\n", algo
,
708 get_driver_name(crypto_hash
, tfm
));
713 if (crypto_hash_digestsize(tfm
) > sizeof(output
)) {
714 printk(KERN_ERR
"digestsize(%u) > outputbuffer(%zu)\n",
715 crypto_hash_digestsize(tfm
), sizeof(output
));
719 test_hash_sg_init(sg
);
720 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
721 if (speed
[i
].blen
> TVMEMSIZE
* PAGE_SIZE
) {
723 "template (%u) too big for tvmem (%lu)\n",
724 speed
[i
].blen
, TVMEMSIZE
* PAGE_SIZE
);
729 crypto_hash_setkey(tfm
, tvmem
[0], speed
[i
].klen
);
731 printk(KERN_INFO
"test%3u "
732 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
733 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
736 ret
= test_hash_jiffies(&desc
, sg
, speed
[i
].blen
,
737 speed
[i
].plen
, output
, secs
);
739 ret
= test_hash_cycles(&desc
, sg
, speed
[i
].blen
,
740 speed
[i
].plen
, output
);
743 printk(KERN_ERR
"hashing failed ret=%d\n", ret
);
749 crypto_free_hash(tfm
);
752 struct tcrypt_result
{
753 struct completion completion
;
757 static void tcrypt_complete(struct crypto_async_request
*req
, int err
)
759 struct tcrypt_result
*res
= req
->data
;
761 if (err
== -EINPROGRESS
)
765 complete(&res
->completion
);
768 static inline int do_one_ahash_op(struct ahash_request
*req
, int ret
)
770 if (ret
== -EINPROGRESS
|| ret
== -EBUSY
) {
771 struct tcrypt_result
*tr
= req
->base
.data
;
773 wait_for_completion(&tr
->completion
);
774 reinit_completion(&tr
->completion
);
780 static int test_ahash_jiffies_digest(struct ahash_request
*req
, int blen
,
783 unsigned long start
, end
;
787 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
788 time_before(jiffies
, end
); bcount
++) {
789 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
794 printk("%6u opers/sec, %9lu bytes/sec\n",
795 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
800 static int test_ahash_jiffies(struct ahash_request
*req
, int blen
,
801 int plen
, char *out
, int secs
)
803 unsigned long start
, end
;
808 return test_ahash_jiffies_digest(req
, blen
, out
, secs
);
810 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
811 time_before(jiffies
, end
); bcount
++) {
812 ret
= do_one_ahash_op(req
, crypto_ahash_init(req
));
815 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
816 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
820 /* we assume there is enough space in 'out' for the result */
821 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
826 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
827 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
832 static int test_ahash_cycles_digest(struct ahash_request
*req
, int blen
,
835 unsigned long cycles
= 0;
839 for (i
= 0; i
< 4; i
++) {
840 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
845 /* The real thing. */
846 for (i
= 0; i
< 8; i
++) {
849 start
= get_cycles();
851 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
857 cycles
+= end
- start
;
864 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
865 cycles
/ 8, cycles
/ (8 * blen
));
870 static int test_ahash_cycles(struct ahash_request
*req
, int blen
,
873 unsigned long cycles
= 0;
877 return test_ahash_cycles_digest(req
, blen
, out
);
880 for (i
= 0; i
< 4; i
++) {
881 ret
= do_one_ahash_op(req
, crypto_ahash_init(req
));
884 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
885 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
889 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
894 /* The real thing. */
895 for (i
= 0; i
< 8; i
++) {
898 start
= get_cycles();
900 ret
= do_one_ahash_op(req
, crypto_ahash_init(req
));
903 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
904 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
908 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
914 cycles
+= end
- start
;
921 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
922 cycles
/ 8, cycles
/ (8 * blen
));
927 static void test_ahash_speed(const char *algo
, unsigned int secs
,
928 struct hash_speed
*speed
)
930 struct scatterlist sg
[TVMEMSIZE
];
931 struct tcrypt_result tresult
;
932 struct ahash_request
*req
;
933 struct crypto_ahash
*tfm
;
934 static char output
[1024];
937 tfm
= crypto_alloc_ahash(algo
, 0, 0);
939 pr_err("failed to load transform for %s: %ld\n",
944 printk(KERN_INFO
"\ntesting speed of async %s (%s)\n", algo
,
945 get_driver_name(crypto_ahash
, tfm
));
947 if (crypto_ahash_digestsize(tfm
) > sizeof(output
)) {
948 pr_err("digestsize(%u) > outputbuffer(%zu)\n",
949 crypto_ahash_digestsize(tfm
), sizeof(output
));
953 test_hash_sg_init(sg
);
954 req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
956 pr_err("ahash request allocation failure\n");
960 init_completion(&tresult
.completion
);
961 ahash_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
962 tcrypt_complete
, &tresult
);
964 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
965 if (speed
[i
].blen
> TVMEMSIZE
* PAGE_SIZE
) {
966 pr_err("template (%u) too big for tvmem (%lu)\n",
967 speed
[i
].blen
, TVMEMSIZE
* PAGE_SIZE
);
972 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
973 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
975 ahash_request_set_crypt(req
, sg
, output
, speed
[i
].plen
);
978 ret
= test_ahash_jiffies(req
, speed
[i
].blen
,
979 speed
[i
].plen
, output
, secs
);
981 ret
= test_ahash_cycles(req
, speed
[i
].blen
,
982 speed
[i
].plen
, output
);
985 pr_err("hashing failed ret=%d\n", ret
);
990 ahash_request_free(req
);
993 crypto_free_ahash(tfm
);
996 static inline int do_one_acipher_op(struct ablkcipher_request
*req
, int ret
)
998 if (ret
== -EINPROGRESS
|| ret
== -EBUSY
) {
999 struct tcrypt_result
*tr
= req
->base
.data
;
1001 wait_for_completion(&tr
->completion
);
1002 reinit_completion(&tr
->completion
);
1009 static int test_acipher_jiffies(struct ablkcipher_request
*req
, int enc
,
1012 unsigned long start
, end
;
1016 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
1017 time_before(jiffies
, end
); bcount
++) {
1019 ret
= do_one_acipher_op(req
,
1020 crypto_ablkcipher_encrypt(req
));
1022 ret
= do_one_acipher_op(req
,
1023 crypto_ablkcipher_decrypt(req
));
1029 pr_cont("%d operations in %d seconds (%ld bytes)\n",
1030 bcount
, secs
, (long)bcount
* blen
);
1034 static int test_acipher_cycles(struct ablkcipher_request
*req
, int enc
,
1037 unsigned long cycles
= 0;
1042 for (i
= 0; i
< 4; i
++) {
1044 ret
= do_one_acipher_op(req
,
1045 crypto_ablkcipher_encrypt(req
));
1047 ret
= do_one_acipher_op(req
,
1048 crypto_ablkcipher_decrypt(req
));
1054 /* The real thing. */
1055 for (i
= 0; i
< 8; i
++) {
1056 cycles_t start
, end
;
1058 start
= get_cycles();
1060 ret
= do_one_acipher_op(req
,
1061 crypto_ablkcipher_encrypt(req
));
1063 ret
= do_one_acipher_op(req
,
1064 crypto_ablkcipher_decrypt(req
));
1070 cycles
+= end
- start
;
1075 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1076 (cycles
+ 4) / 8, blen
);
1081 static void test_acipher_speed(const char *algo
, int enc
, unsigned int secs
,
1082 struct cipher_speed_template
*template,
1083 unsigned int tcount
, u8
*keysize
)
1085 unsigned int ret
, i
, j
, k
, iv_len
;
1086 struct tcrypt_result tresult
;
1089 struct ablkcipher_request
*req
;
1090 struct crypto_ablkcipher
*tfm
;
1099 init_completion(&tresult
.completion
);
1101 tfm
= crypto_alloc_ablkcipher(algo
, 0, 0);
1104 pr_err("failed to load transform for %s: %ld\n", algo
,
1109 pr_info("\ntesting speed of async %s (%s) %s\n", algo
,
1110 get_driver_name(crypto_ablkcipher
, tfm
), e
);
1112 req
= ablkcipher_request_alloc(tfm
, GFP_KERNEL
);
1114 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1119 ablkcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
1120 tcrypt_complete
, &tresult
);
1124 b_size
= block_sizes
;
1127 struct scatterlist sg
[TVMEMSIZE
];
1129 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
1130 pr_err("template (%u) too big for "
1131 "tvmem (%lu)\n", *keysize
+ *b_size
,
1132 TVMEMSIZE
* PAGE_SIZE
);
1136 pr_info("test %u (%d bit key, %d byte blocks): ", i
,
1137 *keysize
* 8, *b_size
);
1139 memset(tvmem
[0], 0xff, PAGE_SIZE
);
1141 /* set key, plain text and IV */
1143 for (j
= 0; j
< tcount
; j
++) {
1144 if (template[j
].klen
== *keysize
) {
1145 key
= template[j
].key
;
1150 crypto_ablkcipher_clear_flags(tfm
, ~0);
1152 ret
= crypto_ablkcipher_setkey(tfm
, key
, *keysize
);
1154 pr_err("setkey() failed flags=%x\n",
1155 crypto_ablkcipher_get_flags(tfm
));
1159 k
= *keysize
+ *b_size
;
1160 sg_init_table(sg
, DIV_ROUND_UP(k
, PAGE_SIZE
));
1162 if (k
> PAGE_SIZE
) {
1163 sg_set_buf(sg
, tvmem
[0] + *keysize
,
1164 PAGE_SIZE
- *keysize
);
1167 while (k
> PAGE_SIZE
) {
1168 sg_set_buf(sg
+ j
, tvmem
[j
], PAGE_SIZE
);
1169 memset(tvmem
[j
], 0xff, PAGE_SIZE
);
1173 sg_set_buf(sg
+ j
, tvmem
[j
], k
);
1174 memset(tvmem
[j
], 0xff, k
);
1176 sg_set_buf(sg
, tvmem
[0] + *keysize
, *b_size
);
1179 iv_len
= crypto_ablkcipher_ivsize(tfm
);
1181 memset(&iv
, 0xff, iv_len
);
1183 ablkcipher_request_set_crypt(req
, sg
, sg
, *b_size
, iv
);
1186 ret
= test_acipher_jiffies(req
, enc
,
1189 ret
= test_acipher_cycles(req
, enc
,
1193 pr_err("%s() failed flags=%x\n", e
,
1194 crypto_ablkcipher_get_flags(tfm
));
1204 ablkcipher_request_free(req
);
1206 crypto_free_ablkcipher(tfm
);
1209 static void test_available(void)
1211 char **name
= check
;
1214 printk("alg %s ", *name
);
1215 printk(crypto_has_alg(*name
, 0, 0) ?
1216 "found\n" : "not found\n");
1221 static inline int tcrypt_test(const char *alg
)
1225 ret
= alg_test(alg
, alg
, 0, 0);
1226 /* non-fips algs return -EINVAL in fips mode */
1227 if (fips_enabled
&& ret
== -EINVAL
)
1232 static int do_test(const char *alg
, u32 type
, u32 mask
, int m
)
1240 if (!crypto_has_alg(alg
, type
,
1241 mask
?: CRYPTO_ALG_TYPE_MASK
))
1246 for (i
= 1; i
< 200; i
++)
1247 ret
+= do_test(NULL
, 0, 0, i
);
1251 ret
+= tcrypt_test("md5");
1255 ret
+= tcrypt_test("sha1");
1259 ret
+= tcrypt_test("ecb(des)");
1260 ret
+= tcrypt_test("cbc(des)");
1261 ret
+= tcrypt_test("ctr(des)");
1265 ret
+= tcrypt_test("ecb(des3_ede)");
1266 ret
+= tcrypt_test("cbc(des3_ede)");
1267 ret
+= tcrypt_test("ctr(des3_ede)");
1271 ret
+= tcrypt_test("md4");
1275 ret
+= tcrypt_test("sha256");
1279 ret
+= tcrypt_test("ecb(blowfish)");
1280 ret
+= tcrypt_test("cbc(blowfish)");
1281 ret
+= tcrypt_test("ctr(blowfish)");
1285 ret
+= tcrypt_test("ecb(twofish)");
1286 ret
+= tcrypt_test("cbc(twofish)");
1287 ret
+= tcrypt_test("ctr(twofish)");
1288 ret
+= tcrypt_test("lrw(twofish)");
1289 ret
+= tcrypt_test("xts(twofish)");
1293 ret
+= tcrypt_test("ecb(serpent)");
1294 ret
+= tcrypt_test("cbc(serpent)");
1295 ret
+= tcrypt_test("ctr(serpent)");
1296 ret
+= tcrypt_test("lrw(serpent)");
1297 ret
+= tcrypt_test("xts(serpent)");
1301 ret
+= tcrypt_test("ecb(aes)");
1302 ret
+= tcrypt_test("cbc(aes)");
1303 ret
+= tcrypt_test("lrw(aes)");
1304 ret
+= tcrypt_test("xts(aes)");
1305 ret
+= tcrypt_test("ctr(aes)");
1306 ret
+= tcrypt_test("rfc3686(ctr(aes))");
1310 ret
+= tcrypt_test("sha384");
1314 ret
+= tcrypt_test("sha512");
1318 ret
+= tcrypt_test("deflate");
1322 ret
+= tcrypt_test("ecb(cast5)");
1323 ret
+= tcrypt_test("cbc(cast5)");
1324 ret
+= tcrypt_test("ctr(cast5)");
1328 ret
+= tcrypt_test("ecb(cast6)");
1329 ret
+= tcrypt_test("cbc(cast6)");
1330 ret
+= tcrypt_test("ctr(cast6)");
1331 ret
+= tcrypt_test("lrw(cast6)");
1332 ret
+= tcrypt_test("xts(cast6)");
1336 ret
+= tcrypt_test("ecb(arc4)");
1340 ret
+= tcrypt_test("michael_mic");
1344 ret
+= tcrypt_test("crc32c");
1348 ret
+= tcrypt_test("ecb(tea)");
1352 ret
+= tcrypt_test("ecb(xtea)");
1356 ret
+= tcrypt_test("ecb(khazad)");
1360 ret
+= tcrypt_test("wp512");
1364 ret
+= tcrypt_test("wp384");
1368 ret
+= tcrypt_test("wp256");
1372 ret
+= tcrypt_test("ecb(tnepres)");
1376 ret
+= tcrypt_test("ecb(anubis)");
1377 ret
+= tcrypt_test("cbc(anubis)");
1381 ret
+= tcrypt_test("tgr192");
1385 ret
+= tcrypt_test("tgr160");
1389 ret
+= tcrypt_test("tgr128");
1393 ret
+= tcrypt_test("ecb(xeta)");
1397 ret
+= tcrypt_test("pcbc(fcrypt)");
1401 ret
+= tcrypt_test("ecb(camellia)");
1402 ret
+= tcrypt_test("cbc(camellia)");
1403 ret
+= tcrypt_test("ctr(camellia)");
1404 ret
+= tcrypt_test("lrw(camellia)");
1405 ret
+= tcrypt_test("xts(camellia)");
1409 ret
+= tcrypt_test("sha224");
1413 ret
+= tcrypt_test("salsa20");
1417 ret
+= tcrypt_test("gcm(aes)");
1421 ret
+= tcrypt_test("lzo");
1425 ret
+= tcrypt_test("ccm(aes)");
1429 ret
+= tcrypt_test("cts(cbc(aes))");
1433 ret
+= tcrypt_test("rmd128");
1437 ret
+= tcrypt_test("rmd160");
1441 ret
+= tcrypt_test("rmd256");
1445 ret
+= tcrypt_test("rmd320");
1449 ret
+= tcrypt_test("ecb(seed)");
1453 ret
+= tcrypt_test("zlib");
1457 ret
+= tcrypt_test("rfc4309(ccm(aes))");
1461 ret
+= tcrypt_test("ghash");
1465 ret
+= tcrypt_test("crct10dif");
1469 ret
+= tcrypt_test("hmac(md5)");
1473 ret
+= tcrypt_test("hmac(sha1)");
1477 ret
+= tcrypt_test("hmac(sha256)");
1481 ret
+= tcrypt_test("hmac(sha384)");
1485 ret
+= tcrypt_test("hmac(sha512)");
1489 ret
+= tcrypt_test("hmac(sha224)");
1493 ret
+= tcrypt_test("xcbc(aes)");
1497 ret
+= tcrypt_test("hmac(rmd128)");
1501 ret
+= tcrypt_test("hmac(rmd160)");
1505 ret
+= tcrypt_test("vmac(aes)");
1509 ret
+= tcrypt_test("hmac(crc32)");
1513 ret
+= tcrypt_test("ansi_cprng");
1517 ret
+= tcrypt_test("rfc4106(gcm(aes))");
1521 ret
+= tcrypt_test("rfc4543(gcm(aes))");
1525 ret
+= tcrypt_test("cmac(aes)");
1529 ret
+= tcrypt_test("cmac(des3_ede)");
1533 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1537 ret
+= tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1541 ret
+= tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1544 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(des))");
1547 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
1550 ret
+= tcrypt_test("authenc(hmac(sha224),cbc(des))");
1553 ret
+= tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
1556 ret
+= tcrypt_test("authenc(hmac(sha256),cbc(des))");
1559 ret
+= tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
1562 ret
+= tcrypt_test("authenc(hmac(sha384),cbc(des))");
1565 ret
+= tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
1568 ret
+= tcrypt_test("authenc(hmac(sha512),cbc(des))");
1571 ret
+= tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
1574 test_cipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1575 speed_template_16_24_32
);
1576 test_cipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1577 speed_template_16_24_32
);
1578 test_cipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1579 speed_template_16_24_32
);
1580 test_cipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1581 speed_template_16_24_32
);
1582 test_cipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1583 speed_template_32_40_48
);
1584 test_cipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1585 speed_template_32_40_48
);
1586 test_cipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1587 speed_template_32_48_64
);
1588 test_cipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1589 speed_template_32_48_64
);
1590 test_cipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
1591 speed_template_16_24_32
);
1592 test_cipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
1593 speed_template_16_24_32
);
1597 test_cipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1598 des3_speed_template
, DES3_SPEED_VECTORS
,
1600 test_cipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1601 des3_speed_template
, DES3_SPEED_VECTORS
,
1603 test_cipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1604 des3_speed_template
, DES3_SPEED_VECTORS
,
1606 test_cipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1607 des3_speed_template
, DES3_SPEED_VECTORS
,
1609 test_cipher_speed("ctr(des3_ede)", ENCRYPT
, sec
,
1610 des3_speed_template
, DES3_SPEED_VECTORS
,
1612 test_cipher_speed("ctr(des3_ede)", DECRYPT
, sec
,
1613 des3_speed_template
, DES3_SPEED_VECTORS
,
1618 test_cipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1619 speed_template_16_24_32
);
1620 test_cipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1621 speed_template_16_24_32
);
1622 test_cipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1623 speed_template_16_24_32
);
1624 test_cipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1625 speed_template_16_24_32
);
1626 test_cipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
1627 speed_template_16_24_32
);
1628 test_cipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
1629 speed_template_16_24_32
);
1630 test_cipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
1631 speed_template_32_40_48
);
1632 test_cipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
1633 speed_template_32_40_48
);
1634 test_cipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
1635 speed_template_32_48_64
);
1636 test_cipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
1637 speed_template_32_48_64
);
1641 test_cipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1642 speed_template_8_32
);
1643 test_cipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
1644 speed_template_8_32
);
1645 test_cipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1646 speed_template_8_32
);
1647 test_cipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
1648 speed_template_8_32
);
1649 test_cipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1650 speed_template_8_32
);
1651 test_cipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
1652 speed_template_8_32
);
1656 test_cipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1658 test_cipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1660 test_cipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1662 test_cipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1667 test_cipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
1668 speed_template_16_24_32
);
1669 test_cipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
1670 speed_template_16_24_32
);
1671 test_cipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
1672 speed_template_16_24_32
);
1673 test_cipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
1674 speed_template_16_24_32
);
1675 test_cipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
1676 speed_template_16_24_32
);
1677 test_cipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
1678 speed_template_16_24_32
);
1679 test_cipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
1680 speed_template_32_40_48
);
1681 test_cipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
1682 speed_template_32_40_48
);
1683 test_cipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
1684 speed_template_32_48_64
);
1685 test_cipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
1686 speed_template_32_48_64
);
1690 test_cipher_speed("salsa20", ENCRYPT
, sec
, NULL
, 0,
1691 speed_template_16_32
);
1695 test_cipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
1696 speed_template_16_32
);
1697 test_cipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
1698 speed_template_16_32
);
1699 test_cipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
1700 speed_template_16_32
);
1701 test_cipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
1702 speed_template_16_32
);
1703 test_cipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
1704 speed_template_16_32
);
1705 test_cipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
1706 speed_template_16_32
);
1707 test_cipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
1708 speed_template_32_48
);
1709 test_cipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
1710 speed_template_32_48
);
1711 test_cipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
1712 speed_template_32_64
);
1713 test_cipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
1714 speed_template_32_64
);
1718 test_cipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
1723 test_cipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
1724 speed_template_8_16
);
1725 test_cipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
1726 speed_template_8_16
);
1727 test_cipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
1728 speed_template_8_16
);
1729 test_cipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
1730 speed_template_8_16
);
1731 test_cipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
1732 speed_template_8_16
);
1733 test_cipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
1734 speed_template_8_16
);
1738 test_cipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
1739 speed_template_16_32
);
1740 test_cipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
1741 speed_template_16_32
);
1742 test_cipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
1743 speed_template_16_32
);
1744 test_cipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
1745 speed_template_16_32
);
1746 test_cipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
1747 speed_template_16_32
);
1748 test_cipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
1749 speed_template_16_32
);
1750 test_cipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
1751 speed_template_32_48
);
1752 test_cipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
1753 speed_template_32_48
);
1754 test_cipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
1755 speed_template_32_64
);
1756 test_cipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
1757 speed_template_32_64
);
1761 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT
, sec
,
1762 NULL
, 0, 16, 8, aead_speed_template_20
);
1766 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT
, sec
,
1767 NULL
, 0, 16, 8, aead_speed_template_19
);
1772 test_hash_speed(alg
, sec
, generic_hash_speed_template
);
1779 test_hash_speed("md4", sec
, generic_hash_speed_template
);
1780 if (mode
> 300 && mode
< 400) break;
1783 test_hash_speed("md5", sec
, generic_hash_speed_template
);
1784 if (mode
> 300 && mode
< 400) break;
1787 test_hash_speed("sha1", sec
, generic_hash_speed_template
);
1788 if (mode
> 300 && mode
< 400) break;
1791 test_hash_speed("sha256", sec
, generic_hash_speed_template
);
1792 if (mode
> 300 && mode
< 400) break;
1795 test_hash_speed("sha384", sec
, generic_hash_speed_template
);
1796 if (mode
> 300 && mode
< 400) break;
1799 test_hash_speed("sha512", sec
, generic_hash_speed_template
);
1800 if (mode
> 300 && mode
< 400) break;
1803 test_hash_speed("wp256", sec
, generic_hash_speed_template
);
1804 if (mode
> 300 && mode
< 400) break;
1807 test_hash_speed("wp384", sec
, generic_hash_speed_template
);
1808 if (mode
> 300 && mode
< 400) break;
1811 test_hash_speed("wp512", sec
, generic_hash_speed_template
);
1812 if (mode
> 300 && mode
< 400) break;
1815 test_hash_speed("tgr128", sec
, generic_hash_speed_template
);
1816 if (mode
> 300 && mode
< 400) break;
1819 test_hash_speed("tgr160", sec
, generic_hash_speed_template
);
1820 if (mode
> 300 && mode
< 400) break;
1823 test_hash_speed("tgr192", sec
, generic_hash_speed_template
);
1824 if (mode
> 300 && mode
< 400) break;
1827 test_hash_speed("sha224", sec
, generic_hash_speed_template
);
1828 if (mode
> 300 && mode
< 400) break;
1831 test_hash_speed("rmd128", sec
, generic_hash_speed_template
);
1832 if (mode
> 300 && mode
< 400) break;
1835 test_hash_speed("rmd160", sec
, generic_hash_speed_template
);
1836 if (mode
> 300 && mode
< 400) break;
1839 test_hash_speed("rmd256", sec
, generic_hash_speed_template
);
1840 if (mode
> 300 && mode
< 400) break;
1843 test_hash_speed("rmd320", sec
, generic_hash_speed_template
);
1844 if (mode
> 300 && mode
< 400) break;
1847 test_hash_speed("ghash-generic", sec
, hash_speed_template_16
);
1848 if (mode
> 300 && mode
< 400) break;
1851 test_hash_speed("crc32c", sec
, generic_hash_speed_template
);
1852 if (mode
> 300 && mode
< 400) break;
1855 test_hash_speed("crct10dif", sec
, generic_hash_speed_template
);
1856 if (mode
> 300 && mode
< 400) break;
1863 test_ahash_speed(alg
, sec
, generic_hash_speed_template
);
1870 test_ahash_speed("md4", sec
, generic_hash_speed_template
);
1871 if (mode
> 400 && mode
< 500) break;
1874 test_ahash_speed("md5", sec
, generic_hash_speed_template
);
1875 if (mode
> 400 && mode
< 500) break;
1878 test_ahash_speed("sha1", sec
, generic_hash_speed_template
);
1879 if (mode
> 400 && mode
< 500) break;
1882 test_ahash_speed("sha256", sec
, generic_hash_speed_template
);
1883 if (mode
> 400 && mode
< 500) break;
1886 test_ahash_speed("sha384", sec
, generic_hash_speed_template
);
1887 if (mode
> 400 && mode
< 500) break;
1890 test_ahash_speed("sha512", sec
, generic_hash_speed_template
);
1891 if (mode
> 400 && mode
< 500) break;
1894 test_ahash_speed("wp256", sec
, generic_hash_speed_template
);
1895 if (mode
> 400 && mode
< 500) break;
1898 test_ahash_speed("wp384", sec
, generic_hash_speed_template
);
1899 if (mode
> 400 && mode
< 500) break;
1902 test_ahash_speed("wp512", sec
, generic_hash_speed_template
);
1903 if (mode
> 400 && mode
< 500) break;
1906 test_ahash_speed("tgr128", sec
, generic_hash_speed_template
);
1907 if (mode
> 400 && mode
< 500) break;
1910 test_ahash_speed("tgr160", sec
, generic_hash_speed_template
);
1911 if (mode
> 400 && mode
< 500) break;
1914 test_ahash_speed("tgr192", sec
, generic_hash_speed_template
);
1915 if (mode
> 400 && mode
< 500) break;
1918 test_ahash_speed("sha224", sec
, generic_hash_speed_template
);
1919 if (mode
> 400 && mode
< 500) break;
1922 test_ahash_speed("rmd128", sec
, generic_hash_speed_template
);
1923 if (mode
> 400 && mode
< 500) break;
1926 test_ahash_speed("rmd160", sec
, generic_hash_speed_template
);
1927 if (mode
> 400 && mode
< 500) break;
1930 test_ahash_speed("rmd256", sec
, generic_hash_speed_template
);
1931 if (mode
> 400 && mode
< 500) break;
1934 test_ahash_speed("rmd320", sec
, generic_hash_speed_template
);
1935 if (mode
> 400 && mode
< 500) break;
1941 test_acipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1942 speed_template_16_24_32
);
1943 test_acipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1944 speed_template_16_24_32
);
1945 test_acipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1946 speed_template_16_24_32
);
1947 test_acipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1948 speed_template_16_24_32
);
1949 test_acipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1950 speed_template_32_40_48
);
1951 test_acipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1952 speed_template_32_40_48
);
1953 test_acipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1954 speed_template_32_48_64
);
1955 test_acipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1956 speed_template_32_48_64
);
1957 test_acipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
1958 speed_template_16_24_32
);
1959 test_acipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
1960 speed_template_16_24_32
);
1961 test_acipher_speed("cfb(aes)", ENCRYPT
, sec
, NULL
, 0,
1962 speed_template_16_24_32
);
1963 test_acipher_speed("cfb(aes)", DECRYPT
, sec
, NULL
, 0,
1964 speed_template_16_24_32
);
1965 test_acipher_speed("ofb(aes)", ENCRYPT
, sec
, NULL
, 0,
1966 speed_template_16_24_32
);
1967 test_acipher_speed("ofb(aes)", DECRYPT
, sec
, NULL
, 0,
1968 speed_template_16_24_32
);
1969 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT
, sec
, NULL
, 0,
1970 speed_template_20_28_36
);
1971 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT
, sec
, NULL
, 0,
1972 speed_template_20_28_36
);
1976 test_acipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1977 des3_speed_template
, DES3_SPEED_VECTORS
,
1979 test_acipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1980 des3_speed_template
, DES3_SPEED_VECTORS
,
1982 test_acipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1983 des3_speed_template
, DES3_SPEED_VECTORS
,
1985 test_acipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1986 des3_speed_template
, DES3_SPEED_VECTORS
,
1988 test_acipher_speed("cfb(des3_ede)", ENCRYPT
, sec
,
1989 des3_speed_template
, DES3_SPEED_VECTORS
,
1991 test_acipher_speed("cfb(des3_ede)", DECRYPT
, sec
,
1992 des3_speed_template
, DES3_SPEED_VECTORS
,
1994 test_acipher_speed("ofb(des3_ede)", ENCRYPT
, sec
,
1995 des3_speed_template
, DES3_SPEED_VECTORS
,
1997 test_acipher_speed("ofb(des3_ede)", DECRYPT
, sec
,
1998 des3_speed_template
, DES3_SPEED_VECTORS
,
2003 test_acipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
2005 test_acipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
2007 test_acipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
2009 test_acipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
2011 test_acipher_speed("cfb(des)", ENCRYPT
, sec
, NULL
, 0,
2013 test_acipher_speed("cfb(des)", DECRYPT
, sec
, NULL
, 0,
2015 test_acipher_speed("ofb(des)", ENCRYPT
, sec
, NULL
, 0,
2017 test_acipher_speed("ofb(des)", DECRYPT
, sec
, NULL
, 0,
2022 test_acipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
2023 speed_template_16_32
);
2024 test_acipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
2025 speed_template_16_32
);
2026 test_acipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
2027 speed_template_16_32
);
2028 test_acipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
2029 speed_template_16_32
);
2030 test_acipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
2031 speed_template_16_32
);
2032 test_acipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
2033 speed_template_16_32
);
2034 test_acipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
2035 speed_template_32_48
);
2036 test_acipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
2037 speed_template_32_48
);
2038 test_acipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
2039 speed_template_32_64
);
2040 test_acipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
2041 speed_template_32_64
);
2045 test_acipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
2046 speed_template_16_24_32
);
2047 test_acipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
2048 speed_template_16_24_32
);
2049 test_acipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
2050 speed_template_16_24_32
);
2051 test_acipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
2052 speed_template_16_24_32
);
2053 test_acipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
2054 speed_template_16_24_32
);
2055 test_acipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
2056 speed_template_16_24_32
);
2057 test_acipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
2058 speed_template_32_40_48
);
2059 test_acipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
2060 speed_template_32_40_48
);
2061 test_acipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
2062 speed_template_32_48_64
);
2063 test_acipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
2064 speed_template_32_48_64
);
2068 test_acipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
2073 test_acipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
2074 speed_template_8_16
);
2075 test_acipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
2076 speed_template_8_16
);
2077 test_acipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
2078 speed_template_8_16
);
2079 test_acipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
2080 speed_template_8_16
);
2081 test_acipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
2082 speed_template_8_16
);
2083 test_acipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
2084 speed_template_8_16
);
2088 test_acipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
2089 speed_template_16_32
);
2090 test_acipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
2091 speed_template_16_32
);
2092 test_acipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
2093 speed_template_16_32
);
2094 test_acipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
2095 speed_template_16_32
);
2096 test_acipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
2097 speed_template_16_32
);
2098 test_acipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
2099 speed_template_16_32
);
2100 test_acipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
2101 speed_template_32_48
);
2102 test_acipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
2103 speed_template_32_48
);
2104 test_acipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
2105 speed_template_32_64
);
2106 test_acipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
2107 speed_template_32_64
);
2111 test_acipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
2112 speed_template_16_32
);
2113 test_acipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
2114 speed_template_16_32
);
2115 test_acipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
2116 speed_template_16_32
);
2117 test_acipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
2118 speed_template_16_32
);
2119 test_acipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
2120 speed_template_16_32
);
2121 test_acipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
2122 speed_template_16_32
);
2123 test_acipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
2124 speed_template_32_48
);
2125 test_acipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
2126 speed_template_32_48
);
2127 test_acipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
2128 speed_template_32_64
);
2129 test_acipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
2130 speed_template_32_64
);
2134 test_acipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2135 speed_template_8_32
);
2136 test_acipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
2137 speed_template_8_32
);
2138 test_acipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2139 speed_template_8_32
);
2140 test_acipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
2141 speed_template_8_32
);
2142 test_acipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2143 speed_template_8_32
);
2144 test_acipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
2145 speed_template_8_32
);
2156 static int __init
tcrypt_mod_init(void)
2161 for (i
= 0; i
< TVMEMSIZE
; i
++) {
2162 tvmem
[i
] = (void *)__get_free_page(GFP_KERNEL
);
2167 err
= do_test(alg
, type
, mask
, mode
);
2170 printk(KERN_ERR
"tcrypt: one or more tests failed!\n");
2174 /* We intentionaly return -EAGAIN to prevent keeping the module,
2175 * unless we're running in fips mode. It does all its work from
2176 * init() and doesn't offer any runtime functionality, but in
2177 * the fips case, checking for a successful load is helpful.
2178 * => we don't need it in the memory, do we?
2185 for (i
= 0; i
< TVMEMSIZE
&& tvmem
[i
]; i
++)
2186 free_page((unsigned long)tvmem
[i
]);
2192 * If an init function is provided, an exit function must also be provided
2193 * to allow module unload.
2195 static void __exit
tcrypt_mod_fini(void) { }
2197 module_init(tcrypt_mod_init
);
2198 module_exit(tcrypt_mod_fini
);
2200 module_param(alg
, charp
, 0);
2201 module_param(type
, uint
, 0);
2202 module_param(mask
, uint
, 0);
2203 module_param(mode
, int, 0);
2204 module_param(sec
, uint
, 0);
2205 MODULE_PARM_DESC(sec
, "Length in seconds of speed tests "
2206 "(defaults to zero which uses CPU cycles instead)");
2208 MODULE_LICENSE("GPL");
2209 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2210 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");