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 struct tcrypt_result
{
77 struct completion completion
;
81 static void tcrypt_complete(struct crypto_async_request
*req
, int err
)
83 struct tcrypt_result
*res
= req
->data
;
85 if (err
== -EINPROGRESS
)
89 complete(&res
->completion
);
92 static int test_cipher_jiffies(struct blkcipher_desc
*desc
, int enc
,
93 struct scatterlist
*sg
, int blen
, int secs
)
95 unsigned long start
, end
;
99 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
100 time_before(jiffies
, end
); bcount
++) {
102 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
104 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
110 printk("%d operations in %d seconds (%ld bytes)\n",
111 bcount
, secs
, (long)bcount
* blen
);
115 static int test_cipher_cycles(struct blkcipher_desc
*desc
, int enc
,
116 struct scatterlist
*sg
, int blen
)
118 unsigned long cycles
= 0;
125 for (i
= 0; i
< 4; i
++) {
127 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
129 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
135 /* The real thing. */
136 for (i
= 0; i
< 8; i
++) {
139 start
= get_cycles();
141 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
143 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
149 cycles
+= end
- start
;
156 printk("1 operation in %lu cycles (%d bytes)\n",
157 (cycles
+ 4) / 8, blen
);
162 static inline int do_one_aead_op(struct aead_request
*req
, int ret
)
164 if (ret
== -EINPROGRESS
|| ret
== -EBUSY
) {
165 struct tcrypt_result
*tr
= req
->base
.data
;
167 ret
= wait_for_completion_interruptible(&tr
->completion
);
170 reinit_completion(&tr
->completion
);
176 static int test_aead_jiffies(struct aead_request
*req
, int enc
,
179 unsigned long start
, end
;
183 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
184 time_before(jiffies
, end
); bcount
++) {
186 ret
= do_one_aead_op(req
, crypto_aead_encrypt(req
));
188 ret
= do_one_aead_op(req
, crypto_aead_decrypt(req
));
194 printk("%d operations in %d seconds (%ld bytes)\n",
195 bcount
, secs
, (long)bcount
* blen
);
199 static int test_aead_cycles(struct aead_request
*req
, int enc
, int blen
)
201 unsigned long cycles
= 0;
208 for (i
= 0; i
< 4; i
++) {
210 ret
= do_one_aead_op(req
, crypto_aead_encrypt(req
));
212 ret
= do_one_aead_op(req
, crypto_aead_decrypt(req
));
218 /* The real thing. */
219 for (i
= 0; i
< 8; i
++) {
222 start
= get_cycles();
224 ret
= do_one_aead_op(req
, crypto_aead_encrypt(req
));
226 ret
= do_one_aead_op(req
, crypto_aead_decrypt(req
));
232 cycles
+= end
- start
;
239 printk("1 operation in %lu cycles (%d bytes)\n",
240 (cycles
+ 4) / 8, blen
);
245 static u32 block_sizes
[] = { 16, 64, 256, 1024, 8192, 0 };
246 static u32 aead_sizes
[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
251 static int testmgr_alloc_buf(char *buf
[XBUFSIZE
])
255 for (i
= 0; i
< XBUFSIZE
; i
++) {
256 buf
[i
] = (void *)__get_free_page(GFP_KERNEL
);
265 free_page((unsigned long)buf
[i
]);
270 static void testmgr_free_buf(char *buf
[XBUFSIZE
])
274 for (i
= 0; i
< XBUFSIZE
; i
++)
275 free_page((unsigned long)buf
[i
]);
278 static void sg_init_aead(struct scatterlist
*sg
, char *xbuf
[XBUFSIZE
],
281 int np
= (buflen
+ PAGE_SIZE
- 1)/PAGE_SIZE
;
288 rem
= buflen
% PAGE_SIZE
;
291 sg_init_table(sg
, np
+ 1);
293 for (k
= 0; k
< np
; k
++)
294 sg_set_buf(&sg
[k
+ 1], xbuf
[k
], PAGE_SIZE
);
296 sg_set_buf(&sg
[k
+ 1], xbuf
[k
], rem
);
299 static void test_aead_speed(const char *algo
, int enc
, unsigned int secs
,
300 struct aead_speed_template
*template,
301 unsigned int tcount
, u8 authsize
,
302 unsigned int aad_size
, u8
*keysize
)
305 struct crypto_aead
*tfm
;
308 struct aead_request
*req
;
309 struct scatterlist
*sg
;
310 struct scatterlist
*sgout
;
314 char *xbuf
[XBUFSIZE
];
315 char *xoutbuf
[XBUFSIZE
];
316 char *axbuf
[XBUFSIZE
];
317 unsigned int *b_size
;
319 struct tcrypt_result result
;
321 iv
= kzalloc(MAX_IVLEN
, GFP_KERNEL
);
325 if (aad_size
>= PAGE_SIZE
) {
326 pr_err("associate data length (%u) too big\n", aad_size
);
335 if (testmgr_alloc_buf(xbuf
))
337 if (testmgr_alloc_buf(axbuf
))
339 if (testmgr_alloc_buf(xoutbuf
))
342 sg
= kmalloc(sizeof(*sg
) * 9 * 2, GFP_KERNEL
);
347 tfm
= crypto_alloc_aead(algo
, 0, 0);
350 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo
,
355 init_completion(&result
.completion
);
356 printk(KERN_INFO
"\ntesting speed of %s (%s) %s\n", algo
,
357 get_driver_name(crypto_aead
, tfm
), e
);
359 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
361 pr_err("alg: aead: Failed to allocate request for %s\n",
366 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
367 tcrypt_complete
, &result
);
374 memset(assoc
, 0xff, aad_size
);
376 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
377 pr_err("template (%u) too big for tvmem (%lu)\n",
379 TVMEMSIZE
* PAGE_SIZE
);
384 for (j
= 0; j
< tcount
; j
++) {
385 if (template[j
].klen
== *keysize
) {
386 key
= template[j
].key
;
390 ret
= crypto_aead_setkey(tfm
, key
, *keysize
);
391 ret
= crypto_aead_setauthsize(tfm
, authsize
);
393 iv_len
= crypto_aead_ivsize(tfm
);
395 memset(iv
, 0xff, iv_len
);
397 crypto_aead_clear_flags(tfm
, ~0);
398 printk(KERN_INFO
"test %u (%d bit key, %d byte blocks): ",
399 i
, *keysize
* 8, *b_size
);
402 memset(tvmem
[0], 0xff, PAGE_SIZE
);
405 pr_err("setkey() failed flags=%x\n",
406 crypto_aead_get_flags(tfm
));
410 sg_init_aead(sg
, xbuf
,
411 *b_size
+ (enc
? authsize
: 0));
413 sg_init_aead(sgout
, xoutbuf
,
414 *b_size
+ (enc
? authsize
: 0));
416 sg_set_buf(&sg
[0], assoc
, aad_size
);
417 sg_set_buf(&sgout
[0], assoc
, aad_size
);
419 aead_request_set_crypt(req
, sg
, sgout
, *b_size
, iv
);
420 aead_request_set_ad(req
, aad_size
);
423 ret
= test_aead_jiffies(req
, enc
, *b_size
,
426 ret
= test_aead_cycles(req
, enc
, *b_size
);
429 pr_err("%s() failed return code=%d\n", e
, ret
);
439 aead_request_free(req
);
441 crypto_free_aead(tfm
);
445 testmgr_free_buf(xoutbuf
);
447 testmgr_free_buf(axbuf
);
449 testmgr_free_buf(xbuf
);
455 static void test_cipher_speed(const char *algo
, int enc
, unsigned int secs
,
456 struct cipher_speed_template
*template,
457 unsigned int tcount
, u8
*keysize
)
459 unsigned int ret
, i
, j
, iv_len
;
462 struct crypto_blkcipher
*tfm
;
463 struct blkcipher_desc desc
;
472 tfm
= crypto_alloc_blkcipher(algo
, 0, CRYPTO_ALG_ASYNC
);
475 printk("failed to load transform for %s: %ld\n", algo
,
482 printk(KERN_INFO
"\ntesting speed of %s (%s) %s\n", algo
,
483 get_driver_name(crypto_blkcipher
, tfm
), e
);
488 b_size
= block_sizes
;
490 struct scatterlist sg
[TVMEMSIZE
];
492 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
493 printk("template (%u) too big for "
494 "tvmem (%lu)\n", *keysize
+ *b_size
,
495 TVMEMSIZE
* PAGE_SIZE
);
499 printk("test %u (%d bit key, %d byte blocks): ", i
,
500 *keysize
* 8, *b_size
);
502 memset(tvmem
[0], 0xff, PAGE_SIZE
);
504 /* set key, plain text and IV */
506 for (j
= 0; j
< tcount
; j
++) {
507 if (template[j
].klen
== *keysize
) {
508 key
= template[j
].key
;
513 ret
= crypto_blkcipher_setkey(tfm
, key
, *keysize
);
515 printk("setkey() failed flags=%x\n",
516 crypto_blkcipher_get_flags(tfm
));
520 sg_init_table(sg
, TVMEMSIZE
);
521 sg_set_buf(sg
, tvmem
[0] + *keysize
,
522 PAGE_SIZE
- *keysize
);
523 for (j
= 1; j
< TVMEMSIZE
; j
++) {
524 sg_set_buf(sg
+ j
, tvmem
[j
], PAGE_SIZE
);
525 memset (tvmem
[j
], 0xff, PAGE_SIZE
);
528 iv_len
= crypto_blkcipher_ivsize(tfm
);
530 memset(&iv
, 0xff, iv_len
);
531 crypto_blkcipher_set_iv(tfm
, iv
, iv_len
);
535 ret
= test_cipher_jiffies(&desc
, enc
, sg
,
538 ret
= test_cipher_cycles(&desc
, enc
, sg
,
542 printk("%s() failed flags=%x\n", e
, desc
.flags
);
552 crypto_free_blkcipher(tfm
);
555 static int test_hash_jiffies_digest(struct hash_desc
*desc
,
556 struct scatterlist
*sg
, int blen
,
559 unsigned long start
, end
;
563 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
564 time_before(jiffies
, end
); bcount
++) {
565 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
570 printk("%6u opers/sec, %9lu bytes/sec\n",
571 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
576 static int test_hash_jiffies(struct hash_desc
*desc
, struct scatterlist
*sg
,
577 int blen
, int plen
, char *out
, int secs
)
579 unsigned long start
, end
;
584 return test_hash_jiffies_digest(desc
, sg
, blen
, out
, secs
);
586 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
587 time_before(jiffies
, end
); bcount
++) {
588 ret
= crypto_hash_init(desc
);
591 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
592 ret
= crypto_hash_update(desc
, sg
, plen
);
596 /* we assume there is enough space in 'out' for the result */
597 ret
= crypto_hash_final(desc
, out
);
602 printk("%6u opers/sec, %9lu bytes/sec\n",
603 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
608 static int test_hash_cycles_digest(struct hash_desc
*desc
,
609 struct scatterlist
*sg
, int blen
, char *out
)
611 unsigned long cycles
= 0;
618 for (i
= 0; i
< 4; i
++) {
619 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
624 /* The real thing. */
625 for (i
= 0; i
< 8; i
++) {
628 start
= get_cycles();
630 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
636 cycles
+= end
- start
;
645 printk("%6lu cycles/operation, %4lu cycles/byte\n",
646 cycles
/ 8, cycles
/ (8 * blen
));
651 static int test_hash_cycles(struct hash_desc
*desc
, struct scatterlist
*sg
,
652 int blen
, int plen
, char *out
)
654 unsigned long cycles
= 0;
659 return test_hash_cycles_digest(desc
, sg
, blen
, out
);
664 for (i
= 0; i
< 4; i
++) {
665 ret
= crypto_hash_init(desc
);
668 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
669 ret
= crypto_hash_update(desc
, sg
, plen
);
673 ret
= crypto_hash_final(desc
, out
);
678 /* The real thing. */
679 for (i
= 0; i
< 8; i
++) {
682 start
= get_cycles();
684 ret
= crypto_hash_init(desc
);
687 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
688 ret
= crypto_hash_update(desc
, sg
, plen
);
692 ret
= crypto_hash_final(desc
, out
);
698 cycles
+= end
- start
;
707 printk("%6lu cycles/operation, %4lu cycles/byte\n",
708 cycles
/ 8, cycles
/ (8 * blen
));
713 static void test_hash_sg_init(struct scatterlist
*sg
)
717 sg_init_table(sg
, TVMEMSIZE
);
718 for (i
= 0; i
< TVMEMSIZE
; i
++) {
719 sg_set_buf(sg
+ i
, tvmem
[i
], PAGE_SIZE
);
720 memset(tvmem
[i
], 0xff, PAGE_SIZE
);
724 static void test_hash_speed(const char *algo
, unsigned int secs
,
725 struct hash_speed
*speed
)
727 struct scatterlist sg
[TVMEMSIZE
];
728 struct crypto_hash
*tfm
;
729 struct hash_desc desc
;
730 static char output
[1024];
734 tfm
= crypto_alloc_hash(algo
, 0, CRYPTO_ALG_ASYNC
);
737 printk(KERN_ERR
"failed to load transform for %s: %ld\n", algo
,
742 printk(KERN_INFO
"\ntesting speed of %s (%s)\n", algo
,
743 get_driver_name(crypto_hash
, tfm
));
748 if (crypto_hash_digestsize(tfm
) > sizeof(output
)) {
749 printk(KERN_ERR
"digestsize(%u) > outputbuffer(%zu)\n",
750 crypto_hash_digestsize(tfm
), sizeof(output
));
754 test_hash_sg_init(sg
);
755 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
756 if (speed
[i
].blen
> TVMEMSIZE
* PAGE_SIZE
) {
758 "template (%u) too big for tvmem (%lu)\n",
759 speed
[i
].blen
, TVMEMSIZE
* PAGE_SIZE
);
764 crypto_hash_setkey(tfm
, tvmem
[0], speed
[i
].klen
);
766 printk(KERN_INFO
"test%3u "
767 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
768 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
771 ret
= test_hash_jiffies(&desc
, sg
, speed
[i
].blen
,
772 speed
[i
].plen
, output
, secs
);
774 ret
= test_hash_cycles(&desc
, sg
, speed
[i
].blen
,
775 speed
[i
].plen
, output
);
778 printk(KERN_ERR
"hashing failed ret=%d\n", ret
);
784 crypto_free_hash(tfm
);
787 static inline int do_one_ahash_op(struct ahash_request
*req
, int ret
)
789 if (ret
== -EINPROGRESS
|| ret
== -EBUSY
) {
790 struct tcrypt_result
*tr
= req
->base
.data
;
792 wait_for_completion(&tr
->completion
);
793 reinit_completion(&tr
->completion
);
799 static int test_ahash_jiffies_digest(struct ahash_request
*req
, int blen
,
802 unsigned long start
, end
;
806 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
807 time_before(jiffies
, end
); bcount
++) {
808 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
813 printk("%6u opers/sec, %9lu bytes/sec\n",
814 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
819 static int test_ahash_jiffies(struct ahash_request
*req
, int blen
,
820 int plen
, char *out
, int secs
)
822 unsigned long start
, end
;
827 return test_ahash_jiffies_digest(req
, blen
, out
, secs
);
829 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
830 time_before(jiffies
, end
); bcount
++) {
831 ret
= do_one_ahash_op(req
, crypto_ahash_init(req
));
834 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
835 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
839 /* we assume there is enough space in 'out' for the result */
840 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
845 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
846 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
851 static int test_ahash_cycles_digest(struct ahash_request
*req
, int blen
,
854 unsigned long cycles
= 0;
858 for (i
= 0; i
< 4; i
++) {
859 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
864 /* The real thing. */
865 for (i
= 0; i
< 8; i
++) {
868 start
= get_cycles();
870 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
876 cycles
+= end
- start
;
883 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
884 cycles
/ 8, cycles
/ (8 * blen
));
889 static int test_ahash_cycles(struct ahash_request
*req
, int blen
,
892 unsigned long cycles
= 0;
896 return test_ahash_cycles_digest(req
, blen
, out
);
899 for (i
= 0; i
< 4; i
++) {
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
));
913 /* The real thing. */
914 for (i
= 0; i
< 8; i
++) {
917 start
= get_cycles();
919 ret
= do_one_ahash_op(req
, crypto_ahash_init(req
));
922 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
923 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
927 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
933 cycles
+= end
- start
;
940 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
941 cycles
/ 8, cycles
/ (8 * blen
));
946 static void test_ahash_speed(const char *algo
, unsigned int secs
,
947 struct hash_speed
*speed
)
949 struct scatterlist sg
[TVMEMSIZE
];
950 struct tcrypt_result tresult
;
951 struct ahash_request
*req
;
952 struct crypto_ahash
*tfm
;
953 static char output
[1024];
956 tfm
= crypto_alloc_ahash(algo
, 0, 0);
958 pr_err("failed to load transform for %s: %ld\n",
963 printk(KERN_INFO
"\ntesting speed of async %s (%s)\n", algo
,
964 get_driver_name(crypto_ahash
, tfm
));
966 if (crypto_ahash_digestsize(tfm
) > sizeof(output
)) {
967 pr_err("digestsize(%u) > outputbuffer(%zu)\n",
968 crypto_ahash_digestsize(tfm
), sizeof(output
));
972 test_hash_sg_init(sg
);
973 req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
975 pr_err("ahash request allocation failure\n");
979 init_completion(&tresult
.completion
);
980 ahash_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
981 tcrypt_complete
, &tresult
);
983 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
984 if (speed
[i
].blen
> TVMEMSIZE
* PAGE_SIZE
) {
985 pr_err("template (%u) too big for tvmem (%lu)\n",
986 speed
[i
].blen
, TVMEMSIZE
* PAGE_SIZE
);
991 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
992 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
994 ahash_request_set_crypt(req
, sg
, output
, speed
[i
].plen
);
997 ret
= test_ahash_jiffies(req
, speed
[i
].blen
,
998 speed
[i
].plen
, output
, secs
);
1000 ret
= test_ahash_cycles(req
, speed
[i
].blen
,
1001 speed
[i
].plen
, output
);
1004 pr_err("hashing failed ret=%d\n", ret
);
1009 ahash_request_free(req
);
1012 crypto_free_ahash(tfm
);
1015 static inline int do_one_acipher_op(struct ablkcipher_request
*req
, int ret
)
1017 if (ret
== -EINPROGRESS
|| ret
== -EBUSY
) {
1018 struct tcrypt_result
*tr
= req
->base
.data
;
1020 wait_for_completion(&tr
->completion
);
1021 reinit_completion(&tr
->completion
);
1028 static int test_acipher_jiffies(struct ablkcipher_request
*req
, int enc
,
1031 unsigned long start
, end
;
1035 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
1036 time_before(jiffies
, end
); bcount
++) {
1038 ret
= do_one_acipher_op(req
,
1039 crypto_ablkcipher_encrypt(req
));
1041 ret
= do_one_acipher_op(req
,
1042 crypto_ablkcipher_decrypt(req
));
1048 pr_cont("%d operations in %d seconds (%ld bytes)\n",
1049 bcount
, secs
, (long)bcount
* blen
);
1053 static int test_acipher_cycles(struct ablkcipher_request
*req
, int enc
,
1056 unsigned long cycles
= 0;
1061 for (i
= 0; i
< 4; i
++) {
1063 ret
= do_one_acipher_op(req
,
1064 crypto_ablkcipher_encrypt(req
));
1066 ret
= do_one_acipher_op(req
,
1067 crypto_ablkcipher_decrypt(req
));
1073 /* The real thing. */
1074 for (i
= 0; i
< 8; i
++) {
1075 cycles_t start
, end
;
1077 start
= get_cycles();
1079 ret
= do_one_acipher_op(req
,
1080 crypto_ablkcipher_encrypt(req
));
1082 ret
= do_one_acipher_op(req
,
1083 crypto_ablkcipher_decrypt(req
));
1089 cycles
+= end
- start
;
1094 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1095 (cycles
+ 4) / 8, blen
);
1100 static void test_acipher_speed(const char *algo
, int enc
, unsigned int secs
,
1101 struct cipher_speed_template
*template,
1102 unsigned int tcount
, u8
*keysize
)
1104 unsigned int ret
, i
, j
, k
, iv_len
;
1105 struct tcrypt_result tresult
;
1108 struct ablkcipher_request
*req
;
1109 struct crypto_ablkcipher
*tfm
;
1118 init_completion(&tresult
.completion
);
1120 tfm
= crypto_alloc_ablkcipher(algo
, 0, 0);
1123 pr_err("failed to load transform for %s: %ld\n", algo
,
1128 pr_info("\ntesting speed of async %s (%s) %s\n", algo
,
1129 get_driver_name(crypto_ablkcipher
, tfm
), e
);
1131 req
= ablkcipher_request_alloc(tfm
, GFP_KERNEL
);
1133 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1138 ablkcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
1139 tcrypt_complete
, &tresult
);
1143 b_size
= block_sizes
;
1146 struct scatterlist sg
[TVMEMSIZE
];
1148 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
1149 pr_err("template (%u) too big for "
1150 "tvmem (%lu)\n", *keysize
+ *b_size
,
1151 TVMEMSIZE
* PAGE_SIZE
);
1155 pr_info("test %u (%d bit key, %d byte blocks): ", i
,
1156 *keysize
* 8, *b_size
);
1158 memset(tvmem
[0], 0xff, PAGE_SIZE
);
1160 /* set key, plain text and IV */
1162 for (j
= 0; j
< tcount
; j
++) {
1163 if (template[j
].klen
== *keysize
) {
1164 key
= template[j
].key
;
1169 crypto_ablkcipher_clear_flags(tfm
, ~0);
1171 ret
= crypto_ablkcipher_setkey(tfm
, key
, *keysize
);
1173 pr_err("setkey() failed flags=%x\n",
1174 crypto_ablkcipher_get_flags(tfm
));
1178 k
= *keysize
+ *b_size
;
1179 sg_init_table(sg
, DIV_ROUND_UP(k
, PAGE_SIZE
));
1181 if (k
> PAGE_SIZE
) {
1182 sg_set_buf(sg
, tvmem
[0] + *keysize
,
1183 PAGE_SIZE
- *keysize
);
1186 while (k
> PAGE_SIZE
) {
1187 sg_set_buf(sg
+ j
, tvmem
[j
], PAGE_SIZE
);
1188 memset(tvmem
[j
], 0xff, PAGE_SIZE
);
1192 sg_set_buf(sg
+ j
, tvmem
[j
], k
);
1193 memset(tvmem
[j
], 0xff, k
);
1195 sg_set_buf(sg
, tvmem
[0] + *keysize
, *b_size
);
1198 iv_len
= crypto_ablkcipher_ivsize(tfm
);
1200 memset(&iv
, 0xff, iv_len
);
1202 ablkcipher_request_set_crypt(req
, sg
, sg
, *b_size
, iv
);
1205 ret
= test_acipher_jiffies(req
, enc
,
1208 ret
= test_acipher_cycles(req
, enc
,
1212 pr_err("%s() failed flags=%x\n", e
,
1213 crypto_ablkcipher_get_flags(tfm
));
1223 ablkcipher_request_free(req
);
1225 crypto_free_ablkcipher(tfm
);
1228 static void test_available(void)
1230 char **name
= check
;
1233 printk("alg %s ", *name
);
1234 printk(crypto_has_alg(*name
, 0, 0) ?
1235 "found\n" : "not found\n");
1240 static inline int tcrypt_test(const char *alg
)
1244 ret
= alg_test(alg
, alg
, 0, 0);
1245 /* non-fips algs return -EINVAL in fips mode */
1246 if (fips_enabled
&& ret
== -EINVAL
)
1251 static int do_test(const char *alg
, u32 type
, u32 mask
, int m
)
1259 if (!crypto_has_alg(alg
, type
,
1260 mask
?: CRYPTO_ALG_TYPE_MASK
))
1265 for (i
= 1; i
< 200; i
++)
1266 ret
+= do_test(NULL
, 0, 0, i
);
1270 ret
+= tcrypt_test("md5");
1274 ret
+= tcrypt_test("sha1");
1278 ret
+= tcrypt_test("ecb(des)");
1279 ret
+= tcrypt_test("cbc(des)");
1280 ret
+= tcrypt_test("ctr(des)");
1284 ret
+= tcrypt_test("ecb(des3_ede)");
1285 ret
+= tcrypt_test("cbc(des3_ede)");
1286 ret
+= tcrypt_test("ctr(des3_ede)");
1290 ret
+= tcrypt_test("md4");
1294 ret
+= tcrypt_test("sha256");
1298 ret
+= tcrypt_test("ecb(blowfish)");
1299 ret
+= tcrypt_test("cbc(blowfish)");
1300 ret
+= tcrypt_test("ctr(blowfish)");
1304 ret
+= tcrypt_test("ecb(twofish)");
1305 ret
+= tcrypt_test("cbc(twofish)");
1306 ret
+= tcrypt_test("ctr(twofish)");
1307 ret
+= tcrypt_test("lrw(twofish)");
1308 ret
+= tcrypt_test("xts(twofish)");
1312 ret
+= tcrypt_test("ecb(serpent)");
1313 ret
+= tcrypt_test("cbc(serpent)");
1314 ret
+= tcrypt_test("ctr(serpent)");
1315 ret
+= tcrypt_test("lrw(serpent)");
1316 ret
+= tcrypt_test("xts(serpent)");
1320 ret
+= tcrypt_test("ecb(aes)");
1321 ret
+= tcrypt_test("cbc(aes)");
1322 ret
+= tcrypt_test("lrw(aes)");
1323 ret
+= tcrypt_test("xts(aes)");
1324 ret
+= tcrypt_test("ctr(aes)");
1325 ret
+= tcrypt_test("rfc3686(ctr(aes))");
1329 ret
+= tcrypt_test("sha384");
1333 ret
+= tcrypt_test("sha512");
1337 ret
+= tcrypt_test("deflate");
1341 ret
+= tcrypt_test("ecb(cast5)");
1342 ret
+= tcrypt_test("cbc(cast5)");
1343 ret
+= tcrypt_test("ctr(cast5)");
1347 ret
+= tcrypt_test("ecb(cast6)");
1348 ret
+= tcrypt_test("cbc(cast6)");
1349 ret
+= tcrypt_test("ctr(cast6)");
1350 ret
+= tcrypt_test("lrw(cast6)");
1351 ret
+= tcrypt_test("xts(cast6)");
1355 ret
+= tcrypt_test("ecb(arc4)");
1359 ret
+= tcrypt_test("michael_mic");
1363 ret
+= tcrypt_test("crc32c");
1367 ret
+= tcrypt_test("ecb(tea)");
1371 ret
+= tcrypt_test("ecb(xtea)");
1375 ret
+= tcrypt_test("ecb(khazad)");
1379 ret
+= tcrypt_test("wp512");
1383 ret
+= tcrypt_test("wp384");
1387 ret
+= tcrypt_test("wp256");
1391 ret
+= tcrypt_test("ecb(tnepres)");
1395 ret
+= tcrypt_test("ecb(anubis)");
1396 ret
+= tcrypt_test("cbc(anubis)");
1400 ret
+= tcrypt_test("tgr192");
1404 ret
+= tcrypt_test("tgr160");
1408 ret
+= tcrypt_test("tgr128");
1412 ret
+= tcrypt_test("ecb(xeta)");
1416 ret
+= tcrypt_test("pcbc(fcrypt)");
1420 ret
+= tcrypt_test("ecb(camellia)");
1421 ret
+= tcrypt_test("cbc(camellia)");
1422 ret
+= tcrypt_test("ctr(camellia)");
1423 ret
+= tcrypt_test("lrw(camellia)");
1424 ret
+= tcrypt_test("xts(camellia)");
1428 ret
+= tcrypt_test("sha224");
1432 ret
+= tcrypt_test("salsa20");
1436 ret
+= tcrypt_test("gcm(aes)");
1440 ret
+= tcrypt_test("lzo");
1444 ret
+= tcrypt_test("ccm(aes)");
1448 ret
+= tcrypt_test("cts(cbc(aes))");
1452 ret
+= tcrypt_test("rmd128");
1456 ret
+= tcrypt_test("rmd160");
1460 ret
+= tcrypt_test("rmd256");
1464 ret
+= tcrypt_test("rmd320");
1468 ret
+= tcrypt_test("ecb(seed)");
1472 ret
+= tcrypt_test("zlib");
1476 ret
+= tcrypt_test("rfc4309(ccm(aes))");
1480 ret
+= tcrypt_test("ghash");
1484 ret
+= tcrypt_test("crct10dif");
1488 ret
+= tcrypt_test("hmac(md5)");
1492 ret
+= tcrypt_test("hmac(sha1)");
1496 ret
+= tcrypt_test("hmac(sha256)");
1500 ret
+= tcrypt_test("hmac(sha384)");
1504 ret
+= tcrypt_test("hmac(sha512)");
1508 ret
+= tcrypt_test("hmac(sha224)");
1512 ret
+= tcrypt_test("xcbc(aes)");
1516 ret
+= tcrypt_test("hmac(rmd128)");
1520 ret
+= tcrypt_test("hmac(rmd160)");
1524 ret
+= tcrypt_test("vmac(aes)");
1528 ret
+= tcrypt_test("hmac(crc32)");
1532 ret
+= tcrypt_test("ansi_cprng");
1536 ret
+= tcrypt_test("rfc4106(gcm(aes))");
1540 ret
+= tcrypt_test("rfc4543(gcm(aes))");
1544 ret
+= tcrypt_test("cmac(aes)");
1548 ret
+= tcrypt_test("cmac(des3_ede)");
1552 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1556 ret
+= tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1560 ret
+= tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1563 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(des))");
1566 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
1569 ret
+= tcrypt_test("authenc(hmac(sha224),cbc(des))");
1572 ret
+= tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
1575 ret
+= tcrypt_test("authenc(hmac(sha256),cbc(des))");
1578 ret
+= tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
1581 ret
+= tcrypt_test("authenc(hmac(sha384),cbc(des))");
1584 ret
+= tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
1587 ret
+= tcrypt_test("authenc(hmac(sha512),cbc(des))");
1590 ret
+= tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
1593 test_cipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1594 speed_template_16_24_32
);
1595 test_cipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1596 speed_template_16_24_32
);
1597 test_cipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1598 speed_template_16_24_32
);
1599 test_cipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1600 speed_template_16_24_32
);
1601 test_cipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1602 speed_template_32_40_48
);
1603 test_cipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1604 speed_template_32_40_48
);
1605 test_cipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1606 speed_template_32_48_64
);
1607 test_cipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1608 speed_template_32_48_64
);
1609 test_cipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
1610 speed_template_16_24_32
);
1611 test_cipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
1612 speed_template_16_24_32
);
1616 test_cipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1617 des3_speed_template
, DES3_SPEED_VECTORS
,
1619 test_cipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1620 des3_speed_template
, DES3_SPEED_VECTORS
,
1622 test_cipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1623 des3_speed_template
, DES3_SPEED_VECTORS
,
1625 test_cipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1626 des3_speed_template
, DES3_SPEED_VECTORS
,
1628 test_cipher_speed("ctr(des3_ede)", ENCRYPT
, sec
,
1629 des3_speed_template
, DES3_SPEED_VECTORS
,
1631 test_cipher_speed("ctr(des3_ede)", DECRYPT
, sec
,
1632 des3_speed_template
, DES3_SPEED_VECTORS
,
1637 test_cipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1638 speed_template_16_24_32
);
1639 test_cipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1640 speed_template_16_24_32
);
1641 test_cipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1642 speed_template_16_24_32
);
1643 test_cipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1644 speed_template_16_24_32
);
1645 test_cipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
1646 speed_template_16_24_32
);
1647 test_cipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
1648 speed_template_16_24_32
);
1649 test_cipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
1650 speed_template_32_40_48
);
1651 test_cipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
1652 speed_template_32_40_48
);
1653 test_cipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
1654 speed_template_32_48_64
);
1655 test_cipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
1656 speed_template_32_48_64
);
1660 test_cipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1661 speed_template_8_32
);
1662 test_cipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
1663 speed_template_8_32
);
1664 test_cipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1665 speed_template_8_32
);
1666 test_cipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
1667 speed_template_8_32
);
1668 test_cipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1669 speed_template_8_32
);
1670 test_cipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
1671 speed_template_8_32
);
1675 test_cipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1677 test_cipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1679 test_cipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1681 test_cipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1686 test_cipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
1687 speed_template_16_24_32
);
1688 test_cipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
1689 speed_template_16_24_32
);
1690 test_cipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
1691 speed_template_16_24_32
);
1692 test_cipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
1693 speed_template_16_24_32
);
1694 test_cipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
1695 speed_template_16_24_32
);
1696 test_cipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
1697 speed_template_16_24_32
);
1698 test_cipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
1699 speed_template_32_40_48
);
1700 test_cipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
1701 speed_template_32_40_48
);
1702 test_cipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
1703 speed_template_32_48_64
);
1704 test_cipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
1705 speed_template_32_48_64
);
1709 test_cipher_speed("salsa20", ENCRYPT
, sec
, NULL
, 0,
1710 speed_template_16_32
);
1714 test_cipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
1715 speed_template_16_32
);
1716 test_cipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
1717 speed_template_16_32
);
1718 test_cipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
1719 speed_template_16_32
);
1720 test_cipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
1721 speed_template_16_32
);
1722 test_cipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
1723 speed_template_16_32
);
1724 test_cipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
1725 speed_template_16_32
);
1726 test_cipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
1727 speed_template_32_48
);
1728 test_cipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
1729 speed_template_32_48
);
1730 test_cipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
1731 speed_template_32_64
);
1732 test_cipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
1733 speed_template_32_64
);
1737 test_cipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
1742 test_cipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
1743 speed_template_8_16
);
1744 test_cipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
1745 speed_template_8_16
);
1746 test_cipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
1747 speed_template_8_16
);
1748 test_cipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
1749 speed_template_8_16
);
1750 test_cipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
1751 speed_template_8_16
);
1752 test_cipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
1753 speed_template_8_16
);
1757 test_cipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
1758 speed_template_16_32
);
1759 test_cipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
1760 speed_template_16_32
);
1761 test_cipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
1762 speed_template_16_32
);
1763 test_cipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
1764 speed_template_16_32
);
1765 test_cipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
1766 speed_template_16_32
);
1767 test_cipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
1768 speed_template_16_32
);
1769 test_cipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
1770 speed_template_32_48
);
1771 test_cipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
1772 speed_template_32_48
);
1773 test_cipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
1774 speed_template_32_64
);
1775 test_cipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
1776 speed_template_32_64
);
1780 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT
, sec
,
1781 NULL
, 0, 16, 16, aead_speed_template_20
);
1782 test_aead_speed("gcm(aes)", ENCRYPT
, sec
,
1783 NULL
, 0, 16, 8, aead_speed_template_20
);
1787 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT
, sec
,
1788 NULL
, 0, 16, 16, aead_speed_template_19
);
1792 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT
, sec
,
1793 NULL
, 0, 16, 8, aead_speed_template_36
);
1797 test_cipher_speed("chacha20", ENCRYPT
, sec
, NULL
, 0,
1804 test_hash_speed(alg
, sec
, generic_hash_speed_template
);
1811 test_hash_speed("md4", sec
, generic_hash_speed_template
);
1812 if (mode
> 300 && mode
< 400) break;
1815 test_hash_speed("md5", sec
, generic_hash_speed_template
);
1816 if (mode
> 300 && mode
< 400) break;
1819 test_hash_speed("sha1", sec
, generic_hash_speed_template
);
1820 if (mode
> 300 && mode
< 400) break;
1823 test_hash_speed("sha256", sec
, generic_hash_speed_template
);
1824 if (mode
> 300 && mode
< 400) break;
1827 test_hash_speed("sha384", sec
, generic_hash_speed_template
);
1828 if (mode
> 300 && mode
< 400) break;
1831 test_hash_speed("sha512", sec
, generic_hash_speed_template
);
1832 if (mode
> 300 && mode
< 400) break;
1835 test_hash_speed("wp256", sec
, generic_hash_speed_template
);
1836 if (mode
> 300 && mode
< 400) break;
1839 test_hash_speed("wp384", sec
, generic_hash_speed_template
);
1840 if (mode
> 300 && mode
< 400) break;
1843 test_hash_speed("wp512", sec
, generic_hash_speed_template
);
1844 if (mode
> 300 && mode
< 400) break;
1847 test_hash_speed("tgr128", sec
, generic_hash_speed_template
);
1848 if (mode
> 300 && mode
< 400) break;
1851 test_hash_speed("tgr160", sec
, generic_hash_speed_template
);
1852 if (mode
> 300 && mode
< 400) break;
1855 test_hash_speed("tgr192", sec
, generic_hash_speed_template
);
1856 if (mode
> 300 && mode
< 400) break;
1859 test_hash_speed("sha224", sec
, generic_hash_speed_template
);
1860 if (mode
> 300 && mode
< 400) break;
1863 test_hash_speed("rmd128", sec
, generic_hash_speed_template
);
1864 if (mode
> 300 && mode
< 400) break;
1867 test_hash_speed("rmd160", sec
, generic_hash_speed_template
);
1868 if (mode
> 300 && mode
< 400) break;
1871 test_hash_speed("rmd256", sec
, generic_hash_speed_template
);
1872 if (mode
> 300 && mode
< 400) break;
1875 test_hash_speed("rmd320", sec
, generic_hash_speed_template
);
1876 if (mode
> 300 && mode
< 400) break;
1879 test_hash_speed("ghash-generic", sec
, hash_speed_template_16
);
1880 if (mode
> 300 && mode
< 400) break;
1883 test_hash_speed("crc32c", sec
, generic_hash_speed_template
);
1884 if (mode
> 300 && mode
< 400) break;
1887 test_hash_speed("crct10dif", sec
, generic_hash_speed_template
);
1888 if (mode
> 300 && mode
< 400) break;
1891 test_hash_speed("poly1305", sec
, poly1305_speed_template
);
1892 if (mode
> 300 && mode
< 400) break;
1899 test_ahash_speed(alg
, sec
, generic_hash_speed_template
);
1906 test_ahash_speed("md4", sec
, generic_hash_speed_template
);
1907 if (mode
> 400 && mode
< 500) break;
1910 test_ahash_speed("md5", sec
, generic_hash_speed_template
);
1911 if (mode
> 400 && mode
< 500) break;
1914 test_ahash_speed("sha1", sec
, generic_hash_speed_template
);
1915 if (mode
> 400 && mode
< 500) break;
1918 test_ahash_speed("sha256", sec
, generic_hash_speed_template
);
1919 if (mode
> 400 && mode
< 500) break;
1922 test_ahash_speed("sha384", sec
, generic_hash_speed_template
);
1923 if (mode
> 400 && mode
< 500) break;
1926 test_ahash_speed("sha512", sec
, generic_hash_speed_template
);
1927 if (mode
> 400 && mode
< 500) break;
1930 test_ahash_speed("wp256", sec
, generic_hash_speed_template
);
1931 if (mode
> 400 && mode
< 500) break;
1934 test_ahash_speed("wp384", sec
, generic_hash_speed_template
);
1935 if (mode
> 400 && mode
< 500) break;
1938 test_ahash_speed("wp512", sec
, generic_hash_speed_template
);
1939 if (mode
> 400 && mode
< 500) break;
1942 test_ahash_speed("tgr128", sec
, generic_hash_speed_template
);
1943 if (mode
> 400 && mode
< 500) break;
1946 test_ahash_speed("tgr160", sec
, generic_hash_speed_template
);
1947 if (mode
> 400 && mode
< 500) break;
1950 test_ahash_speed("tgr192", sec
, generic_hash_speed_template
);
1951 if (mode
> 400 && mode
< 500) break;
1954 test_ahash_speed("sha224", sec
, generic_hash_speed_template
);
1955 if (mode
> 400 && mode
< 500) break;
1958 test_ahash_speed("rmd128", sec
, generic_hash_speed_template
);
1959 if (mode
> 400 && mode
< 500) break;
1962 test_ahash_speed("rmd160", sec
, generic_hash_speed_template
);
1963 if (mode
> 400 && mode
< 500) break;
1966 test_ahash_speed("rmd256", sec
, generic_hash_speed_template
);
1967 if (mode
> 400 && mode
< 500) break;
1970 test_ahash_speed("rmd320", sec
, generic_hash_speed_template
);
1971 if (mode
> 400 && mode
< 500) break;
1977 test_acipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1978 speed_template_16_24_32
);
1979 test_acipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1980 speed_template_16_24_32
);
1981 test_acipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1982 speed_template_16_24_32
);
1983 test_acipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1984 speed_template_16_24_32
);
1985 test_acipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1986 speed_template_32_40_48
);
1987 test_acipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1988 speed_template_32_40_48
);
1989 test_acipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1990 speed_template_32_48_64
);
1991 test_acipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1992 speed_template_32_48_64
);
1993 test_acipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
1994 speed_template_16_24_32
);
1995 test_acipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
1996 speed_template_16_24_32
);
1997 test_acipher_speed("cfb(aes)", ENCRYPT
, sec
, NULL
, 0,
1998 speed_template_16_24_32
);
1999 test_acipher_speed("cfb(aes)", DECRYPT
, sec
, NULL
, 0,
2000 speed_template_16_24_32
);
2001 test_acipher_speed("ofb(aes)", ENCRYPT
, sec
, NULL
, 0,
2002 speed_template_16_24_32
);
2003 test_acipher_speed("ofb(aes)", DECRYPT
, sec
, NULL
, 0,
2004 speed_template_16_24_32
);
2005 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT
, sec
, NULL
, 0,
2006 speed_template_20_28_36
);
2007 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT
, sec
, NULL
, 0,
2008 speed_template_20_28_36
);
2012 test_acipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
2013 des3_speed_template
, DES3_SPEED_VECTORS
,
2015 test_acipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
2016 des3_speed_template
, DES3_SPEED_VECTORS
,
2018 test_acipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
2019 des3_speed_template
, DES3_SPEED_VECTORS
,
2021 test_acipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
2022 des3_speed_template
, DES3_SPEED_VECTORS
,
2024 test_acipher_speed("cfb(des3_ede)", ENCRYPT
, sec
,
2025 des3_speed_template
, DES3_SPEED_VECTORS
,
2027 test_acipher_speed("cfb(des3_ede)", DECRYPT
, sec
,
2028 des3_speed_template
, DES3_SPEED_VECTORS
,
2030 test_acipher_speed("ofb(des3_ede)", ENCRYPT
, sec
,
2031 des3_speed_template
, DES3_SPEED_VECTORS
,
2033 test_acipher_speed("ofb(des3_ede)", DECRYPT
, sec
,
2034 des3_speed_template
, DES3_SPEED_VECTORS
,
2039 test_acipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
2041 test_acipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
2043 test_acipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
2045 test_acipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
2047 test_acipher_speed("cfb(des)", ENCRYPT
, sec
, NULL
, 0,
2049 test_acipher_speed("cfb(des)", DECRYPT
, sec
, NULL
, 0,
2051 test_acipher_speed("ofb(des)", ENCRYPT
, sec
, NULL
, 0,
2053 test_acipher_speed("ofb(des)", DECRYPT
, sec
, NULL
, 0,
2058 test_acipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
2059 speed_template_16_32
);
2060 test_acipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
2061 speed_template_16_32
);
2062 test_acipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
2063 speed_template_16_32
);
2064 test_acipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
2065 speed_template_16_32
);
2066 test_acipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
2067 speed_template_16_32
);
2068 test_acipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
2069 speed_template_16_32
);
2070 test_acipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
2071 speed_template_32_48
);
2072 test_acipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
2073 speed_template_32_48
);
2074 test_acipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
2075 speed_template_32_64
);
2076 test_acipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
2077 speed_template_32_64
);
2081 test_acipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
2082 speed_template_16_24_32
);
2083 test_acipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
2084 speed_template_16_24_32
);
2085 test_acipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
2086 speed_template_16_24_32
);
2087 test_acipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
2088 speed_template_16_24_32
);
2089 test_acipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
2090 speed_template_16_24_32
);
2091 test_acipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
2092 speed_template_16_24_32
);
2093 test_acipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
2094 speed_template_32_40_48
);
2095 test_acipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
2096 speed_template_32_40_48
);
2097 test_acipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
2098 speed_template_32_48_64
);
2099 test_acipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
2100 speed_template_32_48_64
);
2104 test_acipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
2109 test_acipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
2110 speed_template_8_16
);
2111 test_acipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
2112 speed_template_8_16
);
2113 test_acipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
2114 speed_template_8_16
);
2115 test_acipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
2116 speed_template_8_16
);
2117 test_acipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
2118 speed_template_8_16
);
2119 test_acipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
2120 speed_template_8_16
);
2124 test_acipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
2125 speed_template_16_32
);
2126 test_acipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
2127 speed_template_16_32
);
2128 test_acipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
2129 speed_template_16_32
);
2130 test_acipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
2131 speed_template_16_32
);
2132 test_acipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
2133 speed_template_16_32
);
2134 test_acipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
2135 speed_template_16_32
);
2136 test_acipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
2137 speed_template_32_48
);
2138 test_acipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
2139 speed_template_32_48
);
2140 test_acipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
2141 speed_template_32_64
);
2142 test_acipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
2143 speed_template_32_64
);
2147 test_acipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
2148 speed_template_16_32
);
2149 test_acipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
2150 speed_template_16_32
);
2151 test_acipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
2152 speed_template_16_32
);
2153 test_acipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
2154 speed_template_16_32
);
2155 test_acipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
2156 speed_template_16_32
);
2157 test_acipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
2158 speed_template_16_32
);
2159 test_acipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
2160 speed_template_32_48
);
2161 test_acipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
2162 speed_template_32_48
);
2163 test_acipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
2164 speed_template_32_64
);
2165 test_acipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
2166 speed_template_32_64
);
2170 test_acipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2171 speed_template_8_32
);
2172 test_acipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
2173 speed_template_8_32
);
2174 test_acipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2175 speed_template_8_32
);
2176 test_acipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
2177 speed_template_8_32
);
2178 test_acipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2179 speed_template_8_32
);
2180 test_acipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
2181 speed_template_8_32
);
2192 static int __init
tcrypt_mod_init(void)
2197 for (i
= 0; i
< TVMEMSIZE
; i
++) {
2198 tvmem
[i
] = (void *)__get_free_page(GFP_KERNEL
);
2203 err
= do_test(alg
, type
, mask
, mode
);
2206 printk(KERN_ERR
"tcrypt: one or more tests failed!\n");
2210 /* We intentionaly return -EAGAIN to prevent keeping the module,
2211 * unless we're running in fips mode. It does all its work from
2212 * init() and doesn't offer any runtime functionality, but in
2213 * the fips case, checking for a successful load is helpful.
2214 * => we don't need it in the memory, do we?
2221 for (i
= 0; i
< TVMEMSIZE
&& tvmem
[i
]; i
++)
2222 free_page((unsigned long)tvmem
[i
]);
2228 * If an init function is provided, an exit function must also be provided
2229 * to allow module unload.
2231 static void __exit
tcrypt_mod_fini(void) { }
2233 module_init(tcrypt_mod_init
);
2234 module_exit(tcrypt_mod_fini
);
2236 module_param(alg
, charp
, 0);
2237 module_param(type
, uint
, 0);
2238 module_param(mask
, uint
, 0);
2239 module_param(mode
, int, 0);
2240 module_param(sec
, uint
, 0);
2241 MODULE_PARM_DESC(sec
, "Length in seconds of speed tests "
2242 "(defaults to zero which uses CPU cycles instead)");
2244 MODULE_LICENSE("GPL");
2245 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2246 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");