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
;
257 rem
= buflen
% PAGE_SIZE
;
260 sg_init_table(sg
, np
);
262 for (k
= 0; k
< np
; k
++)
263 sg_set_buf(&sg
[k
], xbuf
[k
], PAGE_SIZE
);
265 sg_set_buf(&sg
[k
], xbuf
[k
], rem
);
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 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
) * 8 * 3, GFP_KERNEL
);
317 tfm
= crypto_alloc_aead(algo
, 0, 0);
320 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo
,
325 printk(KERN_INFO
"\ntesting speed of %s (%s) %s\n", algo
,
326 get_driver_name(crypto_aead
, tfm
), e
);
328 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
330 pr_err("alg: aead: Failed to allocate request for %s\n",
340 memset(assoc
, 0xff, aad_size
);
341 sg_init_one(&asg
[0], assoc
, aad_size
);
343 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
344 pr_err("template (%u) too big for tvmem (%lu)\n",
346 TVMEMSIZE
* PAGE_SIZE
);
351 for (j
= 0; j
< tcount
; j
++) {
352 if (template[j
].klen
== *keysize
) {
353 key
= template[j
].key
;
357 ret
= crypto_aead_setkey(tfm
, key
, *keysize
);
358 ret
= crypto_aead_setauthsize(tfm
, authsize
);
360 iv_len
= crypto_aead_ivsize(tfm
);
362 memset(iv
, 0xff, iv_len
);
364 crypto_aead_clear_flags(tfm
, ~0);
365 printk(KERN_INFO
"test %u (%d bit key, %d byte blocks): ",
366 i
, *keysize
* 8, *b_size
);
369 memset(tvmem
[0], 0xff, PAGE_SIZE
);
372 pr_err("setkey() failed flags=%x\n",
373 crypto_aead_get_flags(tfm
));
377 sg_init_aead(&sg
[0], xbuf
,
378 *b_size
+ (enc
? authsize
: 0));
380 sg_init_aead(&sgout
[0], xoutbuf
,
381 *b_size
+ (enc
? authsize
: 0));
383 aead_request_set_crypt(req
, sg
, sgout
, *b_size
, iv
);
384 aead_request_set_assoc(req
, asg
, aad_size
);
387 ret
= test_aead_jiffies(req
, enc
, *b_size
,
390 ret
= test_aead_cycles(req
, enc
, *b_size
);
393 pr_err("%s() failed return code=%d\n", e
, ret
);
403 aead_request_free(req
);
405 crypto_free_aead(tfm
);
409 testmgr_free_buf(xoutbuf
);
411 testmgr_free_buf(axbuf
);
413 testmgr_free_buf(xbuf
);
419 static void test_cipher_speed(const char *algo
, int enc
, unsigned int secs
,
420 struct cipher_speed_template
*template,
421 unsigned int tcount
, u8
*keysize
)
423 unsigned int ret
, i
, j
, iv_len
;
426 struct crypto_blkcipher
*tfm
;
427 struct blkcipher_desc desc
;
436 tfm
= crypto_alloc_blkcipher(algo
, 0, CRYPTO_ALG_ASYNC
);
439 printk("failed to load transform for %s: %ld\n", algo
,
446 printk(KERN_INFO
"\ntesting speed of %s (%s) %s\n", algo
,
447 get_driver_name(crypto_blkcipher
, tfm
), e
);
452 b_size
= block_sizes
;
454 struct scatterlist sg
[TVMEMSIZE
];
456 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
457 printk("template (%u) too big for "
458 "tvmem (%lu)\n", *keysize
+ *b_size
,
459 TVMEMSIZE
* PAGE_SIZE
);
463 printk("test %u (%d bit key, %d byte blocks): ", i
,
464 *keysize
* 8, *b_size
);
466 memset(tvmem
[0], 0xff, PAGE_SIZE
);
468 /* set key, plain text and IV */
470 for (j
= 0; j
< tcount
; j
++) {
471 if (template[j
].klen
== *keysize
) {
472 key
= template[j
].key
;
477 ret
= crypto_blkcipher_setkey(tfm
, key
, *keysize
);
479 printk("setkey() failed flags=%x\n",
480 crypto_blkcipher_get_flags(tfm
));
484 sg_init_table(sg
, TVMEMSIZE
);
485 sg_set_buf(sg
, tvmem
[0] + *keysize
,
486 PAGE_SIZE
- *keysize
);
487 for (j
= 1; j
< TVMEMSIZE
; j
++) {
488 sg_set_buf(sg
+ j
, tvmem
[j
], PAGE_SIZE
);
489 memset (tvmem
[j
], 0xff, PAGE_SIZE
);
492 iv_len
= crypto_blkcipher_ivsize(tfm
);
494 memset(&iv
, 0xff, iv_len
);
495 crypto_blkcipher_set_iv(tfm
, iv
, iv_len
);
499 ret
= test_cipher_jiffies(&desc
, enc
, sg
,
502 ret
= test_cipher_cycles(&desc
, enc
, sg
,
506 printk("%s() failed flags=%x\n", e
, desc
.flags
);
516 crypto_free_blkcipher(tfm
);
519 static int test_hash_jiffies_digest(struct hash_desc
*desc
,
520 struct scatterlist
*sg
, int blen
,
523 unsigned long start
, end
;
527 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
528 time_before(jiffies
, end
); bcount
++) {
529 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
534 printk("%6u opers/sec, %9lu bytes/sec\n",
535 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
540 static int test_hash_jiffies(struct hash_desc
*desc
, struct scatterlist
*sg
,
541 int blen
, int plen
, char *out
, int secs
)
543 unsigned long start
, end
;
548 return test_hash_jiffies_digest(desc
, sg
, blen
, out
, secs
);
550 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
551 time_before(jiffies
, end
); bcount
++) {
552 ret
= crypto_hash_init(desc
);
555 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
556 ret
= crypto_hash_update(desc
, sg
, plen
);
560 /* we assume there is enough space in 'out' for the result */
561 ret
= crypto_hash_final(desc
, out
);
566 printk("%6u opers/sec, %9lu bytes/sec\n",
567 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
572 static int test_hash_cycles_digest(struct hash_desc
*desc
,
573 struct scatterlist
*sg
, int blen
, char *out
)
575 unsigned long cycles
= 0;
582 for (i
= 0; i
< 4; i
++) {
583 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
588 /* The real thing. */
589 for (i
= 0; i
< 8; i
++) {
592 start
= get_cycles();
594 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
600 cycles
+= end
- start
;
609 printk("%6lu cycles/operation, %4lu cycles/byte\n",
610 cycles
/ 8, cycles
/ (8 * blen
));
615 static int test_hash_cycles(struct hash_desc
*desc
, struct scatterlist
*sg
,
616 int blen
, int plen
, char *out
)
618 unsigned long cycles
= 0;
623 return test_hash_cycles_digest(desc
, sg
, blen
, out
);
628 for (i
= 0; i
< 4; i
++) {
629 ret
= crypto_hash_init(desc
);
632 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
633 ret
= crypto_hash_update(desc
, sg
, plen
);
637 ret
= crypto_hash_final(desc
, out
);
642 /* The real thing. */
643 for (i
= 0; i
< 8; i
++) {
646 start
= get_cycles();
648 ret
= crypto_hash_init(desc
);
651 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
652 ret
= crypto_hash_update(desc
, sg
, plen
);
656 ret
= crypto_hash_final(desc
, out
);
662 cycles
+= end
- start
;
671 printk("%6lu cycles/operation, %4lu cycles/byte\n",
672 cycles
/ 8, cycles
/ (8 * blen
));
677 static void test_hash_sg_init(struct scatterlist
*sg
)
681 sg_init_table(sg
, TVMEMSIZE
);
682 for (i
= 0; i
< TVMEMSIZE
; i
++) {
683 sg_set_buf(sg
+ i
, tvmem
[i
], PAGE_SIZE
);
684 memset(tvmem
[i
], 0xff, PAGE_SIZE
);
688 static void test_hash_speed(const char *algo
, unsigned int secs
,
689 struct hash_speed
*speed
)
691 struct scatterlist sg
[TVMEMSIZE
];
692 struct crypto_hash
*tfm
;
693 struct hash_desc desc
;
694 static char output
[1024];
698 tfm
= crypto_alloc_hash(algo
, 0, CRYPTO_ALG_ASYNC
);
701 printk(KERN_ERR
"failed to load transform for %s: %ld\n", algo
,
706 printk(KERN_INFO
"\ntesting speed of %s (%s)\n", algo
,
707 get_driver_name(crypto_hash
, tfm
));
712 if (crypto_hash_digestsize(tfm
) > sizeof(output
)) {
713 printk(KERN_ERR
"digestsize(%u) > outputbuffer(%zu)\n",
714 crypto_hash_digestsize(tfm
), sizeof(output
));
718 test_hash_sg_init(sg
);
719 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
720 if (speed
[i
].blen
> TVMEMSIZE
* PAGE_SIZE
) {
722 "template (%u) too big for tvmem (%lu)\n",
723 speed
[i
].blen
, TVMEMSIZE
* PAGE_SIZE
);
728 crypto_hash_setkey(tfm
, tvmem
[0], speed
[i
].klen
);
730 printk(KERN_INFO
"test%3u "
731 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
732 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
735 ret
= test_hash_jiffies(&desc
, sg
, speed
[i
].blen
,
736 speed
[i
].plen
, output
, secs
);
738 ret
= test_hash_cycles(&desc
, sg
, speed
[i
].blen
,
739 speed
[i
].plen
, output
);
742 printk(KERN_ERR
"hashing failed ret=%d\n", ret
);
748 crypto_free_hash(tfm
);
751 struct tcrypt_result
{
752 struct completion completion
;
756 static void tcrypt_complete(struct crypto_async_request
*req
, int err
)
758 struct tcrypt_result
*res
= req
->data
;
760 if (err
== -EINPROGRESS
)
764 complete(&res
->completion
);
767 static inline int do_one_ahash_op(struct ahash_request
*req
, int ret
)
769 if (ret
== -EINPROGRESS
|| ret
== -EBUSY
) {
770 struct tcrypt_result
*tr
= req
->base
.data
;
772 wait_for_completion(&tr
->completion
);
773 reinit_completion(&tr
->completion
);
779 static int test_ahash_jiffies_digest(struct ahash_request
*req
, int blen
,
782 unsigned long start
, end
;
786 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
787 time_before(jiffies
, end
); bcount
++) {
788 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
793 printk("%6u opers/sec, %9lu bytes/sec\n",
794 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
799 static int test_ahash_jiffies(struct ahash_request
*req
, int blen
,
800 int plen
, char *out
, int secs
)
802 unsigned long start
, end
;
807 return test_ahash_jiffies_digest(req
, blen
, out
, secs
);
809 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
810 time_before(jiffies
, end
); bcount
++) {
811 ret
= crypto_ahash_init(req
);
814 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
815 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
819 /* we assume there is enough space in 'out' for the result */
820 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
825 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
826 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
831 static int test_ahash_cycles_digest(struct ahash_request
*req
, int blen
,
834 unsigned long cycles
= 0;
838 for (i
= 0; i
< 4; i
++) {
839 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
844 /* The real thing. */
845 for (i
= 0; i
< 8; i
++) {
848 start
= get_cycles();
850 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
856 cycles
+= end
- start
;
863 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
864 cycles
/ 8, cycles
/ (8 * blen
));
869 static int test_ahash_cycles(struct ahash_request
*req
, int blen
,
872 unsigned long cycles
= 0;
876 return test_ahash_cycles_digest(req
, blen
, out
);
879 for (i
= 0; i
< 4; i
++) {
880 ret
= crypto_ahash_init(req
);
883 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
884 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
888 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
893 /* The real thing. */
894 for (i
= 0; i
< 8; i
++) {
897 start
= get_cycles();
899 ret
= crypto_ahash_init(req
);
902 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
903 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
907 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
913 cycles
+= end
- start
;
920 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
921 cycles
/ 8, cycles
/ (8 * blen
));
926 static void test_ahash_speed(const char *algo
, unsigned int secs
,
927 struct hash_speed
*speed
)
929 struct scatterlist sg
[TVMEMSIZE
];
930 struct tcrypt_result tresult
;
931 struct ahash_request
*req
;
932 struct crypto_ahash
*tfm
;
933 static char output
[1024];
936 tfm
= crypto_alloc_ahash(algo
, 0, 0);
938 pr_err("failed to load transform for %s: %ld\n",
943 printk(KERN_INFO
"\ntesting speed of async %s (%s)\n", algo
,
944 get_driver_name(crypto_ahash
, tfm
));
946 if (crypto_ahash_digestsize(tfm
) > sizeof(output
)) {
947 pr_err("digestsize(%u) > outputbuffer(%zu)\n",
948 crypto_ahash_digestsize(tfm
), sizeof(output
));
952 test_hash_sg_init(sg
);
953 req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
955 pr_err("ahash request allocation failure\n");
959 init_completion(&tresult
.completion
);
960 ahash_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
961 tcrypt_complete
, &tresult
);
963 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
964 if (speed
[i
].blen
> TVMEMSIZE
* PAGE_SIZE
) {
965 pr_err("template (%u) too big for tvmem (%lu)\n",
966 speed
[i
].blen
, TVMEMSIZE
* PAGE_SIZE
);
971 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
972 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
974 ahash_request_set_crypt(req
, sg
, output
, speed
[i
].plen
);
977 ret
= test_ahash_jiffies(req
, speed
[i
].blen
,
978 speed
[i
].plen
, output
, secs
);
980 ret
= test_ahash_cycles(req
, speed
[i
].blen
,
981 speed
[i
].plen
, output
);
984 pr_err("hashing failed ret=%d\n", ret
);
989 ahash_request_free(req
);
992 crypto_free_ahash(tfm
);
995 static inline int do_one_acipher_op(struct ablkcipher_request
*req
, int ret
)
997 if (ret
== -EINPROGRESS
|| ret
== -EBUSY
) {
998 struct tcrypt_result
*tr
= req
->base
.data
;
1000 wait_for_completion(&tr
->completion
);
1001 reinit_completion(&tr
->completion
);
1008 static int test_acipher_jiffies(struct ablkcipher_request
*req
, int enc
,
1011 unsigned long start
, end
;
1015 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
1016 time_before(jiffies
, end
); bcount
++) {
1018 ret
= do_one_acipher_op(req
,
1019 crypto_ablkcipher_encrypt(req
));
1021 ret
= do_one_acipher_op(req
,
1022 crypto_ablkcipher_decrypt(req
));
1028 pr_cont("%d operations in %d seconds (%ld bytes)\n",
1029 bcount
, secs
, (long)bcount
* blen
);
1033 static int test_acipher_cycles(struct ablkcipher_request
*req
, int enc
,
1036 unsigned long cycles
= 0;
1041 for (i
= 0; i
< 4; i
++) {
1043 ret
= do_one_acipher_op(req
,
1044 crypto_ablkcipher_encrypt(req
));
1046 ret
= do_one_acipher_op(req
,
1047 crypto_ablkcipher_decrypt(req
));
1053 /* The real thing. */
1054 for (i
= 0; i
< 8; i
++) {
1055 cycles_t start
, end
;
1057 start
= get_cycles();
1059 ret
= do_one_acipher_op(req
,
1060 crypto_ablkcipher_encrypt(req
));
1062 ret
= do_one_acipher_op(req
,
1063 crypto_ablkcipher_decrypt(req
));
1069 cycles
+= end
- start
;
1074 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1075 (cycles
+ 4) / 8, blen
);
1080 static void test_acipher_speed(const char *algo
, int enc
, unsigned int secs
,
1081 struct cipher_speed_template
*template,
1082 unsigned int tcount
, u8
*keysize
)
1084 unsigned int ret
, i
, j
, k
, iv_len
;
1085 struct tcrypt_result tresult
;
1088 struct ablkcipher_request
*req
;
1089 struct crypto_ablkcipher
*tfm
;
1098 init_completion(&tresult
.completion
);
1100 tfm
= crypto_alloc_ablkcipher(algo
, 0, 0);
1103 pr_err("failed to load transform for %s: %ld\n", algo
,
1108 pr_info("\ntesting speed of async %s (%s) %s\n", algo
,
1109 get_driver_name(crypto_ablkcipher
, tfm
), e
);
1111 req
= ablkcipher_request_alloc(tfm
, GFP_KERNEL
);
1113 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1118 ablkcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
1119 tcrypt_complete
, &tresult
);
1123 b_size
= block_sizes
;
1126 struct scatterlist sg
[TVMEMSIZE
];
1128 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
1129 pr_err("template (%u) too big for "
1130 "tvmem (%lu)\n", *keysize
+ *b_size
,
1131 TVMEMSIZE
* PAGE_SIZE
);
1135 pr_info("test %u (%d bit key, %d byte blocks): ", i
,
1136 *keysize
* 8, *b_size
);
1138 memset(tvmem
[0], 0xff, PAGE_SIZE
);
1140 /* set key, plain text and IV */
1142 for (j
= 0; j
< tcount
; j
++) {
1143 if (template[j
].klen
== *keysize
) {
1144 key
= template[j
].key
;
1149 crypto_ablkcipher_clear_flags(tfm
, ~0);
1151 ret
= crypto_ablkcipher_setkey(tfm
, key
, *keysize
);
1153 pr_err("setkey() failed flags=%x\n",
1154 crypto_ablkcipher_get_flags(tfm
));
1158 k
= *keysize
+ *b_size
;
1159 sg_init_table(sg
, DIV_ROUND_UP(k
, PAGE_SIZE
));
1161 if (k
> PAGE_SIZE
) {
1162 sg_set_buf(sg
, tvmem
[0] + *keysize
,
1163 PAGE_SIZE
- *keysize
);
1166 while (k
> PAGE_SIZE
) {
1167 sg_set_buf(sg
+ j
, tvmem
[j
], PAGE_SIZE
);
1168 memset(tvmem
[j
], 0xff, PAGE_SIZE
);
1172 sg_set_buf(sg
+ j
, tvmem
[j
], k
);
1173 memset(tvmem
[j
], 0xff, k
);
1175 sg_set_buf(sg
, tvmem
[0] + *keysize
, *b_size
);
1178 iv_len
= crypto_ablkcipher_ivsize(tfm
);
1180 memset(&iv
, 0xff, iv_len
);
1182 ablkcipher_request_set_crypt(req
, sg
, sg
, *b_size
, iv
);
1185 ret
= test_acipher_jiffies(req
, enc
,
1188 ret
= test_acipher_cycles(req
, enc
,
1192 pr_err("%s() failed flags=%x\n", e
,
1193 crypto_ablkcipher_get_flags(tfm
));
1203 ablkcipher_request_free(req
);
1205 crypto_free_ablkcipher(tfm
);
1208 static void test_available(void)
1210 char **name
= check
;
1213 printk("alg %s ", *name
);
1214 printk(crypto_has_alg(*name
, 0, 0) ?
1215 "found\n" : "not found\n");
1220 static inline int tcrypt_test(const char *alg
)
1224 ret
= alg_test(alg
, alg
, 0, 0);
1225 /* non-fips algs return -EINVAL in fips mode */
1226 if (fips_enabled
&& ret
== -EINVAL
)
1231 static int do_test(const char *alg
, u32 type
, u32 mask
, int m
)
1239 if (!crypto_has_alg(alg
, type
,
1240 mask
?: CRYPTO_ALG_TYPE_MASK
))
1245 for (i
= 1; i
< 200; i
++)
1246 ret
+= do_test(NULL
, 0, 0, i
);
1250 ret
+= tcrypt_test("md5");
1254 ret
+= tcrypt_test("sha1");
1258 ret
+= tcrypt_test("ecb(des)");
1259 ret
+= tcrypt_test("cbc(des)");
1260 ret
+= tcrypt_test("ctr(des)");
1264 ret
+= tcrypt_test("ecb(des3_ede)");
1265 ret
+= tcrypt_test("cbc(des3_ede)");
1266 ret
+= tcrypt_test("ctr(des3_ede)");
1270 ret
+= tcrypt_test("md4");
1274 ret
+= tcrypt_test("sha256");
1278 ret
+= tcrypt_test("ecb(blowfish)");
1279 ret
+= tcrypt_test("cbc(blowfish)");
1280 ret
+= tcrypt_test("ctr(blowfish)");
1284 ret
+= tcrypt_test("ecb(twofish)");
1285 ret
+= tcrypt_test("cbc(twofish)");
1286 ret
+= tcrypt_test("ctr(twofish)");
1287 ret
+= tcrypt_test("lrw(twofish)");
1288 ret
+= tcrypt_test("xts(twofish)");
1292 ret
+= tcrypt_test("ecb(serpent)");
1293 ret
+= tcrypt_test("cbc(serpent)");
1294 ret
+= tcrypt_test("ctr(serpent)");
1295 ret
+= tcrypt_test("lrw(serpent)");
1296 ret
+= tcrypt_test("xts(serpent)");
1300 ret
+= tcrypt_test("ecb(aes)");
1301 ret
+= tcrypt_test("cbc(aes)");
1302 ret
+= tcrypt_test("lrw(aes)");
1303 ret
+= tcrypt_test("xts(aes)");
1304 ret
+= tcrypt_test("ctr(aes)");
1305 ret
+= tcrypt_test("rfc3686(ctr(aes))");
1309 ret
+= tcrypt_test("sha384");
1313 ret
+= tcrypt_test("sha512");
1317 ret
+= tcrypt_test("deflate");
1321 ret
+= tcrypt_test("ecb(cast5)");
1322 ret
+= tcrypt_test("cbc(cast5)");
1323 ret
+= tcrypt_test("ctr(cast5)");
1327 ret
+= tcrypt_test("ecb(cast6)");
1328 ret
+= tcrypt_test("cbc(cast6)");
1329 ret
+= tcrypt_test("ctr(cast6)");
1330 ret
+= tcrypt_test("lrw(cast6)");
1331 ret
+= tcrypt_test("xts(cast6)");
1335 ret
+= tcrypt_test("ecb(arc4)");
1339 ret
+= tcrypt_test("michael_mic");
1343 ret
+= tcrypt_test("crc32c");
1347 ret
+= tcrypt_test("ecb(tea)");
1351 ret
+= tcrypt_test("ecb(xtea)");
1355 ret
+= tcrypt_test("ecb(khazad)");
1359 ret
+= tcrypt_test("wp512");
1363 ret
+= tcrypt_test("wp384");
1367 ret
+= tcrypt_test("wp256");
1371 ret
+= tcrypt_test("ecb(tnepres)");
1375 ret
+= tcrypt_test("ecb(anubis)");
1376 ret
+= tcrypt_test("cbc(anubis)");
1380 ret
+= tcrypt_test("tgr192");
1384 ret
+= tcrypt_test("tgr160");
1388 ret
+= tcrypt_test("tgr128");
1392 ret
+= tcrypt_test("ecb(xeta)");
1396 ret
+= tcrypt_test("pcbc(fcrypt)");
1400 ret
+= tcrypt_test("ecb(camellia)");
1401 ret
+= tcrypt_test("cbc(camellia)");
1402 ret
+= tcrypt_test("ctr(camellia)");
1403 ret
+= tcrypt_test("lrw(camellia)");
1404 ret
+= tcrypt_test("xts(camellia)");
1408 ret
+= tcrypt_test("sha224");
1412 ret
+= tcrypt_test("salsa20");
1416 ret
+= tcrypt_test("gcm(aes)");
1420 ret
+= tcrypt_test("lzo");
1424 ret
+= tcrypt_test("ccm(aes)");
1428 ret
+= tcrypt_test("cts(cbc(aes))");
1432 ret
+= tcrypt_test("rmd128");
1436 ret
+= tcrypt_test("rmd160");
1440 ret
+= tcrypt_test("rmd256");
1444 ret
+= tcrypt_test("rmd320");
1448 ret
+= tcrypt_test("ecb(seed)");
1452 ret
+= tcrypt_test("zlib");
1456 ret
+= tcrypt_test("rfc4309(ccm(aes))");
1460 ret
+= tcrypt_test("ghash");
1464 ret
+= tcrypt_test("crct10dif");
1468 ret
+= tcrypt_test("hmac(md5)");
1472 ret
+= tcrypt_test("hmac(sha1)");
1476 ret
+= tcrypt_test("hmac(sha256)");
1480 ret
+= tcrypt_test("hmac(sha384)");
1484 ret
+= tcrypt_test("hmac(sha512)");
1488 ret
+= tcrypt_test("hmac(sha224)");
1492 ret
+= tcrypt_test("xcbc(aes)");
1496 ret
+= tcrypt_test("hmac(rmd128)");
1500 ret
+= tcrypt_test("hmac(rmd160)");
1504 ret
+= tcrypt_test("vmac(aes)");
1508 ret
+= tcrypt_test("hmac(crc32)");
1512 ret
+= tcrypt_test("ansi_cprng");
1516 ret
+= tcrypt_test("rfc4106(gcm(aes))");
1520 ret
+= tcrypt_test("rfc4543(gcm(aes))");
1524 ret
+= tcrypt_test("cmac(aes)");
1528 ret
+= tcrypt_test("cmac(des3_ede)");
1532 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1536 ret
+= tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1540 ret
+= tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1543 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(des))");
1546 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
1549 ret
+= tcrypt_test("authenc(hmac(sha224),cbc(des))");
1552 ret
+= tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
1555 ret
+= tcrypt_test("authenc(hmac(sha256),cbc(des))");
1558 ret
+= tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
1561 ret
+= tcrypt_test("authenc(hmac(sha384),cbc(des))");
1564 ret
+= tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
1567 ret
+= tcrypt_test("authenc(hmac(sha512),cbc(des))");
1570 ret
+= tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
1573 test_cipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1574 speed_template_16_24_32
);
1575 test_cipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1576 speed_template_16_24_32
);
1577 test_cipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1578 speed_template_16_24_32
);
1579 test_cipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1580 speed_template_16_24_32
);
1581 test_cipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1582 speed_template_32_40_48
);
1583 test_cipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1584 speed_template_32_40_48
);
1585 test_cipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1586 speed_template_32_48_64
);
1587 test_cipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1588 speed_template_32_48_64
);
1589 test_cipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
1590 speed_template_16_24_32
);
1591 test_cipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
1592 speed_template_16_24_32
);
1596 test_cipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1597 des3_speed_template
, DES3_SPEED_VECTORS
,
1599 test_cipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1600 des3_speed_template
, DES3_SPEED_VECTORS
,
1602 test_cipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1603 des3_speed_template
, DES3_SPEED_VECTORS
,
1605 test_cipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1606 des3_speed_template
, DES3_SPEED_VECTORS
,
1608 test_cipher_speed("ctr(des3_ede)", ENCRYPT
, sec
,
1609 des3_speed_template
, DES3_SPEED_VECTORS
,
1611 test_cipher_speed("ctr(des3_ede)", DECRYPT
, sec
,
1612 des3_speed_template
, DES3_SPEED_VECTORS
,
1617 test_cipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1618 speed_template_16_24_32
);
1619 test_cipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1620 speed_template_16_24_32
);
1621 test_cipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1622 speed_template_16_24_32
);
1623 test_cipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1624 speed_template_16_24_32
);
1625 test_cipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
1626 speed_template_16_24_32
);
1627 test_cipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
1628 speed_template_16_24_32
);
1629 test_cipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
1630 speed_template_32_40_48
);
1631 test_cipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
1632 speed_template_32_40_48
);
1633 test_cipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
1634 speed_template_32_48_64
);
1635 test_cipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
1636 speed_template_32_48_64
);
1640 test_cipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1641 speed_template_8_32
);
1642 test_cipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
1643 speed_template_8_32
);
1644 test_cipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1645 speed_template_8_32
);
1646 test_cipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
1647 speed_template_8_32
);
1648 test_cipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1649 speed_template_8_32
);
1650 test_cipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
1651 speed_template_8_32
);
1655 test_cipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1657 test_cipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1659 test_cipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1661 test_cipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1666 test_cipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
1667 speed_template_16_24_32
);
1668 test_cipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
1669 speed_template_16_24_32
);
1670 test_cipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
1671 speed_template_16_24_32
);
1672 test_cipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
1673 speed_template_16_24_32
);
1674 test_cipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
1675 speed_template_16_24_32
);
1676 test_cipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
1677 speed_template_16_24_32
);
1678 test_cipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
1679 speed_template_32_40_48
);
1680 test_cipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
1681 speed_template_32_40_48
);
1682 test_cipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
1683 speed_template_32_48_64
);
1684 test_cipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
1685 speed_template_32_48_64
);
1689 test_cipher_speed("salsa20", ENCRYPT
, sec
, NULL
, 0,
1690 speed_template_16_32
);
1694 test_cipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
1695 speed_template_16_32
);
1696 test_cipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
1697 speed_template_16_32
);
1698 test_cipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
1699 speed_template_16_32
);
1700 test_cipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
1701 speed_template_16_32
);
1702 test_cipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
1703 speed_template_16_32
);
1704 test_cipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
1705 speed_template_16_32
);
1706 test_cipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
1707 speed_template_32_48
);
1708 test_cipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
1709 speed_template_32_48
);
1710 test_cipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
1711 speed_template_32_64
);
1712 test_cipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
1713 speed_template_32_64
);
1717 test_cipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
1722 test_cipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
1723 speed_template_8_16
);
1724 test_cipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
1725 speed_template_8_16
);
1726 test_cipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
1727 speed_template_8_16
);
1728 test_cipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
1729 speed_template_8_16
);
1730 test_cipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
1731 speed_template_8_16
);
1732 test_cipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
1733 speed_template_8_16
);
1737 test_cipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
1738 speed_template_16_32
);
1739 test_cipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
1740 speed_template_16_32
);
1741 test_cipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
1742 speed_template_16_32
);
1743 test_cipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
1744 speed_template_16_32
);
1745 test_cipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
1746 speed_template_16_32
);
1747 test_cipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
1748 speed_template_16_32
);
1749 test_cipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
1750 speed_template_32_48
);
1751 test_cipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
1752 speed_template_32_48
);
1753 test_cipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
1754 speed_template_32_64
);
1755 test_cipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
1756 speed_template_32_64
);
1760 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT
, sec
,
1761 NULL
, 0, 16, 8, aead_speed_template_20
);
1766 test_hash_speed(alg
, sec
, generic_hash_speed_template
);
1773 test_hash_speed("md4", sec
, generic_hash_speed_template
);
1774 if (mode
> 300 && mode
< 400) break;
1777 test_hash_speed("md5", sec
, generic_hash_speed_template
);
1778 if (mode
> 300 && mode
< 400) break;
1781 test_hash_speed("sha1", sec
, generic_hash_speed_template
);
1782 if (mode
> 300 && mode
< 400) break;
1785 test_hash_speed("sha256", sec
, generic_hash_speed_template
);
1786 if (mode
> 300 && mode
< 400) break;
1789 test_hash_speed("sha384", sec
, generic_hash_speed_template
);
1790 if (mode
> 300 && mode
< 400) break;
1793 test_hash_speed("sha512", sec
, generic_hash_speed_template
);
1794 if (mode
> 300 && mode
< 400) break;
1797 test_hash_speed("wp256", sec
, generic_hash_speed_template
);
1798 if (mode
> 300 && mode
< 400) break;
1801 test_hash_speed("wp384", sec
, generic_hash_speed_template
);
1802 if (mode
> 300 && mode
< 400) break;
1805 test_hash_speed("wp512", sec
, generic_hash_speed_template
);
1806 if (mode
> 300 && mode
< 400) break;
1809 test_hash_speed("tgr128", sec
, generic_hash_speed_template
);
1810 if (mode
> 300 && mode
< 400) break;
1813 test_hash_speed("tgr160", sec
, generic_hash_speed_template
);
1814 if (mode
> 300 && mode
< 400) break;
1817 test_hash_speed("tgr192", sec
, generic_hash_speed_template
);
1818 if (mode
> 300 && mode
< 400) break;
1821 test_hash_speed("sha224", sec
, generic_hash_speed_template
);
1822 if (mode
> 300 && mode
< 400) break;
1825 test_hash_speed("rmd128", sec
, generic_hash_speed_template
);
1826 if (mode
> 300 && mode
< 400) break;
1829 test_hash_speed("rmd160", sec
, generic_hash_speed_template
);
1830 if (mode
> 300 && mode
< 400) break;
1833 test_hash_speed("rmd256", sec
, generic_hash_speed_template
);
1834 if (mode
> 300 && mode
< 400) break;
1837 test_hash_speed("rmd320", sec
, generic_hash_speed_template
);
1838 if (mode
> 300 && mode
< 400) break;
1841 test_hash_speed("ghash-generic", sec
, hash_speed_template_16
);
1842 if (mode
> 300 && mode
< 400) break;
1845 test_hash_speed("crc32c", sec
, generic_hash_speed_template
);
1846 if (mode
> 300 && mode
< 400) break;
1849 test_hash_speed("crct10dif", sec
, generic_hash_speed_template
);
1850 if (mode
> 300 && mode
< 400) break;
1857 test_ahash_speed(alg
, sec
, generic_hash_speed_template
);
1864 test_ahash_speed("md4", sec
, generic_hash_speed_template
);
1865 if (mode
> 400 && mode
< 500) break;
1868 test_ahash_speed("md5", sec
, generic_hash_speed_template
);
1869 if (mode
> 400 && mode
< 500) break;
1872 test_ahash_speed("sha1", sec
, generic_hash_speed_template
);
1873 if (mode
> 400 && mode
< 500) break;
1876 test_ahash_speed("sha256", sec
, generic_hash_speed_template
);
1877 if (mode
> 400 && mode
< 500) break;
1880 test_ahash_speed("sha384", sec
, generic_hash_speed_template
);
1881 if (mode
> 400 && mode
< 500) break;
1884 test_ahash_speed("sha512", sec
, generic_hash_speed_template
);
1885 if (mode
> 400 && mode
< 500) break;
1888 test_ahash_speed("wp256", sec
, generic_hash_speed_template
);
1889 if (mode
> 400 && mode
< 500) break;
1892 test_ahash_speed("wp384", sec
, generic_hash_speed_template
);
1893 if (mode
> 400 && mode
< 500) break;
1896 test_ahash_speed("wp512", sec
, generic_hash_speed_template
);
1897 if (mode
> 400 && mode
< 500) break;
1900 test_ahash_speed("tgr128", sec
, generic_hash_speed_template
);
1901 if (mode
> 400 && mode
< 500) break;
1904 test_ahash_speed("tgr160", sec
, generic_hash_speed_template
);
1905 if (mode
> 400 && mode
< 500) break;
1908 test_ahash_speed("tgr192", sec
, generic_hash_speed_template
);
1909 if (mode
> 400 && mode
< 500) break;
1912 test_ahash_speed("sha224", sec
, generic_hash_speed_template
);
1913 if (mode
> 400 && mode
< 500) break;
1916 test_ahash_speed("rmd128", sec
, generic_hash_speed_template
);
1917 if (mode
> 400 && mode
< 500) break;
1920 test_ahash_speed("rmd160", sec
, generic_hash_speed_template
);
1921 if (mode
> 400 && mode
< 500) break;
1924 test_ahash_speed("rmd256", sec
, generic_hash_speed_template
);
1925 if (mode
> 400 && mode
< 500) break;
1928 test_ahash_speed("rmd320", sec
, generic_hash_speed_template
);
1929 if (mode
> 400 && mode
< 500) break;
1935 test_acipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1936 speed_template_16_24_32
);
1937 test_acipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1938 speed_template_16_24_32
);
1939 test_acipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1940 speed_template_16_24_32
);
1941 test_acipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1942 speed_template_16_24_32
);
1943 test_acipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1944 speed_template_32_40_48
);
1945 test_acipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1946 speed_template_32_40_48
);
1947 test_acipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1948 speed_template_32_48_64
);
1949 test_acipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1950 speed_template_32_48_64
);
1951 test_acipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
1952 speed_template_16_24_32
);
1953 test_acipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
1954 speed_template_16_24_32
);
1955 test_acipher_speed("cfb(aes)", ENCRYPT
, sec
, NULL
, 0,
1956 speed_template_16_24_32
);
1957 test_acipher_speed("cfb(aes)", DECRYPT
, sec
, NULL
, 0,
1958 speed_template_16_24_32
);
1959 test_acipher_speed("ofb(aes)", ENCRYPT
, sec
, NULL
, 0,
1960 speed_template_16_24_32
);
1961 test_acipher_speed("ofb(aes)", DECRYPT
, sec
, NULL
, 0,
1962 speed_template_16_24_32
);
1963 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT
, sec
, NULL
, 0,
1964 speed_template_20_28_36
);
1965 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT
, sec
, NULL
, 0,
1966 speed_template_20_28_36
);
1970 test_acipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1971 des3_speed_template
, DES3_SPEED_VECTORS
,
1973 test_acipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1974 des3_speed_template
, DES3_SPEED_VECTORS
,
1976 test_acipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1977 des3_speed_template
, DES3_SPEED_VECTORS
,
1979 test_acipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1980 des3_speed_template
, DES3_SPEED_VECTORS
,
1982 test_acipher_speed("cfb(des3_ede)", ENCRYPT
, sec
,
1983 des3_speed_template
, DES3_SPEED_VECTORS
,
1985 test_acipher_speed("cfb(des3_ede)", DECRYPT
, sec
,
1986 des3_speed_template
, DES3_SPEED_VECTORS
,
1988 test_acipher_speed("ofb(des3_ede)", ENCRYPT
, sec
,
1989 des3_speed_template
, DES3_SPEED_VECTORS
,
1991 test_acipher_speed("ofb(des3_ede)", DECRYPT
, sec
,
1992 des3_speed_template
, DES3_SPEED_VECTORS
,
1997 test_acipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1999 test_acipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
2001 test_acipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
2003 test_acipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
2005 test_acipher_speed("cfb(des)", ENCRYPT
, sec
, NULL
, 0,
2007 test_acipher_speed("cfb(des)", DECRYPT
, sec
, NULL
, 0,
2009 test_acipher_speed("ofb(des)", ENCRYPT
, sec
, NULL
, 0,
2011 test_acipher_speed("ofb(des)", DECRYPT
, sec
, NULL
, 0,
2016 test_acipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
2017 speed_template_16_32
);
2018 test_acipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
2019 speed_template_16_32
);
2020 test_acipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
2021 speed_template_16_32
);
2022 test_acipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
2023 speed_template_16_32
);
2024 test_acipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
2025 speed_template_16_32
);
2026 test_acipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
2027 speed_template_16_32
);
2028 test_acipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
2029 speed_template_32_48
);
2030 test_acipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
2031 speed_template_32_48
);
2032 test_acipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
2033 speed_template_32_64
);
2034 test_acipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
2035 speed_template_32_64
);
2039 test_acipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
2040 speed_template_16_24_32
);
2041 test_acipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
2042 speed_template_16_24_32
);
2043 test_acipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
2044 speed_template_16_24_32
);
2045 test_acipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
2046 speed_template_16_24_32
);
2047 test_acipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
2048 speed_template_16_24_32
);
2049 test_acipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
2050 speed_template_16_24_32
);
2051 test_acipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
2052 speed_template_32_40_48
);
2053 test_acipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
2054 speed_template_32_40_48
);
2055 test_acipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
2056 speed_template_32_48_64
);
2057 test_acipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
2058 speed_template_32_48_64
);
2062 test_acipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
2067 test_acipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
2068 speed_template_8_16
);
2069 test_acipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
2070 speed_template_8_16
);
2071 test_acipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
2072 speed_template_8_16
);
2073 test_acipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
2074 speed_template_8_16
);
2075 test_acipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
2076 speed_template_8_16
);
2077 test_acipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
2078 speed_template_8_16
);
2082 test_acipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
2083 speed_template_16_32
);
2084 test_acipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
2085 speed_template_16_32
);
2086 test_acipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
2087 speed_template_16_32
);
2088 test_acipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
2089 speed_template_16_32
);
2090 test_acipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
2091 speed_template_16_32
);
2092 test_acipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
2093 speed_template_16_32
);
2094 test_acipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
2095 speed_template_32_48
);
2096 test_acipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
2097 speed_template_32_48
);
2098 test_acipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
2099 speed_template_32_64
);
2100 test_acipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
2101 speed_template_32_64
);
2105 test_acipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
2106 speed_template_16_32
);
2107 test_acipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
2108 speed_template_16_32
);
2109 test_acipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
2110 speed_template_16_32
);
2111 test_acipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
2112 speed_template_16_32
);
2113 test_acipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
2114 speed_template_16_32
);
2115 test_acipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
2116 speed_template_16_32
);
2117 test_acipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
2118 speed_template_32_48
);
2119 test_acipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
2120 speed_template_32_48
);
2121 test_acipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
2122 speed_template_32_64
);
2123 test_acipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
2124 speed_template_32_64
);
2128 test_acipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2129 speed_template_8_32
);
2130 test_acipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
2131 speed_template_8_32
);
2132 test_acipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2133 speed_template_8_32
);
2134 test_acipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
2135 speed_template_8_32
);
2136 test_acipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2137 speed_template_8_32
);
2138 test_acipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
2139 speed_template_8_32
);
2150 static int __init
tcrypt_mod_init(void)
2155 for (i
= 0; i
< TVMEMSIZE
; i
++) {
2156 tvmem
[i
] = (void *)__get_free_page(GFP_KERNEL
);
2161 err
= do_test(alg
, type
, mask
, mode
);
2164 printk(KERN_ERR
"tcrypt: one or more tests failed!\n");
2168 /* We intentionaly return -EAGAIN to prevent keeping the module,
2169 * unless we're running in fips mode. It does all its work from
2170 * init() and doesn't offer any runtime functionality, but in
2171 * the fips case, checking for a successful load is helpful.
2172 * => we don't need it in the memory, do we?
2179 for (i
= 0; i
< TVMEMSIZE
&& tvmem
[i
]; i
++)
2180 free_page((unsigned long)tvmem
[i
]);
2186 * If an init function is provided, an exit function must also be provided
2187 * to allow module unload.
2189 static void __exit
tcrypt_mod_fini(void) { }
2191 module_init(tcrypt_mod_init
);
2192 module_exit(tcrypt_mod_fini
);
2194 module_param(alg
, charp
, 0);
2195 module_param(type
, uint
, 0);
2196 module_param(mask
, uint
, 0);
2197 module_param(mode
, int, 0);
2198 module_param(sec
, uint
, 0);
2199 MODULE_PARM_DESC(sec
, "Length in seconds of speed tests "
2200 "(defaults to zero which uses CPU cycles instead)");
2202 MODULE_LICENSE("GPL");
2203 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2204 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");