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 * Used by test_cipher_speed()
53 static unsigned int sec
;
55 static char *alg
= NULL
;
59 static char *tvmem
[TVMEMSIZE
];
61 static char *check
[] = {
62 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
63 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
64 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
65 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
66 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
67 "lzo", "cts", "zlib", NULL
70 static int test_cipher_jiffies(struct blkcipher_desc
*desc
, int enc
,
71 struct scatterlist
*sg
, int blen
, int sec
)
73 unsigned long start
, end
;
77 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
78 time_before(jiffies
, end
); bcount
++) {
80 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
82 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
88 printk("%d operations in %d seconds (%ld bytes)\n",
89 bcount
, sec
, (long)bcount
* blen
);
93 static int test_cipher_cycles(struct blkcipher_desc
*desc
, int enc
,
94 struct scatterlist
*sg
, int blen
)
96 unsigned long cycles
= 0;
103 for (i
= 0; i
< 4; i
++) {
105 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
107 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
113 /* The real thing. */
114 for (i
= 0; i
< 8; i
++) {
117 start
= get_cycles();
119 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
121 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
127 cycles
+= end
- start
;
134 printk("1 operation in %lu cycles (%d bytes)\n",
135 (cycles
+ 4) / 8, blen
);
140 static int test_aead_jiffies(struct aead_request
*req
, int enc
,
143 unsigned long start
, end
;
147 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
148 time_before(jiffies
, end
); bcount
++) {
150 ret
= crypto_aead_encrypt(req
);
152 ret
= crypto_aead_decrypt(req
);
158 printk("%d operations in %d seconds (%ld bytes)\n",
159 bcount
, sec
, (long)bcount
* blen
);
163 static int test_aead_cycles(struct aead_request
*req
, int enc
, int blen
)
165 unsigned long cycles
= 0;
172 for (i
= 0; i
< 4; i
++) {
174 ret
= crypto_aead_encrypt(req
);
176 ret
= crypto_aead_decrypt(req
);
182 /* The real thing. */
183 for (i
= 0; i
< 8; i
++) {
186 start
= get_cycles();
188 ret
= crypto_aead_encrypt(req
);
190 ret
= crypto_aead_decrypt(req
);
196 cycles
+= end
- start
;
203 printk("1 operation in %lu cycles (%d bytes)\n",
204 (cycles
+ 4) / 8, blen
);
209 static u32 block_sizes
[] = { 16, 64, 256, 1024, 8192, 0 };
210 static u32 aead_sizes
[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
215 static int testmgr_alloc_buf(char *buf
[XBUFSIZE
])
219 for (i
= 0; i
< XBUFSIZE
; i
++) {
220 buf
[i
] = (void *)__get_free_page(GFP_KERNEL
);
229 free_page((unsigned long)buf
[i
]);
234 static void testmgr_free_buf(char *buf
[XBUFSIZE
])
238 for (i
= 0; i
< XBUFSIZE
; i
++)
239 free_page((unsigned long)buf
[i
]);
242 static void sg_init_aead(struct scatterlist
*sg
, char *xbuf
[XBUFSIZE
],
245 int np
= (buflen
+ PAGE_SIZE
- 1)/PAGE_SIZE
;
248 np
= (np
> XBUFSIZE
) ? XBUFSIZE
: np
;
249 rem
= buflen
% PAGE_SIZE
;
254 sg_init_table(sg
, np
);
255 for (k
= 0; k
< np
; ++k
) {
257 sg_set_buf(&sg
[k
], xbuf
[k
], rem
);
259 sg_set_buf(&sg
[k
], xbuf
[k
], PAGE_SIZE
);
263 static void test_aead_speed(const char *algo
, int enc
, unsigned int sec
,
264 struct aead_speed_template
*template,
265 unsigned int tcount
, u8 authsize
,
266 unsigned int aad_size
, u8
*keysize
)
269 struct crypto_aead
*tfm
;
272 struct aead_request
*req
;
273 struct scatterlist
*sg
;
274 struct scatterlist
*asg
;
275 struct scatterlist
*sgout
;
279 char *xbuf
[XBUFSIZE
];
280 char *xoutbuf
[XBUFSIZE
];
281 char *axbuf
[XBUFSIZE
];
282 unsigned int *b_size
;
290 if (testmgr_alloc_buf(xbuf
))
292 if (testmgr_alloc_buf(axbuf
))
294 if (testmgr_alloc_buf(xoutbuf
))
297 sg
= kmalloc(sizeof(*sg
) * 8 * 3, GFP_KERNEL
);
304 printk(KERN_INFO
"\ntesting speed of %s %s\n", algo
, e
);
306 tfm
= crypto_alloc_aead(algo
, 0, 0);
309 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo
,
314 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
316 pr_err("alg: aead: Failed to allocate request for %s\n",
327 if (aad_size
< PAGE_SIZE
)
328 memset(assoc
, 0xff, aad_size
);
330 pr_err("associate data length (%u) too big\n",
334 sg_init_one(&asg
[0], assoc
, aad_size
);
336 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
337 pr_err("template (%u) too big for tvmem (%lu)\n",
339 TVMEMSIZE
* PAGE_SIZE
);
344 for (j
= 0; j
< tcount
; j
++) {
345 if (template[j
].klen
== *keysize
) {
346 key
= template[j
].key
;
350 ret
= crypto_aead_setkey(tfm
, key
, *keysize
);
351 ret
= crypto_aead_setauthsize(tfm
, authsize
);
353 iv_len
= crypto_aead_ivsize(tfm
);
355 memset(&iv
, 0xff, iv_len
);
357 crypto_aead_clear_flags(tfm
, ~0);
358 printk(KERN_INFO
"test %u (%d bit key, %d byte blocks): ",
359 i
, *keysize
* 8, *b_size
);
362 memset(tvmem
[0], 0xff, PAGE_SIZE
);
365 pr_err("setkey() failed flags=%x\n",
366 crypto_aead_get_flags(tfm
));
370 sg_init_aead(&sg
[0], xbuf
,
371 *b_size
+ (enc
? authsize
: 0));
373 sg_init_aead(&sgout
[0], xoutbuf
,
374 *b_size
+ (enc
? authsize
: 0));
376 aead_request_set_crypt(req
, sg
, sgout
, *b_size
, iv
);
377 aead_request_set_assoc(req
, asg
, aad_size
);
380 ret
= test_aead_jiffies(req
, enc
, *b_size
, sec
);
382 ret
= test_aead_cycles(req
, enc
, *b_size
);
385 pr_err("%s() failed return code=%d\n", e
, ret
);
395 crypto_free_aead(tfm
);
398 testmgr_free_buf(xoutbuf
);
400 testmgr_free_buf(axbuf
);
402 testmgr_free_buf(xbuf
);
407 static void test_cipher_speed(const char *algo
, int enc
, unsigned int sec
,
408 struct cipher_speed_template
*template,
409 unsigned int tcount
, u8
*keysize
)
411 unsigned int ret
, i
, j
, iv_len
;
414 struct crypto_blkcipher
*tfm
;
415 struct blkcipher_desc desc
;
424 printk("\ntesting speed of %s %s\n", algo
, e
);
426 tfm
= crypto_alloc_blkcipher(algo
, 0, CRYPTO_ALG_ASYNC
);
429 printk("failed to load transform for %s: %ld\n", algo
,
439 b_size
= block_sizes
;
441 struct scatterlist sg
[TVMEMSIZE
];
443 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
444 printk("template (%u) too big for "
445 "tvmem (%lu)\n", *keysize
+ *b_size
,
446 TVMEMSIZE
* PAGE_SIZE
);
450 printk("test %u (%d bit key, %d byte blocks): ", i
,
451 *keysize
* 8, *b_size
);
453 memset(tvmem
[0], 0xff, PAGE_SIZE
);
455 /* set key, plain text and IV */
457 for (j
= 0; j
< tcount
; j
++) {
458 if (template[j
].klen
== *keysize
) {
459 key
= template[j
].key
;
464 ret
= crypto_blkcipher_setkey(tfm
, key
, *keysize
);
466 printk("setkey() failed flags=%x\n",
467 crypto_blkcipher_get_flags(tfm
));
471 sg_init_table(sg
, TVMEMSIZE
);
472 sg_set_buf(sg
, tvmem
[0] + *keysize
,
473 PAGE_SIZE
- *keysize
);
474 for (j
= 1; j
< TVMEMSIZE
; j
++) {
475 sg_set_buf(sg
+ j
, tvmem
[j
], PAGE_SIZE
);
476 memset (tvmem
[j
], 0xff, PAGE_SIZE
);
479 iv_len
= crypto_blkcipher_ivsize(tfm
);
481 memset(&iv
, 0xff, iv_len
);
482 crypto_blkcipher_set_iv(tfm
, iv
, iv_len
);
486 ret
= test_cipher_jiffies(&desc
, enc
, sg
,
489 ret
= test_cipher_cycles(&desc
, enc
, sg
,
493 printk("%s() failed flags=%x\n", e
, desc
.flags
);
503 crypto_free_blkcipher(tfm
);
506 static int test_hash_jiffies_digest(struct hash_desc
*desc
,
507 struct scatterlist
*sg
, int blen
,
510 unsigned long start
, end
;
514 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
515 time_before(jiffies
, end
); bcount
++) {
516 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
521 printk("%6u opers/sec, %9lu bytes/sec\n",
522 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
527 static int test_hash_jiffies(struct hash_desc
*desc
, struct scatterlist
*sg
,
528 int blen
, int plen
, char *out
, int sec
)
530 unsigned long start
, end
;
535 return test_hash_jiffies_digest(desc
, sg
, blen
, out
, sec
);
537 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
538 time_before(jiffies
, end
); bcount
++) {
539 ret
= crypto_hash_init(desc
);
542 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
543 ret
= crypto_hash_update(desc
, sg
, plen
);
547 /* we assume there is enough space in 'out' for the result */
548 ret
= crypto_hash_final(desc
, out
);
553 printk("%6u opers/sec, %9lu bytes/sec\n",
554 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
559 static int test_hash_cycles_digest(struct hash_desc
*desc
,
560 struct scatterlist
*sg
, int blen
, char *out
)
562 unsigned long cycles
= 0;
569 for (i
= 0; i
< 4; i
++) {
570 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
575 /* The real thing. */
576 for (i
= 0; i
< 8; i
++) {
579 start
= get_cycles();
581 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
587 cycles
+= end
- start
;
596 printk("%6lu cycles/operation, %4lu cycles/byte\n",
597 cycles
/ 8, cycles
/ (8 * blen
));
602 static int test_hash_cycles(struct hash_desc
*desc
, struct scatterlist
*sg
,
603 int blen
, int plen
, char *out
)
605 unsigned long cycles
= 0;
610 return test_hash_cycles_digest(desc
, sg
, blen
, out
);
615 for (i
= 0; i
< 4; i
++) {
616 ret
= crypto_hash_init(desc
);
619 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
620 ret
= crypto_hash_update(desc
, sg
, plen
);
624 ret
= crypto_hash_final(desc
, out
);
629 /* The real thing. */
630 for (i
= 0; i
< 8; i
++) {
633 start
= get_cycles();
635 ret
= crypto_hash_init(desc
);
638 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
639 ret
= crypto_hash_update(desc
, sg
, plen
);
643 ret
= crypto_hash_final(desc
, out
);
649 cycles
+= end
- start
;
658 printk("%6lu cycles/operation, %4lu cycles/byte\n",
659 cycles
/ 8, cycles
/ (8 * blen
));
664 static void test_hash_sg_init(struct scatterlist
*sg
)
668 sg_init_table(sg
, TVMEMSIZE
);
669 for (i
= 0; i
< TVMEMSIZE
; i
++) {
670 sg_set_buf(sg
+ i
, tvmem
[i
], PAGE_SIZE
);
671 memset(tvmem
[i
], 0xff, PAGE_SIZE
);
675 static void test_hash_speed(const char *algo
, unsigned int sec
,
676 struct hash_speed
*speed
)
678 struct scatterlist sg
[TVMEMSIZE
];
679 struct crypto_hash
*tfm
;
680 struct hash_desc desc
;
681 static char output
[1024];
685 printk(KERN_INFO
"\ntesting speed of %s\n", algo
);
687 tfm
= crypto_alloc_hash(algo
, 0, CRYPTO_ALG_ASYNC
);
690 printk(KERN_ERR
"failed to load transform for %s: %ld\n", algo
,
698 if (crypto_hash_digestsize(tfm
) > sizeof(output
)) {
699 printk(KERN_ERR
"digestsize(%u) > outputbuffer(%zu)\n",
700 crypto_hash_digestsize(tfm
), sizeof(output
));
704 test_hash_sg_init(sg
);
705 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
706 if (speed
[i
].blen
> TVMEMSIZE
* PAGE_SIZE
) {
708 "template (%u) too big for tvmem (%lu)\n",
709 speed
[i
].blen
, TVMEMSIZE
* PAGE_SIZE
);
714 crypto_hash_setkey(tfm
, tvmem
[0], speed
[i
].klen
);
716 printk(KERN_INFO
"test%3u "
717 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
718 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
721 ret
= test_hash_jiffies(&desc
, sg
, speed
[i
].blen
,
722 speed
[i
].plen
, output
, sec
);
724 ret
= test_hash_cycles(&desc
, sg
, speed
[i
].blen
,
725 speed
[i
].plen
, output
);
728 printk(KERN_ERR
"hashing failed ret=%d\n", ret
);
734 crypto_free_hash(tfm
);
737 struct tcrypt_result
{
738 struct completion completion
;
742 static void tcrypt_complete(struct crypto_async_request
*req
, int err
)
744 struct tcrypt_result
*res
= req
->data
;
746 if (err
== -EINPROGRESS
)
750 complete(&res
->completion
);
753 static inline int do_one_ahash_op(struct ahash_request
*req
, int ret
)
755 if (ret
== -EINPROGRESS
|| ret
== -EBUSY
) {
756 struct tcrypt_result
*tr
= req
->base
.data
;
758 ret
= wait_for_completion_interruptible(&tr
->completion
);
761 reinit_completion(&tr
->completion
);
766 static int test_ahash_jiffies_digest(struct ahash_request
*req
, int blen
,
769 unsigned long start
, end
;
773 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
774 time_before(jiffies
, end
); bcount
++) {
775 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
780 printk("%6u opers/sec, %9lu bytes/sec\n",
781 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
786 static int test_ahash_jiffies(struct ahash_request
*req
, int blen
,
787 int plen
, char *out
, int sec
)
789 unsigned long start
, end
;
794 return test_ahash_jiffies_digest(req
, blen
, out
, sec
);
796 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
797 time_before(jiffies
, end
); bcount
++) {
798 ret
= crypto_ahash_init(req
);
801 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
802 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
806 /* we assume there is enough space in 'out' for the result */
807 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
812 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
813 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
818 static int test_ahash_cycles_digest(struct ahash_request
*req
, int blen
,
821 unsigned long cycles
= 0;
825 for (i
= 0; i
< 4; i
++) {
826 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
831 /* The real thing. */
832 for (i
= 0; i
< 8; i
++) {
835 start
= get_cycles();
837 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
843 cycles
+= end
- start
;
850 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
851 cycles
/ 8, cycles
/ (8 * blen
));
856 static int test_ahash_cycles(struct ahash_request
*req
, int blen
,
859 unsigned long cycles
= 0;
863 return test_ahash_cycles_digest(req
, blen
, out
);
866 for (i
= 0; i
< 4; i
++) {
867 ret
= crypto_ahash_init(req
);
870 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
871 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
875 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
880 /* The real thing. */
881 for (i
= 0; i
< 8; i
++) {
884 start
= get_cycles();
886 ret
= crypto_ahash_init(req
);
889 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
890 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
894 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
900 cycles
+= end
- start
;
907 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
908 cycles
/ 8, cycles
/ (8 * blen
));
913 static void test_ahash_speed(const char *algo
, unsigned int sec
,
914 struct hash_speed
*speed
)
916 struct scatterlist sg
[TVMEMSIZE
];
917 struct tcrypt_result tresult
;
918 struct ahash_request
*req
;
919 struct crypto_ahash
*tfm
;
920 static char output
[1024];
923 printk(KERN_INFO
"\ntesting speed of async %s\n", algo
);
925 tfm
= crypto_alloc_ahash(algo
, 0, 0);
927 pr_err("failed to load transform for %s: %ld\n",
932 if (crypto_ahash_digestsize(tfm
) > sizeof(output
)) {
933 pr_err("digestsize(%u) > outputbuffer(%zu)\n",
934 crypto_ahash_digestsize(tfm
), sizeof(output
));
938 test_hash_sg_init(sg
);
939 req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
941 pr_err("ahash request allocation failure\n");
945 init_completion(&tresult
.completion
);
946 ahash_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
947 tcrypt_complete
, &tresult
);
949 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
950 if (speed
[i
].blen
> TVMEMSIZE
* PAGE_SIZE
) {
951 pr_err("template (%u) too big for tvmem (%lu)\n",
952 speed
[i
].blen
, TVMEMSIZE
* PAGE_SIZE
);
957 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
958 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
960 ahash_request_set_crypt(req
, sg
, output
, speed
[i
].plen
);
963 ret
= test_ahash_jiffies(req
, speed
[i
].blen
,
964 speed
[i
].plen
, output
, sec
);
966 ret
= test_ahash_cycles(req
, speed
[i
].blen
,
967 speed
[i
].plen
, output
);
970 pr_err("hashing failed ret=%d\n", ret
);
975 ahash_request_free(req
);
978 crypto_free_ahash(tfm
);
981 static inline int do_one_acipher_op(struct ablkcipher_request
*req
, int ret
)
983 if (ret
== -EINPROGRESS
|| ret
== -EBUSY
) {
984 struct tcrypt_result
*tr
= req
->base
.data
;
986 ret
= wait_for_completion_interruptible(&tr
->completion
);
989 reinit_completion(&tr
->completion
);
995 static int test_acipher_jiffies(struct ablkcipher_request
*req
, int enc
,
998 unsigned long start
, end
;
1002 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
1003 time_before(jiffies
, end
); bcount
++) {
1005 ret
= do_one_acipher_op(req
,
1006 crypto_ablkcipher_encrypt(req
));
1008 ret
= do_one_acipher_op(req
,
1009 crypto_ablkcipher_decrypt(req
));
1015 pr_cont("%d operations in %d seconds (%ld bytes)\n",
1016 bcount
, sec
, (long)bcount
* blen
);
1020 static int test_acipher_cycles(struct ablkcipher_request
*req
, int enc
,
1023 unsigned long cycles
= 0;
1028 for (i
= 0; i
< 4; i
++) {
1030 ret
= do_one_acipher_op(req
,
1031 crypto_ablkcipher_encrypt(req
));
1033 ret
= do_one_acipher_op(req
,
1034 crypto_ablkcipher_decrypt(req
));
1040 /* The real thing. */
1041 for (i
= 0; i
< 8; i
++) {
1042 cycles_t start
, end
;
1044 start
= get_cycles();
1046 ret
= do_one_acipher_op(req
,
1047 crypto_ablkcipher_encrypt(req
));
1049 ret
= do_one_acipher_op(req
,
1050 crypto_ablkcipher_decrypt(req
));
1056 cycles
+= end
- start
;
1061 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1062 (cycles
+ 4) / 8, blen
);
1067 static void test_acipher_speed(const char *algo
, int enc
, unsigned int sec
,
1068 struct cipher_speed_template
*template,
1069 unsigned int tcount
, u8
*keysize
)
1071 unsigned int ret
, i
, j
, k
, iv_len
;
1072 struct tcrypt_result tresult
;
1075 struct ablkcipher_request
*req
;
1076 struct crypto_ablkcipher
*tfm
;
1085 pr_info("\ntesting speed of async %s %s\n", algo
, e
);
1087 init_completion(&tresult
.completion
);
1089 tfm
= crypto_alloc_ablkcipher(algo
, 0, 0);
1092 pr_err("failed to load transform for %s: %ld\n", algo
,
1097 req
= ablkcipher_request_alloc(tfm
, GFP_KERNEL
);
1099 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1104 ablkcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
1105 tcrypt_complete
, &tresult
);
1109 b_size
= block_sizes
;
1112 struct scatterlist sg
[TVMEMSIZE
];
1114 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
1115 pr_err("template (%u) too big for "
1116 "tvmem (%lu)\n", *keysize
+ *b_size
,
1117 TVMEMSIZE
* PAGE_SIZE
);
1121 pr_info("test %u (%d bit key, %d byte blocks): ", i
,
1122 *keysize
* 8, *b_size
);
1124 memset(tvmem
[0], 0xff, PAGE_SIZE
);
1126 /* set key, plain text and IV */
1128 for (j
= 0; j
< tcount
; j
++) {
1129 if (template[j
].klen
== *keysize
) {
1130 key
= template[j
].key
;
1135 crypto_ablkcipher_clear_flags(tfm
, ~0);
1137 ret
= crypto_ablkcipher_setkey(tfm
, key
, *keysize
);
1139 pr_err("setkey() failed flags=%x\n",
1140 crypto_ablkcipher_get_flags(tfm
));
1144 sg_init_table(sg
, TVMEMSIZE
);
1146 k
= *keysize
+ *b_size
;
1147 if (k
> PAGE_SIZE
) {
1148 sg_set_buf(sg
, tvmem
[0] + *keysize
,
1149 PAGE_SIZE
- *keysize
);
1152 while (k
> PAGE_SIZE
) {
1153 sg_set_buf(sg
+ j
, tvmem
[j
], PAGE_SIZE
);
1154 memset(tvmem
[j
], 0xff, PAGE_SIZE
);
1158 sg_set_buf(sg
+ j
, tvmem
[j
], k
);
1159 memset(tvmem
[j
], 0xff, k
);
1161 sg_set_buf(sg
, tvmem
[0] + *keysize
, *b_size
);
1164 iv_len
= crypto_ablkcipher_ivsize(tfm
);
1166 memset(&iv
, 0xff, iv_len
);
1168 ablkcipher_request_set_crypt(req
, sg
, sg
, *b_size
, iv
);
1171 ret
= test_acipher_jiffies(req
, enc
,
1174 ret
= test_acipher_cycles(req
, enc
,
1178 pr_err("%s() failed flags=%x\n", e
,
1179 crypto_ablkcipher_get_flags(tfm
));
1189 ablkcipher_request_free(req
);
1191 crypto_free_ablkcipher(tfm
);
1194 static void test_available(void)
1196 char **name
= check
;
1199 printk("alg %s ", *name
);
1200 printk(crypto_has_alg(*name
, 0, 0) ?
1201 "found\n" : "not found\n");
1206 static inline int tcrypt_test(const char *alg
)
1210 ret
= alg_test(alg
, alg
, 0, 0);
1211 /* non-fips algs return -EINVAL in fips mode */
1212 if (fips_enabled
&& ret
== -EINVAL
)
1217 static int do_test(int m
)
1224 for (i
= 1; i
< 200; i
++)
1229 ret
+= tcrypt_test("md5");
1233 ret
+= tcrypt_test("sha1");
1237 ret
+= tcrypt_test("ecb(des)");
1238 ret
+= tcrypt_test("cbc(des)");
1239 ret
+= tcrypt_test("ctr(des)");
1243 ret
+= tcrypt_test("ecb(des3_ede)");
1244 ret
+= tcrypt_test("cbc(des3_ede)");
1245 ret
+= tcrypt_test("ctr(des3_ede)");
1249 ret
+= tcrypt_test("md4");
1253 ret
+= tcrypt_test("sha256");
1257 ret
+= tcrypt_test("ecb(blowfish)");
1258 ret
+= tcrypt_test("cbc(blowfish)");
1259 ret
+= tcrypt_test("ctr(blowfish)");
1263 ret
+= tcrypt_test("ecb(twofish)");
1264 ret
+= tcrypt_test("cbc(twofish)");
1265 ret
+= tcrypt_test("ctr(twofish)");
1266 ret
+= tcrypt_test("lrw(twofish)");
1267 ret
+= tcrypt_test("xts(twofish)");
1271 ret
+= tcrypt_test("ecb(serpent)");
1272 ret
+= tcrypt_test("cbc(serpent)");
1273 ret
+= tcrypt_test("ctr(serpent)");
1274 ret
+= tcrypt_test("lrw(serpent)");
1275 ret
+= tcrypt_test("xts(serpent)");
1279 ret
+= tcrypt_test("ecb(aes)");
1280 ret
+= tcrypt_test("cbc(aes)");
1281 ret
+= tcrypt_test("lrw(aes)");
1282 ret
+= tcrypt_test("xts(aes)");
1283 ret
+= tcrypt_test("ctr(aes)");
1284 ret
+= tcrypt_test("rfc3686(ctr(aes))");
1288 ret
+= tcrypt_test("sha384");
1292 ret
+= tcrypt_test("sha512");
1296 ret
+= tcrypt_test("deflate");
1300 ret
+= tcrypt_test("ecb(cast5)");
1301 ret
+= tcrypt_test("cbc(cast5)");
1302 ret
+= tcrypt_test("ctr(cast5)");
1306 ret
+= tcrypt_test("ecb(cast6)");
1307 ret
+= tcrypt_test("cbc(cast6)");
1308 ret
+= tcrypt_test("ctr(cast6)");
1309 ret
+= tcrypt_test("lrw(cast6)");
1310 ret
+= tcrypt_test("xts(cast6)");
1314 ret
+= tcrypt_test("ecb(arc4)");
1318 ret
+= tcrypt_test("michael_mic");
1322 ret
+= tcrypt_test("crc32c");
1326 ret
+= tcrypt_test("ecb(tea)");
1330 ret
+= tcrypt_test("ecb(xtea)");
1334 ret
+= tcrypt_test("ecb(khazad)");
1338 ret
+= tcrypt_test("wp512");
1342 ret
+= tcrypt_test("wp384");
1346 ret
+= tcrypt_test("wp256");
1350 ret
+= tcrypt_test("ecb(tnepres)");
1354 ret
+= tcrypt_test("ecb(anubis)");
1355 ret
+= tcrypt_test("cbc(anubis)");
1359 ret
+= tcrypt_test("tgr192");
1363 ret
+= tcrypt_test("tgr160");
1367 ret
+= tcrypt_test("tgr128");
1371 ret
+= tcrypt_test("ecb(xeta)");
1375 ret
+= tcrypt_test("pcbc(fcrypt)");
1379 ret
+= tcrypt_test("ecb(camellia)");
1380 ret
+= tcrypt_test("cbc(camellia)");
1381 ret
+= tcrypt_test("ctr(camellia)");
1382 ret
+= tcrypt_test("lrw(camellia)");
1383 ret
+= tcrypt_test("xts(camellia)");
1387 ret
+= tcrypt_test("sha224");
1391 ret
+= tcrypt_test("salsa20");
1395 ret
+= tcrypt_test("gcm(aes)");
1399 ret
+= tcrypt_test("lzo");
1403 ret
+= tcrypt_test("ccm(aes)");
1407 ret
+= tcrypt_test("cts(cbc(aes))");
1411 ret
+= tcrypt_test("rmd128");
1415 ret
+= tcrypt_test("rmd160");
1419 ret
+= tcrypt_test("rmd256");
1423 ret
+= tcrypt_test("rmd320");
1427 ret
+= tcrypt_test("ecb(seed)");
1431 ret
+= tcrypt_test("zlib");
1435 ret
+= tcrypt_test("rfc4309(ccm(aes))");
1439 ret
+= tcrypt_test("ghash");
1443 ret
+= tcrypt_test("crct10dif");
1447 ret
+= tcrypt_test("hmac(md5)");
1451 ret
+= tcrypt_test("hmac(sha1)");
1455 ret
+= tcrypt_test("hmac(sha256)");
1459 ret
+= tcrypt_test("hmac(sha384)");
1463 ret
+= tcrypt_test("hmac(sha512)");
1467 ret
+= tcrypt_test("hmac(sha224)");
1471 ret
+= tcrypt_test("xcbc(aes)");
1475 ret
+= tcrypt_test("hmac(rmd128)");
1479 ret
+= tcrypt_test("hmac(rmd160)");
1483 ret
+= tcrypt_test("vmac(aes)");
1487 ret
+= tcrypt_test("hmac(crc32)");
1491 ret
+= tcrypt_test("ansi_cprng");
1495 ret
+= tcrypt_test("rfc4106(gcm(aes))");
1499 ret
+= tcrypt_test("rfc4543(gcm(aes))");
1503 ret
+= tcrypt_test("cmac(aes)");
1507 ret
+= tcrypt_test("cmac(des3_ede)");
1511 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1515 ret
+= tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1519 ret
+= tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1523 test_cipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1524 speed_template_16_24_32
);
1525 test_cipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1526 speed_template_16_24_32
);
1527 test_cipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1528 speed_template_16_24_32
);
1529 test_cipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1530 speed_template_16_24_32
);
1531 test_cipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1532 speed_template_32_40_48
);
1533 test_cipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1534 speed_template_32_40_48
);
1535 test_cipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1536 speed_template_32_48_64
);
1537 test_cipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1538 speed_template_32_48_64
);
1539 test_cipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
1540 speed_template_16_24_32
);
1541 test_cipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
1542 speed_template_16_24_32
);
1546 test_cipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1547 des3_speed_template
, DES3_SPEED_VECTORS
,
1549 test_cipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1550 des3_speed_template
, DES3_SPEED_VECTORS
,
1552 test_cipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1553 des3_speed_template
, DES3_SPEED_VECTORS
,
1555 test_cipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1556 des3_speed_template
, DES3_SPEED_VECTORS
,
1561 test_cipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1562 speed_template_16_24_32
);
1563 test_cipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1564 speed_template_16_24_32
);
1565 test_cipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1566 speed_template_16_24_32
);
1567 test_cipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1568 speed_template_16_24_32
);
1569 test_cipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
1570 speed_template_16_24_32
);
1571 test_cipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
1572 speed_template_16_24_32
);
1573 test_cipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
1574 speed_template_32_40_48
);
1575 test_cipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
1576 speed_template_32_40_48
);
1577 test_cipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
1578 speed_template_32_48_64
);
1579 test_cipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
1580 speed_template_32_48_64
);
1584 test_cipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1585 speed_template_8_32
);
1586 test_cipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
1587 speed_template_8_32
);
1588 test_cipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1589 speed_template_8_32
);
1590 test_cipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
1591 speed_template_8_32
);
1592 test_cipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1593 speed_template_8_32
);
1594 test_cipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
1595 speed_template_8_32
);
1599 test_cipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1601 test_cipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1603 test_cipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1605 test_cipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1610 test_cipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
1611 speed_template_16_24_32
);
1612 test_cipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
1613 speed_template_16_24_32
);
1614 test_cipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
1615 speed_template_16_24_32
);
1616 test_cipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
1617 speed_template_16_24_32
);
1618 test_cipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
1619 speed_template_16_24_32
);
1620 test_cipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
1621 speed_template_16_24_32
);
1622 test_cipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
1623 speed_template_32_40_48
);
1624 test_cipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
1625 speed_template_32_40_48
);
1626 test_cipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
1627 speed_template_32_48_64
);
1628 test_cipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
1629 speed_template_32_48_64
);
1633 test_cipher_speed("salsa20", ENCRYPT
, sec
, NULL
, 0,
1634 speed_template_16_32
);
1638 test_cipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
1639 speed_template_16_32
);
1640 test_cipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
1641 speed_template_16_32
);
1642 test_cipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
1643 speed_template_16_32
);
1644 test_cipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
1645 speed_template_16_32
);
1646 test_cipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
1647 speed_template_16_32
);
1648 test_cipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
1649 speed_template_16_32
);
1650 test_cipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
1651 speed_template_32_48
);
1652 test_cipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
1653 speed_template_32_48
);
1654 test_cipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
1655 speed_template_32_64
);
1656 test_cipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
1657 speed_template_32_64
);
1661 test_cipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
1666 test_cipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
1667 speed_template_8_16
);
1668 test_cipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
1669 speed_template_8_16
);
1670 test_cipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
1671 speed_template_8_16
);
1672 test_cipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
1673 speed_template_8_16
);
1674 test_cipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
1675 speed_template_8_16
);
1676 test_cipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
1677 speed_template_8_16
);
1681 test_cipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
1682 speed_template_16_32
);
1683 test_cipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
1684 speed_template_16_32
);
1685 test_cipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
1686 speed_template_16_32
);
1687 test_cipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
1688 speed_template_16_32
);
1689 test_cipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
1690 speed_template_16_32
);
1691 test_cipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
1692 speed_template_16_32
);
1693 test_cipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
1694 speed_template_32_48
);
1695 test_cipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
1696 speed_template_32_48
);
1697 test_cipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
1698 speed_template_32_64
);
1699 test_cipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
1700 speed_template_32_64
);
1704 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT
, sec
,
1705 NULL
, 0, 16, 8, aead_speed_template_20
);
1712 test_hash_speed("md4", sec
, generic_hash_speed_template
);
1713 if (mode
> 300 && mode
< 400) break;
1716 test_hash_speed("md5", sec
, generic_hash_speed_template
);
1717 if (mode
> 300 && mode
< 400) break;
1720 test_hash_speed("sha1", sec
, generic_hash_speed_template
);
1721 if (mode
> 300 && mode
< 400) break;
1724 test_hash_speed("sha256", sec
, generic_hash_speed_template
);
1725 if (mode
> 300 && mode
< 400) break;
1728 test_hash_speed("sha384", sec
, generic_hash_speed_template
);
1729 if (mode
> 300 && mode
< 400) break;
1732 test_hash_speed("sha512", sec
, generic_hash_speed_template
);
1733 if (mode
> 300 && mode
< 400) break;
1736 test_hash_speed("wp256", sec
, generic_hash_speed_template
);
1737 if (mode
> 300 && mode
< 400) break;
1740 test_hash_speed("wp384", sec
, generic_hash_speed_template
);
1741 if (mode
> 300 && mode
< 400) break;
1744 test_hash_speed("wp512", sec
, generic_hash_speed_template
);
1745 if (mode
> 300 && mode
< 400) break;
1748 test_hash_speed("tgr128", sec
, generic_hash_speed_template
);
1749 if (mode
> 300 && mode
< 400) break;
1752 test_hash_speed("tgr160", sec
, generic_hash_speed_template
);
1753 if (mode
> 300 && mode
< 400) break;
1756 test_hash_speed("tgr192", sec
, generic_hash_speed_template
);
1757 if (mode
> 300 && mode
< 400) break;
1760 test_hash_speed("sha224", sec
, generic_hash_speed_template
);
1761 if (mode
> 300 && mode
< 400) break;
1764 test_hash_speed("rmd128", sec
, generic_hash_speed_template
);
1765 if (mode
> 300 && mode
< 400) break;
1768 test_hash_speed("rmd160", sec
, generic_hash_speed_template
);
1769 if (mode
> 300 && mode
< 400) break;
1772 test_hash_speed("rmd256", sec
, generic_hash_speed_template
);
1773 if (mode
> 300 && mode
< 400) break;
1776 test_hash_speed("rmd320", sec
, generic_hash_speed_template
);
1777 if (mode
> 300 && mode
< 400) break;
1780 test_hash_speed("ghash-generic", sec
, hash_speed_template_16
);
1781 if (mode
> 300 && mode
< 400) break;
1784 test_hash_speed("crc32c", sec
, generic_hash_speed_template
);
1785 if (mode
> 300 && mode
< 400) break;
1788 test_hash_speed("crct10dif", sec
, generic_hash_speed_template
);
1789 if (mode
> 300 && mode
< 400) break;
1798 test_ahash_speed("md4", sec
, generic_hash_speed_template
);
1799 if (mode
> 400 && mode
< 500) break;
1802 test_ahash_speed("md5", sec
, generic_hash_speed_template
);
1803 if (mode
> 400 && mode
< 500) break;
1806 test_ahash_speed("sha1", sec
, generic_hash_speed_template
);
1807 if (mode
> 400 && mode
< 500) break;
1810 test_ahash_speed("sha256", sec
, generic_hash_speed_template
);
1811 if (mode
> 400 && mode
< 500) break;
1814 test_ahash_speed("sha384", sec
, generic_hash_speed_template
);
1815 if (mode
> 400 && mode
< 500) break;
1818 test_ahash_speed("sha512", sec
, generic_hash_speed_template
);
1819 if (mode
> 400 && mode
< 500) break;
1822 test_ahash_speed("wp256", sec
, generic_hash_speed_template
);
1823 if (mode
> 400 && mode
< 500) break;
1826 test_ahash_speed("wp384", sec
, generic_hash_speed_template
);
1827 if (mode
> 400 && mode
< 500) break;
1830 test_ahash_speed("wp512", sec
, generic_hash_speed_template
);
1831 if (mode
> 400 && mode
< 500) break;
1834 test_ahash_speed("tgr128", sec
, generic_hash_speed_template
);
1835 if (mode
> 400 && mode
< 500) break;
1838 test_ahash_speed("tgr160", sec
, generic_hash_speed_template
);
1839 if (mode
> 400 && mode
< 500) break;
1842 test_ahash_speed("tgr192", sec
, generic_hash_speed_template
);
1843 if (mode
> 400 && mode
< 500) break;
1846 test_ahash_speed("sha224", sec
, generic_hash_speed_template
);
1847 if (mode
> 400 && mode
< 500) break;
1850 test_ahash_speed("rmd128", sec
, generic_hash_speed_template
);
1851 if (mode
> 400 && mode
< 500) break;
1854 test_ahash_speed("rmd160", sec
, generic_hash_speed_template
);
1855 if (mode
> 400 && mode
< 500) break;
1858 test_ahash_speed("rmd256", sec
, generic_hash_speed_template
);
1859 if (mode
> 400 && mode
< 500) break;
1862 test_ahash_speed("rmd320", sec
, generic_hash_speed_template
);
1863 if (mode
> 400 && mode
< 500) break;
1869 test_acipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1870 speed_template_16_24_32
);
1871 test_acipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1872 speed_template_16_24_32
);
1873 test_acipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1874 speed_template_16_24_32
);
1875 test_acipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1876 speed_template_16_24_32
);
1877 test_acipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1878 speed_template_32_40_48
);
1879 test_acipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1880 speed_template_32_40_48
);
1881 test_acipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1882 speed_template_32_48_64
);
1883 test_acipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1884 speed_template_32_48_64
);
1885 test_acipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
1886 speed_template_16_24_32
);
1887 test_acipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
1888 speed_template_16_24_32
);
1889 test_acipher_speed("cfb(aes)", ENCRYPT
, sec
, NULL
, 0,
1890 speed_template_16_24_32
);
1891 test_acipher_speed("cfb(aes)", DECRYPT
, sec
, NULL
, 0,
1892 speed_template_16_24_32
);
1893 test_acipher_speed("ofb(aes)", ENCRYPT
, sec
, NULL
, 0,
1894 speed_template_16_24_32
);
1895 test_acipher_speed("ofb(aes)", DECRYPT
, sec
, NULL
, 0,
1896 speed_template_16_24_32
);
1897 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT
, sec
, NULL
, 0,
1898 speed_template_20_28_36
);
1899 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT
, sec
, NULL
, 0,
1900 speed_template_20_28_36
);
1904 test_acipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1905 des3_speed_template
, DES3_SPEED_VECTORS
,
1907 test_acipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1908 des3_speed_template
, DES3_SPEED_VECTORS
,
1910 test_acipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1911 des3_speed_template
, DES3_SPEED_VECTORS
,
1913 test_acipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1914 des3_speed_template
, DES3_SPEED_VECTORS
,
1916 test_acipher_speed("cfb(des3_ede)", ENCRYPT
, sec
,
1917 des3_speed_template
, DES3_SPEED_VECTORS
,
1919 test_acipher_speed("cfb(des3_ede)", DECRYPT
, sec
,
1920 des3_speed_template
, DES3_SPEED_VECTORS
,
1922 test_acipher_speed("ofb(des3_ede)", ENCRYPT
, sec
,
1923 des3_speed_template
, DES3_SPEED_VECTORS
,
1925 test_acipher_speed("ofb(des3_ede)", DECRYPT
, sec
,
1926 des3_speed_template
, DES3_SPEED_VECTORS
,
1931 test_acipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1933 test_acipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1935 test_acipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1937 test_acipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1939 test_acipher_speed("cfb(des)", ENCRYPT
, sec
, NULL
, 0,
1941 test_acipher_speed("cfb(des)", DECRYPT
, sec
, NULL
, 0,
1943 test_acipher_speed("ofb(des)", ENCRYPT
, sec
, NULL
, 0,
1945 test_acipher_speed("ofb(des)", DECRYPT
, sec
, NULL
, 0,
1950 test_acipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
1951 speed_template_16_32
);
1952 test_acipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
1953 speed_template_16_32
);
1954 test_acipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
1955 speed_template_16_32
);
1956 test_acipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
1957 speed_template_16_32
);
1958 test_acipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
1959 speed_template_16_32
);
1960 test_acipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
1961 speed_template_16_32
);
1962 test_acipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
1963 speed_template_32_48
);
1964 test_acipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
1965 speed_template_32_48
);
1966 test_acipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
1967 speed_template_32_64
);
1968 test_acipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
1969 speed_template_32_64
);
1973 test_acipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1974 speed_template_16_24_32
);
1975 test_acipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1976 speed_template_16_24_32
);
1977 test_acipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1978 speed_template_16_24_32
);
1979 test_acipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1980 speed_template_16_24_32
);
1981 test_acipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
1982 speed_template_16_24_32
);
1983 test_acipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
1984 speed_template_16_24_32
);
1985 test_acipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
1986 speed_template_32_40_48
);
1987 test_acipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
1988 speed_template_32_40_48
);
1989 test_acipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
1990 speed_template_32_48_64
);
1991 test_acipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
1992 speed_template_32_48_64
);
1996 test_acipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
2001 test_acipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
2002 speed_template_8_16
);
2003 test_acipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
2004 speed_template_8_16
);
2005 test_acipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
2006 speed_template_8_16
);
2007 test_acipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
2008 speed_template_8_16
);
2009 test_acipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
2010 speed_template_8_16
);
2011 test_acipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
2012 speed_template_8_16
);
2016 test_acipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
2017 speed_template_16_32
);
2018 test_acipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
2019 speed_template_16_32
);
2020 test_acipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
2021 speed_template_16_32
);
2022 test_acipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
2023 speed_template_16_32
);
2024 test_acipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
2025 speed_template_16_32
);
2026 test_acipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
2027 speed_template_16_32
);
2028 test_acipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
2029 speed_template_32_48
);
2030 test_acipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
2031 speed_template_32_48
);
2032 test_acipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
2033 speed_template_32_64
);
2034 test_acipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
2035 speed_template_32_64
);
2039 test_acipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
2040 speed_template_16_32
);
2041 test_acipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
2042 speed_template_16_32
);
2043 test_acipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
2044 speed_template_16_32
);
2045 test_acipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
2046 speed_template_16_32
);
2047 test_acipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
2048 speed_template_16_32
);
2049 test_acipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
2050 speed_template_16_32
);
2051 test_acipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
2052 speed_template_32_48
);
2053 test_acipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
2054 speed_template_32_48
);
2055 test_acipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
2056 speed_template_32_64
);
2057 test_acipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
2058 speed_template_32_64
);
2062 test_acipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2063 speed_template_8_32
);
2064 test_acipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
2065 speed_template_8_32
);
2066 test_acipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2067 speed_template_8_32
);
2068 test_acipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
2069 speed_template_8_32
);
2070 test_acipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2071 speed_template_8_32
);
2072 test_acipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
2073 speed_template_8_32
);
2084 static int do_alg_test(const char *alg
, u32 type
, u32 mask
)
2086 return crypto_has_alg(alg
, type
, mask
?: CRYPTO_ALG_TYPE_MASK
) ?
2090 static int __init
tcrypt_mod_init(void)
2095 for (i
= 0; i
< TVMEMSIZE
; i
++) {
2096 tvmem
[i
] = (void *)__get_free_page(GFP_KERNEL
);
2102 err
= do_alg_test(alg
, type
, mask
);
2104 err
= do_test(mode
);
2107 printk(KERN_ERR
"tcrypt: one or more tests failed!\n");
2111 /* We intentionaly return -EAGAIN to prevent keeping the module,
2112 * unless we're running in fips mode. It does all its work from
2113 * init() and doesn't offer any runtime functionality, but in
2114 * the fips case, checking for a successful load is helpful.
2115 * => we don't need it in the memory, do we?
2122 for (i
= 0; i
< TVMEMSIZE
&& tvmem
[i
]; i
++)
2123 free_page((unsigned long)tvmem
[i
]);
2129 * If an init function is provided, an exit function must also be provided
2130 * to allow module unload.
2132 static void __exit
tcrypt_mod_fini(void) { }
2134 module_init(tcrypt_mod_init
);
2135 module_exit(tcrypt_mod_fini
);
2137 module_param(alg
, charp
, 0);
2138 module_param(type
, uint
, 0);
2139 module_param(mask
, uint
, 0);
2140 module_param(mode
, int, 0);
2141 module_param(sec
, uint
, 0);
2142 MODULE_PARM_DESC(sec
, "Length in seconds of speed tests "
2143 "(defaults to zero which uses CPU cycles instead)");
2145 MODULE_LICENSE("GPL");
2146 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2147 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");