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);
1299 for (i = 0; i < num_mb; ++i)
1300 if (testmgr_alloc_buf(data[i].xbuf)) {
1302 testmgr_free_buf(data[i].xbuf);
1307 for (i = 0; i < num_mb; ++i) {
1308 data[i].req = skcipher_request_alloc(tfm, GFP_KERNEL);
1310 pr_err("alg: skcipher: Failed to allocate request for %s\n",
1313 skcipher_request_free(data[i].req);
1318 for (i = 0; i < num_mb; ++i) {
1319 skcipher_request_set_callback(data[i].req,
1320 CRYPTO_TFM_REQ_MAY_BACKLOG,
1321 crypto_req_done, &data[i].wait);
1322 crypto_init_wait(&data[i].wait);
1325 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo,
1326 get_driver_name(crypto_skcipher, tfm), e);
1330 b_size = block_sizes;
1332 u32 bs = round_up(*b_size, crypto_skcipher_blocksize(tfm));
1334 if (bs > XBUFSIZE * PAGE_SIZE) {
1335 pr_err("template (%u) too big for buffer (%lu)\n",
1336 *b_size, XBUFSIZE * PAGE_SIZE);
1340 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1343 /* Set up tfm global state, i.e. the key */
1345 memset(tvmem[0], 0xff, PAGE_SIZE);
1347 for (j = 0; j < tcount; j++) {
1348 if (template[j].klen == *keysize) {
1349 key = template[j].key;
1354 crypto_skcipher_clear_flags(tfm, ~0);
1356 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1358 pr_err("setkey() failed flags=%x\n",
1359 crypto_skcipher_get_flags(tfm));
1363 iv_len = crypto_skcipher_ivsize(tfm);
1365 memset(&iv, 0xff, iv_len);
1367 /* Now setup per request stuff, i.e. buffers */
1369 for (j = 0; j < num_mb; ++j) {
1370 struct test_mb_skcipher_data *cur = &data[j];
1371 unsigned int k = bs;
1372 unsigned int pages = DIV_ROUND_UP(k, PAGE_SIZE);
1375 sg_init_table(cur->sg, pages);
1377 while (k > PAGE_SIZE) {
1378 sg_set_buf(cur->sg + p, cur->xbuf[p],
1380 memset(cur->xbuf[p], 0xff, PAGE_SIZE);
1385 sg_set_buf(cur->sg + p, cur->xbuf[p], k);
1386 memset(cur->xbuf[p], 0xff, k);
1388 skcipher_request_set_crypt(cur->req, cur->sg,
1394 ret = test_mb_acipher_jiffies(data, enc,
1399 ret = test_mb_acipher_cycles(data, enc,
1404 pr_err("%s() failed flags=%x\n", e,
1405 crypto_skcipher_get_flags(tfm));
1415 for (i = 0; i < num_mb; ++i)
1416 skcipher_request_free(data[i].req);
1418 for (i = 0; i < num_mb; ++i)
1419 testmgr_free_buf(data[i].xbuf);
1421 crypto_free_skcipher(tfm);
1426 static inline int do_one_acipher_op(struct skcipher_request *req, int ret)
1428 struct crypto_wait *wait = req->base.data;
1430 return crypto_wait_req(ret, wait);
1433 static int test_acipher_jiffies(struct skcipher_request *req, int enc,
1436 unsigned long start, end;
1440 for (start = jiffies, end = start + secs * HZ, bcount = 0;
1441 time_before(jiffies, end); bcount++) {
1443 ret = do_one_acipher_op(req,
1444 crypto_skcipher_encrypt(req));
1446 ret = do_one_acipher_op(req,
1447 crypto_skcipher_decrypt(req));
1453 pr_cont("%d operations in %d seconds (%llu bytes)\n",
1454 bcount, secs, (u64)bcount * blen);
1458 static int test_acipher_cycles(struct skcipher_request *req, int enc,
1461 unsigned long cycles = 0;
1466 for (i = 0; i < 4; i++) {
1468 ret = do_one_acipher_op(req,
1469 crypto_skcipher_encrypt(req));
1471 ret = do_one_acipher_op(req,
1472 crypto_skcipher_decrypt(req));
1478 /* The real thing. */
1479 for (i = 0; i < 8; i++) {
1480 cycles_t start, end;
1482 start = get_cycles();
1484 ret = do_one_acipher_op(req,
1485 crypto_skcipher_encrypt(req));
1487 ret = do_one_acipher_op(req,
1488 crypto_skcipher_decrypt(req));
1494 cycles += end - start;
1499 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1500 (cycles + 4) / 8, blen);
1505 static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
1506 struct cipher_speed_template *template,
1507 unsigned int tcount, u8 *keysize, bool async)
1509 unsigned int ret, i, j, k, iv_len;
1510 struct crypto_wait wait;
1513 struct skcipher_request *req;
1514 struct crypto_skcipher *tfm;
1523 crypto_init_wait(&wait);
1525 tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC);
1528 pr_err("failed to load transform for %s: %ld\n", algo,
1533 pr_info("\ntesting speed of %s %s (%s) %s\n", async ? "async" : "sync",
1534 algo, get_driver_name(crypto_skcipher, tfm), e);
1536 req = skcipher_request_alloc(tfm, GFP_KERNEL);
1538 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1543 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1544 crypto_req_done, &wait);
1548 b_size = block_sizes;
1551 u32 bs = round_up(*b_size, crypto_skcipher_blocksize(tfm));
1552 struct scatterlist sg[TVMEMSIZE];
1554 if ((*keysize + bs) > TVMEMSIZE * PAGE_SIZE) {
1555 pr_err("template (%u) too big for "
1556 "tvmem (%lu)\n", *keysize + bs,
1557 TVMEMSIZE * PAGE_SIZE);
1561 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1564 memset(tvmem[0], 0xff, PAGE_SIZE);
1566 /* set key, plain text and IV */
1568 for (j = 0; j < tcount; j++) {
1569 if (template[j].klen == *keysize) {
1570 key = template[j].key;
1575 crypto_skcipher_clear_flags(tfm, ~0);
1577 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1579 pr_err("setkey() failed flags=%x\n",
1580 crypto_skcipher_get_flags(tfm));
1585 sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
1587 if (k > PAGE_SIZE) {
1588 sg_set_buf(sg, tvmem[0] + *keysize,
1589 PAGE_SIZE - *keysize);
1592 while (k > PAGE_SIZE) {
1593 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
1594 memset(tvmem[j], 0xff, PAGE_SIZE);
1598 sg_set_buf(sg + j, tvmem[j], k);
1599 memset(tvmem[j], 0xff, k);
1601 sg_set_buf(sg, tvmem[0] + *keysize, bs);
1604 iv_len = crypto_skcipher_ivsize(tfm);
1606 memset(&iv, 0xff, iv_len);
1608 skcipher_request_set_crypt(req, sg, sg, bs, iv);
1611 ret = test_acipher_jiffies(req, enc,
1615 ret = test_acipher_cycles(req, enc,
1620 pr_err("%s() failed flags=%x\n", e,
1621 crypto_skcipher_get_flags(tfm));
1631 skcipher_request_free(req);
1633 crypto_free_skcipher(tfm);
1636 static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
1637 struct cipher_speed_template *template,
1638 unsigned int tcount, u8 *keysize)
1640 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1644 static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
1645 struct cipher_speed_template *template,
1646 unsigned int tcount, u8 *keysize)
1648 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1652 static void test_available(void)
1654 const char **name = check;
1657 printk("alg %s ", *name);
1658 printk(crypto_has_alg(*name, 0, 0) ?
1659 "found\n" : "not found\n");
1664 static inline int tcrypt_test(const char *alg)
1668 pr_debug("testing %s\n", alg);
1670 ret = alg_test(alg, alg, 0, 0);
1671 /* non-fips algs return -EINVAL in fips mode */
1672 if (fips_enabled && ret == -EINVAL)
1677 static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)
1685 if (!crypto_has_alg(alg, type,
1686 mask ?: CRYPTO_ALG_TYPE_MASK))
1691 for (i = 1; i < 200; i++)
1692 ret += do_test(NULL, 0, 0, i, num_mb);
1696 ret += tcrypt_test("md5");
1700 ret += tcrypt_test("sha1");
1704 ret += tcrypt_test("ecb(des)");
1705 ret += tcrypt_test("cbc(des)");
1706 ret += tcrypt_test("ctr(des)");
1710 ret += tcrypt_test("ecb(des3_ede)");
1711 ret += tcrypt_test("cbc(des3_ede)");
1712 ret += tcrypt_test("ctr(des3_ede)");
1716 ret += tcrypt_test("md4");
1720 ret += tcrypt_test("sha256");
1724 ret += tcrypt_test("ecb(blowfish)");
1725 ret += tcrypt_test("cbc(blowfish)");
1726 ret += tcrypt_test("ctr(blowfish)");
1730 ret += tcrypt_test("ecb(twofish)");
1731 ret += tcrypt_test("cbc(twofish)");
1732 ret += tcrypt_test("ctr(twofish)");
1733 ret += tcrypt_test("lrw(twofish)");
1734 ret += tcrypt_test("xts(twofish)");
1738 ret += tcrypt_test("ecb(serpent)");
1739 ret += tcrypt_test("cbc(serpent)");
1740 ret += tcrypt_test("ctr(serpent)");
1741 ret += tcrypt_test("lrw(serpent)");
1742 ret += tcrypt_test("xts(serpent)");
1746 ret += tcrypt_test("ecb(aes)");
1747 ret += tcrypt_test("cbc(aes)");
1748 ret += tcrypt_test("lrw(aes)");
1749 ret += tcrypt_test("xts(aes)");
1750 ret += tcrypt_test("ctr(aes)");
1751 ret += tcrypt_test("rfc3686(ctr(aes))");
1752 ret += tcrypt_test("ofb(aes)");
1753 ret += tcrypt_test("cfb(aes)");
1757 ret += tcrypt_test("sha384");
1761 ret += tcrypt_test("sha512");
1765 ret += tcrypt_test("deflate");
1769 ret += tcrypt_test("ecb(cast5)");
1770 ret += tcrypt_test("cbc(cast5)");
1771 ret += tcrypt_test("ctr(cast5)");
1775 ret += tcrypt_test("ecb(cast6)");
1776 ret += tcrypt_test("cbc(cast6)");
1777 ret += tcrypt_test("ctr(cast6)");
1778 ret += tcrypt_test("lrw(cast6)");
1779 ret += tcrypt_test("xts(cast6)");
1783 ret += tcrypt_test("ecb(arc4)");
1787 ret += tcrypt_test("michael_mic");
1791 ret += tcrypt_test("crc32c");
1795 ret += tcrypt_test("ecb(tea)");
1799 ret += tcrypt_test("ecb(xtea)");
1803 ret += tcrypt_test("ecb(khazad)");
1807 ret += tcrypt_test("wp512");
1811 ret += tcrypt_test("wp384");
1815 ret += tcrypt_test("wp256");
1819 ret += tcrypt_test("ecb(anubis)");
1820 ret += tcrypt_test("cbc(anubis)");
1824 ret += tcrypt_test("ecb(xeta)");
1828 ret += tcrypt_test("pcbc(fcrypt)");
1832 ret += tcrypt_test("ecb(camellia)");
1833 ret += tcrypt_test("cbc(camellia)");
1834 ret += tcrypt_test("ctr(camellia)");
1835 ret += tcrypt_test("lrw(camellia)");
1836 ret += tcrypt_test("xts(camellia)");
1840 ret += tcrypt_test("sha224");
1844 ret += tcrypt_test("gcm(aes)");
1848 ret += tcrypt_test("lzo");
1852 ret += tcrypt_test("ccm(aes)");
1856 ret += tcrypt_test("cts(cbc(aes))");
1860 ret += tcrypt_test("xxhash64");
1864 ret += tcrypt_test("rmd160");
1868 ret += tcrypt_test("blake2s-256");
1872 ret += tcrypt_test("blake2b-512");
1876 ret += tcrypt_test("ecb(seed)");
1880 ret += tcrypt_test("rfc4309(ccm(aes))");
1884 ret += tcrypt_test("ghash");
1888 ret += tcrypt_test("crct10dif");
1892 ret += tcrypt_test("sha3-224");
1896 ret += tcrypt_test("sha3-256");
1900 ret += tcrypt_test("sha3-384");
1904 ret += tcrypt_test("sha3-512");
1908 ret += tcrypt_test("sm3");
1912 ret += tcrypt_test("streebog256");
1916 ret += tcrypt_test("streebog512");
1920 ret += tcrypt_test("gcm(sm4)");
1924 ret += tcrypt_test("ccm(sm4)");
1928 ret += tcrypt_test("hmac(md5)");
1932 ret += tcrypt_test("hmac(sha1)");
1936 ret += tcrypt_test("hmac(sha256)");
1940 ret += tcrypt_test("hmac(sha384)");
1944 ret += tcrypt_test("hmac(sha512)");
1948 ret += tcrypt_test("hmac(sha224)");
1952 ret += tcrypt_test("xcbc(aes)");
1956 ret += tcrypt_test("hmac(rmd160)");
1960 ret += tcrypt_test("vmac64(aes)");
1964 ret += tcrypt_test("hmac(sha3-224)");
1968 ret += tcrypt_test("hmac(sha3-256)");
1972 ret += tcrypt_test("hmac(sha3-384)");
1976 ret += tcrypt_test("hmac(sha3-512)");
1980 ret += tcrypt_test("hmac(streebog256)");
1984 ret += tcrypt_test("hmac(streebog512)");
1988 ret += tcrypt_test("ansi_cprng");
1992 ret += tcrypt_test("rfc4106(gcm(aes))");
1996 ret += tcrypt_test("rfc4543(gcm(aes))");
2000 ret += tcrypt_test("cmac(aes)");
2004 ret += tcrypt_test("cmac(des3_ede)");
2008 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
2012 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
2016 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
2020 ret += tcrypt_test("cbcmac(sm4)");
2024 ret += tcrypt_test("cmac(sm4)");
2028 ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
2031 ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
2034 ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
2037 ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
2040 ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
2043 ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
2046 ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
2049 ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
2052 ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
2055 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
2058 ret += tcrypt_test("ecb(sm4)");
2059 ret += tcrypt_test("cbc(sm4)");
2060 ret += tcrypt_test("cfb(sm4)");
2061 ret += tcrypt_test("ctr(sm4)");
2064 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2065 speed_template_16_24_32);
2066 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2067 speed_template_16_24_32);
2068 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2069 speed_template_16_24_32);
2070 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2071 speed_template_16_24_32);
2072 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2073 speed_template_32_40_48);
2074 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2075 speed_template_32_40_48);
2076 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2077 speed_template_32_64);
2078 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2079 speed_template_32_64);
2080 test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2081 speed_template_16_24_32);
2082 test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2083 speed_template_16_24_32);
2084 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2085 speed_template_16_24_32);
2086 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2087 speed_template_16_24_32);
2088 test_cipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2089 speed_template_16_24_32);
2090 test_cipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2091 speed_template_16_24_32);
2095 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2096 des3_speed_template, DES3_SPEED_VECTORS,
2098 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
2099 des3_speed_template, DES3_SPEED_VECTORS,
2101 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2102 des3_speed_template, DES3_SPEED_VECTORS,
2104 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
2105 des3_speed_template, DES3_SPEED_VECTORS,
2107 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
2108 des3_speed_template, DES3_SPEED_VECTORS,
2110 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
2111 des3_speed_template, DES3_SPEED_VECTORS,
2116 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2117 speed_template_16_24_32);
2118 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2119 speed_template_16_24_32);
2120 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2121 speed_template_16_24_32);
2122 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2123 speed_template_16_24_32);
2124 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2125 speed_template_16_24_32);
2126 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2127 speed_template_16_24_32);
2128 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2129 speed_template_32_40_48);
2130 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2131 speed_template_32_40_48);
2132 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2133 speed_template_32_48_64);
2134 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2135 speed_template_32_48_64);
2139 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2140 speed_template_8_32);
2141 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2142 speed_template_8_32);
2143 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2144 speed_template_8_32);
2145 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2146 speed_template_8_32);
2147 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2148 speed_template_8_32);
2149 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2150 speed_template_8_32);
2154 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2156 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2158 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2160 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2165 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2166 speed_template_16_24_32);
2167 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2168 speed_template_16_24_32);
2169 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2170 speed_template_16_24_32);
2171 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2172 speed_template_16_24_32);
2173 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2174 speed_template_16_24_32);
2175 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2176 speed_template_16_24_32);
2177 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2178 speed_template_32_40_48);
2179 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2180 speed_template_32_40_48);
2181 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2182 speed_template_32_48_64);
2183 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2184 speed_template_32_48_64);
2188 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2189 speed_template_16_32);
2190 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2191 speed_template_16_32);
2192 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2193 speed_template_16_32);
2194 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2195 speed_template_16_32);
2196 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2197 speed_template_16_32);
2198 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2199 speed_template_16_32);
2200 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2201 speed_template_32_48);
2202 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2203 speed_template_32_48);
2204 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2205 speed_template_32_64);
2206 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2207 speed_template_32_64);
2211 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2216 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2217 speed_template_8_16);
2218 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2219 speed_template_8_16);
2220 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2221 speed_template_8_16);
2222 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2223 speed_template_8_16);
2224 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2225 speed_template_8_16);
2226 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2227 speed_template_8_16);
2231 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2232 speed_template_16_32);
2233 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2234 speed_template_16_32);
2235 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2236 speed_template_16_32);
2237 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2238 speed_template_16_32);
2239 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2240 speed_template_16_32);
2241 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2242 speed_template_16_32);
2243 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2244 speed_template_32_48);
2245 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2246 speed_template_32_48);
2247 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2248 speed_template_32_64);
2249 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2250 speed_template_32_64);
2254 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
2255 NULL, 0, 16, 16, aead_speed_template_20);
2256 test_aead_speed("gcm(aes)", ENCRYPT, sec,
2257 NULL, 0, 16, 8, speed_template_16_24_32);
2258 test_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec,
2259 NULL, 0, 16, 16, aead_speed_template_20);
2260 test_aead_speed("gcm(aes)", DECRYPT, sec,
2261 NULL, 0, 16, 8, speed_template_16_24_32);
2265 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
2266 NULL, 0, 16, 16, aead_speed_template_19);
2267 test_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec,
2268 NULL, 0, 16, 16, aead_speed_template_19);
2272 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
2273 NULL, 0, 16, 8, aead_speed_template_36);
2274 test_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT, sec,
2275 NULL, 0, 16, 8, aead_speed_template_36);
2279 test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
2284 test_mb_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec, NULL,
2285 0, 16, 16, aead_speed_template_20, num_mb);
2286 test_mb_aead_speed("gcm(aes)", ENCRYPT, sec, NULL, 0, 16, 8,
2287 speed_template_16_24_32, num_mb);
2288 test_mb_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec, NULL,
2289 0, 16, 16, aead_speed_template_20, num_mb);
2290 test_mb_aead_speed("gcm(aes)", DECRYPT, sec, NULL, 0, 16, 8,
2291 speed_template_16_24_32, num_mb);
2295 test_mb_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec, NULL, 0,
2296 16, 16, aead_speed_template_19, num_mb);
2297 test_mb_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec, NULL, 0,
2298 16, 16, aead_speed_template_19, num_mb);
2302 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT,
2303 sec, NULL, 0, 16, 8, aead_speed_template_36,
2305 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT,
2306 sec, NULL, 0, 16, 8, aead_speed_template_36,
2311 test_cipher_speed("ecb(sm4)", ENCRYPT, sec, NULL, 0,
2313 test_cipher_speed("ecb(sm4)", DECRYPT, sec, NULL, 0,
2315 test_cipher_speed("cbc(sm4)", ENCRYPT, sec, NULL, 0,
2317 test_cipher_speed("cbc(sm4)", DECRYPT, sec, NULL, 0,
2319 test_cipher_speed("cfb(sm4)", ENCRYPT, sec, NULL, 0,
2321 test_cipher_speed("cfb(sm4)", DECRYPT, sec, NULL, 0,
2323 test_cipher_speed("ctr(sm4)", ENCRYPT, sec, NULL, 0,
2325 test_cipher_speed("ctr(sm4)", DECRYPT, sec, NULL, 0,
2330 test_cipher_speed("adiantum(xchacha12,aes)", ENCRYPT, sec, NULL,
2331 0, speed_template_32);
2332 test_cipher_speed("adiantum(xchacha12,aes)", DECRYPT, sec, NULL,
2333 0, speed_template_32);
2334 test_cipher_speed("adiantum(xchacha20,aes)", ENCRYPT, sec, NULL,
2335 0, speed_template_32);
2336 test_cipher_speed("adiantum(xchacha20,aes)", DECRYPT, sec, NULL,
2337 0, speed_template_32);
2341 test_acipher_speed("essiv(cbc(aes),sha256)",
2342 ENCRYPT, sec, NULL, 0,
2343 speed_template_16_24_32);
2344 test_acipher_speed("essiv(cbc(aes),sha256)",
2345 DECRYPT, sec, NULL, 0,
2346 speed_template_16_24_32);
2350 test_aead_speed("aegis128", ENCRYPT, sec,
2351 NULL, 0, 16, 8, speed_template_16);
2352 test_aead_speed("aegis128", DECRYPT, sec,
2353 NULL, 0, 16, 8, speed_template_16);
2357 test_aead_speed("gcm(sm4)", ENCRYPT, sec,
2358 NULL, 0, 16, 8, speed_template_16);
2359 test_aead_speed("gcm(sm4)", DECRYPT, sec,
2360 NULL, 0, 16, 8, speed_template_16);
2364 test_aead_speed("rfc4309(ccm(sm4))", ENCRYPT, sec,
2365 NULL, 0, 16, 16, aead_speed_template_19);
2366 test_aead_speed("rfc4309(ccm(sm4))", DECRYPT, sec,
2367 NULL, 0, 16, 16, aead_speed_template_19);
2371 test_mb_aead_speed("gcm(sm4)", ENCRYPT, sec, NULL, 0, 16, 8,
2372 speed_template_16, num_mb);
2373 test_mb_aead_speed("gcm(sm4)", DECRYPT, sec, NULL, 0, 16, 8,
2374 speed_template_16, num_mb);
2378 test_mb_aead_speed("rfc4309(ccm(sm4))", ENCRYPT, sec, NULL, 0,
2379 16, 16, aead_speed_template_19, num_mb);
2380 test_mb_aead_speed("rfc4309(ccm(sm4))", DECRYPT, sec, NULL, 0,
2381 16, 16, aead_speed_template_19, num_mb);
2386 test_hash_speed(alg, sec, generic_hash_speed_template);
2391 test_hash_speed("md4", sec, generic_hash_speed_template);
2392 if (mode > 300 && mode < 400) break;
2395 test_hash_speed("md5", sec, generic_hash_speed_template);
2396 if (mode > 300 && mode < 400) break;
2399 test_hash_speed("sha1", sec, generic_hash_speed_template);
2400 if (mode > 300 && mode < 400) break;
2403 test_hash_speed("sha256", sec, generic_hash_speed_template);
2404 if (mode > 300 && mode < 400) break;
2407 test_hash_speed("sha384", sec, generic_hash_speed_template);
2408 if (mode > 300 && mode < 400) break;
2411 test_hash_speed("sha512", sec, generic_hash_speed_template);
2412 if (mode > 300 && mode < 400) break;
2415 test_hash_speed("wp256", sec, generic_hash_speed_template);
2416 if (mode > 300 && mode < 400) break;
2419 test_hash_speed("wp384", sec, generic_hash_speed_template);
2420 if (mode > 300 && mode < 400) break;
2423 test_hash_speed("wp512", sec, generic_hash_speed_template);
2424 if (mode > 300 && mode < 400) break;
2427 test_hash_speed("sha224", sec, generic_hash_speed_template);
2428 if (mode > 300 && mode < 400) break;
2431 test_hash_speed("xxhash64", sec, generic_hash_speed_template);
2432 if (mode > 300 && mode < 400) break;
2435 test_hash_speed("rmd160", sec, generic_hash_speed_template);
2436 if (mode > 300 && mode < 400) break;
2439 test_hash_speed("blake2s-256", sec, generic_hash_speed_template);
2440 if (mode > 300 && mode < 400) break;
2443 test_hash_speed("blake2b-512", sec, generic_hash_speed_template);
2444 if (mode > 300 && mode < 400) break;
2448 test_hash_speed("ghash", sec, generic_hash_speed_template);
2449 if (mode > 300 && mode < 400) break;
2452 test_hash_speed("crc32c", sec, generic_hash_speed_template);
2453 if (mode > 300 && mode < 400) break;
2456 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
2457 if (mode > 300 && mode < 400) break;
2460 test_hash_speed("poly1305", sec, poly1305_speed_template);
2461 if (mode > 300 && mode < 400) break;
2464 test_hash_speed("sha3-224", sec, generic_hash_speed_template);
2465 if (mode > 300 && mode < 400) break;
2468 test_hash_speed("sha3-256", sec, generic_hash_speed_template);
2469 if (mode > 300 && mode < 400) break;
2472 test_hash_speed("sha3-384", sec, generic_hash_speed_template);
2473 if (mode > 300 && mode < 400) break;
2476 test_hash_speed("sha3-512", sec, generic_hash_speed_template);
2477 if (mode > 300 && mode < 400) break;
2480 test_hash_speed("sm3", sec, generic_hash_speed_template);
2481 if (mode > 300 && mode < 400) break;
2484 test_hash_speed("streebog256", sec,
2485 generic_hash_speed_template);
2486 if (mode > 300 && mode < 400) break;
2489 test_hash_speed("streebog512", sec,
2490 generic_hash_speed_template);
2491 if (mode > 300 && mode < 400) break;
2498 test_ahash_speed(alg, sec, generic_hash_speed_template);
2503 test_ahash_speed("md4", sec, generic_hash_speed_template);
2504 if (mode > 400 && mode < 500) break;
2507 test_ahash_speed("md5", sec, generic_hash_speed_template);
2508 if (mode > 400 && mode < 500) break;
2511 test_ahash_speed("sha1", sec, generic_hash_speed_template);
2512 if (mode > 400 && mode < 500) break;
2515 test_ahash_speed("sha256", sec, generic_hash_speed_template);
2516 if (mode > 400 && mode < 500) break;
2519 test_ahash_speed("sha384", sec, generic_hash_speed_template);
2520 if (mode > 400 && mode < 500) break;
2523 test_ahash_speed("sha512", sec, generic_hash_speed_template);
2524 if (mode > 400 && mode < 500) break;
2527 test_ahash_speed("wp256", sec, generic_hash_speed_template);
2528 if (mode > 400 && mode < 500) break;
2531 test_ahash_speed("wp384", sec, generic_hash_speed_template);
2532 if (mode > 400 && mode < 500) break;
2535 test_ahash_speed("wp512", sec, generic_hash_speed_template);
2536 if (mode > 400 && mode < 500) break;
2539 test_ahash_speed("sha224", sec, generic_hash_speed_template);
2540 if (mode > 400 && mode < 500) break;
2543 test_ahash_speed("xxhash64", sec, generic_hash_speed_template);
2544 if (mode > 400 && mode < 500) break;
2547 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
2548 if (mode > 400 && mode < 500) break;
2551 test_ahash_speed("blake2s-256", sec, generic_hash_speed_template);
2552 if (mode > 400 && mode < 500) break;
2555 test_ahash_speed("blake2b-512", sec, generic_hash_speed_template);
2556 if (mode > 400 && mode < 500) break;
2559 test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
2560 if (mode > 400 && mode < 500) break;
2563 test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
2564 if (mode > 400 && mode < 500) break;
2567 test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
2568 if (mode > 400 && mode < 500) break;
2571 test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
2572 if (mode > 400 && mode < 500) break;
2575 test_mb_ahash_speed("sha1", sec, generic_hash_speed_template,
2577 if (mode > 400 && mode < 500) break;
2580 test_mb_ahash_speed("sha256", sec, generic_hash_speed_template,
2582 if (mode > 400 && mode < 500) break;
2585 test_mb_ahash_speed("sha512", sec, generic_hash_speed_template,
2587 if (mode > 400 && mode < 500) break;
2590 test_mb_ahash_speed("sm3", sec, generic_hash_speed_template,
2592 if (mode > 400 && mode < 500) break;
2595 test_mb_ahash_speed("streebog256", sec,
2596 generic_hash_speed_template, num_mb);
2597 if (mode > 400 && mode < 500) break;
2600 test_mb_ahash_speed("streebog512", sec,
2601 generic_hash_speed_template, num_mb);
2602 if (mode > 400 && mode < 500) break;
2608 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2609 speed_template_16_24_32);
2610 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2611 speed_template_16_24_32);
2612 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2613 speed_template_16_24_32);
2614 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2615 speed_template_16_24_32);
2616 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2617 speed_template_32_40_48);
2618 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2619 speed_template_32_40_48);
2620 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2621 speed_template_32_64);
2622 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2623 speed_template_32_64);
2624 test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2625 speed_template_16_24_32);
2626 test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2627 speed_template_16_24_32);
2628 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2629 speed_template_16_24_32);
2630 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2631 speed_template_16_24_32);
2632 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2633 speed_template_16_24_32);
2634 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2635 speed_template_16_24_32);
2636 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2637 speed_template_16_24_32);
2638 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2639 speed_template_16_24_32);
2640 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
2641 speed_template_20_28_36);
2642 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
2643 speed_template_20_28_36);
2647 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2648 des3_speed_template, DES3_SPEED_VECTORS,
2650 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
2651 des3_speed_template, DES3_SPEED_VECTORS,
2653 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2654 des3_speed_template, DES3_SPEED_VECTORS,
2656 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
2657 des3_speed_template, DES3_SPEED_VECTORS,
2659 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2660 des3_speed_template, DES3_SPEED_VECTORS,
2662 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
2663 des3_speed_template, DES3_SPEED_VECTORS,
2665 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2666 des3_speed_template, DES3_SPEED_VECTORS,
2668 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
2669 des3_speed_template, DES3_SPEED_VECTORS,
2674 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2676 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2678 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2680 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2682 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2684 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2686 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2688 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2693 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2694 speed_template_16_32);
2695 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2696 speed_template_16_32);
2697 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2698 speed_template_16_32);
2699 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2700 speed_template_16_32);
2701 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2702 speed_template_16_32);
2703 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2704 speed_template_16_32);
2705 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2706 speed_template_32_48);
2707 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2708 speed_template_32_48);
2709 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2710 speed_template_32_64);
2711 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2712 speed_template_32_64);
2716 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2717 speed_template_16_24_32);
2718 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2719 speed_template_16_24_32);
2720 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2721 speed_template_16_24_32);
2722 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2723 speed_template_16_24_32);
2724 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2725 speed_template_16_24_32);
2726 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2727 speed_template_16_24_32);
2728 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2729 speed_template_32_40_48);
2730 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2731 speed_template_32_40_48);
2732 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2733 speed_template_32_48_64);
2734 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2735 speed_template_32_48_64);
2739 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2744 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2745 speed_template_8_16);
2746 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2747 speed_template_8_16);
2748 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2749 speed_template_8_16);
2750 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2751 speed_template_8_16);
2752 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2753 speed_template_8_16);
2754 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2755 speed_template_8_16);
2759 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2760 speed_template_16_32);
2761 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2762 speed_template_16_32);
2763 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2764 speed_template_16_32);
2765 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2766 speed_template_16_32);
2767 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2768 speed_template_16_32);
2769 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2770 speed_template_16_32);
2771 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2772 speed_template_32_48);
2773 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2774 speed_template_32_48);
2775 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2776 speed_template_32_64);
2777 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2778 speed_template_32_64);
2782 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2783 speed_template_16_32);
2784 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2785 speed_template_16_32);
2786 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2787 speed_template_16_32);
2788 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2789 speed_template_16_32);
2790 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2791 speed_template_16_32);
2792 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2793 speed_template_16_32);
2794 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2795 speed_template_32_48);
2796 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2797 speed_template_32_48);
2798 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2799 speed_template_32_64);
2800 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2801 speed_template_32_64);
2805 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2806 speed_template_8_32);
2807 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2808 speed_template_8_32);
2809 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2810 speed_template_8_32);
2811 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2812 speed_template_8_32);
2813 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2814 speed_template_8_32);
2815 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2816 speed_template_8_32);
2820 test_acipher_speed("ecb(sm4)", ENCRYPT, sec, NULL, 0,
2822 test_acipher_speed("ecb(sm4)", DECRYPT, sec, NULL, 0,
2824 test_acipher_speed("cbc(sm4)", ENCRYPT, sec, NULL, 0,
2826 test_acipher_speed("cbc(sm4)", DECRYPT, sec, NULL, 0,
2828 test_acipher_speed("cfb(sm4)", ENCRYPT, sec, NULL, 0,
2830 test_acipher_speed("cfb(sm4)", DECRYPT, sec, NULL, 0,
2832 test_acipher_speed("ctr(sm4)", ENCRYPT, sec, NULL, 0,
2834 test_acipher_speed("ctr(sm4)", DECRYPT, sec, NULL, 0,
2839 test_mb_skcipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2840 speed_template_16_24_32, num_mb);
2841 test_mb_skcipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2842 speed_template_16_24_32, num_mb);
2843 test_mb_skcipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2844 speed_template_16_24_32, num_mb);
2845 test_mb_skcipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2846 speed_template_16_24_32, num_mb);
2847 test_mb_skcipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2848 speed_template_32_40_48, num_mb);
2849 test_mb_skcipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2850 speed_template_32_40_48, num_mb);
2851 test_mb_skcipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2852 speed_template_32_64, num_mb);
2853 test_mb_skcipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2854 speed_template_32_64, num_mb);
2855 test_mb_skcipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2856 speed_template_16_24_32, num_mb);
2857 test_mb_skcipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2858 speed_template_16_24_32, num_mb);
2859 test_mb_skcipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2860 speed_template_16_24_32, num_mb);
2861 test_mb_skcipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2862 speed_template_16_24_32, num_mb);
2863 test_mb_skcipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2864 speed_template_16_24_32, num_mb);
2865 test_mb_skcipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2866 speed_template_16_24_32, num_mb);
2867 test_mb_skcipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2868 speed_template_16_24_32, num_mb);
2869 test_mb_skcipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2870 speed_template_16_24_32, num_mb);
2871 test_mb_skcipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL,
2872 0, speed_template_20_28_36, num_mb);
2873 test_mb_skcipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL,
2874 0, speed_template_20_28_36, num_mb);
2878 test_mb_skcipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2879 des3_speed_template, DES3_SPEED_VECTORS,
2880 speed_template_24, num_mb);
2881 test_mb_skcipher_speed("ecb(des3_ede)", DECRYPT, sec,
2882 des3_speed_template, DES3_SPEED_VECTORS,
2883 speed_template_24, num_mb);
2884 test_mb_skcipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2885 des3_speed_template, DES3_SPEED_VECTORS,
2886 speed_template_24, num_mb);
2887 test_mb_skcipher_speed("cbc(des3_ede)", DECRYPT, sec,
2888 des3_speed_template, DES3_SPEED_VECTORS,
2889 speed_template_24, num_mb);
2890 test_mb_skcipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2891 des3_speed_template, DES3_SPEED_VECTORS,
2892 speed_template_24, num_mb);
2893 test_mb_skcipher_speed("cfb(des3_ede)", DECRYPT, sec,
2894 des3_speed_template, DES3_SPEED_VECTORS,
2895 speed_template_24, num_mb);
2896 test_mb_skcipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2897 des3_speed_template, DES3_SPEED_VECTORS,
2898 speed_template_24, num_mb);
2899 test_mb_skcipher_speed("ofb(des3_ede)", DECRYPT, sec,
2900 des3_speed_template, DES3_SPEED_VECTORS,
2901 speed_template_24, num_mb);
2905 test_mb_skcipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2906 speed_template_8, num_mb);
2907 test_mb_skcipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2908 speed_template_8, num_mb);
2909 test_mb_skcipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2910 speed_template_8, num_mb);
2911 test_mb_skcipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2912 speed_template_8, num_mb);
2913 test_mb_skcipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2914 speed_template_8, num_mb);
2915 test_mb_skcipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2916 speed_template_8, num_mb);
2917 test_mb_skcipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2918 speed_template_8, num_mb);
2919 test_mb_skcipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2920 speed_template_8, num_mb);
2924 test_mb_skcipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2925 speed_template_16_32, num_mb);
2926 test_mb_skcipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2927 speed_template_16_32, num_mb);
2928 test_mb_skcipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2929 speed_template_16_32, num_mb);
2930 test_mb_skcipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2931 speed_template_16_32, num_mb);
2932 test_mb_skcipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2933 speed_template_16_32, num_mb);
2934 test_mb_skcipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2935 speed_template_16_32, num_mb);
2936 test_mb_skcipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2937 speed_template_32_48, num_mb);
2938 test_mb_skcipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2939 speed_template_32_48, num_mb);
2940 test_mb_skcipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2941 speed_template_32_64, num_mb);
2942 test_mb_skcipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2943 speed_template_32_64, num_mb);
2947 test_mb_skcipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2948 speed_template_16_24_32, num_mb);
2949 test_mb_skcipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2950 speed_template_16_24_32, num_mb);
2951 test_mb_skcipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2952 speed_template_16_24_32, num_mb);
2953 test_mb_skcipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2954 speed_template_16_24_32, num_mb);
2955 test_mb_skcipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2956 speed_template_16_24_32, num_mb);
2957 test_mb_skcipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2958 speed_template_16_24_32, num_mb);
2959 test_mb_skcipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2960 speed_template_32_40_48, num_mb);
2961 test_mb_skcipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2962 speed_template_32_40_48, num_mb);
2963 test_mb_skcipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2964 speed_template_32_48_64, num_mb);
2965 test_mb_skcipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2966 speed_template_32_48_64, num_mb);
2970 test_mb_skcipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2971 speed_template_8, num_mb);
2975 test_mb_skcipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2976 speed_template_8_16, num_mb);
2977 test_mb_skcipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2978 speed_template_8_16, num_mb);
2979 test_mb_skcipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2980 speed_template_8_16, num_mb);
2981 test_mb_skcipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2982 speed_template_8_16, num_mb);
2983 test_mb_skcipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2984 speed_template_8_16, num_mb);
2985 test_mb_skcipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2986 speed_template_8_16, num_mb);
2990 test_mb_skcipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2991 speed_template_16_32, num_mb);
2992 test_mb_skcipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2993 speed_template_16_32, num_mb);
2994 test_mb_skcipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2995 speed_template_16_32, num_mb);
2996 test_mb_skcipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2997 speed_template_16_32, num_mb);
2998 test_mb_skcipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2999 speed_template_16_32, num_mb);
3000 test_mb_skcipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
3001 speed_template_16_32, num_mb);
3002 test_mb_skcipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
3003 speed_template_32_48, num_mb);
3004 test_mb_skcipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
3005 speed_template_32_48, num_mb);
3006 test_mb_skcipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
3007 speed_template_32_64, num_mb);
3008 test_mb_skcipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
3009 speed_template_32_64, num_mb);
3013 test_mb_skcipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
3014 speed_template_16_32, num_mb);
3015 test_mb_skcipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
3016 speed_template_16_32, num_mb);
3017 test_mb_skcipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
3018 speed_template_16_32, num_mb);
3019 test_mb_skcipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
3020 speed_template_16_32, num_mb);
3021 test_mb_skcipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
3022 speed_template_16_32, num_mb);
3023 test_mb_skcipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
3024 speed_template_16_32, num_mb);
3025 test_mb_skcipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
3026 speed_template_32_48, num_mb);
3027 test_mb_skcipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
3028 speed_template_32_48, num_mb);
3029 test_mb_skcipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
3030 speed_template_32_64, num_mb);
3031 test_mb_skcipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
3032 speed_template_32_64, num_mb);
3036 test_mb_skcipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
3037 speed_template_8_32, num_mb);
3038 test_mb_skcipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
3039 speed_template_8_32, num_mb);
3040 test_mb_skcipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
3041 speed_template_8_32, num_mb);
3042 test_mb_skcipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
3043 speed_template_8_32, num_mb);
3044 test_mb_skcipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
3045 speed_template_8_32, num_mb);
3046 test_mb_skcipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
3047 speed_template_8_32, num_mb);
3058 static int __init tcrypt_mod_init(void)
3063 for (i = 0; i < TVMEMSIZE; i++) {
3064 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
3069 err = do_test(alg, type, mask, mode, num_mb);
3072 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
3075 pr_debug("all tests passed\n");
3078 /* We intentionaly return -EAGAIN to prevent keeping the module,
3079 * unless we're running in fips mode. It does all its work from
3080 * init() and doesn't offer any runtime functionality, but in
3081 * the fips case, checking for a successful load is helpful.
3082 * => we don't need it in the memory, do we?
3089 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
3090 free_page((unsigned long)tvmem[i]);
3096 * If an init function is provided, an exit function must also be provided
3097 * to allow module unload.
3099 static void __exit tcrypt_mod_fini(void) { }
3101 late_initcall(tcrypt_mod_init);
3102 module_exit(tcrypt_mod_fini);
3104 module_param(alg, charp, 0);
3105 module_param(type, uint, 0);
3106 module_param(mask, uint, 0);
3107 module_param(mode, int, 0);
3108 module_param(sec, uint, 0);
3109 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
3110 "(defaults to zero which uses CPU cycles instead)");
3111 module_param(num_mb, uint, 0000);
3112 MODULE_PARM_DESC(num_mb, "Number of concurrent requests to be used in mb speed tests (defaults to 8)");
3113 module_param(klen, uint, 0);
3114 MODULE_PARM_DESC(klen, "Key length (defaults to 0)");
3116 MODULE_LICENSE("GPL");
3117 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
3118 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");