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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27 #include <crypto/aead.h>
28 #include <crypto/hash.h>
29 #include <crypto/skcipher.h>
30 #include <linux/err.h>
31 #include <linux/fips.h>
32 #include <linux/init.h>
33 #include <linux/gfp.h>
34 #include <linux/module.h>
35 #include <linux/scatterlist.h>
36 #include <linux/string.h>
37 #include <linux/moduleparam.h>
38 #include <linux/jiffies.h>
39 #include <linux/timex.h>
40 #include <linux/interrupt.h>
44 * Need slab memory for testing (size in number of pages).
49 * Used by test_cipher_speed()
54 #define MAX_DIGEST_SIZE 64
57 * return a string with the driver name
59 #define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm))
62 * Used by test_cipher_speed()
64 static unsigned int sec
;
66 static char *alg
= NULL
;
70 static u32 num_mb
= 8;
71 static char *tvmem
[TVMEMSIZE
];
73 static char *check
[] = {
74 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", "sm3",
75 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
76 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
77 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
78 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
79 "lzo", "cts", "zlib", "sha3-224", "sha3-256", "sha3-384", "sha3-512",
83 static u32 block_sizes
[] = { 16, 64, 256, 1024, 8192, 0 };
84 static u32 aead_sizes
[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
89 static int testmgr_alloc_buf(char *buf
[XBUFSIZE
])
93 for (i
= 0; i
< XBUFSIZE
; i
++) {
94 buf
[i
] = (void *)__get_free_page(GFP_KERNEL
);
103 free_page((unsigned long)buf
[i
]);
108 static void testmgr_free_buf(char *buf
[XBUFSIZE
])
112 for (i
= 0; i
< XBUFSIZE
; i
++)
113 free_page((unsigned long)buf
[i
]);
116 static void sg_init_aead(struct scatterlist
*sg
, char *xbuf
[XBUFSIZE
],
117 unsigned int buflen
, const void *assoc
,
118 unsigned int aad_size
)
120 int np
= (buflen
+ PAGE_SIZE
- 1)/PAGE_SIZE
;
127 rem
= buflen
% PAGE_SIZE
;
130 sg_init_table(sg
, np
+ 1);
132 sg_set_buf(&sg
[0], assoc
, aad_size
);
136 for (k
= 0; k
< np
; k
++)
137 sg_set_buf(&sg
[k
+ 1], xbuf
[k
], PAGE_SIZE
);
140 sg_set_buf(&sg
[k
+ 1], xbuf
[k
], rem
);
143 static inline int do_one_aead_op(struct aead_request
*req
, int ret
)
145 struct crypto_wait
*wait
= req
->base
.data
;
147 return crypto_wait_req(ret
, wait
);
150 struct test_mb_aead_data
{
151 struct scatterlist sg
[XBUFSIZE
];
152 struct scatterlist sgout
[XBUFSIZE
];
153 struct aead_request
*req
;
154 struct crypto_wait wait
;
155 char *xbuf
[XBUFSIZE
];
156 char *xoutbuf
[XBUFSIZE
];
157 char *axbuf
[XBUFSIZE
];
160 static int do_mult_aead_op(struct test_mb_aead_data
*data
, int enc
,
165 /* Fire up a bunch of concurrent requests */
166 for (i
= 0; i
< num_mb
; i
++) {
168 rc
[i
] = crypto_aead_encrypt(data
[i
].req
);
170 rc
[i
] = crypto_aead_decrypt(data
[i
].req
);
173 /* Wait for all requests to finish */
174 for (i
= 0; i
< num_mb
; i
++) {
175 rc
[i
] = crypto_wait_req(rc
[i
], &data
[i
].wait
);
178 pr_info("concurrent request %d error %d\n", i
, rc
[i
]);
186 static int test_mb_aead_jiffies(struct test_mb_aead_data
*data
, int enc
,
187 int blen
, int secs
, u32 num_mb
)
189 unsigned long start
, end
;
194 rc
= kcalloc(num_mb
, sizeof(*rc
), GFP_KERNEL
);
198 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
199 time_before(jiffies
, end
); bcount
++) {
200 ret
= do_mult_aead_op(data
, enc
, num_mb
, rc
);
205 pr_cont("%d operations in %d seconds (%ld bytes)\n",
206 bcount
* num_mb
, secs
, (long)bcount
* blen
* num_mb
);
213 static int test_mb_aead_cycles(struct test_mb_aead_data
*data
, int enc
,
214 int blen
, u32 num_mb
)
216 unsigned long cycles
= 0;
221 rc
= kcalloc(num_mb
, sizeof(*rc
), GFP_KERNEL
);
226 for (i
= 0; i
< 4; i
++) {
227 ret
= do_mult_aead_op(data
, enc
, num_mb
, rc
);
232 /* The real thing. */
233 for (i
= 0; i
< 8; i
++) {
236 start
= get_cycles();
237 ret
= do_mult_aead_op(data
, enc
, num_mb
, rc
);
243 cycles
+= end
- start
;
246 pr_cont("1 operation in %lu cycles (%d bytes)\n",
247 (cycles
+ 4) / (8 * num_mb
), blen
);
254 static void test_mb_aead_speed(const char *algo
, int enc
, int secs
,
255 struct aead_speed_template
*template,
256 unsigned int tcount
, u8 authsize
,
257 unsigned int aad_size
, u8
*keysize
, u32 num_mb
)
259 struct test_mb_aead_data
*data
;
260 struct crypto_aead
*tfm
;
261 unsigned int i
, j
, iv_len
;
270 if (aad_size
>= PAGE_SIZE
) {
271 pr_err("associate data length (%u) too big\n", aad_size
);
275 iv
= kzalloc(MAX_IVLEN
, GFP_KERNEL
);
284 data
= kcalloc(num_mb
, sizeof(*data
), GFP_KERNEL
);
288 tfm
= crypto_alloc_aead(algo
, 0, 0);
290 pr_err("failed to load transform for %s: %ld\n",
295 ret
= crypto_aead_setauthsize(tfm
, authsize
);
297 for (i
= 0; i
< num_mb
; ++i
)
298 if (testmgr_alloc_buf(data
[i
].xbuf
)) {
300 testmgr_free_buf(data
[i
].xbuf
);
304 for (i
= 0; i
< num_mb
; ++i
)
305 if (testmgr_alloc_buf(data
[i
].axbuf
)) {
307 testmgr_free_buf(data
[i
].axbuf
);
311 for (i
= 0; i
< num_mb
; ++i
)
312 if (testmgr_alloc_buf(data
[i
].xoutbuf
)) {
314 testmgr_free_buf(data
[i
].xoutbuf
);
318 for (i
= 0; i
< num_mb
; ++i
) {
319 data
[i
].req
= aead_request_alloc(tfm
, GFP_KERNEL
);
321 pr_err("alg: skcipher: Failed to allocate request for %s\n",
324 aead_request_free(data
[i
].req
);
325 goto out_free_xoutbuf
;
329 for (i
= 0; i
< num_mb
; ++i
) {
330 crypto_init_wait(&data
[i
].wait
);
331 aead_request_set_callback(data
[i
].req
,
332 CRYPTO_TFM_REQ_MAY_BACKLOG
,
333 crypto_req_done
, &data
[i
].wait
);
336 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo
,
337 get_driver_name(crypto_aead
, tfm
), e
);
343 if (*b_size
+ authsize
> XBUFSIZE
* PAGE_SIZE
) {
344 pr_err("template (%u) too big for buffer (%lu)\n",
346 XBUFSIZE
* PAGE_SIZE
);
350 pr_info("test %u (%d bit key, %d byte blocks): ", i
,
351 *keysize
* 8, *b_size
);
353 /* Set up tfm global state, i.e. the key */
355 memset(tvmem
[0], 0xff, PAGE_SIZE
);
357 for (j
= 0; j
< tcount
; j
++) {
358 if (template[j
].klen
== *keysize
) {
359 key
= template[j
].key
;
364 crypto_aead_clear_flags(tfm
, ~0);
366 ret
= crypto_aead_setkey(tfm
, key
, *keysize
);
368 pr_err("setkey() failed flags=%x\n",
369 crypto_aead_get_flags(tfm
));
373 iv_len
= crypto_aead_ivsize(tfm
);
375 memset(iv
, 0xff, iv_len
);
377 /* Now setup per request stuff, i.e. buffers */
379 for (j
= 0; j
< num_mb
; ++j
) {
380 struct test_mb_aead_data
*cur
= &data
[j
];
382 assoc
= cur
->axbuf
[0];
383 memset(assoc
, 0xff, aad_size
);
385 sg_init_aead(cur
->sg
, cur
->xbuf
,
386 *b_size
+ (enc
? 0 : authsize
),
389 sg_init_aead(cur
->sgout
, cur
->xoutbuf
,
390 *b_size
+ (enc
? authsize
: 0),
393 aead_request_set_ad(cur
->req
, aad_size
);
397 aead_request_set_crypt(cur
->req
,
401 ret
= crypto_aead_encrypt(cur
->req
);
402 ret
= do_one_aead_op(cur
->req
, ret
);
405 pr_err("calculating auth failed failed (%d)\n",
411 aead_request_set_crypt(cur
->req
, cur
->sg
,
412 cur
->sgout
, *b_size
+
413 (enc
? 0 : authsize
),
419 ret
= test_mb_aead_jiffies(data
, enc
, *b_size
,
422 ret
= test_mb_aead_cycles(data
, enc
, *b_size
,
426 pr_err("%s() failed return code=%d\n", e
, ret
);
436 for (i
= 0; i
< num_mb
; ++i
)
437 aead_request_free(data
[i
].req
);
439 for (i
= 0; i
< num_mb
; ++i
)
440 testmgr_free_buf(data
[i
].xoutbuf
);
442 for (i
= 0; i
< num_mb
; ++i
)
443 testmgr_free_buf(data
[i
].axbuf
);
445 for (i
= 0; i
< num_mb
; ++i
)
446 testmgr_free_buf(data
[i
].xbuf
);
448 crypto_free_aead(tfm
);
455 static int test_aead_jiffies(struct aead_request
*req
, int enc
,
458 unsigned long start
, end
;
462 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
463 time_before(jiffies
, end
); bcount
++) {
465 ret
= do_one_aead_op(req
, crypto_aead_encrypt(req
));
467 ret
= do_one_aead_op(req
, crypto_aead_decrypt(req
));
473 printk("%d operations in %d seconds (%ld bytes)\n",
474 bcount
, secs
, (long)bcount
* blen
);
478 static int test_aead_cycles(struct aead_request
*req
, int enc
, int blen
)
480 unsigned long cycles
= 0;
485 for (i
= 0; i
< 4; i
++) {
487 ret
= do_one_aead_op(req
, crypto_aead_encrypt(req
));
489 ret
= do_one_aead_op(req
, crypto_aead_decrypt(req
));
495 /* The real thing. */
496 for (i
= 0; i
< 8; i
++) {
499 start
= get_cycles();
501 ret
= do_one_aead_op(req
, crypto_aead_encrypt(req
));
503 ret
= do_one_aead_op(req
, crypto_aead_decrypt(req
));
509 cycles
+= end
- start
;
514 printk("1 operation in %lu cycles (%d bytes)\n",
515 (cycles
+ 4) / 8, blen
);
520 static void test_aead_speed(const char *algo
, int enc
, unsigned int secs
,
521 struct aead_speed_template
*template,
522 unsigned int tcount
, u8 authsize
,
523 unsigned int aad_size
, u8
*keysize
)
526 struct crypto_aead
*tfm
;
529 struct aead_request
*req
;
530 struct scatterlist
*sg
;
531 struct scatterlist
*sgout
;
535 char *xbuf
[XBUFSIZE
];
536 char *xoutbuf
[XBUFSIZE
];
537 char *axbuf
[XBUFSIZE
];
538 unsigned int *b_size
;
540 struct crypto_wait wait
;
542 iv
= kzalloc(MAX_IVLEN
, GFP_KERNEL
);
546 if (aad_size
>= PAGE_SIZE
) {
547 pr_err("associate data length (%u) too big\n", aad_size
);
556 if (testmgr_alloc_buf(xbuf
))
558 if (testmgr_alloc_buf(axbuf
))
560 if (testmgr_alloc_buf(xoutbuf
))
563 sg
= kmalloc(sizeof(*sg
) * 9 * 2, GFP_KERNEL
);
568 tfm
= crypto_alloc_aead(algo
, 0, 0);
571 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo
,
576 crypto_init_wait(&wait
);
577 printk(KERN_INFO
"\ntesting speed of %s (%s) %s\n", algo
,
578 get_driver_name(crypto_aead
, tfm
), e
);
580 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
582 pr_err("alg: aead: Failed to allocate request for %s\n",
587 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
588 crypto_req_done
, &wait
);
595 memset(assoc
, 0xff, aad_size
);
597 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
598 pr_err("template (%u) too big for tvmem (%lu)\n",
600 TVMEMSIZE
* PAGE_SIZE
);
605 for (j
= 0; j
< tcount
; j
++) {
606 if (template[j
].klen
== *keysize
) {
607 key
= template[j
].key
;
611 ret
= crypto_aead_setkey(tfm
, key
, *keysize
);
612 ret
= crypto_aead_setauthsize(tfm
, authsize
);
614 iv_len
= crypto_aead_ivsize(tfm
);
616 memset(iv
, 0xff, iv_len
);
618 crypto_aead_clear_flags(tfm
, ~0);
619 printk(KERN_INFO
"test %u (%d bit key, %d byte blocks): ",
620 i
, *keysize
* 8, *b_size
);
623 memset(tvmem
[0], 0xff, PAGE_SIZE
);
626 pr_err("setkey() failed flags=%x\n",
627 crypto_aead_get_flags(tfm
));
631 sg_init_aead(sg
, xbuf
, *b_size
+ (enc
? 0 : authsize
),
634 sg_init_aead(sgout
, xoutbuf
,
635 *b_size
+ (enc
? authsize
: 0), assoc
,
638 aead_request_set_ad(req
, aad_size
);
643 * For decryption we need a proper auth so
644 * we do the encryption path once with buffers
645 * reversed (input <-> output) to calculate it
647 aead_request_set_crypt(req
, sgout
, sg
,
649 ret
= do_one_aead_op(req
,
650 crypto_aead_encrypt(req
));
653 pr_err("calculating auth failed failed (%d)\n",
659 aead_request_set_crypt(req
, sg
, sgout
,
660 *b_size
+ (enc
? 0 : authsize
),
664 ret
= test_aead_jiffies(req
, enc
, *b_size
,
667 ret
= test_aead_cycles(req
, enc
, *b_size
);
670 pr_err("%s() failed return code=%d\n", e
, ret
);
680 aead_request_free(req
);
682 crypto_free_aead(tfm
);
686 testmgr_free_buf(xoutbuf
);
688 testmgr_free_buf(axbuf
);
690 testmgr_free_buf(xbuf
);
695 static void test_hash_sg_init(struct scatterlist
*sg
)
699 sg_init_table(sg
, TVMEMSIZE
);
700 for (i
= 0; i
< TVMEMSIZE
; i
++) {
701 sg_set_buf(sg
+ i
, tvmem
[i
], PAGE_SIZE
);
702 memset(tvmem
[i
], 0xff, PAGE_SIZE
);
706 static inline int do_one_ahash_op(struct ahash_request
*req
, int ret
)
708 struct crypto_wait
*wait
= req
->base
.data
;
710 return crypto_wait_req(ret
, wait
);
713 struct test_mb_ahash_data
{
714 struct scatterlist sg
[XBUFSIZE
];
716 struct ahash_request
*req
;
717 struct crypto_wait wait
;
718 char *xbuf
[XBUFSIZE
];
721 static inline int do_mult_ahash_op(struct test_mb_ahash_data
*data
, u32 num_mb
,
726 /* Fire up a bunch of concurrent requests */
727 for (i
= 0; i
< num_mb
; i
++)
728 rc
[i
] = crypto_ahash_digest(data
[i
].req
);
730 /* Wait for all requests to finish */
731 for (i
= 0; i
< num_mb
; i
++) {
732 rc
[i
] = crypto_wait_req(rc
[i
], &data
[i
].wait
);
735 pr_info("concurrent request %d error %d\n", i
, rc
[i
]);
743 static int test_mb_ahash_jiffies(struct test_mb_ahash_data
*data
, int blen
,
744 int secs
, u32 num_mb
)
746 unsigned long start
, end
;
751 rc
= kcalloc(num_mb
, sizeof(*rc
), GFP_KERNEL
);
755 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
756 time_before(jiffies
, end
); bcount
++) {
757 ret
= do_mult_ahash_op(data
, num_mb
, rc
);
762 pr_cont("%d operations in %d seconds (%ld bytes)\n",
763 bcount
* num_mb
, secs
, (long)bcount
* blen
* num_mb
);
770 static int test_mb_ahash_cycles(struct test_mb_ahash_data
*data
, int blen
,
773 unsigned long cycles
= 0;
778 rc
= kcalloc(num_mb
, sizeof(*rc
), GFP_KERNEL
);
783 for (i
= 0; i
< 4; i
++) {
784 ret
= do_mult_ahash_op(data
, num_mb
, rc
);
789 /* The real thing. */
790 for (i
= 0; i
< 8; i
++) {
793 start
= get_cycles();
794 ret
= do_mult_ahash_op(data
, num_mb
, rc
);
800 cycles
+= end
- start
;
803 pr_cont("1 operation in %lu cycles (%d bytes)\n",
804 (cycles
+ 4) / (8 * num_mb
), blen
);
811 static void test_mb_ahash_speed(const char *algo
, unsigned int secs
,
812 struct hash_speed
*speed
, u32 num_mb
)
814 struct test_mb_ahash_data
*data
;
815 struct crypto_ahash
*tfm
;
816 unsigned int i
, j
, k
;
819 data
= kcalloc(num_mb
, sizeof(*data
), GFP_KERNEL
);
823 tfm
= crypto_alloc_ahash(algo
, 0, 0);
825 pr_err("failed to load transform for %s: %ld\n",
830 for (i
= 0; i
< num_mb
; ++i
) {
831 if (testmgr_alloc_buf(data
[i
].xbuf
))
834 crypto_init_wait(&data
[i
].wait
);
836 data
[i
].req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
838 pr_err("alg: hash: Failed to allocate request for %s\n",
843 ahash_request_set_callback(data
[i
].req
, 0, crypto_req_done
,
846 sg_init_table(data
[i
].sg
, XBUFSIZE
);
847 for (j
= 0; j
< XBUFSIZE
; j
++) {
848 sg_set_buf(data
[i
].sg
+ j
, data
[i
].xbuf
[j
], PAGE_SIZE
);
849 memset(data
[i
].xbuf
[j
], 0xff, PAGE_SIZE
);
853 pr_info("\ntesting speed of multibuffer %s (%s)\n", algo
,
854 get_driver_name(crypto_ahash
, tfm
));
856 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
857 /* For some reason this only tests digests. */
858 if (speed
[i
].blen
!= speed
[i
].plen
)
861 if (speed
[i
].blen
> XBUFSIZE
* PAGE_SIZE
) {
862 pr_err("template (%u) too big for tvmem (%lu)\n",
863 speed
[i
].blen
, XBUFSIZE
* PAGE_SIZE
);
868 crypto_ahash_setkey(tfm
, tvmem
[0], speed
[i
].klen
);
870 for (k
= 0; k
< num_mb
; k
++)
871 ahash_request_set_crypt(data
[k
].req
, data
[k
].sg
,
872 data
[k
].result
, speed
[i
].blen
);
875 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
876 i
, speed
[i
].blen
, speed
[i
].plen
,
877 speed
[i
].blen
/ speed
[i
].plen
);
880 ret
= test_mb_ahash_jiffies(data
, speed
[i
].blen
, secs
,
883 ret
= test_mb_ahash_cycles(data
, speed
[i
].blen
, num_mb
);
887 pr_err("At least one hashing failed ret=%d\n", ret
);
893 for (k
= 0; k
< num_mb
; ++k
)
894 ahash_request_free(data
[k
].req
);
896 for (k
= 0; k
< num_mb
; ++k
)
897 testmgr_free_buf(data
[k
].xbuf
);
899 crypto_free_ahash(tfm
);
905 static int test_ahash_jiffies_digest(struct ahash_request
*req
, int blen
,
908 unsigned long start
, end
;
912 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
913 time_before(jiffies
, end
); bcount
++) {
914 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
919 printk("%6u opers/sec, %9lu bytes/sec\n",
920 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
925 static int test_ahash_jiffies(struct ahash_request
*req
, int blen
,
926 int plen
, char *out
, int secs
)
928 unsigned long start
, end
;
933 return test_ahash_jiffies_digest(req
, blen
, out
, secs
);
935 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
936 time_before(jiffies
, end
); bcount
++) {
937 ret
= do_one_ahash_op(req
, crypto_ahash_init(req
));
940 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
941 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
945 /* we assume there is enough space in 'out' for the result */
946 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
951 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
952 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
957 static int test_ahash_cycles_digest(struct ahash_request
*req
, int blen
,
960 unsigned long cycles
= 0;
964 for (i
= 0; i
< 4; i
++) {
965 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
970 /* The real thing. */
971 for (i
= 0; i
< 8; i
++) {
974 start
= get_cycles();
976 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
982 cycles
+= end
- start
;
989 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
990 cycles
/ 8, cycles
/ (8 * blen
));
995 static int test_ahash_cycles(struct ahash_request
*req
, int blen
,
998 unsigned long cycles
= 0;
1002 return test_ahash_cycles_digest(req
, blen
, out
);
1005 for (i
= 0; i
< 4; i
++) {
1006 ret
= do_one_ahash_op(req
, crypto_ahash_init(req
));
1009 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
1010 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
1014 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
1019 /* The real thing. */
1020 for (i
= 0; i
< 8; i
++) {
1021 cycles_t start
, end
;
1023 start
= get_cycles();
1025 ret
= do_one_ahash_op(req
, crypto_ahash_init(req
));
1028 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
1029 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
1033 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
1039 cycles
+= end
- start
;
1046 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
1047 cycles
/ 8, cycles
/ (8 * blen
));
1052 static void test_ahash_speed_common(const char *algo
, unsigned int secs
,
1053 struct hash_speed
*speed
, unsigned mask
)
1055 struct scatterlist sg
[TVMEMSIZE
];
1056 struct crypto_wait wait
;
1057 struct ahash_request
*req
;
1058 struct crypto_ahash
*tfm
;
1062 tfm
= crypto_alloc_ahash(algo
, 0, mask
);
1064 pr_err("failed to load transform for %s: %ld\n",
1065 algo
, PTR_ERR(tfm
));
1069 printk(KERN_INFO
"\ntesting speed of async %s (%s)\n", algo
,
1070 get_driver_name(crypto_ahash
, tfm
));
1072 if (crypto_ahash_digestsize(tfm
) > MAX_DIGEST_SIZE
) {
1073 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm
),
1078 test_hash_sg_init(sg
);
1079 req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
1081 pr_err("ahash request allocation failure\n");
1085 crypto_init_wait(&wait
);
1086 ahash_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
1087 crypto_req_done
, &wait
);
1089 output
= kmalloc(MAX_DIGEST_SIZE
, GFP_KERNEL
);
1093 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
1094 if (speed
[i
].blen
> TVMEMSIZE
* PAGE_SIZE
) {
1095 pr_err("template (%u) too big for tvmem (%lu)\n",
1096 speed
[i
].blen
, TVMEMSIZE
* PAGE_SIZE
);
1101 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
1102 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
1104 ahash_request_set_crypt(req
, sg
, output
, speed
[i
].plen
);
1107 ret
= test_ahash_jiffies(req
, speed
[i
].blen
,
1108 speed
[i
].plen
, output
, secs
);
1110 ret
= test_ahash_cycles(req
, speed
[i
].blen
,
1111 speed
[i
].plen
, output
);
1114 pr_err("hashing failed ret=%d\n", ret
);
1122 ahash_request_free(req
);
1125 crypto_free_ahash(tfm
);
1128 static void test_ahash_speed(const char *algo
, unsigned int secs
,
1129 struct hash_speed
*speed
)
1131 return test_ahash_speed_common(algo
, secs
, speed
, 0);
1134 static void test_hash_speed(const char *algo
, unsigned int secs
,
1135 struct hash_speed
*speed
)
1137 return test_ahash_speed_common(algo
, secs
, speed
, CRYPTO_ALG_ASYNC
);
1140 struct test_mb_skcipher_data
{
1141 struct scatterlist sg
[XBUFSIZE
];
1142 struct skcipher_request
*req
;
1143 struct crypto_wait wait
;
1144 char *xbuf
[XBUFSIZE
];
1147 static int do_mult_acipher_op(struct test_mb_skcipher_data
*data
, int enc
,
1148 u32 num_mb
, int *rc
)
1152 /* Fire up a bunch of concurrent requests */
1153 for (i
= 0; i
< num_mb
; i
++) {
1155 rc
[i
] = crypto_skcipher_encrypt(data
[i
].req
);
1157 rc
[i
] = crypto_skcipher_decrypt(data
[i
].req
);
1160 /* Wait for all requests to finish */
1161 for (i
= 0; i
< num_mb
; i
++) {
1162 rc
[i
] = crypto_wait_req(rc
[i
], &data
[i
].wait
);
1165 pr_info("concurrent request %d error %d\n", i
, rc
[i
]);
1173 static int test_mb_acipher_jiffies(struct test_mb_skcipher_data
*data
, int enc
,
1174 int blen
, int secs
, u32 num_mb
)
1176 unsigned long start
, end
;
1181 rc
= kcalloc(num_mb
, sizeof(*rc
), GFP_KERNEL
);
1185 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
1186 time_before(jiffies
, end
); bcount
++) {
1187 ret
= do_mult_acipher_op(data
, enc
, num_mb
, rc
);
1192 pr_cont("%d operations in %d seconds (%ld bytes)\n",
1193 bcount
* num_mb
, secs
, (long)bcount
* blen
* num_mb
);
1200 static int test_mb_acipher_cycles(struct test_mb_skcipher_data
*data
, int enc
,
1201 int blen
, u32 num_mb
)
1203 unsigned long cycles
= 0;
1208 rc
= kcalloc(num_mb
, sizeof(*rc
), GFP_KERNEL
);
1213 for (i
= 0; i
< 4; i
++) {
1214 ret
= do_mult_acipher_op(data
, enc
, num_mb
, rc
);
1219 /* The real thing. */
1220 for (i
= 0; i
< 8; i
++) {
1221 cycles_t start
, end
;
1223 start
= get_cycles();
1224 ret
= do_mult_acipher_op(data
, enc
, num_mb
, rc
);
1230 cycles
+= end
- start
;
1233 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1234 (cycles
+ 4) / (8 * num_mb
), blen
);
1241 static void test_mb_skcipher_speed(const char *algo
, int enc
, int secs
,
1242 struct cipher_speed_template
*template,
1243 unsigned int tcount
, u8
*keysize
, u32 num_mb
)
1245 struct test_mb_skcipher_data
*data
;
1246 struct crypto_skcipher
*tfm
;
1247 unsigned int i
, j
, iv_len
;
1259 data
= kcalloc(num_mb
, sizeof(*data
), GFP_KERNEL
);
1263 tfm
= crypto_alloc_skcipher(algo
, 0, 0);
1265 pr_err("failed to load transform for %s: %ld\n",
1266 algo
, PTR_ERR(tfm
));
1270 for (i
= 0; i
< num_mb
; ++i
)
1271 if (testmgr_alloc_buf(data
[i
].xbuf
)) {
1273 testmgr_free_buf(data
[i
].xbuf
);
1278 for (i
= 0; i
< num_mb
; ++i
)
1279 if (testmgr_alloc_buf(data
[i
].xbuf
)) {
1281 testmgr_free_buf(data
[i
].xbuf
);
1286 for (i
= 0; i
< num_mb
; ++i
) {
1287 data
[i
].req
= skcipher_request_alloc(tfm
, GFP_KERNEL
);
1289 pr_err("alg: skcipher: Failed to allocate request for %s\n",
1292 skcipher_request_free(data
[i
].req
);
1297 for (i
= 0; i
< num_mb
; ++i
) {
1298 skcipher_request_set_callback(data
[i
].req
,
1299 CRYPTO_TFM_REQ_MAY_BACKLOG
,
1300 crypto_req_done
, &data
[i
].wait
);
1301 crypto_init_wait(&data
[i
].wait
);
1304 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo
,
1305 get_driver_name(crypto_skcipher
, tfm
), e
);
1309 b_size
= block_sizes
;
1311 if (*b_size
> XBUFSIZE
* PAGE_SIZE
) {
1312 pr_err("template (%u) too big for buffer (%lu)\n",
1313 *b_size
, XBUFSIZE
* PAGE_SIZE
);
1317 pr_info("test %u (%d bit key, %d byte blocks): ", i
,
1318 *keysize
* 8, *b_size
);
1320 /* Set up tfm global state, i.e. the key */
1322 memset(tvmem
[0], 0xff, PAGE_SIZE
);
1324 for (j
= 0; j
< tcount
; j
++) {
1325 if (template[j
].klen
== *keysize
) {
1326 key
= template[j
].key
;
1331 crypto_skcipher_clear_flags(tfm
, ~0);
1333 ret
= crypto_skcipher_setkey(tfm
, key
, *keysize
);
1335 pr_err("setkey() failed flags=%x\n",
1336 crypto_skcipher_get_flags(tfm
));
1340 iv_len
= crypto_skcipher_ivsize(tfm
);
1342 memset(&iv
, 0xff, iv_len
);
1344 /* Now setup per request stuff, i.e. buffers */
1346 for (j
= 0; j
< num_mb
; ++j
) {
1347 struct test_mb_skcipher_data
*cur
= &data
[j
];
1348 unsigned int k
= *b_size
;
1349 unsigned int pages
= DIV_ROUND_UP(k
, PAGE_SIZE
);
1352 sg_init_table(cur
->sg
, pages
);
1354 while (k
> PAGE_SIZE
) {
1355 sg_set_buf(cur
->sg
+ p
, cur
->xbuf
[p
],
1357 memset(cur
->xbuf
[p
], 0xff, PAGE_SIZE
);
1362 sg_set_buf(cur
->sg
+ p
, cur
->xbuf
[p
], k
);
1363 memset(cur
->xbuf
[p
], 0xff, k
);
1365 skcipher_request_set_crypt(cur
->req
, cur
->sg
,
1371 ret
= test_mb_acipher_jiffies(data
, enc
,
1375 ret
= test_mb_acipher_cycles(data
, enc
,
1379 pr_err("%s() failed flags=%x\n", e
,
1380 crypto_skcipher_get_flags(tfm
));
1390 for (i
= 0; i
< num_mb
; ++i
)
1391 skcipher_request_free(data
[i
].req
);
1393 for (i
= 0; i
< num_mb
; ++i
)
1394 testmgr_free_buf(data
[i
].xbuf
);
1396 crypto_free_skcipher(tfm
);
1401 static inline int do_one_acipher_op(struct skcipher_request
*req
, int ret
)
1403 struct crypto_wait
*wait
= req
->base
.data
;
1405 return crypto_wait_req(ret
, wait
);
1408 static int test_acipher_jiffies(struct skcipher_request
*req
, int enc
,
1411 unsigned long start
, end
;
1415 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
1416 time_before(jiffies
, end
); bcount
++) {
1418 ret
= do_one_acipher_op(req
,
1419 crypto_skcipher_encrypt(req
));
1421 ret
= do_one_acipher_op(req
,
1422 crypto_skcipher_decrypt(req
));
1428 pr_cont("%d operations in %d seconds (%ld bytes)\n",
1429 bcount
, secs
, (long)bcount
* blen
);
1433 static int test_acipher_cycles(struct skcipher_request
*req
, int enc
,
1436 unsigned long cycles
= 0;
1441 for (i
= 0; i
< 4; i
++) {
1443 ret
= do_one_acipher_op(req
,
1444 crypto_skcipher_encrypt(req
));
1446 ret
= do_one_acipher_op(req
,
1447 crypto_skcipher_decrypt(req
));
1453 /* The real thing. */
1454 for (i
= 0; i
< 8; i
++) {
1455 cycles_t start
, end
;
1457 start
= get_cycles();
1459 ret
= do_one_acipher_op(req
,
1460 crypto_skcipher_encrypt(req
));
1462 ret
= do_one_acipher_op(req
,
1463 crypto_skcipher_decrypt(req
));
1469 cycles
+= end
- start
;
1474 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1475 (cycles
+ 4) / 8, blen
);
1480 static void test_skcipher_speed(const char *algo
, int enc
, unsigned int secs
,
1481 struct cipher_speed_template
*template,
1482 unsigned int tcount
, u8
*keysize
, bool async
)
1484 unsigned int ret
, i
, j
, k
, iv_len
;
1485 struct crypto_wait wait
;
1488 struct skcipher_request
*req
;
1489 struct crypto_skcipher
*tfm
;
1498 crypto_init_wait(&wait
);
1500 tfm
= crypto_alloc_skcipher(algo
, 0, async
? 0 : CRYPTO_ALG_ASYNC
);
1503 pr_err("failed to load transform for %s: %ld\n", algo
,
1508 pr_info("\ntesting speed of async %s (%s) %s\n", algo
,
1509 get_driver_name(crypto_skcipher
, tfm
), e
);
1511 req
= skcipher_request_alloc(tfm
, GFP_KERNEL
);
1513 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1518 skcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
1519 crypto_req_done
, &wait
);
1523 b_size
= block_sizes
;
1526 struct scatterlist sg
[TVMEMSIZE
];
1528 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
1529 pr_err("template (%u) too big for "
1530 "tvmem (%lu)\n", *keysize
+ *b_size
,
1531 TVMEMSIZE
* PAGE_SIZE
);
1535 pr_info("test %u (%d bit key, %d byte blocks): ", i
,
1536 *keysize
* 8, *b_size
);
1538 memset(tvmem
[0], 0xff, PAGE_SIZE
);
1540 /* set key, plain text and IV */
1542 for (j
= 0; j
< tcount
; j
++) {
1543 if (template[j
].klen
== *keysize
) {
1544 key
= template[j
].key
;
1549 crypto_skcipher_clear_flags(tfm
, ~0);
1551 ret
= crypto_skcipher_setkey(tfm
, key
, *keysize
);
1553 pr_err("setkey() failed flags=%x\n",
1554 crypto_skcipher_get_flags(tfm
));
1558 k
= *keysize
+ *b_size
;
1559 sg_init_table(sg
, DIV_ROUND_UP(k
, PAGE_SIZE
));
1561 if (k
> PAGE_SIZE
) {
1562 sg_set_buf(sg
, tvmem
[0] + *keysize
,
1563 PAGE_SIZE
- *keysize
);
1566 while (k
> PAGE_SIZE
) {
1567 sg_set_buf(sg
+ j
, tvmem
[j
], PAGE_SIZE
);
1568 memset(tvmem
[j
], 0xff, PAGE_SIZE
);
1572 sg_set_buf(sg
+ j
, tvmem
[j
], k
);
1573 memset(tvmem
[j
], 0xff, k
);
1575 sg_set_buf(sg
, tvmem
[0] + *keysize
, *b_size
);
1578 iv_len
= crypto_skcipher_ivsize(tfm
);
1580 memset(&iv
, 0xff, iv_len
);
1582 skcipher_request_set_crypt(req
, sg
, sg
, *b_size
, iv
);
1585 ret
= test_acipher_jiffies(req
, enc
,
1588 ret
= test_acipher_cycles(req
, enc
,
1592 pr_err("%s() failed flags=%x\n", e
,
1593 crypto_skcipher_get_flags(tfm
));
1603 skcipher_request_free(req
);
1605 crypto_free_skcipher(tfm
);
1608 static void test_acipher_speed(const char *algo
, int enc
, unsigned int secs
,
1609 struct cipher_speed_template
*template,
1610 unsigned int tcount
, u8
*keysize
)
1612 return test_skcipher_speed(algo
, enc
, secs
, template, tcount
, keysize
,
1616 static void test_cipher_speed(const char *algo
, int enc
, unsigned int secs
,
1617 struct cipher_speed_template
*template,
1618 unsigned int tcount
, u8
*keysize
)
1620 return test_skcipher_speed(algo
, enc
, secs
, template, tcount
, keysize
,
1624 static void test_available(void)
1626 char **name
= check
;
1629 printk("alg %s ", *name
);
1630 printk(crypto_has_alg(*name
, 0, 0) ?
1631 "found\n" : "not found\n");
1636 static inline int tcrypt_test(const char *alg
)
1640 pr_debug("testing %s\n", alg
);
1642 ret
= alg_test(alg
, alg
, 0, 0);
1643 /* non-fips algs return -EINVAL in fips mode */
1644 if (fips_enabled
&& ret
== -EINVAL
)
1649 static int do_test(const char *alg
, u32 type
, u32 mask
, int m
, u32 num_mb
)
1657 if (!crypto_has_alg(alg
, type
,
1658 mask
?: CRYPTO_ALG_TYPE_MASK
))
1663 for (i
= 1; i
< 200; i
++)
1664 ret
+= do_test(NULL
, 0, 0, i
, num_mb
);
1668 ret
+= tcrypt_test("md5");
1672 ret
+= tcrypt_test("sha1");
1676 ret
+= tcrypt_test("ecb(des)");
1677 ret
+= tcrypt_test("cbc(des)");
1678 ret
+= tcrypt_test("ctr(des)");
1682 ret
+= tcrypt_test("ecb(des3_ede)");
1683 ret
+= tcrypt_test("cbc(des3_ede)");
1684 ret
+= tcrypt_test("ctr(des3_ede)");
1688 ret
+= tcrypt_test("md4");
1692 ret
+= tcrypt_test("sha256");
1696 ret
+= tcrypt_test("ecb(blowfish)");
1697 ret
+= tcrypt_test("cbc(blowfish)");
1698 ret
+= tcrypt_test("ctr(blowfish)");
1702 ret
+= tcrypt_test("ecb(twofish)");
1703 ret
+= tcrypt_test("cbc(twofish)");
1704 ret
+= tcrypt_test("ctr(twofish)");
1705 ret
+= tcrypt_test("lrw(twofish)");
1706 ret
+= tcrypt_test("xts(twofish)");
1710 ret
+= tcrypt_test("ecb(serpent)");
1711 ret
+= tcrypt_test("cbc(serpent)");
1712 ret
+= tcrypt_test("ctr(serpent)");
1713 ret
+= tcrypt_test("lrw(serpent)");
1714 ret
+= tcrypt_test("xts(serpent)");
1718 ret
+= tcrypt_test("ecb(aes)");
1719 ret
+= tcrypt_test("cbc(aes)");
1720 ret
+= tcrypt_test("lrw(aes)");
1721 ret
+= tcrypt_test("xts(aes)");
1722 ret
+= tcrypt_test("ctr(aes)");
1723 ret
+= tcrypt_test("rfc3686(ctr(aes))");
1727 ret
+= tcrypt_test("sha384");
1731 ret
+= tcrypt_test("sha512");
1735 ret
+= tcrypt_test("deflate");
1739 ret
+= tcrypt_test("ecb(cast5)");
1740 ret
+= tcrypt_test("cbc(cast5)");
1741 ret
+= tcrypt_test("ctr(cast5)");
1745 ret
+= tcrypt_test("ecb(cast6)");
1746 ret
+= tcrypt_test("cbc(cast6)");
1747 ret
+= tcrypt_test("ctr(cast6)");
1748 ret
+= tcrypt_test("lrw(cast6)");
1749 ret
+= tcrypt_test("xts(cast6)");
1753 ret
+= tcrypt_test("ecb(arc4)");
1757 ret
+= tcrypt_test("michael_mic");
1761 ret
+= tcrypt_test("crc32c");
1765 ret
+= tcrypt_test("ecb(tea)");
1769 ret
+= tcrypt_test("ecb(xtea)");
1773 ret
+= tcrypt_test("ecb(khazad)");
1777 ret
+= tcrypt_test("wp512");
1781 ret
+= tcrypt_test("wp384");
1785 ret
+= tcrypt_test("wp256");
1789 ret
+= tcrypt_test("ecb(tnepres)");
1793 ret
+= tcrypt_test("ecb(anubis)");
1794 ret
+= tcrypt_test("cbc(anubis)");
1798 ret
+= tcrypt_test("tgr192");
1802 ret
+= tcrypt_test("tgr160");
1806 ret
+= tcrypt_test("tgr128");
1810 ret
+= tcrypt_test("ecb(xeta)");
1814 ret
+= tcrypt_test("pcbc(fcrypt)");
1818 ret
+= tcrypt_test("ecb(camellia)");
1819 ret
+= tcrypt_test("cbc(camellia)");
1820 ret
+= tcrypt_test("ctr(camellia)");
1821 ret
+= tcrypt_test("lrw(camellia)");
1822 ret
+= tcrypt_test("xts(camellia)");
1826 ret
+= tcrypt_test("sha224");
1830 ret
+= tcrypt_test("salsa20");
1834 ret
+= tcrypt_test("gcm(aes)");
1838 ret
+= tcrypt_test("lzo");
1842 ret
+= tcrypt_test("ccm(aes)");
1846 ret
+= tcrypt_test("cts(cbc(aes))");
1850 ret
+= tcrypt_test("rmd128");
1854 ret
+= tcrypt_test("rmd160");
1858 ret
+= tcrypt_test("rmd256");
1862 ret
+= tcrypt_test("rmd320");
1866 ret
+= tcrypt_test("ecb(seed)");
1870 ret
+= tcrypt_test("zlib");
1874 ret
+= tcrypt_test("rfc4309(ccm(aes))");
1878 ret
+= tcrypt_test("ghash");
1882 ret
+= tcrypt_test("crct10dif");
1886 ret
+= tcrypt_test("sha3-224");
1890 ret
+= tcrypt_test("sha3-256");
1894 ret
+= tcrypt_test("sha3-384");
1898 ret
+= tcrypt_test("sha3-512");
1902 ret
+= tcrypt_test("sm3");
1906 ret
+= tcrypt_test("hmac(md5)");
1910 ret
+= tcrypt_test("hmac(sha1)");
1914 ret
+= tcrypt_test("hmac(sha256)");
1918 ret
+= tcrypt_test("hmac(sha384)");
1922 ret
+= tcrypt_test("hmac(sha512)");
1926 ret
+= tcrypt_test("hmac(sha224)");
1930 ret
+= tcrypt_test("xcbc(aes)");
1934 ret
+= tcrypt_test("hmac(rmd128)");
1938 ret
+= tcrypt_test("hmac(rmd160)");
1942 ret
+= tcrypt_test("vmac(aes)");
1946 ret
+= tcrypt_test("hmac(sha3-224)");
1950 ret
+= tcrypt_test("hmac(sha3-256)");
1954 ret
+= tcrypt_test("hmac(sha3-384)");
1958 ret
+= tcrypt_test("hmac(sha3-512)");
1962 ret
+= tcrypt_test("ansi_cprng");
1966 ret
+= tcrypt_test("rfc4106(gcm(aes))");
1970 ret
+= tcrypt_test("rfc4543(gcm(aes))");
1974 ret
+= tcrypt_test("cmac(aes)");
1978 ret
+= tcrypt_test("cmac(des3_ede)");
1982 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1986 ret
+= tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1990 ret
+= tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1993 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(des))");
1996 ret
+= tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
1999 ret
+= tcrypt_test("authenc(hmac(sha224),cbc(des))");
2002 ret
+= tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
2005 ret
+= tcrypt_test("authenc(hmac(sha256),cbc(des))");
2008 ret
+= tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
2011 ret
+= tcrypt_test("authenc(hmac(sha384),cbc(des))");
2014 ret
+= tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
2017 ret
+= tcrypt_test("authenc(hmac(sha512),cbc(des))");
2020 ret
+= tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
2023 ret
+= tcrypt_test("ecb(sm4)");
2026 test_cipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
2027 speed_template_16_24_32
);
2028 test_cipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
2029 speed_template_16_24_32
);
2030 test_cipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
2031 speed_template_16_24_32
);
2032 test_cipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
2033 speed_template_16_24_32
);
2034 test_cipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
2035 speed_template_32_40_48
);
2036 test_cipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
2037 speed_template_32_40_48
);
2038 test_cipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
2039 speed_template_32_64
);
2040 test_cipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
2041 speed_template_32_64
);
2042 test_cipher_speed("cts(cbc(aes))", ENCRYPT
, sec
, NULL
, 0,
2043 speed_template_16_24_32
);
2044 test_cipher_speed("cts(cbc(aes))", DECRYPT
, sec
, NULL
, 0,
2045 speed_template_16_24_32
);
2046 test_cipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
2047 speed_template_16_24_32
);
2048 test_cipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
2049 speed_template_16_24_32
);
2053 test_cipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
2054 des3_speed_template
, DES3_SPEED_VECTORS
,
2056 test_cipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
2057 des3_speed_template
, DES3_SPEED_VECTORS
,
2059 test_cipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
2060 des3_speed_template
, DES3_SPEED_VECTORS
,
2062 test_cipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
2063 des3_speed_template
, DES3_SPEED_VECTORS
,
2065 test_cipher_speed("ctr(des3_ede)", ENCRYPT
, sec
,
2066 des3_speed_template
, DES3_SPEED_VECTORS
,
2068 test_cipher_speed("ctr(des3_ede)", DECRYPT
, sec
,
2069 des3_speed_template
, DES3_SPEED_VECTORS
,
2074 test_cipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
2075 speed_template_16_24_32
);
2076 test_cipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
2077 speed_template_16_24_32
);
2078 test_cipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
2079 speed_template_16_24_32
);
2080 test_cipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
2081 speed_template_16_24_32
);
2082 test_cipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
2083 speed_template_16_24_32
);
2084 test_cipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
2085 speed_template_16_24_32
);
2086 test_cipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
2087 speed_template_32_40_48
);
2088 test_cipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
2089 speed_template_32_40_48
);
2090 test_cipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
2091 speed_template_32_48_64
);
2092 test_cipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
2093 speed_template_32_48_64
);
2097 test_cipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2098 speed_template_8_32
);
2099 test_cipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
2100 speed_template_8_32
);
2101 test_cipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2102 speed_template_8_32
);
2103 test_cipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
2104 speed_template_8_32
);
2105 test_cipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2106 speed_template_8_32
);
2107 test_cipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
2108 speed_template_8_32
);
2112 test_cipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
2114 test_cipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
2116 test_cipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
2118 test_cipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
2123 test_cipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
2124 speed_template_16_24_32
);
2125 test_cipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
2126 speed_template_16_24_32
);
2127 test_cipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
2128 speed_template_16_24_32
);
2129 test_cipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
2130 speed_template_16_24_32
);
2131 test_cipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
2132 speed_template_16_24_32
);
2133 test_cipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
2134 speed_template_16_24_32
);
2135 test_cipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
2136 speed_template_32_40_48
);
2137 test_cipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
2138 speed_template_32_40_48
);
2139 test_cipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
2140 speed_template_32_48_64
);
2141 test_cipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
2142 speed_template_32_48_64
);
2146 test_cipher_speed("salsa20", ENCRYPT
, sec
, NULL
, 0,
2147 speed_template_16_32
);
2151 test_cipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
2152 speed_template_16_32
);
2153 test_cipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
2154 speed_template_16_32
);
2155 test_cipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
2156 speed_template_16_32
);
2157 test_cipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
2158 speed_template_16_32
);
2159 test_cipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
2160 speed_template_16_32
);
2161 test_cipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
2162 speed_template_16_32
);
2163 test_cipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
2164 speed_template_32_48
);
2165 test_cipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
2166 speed_template_32_48
);
2167 test_cipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
2168 speed_template_32_64
);
2169 test_cipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
2170 speed_template_32_64
);
2174 test_cipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
2179 test_cipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
2180 speed_template_8_16
);
2181 test_cipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
2182 speed_template_8_16
);
2183 test_cipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
2184 speed_template_8_16
);
2185 test_cipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
2186 speed_template_8_16
);
2187 test_cipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
2188 speed_template_8_16
);
2189 test_cipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
2190 speed_template_8_16
);
2194 test_cipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
2195 speed_template_16_32
);
2196 test_cipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
2197 speed_template_16_32
);
2198 test_cipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
2199 speed_template_16_32
);
2200 test_cipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
2201 speed_template_16_32
);
2202 test_cipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
2203 speed_template_16_32
);
2204 test_cipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
2205 speed_template_16_32
);
2206 test_cipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
2207 speed_template_32_48
);
2208 test_cipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
2209 speed_template_32_48
);
2210 test_cipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
2211 speed_template_32_64
);
2212 test_cipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
2213 speed_template_32_64
);
2217 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT
, sec
,
2218 NULL
, 0, 16, 16, aead_speed_template_20
);
2219 test_aead_speed("gcm(aes)", ENCRYPT
, sec
,
2220 NULL
, 0, 16, 8, speed_template_16_24_32
);
2221 test_aead_speed("rfc4106(gcm(aes))", DECRYPT
, sec
,
2222 NULL
, 0, 16, 16, aead_speed_template_20
);
2223 test_aead_speed("gcm(aes)", DECRYPT
, sec
,
2224 NULL
, 0, 16, 8, speed_template_16_24_32
);
2228 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT
, sec
,
2229 NULL
, 0, 16, 16, aead_speed_template_19
);
2230 test_aead_speed("rfc4309(ccm(aes))", DECRYPT
, sec
,
2231 NULL
, 0, 16, 16, aead_speed_template_19
);
2235 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT
, sec
,
2236 NULL
, 0, 16, 8, aead_speed_template_36
);
2237 test_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT
, sec
,
2238 NULL
, 0, 16, 8, aead_speed_template_36
);
2242 test_cipher_speed("chacha20", ENCRYPT
, sec
, NULL
, 0,
2247 test_mb_aead_speed("rfc4106(gcm(aes))", ENCRYPT
, sec
, NULL
,
2248 0, 16, 16, aead_speed_template_20
, num_mb
);
2249 test_mb_aead_speed("gcm(aes)", ENCRYPT
, sec
, NULL
, 0, 16, 8,
2250 speed_template_16_24_32
, num_mb
);
2251 test_mb_aead_speed("rfc4106(gcm(aes))", DECRYPT
, sec
, NULL
,
2252 0, 16, 16, aead_speed_template_20
, num_mb
);
2253 test_mb_aead_speed("gcm(aes)", DECRYPT
, sec
, NULL
, 0, 16, 8,
2254 speed_template_16_24_32
, num_mb
);
2258 test_mb_aead_speed("rfc4309(ccm(aes))", ENCRYPT
, sec
, NULL
, 0,
2259 16, 16, aead_speed_template_19
, num_mb
);
2260 test_mb_aead_speed("rfc4309(ccm(aes))", DECRYPT
, sec
, NULL
, 0,
2261 16, 16, aead_speed_template_19
, num_mb
);
2265 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT
,
2266 sec
, NULL
, 0, 16, 8, aead_speed_template_36
,
2268 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT
,
2269 sec
, NULL
, 0, 16, 8, aead_speed_template_36
,
2275 test_hash_speed(alg
, sec
, generic_hash_speed_template
);
2280 test_hash_speed("md4", sec
, generic_hash_speed_template
);
2281 if (mode
> 300 && mode
< 400) break;
2284 test_hash_speed("md5", sec
, generic_hash_speed_template
);
2285 if (mode
> 300 && mode
< 400) break;
2288 test_hash_speed("sha1", sec
, generic_hash_speed_template
);
2289 if (mode
> 300 && mode
< 400) break;
2292 test_hash_speed("sha256", sec
, generic_hash_speed_template
);
2293 if (mode
> 300 && mode
< 400) break;
2296 test_hash_speed("sha384", sec
, generic_hash_speed_template
);
2297 if (mode
> 300 && mode
< 400) break;
2300 test_hash_speed("sha512", sec
, generic_hash_speed_template
);
2301 if (mode
> 300 && mode
< 400) break;
2304 test_hash_speed("wp256", sec
, generic_hash_speed_template
);
2305 if (mode
> 300 && mode
< 400) break;
2308 test_hash_speed("wp384", sec
, generic_hash_speed_template
);
2309 if (mode
> 300 && mode
< 400) break;
2312 test_hash_speed("wp512", sec
, generic_hash_speed_template
);
2313 if (mode
> 300 && mode
< 400) break;
2316 test_hash_speed("tgr128", sec
, generic_hash_speed_template
);
2317 if (mode
> 300 && mode
< 400) break;
2320 test_hash_speed("tgr160", sec
, generic_hash_speed_template
);
2321 if (mode
> 300 && mode
< 400) break;
2324 test_hash_speed("tgr192", sec
, generic_hash_speed_template
);
2325 if (mode
> 300 && mode
< 400) break;
2328 test_hash_speed("sha224", sec
, generic_hash_speed_template
);
2329 if (mode
> 300 && mode
< 400) break;
2332 test_hash_speed("rmd128", sec
, generic_hash_speed_template
);
2333 if (mode
> 300 && mode
< 400) break;
2336 test_hash_speed("rmd160", sec
, generic_hash_speed_template
);
2337 if (mode
> 300 && mode
< 400) break;
2340 test_hash_speed("rmd256", sec
, generic_hash_speed_template
);
2341 if (mode
> 300 && mode
< 400) break;
2344 test_hash_speed("rmd320", sec
, generic_hash_speed_template
);
2345 if (mode
> 300 && mode
< 400) break;
2348 test_hash_speed("ghash-generic", sec
, hash_speed_template_16
);
2349 if (mode
> 300 && mode
< 400) break;
2352 test_hash_speed("crc32c", sec
, generic_hash_speed_template
);
2353 if (mode
> 300 && mode
< 400) break;
2356 test_hash_speed("crct10dif", sec
, generic_hash_speed_template
);
2357 if (mode
> 300 && mode
< 400) break;
2360 test_hash_speed("poly1305", sec
, poly1305_speed_template
);
2361 if (mode
> 300 && mode
< 400) break;
2364 test_hash_speed("sha3-224", sec
, generic_hash_speed_template
);
2365 if (mode
> 300 && mode
< 400) break;
2368 test_hash_speed("sha3-256", sec
, generic_hash_speed_template
);
2369 if (mode
> 300 && mode
< 400) break;
2372 test_hash_speed("sha3-384", sec
, generic_hash_speed_template
);
2373 if (mode
> 300 && mode
< 400) break;
2376 test_hash_speed("sha3-512", sec
, generic_hash_speed_template
);
2377 if (mode
> 300 && mode
< 400) break;
2380 test_hash_speed("sm3", sec
, generic_hash_speed_template
);
2381 if (mode
> 300 && mode
< 400) break;
2388 test_ahash_speed(alg
, sec
, generic_hash_speed_template
);
2393 test_ahash_speed("md4", sec
, generic_hash_speed_template
);
2394 if (mode
> 400 && mode
< 500) break;
2397 test_ahash_speed("md5", sec
, generic_hash_speed_template
);
2398 if (mode
> 400 && mode
< 500) break;
2401 test_ahash_speed("sha1", sec
, generic_hash_speed_template
);
2402 if (mode
> 400 && mode
< 500) break;
2405 test_ahash_speed("sha256", sec
, generic_hash_speed_template
);
2406 if (mode
> 400 && mode
< 500) break;
2409 test_ahash_speed("sha384", sec
, generic_hash_speed_template
);
2410 if (mode
> 400 && mode
< 500) break;
2413 test_ahash_speed("sha512", sec
, generic_hash_speed_template
);
2414 if (mode
> 400 && mode
< 500) break;
2417 test_ahash_speed("wp256", sec
, generic_hash_speed_template
);
2418 if (mode
> 400 && mode
< 500) break;
2421 test_ahash_speed("wp384", sec
, generic_hash_speed_template
);
2422 if (mode
> 400 && mode
< 500) break;
2425 test_ahash_speed("wp512", sec
, generic_hash_speed_template
);
2426 if (mode
> 400 && mode
< 500) break;
2429 test_ahash_speed("tgr128", sec
, generic_hash_speed_template
);
2430 if (mode
> 400 && mode
< 500) break;
2433 test_ahash_speed("tgr160", sec
, generic_hash_speed_template
);
2434 if (mode
> 400 && mode
< 500) break;
2437 test_ahash_speed("tgr192", sec
, generic_hash_speed_template
);
2438 if (mode
> 400 && mode
< 500) break;
2441 test_ahash_speed("sha224", sec
, generic_hash_speed_template
);
2442 if (mode
> 400 && mode
< 500) break;
2445 test_ahash_speed("rmd128", sec
, generic_hash_speed_template
);
2446 if (mode
> 400 && mode
< 500) break;
2449 test_ahash_speed("rmd160", sec
, generic_hash_speed_template
);
2450 if (mode
> 400 && mode
< 500) break;
2453 test_ahash_speed("rmd256", sec
, generic_hash_speed_template
);
2454 if (mode
> 400 && mode
< 500) break;
2457 test_ahash_speed("rmd320", sec
, generic_hash_speed_template
);
2458 if (mode
> 400 && mode
< 500) break;
2461 test_ahash_speed("sha3-224", sec
, generic_hash_speed_template
);
2462 if (mode
> 400 && mode
< 500) break;
2465 test_ahash_speed("sha3-256", sec
, generic_hash_speed_template
);
2466 if (mode
> 400 && mode
< 500) break;
2469 test_ahash_speed("sha3-384", sec
, generic_hash_speed_template
);
2470 if (mode
> 400 && mode
< 500) break;
2473 test_ahash_speed("sha3-512", sec
, generic_hash_speed_template
);
2474 if (mode
> 400 && mode
< 500) break;
2477 test_mb_ahash_speed("sha1", sec
, generic_hash_speed_template
,
2479 if (mode
> 400 && mode
< 500) break;
2482 test_mb_ahash_speed("sha256", sec
, generic_hash_speed_template
,
2484 if (mode
> 400 && mode
< 500) break;
2487 test_mb_ahash_speed("sha512", sec
, generic_hash_speed_template
,
2489 if (mode
> 400 && mode
< 500) break;
2492 test_mb_ahash_speed("sm3", sec
, generic_hash_speed_template
,
2494 if (mode
> 400 && mode
< 500) break;
2500 test_acipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
2501 speed_template_16_24_32
);
2502 test_acipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
2503 speed_template_16_24_32
);
2504 test_acipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
2505 speed_template_16_24_32
);
2506 test_acipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
2507 speed_template_16_24_32
);
2508 test_acipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
2509 speed_template_32_40_48
);
2510 test_acipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
2511 speed_template_32_40_48
);
2512 test_acipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
2513 speed_template_32_64
);
2514 test_acipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
2515 speed_template_32_64
);
2516 test_acipher_speed("cts(cbc(aes))", ENCRYPT
, sec
, NULL
, 0,
2517 speed_template_16_24_32
);
2518 test_acipher_speed("cts(cbc(aes))", DECRYPT
, sec
, NULL
, 0,
2519 speed_template_16_24_32
);
2520 test_acipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
2521 speed_template_16_24_32
);
2522 test_acipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
2523 speed_template_16_24_32
);
2524 test_acipher_speed("cfb(aes)", ENCRYPT
, sec
, NULL
, 0,
2525 speed_template_16_24_32
);
2526 test_acipher_speed("cfb(aes)", DECRYPT
, sec
, NULL
, 0,
2527 speed_template_16_24_32
);
2528 test_acipher_speed("ofb(aes)", ENCRYPT
, sec
, NULL
, 0,
2529 speed_template_16_24_32
);
2530 test_acipher_speed("ofb(aes)", DECRYPT
, sec
, NULL
, 0,
2531 speed_template_16_24_32
);
2532 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT
, sec
, NULL
, 0,
2533 speed_template_20_28_36
);
2534 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT
, sec
, NULL
, 0,
2535 speed_template_20_28_36
);
2539 test_acipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
2540 des3_speed_template
, DES3_SPEED_VECTORS
,
2542 test_acipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
2543 des3_speed_template
, DES3_SPEED_VECTORS
,
2545 test_acipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
2546 des3_speed_template
, DES3_SPEED_VECTORS
,
2548 test_acipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
2549 des3_speed_template
, DES3_SPEED_VECTORS
,
2551 test_acipher_speed("cfb(des3_ede)", ENCRYPT
, sec
,
2552 des3_speed_template
, DES3_SPEED_VECTORS
,
2554 test_acipher_speed("cfb(des3_ede)", DECRYPT
, sec
,
2555 des3_speed_template
, DES3_SPEED_VECTORS
,
2557 test_acipher_speed("ofb(des3_ede)", ENCRYPT
, sec
,
2558 des3_speed_template
, DES3_SPEED_VECTORS
,
2560 test_acipher_speed("ofb(des3_ede)", DECRYPT
, sec
,
2561 des3_speed_template
, DES3_SPEED_VECTORS
,
2566 test_acipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
2568 test_acipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
2570 test_acipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
2572 test_acipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
2574 test_acipher_speed("cfb(des)", ENCRYPT
, sec
, NULL
, 0,
2576 test_acipher_speed("cfb(des)", DECRYPT
, sec
, NULL
, 0,
2578 test_acipher_speed("ofb(des)", ENCRYPT
, sec
, NULL
, 0,
2580 test_acipher_speed("ofb(des)", DECRYPT
, sec
, NULL
, 0,
2585 test_acipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
2586 speed_template_16_32
);
2587 test_acipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
2588 speed_template_16_32
);
2589 test_acipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
2590 speed_template_16_32
);
2591 test_acipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
2592 speed_template_16_32
);
2593 test_acipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
2594 speed_template_16_32
);
2595 test_acipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
2596 speed_template_16_32
);
2597 test_acipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
2598 speed_template_32_48
);
2599 test_acipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
2600 speed_template_32_48
);
2601 test_acipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
2602 speed_template_32_64
);
2603 test_acipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
2604 speed_template_32_64
);
2608 test_acipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
2609 speed_template_16_24_32
);
2610 test_acipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
2611 speed_template_16_24_32
);
2612 test_acipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
2613 speed_template_16_24_32
);
2614 test_acipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
2615 speed_template_16_24_32
);
2616 test_acipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
2617 speed_template_16_24_32
);
2618 test_acipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
2619 speed_template_16_24_32
);
2620 test_acipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
2621 speed_template_32_40_48
);
2622 test_acipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
2623 speed_template_32_40_48
);
2624 test_acipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
2625 speed_template_32_48_64
);
2626 test_acipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
2627 speed_template_32_48_64
);
2631 test_acipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
2636 test_acipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
2637 speed_template_8_16
);
2638 test_acipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
2639 speed_template_8_16
);
2640 test_acipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
2641 speed_template_8_16
);
2642 test_acipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
2643 speed_template_8_16
);
2644 test_acipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
2645 speed_template_8_16
);
2646 test_acipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
2647 speed_template_8_16
);
2651 test_acipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
2652 speed_template_16_32
);
2653 test_acipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
2654 speed_template_16_32
);
2655 test_acipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
2656 speed_template_16_32
);
2657 test_acipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
2658 speed_template_16_32
);
2659 test_acipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
2660 speed_template_16_32
);
2661 test_acipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
2662 speed_template_16_32
);
2663 test_acipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
2664 speed_template_32_48
);
2665 test_acipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
2666 speed_template_32_48
);
2667 test_acipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
2668 speed_template_32_64
);
2669 test_acipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
2670 speed_template_32_64
);
2674 test_acipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
2675 speed_template_16_32
);
2676 test_acipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
2677 speed_template_16_32
);
2678 test_acipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
2679 speed_template_16_32
);
2680 test_acipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
2681 speed_template_16_32
);
2682 test_acipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
2683 speed_template_16_32
);
2684 test_acipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
2685 speed_template_16_32
);
2686 test_acipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
2687 speed_template_32_48
);
2688 test_acipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
2689 speed_template_32_48
);
2690 test_acipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
2691 speed_template_32_64
);
2692 test_acipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
2693 speed_template_32_64
);
2697 test_acipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2698 speed_template_8_32
);
2699 test_acipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
2700 speed_template_8_32
);
2701 test_acipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2702 speed_template_8_32
);
2703 test_acipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
2704 speed_template_8_32
);
2705 test_acipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2706 speed_template_8_32
);
2707 test_acipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
2708 speed_template_8_32
);
2712 test_mb_skcipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
2713 speed_template_16_24_32
, num_mb
);
2714 test_mb_skcipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
2715 speed_template_16_24_32
, num_mb
);
2716 test_mb_skcipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
2717 speed_template_16_24_32
, num_mb
);
2718 test_mb_skcipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
2719 speed_template_16_24_32
, num_mb
);
2720 test_mb_skcipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
2721 speed_template_32_40_48
, num_mb
);
2722 test_mb_skcipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
2723 speed_template_32_40_48
, num_mb
);
2724 test_mb_skcipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
2725 speed_template_32_64
, num_mb
);
2726 test_mb_skcipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
2727 speed_template_32_64
, num_mb
);
2728 test_mb_skcipher_speed("cts(cbc(aes))", ENCRYPT
, sec
, NULL
, 0,
2729 speed_template_16_24_32
, num_mb
);
2730 test_mb_skcipher_speed("cts(cbc(aes))", DECRYPT
, sec
, NULL
, 0,
2731 speed_template_16_24_32
, num_mb
);
2732 test_mb_skcipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
2733 speed_template_16_24_32
, num_mb
);
2734 test_mb_skcipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
2735 speed_template_16_24_32
, num_mb
);
2736 test_mb_skcipher_speed("cfb(aes)", ENCRYPT
, sec
, NULL
, 0,
2737 speed_template_16_24_32
, num_mb
);
2738 test_mb_skcipher_speed("cfb(aes)", DECRYPT
, sec
, NULL
, 0,
2739 speed_template_16_24_32
, num_mb
);
2740 test_mb_skcipher_speed("ofb(aes)", ENCRYPT
, sec
, NULL
, 0,
2741 speed_template_16_24_32
, num_mb
);
2742 test_mb_skcipher_speed("ofb(aes)", DECRYPT
, sec
, NULL
, 0,
2743 speed_template_16_24_32
, num_mb
);
2744 test_mb_skcipher_speed("rfc3686(ctr(aes))", ENCRYPT
, sec
, NULL
,
2745 0, speed_template_20_28_36
, num_mb
);
2746 test_mb_skcipher_speed("rfc3686(ctr(aes))", DECRYPT
, sec
, NULL
,
2747 0, speed_template_20_28_36
, num_mb
);
2751 test_mb_skcipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
2752 des3_speed_template
, DES3_SPEED_VECTORS
,
2753 speed_template_24
, num_mb
);
2754 test_mb_skcipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
2755 des3_speed_template
, DES3_SPEED_VECTORS
,
2756 speed_template_24
, num_mb
);
2757 test_mb_skcipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
2758 des3_speed_template
, DES3_SPEED_VECTORS
,
2759 speed_template_24
, num_mb
);
2760 test_mb_skcipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
2761 des3_speed_template
, DES3_SPEED_VECTORS
,
2762 speed_template_24
, num_mb
);
2763 test_mb_skcipher_speed("cfb(des3_ede)", ENCRYPT
, sec
,
2764 des3_speed_template
, DES3_SPEED_VECTORS
,
2765 speed_template_24
, num_mb
);
2766 test_mb_skcipher_speed("cfb(des3_ede)", DECRYPT
, sec
,
2767 des3_speed_template
, DES3_SPEED_VECTORS
,
2768 speed_template_24
, num_mb
);
2769 test_mb_skcipher_speed("ofb(des3_ede)", ENCRYPT
, sec
,
2770 des3_speed_template
, DES3_SPEED_VECTORS
,
2771 speed_template_24
, num_mb
);
2772 test_mb_skcipher_speed("ofb(des3_ede)", DECRYPT
, sec
,
2773 des3_speed_template
, DES3_SPEED_VECTORS
,
2774 speed_template_24
, num_mb
);
2778 test_mb_skcipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
2779 speed_template_8
, num_mb
);
2780 test_mb_skcipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
2781 speed_template_8
, num_mb
);
2782 test_mb_skcipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
2783 speed_template_8
, num_mb
);
2784 test_mb_skcipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
2785 speed_template_8
, num_mb
);
2786 test_mb_skcipher_speed("cfb(des)", ENCRYPT
, sec
, NULL
, 0,
2787 speed_template_8
, num_mb
);
2788 test_mb_skcipher_speed("cfb(des)", DECRYPT
, sec
, NULL
, 0,
2789 speed_template_8
, num_mb
);
2790 test_mb_skcipher_speed("ofb(des)", ENCRYPT
, sec
, NULL
, 0,
2791 speed_template_8
, num_mb
);
2792 test_mb_skcipher_speed("ofb(des)", DECRYPT
, sec
, NULL
, 0,
2793 speed_template_8
, num_mb
);
2797 test_mb_skcipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
2798 speed_template_16_32
, num_mb
);
2799 test_mb_skcipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
2800 speed_template_16_32
, num_mb
);
2801 test_mb_skcipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
2802 speed_template_16_32
, num_mb
);
2803 test_mb_skcipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
2804 speed_template_16_32
, num_mb
);
2805 test_mb_skcipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
2806 speed_template_16_32
, num_mb
);
2807 test_mb_skcipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
2808 speed_template_16_32
, num_mb
);
2809 test_mb_skcipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
2810 speed_template_32_48
, num_mb
);
2811 test_mb_skcipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
2812 speed_template_32_48
, num_mb
);
2813 test_mb_skcipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
2814 speed_template_32_64
, num_mb
);
2815 test_mb_skcipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
2816 speed_template_32_64
, num_mb
);
2820 test_mb_skcipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
2821 speed_template_16_24_32
, num_mb
);
2822 test_mb_skcipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
2823 speed_template_16_24_32
, num_mb
);
2824 test_mb_skcipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
2825 speed_template_16_24_32
, num_mb
);
2826 test_mb_skcipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
2827 speed_template_16_24_32
, num_mb
);
2828 test_mb_skcipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
2829 speed_template_16_24_32
, num_mb
);
2830 test_mb_skcipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
2831 speed_template_16_24_32
, num_mb
);
2832 test_mb_skcipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
2833 speed_template_32_40_48
, num_mb
);
2834 test_mb_skcipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
2835 speed_template_32_40_48
, num_mb
);
2836 test_mb_skcipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
2837 speed_template_32_48_64
, num_mb
);
2838 test_mb_skcipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
2839 speed_template_32_48_64
, num_mb
);
2843 test_mb_skcipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
2844 speed_template_8
, num_mb
);
2848 test_mb_skcipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
2849 speed_template_8_16
, num_mb
);
2850 test_mb_skcipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
2851 speed_template_8_16
, num_mb
);
2852 test_mb_skcipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
2853 speed_template_8_16
, num_mb
);
2854 test_mb_skcipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
2855 speed_template_8_16
, num_mb
);
2856 test_mb_skcipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
2857 speed_template_8_16
, num_mb
);
2858 test_mb_skcipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
2859 speed_template_8_16
, num_mb
);
2863 test_mb_skcipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
2864 speed_template_16_32
, num_mb
);
2865 test_mb_skcipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
2866 speed_template_16_32
, num_mb
);
2867 test_mb_skcipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
2868 speed_template_16_32
, num_mb
);
2869 test_mb_skcipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
2870 speed_template_16_32
, num_mb
);
2871 test_mb_skcipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
2872 speed_template_16_32
, num_mb
);
2873 test_mb_skcipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
2874 speed_template_16_32
, num_mb
);
2875 test_mb_skcipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
2876 speed_template_32_48
, num_mb
);
2877 test_mb_skcipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
2878 speed_template_32_48
, num_mb
);
2879 test_mb_skcipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
2880 speed_template_32_64
, num_mb
);
2881 test_mb_skcipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
2882 speed_template_32_64
, num_mb
);
2886 test_mb_skcipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
2887 speed_template_16_32
, num_mb
);
2888 test_mb_skcipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
2889 speed_template_16_32
, num_mb
);
2890 test_mb_skcipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
2891 speed_template_16_32
, num_mb
);
2892 test_mb_skcipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
2893 speed_template_16_32
, num_mb
);
2894 test_mb_skcipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
2895 speed_template_16_32
, num_mb
);
2896 test_mb_skcipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
2897 speed_template_16_32
, num_mb
);
2898 test_mb_skcipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
2899 speed_template_32_48
, num_mb
);
2900 test_mb_skcipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
2901 speed_template_32_48
, num_mb
);
2902 test_mb_skcipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
2903 speed_template_32_64
, num_mb
);
2904 test_mb_skcipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
2905 speed_template_32_64
, num_mb
);
2909 test_mb_skcipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2910 speed_template_8_32
, num_mb
);
2911 test_mb_skcipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
2912 speed_template_8_32
, num_mb
);
2913 test_mb_skcipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2914 speed_template_8_32
, num_mb
);
2915 test_mb_skcipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
2916 speed_template_8_32
, num_mb
);
2917 test_mb_skcipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2918 speed_template_8_32
, num_mb
);
2919 test_mb_skcipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
2920 speed_template_8_32
, num_mb
);
2931 static int __init
tcrypt_mod_init(void)
2936 for (i
= 0; i
< TVMEMSIZE
; i
++) {
2937 tvmem
[i
] = (void *)__get_free_page(GFP_KERNEL
);
2942 err
= do_test(alg
, type
, mask
, mode
, num_mb
);
2945 printk(KERN_ERR
"tcrypt: one or more tests failed!\n");
2948 pr_debug("all tests passed\n");
2951 /* We intentionaly return -EAGAIN to prevent keeping the module,
2952 * unless we're running in fips mode. It does all its work from
2953 * init() and doesn't offer any runtime functionality, but in
2954 * the fips case, checking for a successful load is helpful.
2955 * => we don't need it in the memory, do we?
2962 for (i
= 0; i
< TVMEMSIZE
&& tvmem
[i
]; i
++)
2963 free_page((unsigned long)tvmem
[i
]);
2969 * If an init function is provided, an exit function must also be provided
2970 * to allow module unload.
2972 static void __exit
tcrypt_mod_fini(void) { }
2974 module_init(tcrypt_mod_init
);
2975 module_exit(tcrypt_mod_fini
);
2977 module_param(alg
, charp
, 0);
2978 module_param(type
, uint
, 0);
2979 module_param(mask
, uint
, 0);
2980 module_param(mode
, int, 0);
2981 module_param(sec
, uint
, 0);
2982 MODULE_PARM_DESC(sec
, "Length in seconds of speed tests "
2983 "(defaults to zero which uses CPU cycles instead)");
2984 module_param(num_mb
, uint
, 0000);
2985 MODULE_PARM_DESC(num_mb
, "Number of concurrent requests to be used in mb speed tests (defaults to 8)");
2987 MODULE_LICENSE("GPL");
2988 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2989 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");