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/gfp.h>
29 #include <linux/module.h>
30 #include <linux/scatterlist.h>
31 #include <linux/string.h>
32 #include <linux/moduleparam.h>
33 #include <linux/jiffies.h>
34 #include <linux/timex.h>
35 #include <linux/interrupt.h>
39 * Need slab memory for testing (size in number of pages).
44 * Used by test_cipher_speed()
49 #define MAX_DIGEST_SIZE 64
52 * return a string with the driver name
54 #define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm))
57 * Used by test_cipher_speed()
59 static unsigned int sec;
61 static char *alg = NULL;
65 static u32 num_mb = 8;
66 static unsigned int klen;
67 static char *tvmem[TVMEMSIZE];
69 static const char *check[] = {
70 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", "sm3",
71 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
72 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
73 "khazad", "wp512", "wp384", "wp256", "xeta", "fcrypt",
74 "camellia", "seed", "rmd160",
75 "lzo", "lzo-rle", "cts", "sha3-224", "sha3-256", "sha3-384",
76 "sha3-512", "streebog256", "streebog512",
80 static const int block_sizes[] = { 16, 64, 128, 256, 1024, 1420, 4096, 0 };
81 static const int aead_sizes[] = { 16, 64, 256, 512, 1024, 1420, 4096, 8192, 0 };
86 static int testmgr_alloc_buf(char *buf[XBUFSIZE])
90 for (i = 0; i < XBUFSIZE; i++) {
91 buf[i] = (void *)__get_free_page(GFP_KERNEL);
100 free_page((unsigned long)buf[i]);
105 static void testmgr_free_buf(char *buf[XBUFSIZE])
109 for (i = 0; i < XBUFSIZE; i++)
110 free_page((unsigned long)buf[i]);
113 static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],
114 unsigned int buflen, const void *assoc,
115 unsigned int aad_size)
117 int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
124 rem = buflen % PAGE_SIZE;
127 sg_init_table(sg, np + 1);
129 sg_set_buf(&sg[0], assoc, aad_size);
133 for (k = 0; k < np; k++)
134 sg_set_buf(&sg[k + 1], xbuf[k], PAGE_SIZE);
137 sg_set_buf(&sg[k + 1], xbuf[k], rem);
140 static inline int do_one_aead_op(struct aead_request *req, int ret)
142 struct crypto_wait *wait = req->base.data;
144 return crypto_wait_req(ret, wait);
147 struct test_mb_aead_data {
148 struct scatterlist sg[XBUFSIZE];
149 struct scatterlist sgout[XBUFSIZE];
150 struct aead_request *req;
151 struct crypto_wait wait;
152 char *xbuf[XBUFSIZE];
153 char *xoutbuf[XBUFSIZE];
154 char *axbuf[XBUFSIZE];
157 static int do_mult_aead_op(struct test_mb_aead_data *data, int enc,
162 /* Fire up a bunch of concurrent requests */
163 for (i = 0; i < num_mb; i++) {
165 rc[i] = crypto_aead_encrypt(data[i].req);
167 rc[i] = crypto_aead_decrypt(data[i].req);
170 /* Wait for all requests to finish */
171 for (i = 0; i < num_mb; i++) {
172 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
175 pr_info("concurrent request %d error %d\n", i, rc[i]);
183 static int test_mb_aead_jiffies(struct test_mb_aead_data *data, int enc,
184 int blen, int secs, u32 num_mb)
186 unsigned long start, end;
191 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
195 for (start = jiffies, end = start + secs * HZ, bcount = 0;
196 time_before(jiffies, end); bcount++) {
197 ret = do_mult_aead_op(data, enc, num_mb, rc);
202 pr_cont("%d operations in %d seconds (%llu bytes)\n",
203 bcount * num_mb, secs, (u64)bcount * blen * num_mb);
210 static int test_mb_aead_cycles(struct test_mb_aead_data *data, int enc,
211 int blen, u32 num_mb)
213 unsigned long cycles = 0;
218 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
223 for (i = 0; i < 4; i++) {
224 ret = do_mult_aead_op(data, enc, num_mb, rc);
229 /* The real thing. */
230 for (i = 0; i < 8; i++) {
233 start = get_cycles();
234 ret = do_mult_aead_op(data, enc, num_mb, rc);
240 cycles += end - start;
243 pr_cont("1 operation in %lu cycles (%d bytes)\n",
244 (cycles + 4) / (8 * num_mb), blen);
251 static void test_mb_aead_speed(const char *algo, int enc, int secs,
252 struct aead_speed_template *template,
253 unsigned int tcount, u8 authsize,
254 unsigned int aad_size, u8 *keysize, u32 num_mb)
256 struct test_mb_aead_data *data;
257 struct crypto_aead *tfm;
258 unsigned int i, j, iv_len;
267 if (aad_size >= PAGE_SIZE) {
268 pr_err("associate data length (%u) too big\n", aad_size);
272 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
281 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
285 tfm = crypto_alloc_aead(algo, 0, 0);
287 pr_err("failed to load transform for %s: %ld\n",
292 ret = crypto_aead_setauthsize(tfm, authsize);
294 pr_err("alg: aead: Failed to setauthsize for %s: %d\n", algo,
299 for (i = 0; i < num_mb; ++i)
300 if (testmgr_alloc_buf(data[i].xbuf)) {
302 testmgr_free_buf(data[i].xbuf);
306 for (i = 0; i < num_mb; ++i)
307 if (testmgr_alloc_buf(data[i].axbuf)) {
309 testmgr_free_buf(data[i].axbuf);
313 for (i = 0; i < num_mb; ++i)
314 if (testmgr_alloc_buf(data[i].xoutbuf)) {
316 testmgr_free_buf(data[i].xoutbuf);
320 for (i = 0; i < num_mb; ++i) {
321 data[i].req = aead_request_alloc(tfm, GFP_KERNEL);
323 pr_err("alg: aead: Failed to allocate request for %s\n",
326 aead_request_free(data[i].req);
327 goto out_free_xoutbuf;
331 for (i = 0; i < num_mb; ++i) {
332 crypto_init_wait(&data[i].wait);
333 aead_request_set_callback(data[i].req,
334 CRYPTO_TFM_REQ_MAY_BACKLOG,
335 crypto_req_done, &data[i].wait);
338 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo,
339 get_driver_name(crypto_aead, tfm), e);
345 int bs = round_up(*b_size, crypto_aead_blocksize(tfm));
347 if (bs + authsize > XBUFSIZE * PAGE_SIZE) {
348 pr_err("template (%u) too big for buffer (%lu)\n",
350 XBUFSIZE * PAGE_SIZE);
354 pr_info("test %u (%d bit key, %d byte blocks): ", i,
357 /* Set up tfm global state, i.e. the key */
359 memset(tvmem[0], 0xff, PAGE_SIZE);
361 for (j = 0; j < tcount; j++) {
362 if (template[j].klen == *keysize) {
363 key = template[j].key;
368 crypto_aead_clear_flags(tfm, ~0);
370 ret = crypto_aead_setkey(tfm, key, *keysize);
372 pr_err("setkey() failed flags=%x\n",
373 crypto_aead_get_flags(tfm));
377 iv_len = crypto_aead_ivsize(tfm);
379 memset(iv, 0xff, iv_len);
381 /* Now setup per request stuff, i.e. buffers */
383 for (j = 0; j < num_mb; ++j) {
384 struct test_mb_aead_data *cur = &data[j];
386 assoc = cur->axbuf[0];
387 memset(assoc, 0xff, aad_size);
389 sg_init_aead(cur->sg, cur->xbuf,
390 bs + (enc ? 0 : authsize),
393 sg_init_aead(cur->sgout, cur->xoutbuf,
394 bs + (enc ? authsize : 0),
397 aead_request_set_ad(cur->req, aad_size);
401 aead_request_set_crypt(cur->req,
405 ret = crypto_aead_encrypt(cur->req);
406 ret = do_one_aead_op(cur->req, ret);
409 pr_err("calculating auth failed (%d)\n",
415 aead_request_set_crypt(cur->req, cur->sg,
417 (enc ? 0 : authsize),
423 ret = test_mb_aead_jiffies(data, enc, bs,
427 ret = test_mb_aead_cycles(data, enc, bs,
432 pr_err("%s() failed return code=%d\n", e, ret);
442 for (i = 0; i < num_mb; ++i)
443 aead_request_free(data[i].req);
445 for (i = 0; i < num_mb; ++i)
446 testmgr_free_buf(data[i].xoutbuf);
448 for (i = 0; i < num_mb; ++i)
449 testmgr_free_buf(data[i].axbuf);
451 for (i = 0; i < num_mb; ++i)
452 testmgr_free_buf(data[i].xbuf);
454 crypto_free_aead(tfm);
461 static int test_aead_jiffies(struct aead_request *req, int enc,
464 unsigned long start, end;
468 for (start = jiffies, end = start + secs * HZ, bcount = 0;
469 time_before(jiffies, end); bcount++) {
471 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
473 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
479 pr_cont("%d operations in %d seconds (%llu bytes)\n",
480 bcount, secs, (u64)bcount * blen);
484 static int test_aead_cycles(struct aead_request *req, int enc, int blen)
486 unsigned long cycles = 0;
491 for (i = 0; i < 4; i++) {
493 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
495 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
501 /* The real thing. */
502 for (i = 0; i < 8; i++) {
505 start = get_cycles();
507 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
509 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
515 cycles += end - start;
520 printk("1 operation in %lu cycles (%d bytes)\n",
521 (cycles + 4) / 8, blen);
526 static void test_aead_speed(const char *algo, int enc, unsigned int secs,
527 struct aead_speed_template *template,
528 unsigned int tcount, u8 authsize,
529 unsigned int aad_size, u8 *keysize)
532 struct crypto_aead *tfm;
535 struct aead_request *req;
536 struct scatterlist *sg;
537 struct scatterlist *sgout;
541 char *xbuf[XBUFSIZE];
542 char *xoutbuf[XBUFSIZE];
543 char *axbuf[XBUFSIZE];
546 struct crypto_wait wait;
548 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
552 if (aad_size >= PAGE_SIZE) {
553 pr_err("associate data length (%u) too big\n", aad_size);
562 if (testmgr_alloc_buf(xbuf))
564 if (testmgr_alloc_buf(axbuf))
566 if (testmgr_alloc_buf(xoutbuf))
569 sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL);
574 tfm = crypto_alloc_aead(algo, 0, 0);
576 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
581 ret = crypto_aead_setauthsize(tfm, authsize);
583 pr_err("alg: aead: Failed to setauthsize for %s: %d\n", algo,
588 crypto_init_wait(&wait);
589 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
590 get_driver_name(crypto_aead, tfm), e);
592 req = aead_request_alloc(tfm, GFP_KERNEL);
594 pr_err("alg: aead: Failed to allocate request for %s\n",
599 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
600 crypto_req_done, &wait);
606 u32 bs = round_up(*b_size, crypto_aead_blocksize(tfm));
609 memset(assoc, 0xff, aad_size);
611 if ((*keysize + bs) > TVMEMSIZE * PAGE_SIZE) {
612 pr_err("template (%u) too big for tvmem (%lu)\n",
614 TVMEMSIZE * PAGE_SIZE);
619 for (j = 0; j < tcount; j++) {
620 if (template[j].klen == *keysize) {
621 key = template[j].key;
626 ret = crypto_aead_setkey(tfm, key, *keysize);
628 pr_err("setkey() failed flags=%x: %d\n",
629 crypto_aead_get_flags(tfm), ret);
633 iv_len = crypto_aead_ivsize(tfm);
635 memset(iv, 0xff, iv_len);
637 crypto_aead_clear_flags(tfm, ~0);
638 printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
639 i, *keysize * 8, bs);
641 memset(tvmem[0], 0xff, PAGE_SIZE);
643 sg_init_aead(sg, xbuf, bs + (enc ? 0 : authsize),
646 sg_init_aead(sgout, xoutbuf,
647 bs + (enc ? authsize : 0), assoc,
650 aead_request_set_ad(req, aad_size);
655 * For decryption we need a proper auth so
656 * we do the encryption path once with buffers
657 * reversed (input <-> output) to calculate it
659 aead_request_set_crypt(req, sgout, sg,
661 ret = do_one_aead_op(req,
662 crypto_aead_encrypt(req));
665 pr_err("calculating auth failed (%d)\n",
671 aead_request_set_crypt(req, sg, sgout,
672 bs + (enc ? 0 : authsize),
676 ret = test_aead_jiffies(req, enc, bs,
680 ret = test_aead_cycles(req, enc, bs);
684 pr_err("%s() failed return code=%d\n", e, ret);
694 aead_request_free(req);
696 crypto_free_aead(tfm);
700 testmgr_free_buf(xoutbuf);
702 testmgr_free_buf(axbuf);
704 testmgr_free_buf(xbuf);
709 static void test_hash_sg_init(struct scatterlist *sg)
713 sg_init_table(sg, TVMEMSIZE);
714 for (i = 0; i < TVMEMSIZE; i++) {
715 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
716 memset(tvmem[i], 0xff, PAGE_SIZE);
720 static inline int do_one_ahash_op(struct ahash_request *req, int ret)
722 struct crypto_wait *wait = req->base.data;
724 return crypto_wait_req(ret, wait);
727 struct test_mb_ahash_data {
728 struct scatterlist sg[XBUFSIZE];
730 struct ahash_request *req;
731 struct crypto_wait wait;
732 char *xbuf[XBUFSIZE];
735 static inline int do_mult_ahash_op(struct test_mb_ahash_data *data, u32 num_mb,
740 /* Fire up a bunch of concurrent requests */
741 for (i = 0; i < num_mb; i++)
742 rc[i] = crypto_ahash_digest(data[i].req);
744 /* Wait for all requests to finish */
745 for (i = 0; i < num_mb; i++) {
746 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
749 pr_info("concurrent request %d error %d\n", i, rc[i]);
757 static int test_mb_ahash_jiffies(struct test_mb_ahash_data *data, int blen,
758 int secs, u32 num_mb)
760 unsigned long start, end;
765 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
769 for (start = jiffies, end = start + secs * HZ, bcount = 0;
770 time_before(jiffies, end); bcount++) {
771 ret = do_mult_ahash_op(data, num_mb, rc);
776 pr_cont("%d operations in %d seconds (%llu bytes)\n",
777 bcount * num_mb, secs, (u64)bcount * blen * num_mb);
784 static int test_mb_ahash_cycles(struct test_mb_ahash_data *data, int blen,
787 unsigned long cycles = 0;
792 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
797 for (i = 0; i < 4; i++) {
798 ret = do_mult_ahash_op(data, num_mb, rc);
803 /* The real thing. */
804 for (i = 0; i < 8; i++) {
807 start = get_cycles();
808 ret = do_mult_ahash_op(data, num_mb, rc);
814 cycles += end - start;
817 pr_cont("1 operation in %lu cycles (%d bytes)\n",
818 (cycles + 4) / (8 * num_mb), blen);
825 static void test_mb_ahash_speed(const char *algo, unsigned int secs,
826 struct hash_speed *speed, u32 num_mb)
828 struct test_mb_ahash_data *data;
829 struct crypto_ahash *tfm;
830 unsigned int i, j, k;
833 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
837 tfm = crypto_alloc_ahash(algo, 0, 0);
839 pr_err("failed to load transform for %s: %ld\n",
844 for (i = 0; i < num_mb; ++i) {
845 if (testmgr_alloc_buf(data[i].xbuf))
848 crypto_init_wait(&data[i].wait);
850 data[i].req = ahash_request_alloc(tfm, GFP_KERNEL);
852 pr_err("alg: hash: Failed to allocate request for %s\n",
857 ahash_request_set_callback(data[i].req, 0, crypto_req_done,
860 sg_init_table(data[i].sg, XBUFSIZE);
861 for (j = 0; j < XBUFSIZE; j++) {
862 sg_set_buf(data[i].sg + j, data[i].xbuf[j], PAGE_SIZE);
863 memset(data[i].xbuf[j], 0xff, PAGE_SIZE);
867 pr_info("\ntesting speed of multibuffer %s (%s)\n", algo,
868 get_driver_name(crypto_ahash, tfm));
870 for (i = 0; speed[i].blen != 0; i++) {
871 /* For some reason this only tests digests. */
872 if (speed[i].blen != speed[i].plen)
875 if (speed[i].blen > XBUFSIZE * PAGE_SIZE) {
876 pr_err("template (%u) too big for tvmem (%lu)\n",
877 speed[i].blen, XBUFSIZE * PAGE_SIZE);
882 crypto_ahash_setkey(tfm, tvmem[0], klen);
884 for (k = 0; k < num_mb; k++)
885 ahash_request_set_crypt(data[k].req, data[k].sg,
886 data[k].result, speed[i].blen);
889 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
890 i, speed[i].blen, speed[i].plen,
891 speed[i].blen / speed[i].plen);
894 ret = test_mb_ahash_jiffies(data, speed[i].blen, secs,
898 ret = test_mb_ahash_cycles(data, speed[i].blen, num_mb);
903 pr_err("At least one hashing failed ret=%d\n", ret);
909 for (k = 0; k < num_mb; ++k)
910 ahash_request_free(data[k].req);
912 for (k = 0; k < num_mb; ++k)
913 testmgr_free_buf(data[k].xbuf);
915 crypto_free_ahash(tfm);
921 static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
924 unsigned long start, end;
928 for (start = jiffies, end = start + secs * HZ, bcount = 0;
929 time_before(jiffies, end); bcount++) {
930 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
935 printk("%6u opers/sec, %9lu bytes/sec\n",
936 bcount / secs, ((long)bcount * blen) / secs);
941 static int test_ahash_jiffies(struct ahash_request *req, int blen,
942 int plen, char *out, int secs)
944 unsigned long start, end;
949 return test_ahash_jiffies_digest(req, blen, out, secs);
951 for (start = jiffies, end = start + secs * HZ, bcount = 0;
952 time_before(jiffies, end); bcount++) {
953 ret = do_one_ahash_op(req, crypto_ahash_init(req));
956 for (pcount = 0; pcount < blen; pcount += plen) {
957 ret = do_one_ahash_op(req, crypto_ahash_update(req));
961 /* we assume there is enough space in 'out' for the result */
962 ret = do_one_ahash_op(req, crypto_ahash_final(req));
967 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
968 bcount / secs, ((long)bcount * blen) / secs);
973 static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
976 unsigned long cycles = 0;
980 for (i = 0; i < 4; i++) {
981 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
986 /* The real thing. */
987 for (i = 0; i < 8; i++) {
990 start = get_cycles();
992 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
998 cycles += end - start;
1005 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
1006 cycles / 8, cycles / (8 * blen));
1011 static int test_ahash_cycles(struct ahash_request *req, int blen,
1012 int plen, char *out)
1014 unsigned long cycles = 0;
1018 return test_ahash_cycles_digest(req, blen, out);
1021 for (i = 0; i < 4; i++) {
1022 ret = do_one_ahash_op(req, crypto_ahash_init(req));
1025 for (pcount = 0; pcount < blen; pcount += plen) {
1026 ret = do_one_ahash_op(req, crypto_ahash_update(req));
1030 ret = do_one_ahash_op(req, crypto_ahash_final(req));
1035 /* The real thing. */
1036 for (i = 0; i < 8; i++) {
1037 cycles_t start, end;
1039 start = get_cycles();
1041 ret = do_one_ahash_op(req, crypto_ahash_init(req));
1044 for (pcount = 0; pcount < blen; pcount += plen) {
1045 ret = do_one_ahash_op(req, crypto_ahash_update(req));
1049 ret = do_one_ahash_op(req, crypto_ahash_final(req));
1055 cycles += end - start;
1062 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
1063 cycles / 8, cycles / (8 * blen));
1068 static void test_ahash_speed_common(const char *algo, unsigned int secs,
1069 struct hash_speed *speed, unsigned mask)
1071 struct scatterlist sg[TVMEMSIZE];
1072 struct crypto_wait wait;
1073 struct ahash_request *req;
1074 struct crypto_ahash *tfm;
1078 tfm = crypto_alloc_ahash(algo, 0, mask);
1080 pr_err("failed to load transform for %s: %ld\n",
1081 algo, PTR_ERR(tfm));
1085 printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
1086 get_driver_name(crypto_ahash, tfm));
1088 if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) {
1089 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm),
1094 test_hash_sg_init(sg);
1095 req = ahash_request_alloc(tfm, GFP_KERNEL);
1097 pr_err("ahash request allocation failure\n");
1101 crypto_init_wait(&wait);
1102 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1103 crypto_req_done, &wait);
1105 output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
1109 for (i = 0; speed[i].blen != 0; i++) {
1110 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
1111 pr_err("template (%u) too big for tvmem (%lu)\n",
1112 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
1117 crypto_ahash_setkey(tfm, tvmem[0], klen);
1120 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
1121 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
1123 ahash_request_set_crypt(req, sg, output, speed[i].plen);
1126 ret = test_ahash_jiffies(req, speed[i].blen,
1127 speed[i].plen, output, secs);
1130 ret = test_ahash_cycles(req, speed[i].blen,
1131 speed[i].plen, output);
1135 pr_err("hashing failed ret=%d\n", ret);
1143 ahash_request_free(req);
1146 crypto_free_ahash(tfm);
1149 static void test_ahash_speed(const char *algo, unsigned int secs,
1150 struct hash_speed *speed)
1152 return test_ahash_speed_common(algo, secs, speed, 0);
1155 static void test_hash_speed(const char *algo, unsigned int secs,
1156 struct hash_speed *speed)
1158 return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC);
1161 struct test_mb_skcipher_data {
1162 struct scatterlist sg[XBUFSIZE];
1163 struct skcipher_request *req;
1164 struct crypto_wait wait;
1165 char *xbuf[XBUFSIZE];
1168 static int do_mult_acipher_op(struct test_mb_skcipher_data *data, int enc,
1169 u32 num_mb, int *rc)
1173 /* Fire up a bunch of concurrent requests */
1174 for (i = 0; i < num_mb; i++) {
1176 rc[i] = crypto_skcipher_encrypt(data[i].req);
1178 rc[i] = crypto_skcipher_decrypt(data[i].req);
1181 /* Wait for all requests to finish */
1182 for (i = 0; i < num_mb; i++) {
1183 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
1186 pr_info("concurrent request %d error %d\n", i, rc[i]);
1194 static int test_mb_acipher_jiffies(struct test_mb_skcipher_data *data, int enc,
1195 int blen, int secs, u32 num_mb)
1197 unsigned long start, end;
1202 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
1206 for (start = jiffies, end = start + secs * HZ, bcount = 0;
1207 time_before(jiffies, end); bcount++) {
1208 ret = do_mult_acipher_op(data, enc, num_mb, rc);
1213 pr_cont("%d operations in %d seconds (%llu bytes)\n",
1214 bcount * num_mb, secs, (u64)bcount * blen * num_mb);
1221 static int test_mb_acipher_cycles(struct test_mb_skcipher_data *data, int enc,
1222 int blen, u32 num_mb)
1224 unsigned long cycles = 0;
1229 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
1234 for (i = 0; i < 4; i++) {
1235 ret = do_mult_acipher_op(data, enc, num_mb, rc);
1240 /* The real thing. */
1241 for (i = 0; i < 8; i++) {
1242 cycles_t start, end;
1244 start = get_cycles();
1245 ret = do_mult_acipher_op(data, enc, num_mb, rc);
1251 cycles += end - start;
1254 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1255 (cycles + 4) / (8 * num_mb), blen);
1262 static void test_mb_skcipher_speed(const char *algo, int enc, int secs,
1263 struct cipher_speed_template *template,
1264 unsigned int tcount, u8 *keysize, u32 num_mb)
1266 struct test_mb_skcipher_data *data;
1267 struct crypto_skcipher *tfm;
1268 unsigned int i, j, iv_len;
1280 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
1284 tfm = crypto_alloc_skcipher(algo, 0, 0);
1286 pr_err("failed to load transform for %s: %ld\n",
1287 algo, PTR_ERR(tfm));
1291 for (i = 0; i < num_mb; ++i)
1292 if (testmgr_alloc_buf(data[i].xbuf)) {
1294 testmgr_free_buf(data[i].xbuf);
1298 for (i = 0; i < num_mb; ++i) {
1299 data[i].req = skcipher_request_alloc(tfm, GFP_KERNEL);
1301 pr_err("alg: skcipher: Failed to allocate request for %s\n",
1304 skcipher_request_free(data[i].req);
1309 for (i = 0; i < num_mb; ++i) {
1310 skcipher_request_set_callback(data[i].req,
1311 CRYPTO_TFM_REQ_MAY_BACKLOG,
1312 crypto_req_done, &data[i].wait);
1313 crypto_init_wait(&data[i].wait);
1316 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo,
1317 get_driver_name(crypto_skcipher, tfm), e);
1321 b_size = block_sizes;
1323 u32 bs = round_up(*b_size, crypto_skcipher_blocksize(tfm));
1325 if (bs > XBUFSIZE * PAGE_SIZE) {
1326 pr_err("template (%u) too big for buffer (%lu)\n",
1327 bs, XBUFSIZE * PAGE_SIZE);
1331 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1334 /* Set up tfm global state, i.e. the key */
1336 memset(tvmem[0], 0xff, PAGE_SIZE);
1338 for (j = 0; j < tcount; j++) {
1339 if (template[j].klen == *keysize) {
1340 key = template[j].key;
1345 crypto_skcipher_clear_flags(tfm, ~0);
1347 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1349 pr_err("setkey() failed flags=%x\n",
1350 crypto_skcipher_get_flags(tfm));
1354 iv_len = crypto_skcipher_ivsize(tfm);
1356 memset(&iv, 0xff, iv_len);
1358 /* Now setup per request stuff, i.e. buffers */
1360 for (j = 0; j < num_mb; ++j) {
1361 struct test_mb_skcipher_data *cur = &data[j];
1362 unsigned int k = bs;
1363 unsigned int pages = DIV_ROUND_UP(k, PAGE_SIZE);
1366 sg_init_table(cur->sg, pages);
1368 while (k > PAGE_SIZE) {
1369 sg_set_buf(cur->sg + p, cur->xbuf[p],
1371 memset(cur->xbuf[p], 0xff, PAGE_SIZE);
1376 sg_set_buf(cur->sg + p, cur->xbuf[p], k);
1377 memset(cur->xbuf[p], 0xff, k);
1379 skcipher_request_set_crypt(cur->req, cur->sg,
1384 ret = test_mb_acipher_jiffies(data, enc,
1389 ret = test_mb_acipher_cycles(data, enc,
1394 pr_err("%s() failed flags=%x\n", e,
1395 crypto_skcipher_get_flags(tfm));
1405 for (i = 0; i < num_mb; ++i)
1406 skcipher_request_free(data[i].req);
1408 for (i = 0; i < num_mb; ++i)
1409 testmgr_free_buf(data[i].xbuf);
1411 crypto_free_skcipher(tfm);
1416 static inline int do_one_acipher_op(struct skcipher_request *req, int ret)
1418 struct crypto_wait *wait = req->base.data;
1420 return crypto_wait_req(ret, wait);
1423 static int test_acipher_jiffies(struct skcipher_request *req, int enc,
1426 unsigned long start, end;
1430 for (start = jiffies, end = start + secs * HZ, bcount = 0;
1431 time_before(jiffies, end); bcount++) {
1433 ret = do_one_acipher_op(req,
1434 crypto_skcipher_encrypt(req));
1436 ret = do_one_acipher_op(req,
1437 crypto_skcipher_decrypt(req));
1443 pr_cont("%d operations in %d seconds (%llu bytes)\n",
1444 bcount, secs, (u64)bcount * blen);
1448 static int test_acipher_cycles(struct skcipher_request *req, int enc,
1451 unsigned long cycles = 0;
1456 for (i = 0; i < 4; i++) {
1458 ret = do_one_acipher_op(req,
1459 crypto_skcipher_encrypt(req));
1461 ret = do_one_acipher_op(req,
1462 crypto_skcipher_decrypt(req));
1468 /* The real thing. */
1469 for (i = 0; i < 8; i++) {
1470 cycles_t start, end;
1472 start = get_cycles();
1474 ret = do_one_acipher_op(req,
1475 crypto_skcipher_encrypt(req));
1477 ret = do_one_acipher_op(req,
1478 crypto_skcipher_decrypt(req));
1484 cycles += end - start;
1489 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1490 (cycles + 4) / 8, blen);
1495 static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
1496 struct cipher_speed_template *template,
1497 unsigned int tcount, u8 *keysize, bool async)
1499 unsigned int ret, i, j, k, iv_len;
1500 struct crypto_wait wait;
1503 struct skcipher_request *req;
1504 struct crypto_skcipher *tfm;
1513 crypto_init_wait(&wait);
1515 tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC);
1518 pr_err("failed to load transform for %s: %ld\n", algo,
1523 pr_info("\ntesting speed of %s %s (%s) %s\n", async ? "async" : "sync",
1524 algo, get_driver_name(crypto_skcipher, tfm), e);
1526 req = skcipher_request_alloc(tfm, GFP_KERNEL);
1528 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1533 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1534 crypto_req_done, &wait);
1538 b_size = block_sizes;
1541 u32 bs = round_up(*b_size, crypto_skcipher_blocksize(tfm));
1542 struct scatterlist sg[TVMEMSIZE];
1544 if ((*keysize + bs) > TVMEMSIZE * PAGE_SIZE) {
1545 pr_err("template (%u) too big for "
1546 "tvmem (%lu)\n", *keysize + bs,
1547 TVMEMSIZE * PAGE_SIZE);
1551 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1554 memset(tvmem[0], 0xff, PAGE_SIZE);
1556 /* set key, plain text and IV */
1558 for (j = 0; j < tcount; j++) {
1559 if (template[j].klen == *keysize) {
1560 key = template[j].key;
1565 crypto_skcipher_clear_flags(tfm, ~0);
1567 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1569 pr_err("setkey() failed flags=%x\n",
1570 crypto_skcipher_get_flags(tfm));
1575 sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
1577 if (k > PAGE_SIZE) {
1578 sg_set_buf(sg, tvmem[0] + *keysize,
1579 PAGE_SIZE - *keysize);
1582 while (k > PAGE_SIZE) {
1583 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
1584 memset(tvmem[j], 0xff, PAGE_SIZE);
1588 sg_set_buf(sg + j, tvmem[j], k);
1589 memset(tvmem[j], 0xff, k);
1591 sg_set_buf(sg, tvmem[0] + *keysize, bs);
1594 iv_len = crypto_skcipher_ivsize(tfm);
1596 memset(&iv, 0xff, iv_len);
1598 skcipher_request_set_crypt(req, sg, sg, bs, iv);
1601 ret = test_acipher_jiffies(req, enc,
1605 ret = test_acipher_cycles(req, enc,
1610 pr_err("%s() failed flags=%x\n", e,
1611 crypto_skcipher_get_flags(tfm));
1621 skcipher_request_free(req);
1623 crypto_free_skcipher(tfm);
1626 static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
1627 struct cipher_speed_template *template,
1628 unsigned int tcount, u8 *keysize)
1630 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1634 static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
1635 struct cipher_speed_template *template,
1636 unsigned int tcount, u8 *keysize)
1638 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1642 static void test_available(void)
1644 const char **name = check;
1647 printk("alg %s ", *name);
1648 printk(crypto_has_alg(*name, 0, 0) ?
1649 "found\n" : "not found\n");
1654 static inline int tcrypt_test(const char *alg)
1658 pr_debug("testing %s\n", alg);
1660 ret = alg_test(alg, alg, 0, 0);
1661 /* non-fips algs return -EINVAL in fips mode */
1662 if (fips_enabled && ret == -EINVAL)
1667 static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)
1675 if (!crypto_has_alg(alg, type,
1676 mask ?: CRYPTO_ALG_TYPE_MASK))
1681 for (i = 1; i < 200; i++)
1682 ret += do_test(NULL, 0, 0, i, num_mb);
1686 ret += tcrypt_test("md5");
1690 ret += tcrypt_test("sha1");
1694 ret += tcrypt_test("ecb(des)");
1695 ret += tcrypt_test("cbc(des)");
1696 ret += tcrypt_test("ctr(des)");
1700 ret += tcrypt_test("ecb(des3_ede)");
1701 ret += tcrypt_test("cbc(des3_ede)");
1702 ret += tcrypt_test("ctr(des3_ede)");
1706 ret += tcrypt_test("md4");
1710 ret += tcrypt_test("sha256");
1714 ret += tcrypt_test("ecb(blowfish)");
1715 ret += tcrypt_test("cbc(blowfish)");
1716 ret += tcrypt_test("ctr(blowfish)");
1720 ret += tcrypt_test("ecb(twofish)");
1721 ret += tcrypt_test("cbc(twofish)");
1722 ret += tcrypt_test("ctr(twofish)");
1723 ret += tcrypt_test("lrw(twofish)");
1724 ret += tcrypt_test("xts(twofish)");
1728 ret += tcrypt_test("ecb(serpent)");
1729 ret += tcrypt_test("cbc(serpent)");
1730 ret += tcrypt_test("ctr(serpent)");
1731 ret += tcrypt_test("lrw(serpent)");
1732 ret += tcrypt_test("xts(serpent)");
1736 ret += tcrypt_test("ecb(aes)");
1737 ret += tcrypt_test("cbc(aes)");
1738 ret += tcrypt_test("lrw(aes)");
1739 ret += tcrypt_test("xts(aes)");
1740 ret += tcrypt_test("ctr(aes)");
1741 ret += tcrypt_test("rfc3686(ctr(aes))");
1742 ret += tcrypt_test("ofb(aes)");
1743 ret += tcrypt_test("cfb(aes)");
1747 ret += tcrypt_test("sha384");
1751 ret += tcrypt_test("sha512");
1755 ret += tcrypt_test("deflate");
1759 ret += tcrypt_test("ecb(cast5)");
1760 ret += tcrypt_test("cbc(cast5)");
1761 ret += tcrypt_test("ctr(cast5)");
1765 ret += tcrypt_test("ecb(cast6)");
1766 ret += tcrypt_test("cbc(cast6)");
1767 ret += tcrypt_test("ctr(cast6)");
1768 ret += tcrypt_test("lrw(cast6)");
1769 ret += tcrypt_test("xts(cast6)");
1773 ret += tcrypt_test("ecb(arc4)");
1777 ret += tcrypt_test("michael_mic");
1781 ret += tcrypt_test("crc32c");
1785 ret += tcrypt_test("ecb(tea)");
1789 ret += tcrypt_test("ecb(xtea)");
1793 ret += tcrypt_test("ecb(khazad)");
1797 ret += tcrypt_test("wp512");
1801 ret += tcrypt_test("wp384");
1805 ret += tcrypt_test("wp256");
1809 ret += tcrypt_test("ecb(anubis)");
1810 ret += tcrypt_test("cbc(anubis)");
1814 ret += tcrypt_test("ecb(xeta)");
1818 ret += tcrypt_test("pcbc(fcrypt)");
1822 ret += tcrypt_test("ecb(camellia)");
1823 ret += tcrypt_test("cbc(camellia)");
1824 ret += tcrypt_test("ctr(camellia)");
1825 ret += tcrypt_test("lrw(camellia)");
1826 ret += tcrypt_test("xts(camellia)");
1830 ret += tcrypt_test("sha224");
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("xxhash64");
1854 ret += tcrypt_test("rmd160");
1858 ret += tcrypt_test("blake2b-512");
1862 ret += tcrypt_test("ecb(seed)");
1866 ret += tcrypt_test("rfc4309(ccm(aes))");
1870 ret += tcrypt_test("ghash");
1874 ret += tcrypt_test("crct10dif");
1878 ret += tcrypt_test("sha3-224");
1882 ret += tcrypt_test("sha3-256");
1886 ret += tcrypt_test("sha3-384");
1890 ret += tcrypt_test("sha3-512");
1894 ret += tcrypt_test("sm3");
1898 ret += tcrypt_test("streebog256");
1902 ret += tcrypt_test("streebog512");
1906 ret += tcrypt_test("gcm(sm4)");
1910 ret += tcrypt_test("ccm(sm4)");
1914 ret += tcrypt_test("hmac(md5)");
1918 ret += tcrypt_test("hmac(sha1)");
1922 ret += tcrypt_test("hmac(sha256)");
1926 ret += tcrypt_test("hmac(sha384)");
1930 ret += tcrypt_test("hmac(sha512)");
1934 ret += tcrypt_test("hmac(sha224)");
1938 ret += tcrypt_test("xcbc(aes)");
1942 ret += tcrypt_test("hmac(rmd160)");
1946 ret += tcrypt_test("vmac64(aes)");
1950 ret += tcrypt_test("hmac(sha3-224)");
1954 ret += tcrypt_test("hmac(sha3-256)");
1958 ret += tcrypt_test("hmac(sha3-384)");
1962 ret += tcrypt_test("hmac(sha3-512)");
1966 ret += tcrypt_test("hmac(streebog256)");
1970 ret += tcrypt_test("hmac(streebog512)");
1974 ret += tcrypt_test("ansi_cprng");
1978 ret += tcrypt_test("rfc4106(gcm(aes))");
1982 ret += tcrypt_test("rfc4543(gcm(aes))");
1986 ret += tcrypt_test("cmac(aes)");
1990 ret += tcrypt_test("cmac(des3_ede)");
1994 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1998 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
2002 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
2006 ret += tcrypt_test("cbcmac(sm4)");
2010 ret += tcrypt_test("cmac(sm4)");
2014 ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
2017 ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
2020 ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
2023 ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
2026 ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
2029 ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
2032 ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
2035 ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
2038 ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
2041 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
2044 ret += tcrypt_test("ecb(sm4)");
2045 ret += tcrypt_test("cbc(sm4)");
2046 ret += tcrypt_test("cfb(sm4)");
2047 ret += tcrypt_test("ctr(sm4)");
2050 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2051 speed_template_16_24_32);
2052 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2053 speed_template_16_24_32);
2054 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2055 speed_template_16_24_32);
2056 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2057 speed_template_16_24_32);
2058 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2059 speed_template_32_40_48);
2060 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2061 speed_template_32_40_48);
2062 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2063 speed_template_32_64);
2064 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2065 speed_template_32_64);
2066 test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2067 speed_template_16_24_32);
2068 test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2069 speed_template_16_24_32);
2070 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2071 speed_template_16_24_32);
2072 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2073 speed_template_16_24_32);
2074 test_cipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2075 speed_template_16_24_32);
2076 test_cipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2077 speed_template_16_24_32);
2081 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2082 des3_speed_template, DES3_SPEED_VECTORS,
2084 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
2085 des3_speed_template, DES3_SPEED_VECTORS,
2087 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2088 des3_speed_template, DES3_SPEED_VECTORS,
2090 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
2091 des3_speed_template, DES3_SPEED_VECTORS,
2093 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
2094 des3_speed_template, DES3_SPEED_VECTORS,
2096 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
2097 des3_speed_template, DES3_SPEED_VECTORS,
2102 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2103 speed_template_16_24_32);
2104 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2105 speed_template_16_24_32);
2106 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2107 speed_template_16_24_32);
2108 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2109 speed_template_16_24_32);
2110 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2111 speed_template_16_24_32);
2112 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2113 speed_template_16_24_32);
2114 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2115 speed_template_32_40_48);
2116 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2117 speed_template_32_40_48);
2118 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2119 speed_template_32_48_64);
2120 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2121 speed_template_32_48_64);
2125 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2126 speed_template_8_32);
2127 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2128 speed_template_8_32);
2129 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2130 speed_template_8_32);
2131 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2132 speed_template_8_32);
2133 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2134 speed_template_8_32);
2135 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2136 speed_template_8_32);
2140 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2142 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2144 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2146 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2151 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2152 speed_template_16_24_32);
2153 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2154 speed_template_16_24_32);
2155 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2156 speed_template_16_24_32);
2157 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2158 speed_template_16_24_32);
2159 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2160 speed_template_16_24_32);
2161 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2162 speed_template_16_24_32);
2163 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2164 speed_template_32_40_48);
2165 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2166 speed_template_32_40_48);
2167 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2168 speed_template_32_48_64);
2169 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2170 speed_template_32_48_64);
2174 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2175 speed_template_16_32);
2176 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2177 speed_template_16_32);
2178 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2179 speed_template_16_32);
2180 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2181 speed_template_16_32);
2182 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2183 speed_template_16_32);
2184 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2185 speed_template_16_32);
2186 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2187 speed_template_32_48);
2188 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2189 speed_template_32_48);
2190 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2191 speed_template_32_64);
2192 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2193 speed_template_32_64);
2197 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2202 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2203 speed_template_8_16);
2204 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2205 speed_template_8_16);
2206 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2207 speed_template_8_16);
2208 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2209 speed_template_8_16);
2210 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2211 speed_template_8_16);
2212 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2213 speed_template_8_16);
2217 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2218 speed_template_16_32);
2219 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2220 speed_template_16_32);
2221 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2222 speed_template_16_32);
2223 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2224 speed_template_16_32);
2225 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2226 speed_template_16_32);
2227 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2228 speed_template_16_32);
2229 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2230 speed_template_32_48);
2231 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2232 speed_template_32_48);
2233 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2234 speed_template_32_64);
2235 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2236 speed_template_32_64);
2240 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
2241 NULL, 0, 16, 16, aead_speed_template_20);
2242 test_aead_speed("gcm(aes)", ENCRYPT, sec,
2243 NULL, 0, 16, 8, speed_template_16_24_32);
2244 test_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec,
2245 NULL, 0, 16, 16, aead_speed_template_20);
2246 test_aead_speed("gcm(aes)", DECRYPT, sec,
2247 NULL, 0, 16, 8, speed_template_16_24_32);
2251 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
2252 NULL, 0, 16, 16, aead_speed_template_19);
2253 test_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec,
2254 NULL, 0, 16, 16, aead_speed_template_19);
2258 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
2259 NULL, 0, 16, 8, aead_speed_template_36);
2260 test_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT, sec,
2261 NULL, 0, 16, 8, aead_speed_template_36);
2265 test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
2270 test_mb_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec, NULL,
2271 0, 16, 16, aead_speed_template_20, num_mb);
2272 test_mb_aead_speed("gcm(aes)", ENCRYPT, sec, NULL, 0, 16, 8,
2273 speed_template_16_24_32, num_mb);
2274 test_mb_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec, NULL,
2275 0, 16, 16, aead_speed_template_20, num_mb);
2276 test_mb_aead_speed("gcm(aes)", DECRYPT, sec, NULL, 0, 16, 8,
2277 speed_template_16_24_32, num_mb);
2281 test_mb_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec, NULL, 0,
2282 16, 16, aead_speed_template_19, num_mb);
2283 test_mb_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec, NULL, 0,
2284 16, 16, aead_speed_template_19, num_mb);
2288 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT,
2289 sec, NULL, 0, 16, 8, aead_speed_template_36,
2291 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT,
2292 sec, NULL, 0, 16, 8, aead_speed_template_36,
2297 test_cipher_speed("ecb(sm4)", ENCRYPT, sec, NULL, 0,
2299 test_cipher_speed("ecb(sm4)", DECRYPT, sec, NULL, 0,
2301 test_cipher_speed("cbc(sm4)", ENCRYPT, sec, NULL, 0,
2303 test_cipher_speed("cbc(sm4)", DECRYPT, sec, NULL, 0,
2305 test_cipher_speed("cfb(sm4)", ENCRYPT, sec, NULL, 0,
2307 test_cipher_speed("cfb(sm4)", DECRYPT, sec, NULL, 0,
2309 test_cipher_speed("ctr(sm4)", ENCRYPT, sec, NULL, 0,
2311 test_cipher_speed("ctr(sm4)", DECRYPT, sec, NULL, 0,
2316 test_cipher_speed("adiantum(xchacha12,aes)", ENCRYPT, sec, NULL,
2317 0, speed_template_32);
2318 test_cipher_speed("adiantum(xchacha12,aes)", DECRYPT, sec, NULL,
2319 0, speed_template_32);
2320 test_cipher_speed("adiantum(xchacha20,aes)", ENCRYPT, sec, NULL,
2321 0, speed_template_32);
2322 test_cipher_speed("adiantum(xchacha20,aes)", DECRYPT, sec, NULL,
2323 0, speed_template_32);
2327 test_acipher_speed("essiv(cbc(aes),sha256)",
2328 ENCRYPT, sec, NULL, 0,
2329 speed_template_16_24_32);
2330 test_acipher_speed("essiv(cbc(aes),sha256)",
2331 DECRYPT, sec, NULL, 0,
2332 speed_template_16_24_32);
2336 test_aead_speed("aegis128", ENCRYPT, sec,
2337 NULL, 0, 16, 8, speed_template_16);
2338 test_aead_speed("aegis128", DECRYPT, sec,
2339 NULL, 0, 16, 8, speed_template_16);
2343 test_aead_speed("gcm(sm4)", ENCRYPT, sec,
2344 NULL, 0, 16, 8, speed_template_16);
2345 test_aead_speed("gcm(sm4)", DECRYPT, sec,
2346 NULL, 0, 16, 8, speed_template_16);
2350 test_aead_speed("rfc4309(ccm(sm4))", ENCRYPT, sec,
2351 NULL, 0, 16, 16, aead_speed_template_19);
2352 test_aead_speed("rfc4309(ccm(sm4))", DECRYPT, sec,
2353 NULL, 0, 16, 16, aead_speed_template_19);
2357 test_mb_aead_speed("gcm(sm4)", ENCRYPT, sec, NULL, 0, 16, 8,
2358 speed_template_16, num_mb);
2359 test_mb_aead_speed("gcm(sm4)", DECRYPT, sec, NULL, 0, 16, 8,
2360 speed_template_16, num_mb);
2364 test_mb_aead_speed("rfc4309(ccm(sm4))", ENCRYPT, sec, NULL, 0,
2365 16, 16, aead_speed_template_19, num_mb);
2366 test_mb_aead_speed("rfc4309(ccm(sm4))", DECRYPT, sec, NULL, 0,
2367 16, 16, aead_speed_template_19, num_mb);
2372 test_hash_speed(alg, sec, generic_hash_speed_template);
2377 test_hash_speed("md4", sec, generic_hash_speed_template);
2378 if (mode > 300 && mode < 400) break;
2381 test_hash_speed("md5", sec, generic_hash_speed_template);
2382 if (mode > 300 && mode < 400) break;
2385 test_hash_speed("sha1", sec, generic_hash_speed_template);
2386 if (mode > 300 && mode < 400) break;
2389 test_hash_speed("sha256", sec, generic_hash_speed_template);
2390 if (mode > 300 && mode < 400) break;
2393 test_hash_speed("sha384", sec, generic_hash_speed_template);
2394 if (mode > 300 && mode < 400) break;
2397 test_hash_speed("sha512", sec, generic_hash_speed_template);
2398 if (mode > 300 && mode < 400) break;
2401 test_hash_speed("wp256", sec, generic_hash_speed_template);
2402 if (mode > 300 && mode < 400) break;
2405 test_hash_speed("wp384", sec, generic_hash_speed_template);
2406 if (mode > 300 && mode < 400) break;
2409 test_hash_speed("wp512", sec, generic_hash_speed_template);
2410 if (mode > 300 && mode < 400) break;
2413 test_hash_speed("sha224", sec, generic_hash_speed_template);
2414 if (mode > 300 && mode < 400) break;
2417 test_hash_speed("xxhash64", sec, generic_hash_speed_template);
2418 if (mode > 300 && mode < 400) break;
2421 test_hash_speed("rmd160", sec, generic_hash_speed_template);
2422 if (mode > 300 && mode < 400) break;
2425 test_hash_speed("blake2b-512", sec, generic_hash_speed_template);
2426 if (mode > 300 && mode < 400) break;
2430 test_hash_speed("ghash", sec, generic_hash_speed_template);
2431 if (mode > 300 && mode < 400) break;
2434 test_hash_speed("crc32c", sec, generic_hash_speed_template);
2435 if (mode > 300 && mode < 400) break;
2438 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
2439 if (mode > 300 && mode < 400) break;
2442 test_hash_speed("poly1305", sec, poly1305_speed_template);
2443 if (mode > 300 && mode < 400) break;
2446 test_hash_speed("sha3-224", sec, generic_hash_speed_template);
2447 if (mode > 300 && mode < 400) break;
2450 test_hash_speed("sha3-256", sec, generic_hash_speed_template);
2451 if (mode > 300 && mode < 400) break;
2454 test_hash_speed("sha3-384", sec, generic_hash_speed_template);
2455 if (mode > 300 && mode < 400) break;
2458 test_hash_speed("sha3-512", sec, generic_hash_speed_template);
2459 if (mode > 300 && mode < 400) break;
2462 test_hash_speed("sm3", sec, generic_hash_speed_template);
2463 if (mode > 300 && mode < 400) break;
2466 test_hash_speed("streebog256", sec,
2467 generic_hash_speed_template);
2468 if (mode > 300 && mode < 400) break;
2471 test_hash_speed("streebog512", sec,
2472 generic_hash_speed_template);
2473 if (mode > 300 && mode < 400) break;
2480 test_ahash_speed(alg, sec, generic_hash_speed_template);
2485 test_ahash_speed("md4", sec, generic_hash_speed_template);
2486 if (mode > 400 && mode < 500) break;
2489 test_ahash_speed("md5", sec, generic_hash_speed_template);
2490 if (mode > 400 && mode < 500) break;
2493 test_ahash_speed("sha1", sec, generic_hash_speed_template);
2494 if (mode > 400 && mode < 500) break;
2497 test_ahash_speed("sha256", sec, generic_hash_speed_template);
2498 if (mode > 400 && mode < 500) break;
2501 test_ahash_speed("sha384", sec, generic_hash_speed_template);
2502 if (mode > 400 && mode < 500) break;
2505 test_ahash_speed("sha512", sec, generic_hash_speed_template);
2506 if (mode > 400 && mode < 500) break;
2509 test_ahash_speed("wp256", sec, generic_hash_speed_template);
2510 if (mode > 400 && mode < 500) break;
2513 test_ahash_speed("wp384", sec, generic_hash_speed_template);
2514 if (mode > 400 && mode < 500) break;
2517 test_ahash_speed("wp512", sec, generic_hash_speed_template);
2518 if (mode > 400 && mode < 500) break;
2521 test_ahash_speed("sha224", sec, generic_hash_speed_template);
2522 if (mode > 400 && mode < 500) break;
2525 test_ahash_speed("xxhash64", sec, generic_hash_speed_template);
2526 if (mode > 400 && mode < 500) break;
2529 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
2530 if (mode > 400 && mode < 500) break;
2533 test_ahash_speed("blake2b-512", sec, generic_hash_speed_template);
2534 if (mode > 400 && mode < 500) break;
2537 test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
2538 if (mode > 400 && mode < 500) break;
2541 test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
2542 if (mode > 400 && mode < 500) break;
2545 test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
2546 if (mode > 400 && mode < 500) break;
2549 test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
2550 if (mode > 400 && mode < 500) break;
2553 test_mb_ahash_speed("sha1", sec, generic_hash_speed_template,
2555 if (mode > 400 && mode < 500) break;
2558 test_mb_ahash_speed("sha256", sec, generic_hash_speed_template,
2560 if (mode > 400 && mode < 500) break;
2563 test_mb_ahash_speed("sha512", sec, generic_hash_speed_template,
2565 if (mode > 400 && mode < 500) break;
2568 test_mb_ahash_speed("sm3", sec, generic_hash_speed_template,
2570 if (mode > 400 && mode < 500) break;
2573 test_mb_ahash_speed("streebog256", sec,
2574 generic_hash_speed_template, num_mb);
2575 if (mode > 400 && mode < 500) break;
2578 test_mb_ahash_speed("streebog512", sec,
2579 generic_hash_speed_template, num_mb);
2580 if (mode > 400 && mode < 500) break;
2586 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2587 speed_template_16_24_32);
2588 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2589 speed_template_16_24_32);
2590 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2591 speed_template_16_24_32);
2592 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2593 speed_template_16_24_32);
2594 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2595 speed_template_32_40_48);
2596 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2597 speed_template_32_40_48);
2598 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2599 speed_template_32_64);
2600 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2601 speed_template_32_64);
2602 test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2603 speed_template_16_24_32);
2604 test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2605 speed_template_16_24_32);
2606 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2607 speed_template_16_24_32);
2608 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2609 speed_template_16_24_32);
2610 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2611 speed_template_16_24_32);
2612 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2613 speed_template_16_24_32);
2614 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2615 speed_template_16_24_32);
2616 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2617 speed_template_16_24_32);
2618 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
2619 speed_template_20_28_36);
2620 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
2621 speed_template_20_28_36);
2625 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2626 des3_speed_template, DES3_SPEED_VECTORS,
2628 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
2629 des3_speed_template, DES3_SPEED_VECTORS,
2631 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2632 des3_speed_template, DES3_SPEED_VECTORS,
2634 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
2635 des3_speed_template, DES3_SPEED_VECTORS,
2637 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2638 des3_speed_template, DES3_SPEED_VECTORS,
2640 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
2641 des3_speed_template, DES3_SPEED_VECTORS,
2643 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2644 des3_speed_template, DES3_SPEED_VECTORS,
2646 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
2647 des3_speed_template, DES3_SPEED_VECTORS,
2652 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2654 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2656 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2658 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2660 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2662 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2664 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2666 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2671 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2672 speed_template_16_32);
2673 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2674 speed_template_16_32);
2675 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2676 speed_template_16_32);
2677 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2678 speed_template_16_32);
2679 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2680 speed_template_16_32);
2681 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2682 speed_template_16_32);
2683 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2684 speed_template_32_48);
2685 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2686 speed_template_32_48);
2687 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2688 speed_template_32_64);
2689 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2690 speed_template_32_64);
2694 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2695 speed_template_16_24_32);
2696 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2697 speed_template_16_24_32);
2698 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2699 speed_template_16_24_32);
2700 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2701 speed_template_16_24_32);
2702 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2703 speed_template_16_24_32);
2704 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2705 speed_template_16_24_32);
2706 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2707 speed_template_32_40_48);
2708 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2709 speed_template_32_40_48);
2710 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2711 speed_template_32_48_64);
2712 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2713 speed_template_32_48_64);
2717 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2722 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2723 speed_template_8_16);
2724 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2725 speed_template_8_16);
2726 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2727 speed_template_8_16);
2728 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2729 speed_template_8_16);
2730 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2731 speed_template_8_16);
2732 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2733 speed_template_8_16);
2737 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2738 speed_template_16_32);
2739 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2740 speed_template_16_32);
2741 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2742 speed_template_16_32);
2743 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2744 speed_template_16_32);
2745 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2746 speed_template_16_32);
2747 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2748 speed_template_16_32);
2749 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2750 speed_template_32_48);
2751 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2752 speed_template_32_48);
2753 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2754 speed_template_32_64);
2755 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2756 speed_template_32_64);
2760 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2761 speed_template_16_32);
2762 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2763 speed_template_16_32);
2764 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2765 speed_template_16_32);
2766 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2767 speed_template_16_32);
2768 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2769 speed_template_16_32);
2770 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2771 speed_template_16_32);
2772 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2773 speed_template_32_48);
2774 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2775 speed_template_32_48);
2776 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2777 speed_template_32_64);
2778 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2779 speed_template_32_64);
2783 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2784 speed_template_8_32);
2785 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2786 speed_template_8_32);
2787 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2788 speed_template_8_32);
2789 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2790 speed_template_8_32);
2791 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2792 speed_template_8_32);
2793 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2794 speed_template_8_32);
2798 test_acipher_speed("ecb(sm4)", ENCRYPT, sec, NULL, 0,
2800 test_acipher_speed("ecb(sm4)", DECRYPT, sec, NULL, 0,
2802 test_acipher_speed("cbc(sm4)", ENCRYPT, sec, NULL, 0,
2804 test_acipher_speed("cbc(sm4)", DECRYPT, sec, NULL, 0,
2806 test_acipher_speed("cfb(sm4)", ENCRYPT, sec, NULL, 0,
2808 test_acipher_speed("cfb(sm4)", DECRYPT, sec, NULL, 0,
2810 test_acipher_speed("ctr(sm4)", ENCRYPT, sec, NULL, 0,
2812 test_acipher_speed("ctr(sm4)", DECRYPT, sec, NULL, 0,
2817 test_mb_skcipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2818 speed_template_16_24_32, num_mb);
2819 test_mb_skcipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2820 speed_template_16_24_32, num_mb);
2821 test_mb_skcipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2822 speed_template_16_24_32, num_mb);
2823 test_mb_skcipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2824 speed_template_16_24_32, num_mb);
2825 test_mb_skcipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2826 speed_template_32_40_48, num_mb);
2827 test_mb_skcipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2828 speed_template_32_40_48, num_mb);
2829 test_mb_skcipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2830 speed_template_32_64, num_mb);
2831 test_mb_skcipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2832 speed_template_32_64, num_mb);
2833 test_mb_skcipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2834 speed_template_16_24_32, num_mb);
2835 test_mb_skcipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2836 speed_template_16_24_32, num_mb);
2837 test_mb_skcipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2838 speed_template_16_24_32, num_mb);
2839 test_mb_skcipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2840 speed_template_16_24_32, num_mb);
2841 test_mb_skcipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2842 speed_template_16_24_32, num_mb);
2843 test_mb_skcipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2844 speed_template_16_24_32, num_mb);
2845 test_mb_skcipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2846 speed_template_16_24_32, num_mb);
2847 test_mb_skcipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2848 speed_template_16_24_32, num_mb);
2849 test_mb_skcipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL,
2850 0, speed_template_20_28_36, num_mb);
2851 test_mb_skcipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL,
2852 0, speed_template_20_28_36, num_mb);
2856 test_mb_skcipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2857 des3_speed_template, DES3_SPEED_VECTORS,
2858 speed_template_24, num_mb);
2859 test_mb_skcipher_speed("ecb(des3_ede)", DECRYPT, sec,
2860 des3_speed_template, DES3_SPEED_VECTORS,
2861 speed_template_24, num_mb);
2862 test_mb_skcipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2863 des3_speed_template, DES3_SPEED_VECTORS,
2864 speed_template_24, num_mb);
2865 test_mb_skcipher_speed("cbc(des3_ede)", DECRYPT, sec,
2866 des3_speed_template, DES3_SPEED_VECTORS,
2867 speed_template_24, num_mb);
2868 test_mb_skcipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2869 des3_speed_template, DES3_SPEED_VECTORS,
2870 speed_template_24, num_mb);
2871 test_mb_skcipher_speed("cfb(des3_ede)", DECRYPT, sec,
2872 des3_speed_template, DES3_SPEED_VECTORS,
2873 speed_template_24, num_mb);
2874 test_mb_skcipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2875 des3_speed_template, DES3_SPEED_VECTORS,
2876 speed_template_24, num_mb);
2877 test_mb_skcipher_speed("ofb(des3_ede)", DECRYPT, sec,
2878 des3_speed_template, DES3_SPEED_VECTORS,
2879 speed_template_24, num_mb);
2883 test_mb_skcipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2884 speed_template_8, num_mb);
2885 test_mb_skcipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2886 speed_template_8, num_mb);
2887 test_mb_skcipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2888 speed_template_8, num_mb);
2889 test_mb_skcipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2890 speed_template_8, num_mb);
2891 test_mb_skcipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2892 speed_template_8, num_mb);
2893 test_mb_skcipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2894 speed_template_8, num_mb);
2895 test_mb_skcipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2896 speed_template_8, num_mb);
2897 test_mb_skcipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2898 speed_template_8, num_mb);
2902 test_mb_skcipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2903 speed_template_16_32, num_mb);
2904 test_mb_skcipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2905 speed_template_16_32, num_mb);
2906 test_mb_skcipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2907 speed_template_16_32, num_mb);
2908 test_mb_skcipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2909 speed_template_16_32, num_mb);
2910 test_mb_skcipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2911 speed_template_16_32, num_mb);
2912 test_mb_skcipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2913 speed_template_16_32, num_mb);
2914 test_mb_skcipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2915 speed_template_32_48, num_mb);
2916 test_mb_skcipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2917 speed_template_32_48, num_mb);
2918 test_mb_skcipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2919 speed_template_32_64, num_mb);
2920 test_mb_skcipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2921 speed_template_32_64, num_mb);
2925 test_mb_skcipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2926 speed_template_16_24_32, num_mb);
2927 test_mb_skcipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2928 speed_template_16_24_32, num_mb);
2929 test_mb_skcipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2930 speed_template_16_24_32, num_mb);
2931 test_mb_skcipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2932 speed_template_16_24_32, num_mb);
2933 test_mb_skcipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2934 speed_template_16_24_32, num_mb);
2935 test_mb_skcipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2936 speed_template_16_24_32, num_mb);
2937 test_mb_skcipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2938 speed_template_32_40_48, num_mb);
2939 test_mb_skcipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2940 speed_template_32_40_48, num_mb);
2941 test_mb_skcipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2942 speed_template_32_48_64, num_mb);
2943 test_mb_skcipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2944 speed_template_32_48_64, num_mb);
2948 test_mb_skcipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2949 speed_template_8, num_mb);
2953 test_mb_skcipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2954 speed_template_8_16, num_mb);
2955 test_mb_skcipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2956 speed_template_8_16, num_mb);
2957 test_mb_skcipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2958 speed_template_8_16, num_mb);
2959 test_mb_skcipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2960 speed_template_8_16, num_mb);
2961 test_mb_skcipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2962 speed_template_8_16, num_mb);
2963 test_mb_skcipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2964 speed_template_8_16, num_mb);
2968 test_mb_skcipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2969 speed_template_16_32, num_mb);
2970 test_mb_skcipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2971 speed_template_16_32, num_mb);
2972 test_mb_skcipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2973 speed_template_16_32, num_mb);
2974 test_mb_skcipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2975 speed_template_16_32, num_mb);
2976 test_mb_skcipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2977 speed_template_16_32, num_mb);
2978 test_mb_skcipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2979 speed_template_16_32, num_mb);
2980 test_mb_skcipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2981 speed_template_32_48, num_mb);
2982 test_mb_skcipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2983 speed_template_32_48, num_mb);
2984 test_mb_skcipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2985 speed_template_32_64, num_mb);
2986 test_mb_skcipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2987 speed_template_32_64, num_mb);
2991 test_mb_skcipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2992 speed_template_16_32, num_mb);
2993 test_mb_skcipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2994 speed_template_16_32, num_mb);
2995 test_mb_skcipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2996 speed_template_16_32, num_mb);
2997 test_mb_skcipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2998 speed_template_16_32, num_mb);
2999 test_mb_skcipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
3000 speed_template_16_32, num_mb);
3001 test_mb_skcipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
3002 speed_template_16_32, num_mb);
3003 test_mb_skcipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
3004 speed_template_32_48, num_mb);
3005 test_mb_skcipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
3006 speed_template_32_48, num_mb);
3007 test_mb_skcipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
3008 speed_template_32_64, num_mb);
3009 test_mb_skcipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
3010 speed_template_32_64, num_mb);
3014 test_mb_skcipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
3015 speed_template_8_32, num_mb);
3016 test_mb_skcipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
3017 speed_template_8_32, num_mb);
3018 test_mb_skcipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
3019 speed_template_8_32, num_mb);
3020 test_mb_skcipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
3021 speed_template_8_32, num_mb);
3022 test_mb_skcipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
3023 speed_template_8_32, num_mb);
3024 test_mb_skcipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
3025 speed_template_8_32, num_mb);
3036 static int __init tcrypt_mod_init(void)
3041 for (i = 0; i < TVMEMSIZE; i++) {
3042 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
3047 err = do_test(alg, type, mask, mode, num_mb);
3050 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
3053 pr_debug("all tests passed\n");
3056 /* We intentionaly return -EAGAIN to prevent keeping the module,
3057 * unless we're running in fips mode. It does all its work from
3058 * init() and doesn't offer any runtime functionality, but in
3059 * the fips case, checking for a successful load is helpful.
3060 * => we don't need it in the memory, do we?
3067 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
3068 free_page((unsigned long)tvmem[i]);
3074 * If an init function is provided, an exit function must also be provided
3075 * to allow module unload.
3077 static void __exit tcrypt_mod_fini(void) { }
3079 late_initcall(tcrypt_mod_init);
3080 module_exit(tcrypt_mod_fini);
3082 module_param(alg, charp, 0);
3083 module_param(type, uint, 0);
3084 module_param(mask, uint, 0);
3085 module_param(mode, int, 0);
3086 module_param(sec, uint, 0);
3087 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
3088 "(defaults to zero which uses CPU cycles instead)");
3089 module_param(num_mb, uint, 0000);
3090 MODULE_PARM_DESC(num_mb, "Number of concurrent requests to be used in mb speed tests (defaults to 8)");
3091 module_param(klen, uint, 0);
3092 MODULE_PARM_DESC(klen, "Key length (defaults to 0)");
3094 MODULE_LICENSE("GPL");
3095 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
3096 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");