1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Quick & dirty crypto testing module.
5 * This will only exist until we have a better testing mechanism
6 * (e.g. a char device).
8 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
9 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
10 * Copyright (c) 2007 Nokia Siemens Networks
12 * Updated RFC4106 AES-GCM testing.
13 * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
14 * Adrian Hoban <adrian.hoban@intel.com>
15 * Gabriele Paoloni <gabriele.paoloni@intel.com>
16 * Tadeusz Struk (tadeusz.struk@intel.com)
17 * Copyright (c) 2010, Intel Corporation.
20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22 #include <crypto/aead.h>
23 #include <crypto/hash.h>
24 #include <crypto/skcipher.h>
25 #include <linux/err.h>
26 #include <linux/fips.h>
27 #include <linux/init.h>
28 #include <linux/interrupt.h>
29 #include <linux/jiffies.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/moduleparam.h>
33 #include <linux/scatterlist.h>
34 #include <linux/slab.h>
35 #include <linux/string.h>
36 #include <linux/timex.h>
42 * Need slab memory for testing (size in number of pages).
47 * Used by test_cipher_speed()
52 #define MAX_DIGEST_SIZE 64
55 * return a string with the driver name
57 #define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm))
60 * Used by test_cipher_speed()
62 static unsigned int sec
;
68 static u32 num_mb
= 8;
69 static unsigned int klen
;
70 static char *tvmem
[TVMEMSIZE
];
72 static const int block_sizes
[] = { 16, 64, 128, 256, 1024, 1420, 4096, 0 };
73 static const int aead_sizes
[] = { 16, 64, 256, 512, 1024, 1420, 4096, 8192, 0 };
78 static int testmgr_alloc_buf(char *buf
[XBUFSIZE
])
82 for (i
= 0; i
< XBUFSIZE
; i
++) {
83 buf
[i
] = (void *)__get_free_page(GFP_KERNEL
);
92 free_page((unsigned long)buf
[i
]);
97 static void testmgr_free_buf(char *buf
[XBUFSIZE
])
101 for (i
= 0; i
< XBUFSIZE
; i
++)
102 free_page((unsigned long)buf
[i
]);
105 static void sg_init_aead(struct scatterlist
*sg
, char *xbuf
[XBUFSIZE
],
106 unsigned int buflen
, const void *assoc
,
107 unsigned int aad_size
)
109 int np
= (buflen
+ PAGE_SIZE
- 1)/PAGE_SIZE
;
116 rem
= buflen
% PAGE_SIZE
;
119 sg_init_table(sg
, np
+ 1);
121 sg_set_buf(&sg
[0], assoc
, aad_size
);
125 for (k
= 0; k
< np
; k
++)
126 sg_set_buf(&sg
[k
+ 1], xbuf
[k
], PAGE_SIZE
);
129 sg_set_buf(&sg
[k
+ 1], xbuf
[k
], rem
);
132 static inline int do_one_aead_op(struct aead_request
*req
, int ret
)
134 struct crypto_wait
*wait
= req
->base
.data
;
136 return crypto_wait_req(ret
, wait
);
139 struct test_mb_aead_data
{
140 struct scatterlist sg
[XBUFSIZE
];
141 struct scatterlist sgout
[XBUFSIZE
];
142 struct aead_request
*req
;
143 struct crypto_wait wait
;
144 char *xbuf
[XBUFSIZE
];
145 char *xoutbuf
[XBUFSIZE
];
146 char *axbuf
[XBUFSIZE
];
149 static int do_mult_aead_op(struct test_mb_aead_data
*data
, int enc
,
154 /* Fire up a bunch of concurrent requests */
155 for (i
= 0; i
< num_mb
; i
++) {
157 rc
[i
] = crypto_aead_encrypt(data
[i
].req
);
159 rc
[i
] = crypto_aead_decrypt(data
[i
].req
);
162 /* Wait for all requests to finish */
163 for (i
= 0; i
< num_mb
; i
++) {
164 rc
[i
] = crypto_wait_req(rc
[i
], &data
[i
].wait
);
167 pr_info("concurrent request %d error %d\n", i
, rc
[i
]);
175 static int test_mb_aead_jiffies(struct test_mb_aead_data
*data
, int enc
,
176 int blen
, int secs
, u32 num_mb
)
178 unsigned long start
, end
;
183 rc
= kcalloc(num_mb
, sizeof(*rc
), GFP_KERNEL
);
187 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
188 time_before(jiffies
, end
); bcount
++) {
189 ret
= do_mult_aead_op(data
, enc
, num_mb
, rc
);
194 pr_cont("%d operations in %d seconds (%llu bytes)\n",
195 bcount
* num_mb
, secs
, (u64
)bcount
* blen
* num_mb
);
202 static int test_mb_aead_cycles(struct test_mb_aead_data
*data
, int enc
,
203 int blen
, u32 num_mb
)
205 unsigned long cycles
= 0;
210 rc
= kcalloc(num_mb
, sizeof(*rc
), GFP_KERNEL
);
215 for (i
= 0; i
< 4; i
++) {
216 ret
= do_mult_aead_op(data
, enc
, num_mb
, rc
);
221 /* The real thing. */
222 for (i
= 0; i
< 8; i
++) {
225 start
= get_cycles();
226 ret
= do_mult_aead_op(data
, enc
, num_mb
, rc
);
232 cycles
+= end
- start
;
235 pr_cont("1 operation in %lu cycles (%d bytes)\n",
236 (cycles
+ 4) / (8 * num_mb
), blen
);
243 static void test_mb_aead_speed(const char *algo
, int enc
, int secs
,
244 struct aead_speed_template
*template,
245 unsigned int tcount
, u8 authsize
,
246 unsigned int aad_size
, u8
*keysize
, u32 num_mb
)
248 struct test_mb_aead_data
*data
;
249 struct crypto_aead
*tfm
;
250 unsigned int i
, j
, iv_len
;
259 if (aad_size
>= PAGE_SIZE
) {
260 pr_err("associate data length (%u) too big\n", aad_size
);
264 iv
= kzalloc(MAX_IVLEN
, GFP_KERNEL
);
273 data
= kcalloc(num_mb
, sizeof(*data
), GFP_KERNEL
);
277 tfm
= crypto_alloc_aead(algo
, 0, 0);
279 pr_err("failed to load transform for %s: %ld\n",
284 ret
= crypto_aead_setauthsize(tfm
, authsize
);
286 pr_err("alg: aead: Failed to setauthsize for %s: %d\n", algo
,
291 for (i
= 0; i
< num_mb
; ++i
)
292 if (testmgr_alloc_buf(data
[i
].xbuf
)) {
294 testmgr_free_buf(data
[i
].xbuf
);
298 for (i
= 0; i
< num_mb
; ++i
)
299 if (testmgr_alloc_buf(data
[i
].axbuf
)) {
301 testmgr_free_buf(data
[i
].axbuf
);
305 for (i
= 0; i
< num_mb
; ++i
)
306 if (testmgr_alloc_buf(data
[i
].xoutbuf
)) {
308 testmgr_free_buf(data
[i
].xoutbuf
);
312 for (i
= 0; i
< num_mb
; ++i
) {
313 data
[i
].req
= aead_request_alloc(tfm
, GFP_KERNEL
);
315 pr_err("alg: aead: Failed to allocate request for %s\n",
318 aead_request_free(data
[i
].req
);
319 goto out_free_xoutbuf
;
323 for (i
= 0; i
< num_mb
; ++i
) {
324 crypto_init_wait(&data
[i
].wait
);
325 aead_request_set_callback(data
[i
].req
,
326 CRYPTO_TFM_REQ_MAY_BACKLOG
,
327 crypto_req_done
, &data
[i
].wait
);
330 pr_info("testing speed of multibuffer %s (%s) %s\n", algo
,
331 get_driver_name(crypto_aead
, tfm
), e
);
337 int bs
= round_up(*b_size
, crypto_aead_blocksize(tfm
));
339 if (bs
+ authsize
> XBUFSIZE
* PAGE_SIZE
) {
340 pr_err("template (%u) too big for buffer (%lu)\n",
342 XBUFSIZE
* PAGE_SIZE
);
346 pr_info("test %u (%d bit key, %d byte blocks): ", i
,
349 /* Set up tfm global state, i.e. the key */
351 memset(tvmem
[0], 0xff, PAGE_SIZE
);
353 for (j
= 0; j
< tcount
; j
++) {
354 if (template[j
].klen
== *keysize
) {
355 key
= template[j
].key
;
360 crypto_aead_clear_flags(tfm
, ~0);
362 ret
= crypto_aead_setkey(tfm
, key
, *keysize
);
364 pr_err("setkey() failed flags=%x\n",
365 crypto_aead_get_flags(tfm
));
369 iv_len
= crypto_aead_ivsize(tfm
);
371 memset(iv
, 0xff, iv_len
);
373 /* Now setup per request stuff, i.e. buffers */
375 for (j
= 0; j
< num_mb
; ++j
) {
376 struct test_mb_aead_data
*cur
= &data
[j
];
378 assoc
= cur
->axbuf
[0];
379 memset(assoc
, 0xff, aad_size
);
381 sg_init_aead(cur
->sg
, cur
->xbuf
,
382 bs
+ (enc
? 0 : authsize
),
385 sg_init_aead(cur
->sgout
, cur
->xoutbuf
,
386 bs
+ (enc
? authsize
: 0),
389 aead_request_set_ad(cur
->req
, aad_size
);
393 aead_request_set_crypt(cur
->req
,
397 ret
= crypto_aead_encrypt(cur
->req
);
398 ret
= do_one_aead_op(cur
->req
, ret
);
401 pr_err("calculating auth failed (%d)\n",
407 aead_request_set_crypt(cur
->req
, cur
->sg
,
409 (enc
? 0 : authsize
),
415 ret
= test_mb_aead_jiffies(data
, enc
, bs
,
419 ret
= test_mb_aead_cycles(data
, enc
, bs
,
424 pr_err("%s() failed return code=%d\n", e
, ret
);
434 for (i
= 0; i
< num_mb
; ++i
)
435 aead_request_free(data
[i
].req
);
437 for (i
= 0; i
< num_mb
; ++i
)
438 testmgr_free_buf(data
[i
].xoutbuf
);
440 for (i
= 0; i
< num_mb
; ++i
)
441 testmgr_free_buf(data
[i
].axbuf
);
443 for (i
= 0; i
< num_mb
; ++i
)
444 testmgr_free_buf(data
[i
].xbuf
);
446 crypto_free_aead(tfm
);
453 static int test_aead_jiffies(struct aead_request
*req
, int enc
,
456 unsigned long start
, end
;
460 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
461 time_before(jiffies
, end
); bcount
++) {
463 ret
= do_one_aead_op(req
, crypto_aead_encrypt(req
));
465 ret
= do_one_aead_op(req
, crypto_aead_decrypt(req
));
471 pr_cont("%d operations in %d seconds (%llu bytes)\n",
472 bcount
, secs
, (u64
)bcount
* blen
);
476 static int test_aead_cycles(struct aead_request
*req
, int enc
, int blen
)
478 unsigned long cycles
= 0;
483 for (i
= 0; i
< 4; i
++) {
485 ret
= do_one_aead_op(req
, crypto_aead_encrypt(req
));
487 ret
= do_one_aead_op(req
, crypto_aead_decrypt(req
));
493 /* The real thing. */
494 for (i
= 0; i
< 8; i
++) {
497 start
= get_cycles();
499 ret
= do_one_aead_op(req
, crypto_aead_encrypt(req
));
501 ret
= do_one_aead_op(req
, crypto_aead_decrypt(req
));
507 cycles
+= end
- start
;
512 pr_cont("1 operation in %lu cycles (%d bytes)\n",
513 (cycles
+ 4) / 8, blen
);
518 static void test_aead_speed(const char *algo
, int enc
, unsigned int secs
,
519 struct aead_speed_template
*template,
520 unsigned int tcount
, u8 authsize
,
521 unsigned int aad_size
, u8
*keysize
)
524 struct crypto_aead
*tfm
;
527 struct aead_request
*req
;
528 struct scatterlist
*sg
;
529 struct scatterlist
*sgout
;
533 char *xbuf
[XBUFSIZE
];
534 char *xoutbuf
[XBUFSIZE
];
535 char *axbuf
[XBUFSIZE
];
538 struct crypto_wait wait
;
540 iv
= kzalloc(MAX_IVLEN
, GFP_KERNEL
);
544 if (aad_size
>= PAGE_SIZE
) {
545 pr_err("associate data length (%u) too big\n", aad_size
);
554 if (testmgr_alloc_buf(xbuf
))
556 if (testmgr_alloc_buf(axbuf
))
558 if (testmgr_alloc_buf(xoutbuf
))
561 sg
= kmalloc(sizeof(*sg
) * 9 * 2, GFP_KERNEL
);
566 tfm
= crypto_alloc_aead(algo
, 0, 0);
568 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo
,
573 ret
= crypto_aead_setauthsize(tfm
, authsize
);
575 pr_err("alg: aead: Failed to setauthsize for %s: %d\n", algo
,
580 crypto_init_wait(&wait
);
581 pr_info("testing speed of %s (%s) %s\n", algo
,
582 get_driver_name(crypto_aead
, tfm
), e
);
584 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
586 pr_err("alg: aead: Failed to allocate request for %s\n",
591 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
592 crypto_req_done
, &wait
);
598 u32 bs
= round_up(*b_size
, crypto_aead_blocksize(tfm
));
601 memset(assoc
, 0xff, aad_size
);
603 if ((*keysize
+ bs
) > TVMEMSIZE
* PAGE_SIZE
) {
604 pr_err("template (%u) too big for tvmem (%lu)\n",
606 TVMEMSIZE
* PAGE_SIZE
);
611 for (j
= 0; j
< tcount
; j
++) {
612 if (template[j
].klen
== *keysize
) {
613 key
= template[j
].key
;
618 ret
= crypto_aead_setkey(tfm
, key
, *keysize
);
620 pr_err("setkey() failed flags=%x: %d\n",
621 crypto_aead_get_flags(tfm
), ret
);
625 iv_len
= crypto_aead_ivsize(tfm
);
627 memset(iv
, 0xff, iv_len
);
629 crypto_aead_clear_flags(tfm
, ~0);
630 pr_info("test %u (%d bit key, %d byte blocks): ",
631 i
, *keysize
* 8, bs
);
633 memset(tvmem
[0], 0xff, PAGE_SIZE
);
635 sg_init_aead(sg
, xbuf
, bs
+ (enc
? 0 : authsize
),
638 sg_init_aead(sgout
, xoutbuf
,
639 bs
+ (enc
? authsize
: 0), assoc
,
642 aead_request_set_ad(req
, aad_size
);
647 * For decryption we need a proper auth so
648 * we do the encryption path once with buffers
649 * reversed (input <-> output) to calculate it
651 aead_request_set_crypt(req
, sgout
, sg
,
653 ret
= do_one_aead_op(req
,
654 crypto_aead_encrypt(req
));
657 pr_err("calculating auth failed (%d)\n",
663 aead_request_set_crypt(req
, sg
, sgout
,
664 bs
+ (enc
? 0 : authsize
),
668 ret
= test_aead_jiffies(req
, enc
, bs
,
672 ret
= test_aead_cycles(req
, enc
, bs
);
676 pr_err("%s() failed return code=%d\n", e
, ret
);
686 aead_request_free(req
);
688 crypto_free_aead(tfm
);
692 testmgr_free_buf(xoutbuf
);
694 testmgr_free_buf(axbuf
);
696 testmgr_free_buf(xbuf
);
701 static void test_hash_sg_init(struct scatterlist
*sg
)
705 sg_init_table(sg
, TVMEMSIZE
);
706 for (i
= 0; i
< TVMEMSIZE
; i
++) {
707 sg_set_buf(sg
+ i
, tvmem
[i
], PAGE_SIZE
);
708 memset(tvmem
[i
], 0xff, PAGE_SIZE
);
712 static inline int do_one_ahash_op(struct ahash_request
*req
, int ret
)
714 struct crypto_wait
*wait
= req
->base
.data
;
716 return crypto_wait_req(ret
, wait
);
719 static int test_ahash_jiffies_digest(struct ahash_request
*req
, int blen
,
722 unsigned long start
, end
;
726 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
727 time_before(jiffies
, end
); bcount
++) {
728 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
733 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
734 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
739 static int test_ahash_jiffies(struct ahash_request
*req
, int blen
,
740 int plen
, char *out
, int secs
)
742 unsigned long start
, end
;
747 return test_ahash_jiffies_digest(req
, blen
, out
, secs
);
749 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
750 time_before(jiffies
, end
); bcount
++) {
751 ret
= do_one_ahash_op(req
, crypto_ahash_init(req
));
754 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
755 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
759 /* we assume there is enough space in 'out' for the result */
760 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
765 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
766 bcount
/ secs
, ((long)bcount
* blen
) / secs
);
771 static int test_ahash_cycles_digest(struct ahash_request
*req
, int blen
,
774 unsigned long cycles
= 0;
778 for (i
= 0; i
< 4; i
++) {
779 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
784 /* The real thing. */
785 for (i
= 0; i
< 8; i
++) {
788 start
= get_cycles();
790 ret
= do_one_ahash_op(req
, crypto_ahash_digest(req
));
796 cycles
+= end
- start
;
803 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
804 cycles
/ 8, cycles
/ (8 * blen
));
809 static int test_ahash_cycles(struct ahash_request
*req
, int blen
,
812 unsigned long cycles
= 0;
816 return test_ahash_cycles_digest(req
, blen
, out
);
819 for (i
= 0; i
< 4; i
++) {
820 ret
= do_one_ahash_op(req
, crypto_ahash_init(req
));
823 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
824 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
828 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
833 /* The real thing. */
834 for (i
= 0; i
< 8; i
++) {
837 start
= get_cycles();
839 ret
= do_one_ahash_op(req
, crypto_ahash_init(req
));
842 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
843 ret
= do_one_ahash_op(req
, crypto_ahash_update(req
));
847 ret
= do_one_ahash_op(req
, crypto_ahash_final(req
));
853 cycles
+= end
- start
;
860 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
861 cycles
/ 8, cycles
/ (8 * blen
));
866 static void test_ahash_speed_common(const char *algo
, unsigned int secs
,
867 struct hash_speed
*speed
, unsigned mask
)
869 struct scatterlist sg
[TVMEMSIZE
];
870 struct crypto_wait wait
;
871 struct ahash_request
*req
;
872 struct crypto_ahash
*tfm
;
876 tfm
= crypto_alloc_ahash(algo
, 0, mask
);
878 pr_err("failed to load transform for %s: %ld\n",
883 pr_info("testing speed of async %s (%s)\n", algo
,
884 get_driver_name(crypto_ahash
, tfm
));
886 if (crypto_ahash_digestsize(tfm
) > MAX_DIGEST_SIZE
) {
887 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm
),
892 test_hash_sg_init(sg
);
893 req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
895 pr_err("ahash request allocation failure\n");
899 crypto_init_wait(&wait
);
900 ahash_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
901 crypto_req_done
, &wait
);
903 output
= kmalloc(MAX_DIGEST_SIZE
, GFP_KERNEL
);
907 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
908 if (speed
[i
].blen
> TVMEMSIZE
* PAGE_SIZE
) {
909 pr_err("template (%u) too big for tvmem (%lu)\n",
910 speed
[i
].blen
, TVMEMSIZE
* PAGE_SIZE
);
915 crypto_ahash_setkey(tfm
, tvmem
[0], klen
);
918 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
919 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
921 ahash_request_set_crypt(req
, sg
, output
, speed
[i
].plen
);
924 ret
= test_ahash_jiffies(req
, speed
[i
].blen
,
925 speed
[i
].plen
, output
, secs
);
928 ret
= test_ahash_cycles(req
, speed
[i
].blen
,
929 speed
[i
].plen
, output
);
933 pr_err("hashing failed ret=%d\n", ret
);
941 ahash_request_free(req
);
944 crypto_free_ahash(tfm
);
947 static void test_ahash_speed(const char *algo
, unsigned int secs
,
948 struct hash_speed
*speed
)
950 return test_ahash_speed_common(algo
, secs
, speed
, 0);
953 static void test_hash_speed(const char *algo
, unsigned int secs
,
954 struct hash_speed
*speed
)
956 return test_ahash_speed_common(algo
, secs
, speed
, CRYPTO_ALG_ASYNC
);
959 struct test_mb_skcipher_data
{
960 struct scatterlist sg
[XBUFSIZE
];
961 struct skcipher_request
*req
;
962 struct crypto_wait wait
;
963 char *xbuf
[XBUFSIZE
];
966 static int do_mult_acipher_op(struct test_mb_skcipher_data
*data
, int enc
,
971 /* Fire up a bunch of concurrent requests */
972 for (i
= 0; i
< num_mb
; i
++) {
974 rc
[i
] = crypto_skcipher_encrypt(data
[i
].req
);
976 rc
[i
] = crypto_skcipher_decrypt(data
[i
].req
);
979 /* Wait for all requests to finish */
980 for (i
= 0; i
< num_mb
; i
++) {
981 rc
[i
] = crypto_wait_req(rc
[i
], &data
[i
].wait
);
984 pr_info("concurrent request %d error %d\n", i
, rc
[i
]);
992 static int test_mb_acipher_jiffies(struct test_mb_skcipher_data
*data
, int enc
,
993 int blen
, int secs
, u32 num_mb
)
995 unsigned long start
, end
;
1000 rc
= kcalloc(num_mb
, sizeof(*rc
), GFP_KERNEL
);
1004 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
1005 time_before(jiffies
, end
); bcount
++) {
1006 ret
= do_mult_acipher_op(data
, enc
, num_mb
, rc
);
1011 pr_cont("%d operations in %d seconds (%llu bytes)\n",
1012 bcount
* num_mb
, secs
, (u64
)bcount
* blen
* num_mb
);
1019 static int test_mb_acipher_cycles(struct test_mb_skcipher_data
*data
, int enc
,
1020 int blen
, u32 num_mb
)
1022 unsigned long cycles
= 0;
1027 rc
= kcalloc(num_mb
, sizeof(*rc
), GFP_KERNEL
);
1032 for (i
= 0; i
< 4; i
++) {
1033 ret
= do_mult_acipher_op(data
, enc
, num_mb
, rc
);
1038 /* The real thing. */
1039 for (i
= 0; i
< 8; i
++) {
1040 cycles_t start
, end
;
1042 start
= get_cycles();
1043 ret
= do_mult_acipher_op(data
, enc
, num_mb
, rc
);
1049 cycles
+= end
- start
;
1052 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1053 (cycles
+ 4) / (8 * num_mb
), blen
);
1060 static void test_mb_skcipher_speed(const char *algo
, int enc
, int secs
,
1061 struct cipher_speed_template
*template,
1062 unsigned int tcount
, u8
*keysize
, u32 num_mb
)
1064 struct test_mb_skcipher_data
*data
;
1065 struct crypto_skcipher
*tfm
;
1066 unsigned int i
, j
, iv_len
;
1078 data
= kcalloc(num_mb
, sizeof(*data
), GFP_KERNEL
);
1082 tfm
= crypto_alloc_skcipher(algo
, 0, 0);
1084 pr_err("failed to load transform for %s: %ld\n",
1085 algo
, PTR_ERR(tfm
));
1089 for (i
= 0; i
< num_mb
; ++i
)
1090 if (testmgr_alloc_buf(data
[i
].xbuf
)) {
1092 testmgr_free_buf(data
[i
].xbuf
);
1096 for (i
= 0; i
< num_mb
; ++i
) {
1097 data
[i
].req
= skcipher_request_alloc(tfm
, GFP_KERNEL
);
1099 pr_err("alg: skcipher: Failed to allocate request for %s\n",
1102 skcipher_request_free(data
[i
].req
);
1107 for (i
= 0; i
< num_mb
; ++i
) {
1108 skcipher_request_set_callback(data
[i
].req
,
1109 CRYPTO_TFM_REQ_MAY_BACKLOG
,
1110 crypto_req_done
, &data
[i
].wait
);
1111 crypto_init_wait(&data
[i
].wait
);
1114 pr_info("testing speed of multibuffer %s (%s) %s\n", algo
,
1115 get_driver_name(crypto_skcipher
, tfm
), e
);
1119 b_size
= block_sizes
;
1121 u32 bs
= round_up(*b_size
, crypto_skcipher_blocksize(tfm
));
1123 if (bs
> XBUFSIZE
* PAGE_SIZE
) {
1124 pr_err("template (%u) too big for buffer (%lu)\n",
1125 bs
, XBUFSIZE
* PAGE_SIZE
);
1129 pr_info("test %u (%d bit key, %d byte blocks): ", i
,
1132 /* Set up tfm global state, i.e. the key */
1134 memset(tvmem
[0], 0xff, PAGE_SIZE
);
1136 for (j
= 0; j
< tcount
; j
++) {
1137 if (template[j
].klen
== *keysize
) {
1138 key
= template[j
].key
;
1143 crypto_skcipher_clear_flags(tfm
, ~0);
1145 ret
= crypto_skcipher_setkey(tfm
, key
, *keysize
);
1147 pr_err("setkey() failed flags=%x\n",
1148 crypto_skcipher_get_flags(tfm
));
1152 iv_len
= crypto_skcipher_ivsize(tfm
);
1154 memset(&iv
, 0xff, iv_len
);
1156 /* Now setup per request stuff, i.e. buffers */
1158 for (j
= 0; j
< num_mb
; ++j
) {
1159 struct test_mb_skcipher_data
*cur
= &data
[j
];
1160 unsigned int k
= bs
;
1161 unsigned int pages
= DIV_ROUND_UP(k
, PAGE_SIZE
);
1164 sg_init_table(cur
->sg
, pages
);
1166 while (k
> PAGE_SIZE
) {
1167 sg_set_buf(cur
->sg
+ p
, cur
->xbuf
[p
],
1169 memset(cur
->xbuf
[p
], 0xff, PAGE_SIZE
);
1174 sg_set_buf(cur
->sg
+ p
, cur
->xbuf
[p
], k
);
1175 memset(cur
->xbuf
[p
], 0xff, k
);
1177 skcipher_request_set_crypt(cur
->req
, cur
->sg
,
1182 ret
= test_mb_acipher_jiffies(data
, enc
,
1187 ret
= test_mb_acipher_cycles(data
, enc
,
1192 pr_err("%s() failed flags=%x\n", e
,
1193 crypto_skcipher_get_flags(tfm
));
1203 for (i
= 0; i
< num_mb
; ++i
)
1204 skcipher_request_free(data
[i
].req
);
1206 for (i
= 0; i
< num_mb
; ++i
)
1207 testmgr_free_buf(data
[i
].xbuf
);
1209 crypto_free_skcipher(tfm
);
1214 static inline int do_one_acipher_op(struct skcipher_request
*req
, int ret
)
1216 struct crypto_wait
*wait
= req
->base
.data
;
1218 return crypto_wait_req(ret
, wait
);
1221 static int test_acipher_jiffies(struct skcipher_request
*req
, int enc
,
1224 unsigned long start
, end
;
1228 for (start
= jiffies
, end
= start
+ secs
* HZ
, bcount
= 0;
1229 time_before(jiffies
, end
); bcount
++) {
1231 ret
= do_one_acipher_op(req
,
1232 crypto_skcipher_encrypt(req
));
1234 ret
= do_one_acipher_op(req
,
1235 crypto_skcipher_decrypt(req
));
1241 pr_cont("%d operations in %d seconds (%llu bytes)\n",
1242 bcount
, secs
, (u64
)bcount
* blen
);
1246 static int test_acipher_cycles(struct skcipher_request
*req
, int enc
,
1249 unsigned long cycles
= 0;
1254 for (i
= 0; i
< 4; i
++) {
1256 ret
= do_one_acipher_op(req
,
1257 crypto_skcipher_encrypt(req
));
1259 ret
= do_one_acipher_op(req
,
1260 crypto_skcipher_decrypt(req
));
1266 /* The real thing. */
1267 for (i
= 0; i
< 8; i
++) {
1268 cycles_t start
, end
;
1270 start
= get_cycles();
1272 ret
= do_one_acipher_op(req
,
1273 crypto_skcipher_encrypt(req
));
1275 ret
= do_one_acipher_op(req
,
1276 crypto_skcipher_decrypt(req
));
1282 cycles
+= end
- start
;
1287 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1288 (cycles
+ 4) / 8, blen
);
1293 static void test_skcipher_speed(const char *algo
, int enc
, unsigned int secs
,
1294 struct cipher_speed_template
*template,
1295 unsigned int tcount
, u8
*keysize
, bool async
)
1297 unsigned int ret
, i
, j
, k
, iv_len
;
1298 struct crypto_wait wait
;
1301 struct skcipher_request
*req
;
1302 struct crypto_skcipher
*tfm
;
1311 crypto_init_wait(&wait
);
1313 tfm
= crypto_alloc_skcipher(algo
, 0, async
? 0 : CRYPTO_ALG_ASYNC
);
1316 pr_err("failed to load transform for %s: %ld\n", algo
,
1321 pr_info("testing speed of %s %s (%s) %s\n", async
? "async" : "sync",
1322 algo
, get_driver_name(crypto_skcipher
, tfm
), e
);
1324 req
= skcipher_request_alloc(tfm
, GFP_KERNEL
);
1326 pr_err("skcipher: Failed to allocate request for %s\n", algo
);
1330 skcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
1331 crypto_req_done
, &wait
);
1335 b_size
= block_sizes
;
1338 u32 bs
= round_up(*b_size
, crypto_skcipher_blocksize(tfm
));
1339 struct scatterlist sg
[TVMEMSIZE
];
1341 if ((*keysize
+ bs
) > TVMEMSIZE
* PAGE_SIZE
) {
1342 pr_err("template (%u) too big for "
1343 "tvmem (%lu)\n", *keysize
+ bs
,
1344 TVMEMSIZE
* PAGE_SIZE
);
1348 pr_info("test %u (%d bit key, %d byte blocks): ", i
,
1351 memset(tvmem
[0], 0xff, PAGE_SIZE
);
1353 /* set key, plain text and IV */
1355 for (j
= 0; j
< tcount
; j
++) {
1356 if (template[j
].klen
== *keysize
) {
1357 key
= template[j
].key
;
1362 crypto_skcipher_clear_flags(tfm
, ~0);
1364 ret
= crypto_skcipher_setkey(tfm
, key
, *keysize
);
1366 pr_err("setkey() failed flags=%x\n",
1367 crypto_skcipher_get_flags(tfm
));
1372 sg_init_table(sg
, DIV_ROUND_UP(k
, PAGE_SIZE
));
1374 if (k
> PAGE_SIZE
) {
1375 sg_set_buf(sg
, tvmem
[0] + *keysize
,
1376 PAGE_SIZE
- *keysize
);
1379 while (k
> PAGE_SIZE
) {
1380 sg_set_buf(sg
+ j
, tvmem
[j
], PAGE_SIZE
);
1381 memset(tvmem
[j
], 0xff, PAGE_SIZE
);
1385 sg_set_buf(sg
+ j
, tvmem
[j
], k
);
1386 memset(tvmem
[j
], 0xff, k
);
1388 sg_set_buf(sg
, tvmem
[0] + *keysize
, bs
);
1391 iv_len
= crypto_skcipher_ivsize(tfm
);
1393 memset(&iv
, 0xff, iv_len
);
1395 skcipher_request_set_crypt(req
, sg
, sg
, bs
, iv
);
1398 ret
= test_acipher_jiffies(req
, enc
,
1402 ret
= test_acipher_cycles(req
, enc
,
1407 pr_err("%s() failed flags=%x\n", e
,
1408 crypto_skcipher_get_flags(tfm
));
1418 skcipher_request_free(req
);
1420 crypto_free_skcipher(tfm
);
1423 static void test_acipher_speed(const char *algo
, int enc
, unsigned int secs
,
1424 struct cipher_speed_template
*template,
1425 unsigned int tcount
, u8
*keysize
)
1427 return test_skcipher_speed(algo
, enc
, secs
, template, tcount
, keysize
,
1431 static void test_cipher_speed(const char *algo
, int enc
, unsigned int secs
,
1432 struct cipher_speed_template
*template,
1433 unsigned int tcount
, u8
*keysize
)
1435 return test_skcipher_speed(algo
, enc
, secs
, template, tcount
, keysize
,
1439 static inline int tcrypt_test(const char *alg
)
1443 pr_debug("testing %s\n", alg
);
1445 ret
= alg_test(alg
, alg
, 0, 0);
1446 /* non-fips algs return -EINVAL or -ECANCELED in fips mode */
1447 if (fips_enabled
&& (ret
== -EINVAL
|| ret
== -ECANCELED
))
1452 static int do_test(const char *alg
, u32 type
, u32 mask
, int m
, u32 num_mb
)
1460 if (!crypto_has_alg(alg
, type
,
1461 mask
?: CRYPTO_ALG_TYPE_MASK
))
1466 for (i
= 1; i
< 200; i
++)
1467 ret
= min(ret
, do_test(NULL
, 0, 0, i
, num_mb
));
1471 ret
= min(ret
, tcrypt_test("md5"));
1475 ret
= min(ret
, tcrypt_test("sha1"));
1479 ret
= min(ret
, tcrypt_test("ecb(des)"));
1480 ret
= min(ret
, tcrypt_test("cbc(des)"));
1481 ret
= min(ret
, tcrypt_test("ctr(des)"));
1485 ret
= min(ret
, tcrypt_test("ecb(des3_ede)"));
1486 ret
= min(ret
, tcrypt_test("cbc(des3_ede)"));
1487 ret
= min(ret
, tcrypt_test("ctr(des3_ede)"));
1491 ret
= min(ret
, tcrypt_test("md4"));
1495 ret
= min(ret
, tcrypt_test("sha256"));
1499 ret
= min(ret
, tcrypt_test("ecb(blowfish)"));
1500 ret
= min(ret
, tcrypt_test("cbc(blowfish)"));
1501 ret
= min(ret
, tcrypt_test("ctr(blowfish)"));
1505 ret
= min(ret
, tcrypt_test("ecb(twofish)"));
1506 ret
= min(ret
, tcrypt_test("cbc(twofish)"));
1507 ret
= min(ret
, tcrypt_test("ctr(twofish)"));
1508 ret
= min(ret
, tcrypt_test("lrw(twofish)"));
1509 ret
= min(ret
, tcrypt_test("xts(twofish)"));
1513 ret
= min(ret
, tcrypt_test("ecb(serpent)"));
1514 ret
= min(ret
, tcrypt_test("cbc(serpent)"));
1515 ret
= min(ret
, tcrypt_test("ctr(serpent)"));
1516 ret
= min(ret
, tcrypt_test("lrw(serpent)"));
1517 ret
= min(ret
, tcrypt_test("xts(serpent)"));
1521 ret
= min(ret
, tcrypt_test("ecb(aes)"));
1522 ret
= min(ret
, tcrypt_test("cbc(aes)"));
1523 ret
= min(ret
, tcrypt_test("lrw(aes)"));
1524 ret
= min(ret
, tcrypt_test("xts(aes)"));
1525 ret
= min(ret
, tcrypt_test("ctr(aes)"));
1526 ret
= min(ret
, tcrypt_test("rfc3686(ctr(aes))"));
1527 ret
= min(ret
, tcrypt_test("xctr(aes)"));
1531 ret
= min(ret
, tcrypt_test("sha384"));
1535 ret
= min(ret
, tcrypt_test("sha512"));
1539 ret
= min(ret
, tcrypt_test("deflate"));
1543 ret
= min(ret
, tcrypt_test("ecb(cast5)"));
1544 ret
= min(ret
, tcrypt_test("cbc(cast5)"));
1545 ret
= min(ret
, tcrypt_test("ctr(cast5)"));
1549 ret
= min(ret
, tcrypt_test("ecb(cast6)"));
1550 ret
= min(ret
, tcrypt_test("cbc(cast6)"));
1551 ret
= min(ret
, tcrypt_test("ctr(cast6)"));
1552 ret
= min(ret
, tcrypt_test("lrw(cast6)"));
1553 ret
= min(ret
, tcrypt_test("xts(cast6)"));
1557 ret
= min(ret
, tcrypt_test("ecb(arc4)"));
1561 ret
= min(ret
, tcrypt_test("michael_mic"));
1565 ret
= min(ret
, tcrypt_test("crc32c"));
1569 ret
= min(ret
, tcrypt_test("ecb(tea)"));
1573 ret
= min(ret
, tcrypt_test("ecb(xtea)"));
1577 ret
= min(ret
, tcrypt_test("ecb(khazad)"));
1581 ret
= min(ret
, tcrypt_test("wp512"));
1585 ret
= min(ret
, tcrypt_test("wp384"));
1589 ret
= min(ret
, tcrypt_test("wp256"));
1593 ret
= min(ret
, tcrypt_test("ecb(anubis)"));
1594 ret
= min(ret
, tcrypt_test("cbc(anubis)"));
1598 ret
= min(ret
, tcrypt_test("ecb(xeta)"));
1602 ret
= min(ret
, tcrypt_test("pcbc(fcrypt)"));
1606 ret
= min(ret
, tcrypt_test("ecb(camellia)"));
1607 ret
= min(ret
, tcrypt_test("cbc(camellia)"));
1608 ret
= min(ret
, tcrypt_test("ctr(camellia)"));
1609 ret
= min(ret
, tcrypt_test("lrw(camellia)"));
1610 ret
= min(ret
, tcrypt_test("xts(camellia)"));
1614 ret
= min(ret
, tcrypt_test("sha224"));
1618 ret
= min(ret
, tcrypt_test("gcm(aes)"));
1622 ret
= min(ret
, tcrypt_test("lzo"));
1626 ret
= min(ret
, tcrypt_test("ccm(aes)"));
1630 ret
= min(ret
, tcrypt_test("cts(cbc(aes))"));
1634 ret
= min(ret
, tcrypt_test("xxhash64"));
1638 ret
= min(ret
, tcrypt_test("rmd160"));
1642 ret
= min(ret
, tcrypt_test("blake2b-512"));
1646 ret
= min(ret
, tcrypt_test("ecb(seed)"));
1650 ret
= min(ret
, tcrypt_test("rfc4309(ccm(aes))"));
1654 ret
= min(ret
, tcrypt_test("ghash"));
1658 ret
= min(ret
, tcrypt_test("crct10dif"));
1662 ret
= min(ret
, tcrypt_test("sha3-224"));
1666 ret
= min(ret
, tcrypt_test("sha3-256"));
1670 ret
= min(ret
, tcrypt_test("sha3-384"));
1674 ret
= min(ret
, tcrypt_test("sha3-512"));
1678 ret
= min(ret
, tcrypt_test("sm3"));
1682 ret
= min(ret
, tcrypt_test("streebog256"));
1686 ret
= min(ret
, tcrypt_test("streebog512"));
1690 ret
= min(ret
, tcrypt_test("gcm(sm4)"));
1694 ret
= min(ret
, tcrypt_test("ccm(sm4)"));
1698 ret
= min(ret
, tcrypt_test("polyval"));
1702 ret
= min(ret
, tcrypt_test("gcm(aria)"));
1706 ret
= min(ret
, tcrypt_test("cts(cbc(sm4))"));
1710 ret
= min(ret
, tcrypt_test("hmac(md5)"));
1714 ret
= min(ret
, tcrypt_test("hmac(sha1)"));
1718 ret
= min(ret
, tcrypt_test("hmac(sha256)"));
1722 ret
= min(ret
, tcrypt_test("hmac(sha384)"));
1726 ret
= min(ret
, tcrypt_test("hmac(sha512)"));
1730 ret
= min(ret
, tcrypt_test("hmac(sha224)"));
1734 ret
= min(ret
, tcrypt_test("xcbc(aes)"));
1738 ret
= min(ret
, tcrypt_test("hmac(rmd160)"));
1742 ret
= min(ret
, tcrypt_test("vmac64(aes)"));
1746 ret
= min(ret
, tcrypt_test("hmac(sha3-224)"));
1750 ret
= min(ret
, tcrypt_test("hmac(sha3-256)"));
1754 ret
= min(ret
, tcrypt_test("hmac(sha3-384)"));
1758 ret
= min(ret
, tcrypt_test("hmac(sha3-512)"));
1762 ret
= min(ret
, tcrypt_test("hmac(streebog256)"));
1766 ret
= min(ret
, tcrypt_test("hmac(streebog512)"));
1770 ret
= min(ret
, tcrypt_test("ansi_cprng"));
1774 ret
= min(ret
, tcrypt_test("rfc4106(gcm(aes))"));
1778 ret
= min(ret
, tcrypt_test("rfc4543(gcm(aes))"));
1782 ret
= min(ret
, tcrypt_test("cmac(aes)"));
1786 ret
= min(ret
, tcrypt_test("cmac(des3_ede)"));
1790 ret
= min(ret
, tcrypt_test("authenc(hmac(sha1),cbc(aes))"));
1794 ret
= min(ret
, tcrypt_test("authenc(hmac(md5),ecb(cipher_null))"));
1798 ret
= min(ret
, tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))"));
1802 ret
= min(ret
, tcrypt_test("cbcmac(sm4)"));
1806 ret
= min(ret
, tcrypt_test("cmac(sm4)"));
1810 ret
= min(ret
, tcrypt_test("xcbc(sm4)"));
1814 ret
= min(ret
, tcrypt_test("authenc(hmac(sha1),cbc(des))"));
1817 ret
= min(ret
, tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))"));
1820 ret
= min(ret
, tcrypt_test("authenc(hmac(sha224),cbc(des))"));
1823 ret
= min(ret
, tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))"));
1826 ret
= min(ret
, tcrypt_test("authenc(hmac(sha256),cbc(des))"));
1829 ret
= min(ret
, tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))"));
1832 ret
= min(ret
, tcrypt_test("authenc(hmac(sha384),cbc(des))"));
1835 ret
= min(ret
, tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))"));
1838 ret
= min(ret
, tcrypt_test("authenc(hmac(sha512),cbc(des))"));
1841 ret
= min(ret
, tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))"));
1844 ret
= min(ret
, tcrypt_test("ecb(sm4)"));
1845 ret
= min(ret
, tcrypt_test("cbc(sm4)"));
1846 ret
= min(ret
, tcrypt_test("ctr(sm4)"));
1847 ret
= min(ret
, tcrypt_test("xts(sm4)"));
1850 ret
= min(ret
, tcrypt_test("ecb(aria)"));
1851 ret
= min(ret
, tcrypt_test("cbc(aria)"));
1852 ret
= min(ret
, tcrypt_test("ctr(aria)"));
1855 ret
= min(ret
, tcrypt_test("ffdhe2048(dh)"));
1858 test_cipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1859 speed_template_16_24_32
);
1860 test_cipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1861 speed_template_16_24_32
);
1862 test_cipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1863 speed_template_16_24_32
);
1864 test_cipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1865 speed_template_16_24_32
);
1866 test_cipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1867 speed_template_32_40_48
);
1868 test_cipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1869 speed_template_32_40_48
);
1870 test_cipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1871 speed_template_32_64
);
1872 test_cipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1873 speed_template_32_64
);
1874 test_cipher_speed("cts(cbc(aes))", ENCRYPT
, sec
, NULL
, 0,
1875 speed_template_16_24_32
);
1876 test_cipher_speed("cts(cbc(aes))", DECRYPT
, sec
, NULL
, 0,
1877 speed_template_16_24_32
);
1878 test_cipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
1879 speed_template_16_24_32
);
1880 test_cipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
1881 speed_template_16_24_32
);
1885 test_cipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1886 des3_speed_template
, DES3_SPEED_VECTORS
,
1888 test_cipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1889 des3_speed_template
, DES3_SPEED_VECTORS
,
1891 test_cipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1892 des3_speed_template
, DES3_SPEED_VECTORS
,
1894 test_cipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1895 des3_speed_template
, DES3_SPEED_VECTORS
,
1897 test_cipher_speed("ctr(des3_ede)", ENCRYPT
, sec
,
1898 des3_speed_template
, DES3_SPEED_VECTORS
,
1900 test_cipher_speed("ctr(des3_ede)", DECRYPT
, sec
,
1901 des3_speed_template
, DES3_SPEED_VECTORS
,
1906 test_cipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1907 speed_template_16_24_32
);
1908 test_cipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1909 speed_template_16_24_32
);
1910 test_cipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1911 speed_template_16_24_32
);
1912 test_cipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1913 speed_template_16_24_32
);
1914 test_cipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
1915 speed_template_16_24_32
);
1916 test_cipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
1917 speed_template_16_24_32
);
1918 test_cipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
1919 speed_template_32_40_48
);
1920 test_cipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
1921 speed_template_32_40_48
);
1922 test_cipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
1923 speed_template_32_48_64
);
1924 test_cipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
1925 speed_template_32_48_64
);
1929 test_cipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1930 speed_template_8_32
);
1931 test_cipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
1932 speed_template_8_32
);
1933 test_cipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1934 speed_template_8_32
);
1935 test_cipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
1936 speed_template_8_32
);
1937 test_cipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1938 speed_template_8_32
);
1939 test_cipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
1940 speed_template_8_32
);
1944 test_cipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1946 test_cipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1948 test_cipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1950 test_cipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1955 test_cipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
1956 speed_template_16_24_32
);
1957 test_cipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
1958 speed_template_16_24_32
);
1959 test_cipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
1960 speed_template_16_24_32
);
1961 test_cipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
1962 speed_template_16_24_32
);
1963 test_cipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
1964 speed_template_16_24_32
);
1965 test_cipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
1966 speed_template_16_24_32
);
1967 test_cipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
1968 speed_template_32_40_48
);
1969 test_cipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
1970 speed_template_32_40_48
);
1971 test_cipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
1972 speed_template_32_48_64
);
1973 test_cipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
1974 speed_template_32_48_64
);
1978 test_cipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
1979 speed_template_16_32
);
1980 test_cipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
1981 speed_template_16_32
);
1982 test_cipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
1983 speed_template_16_32
);
1984 test_cipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
1985 speed_template_16_32
);
1986 test_cipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
1987 speed_template_16_32
);
1988 test_cipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
1989 speed_template_16_32
);
1990 test_cipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
1991 speed_template_32_48
);
1992 test_cipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
1993 speed_template_32_48
);
1994 test_cipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
1995 speed_template_32_64
);
1996 test_cipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
1997 speed_template_32_64
);
2001 test_cipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
2006 test_cipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
2007 speed_template_8_16
);
2008 test_cipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
2009 speed_template_8_16
);
2010 test_cipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
2011 speed_template_8_16
);
2012 test_cipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
2013 speed_template_8_16
);
2014 test_cipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
2015 speed_template_8_16
);
2016 test_cipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
2017 speed_template_8_16
);
2021 test_cipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
2022 speed_template_16_32
);
2023 test_cipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
2024 speed_template_16_32
);
2025 test_cipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
2026 speed_template_16_32
);
2027 test_cipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
2028 speed_template_16_32
);
2029 test_cipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
2030 speed_template_16_32
);
2031 test_cipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
2032 speed_template_16_32
);
2033 test_cipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
2034 speed_template_32_48
);
2035 test_cipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
2036 speed_template_32_48
);
2037 test_cipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
2038 speed_template_32_64
);
2039 test_cipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
2040 speed_template_32_64
);
2044 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT
, sec
,
2045 NULL
, 0, 16, 16, aead_speed_template_20_28_36
);
2046 test_aead_speed("gcm(aes)", ENCRYPT
, sec
,
2047 NULL
, 0, 16, 8, speed_template_16_24_32
);
2048 test_aead_speed("rfc4106(gcm(aes))", DECRYPT
, sec
,
2049 NULL
, 0, 16, 16, aead_speed_template_20_28_36
);
2050 test_aead_speed("gcm(aes)", DECRYPT
, sec
,
2051 NULL
, 0, 16, 8, speed_template_16_24_32
);
2055 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT
, sec
,
2056 NULL
, 0, 16, 16, aead_speed_template_19
);
2057 test_aead_speed("rfc4309(ccm(aes))", DECRYPT
, sec
,
2058 NULL
, 0, 16, 16, aead_speed_template_19
);
2062 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT
, sec
,
2063 NULL
, 0, 16, 8, aead_speed_template_36
);
2064 test_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT
, sec
,
2065 NULL
, 0, 16, 8, aead_speed_template_36
);
2069 test_cipher_speed("chacha20", ENCRYPT
, sec
, NULL
, 0,
2074 test_mb_aead_speed("rfc4106(gcm(aes))", ENCRYPT
, sec
, NULL
,
2075 0, 16, 16, aead_speed_template_20_28_36
, num_mb
);
2076 test_mb_aead_speed("gcm(aes)", ENCRYPT
, sec
, NULL
, 0, 16, 8,
2077 speed_template_16_24_32
, num_mb
);
2078 test_mb_aead_speed("rfc4106(gcm(aes))", DECRYPT
, sec
, NULL
,
2079 0, 16, 16, aead_speed_template_20_28_36
, num_mb
);
2080 test_mb_aead_speed("gcm(aes)", DECRYPT
, sec
, NULL
, 0, 16, 8,
2081 speed_template_16_24_32
, num_mb
);
2085 test_mb_aead_speed("rfc4309(ccm(aes))", ENCRYPT
, sec
, NULL
, 0,
2086 16, 16, aead_speed_template_19
, num_mb
);
2087 test_mb_aead_speed("rfc4309(ccm(aes))", DECRYPT
, sec
, NULL
, 0,
2088 16, 16, aead_speed_template_19
, num_mb
);
2092 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT
,
2093 sec
, NULL
, 0, 16, 8, aead_speed_template_36
,
2095 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT
,
2096 sec
, NULL
, 0, 16, 8, aead_speed_template_36
,
2101 test_cipher_speed("ecb(sm4)", ENCRYPT
, sec
, NULL
, 0,
2103 test_cipher_speed("ecb(sm4)", DECRYPT
, sec
, NULL
, 0,
2105 test_cipher_speed("cbc(sm4)", ENCRYPT
, sec
, NULL
, 0,
2107 test_cipher_speed("cbc(sm4)", DECRYPT
, sec
, NULL
, 0,
2109 test_cipher_speed("cts(cbc(sm4))", ENCRYPT
, sec
, NULL
, 0,
2111 test_cipher_speed("cts(cbc(sm4))", DECRYPT
, sec
, NULL
, 0,
2113 test_cipher_speed("ctr(sm4)", ENCRYPT
, sec
, NULL
, 0,
2115 test_cipher_speed("ctr(sm4)", DECRYPT
, sec
, NULL
, 0,
2117 test_cipher_speed("xts(sm4)", ENCRYPT
, sec
, NULL
, 0,
2119 test_cipher_speed("xts(sm4)", DECRYPT
, sec
, NULL
, 0,
2124 test_cipher_speed("adiantum(xchacha12,aes)", ENCRYPT
, sec
, NULL
,
2125 0, speed_template_32
);
2126 test_cipher_speed("adiantum(xchacha12,aes)", DECRYPT
, sec
, NULL
,
2127 0, speed_template_32
);
2128 test_cipher_speed("adiantum(xchacha20,aes)", ENCRYPT
, sec
, NULL
,
2129 0, speed_template_32
);
2130 test_cipher_speed("adiantum(xchacha20,aes)", DECRYPT
, sec
, NULL
,
2131 0, speed_template_32
);
2135 test_acipher_speed("essiv(cbc(aes),sha256)",
2136 ENCRYPT
, sec
, NULL
, 0,
2137 speed_template_16_24_32
);
2138 test_acipher_speed("essiv(cbc(aes),sha256)",
2139 DECRYPT
, sec
, NULL
, 0,
2140 speed_template_16_24_32
);
2144 test_aead_speed("aegis128", ENCRYPT
, sec
,
2145 NULL
, 0, 16, 8, speed_template_16
);
2146 test_aead_speed("aegis128", DECRYPT
, sec
,
2147 NULL
, 0, 16, 8, speed_template_16
);
2151 test_aead_speed("gcm(sm4)", ENCRYPT
, sec
,
2152 NULL
, 0, 16, 8, speed_template_16
);
2153 test_aead_speed("gcm(sm4)", DECRYPT
, sec
,
2154 NULL
, 0, 16, 8, speed_template_16
);
2158 test_aead_speed("rfc4309(ccm(sm4))", ENCRYPT
, sec
,
2159 NULL
, 0, 16, 16, aead_speed_template_19
);
2160 test_aead_speed("rfc4309(ccm(sm4))", DECRYPT
, sec
,
2161 NULL
, 0, 16, 16, aead_speed_template_19
);
2165 test_mb_aead_speed("gcm(sm4)", ENCRYPT
, sec
, NULL
, 0, 16, 8,
2166 speed_template_16
, num_mb
);
2167 test_mb_aead_speed("gcm(sm4)", DECRYPT
, sec
, NULL
, 0, 16, 8,
2168 speed_template_16
, num_mb
);
2172 test_mb_aead_speed("rfc4309(ccm(sm4))", ENCRYPT
, sec
, NULL
, 0,
2173 16, 16, aead_speed_template_19
, num_mb
);
2174 test_mb_aead_speed("rfc4309(ccm(sm4))", DECRYPT
, sec
, NULL
, 0,
2175 16, 16, aead_speed_template_19
, num_mb
);
2179 test_cipher_speed("hctr2(aes)", ENCRYPT
, sec
, NULL
,
2180 0, speed_template_32
);
2184 test_cipher_speed("ecb(aria)", ENCRYPT
, sec
, NULL
, 0,
2185 speed_template_16_24_32
);
2186 test_cipher_speed("ecb(aria)", DECRYPT
, sec
, NULL
, 0,
2187 speed_template_16_24_32
);
2188 test_cipher_speed("cbc(aria)", ENCRYPT
, sec
, NULL
, 0,
2189 speed_template_16_24_32
);
2190 test_cipher_speed("cbc(aria)", DECRYPT
, sec
, NULL
, 0,
2191 speed_template_16_24_32
);
2192 test_cipher_speed("ctr(aria)", ENCRYPT
, sec
, NULL
, 0,
2193 speed_template_16_24_32
);
2194 test_cipher_speed("ctr(aria)", DECRYPT
, sec
, NULL
, 0,
2195 speed_template_16_24_32
);
2199 test_aead_speed("gcm(aria)", ENCRYPT
, sec
,
2200 NULL
, 0, 16, 8, speed_template_16_24_32
);
2201 test_aead_speed("gcm(aria)", DECRYPT
, sec
,
2202 NULL
, 0, 16, 8, speed_template_16_24_32
);
2206 test_mb_aead_speed("gcm(aria)", ENCRYPT
, sec
, NULL
, 0, 16, 8,
2207 speed_template_16
, num_mb
);
2208 test_mb_aead_speed("gcm(aria)", DECRYPT
, sec
, NULL
, 0, 16, 8,
2209 speed_template_16
, num_mb
);
2214 test_hash_speed(alg
, sec
, generic_hash_speed_template
);
2219 test_hash_speed("md4", sec
, generic_hash_speed_template
);
2220 if (mode
> 300 && mode
< 400) break;
2223 test_hash_speed("md5", sec
, generic_hash_speed_template
);
2224 if (mode
> 300 && mode
< 400) break;
2227 test_hash_speed("sha1", sec
, generic_hash_speed_template
);
2228 if (mode
> 300 && mode
< 400) break;
2231 test_hash_speed("sha256", sec
, generic_hash_speed_template
);
2232 if (mode
> 300 && mode
< 400) break;
2235 test_hash_speed("sha384", sec
, generic_hash_speed_template
);
2236 if (mode
> 300 && mode
< 400) break;
2239 test_hash_speed("sha512", sec
, generic_hash_speed_template
);
2240 if (mode
> 300 && mode
< 400) break;
2243 test_hash_speed("wp256", sec
, generic_hash_speed_template
);
2244 if (mode
> 300 && mode
< 400) break;
2247 test_hash_speed("wp384", sec
, generic_hash_speed_template
);
2248 if (mode
> 300 && mode
< 400) break;
2251 test_hash_speed("wp512", sec
, generic_hash_speed_template
);
2252 if (mode
> 300 && mode
< 400) break;
2255 test_hash_speed("sha224", sec
, generic_hash_speed_template
);
2256 if (mode
> 300 && mode
< 400) break;
2259 test_hash_speed("xxhash64", sec
, generic_hash_speed_template
);
2260 if (mode
> 300 && mode
< 400) break;
2263 test_hash_speed("rmd160", sec
, generic_hash_speed_template
);
2264 if (mode
> 300 && mode
< 400) break;
2267 test_hash_speed("blake2b-512", sec
, generic_hash_speed_template
);
2268 if (mode
> 300 && mode
< 400) break;
2272 test_hash_speed("ghash", sec
, generic_hash_speed_template
);
2273 if (mode
> 300 && mode
< 400) break;
2276 test_hash_speed("crc32c", sec
, generic_hash_speed_template
);
2277 if (mode
> 300 && mode
< 400) break;
2280 test_hash_speed("crct10dif", sec
, generic_hash_speed_template
);
2281 if (mode
> 300 && mode
< 400) break;
2284 test_hash_speed("poly1305", sec
, poly1305_speed_template
);
2285 if (mode
> 300 && mode
< 400) break;
2288 test_hash_speed("sha3-224", sec
, generic_hash_speed_template
);
2289 if (mode
> 300 && mode
< 400) break;
2292 test_hash_speed("sha3-256", sec
, generic_hash_speed_template
);
2293 if (mode
> 300 && mode
< 400) break;
2296 test_hash_speed("sha3-384", sec
, generic_hash_speed_template
);
2297 if (mode
> 300 && mode
< 400) break;
2300 test_hash_speed("sha3-512", sec
, generic_hash_speed_template
);
2301 if (mode
> 300 && mode
< 400) break;
2304 test_hash_speed("sm3", sec
, generic_hash_speed_template
);
2305 if (mode
> 300 && mode
< 400) break;
2308 test_hash_speed("streebog256", sec
,
2309 generic_hash_speed_template
);
2310 if (mode
> 300 && mode
< 400) break;
2313 test_hash_speed("streebog512", sec
,
2314 generic_hash_speed_template
);
2315 if (mode
> 300 && mode
< 400) break;
2322 test_ahash_speed(alg
, sec
, generic_hash_speed_template
);
2327 test_ahash_speed("md4", sec
, generic_hash_speed_template
);
2328 if (mode
> 400 && mode
< 500) break;
2331 test_ahash_speed("md5", sec
, generic_hash_speed_template
);
2332 if (mode
> 400 && mode
< 500) break;
2335 test_ahash_speed("sha1", sec
, generic_hash_speed_template
);
2336 if (mode
> 400 && mode
< 500) break;
2339 test_ahash_speed("sha256", sec
, generic_hash_speed_template
);
2340 if (mode
> 400 && mode
< 500) break;
2343 test_ahash_speed("sha384", sec
, generic_hash_speed_template
);
2344 if (mode
> 400 && mode
< 500) break;
2347 test_ahash_speed("sha512", sec
, generic_hash_speed_template
);
2348 if (mode
> 400 && mode
< 500) break;
2351 test_ahash_speed("wp256", sec
, generic_hash_speed_template
);
2352 if (mode
> 400 && mode
< 500) break;
2355 test_ahash_speed("wp384", sec
, generic_hash_speed_template
);
2356 if (mode
> 400 && mode
< 500) break;
2359 test_ahash_speed("wp512", sec
, generic_hash_speed_template
);
2360 if (mode
> 400 && mode
< 500) break;
2363 test_ahash_speed("sha224", sec
, generic_hash_speed_template
);
2364 if (mode
> 400 && mode
< 500) break;
2367 test_ahash_speed("xxhash64", sec
, generic_hash_speed_template
);
2368 if (mode
> 400 && mode
< 500) break;
2371 test_ahash_speed("rmd160", sec
, generic_hash_speed_template
);
2372 if (mode
> 400 && mode
< 500) break;
2375 test_ahash_speed("blake2b-512", sec
, generic_hash_speed_template
);
2376 if (mode
> 400 && mode
< 500) break;
2379 test_ahash_speed("sha3-224", sec
, generic_hash_speed_template
);
2380 if (mode
> 400 && mode
< 500) break;
2383 test_ahash_speed("sha3-256", sec
, generic_hash_speed_template
);
2384 if (mode
> 400 && mode
< 500) break;
2387 test_ahash_speed("sha3-384", sec
, generic_hash_speed_template
);
2388 if (mode
> 400 && mode
< 500) break;
2391 test_ahash_speed("sha3-512", sec
, generic_hash_speed_template
);
2392 if (mode
> 400 && mode
< 500) break;
2395 test_ahash_speed("sm3", sec
, generic_hash_speed_template
);
2396 if (mode
> 400 && mode
< 500) break;
2402 test_acipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
2403 speed_template_16_24_32
);
2404 test_acipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
2405 speed_template_16_24_32
);
2406 test_acipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
2407 speed_template_16_24_32
);
2408 test_acipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
2409 speed_template_16_24_32
);
2410 test_acipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
2411 speed_template_32_40_48
);
2412 test_acipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
2413 speed_template_32_40_48
);
2414 test_acipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
2415 speed_template_32_64
);
2416 test_acipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
2417 speed_template_32_64
);
2418 test_acipher_speed("cts(cbc(aes))", ENCRYPT
, sec
, NULL
, 0,
2419 speed_template_16_24_32
);
2420 test_acipher_speed("cts(cbc(aes))", DECRYPT
, sec
, NULL
, 0,
2421 speed_template_16_24_32
);
2422 test_acipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
2423 speed_template_16_24_32
);
2424 test_acipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
2425 speed_template_16_24_32
);
2426 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT
, sec
, NULL
, 0,
2427 speed_template_20_28_36
);
2428 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT
, sec
, NULL
, 0,
2429 speed_template_20_28_36
);
2433 test_acipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
2434 des3_speed_template
, DES3_SPEED_VECTORS
,
2436 test_acipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
2437 des3_speed_template
, DES3_SPEED_VECTORS
,
2439 test_acipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
2440 des3_speed_template
, DES3_SPEED_VECTORS
,
2442 test_acipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
2443 des3_speed_template
, DES3_SPEED_VECTORS
,
2448 test_acipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
2450 test_acipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
2452 test_acipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
2454 test_acipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
2459 test_acipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
2460 speed_template_16_32
);
2461 test_acipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
2462 speed_template_16_32
);
2463 test_acipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
2464 speed_template_16_32
);
2465 test_acipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
2466 speed_template_16_32
);
2467 test_acipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
2468 speed_template_16_32
);
2469 test_acipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
2470 speed_template_16_32
);
2471 test_acipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
2472 speed_template_32_48
);
2473 test_acipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
2474 speed_template_32_48
);
2475 test_acipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
2476 speed_template_32_64
);
2477 test_acipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
2478 speed_template_32_64
);
2482 test_acipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
2483 speed_template_16_24_32
);
2484 test_acipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
2485 speed_template_16_24_32
);
2486 test_acipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
2487 speed_template_16_24_32
);
2488 test_acipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
2489 speed_template_16_24_32
);
2490 test_acipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
2491 speed_template_16_24_32
);
2492 test_acipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
2493 speed_template_16_24_32
);
2494 test_acipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
2495 speed_template_32_40_48
);
2496 test_acipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
2497 speed_template_32_40_48
);
2498 test_acipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
2499 speed_template_32_48_64
);
2500 test_acipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
2501 speed_template_32_48_64
);
2505 test_acipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
2510 test_acipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
2511 speed_template_8_16
);
2512 test_acipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
2513 speed_template_8_16
);
2514 test_acipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
2515 speed_template_8_16
);
2516 test_acipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
2517 speed_template_8_16
);
2518 test_acipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
2519 speed_template_8_16
);
2520 test_acipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
2521 speed_template_8_16
);
2525 test_acipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
2526 speed_template_16_32
);
2527 test_acipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
2528 speed_template_16_32
);
2529 test_acipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
2530 speed_template_16_32
);
2531 test_acipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
2532 speed_template_16_32
);
2533 test_acipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
2534 speed_template_16_32
);
2535 test_acipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
2536 speed_template_16_32
);
2537 test_acipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
2538 speed_template_32_48
);
2539 test_acipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
2540 speed_template_32_48
);
2541 test_acipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
2542 speed_template_32_64
);
2543 test_acipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
2544 speed_template_32_64
);
2548 test_acipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
2549 speed_template_16_32
);
2550 test_acipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
2551 speed_template_16_32
);
2552 test_acipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
2553 speed_template_16_32
);
2554 test_acipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
2555 speed_template_16_32
);
2556 test_acipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
2557 speed_template_16_32
);
2558 test_acipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
2559 speed_template_16_32
);
2560 test_acipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
2561 speed_template_32_48
);
2562 test_acipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
2563 speed_template_32_48
);
2564 test_acipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
2565 speed_template_32_64
);
2566 test_acipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
2567 speed_template_32_64
);
2571 test_acipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2572 speed_template_8_32
);
2573 test_acipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
2574 speed_template_8_32
);
2575 test_acipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2576 speed_template_8_32
);
2577 test_acipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
2578 speed_template_8_32
);
2579 test_acipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2580 speed_template_8_32
);
2581 test_acipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
2582 speed_template_8_32
);
2586 test_acipher_speed("ecb(sm4)", ENCRYPT
, sec
, NULL
, 0,
2588 test_acipher_speed("ecb(sm4)", DECRYPT
, sec
, NULL
, 0,
2590 test_acipher_speed("cbc(sm4)", ENCRYPT
, sec
, NULL
, 0,
2592 test_acipher_speed("cbc(sm4)", DECRYPT
, sec
, NULL
, 0,
2594 test_acipher_speed("ctr(sm4)", ENCRYPT
, sec
, NULL
, 0,
2596 test_acipher_speed("ctr(sm4)", DECRYPT
, sec
, NULL
, 0,
2598 test_acipher_speed("xts(sm4)", ENCRYPT
, sec
, NULL
, 0,
2600 test_acipher_speed("xts(sm4)", DECRYPT
, sec
, NULL
, 0,
2605 test_acipher_speed("ecb(aria)", ENCRYPT
, sec
, NULL
, 0,
2606 speed_template_16_24_32
);
2607 test_acipher_speed("ecb(aria)", DECRYPT
, sec
, NULL
, 0,
2608 speed_template_16_24_32
);
2609 test_acipher_speed("ctr(aria)", ENCRYPT
, sec
, NULL
, 0,
2610 speed_template_16_24_32
);
2611 test_acipher_speed("ctr(aria)", DECRYPT
, sec
, NULL
, 0,
2612 speed_template_16_24_32
);
2617 u8 speed_template
[2] = {klen
, 0};
2618 test_mb_skcipher_speed(alg
, ENCRYPT
, sec
, NULL
, 0,
2619 speed_template
, num_mb
);
2620 test_mb_skcipher_speed(alg
, DECRYPT
, sec
, NULL
, 0,
2621 speed_template
, num_mb
);
2625 test_mb_skcipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
2626 speed_template_16_24_32
, num_mb
);
2627 test_mb_skcipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
2628 speed_template_16_24_32
, num_mb
);
2629 test_mb_skcipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
2630 speed_template_16_24_32
, num_mb
);
2631 test_mb_skcipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
2632 speed_template_16_24_32
, num_mb
);
2633 test_mb_skcipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
2634 speed_template_32_40_48
, num_mb
);
2635 test_mb_skcipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
2636 speed_template_32_40_48
, num_mb
);
2637 test_mb_skcipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
2638 speed_template_32_64
, num_mb
);
2639 test_mb_skcipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
2640 speed_template_32_64
, num_mb
);
2641 test_mb_skcipher_speed("cts(cbc(aes))", ENCRYPT
, sec
, NULL
, 0,
2642 speed_template_16_24_32
, num_mb
);
2643 test_mb_skcipher_speed("cts(cbc(aes))", DECRYPT
, sec
, NULL
, 0,
2644 speed_template_16_24_32
, num_mb
);
2645 test_mb_skcipher_speed("ctr(aes)", ENCRYPT
, sec
, NULL
, 0,
2646 speed_template_16_24_32
, num_mb
);
2647 test_mb_skcipher_speed("ctr(aes)", DECRYPT
, sec
, NULL
, 0,
2648 speed_template_16_24_32
, num_mb
);
2649 test_mb_skcipher_speed("rfc3686(ctr(aes))", ENCRYPT
, sec
, NULL
,
2650 0, speed_template_20_28_36
, num_mb
);
2651 test_mb_skcipher_speed("rfc3686(ctr(aes))", DECRYPT
, sec
, NULL
,
2652 0, speed_template_20_28_36
, num_mb
);
2656 test_mb_skcipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
2657 des3_speed_template
, DES3_SPEED_VECTORS
,
2658 speed_template_24
, num_mb
);
2659 test_mb_skcipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
2660 des3_speed_template
, DES3_SPEED_VECTORS
,
2661 speed_template_24
, num_mb
);
2662 test_mb_skcipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
2663 des3_speed_template
, DES3_SPEED_VECTORS
,
2664 speed_template_24
, num_mb
);
2665 test_mb_skcipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
2666 des3_speed_template
, DES3_SPEED_VECTORS
,
2667 speed_template_24
, num_mb
);
2671 test_mb_skcipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
2672 speed_template_8
, num_mb
);
2673 test_mb_skcipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
2674 speed_template_8
, num_mb
);
2675 test_mb_skcipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
2676 speed_template_8
, num_mb
);
2677 test_mb_skcipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
2678 speed_template_8
, num_mb
);
2682 test_mb_skcipher_speed("ecb(serpent)", ENCRYPT
, sec
, NULL
, 0,
2683 speed_template_16_32
, num_mb
);
2684 test_mb_skcipher_speed("ecb(serpent)", DECRYPT
, sec
, NULL
, 0,
2685 speed_template_16_32
, num_mb
);
2686 test_mb_skcipher_speed("cbc(serpent)", ENCRYPT
, sec
, NULL
, 0,
2687 speed_template_16_32
, num_mb
);
2688 test_mb_skcipher_speed("cbc(serpent)", DECRYPT
, sec
, NULL
, 0,
2689 speed_template_16_32
, num_mb
);
2690 test_mb_skcipher_speed("ctr(serpent)", ENCRYPT
, sec
, NULL
, 0,
2691 speed_template_16_32
, num_mb
);
2692 test_mb_skcipher_speed("ctr(serpent)", DECRYPT
, sec
, NULL
, 0,
2693 speed_template_16_32
, num_mb
);
2694 test_mb_skcipher_speed("lrw(serpent)", ENCRYPT
, sec
, NULL
, 0,
2695 speed_template_32_48
, num_mb
);
2696 test_mb_skcipher_speed("lrw(serpent)", DECRYPT
, sec
, NULL
, 0,
2697 speed_template_32_48
, num_mb
);
2698 test_mb_skcipher_speed("xts(serpent)", ENCRYPT
, sec
, NULL
, 0,
2699 speed_template_32_64
, num_mb
);
2700 test_mb_skcipher_speed("xts(serpent)", DECRYPT
, sec
, NULL
, 0,
2701 speed_template_32_64
, num_mb
);
2705 test_mb_skcipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
2706 speed_template_16_24_32
, num_mb
);
2707 test_mb_skcipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
2708 speed_template_16_24_32
, num_mb
);
2709 test_mb_skcipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
2710 speed_template_16_24_32
, num_mb
);
2711 test_mb_skcipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
2712 speed_template_16_24_32
, num_mb
);
2713 test_mb_skcipher_speed("ctr(twofish)", ENCRYPT
, sec
, NULL
, 0,
2714 speed_template_16_24_32
, num_mb
);
2715 test_mb_skcipher_speed("ctr(twofish)", DECRYPT
, sec
, NULL
, 0,
2716 speed_template_16_24_32
, num_mb
);
2717 test_mb_skcipher_speed("lrw(twofish)", ENCRYPT
, sec
, NULL
, 0,
2718 speed_template_32_40_48
, num_mb
);
2719 test_mb_skcipher_speed("lrw(twofish)", DECRYPT
, sec
, NULL
, 0,
2720 speed_template_32_40_48
, num_mb
);
2721 test_mb_skcipher_speed("xts(twofish)", ENCRYPT
, sec
, NULL
, 0,
2722 speed_template_32_48_64
, num_mb
);
2723 test_mb_skcipher_speed("xts(twofish)", DECRYPT
, sec
, NULL
, 0,
2724 speed_template_32_48_64
, num_mb
);
2728 test_mb_skcipher_speed("ecb(arc4)", ENCRYPT
, sec
, NULL
, 0,
2729 speed_template_8
, num_mb
);
2733 test_mb_skcipher_speed("ecb(cast5)", ENCRYPT
, sec
, NULL
, 0,
2734 speed_template_8_16
, num_mb
);
2735 test_mb_skcipher_speed("ecb(cast5)", DECRYPT
, sec
, NULL
, 0,
2736 speed_template_8_16
, num_mb
);
2737 test_mb_skcipher_speed("cbc(cast5)", ENCRYPT
, sec
, NULL
, 0,
2738 speed_template_8_16
, num_mb
);
2739 test_mb_skcipher_speed("cbc(cast5)", DECRYPT
, sec
, NULL
, 0,
2740 speed_template_8_16
, num_mb
);
2741 test_mb_skcipher_speed("ctr(cast5)", ENCRYPT
, sec
, NULL
, 0,
2742 speed_template_8_16
, num_mb
);
2743 test_mb_skcipher_speed("ctr(cast5)", DECRYPT
, sec
, NULL
, 0,
2744 speed_template_8_16
, num_mb
);
2748 test_mb_skcipher_speed("ecb(cast6)", ENCRYPT
, sec
, NULL
, 0,
2749 speed_template_16_32
, num_mb
);
2750 test_mb_skcipher_speed("ecb(cast6)", DECRYPT
, sec
, NULL
, 0,
2751 speed_template_16_32
, num_mb
);
2752 test_mb_skcipher_speed("cbc(cast6)", ENCRYPT
, sec
, NULL
, 0,
2753 speed_template_16_32
, num_mb
);
2754 test_mb_skcipher_speed("cbc(cast6)", DECRYPT
, sec
, NULL
, 0,
2755 speed_template_16_32
, num_mb
);
2756 test_mb_skcipher_speed("ctr(cast6)", ENCRYPT
, sec
, NULL
, 0,
2757 speed_template_16_32
, num_mb
);
2758 test_mb_skcipher_speed("ctr(cast6)", DECRYPT
, sec
, NULL
, 0,
2759 speed_template_16_32
, num_mb
);
2760 test_mb_skcipher_speed("lrw(cast6)", ENCRYPT
, sec
, NULL
, 0,
2761 speed_template_32_48
, num_mb
);
2762 test_mb_skcipher_speed("lrw(cast6)", DECRYPT
, sec
, NULL
, 0,
2763 speed_template_32_48
, num_mb
);
2764 test_mb_skcipher_speed("xts(cast6)", ENCRYPT
, sec
, NULL
, 0,
2765 speed_template_32_64
, num_mb
);
2766 test_mb_skcipher_speed("xts(cast6)", DECRYPT
, sec
, NULL
, 0,
2767 speed_template_32_64
, num_mb
);
2771 test_mb_skcipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
2772 speed_template_16_32
, num_mb
);
2773 test_mb_skcipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
2774 speed_template_16_32
, num_mb
);
2775 test_mb_skcipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
2776 speed_template_16_32
, num_mb
);
2777 test_mb_skcipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
2778 speed_template_16_32
, num_mb
);
2779 test_mb_skcipher_speed("ctr(camellia)", ENCRYPT
, sec
, NULL
, 0,
2780 speed_template_16_32
, num_mb
);
2781 test_mb_skcipher_speed("ctr(camellia)", DECRYPT
, sec
, NULL
, 0,
2782 speed_template_16_32
, num_mb
);
2783 test_mb_skcipher_speed("lrw(camellia)", ENCRYPT
, sec
, NULL
, 0,
2784 speed_template_32_48
, num_mb
);
2785 test_mb_skcipher_speed("lrw(camellia)", DECRYPT
, sec
, NULL
, 0,
2786 speed_template_32_48
, num_mb
);
2787 test_mb_skcipher_speed("xts(camellia)", ENCRYPT
, sec
, NULL
, 0,
2788 speed_template_32_64
, num_mb
);
2789 test_mb_skcipher_speed("xts(camellia)", DECRYPT
, sec
, NULL
, 0,
2790 speed_template_32_64
, num_mb
);
2794 test_mb_skcipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2795 speed_template_8_32
, num_mb
);
2796 test_mb_skcipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
2797 speed_template_8_32
, num_mb
);
2798 test_mb_skcipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2799 speed_template_8_32
, num_mb
);
2800 test_mb_skcipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
2801 speed_template_8_32
, num_mb
);
2802 test_mb_skcipher_speed("ctr(blowfish)", ENCRYPT
, sec
, NULL
, 0,
2803 speed_template_8_32
, num_mb
);
2804 test_mb_skcipher_speed("ctr(blowfish)", DECRYPT
, sec
, NULL
, 0,
2805 speed_template_8_32
, num_mb
);
2809 test_mb_skcipher_speed("ecb(aria)", ENCRYPT
, sec
, NULL
, 0,
2810 speed_template_16_32
, num_mb
);
2811 test_mb_skcipher_speed("ecb(aria)", DECRYPT
, sec
, NULL
, 0,
2812 speed_template_16_32
, num_mb
);
2813 test_mb_skcipher_speed("ctr(aria)", ENCRYPT
, sec
, NULL
, 0,
2814 speed_template_16_32
, num_mb
);
2815 test_mb_skcipher_speed("ctr(aria)", DECRYPT
, sec
, NULL
, 0,
2816 speed_template_16_32
, num_mb
);
2824 static int __init
tcrypt_mod_init(void)
2829 for (i
= 0; i
< TVMEMSIZE
; i
++) {
2830 tvmem
[i
] = (void *)__get_free_page(GFP_KERNEL
);
2835 err
= do_test(alg
, type
, mask
, mode
, num_mb
);
2838 pr_err("one or more tests failed!\n");
2841 pr_debug("all tests passed\n");
2844 /* We intentionaly return -EAGAIN to prevent keeping the module,
2845 * unless we're running in fips mode. It does all its work from
2846 * init() and doesn't offer any runtime functionality, but in
2847 * the fips case, checking for a successful load is helpful.
2848 * => we don't need it in the memory, do we?
2855 for (i
= 0; i
< TVMEMSIZE
&& tvmem
[i
]; i
++)
2856 free_page((unsigned long)tvmem
[i
]);
2862 * If an init function is provided, an exit function must also be provided
2863 * to allow module unload.
2865 static void __exit
tcrypt_mod_fini(void) { }
2867 late_initcall(tcrypt_mod_init
);
2868 module_exit(tcrypt_mod_fini
);
2870 module_param(alg
, charp
, 0);
2871 module_param(type
, uint
, 0);
2872 module_param(mask
, uint
, 0);
2873 module_param(mode
, int, 0);
2874 module_param(sec
, uint
, 0);
2875 MODULE_PARM_DESC(sec
, "Length in seconds of speed tests "
2876 "(defaults to zero which uses CPU cycles instead)");
2877 module_param(num_mb
, uint
, 0000);
2878 MODULE_PARM_DESC(num_mb
, "Number of concurrent requests to be used in mb speed tests (defaults to 8)");
2879 module_param(klen
, uint
, 0);
2880 MODULE_PARM_DESC(klen
, "Key length (defaults to 0)");
2882 MODULE_LICENSE("GPL");
2883 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2884 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");