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 static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
730 unsigned long start, end;
734 for (start = jiffies, end = start + secs * HZ, bcount = 0;
735 time_before(jiffies, end); bcount++) {
736 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
741 printk("%6u opers/sec, %9lu bytes/sec\n",
742 bcount / secs, ((long)bcount * blen) / secs);
747 static int test_ahash_jiffies(struct ahash_request *req, int blen,
748 int plen, char *out, int secs)
750 unsigned long start, end;
755 return test_ahash_jiffies_digest(req, blen, out, secs);
757 for (start = jiffies, end = start + secs * HZ, bcount = 0;
758 time_before(jiffies, end); bcount++) {
759 ret = do_one_ahash_op(req, crypto_ahash_init(req));
762 for (pcount = 0; pcount < blen; pcount += plen) {
763 ret = do_one_ahash_op(req, crypto_ahash_update(req));
767 /* we assume there is enough space in 'out' for the result */
768 ret = do_one_ahash_op(req, crypto_ahash_final(req));
773 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
774 bcount / secs, ((long)bcount * blen) / secs);
779 static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
782 unsigned long cycles = 0;
786 for (i = 0; i < 4; i++) {
787 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
792 /* The real thing. */
793 for (i = 0; i < 8; i++) {
796 start = get_cycles();
798 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
804 cycles += end - start;
811 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
812 cycles / 8, cycles / (8 * blen));
817 static int test_ahash_cycles(struct ahash_request *req, int blen,
820 unsigned long cycles = 0;
824 return test_ahash_cycles_digest(req, blen, out);
827 for (i = 0; i < 4; i++) {
828 ret = do_one_ahash_op(req, crypto_ahash_init(req));
831 for (pcount = 0; pcount < blen; pcount += plen) {
832 ret = do_one_ahash_op(req, crypto_ahash_update(req));
836 ret = do_one_ahash_op(req, crypto_ahash_final(req));
841 /* The real thing. */
842 for (i = 0; i < 8; i++) {
845 start = get_cycles();
847 ret = do_one_ahash_op(req, crypto_ahash_init(req));
850 for (pcount = 0; pcount < blen; pcount += plen) {
851 ret = do_one_ahash_op(req, crypto_ahash_update(req));
855 ret = do_one_ahash_op(req, crypto_ahash_final(req));
861 cycles += end - start;
868 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
869 cycles / 8, cycles / (8 * blen));
874 static void test_ahash_speed_common(const char *algo, unsigned int secs,
875 struct hash_speed *speed, unsigned mask)
877 struct scatterlist sg[TVMEMSIZE];
878 struct crypto_wait wait;
879 struct ahash_request *req;
880 struct crypto_ahash *tfm;
884 tfm = crypto_alloc_ahash(algo, 0, mask);
886 pr_err("failed to load transform for %s: %ld\n",
891 printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
892 get_driver_name(crypto_ahash, tfm));
894 if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) {
895 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm),
900 test_hash_sg_init(sg);
901 req = ahash_request_alloc(tfm, GFP_KERNEL);
903 pr_err("ahash request allocation failure\n");
907 crypto_init_wait(&wait);
908 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
909 crypto_req_done, &wait);
911 output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
915 for (i = 0; speed[i].blen != 0; i++) {
916 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
917 pr_err("template (%u) too big for tvmem (%lu)\n",
918 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
923 crypto_ahash_setkey(tfm, tvmem[0], klen);
926 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
927 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
929 ahash_request_set_crypt(req, sg, output, speed[i].plen);
932 ret = test_ahash_jiffies(req, speed[i].blen,
933 speed[i].plen, output, secs);
936 ret = test_ahash_cycles(req, speed[i].blen,
937 speed[i].plen, output);
941 pr_err("hashing failed ret=%d\n", ret);
949 ahash_request_free(req);
952 crypto_free_ahash(tfm);
955 static void test_ahash_speed(const char *algo, unsigned int secs,
956 struct hash_speed *speed)
958 return test_ahash_speed_common(algo, secs, speed, 0);
961 static void test_hash_speed(const char *algo, unsigned int secs,
962 struct hash_speed *speed)
964 return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC);
967 struct test_mb_skcipher_data {
968 struct scatterlist sg[XBUFSIZE];
969 struct skcipher_request *req;
970 struct crypto_wait wait;
971 char *xbuf[XBUFSIZE];
974 static int do_mult_acipher_op(struct test_mb_skcipher_data *data, int enc,
979 /* Fire up a bunch of concurrent requests */
980 for (i = 0; i < num_mb; i++) {
982 rc[i] = crypto_skcipher_encrypt(data[i].req);
984 rc[i] = crypto_skcipher_decrypt(data[i].req);
987 /* Wait for all requests to finish */
988 for (i = 0; i < num_mb; i++) {
989 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
992 pr_info("concurrent request %d error %d\n", i, rc[i]);
1000 static int test_mb_acipher_jiffies(struct test_mb_skcipher_data *data, int enc,
1001 int blen, int secs, u32 num_mb)
1003 unsigned long start, end;
1008 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
1012 for (start = jiffies, end = start + secs * HZ, bcount = 0;
1013 time_before(jiffies, end); bcount++) {
1014 ret = do_mult_acipher_op(data, enc, num_mb, rc);
1019 pr_cont("%d operations in %d seconds (%llu bytes)\n",
1020 bcount * num_mb, secs, (u64)bcount * blen * num_mb);
1027 static int test_mb_acipher_cycles(struct test_mb_skcipher_data *data, int enc,
1028 int blen, u32 num_mb)
1030 unsigned long cycles = 0;
1035 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
1040 for (i = 0; i < 4; i++) {
1041 ret = do_mult_acipher_op(data, enc, num_mb, rc);
1046 /* The real thing. */
1047 for (i = 0; i < 8; i++) {
1048 cycles_t start, end;
1050 start = get_cycles();
1051 ret = do_mult_acipher_op(data, enc, num_mb, rc);
1057 cycles += end - start;
1060 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1061 (cycles + 4) / (8 * num_mb), blen);
1068 static void test_mb_skcipher_speed(const char *algo, int enc, int secs,
1069 struct cipher_speed_template *template,
1070 unsigned int tcount, u8 *keysize, u32 num_mb)
1072 struct test_mb_skcipher_data *data;
1073 struct crypto_skcipher *tfm;
1074 unsigned int i, j, iv_len;
1086 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
1090 tfm = crypto_alloc_skcipher(algo, 0, 0);
1092 pr_err("failed to load transform for %s: %ld\n",
1093 algo, PTR_ERR(tfm));
1097 for (i = 0; i < num_mb; ++i)
1098 if (testmgr_alloc_buf(data[i].xbuf)) {
1100 testmgr_free_buf(data[i].xbuf);
1105 for (i = 0; i < num_mb; ++i)
1106 if (testmgr_alloc_buf(data[i].xbuf)) {
1108 testmgr_free_buf(data[i].xbuf);
1113 for (i = 0; i < num_mb; ++i) {
1114 data[i].req = skcipher_request_alloc(tfm, GFP_KERNEL);
1116 pr_err("alg: skcipher: Failed to allocate request for %s\n",
1119 skcipher_request_free(data[i].req);
1124 for (i = 0; i < num_mb; ++i) {
1125 skcipher_request_set_callback(data[i].req,
1126 CRYPTO_TFM_REQ_MAY_BACKLOG,
1127 crypto_req_done, &data[i].wait);
1128 crypto_init_wait(&data[i].wait);
1131 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo,
1132 get_driver_name(crypto_skcipher, tfm), e);
1136 b_size = block_sizes;
1138 u32 bs = round_up(*b_size, crypto_skcipher_blocksize(tfm));
1140 if (bs > XBUFSIZE * PAGE_SIZE) {
1141 pr_err("template (%u) too big for buffer (%lu)\n",
1142 bs, XBUFSIZE * PAGE_SIZE);
1146 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1149 /* Set up tfm global state, i.e. the key */
1151 memset(tvmem[0], 0xff, PAGE_SIZE);
1153 for (j = 0; j < tcount; j++) {
1154 if (template[j].klen == *keysize) {
1155 key = template[j].key;
1160 crypto_skcipher_clear_flags(tfm, ~0);
1162 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1164 pr_err("setkey() failed flags=%x\n",
1165 crypto_skcipher_get_flags(tfm));
1169 iv_len = crypto_skcipher_ivsize(tfm);
1171 memset(&iv, 0xff, iv_len);
1173 /* Now setup per request stuff, i.e. buffers */
1175 for (j = 0; j < num_mb; ++j) {
1176 struct test_mb_skcipher_data *cur = &data[j];
1177 unsigned int k = bs;
1178 unsigned int pages = DIV_ROUND_UP(k, PAGE_SIZE);
1181 sg_init_table(cur->sg, pages);
1183 while (k > PAGE_SIZE) {
1184 sg_set_buf(cur->sg + p, cur->xbuf[p],
1186 memset(cur->xbuf[p], 0xff, PAGE_SIZE);
1191 sg_set_buf(cur->sg + p, cur->xbuf[p], k);
1192 memset(cur->xbuf[p], 0xff, k);
1194 skcipher_request_set_crypt(cur->req, cur->sg,
1199 ret = test_mb_acipher_jiffies(data, enc,
1204 ret = test_mb_acipher_cycles(data, enc,
1209 pr_err("%s() failed flags=%x\n", e,
1210 crypto_skcipher_get_flags(tfm));
1220 for (i = 0; i < num_mb; ++i)
1221 skcipher_request_free(data[i].req);
1223 for (i = 0; i < num_mb; ++i)
1224 testmgr_free_buf(data[i].xbuf);
1226 crypto_free_skcipher(tfm);
1231 static inline int do_one_acipher_op(struct skcipher_request *req, int ret)
1233 struct crypto_wait *wait = req->base.data;
1235 return crypto_wait_req(ret, wait);
1238 static int test_acipher_jiffies(struct skcipher_request *req, int enc,
1241 unsigned long start, end;
1245 for (start = jiffies, end = start + secs * HZ, bcount = 0;
1246 time_before(jiffies, end); bcount++) {
1248 ret = do_one_acipher_op(req,
1249 crypto_skcipher_encrypt(req));
1251 ret = do_one_acipher_op(req,
1252 crypto_skcipher_decrypt(req));
1258 pr_cont("%d operations in %d seconds (%llu bytes)\n",
1259 bcount, secs, (u64)bcount * blen);
1263 static int test_acipher_cycles(struct skcipher_request *req, int enc,
1266 unsigned long cycles = 0;
1271 for (i = 0; i < 4; i++) {
1273 ret = do_one_acipher_op(req,
1274 crypto_skcipher_encrypt(req));
1276 ret = do_one_acipher_op(req,
1277 crypto_skcipher_decrypt(req));
1283 /* The real thing. */
1284 for (i = 0; i < 8; i++) {
1285 cycles_t start, end;
1287 start = get_cycles();
1289 ret = do_one_acipher_op(req,
1290 crypto_skcipher_encrypt(req));
1292 ret = do_one_acipher_op(req,
1293 crypto_skcipher_decrypt(req));
1299 cycles += end - start;
1304 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1305 (cycles + 4) / 8, blen);
1310 static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
1311 struct cipher_speed_template *template,
1312 unsigned int tcount, u8 *keysize, bool async)
1314 unsigned int ret, i, j, k, iv_len;
1315 struct crypto_wait wait;
1318 struct skcipher_request *req;
1319 struct crypto_skcipher *tfm;
1328 crypto_init_wait(&wait);
1330 tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC);
1333 pr_err("failed to load transform for %s: %ld\n", algo,
1338 pr_info("\ntesting speed of %s %s (%s) %s\n", async ? "async" : "sync",
1339 algo, get_driver_name(crypto_skcipher, tfm), e);
1341 req = skcipher_request_alloc(tfm, GFP_KERNEL);
1343 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1348 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1349 crypto_req_done, &wait);
1353 b_size = block_sizes;
1356 u32 bs = round_up(*b_size, crypto_skcipher_blocksize(tfm));
1357 struct scatterlist sg[TVMEMSIZE];
1359 if ((*keysize + bs) > TVMEMSIZE * PAGE_SIZE) {
1360 pr_err("template (%u) too big for "
1361 "tvmem (%lu)\n", *keysize + bs,
1362 TVMEMSIZE * PAGE_SIZE);
1366 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1369 memset(tvmem[0], 0xff, PAGE_SIZE);
1371 /* set key, plain text and IV */
1373 for (j = 0; j < tcount; j++) {
1374 if (template[j].klen == *keysize) {
1375 key = template[j].key;
1380 crypto_skcipher_clear_flags(tfm, ~0);
1382 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1384 pr_err("setkey() failed flags=%x\n",
1385 crypto_skcipher_get_flags(tfm));
1390 sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
1392 if (k > PAGE_SIZE) {
1393 sg_set_buf(sg, tvmem[0] + *keysize,
1394 PAGE_SIZE - *keysize);
1397 while (k > PAGE_SIZE) {
1398 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
1399 memset(tvmem[j], 0xff, PAGE_SIZE);
1403 sg_set_buf(sg + j, tvmem[j], k);
1404 memset(tvmem[j], 0xff, k);
1406 sg_set_buf(sg, tvmem[0] + *keysize, bs);
1409 iv_len = crypto_skcipher_ivsize(tfm);
1411 memset(&iv, 0xff, iv_len);
1413 skcipher_request_set_crypt(req, sg, sg, bs, iv);
1416 ret = test_acipher_jiffies(req, enc,
1420 ret = test_acipher_cycles(req, enc,
1425 pr_err("%s() failed flags=%x\n", e,
1426 crypto_skcipher_get_flags(tfm));
1436 skcipher_request_free(req);
1438 crypto_free_skcipher(tfm);
1441 static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
1442 struct cipher_speed_template *template,
1443 unsigned int tcount, u8 *keysize)
1445 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1449 static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
1450 struct cipher_speed_template *template,
1451 unsigned int tcount, u8 *keysize)
1453 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1457 static void test_available(void)
1459 const char **name = check;
1462 printk("alg %s ", *name);
1463 printk(crypto_has_alg(*name, 0, 0) ?
1464 "found\n" : "not found\n");
1469 static inline int tcrypt_test(const char *alg)
1473 pr_debug("testing %s\n", alg);
1475 ret = alg_test(alg, alg, 0, 0);
1476 /* non-fips algs return -EINVAL or -ECANCELED in fips mode */
1477 if (fips_enabled && (ret == -EINVAL || ret == -ECANCELED))
1482 static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)
1490 if (!crypto_has_alg(alg, type,
1491 mask ?: CRYPTO_ALG_TYPE_MASK))
1496 for (i = 1; i < 200; i++)
1497 ret += do_test(NULL, 0, 0, i, num_mb);
1501 ret += tcrypt_test("md5");
1505 ret += tcrypt_test("sha1");
1509 ret += tcrypt_test("ecb(des)");
1510 ret += tcrypt_test("cbc(des)");
1511 ret += tcrypt_test("ctr(des)");
1515 ret += tcrypt_test("ecb(des3_ede)");
1516 ret += tcrypt_test("cbc(des3_ede)");
1517 ret += tcrypt_test("ctr(des3_ede)");
1521 ret += tcrypt_test("md4");
1525 ret += tcrypt_test("sha256");
1529 ret += tcrypt_test("ecb(blowfish)");
1530 ret += tcrypt_test("cbc(blowfish)");
1531 ret += tcrypt_test("ctr(blowfish)");
1535 ret += tcrypt_test("ecb(twofish)");
1536 ret += tcrypt_test("cbc(twofish)");
1537 ret += tcrypt_test("ctr(twofish)");
1538 ret += tcrypt_test("lrw(twofish)");
1539 ret += tcrypt_test("xts(twofish)");
1543 ret += tcrypt_test("ecb(serpent)");
1544 ret += tcrypt_test("cbc(serpent)");
1545 ret += tcrypt_test("ctr(serpent)");
1546 ret += tcrypt_test("lrw(serpent)");
1547 ret += tcrypt_test("xts(serpent)");
1551 ret += tcrypt_test("ecb(aes)");
1552 ret += tcrypt_test("cbc(aes)");
1553 ret += tcrypt_test("lrw(aes)");
1554 ret += tcrypt_test("xts(aes)");
1555 ret += tcrypt_test("ctr(aes)");
1556 ret += tcrypt_test("rfc3686(ctr(aes))");
1557 ret += tcrypt_test("ofb(aes)");
1558 ret += tcrypt_test("cfb(aes)");
1562 ret += tcrypt_test("sha384");
1566 ret += tcrypt_test("sha512");
1570 ret += tcrypt_test("deflate");
1574 ret += tcrypt_test("ecb(cast5)");
1575 ret += tcrypt_test("cbc(cast5)");
1576 ret += tcrypt_test("ctr(cast5)");
1580 ret += tcrypt_test("ecb(cast6)");
1581 ret += tcrypt_test("cbc(cast6)");
1582 ret += tcrypt_test("ctr(cast6)");
1583 ret += tcrypt_test("lrw(cast6)");
1584 ret += tcrypt_test("xts(cast6)");
1588 ret += tcrypt_test("ecb(arc4)");
1592 ret += tcrypt_test("michael_mic");
1596 ret += tcrypt_test("crc32c");
1600 ret += tcrypt_test("ecb(tea)");
1604 ret += tcrypt_test("ecb(xtea)");
1608 ret += tcrypt_test("ecb(khazad)");
1612 ret += tcrypt_test("wp512");
1616 ret += tcrypt_test("wp384");
1620 ret += tcrypt_test("wp256");
1624 ret += tcrypt_test("ecb(anubis)");
1625 ret += tcrypt_test("cbc(anubis)");
1629 ret += tcrypt_test("ecb(xeta)");
1633 ret += tcrypt_test("pcbc(fcrypt)");
1637 ret += tcrypt_test("ecb(camellia)");
1638 ret += tcrypt_test("cbc(camellia)");
1639 ret += tcrypt_test("ctr(camellia)");
1640 ret += tcrypt_test("lrw(camellia)");
1641 ret += tcrypt_test("xts(camellia)");
1645 ret += tcrypt_test("sha224");
1649 ret += tcrypt_test("gcm(aes)");
1653 ret += tcrypt_test("lzo");
1657 ret += tcrypt_test("ccm(aes)");
1661 ret += tcrypt_test("cts(cbc(aes))");
1665 ret += tcrypt_test("xxhash64");
1669 ret += tcrypt_test("rmd160");
1673 ret += tcrypt_test("blake2s-256");
1677 ret += tcrypt_test("blake2b-512");
1681 ret += tcrypt_test("ecb(seed)");
1685 ret += tcrypt_test("rfc4309(ccm(aes))");
1689 ret += tcrypt_test("ghash");
1693 ret += tcrypt_test("crct10dif");
1697 ret += tcrypt_test("sha3-224");
1701 ret += tcrypt_test("sha3-256");
1705 ret += tcrypt_test("sha3-384");
1709 ret += tcrypt_test("sha3-512");
1713 ret += tcrypt_test("sm3");
1717 ret += tcrypt_test("streebog256");
1721 ret += tcrypt_test("streebog512");
1725 ret += tcrypt_test("gcm(sm4)");
1729 ret += tcrypt_test("ccm(sm4)");
1733 ret += tcrypt_test("hmac(md5)");
1737 ret += tcrypt_test("hmac(sha1)");
1741 ret += tcrypt_test("hmac(sha256)");
1745 ret += tcrypt_test("hmac(sha384)");
1749 ret += tcrypt_test("hmac(sha512)");
1753 ret += tcrypt_test("hmac(sha224)");
1757 ret += tcrypt_test("xcbc(aes)");
1761 ret += tcrypt_test("hmac(rmd160)");
1765 ret += tcrypt_test("vmac64(aes)");
1769 ret += tcrypt_test("hmac(sha3-224)");
1773 ret += tcrypt_test("hmac(sha3-256)");
1777 ret += tcrypt_test("hmac(sha3-384)");
1781 ret += tcrypt_test("hmac(sha3-512)");
1785 ret += tcrypt_test("hmac(streebog256)");
1789 ret += tcrypt_test("hmac(streebog512)");
1793 ret += tcrypt_test("ansi_cprng");
1797 ret += tcrypt_test("rfc4106(gcm(aes))");
1801 ret += tcrypt_test("rfc4543(gcm(aes))");
1805 ret += tcrypt_test("cmac(aes)");
1809 ret += tcrypt_test("cmac(des3_ede)");
1813 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1817 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1821 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1825 ret += tcrypt_test("cbcmac(sm4)");
1829 ret += tcrypt_test("cmac(sm4)");
1833 ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
1836 ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
1839 ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
1842 ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
1845 ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
1848 ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
1851 ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
1854 ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
1857 ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
1860 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
1863 ret += tcrypt_test("ecb(sm4)");
1864 ret += tcrypt_test("cbc(sm4)");
1865 ret += tcrypt_test("cfb(sm4)");
1866 ret += tcrypt_test("ctr(sm4)");
1869 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1870 speed_template_16_24_32);
1871 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1872 speed_template_16_24_32);
1873 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1874 speed_template_16_24_32);
1875 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1876 speed_template_16_24_32);
1877 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1878 speed_template_32_40_48);
1879 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1880 speed_template_32_40_48);
1881 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1882 speed_template_32_64);
1883 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1884 speed_template_32_64);
1885 test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
1886 speed_template_16_24_32);
1887 test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
1888 speed_template_16_24_32);
1889 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1890 speed_template_16_24_32);
1891 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1892 speed_template_16_24_32);
1893 test_cipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
1894 speed_template_16_24_32);
1895 test_cipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
1896 speed_template_16_24_32);
1900 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1901 des3_speed_template, DES3_SPEED_VECTORS,
1903 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1904 des3_speed_template, DES3_SPEED_VECTORS,
1906 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1907 des3_speed_template, DES3_SPEED_VECTORS,
1909 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1910 des3_speed_template, DES3_SPEED_VECTORS,
1912 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
1913 des3_speed_template, DES3_SPEED_VECTORS,
1915 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
1916 des3_speed_template, DES3_SPEED_VECTORS,
1921 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1922 speed_template_16_24_32);
1923 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1924 speed_template_16_24_32);
1925 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1926 speed_template_16_24_32);
1927 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1928 speed_template_16_24_32);
1929 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1930 speed_template_16_24_32);
1931 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1932 speed_template_16_24_32);
1933 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1934 speed_template_32_40_48);
1935 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1936 speed_template_32_40_48);
1937 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1938 speed_template_32_48_64);
1939 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1940 speed_template_32_48_64);
1944 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1945 speed_template_8_32);
1946 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1947 speed_template_8_32);
1948 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1949 speed_template_8_32);
1950 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1951 speed_template_8_32);
1952 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
1953 speed_template_8_32);
1954 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
1955 speed_template_8_32);
1959 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1961 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1963 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1965 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1970 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1971 speed_template_16_24_32);
1972 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1973 speed_template_16_24_32);
1974 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1975 speed_template_16_24_32);
1976 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1977 speed_template_16_24_32);
1978 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
1979 speed_template_16_24_32);
1980 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
1981 speed_template_16_24_32);
1982 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
1983 speed_template_32_40_48);
1984 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
1985 speed_template_32_40_48);
1986 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
1987 speed_template_32_48_64);
1988 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
1989 speed_template_32_48_64);
1993 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1994 speed_template_16_32);
1995 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1996 speed_template_16_32);
1997 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1998 speed_template_16_32);
1999 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2000 speed_template_16_32);
2001 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2002 speed_template_16_32);
2003 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2004 speed_template_16_32);
2005 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2006 speed_template_32_48);
2007 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2008 speed_template_32_48);
2009 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2010 speed_template_32_64);
2011 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2012 speed_template_32_64);
2016 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2021 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2022 speed_template_8_16);
2023 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2024 speed_template_8_16);
2025 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2026 speed_template_8_16);
2027 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2028 speed_template_8_16);
2029 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2030 speed_template_8_16);
2031 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2032 speed_template_8_16);
2036 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2037 speed_template_16_32);
2038 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2039 speed_template_16_32);
2040 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2041 speed_template_16_32);
2042 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2043 speed_template_16_32);
2044 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2045 speed_template_16_32);
2046 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2047 speed_template_16_32);
2048 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2049 speed_template_32_48);
2050 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2051 speed_template_32_48);
2052 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2053 speed_template_32_64);
2054 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2055 speed_template_32_64);
2059 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
2060 NULL, 0, 16, 16, aead_speed_template_20);
2061 test_aead_speed("gcm(aes)", ENCRYPT, sec,
2062 NULL, 0, 16, 8, speed_template_16_24_32);
2063 test_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec,
2064 NULL, 0, 16, 16, aead_speed_template_20);
2065 test_aead_speed("gcm(aes)", DECRYPT, sec,
2066 NULL, 0, 16, 8, speed_template_16_24_32);
2070 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
2071 NULL, 0, 16, 16, aead_speed_template_19);
2072 test_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec,
2073 NULL, 0, 16, 16, aead_speed_template_19);
2077 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
2078 NULL, 0, 16, 8, aead_speed_template_36);
2079 test_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT, sec,
2080 NULL, 0, 16, 8, aead_speed_template_36);
2084 test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
2089 test_mb_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec, NULL,
2090 0, 16, 16, aead_speed_template_20, num_mb);
2091 test_mb_aead_speed("gcm(aes)", ENCRYPT, sec, NULL, 0, 16, 8,
2092 speed_template_16_24_32, num_mb);
2093 test_mb_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec, NULL,
2094 0, 16, 16, aead_speed_template_20, num_mb);
2095 test_mb_aead_speed("gcm(aes)", DECRYPT, sec, NULL, 0, 16, 8,
2096 speed_template_16_24_32, num_mb);
2100 test_mb_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec, NULL, 0,
2101 16, 16, aead_speed_template_19, num_mb);
2102 test_mb_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec, NULL, 0,
2103 16, 16, aead_speed_template_19, num_mb);
2107 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT,
2108 sec, NULL, 0, 16, 8, aead_speed_template_36,
2110 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT,
2111 sec, NULL, 0, 16, 8, aead_speed_template_36,
2116 test_cipher_speed("ecb(sm4)", ENCRYPT, sec, NULL, 0,
2118 test_cipher_speed("ecb(sm4)", DECRYPT, sec, NULL, 0,
2120 test_cipher_speed("cbc(sm4)", ENCRYPT, sec, NULL, 0,
2122 test_cipher_speed("cbc(sm4)", DECRYPT, sec, NULL, 0,
2124 test_cipher_speed("cfb(sm4)", ENCRYPT, sec, NULL, 0,
2126 test_cipher_speed("cfb(sm4)", DECRYPT, sec, NULL, 0,
2128 test_cipher_speed("ctr(sm4)", ENCRYPT, sec, NULL, 0,
2130 test_cipher_speed("ctr(sm4)", DECRYPT, sec, NULL, 0,
2135 test_cipher_speed("adiantum(xchacha12,aes)", ENCRYPT, sec, NULL,
2136 0, speed_template_32);
2137 test_cipher_speed("adiantum(xchacha12,aes)", DECRYPT, sec, NULL,
2138 0, speed_template_32);
2139 test_cipher_speed("adiantum(xchacha20,aes)", ENCRYPT, sec, NULL,
2140 0, speed_template_32);
2141 test_cipher_speed("adiantum(xchacha20,aes)", DECRYPT, sec, NULL,
2142 0, speed_template_32);
2146 test_acipher_speed("essiv(cbc(aes),sha256)",
2147 ENCRYPT, sec, NULL, 0,
2148 speed_template_16_24_32);
2149 test_acipher_speed("essiv(cbc(aes),sha256)",
2150 DECRYPT, sec, NULL, 0,
2151 speed_template_16_24_32);
2155 test_aead_speed("aegis128", ENCRYPT, sec,
2156 NULL, 0, 16, 8, speed_template_16);
2157 test_aead_speed("aegis128", DECRYPT, sec,
2158 NULL, 0, 16, 8, speed_template_16);
2162 test_aead_speed("gcm(sm4)", ENCRYPT, sec,
2163 NULL, 0, 16, 8, speed_template_16);
2164 test_aead_speed("gcm(sm4)", DECRYPT, sec,
2165 NULL, 0, 16, 8, speed_template_16);
2169 test_aead_speed("rfc4309(ccm(sm4))", ENCRYPT, sec,
2170 NULL, 0, 16, 16, aead_speed_template_19);
2171 test_aead_speed("rfc4309(ccm(sm4))", DECRYPT, sec,
2172 NULL, 0, 16, 16, aead_speed_template_19);
2176 test_mb_aead_speed("gcm(sm4)", ENCRYPT, sec, NULL, 0, 16, 8,
2177 speed_template_16, num_mb);
2178 test_mb_aead_speed("gcm(sm4)", DECRYPT, sec, NULL, 0, 16, 8,
2179 speed_template_16, num_mb);
2183 test_mb_aead_speed("rfc4309(ccm(sm4))", ENCRYPT, sec, NULL, 0,
2184 16, 16, aead_speed_template_19, num_mb);
2185 test_mb_aead_speed("rfc4309(ccm(sm4))", DECRYPT, sec, NULL, 0,
2186 16, 16, aead_speed_template_19, num_mb);
2191 test_hash_speed(alg, sec, generic_hash_speed_template);
2196 test_hash_speed("md4", sec, generic_hash_speed_template);
2197 if (mode > 300 && mode < 400) break;
2200 test_hash_speed("md5", sec, generic_hash_speed_template);
2201 if (mode > 300 && mode < 400) break;
2204 test_hash_speed("sha1", sec, generic_hash_speed_template);
2205 if (mode > 300 && mode < 400) break;
2208 test_hash_speed("sha256", sec, generic_hash_speed_template);
2209 if (mode > 300 && mode < 400) break;
2212 test_hash_speed("sha384", sec, generic_hash_speed_template);
2213 if (mode > 300 && mode < 400) break;
2216 test_hash_speed("sha512", sec, generic_hash_speed_template);
2217 if (mode > 300 && mode < 400) break;
2220 test_hash_speed("wp256", sec, generic_hash_speed_template);
2221 if (mode > 300 && mode < 400) break;
2224 test_hash_speed("wp384", sec, generic_hash_speed_template);
2225 if (mode > 300 && mode < 400) break;
2228 test_hash_speed("wp512", sec, generic_hash_speed_template);
2229 if (mode > 300 && mode < 400) break;
2232 test_hash_speed("sha224", sec, generic_hash_speed_template);
2233 if (mode > 300 && mode < 400) break;
2236 test_hash_speed("xxhash64", sec, generic_hash_speed_template);
2237 if (mode > 300 && mode < 400) break;
2240 test_hash_speed("rmd160", sec, generic_hash_speed_template);
2241 if (mode > 300 && mode < 400) break;
2244 test_hash_speed("blake2s-256", sec, generic_hash_speed_template);
2245 if (mode > 300 && mode < 400) break;
2248 test_hash_speed("blake2b-512", sec, generic_hash_speed_template);
2249 if (mode > 300 && mode < 400) break;
2253 test_hash_speed("ghash", sec, generic_hash_speed_template);
2254 if (mode > 300 && mode < 400) break;
2257 test_hash_speed("crc32c", sec, generic_hash_speed_template);
2258 if (mode > 300 && mode < 400) break;
2261 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
2262 if (mode > 300 && mode < 400) break;
2265 test_hash_speed("poly1305", sec, poly1305_speed_template);
2266 if (mode > 300 && mode < 400) break;
2269 test_hash_speed("sha3-224", sec, generic_hash_speed_template);
2270 if (mode > 300 && mode < 400) break;
2273 test_hash_speed("sha3-256", sec, generic_hash_speed_template);
2274 if (mode > 300 && mode < 400) break;
2277 test_hash_speed("sha3-384", sec, generic_hash_speed_template);
2278 if (mode > 300 && mode < 400) break;
2281 test_hash_speed("sha3-512", sec, generic_hash_speed_template);
2282 if (mode > 300 && mode < 400) break;
2285 test_hash_speed("sm3", sec, generic_hash_speed_template);
2286 if (mode > 300 && mode < 400) break;
2289 test_hash_speed("streebog256", sec,
2290 generic_hash_speed_template);
2291 if (mode > 300 && mode < 400) break;
2294 test_hash_speed("streebog512", sec,
2295 generic_hash_speed_template);
2296 if (mode > 300 && mode < 400) break;
2303 test_ahash_speed(alg, sec, generic_hash_speed_template);
2308 test_ahash_speed("md4", sec, generic_hash_speed_template);
2309 if (mode > 400 && mode < 500) break;
2312 test_ahash_speed("md5", sec, generic_hash_speed_template);
2313 if (mode > 400 && mode < 500) break;
2316 test_ahash_speed("sha1", sec, generic_hash_speed_template);
2317 if (mode > 400 && mode < 500) break;
2320 test_ahash_speed("sha256", sec, generic_hash_speed_template);
2321 if (mode > 400 && mode < 500) break;
2324 test_ahash_speed("sha384", sec, generic_hash_speed_template);
2325 if (mode > 400 && mode < 500) break;
2328 test_ahash_speed("sha512", sec, generic_hash_speed_template);
2329 if (mode > 400 && mode < 500) break;
2332 test_ahash_speed("wp256", sec, generic_hash_speed_template);
2333 if (mode > 400 && mode < 500) break;
2336 test_ahash_speed("wp384", sec, generic_hash_speed_template);
2337 if (mode > 400 && mode < 500) break;
2340 test_ahash_speed("wp512", sec, generic_hash_speed_template);
2341 if (mode > 400 && mode < 500) break;
2344 test_ahash_speed("sha224", sec, generic_hash_speed_template);
2345 if (mode > 400 && mode < 500) break;
2348 test_ahash_speed("xxhash64", sec, generic_hash_speed_template);
2349 if (mode > 400 && mode < 500) break;
2352 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
2353 if (mode > 400 && mode < 500) break;
2356 test_ahash_speed("blake2s-256", sec, generic_hash_speed_template);
2357 if (mode > 400 && mode < 500) break;
2360 test_ahash_speed("blake2b-512", sec, generic_hash_speed_template);
2361 if (mode > 400 && mode < 500) break;
2364 test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
2365 if (mode > 400 && mode < 500) break;
2368 test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
2369 if (mode > 400 && mode < 500) break;
2372 test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
2373 if (mode > 400 && mode < 500) break;
2376 test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
2377 if (mode > 400 && mode < 500) break;
2380 test_ahash_speed("sm3", sec, generic_hash_speed_template);
2381 if (mode > 400 && mode < 500) break;
2387 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2388 speed_template_16_24_32);
2389 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2390 speed_template_16_24_32);
2391 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2392 speed_template_16_24_32);
2393 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2394 speed_template_16_24_32);
2395 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2396 speed_template_32_40_48);
2397 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2398 speed_template_32_40_48);
2399 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2400 speed_template_32_64);
2401 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2402 speed_template_32_64);
2403 test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2404 speed_template_16_24_32);
2405 test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2406 speed_template_16_24_32);
2407 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2408 speed_template_16_24_32);
2409 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2410 speed_template_16_24_32);
2411 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2412 speed_template_16_24_32);
2413 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2414 speed_template_16_24_32);
2415 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2416 speed_template_16_24_32);
2417 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2418 speed_template_16_24_32);
2419 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
2420 speed_template_20_28_36);
2421 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
2422 speed_template_20_28_36);
2426 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2427 des3_speed_template, DES3_SPEED_VECTORS,
2429 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
2430 des3_speed_template, DES3_SPEED_VECTORS,
2432 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2433 des3_speed_template, DES3_SPEED_VECTORS,
2435 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
2436 des3_speed_template, DES3_SPEED_VECTORS,
2438 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2439 des3_speed_template, DES3_SPEED_VECTORS,
2441 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
2442 des3_speed_template, DES3_SPEED_VECTORS,
2444 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2445 des3_speed_template, DES3_SPEED_VECTORS,
2447 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
2448 des3_speed_template, DES3_SPEED_VECTORS,
2453 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2455 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2457 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2459 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2461 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2463 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2465 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2467 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2472 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2473 speed_template_16_32);
2474 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2475 speed_template_16_32);
2476 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2477 speed_template_16_32);
2478 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2479 speed_template_16_32);
2480 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2481 speed_template_16_32);
2482 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2483 speed_template_16_32);
2484 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2485 speed_template_32_48);
2486 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2487 speed_template_32_48);
2488 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2489 speed_template_32_64);
2490 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2491 speed_template_32_64);
2495 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2496 speed_template_16_24_32);
2497 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2498 speed_template_16_24_32);
2499 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2500 speed_template_16_24_32);
2501 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2502 speed_template_16_24_32);
2503 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2504 speed_template_16_24_32);
2505 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2506 speed_template_16_24_32);
2507 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2508 speed_template_32_40_48);
2509 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2510 speed_template_32_40_48);
2511 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2512 speed_template_32_48_64);
2513 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2514 speed_template_32_48_64);
2518 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2523 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2524 speed_template_8_16);
2525 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2526 speed_template_8_16);
2527 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2528 speed_template_8_16);
2529 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2530 speed_template_8_16);
2531 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2532 speed_template_8_16);
2533 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2534 speed_template_8_16);
2538 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2539 speed_template_16_32);
2540 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2541 speed_template_16_32);
2542 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2543 speed_template_16_32);
2544 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2545 speed_template_16_32);
2546 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2547 speed_template_16_32);
2548 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2549 speed_template_16_32);
2550 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2551 speed_template_32_48);
2552 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2553 speed_template_32_48);
2554 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2555 speed_template_32_64);
2556 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2557 speed_template_32_64);
2561 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2562 speed_template_16_32);
2563 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2564 speed_template_16_32);
2565 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2566 speed_template_16_32);
2567 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2568 speed_template_16_32);
2569 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2570 speed_template_16_32);
2571 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2572 speed_template_16_32);
2573 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2574 speed_template_32_48);
2575 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2576 speed_template_32_48);
2577 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2578 speed_template_32_64);
2579 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2580 speed_template_32_64);
2584 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2585 speed_template_8_32);
2586 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2587 speed_template_8_32);
2588 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2589 speed_template_8_32);
2590 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2591 speed_template_8_32);
2592 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2593 speed_template_8_32);
2594 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2595 speed_template_8_32);
2599 test_acipher_speed("ecb(sm4)", ENCRYPT, sec, NULL, 0,
2601 test_acipher_speed("ecb(sm4)", DECRYPT, sec, NULL, 0,
2603 test_acipher_speed("cbc(sm4)", ENCRYPT, sec, NULL, 0,
2605 test_acipher_speed("cbc(sm4)", DECRYPT, sec, NULL, 0,
2607 test_acipher_speed("cfb(sm4)", ENCRYPT, sec, NULL, 0,
2609 test_acipher_speed("cfb(sm4)", DECRYPT, sec, NULL, 0,
2611 test_acipher_speed("ctr(sm4)", ENCRYPT, sec, NULL, 0,
2613 test_acipher_speed("ctr(sm4)", DECRYPT, sec, NULL, 0,
2618 test_mb_skcipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2619 speed_template_16_24_32, num_mb);
2620 test_mb_skcipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2621 speed_template_16_24_32, num_mb);
2622 test_mb_skcipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2623 speed_template_16_24_32, num_mb);
2624 test_mb_skcipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2625 speed_template_16_24_32, num_mb);
2626 test_mb_skcipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2627 speed_template_32_40_48, num_mb);
2628 test_mb_skcipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2629 speed_template_32_40_48, num_mb);
2630 test_mb_skcipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2631 speed_template_32_64, num_mb);
2632 test_mb_skcipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2633 speed_template_32_64, num_mb);
2634 test_mb_skcipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2635 speed_template_16_24_32, num_mb);
2636 test_mb_skcipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2637 speed_template_16_24_32, num_mb);
2638 test_mb_skcipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2639 speed_template_16_24_32, num_mb);
2640 test_mb_skcipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2641 speed_template_16_24_32, num_mb);
2642 test_mb_skcipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2643 speed_template_16_24_32, num_mb);
2644 test_mb_skcipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2645 speed_template_16_24_32, num_mb);
2646 test_mb_skcipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2647 speed_template_16_24_32, num_mb);
2648 test_mb_skcipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2649 speed_template_16_24_32, num_mb);
2650 test_mb_skcipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL,
2651 0, speed_template_20_28_36, num_mb);
2652 test_mb_skcipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL,
2653 0, speed_template_20_28_36, num_mb);
2657 test_mb_skcipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2658 des3_speed_template, DES3_SPEED_VECTORS,
2659 speed_template_24, num_mb);
2660 test_mb_skcipher_speed("ecb(des3_ede)", DECRYPT, sec,
2661 des3_speed_template, DES3_SPEED_VECTORS,
2662 speed_template_24, num_mb);
2663 test_mb_skcipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2664 des3_speed_template, DES3_SPEED_VECTORS,
2665 speed_template_24, num_mb);
2666 test_mb_skcipher_speed("cbc(des3_ede)", DECRYPT, sec,
2667 des3_speed_template, DES3_SPEED_VECTORS,
2668 speed_template_24, num_mb);
2669 test_mb_skcipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2670 des3_speed_template, DES3_SPEED_VECTORS,
2671 speed_template_24, num_mb);
2672 test_mb_skcipher_speed("cfb(des3_ede)", DECRYPT, sec,
2673 des3_speed_template, DES3_SPEED_VECTORS,
2674 speed_template_24, num_mb);
2675 test_mb_skcipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2676 des3_speed_template, DES3_SPEED_VECTORS,
2677 speed_template_24, num_mb);
2678 test_mb_skcipher_speed("ofb(des3_ede)", DECRYPT, sec,
2679 des3_speed_template, DES3_SPEED_VECTORS,
2680 speed_template_24, num_mb);
2684 test_mb_skcipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2685 speed_template_8, num_mb);
2686 test_mb_skcipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2687 speed_template_8, num_mb);
2688 test_mb_skcipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2689 speed_template_8, num_mb);
2690 test_mb_skcipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2691 speed_template_8, num_mb);
2692 test_mb_skcipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2693 speed_template_8, num_mb);
2694 test_mb_skcipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2695 speed_template_8, num_mb);
2696 test_mb_skcipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2697 speed_template_8, num_mb);
2698 test_mb_skcipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2699 speed_template_8, num_mb);
2703 test_mb_skcipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2704 speed_template_16_32, num_mb);
2705 test_mb_skcipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2706 speed_template_16_32, num_mb);
2707 test_mb_skcipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2708 speed_template_16_32, num_mb);
2709 test_mb_skcipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2710 speed_template_16_32, num_mb);
2711 test_mb_skcipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2712 speed_template_16_32, num_mb);
2713 test_mb_skcipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2714 speed_template_16_32, num_mb);
2715 test_mb_skcipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2716 speed_template_32_48, num_mb);
2717 test_mb_skcipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2718 speed_template_32_48, num_mb);
2719 test_mb_skcipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2720 speed_template_32_64, num_mb);
2721 test_mb_skcipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2722 speed_template_32_64, num_mb);
2726 test_mb_skcipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2727 speed_template_16_24_32, num_mb);
2728 test_mb_skcipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2729 speed_template_16_24_32, num_mb);
2730 test_mb_skcipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2731 speed_template_16_24_32, num_mb);
2732 test_mb_skcipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2733 speed_template_16_24_32, num_mb);
2734 test_mb_skcipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2735 speed_template_16_24_32, num_mb);
2736 test_mb_skcipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2737 speed_template_16_24_32, num_mb);
2738 test_mb_skcipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2739 speed_template_32_40_48, num_mb);
2740 test_mb_skcipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2741 speed_template_32_40_48, num_mb);
2742 test_mb_skcipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2743 speed_template_32_48_64, num_mb);
2744 test_mb_skcipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2745 speed_template_32_48_64, num_mb);
2749 test_mb_skcipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2750 speed_template_8, num_mb);
2754 test_mb_skcipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2755 speed_template_8_16, num_mb);
2756 test_mb_skcipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2757 speed_template_8_16, num_mb);
2758 test_mb_skcipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2759 speed_template_8_16, num_mb);
2760 test_mb_skcipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2761 speed_template_8_16, num_mb);
2762 test_mb_skcipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2763 speed_template_8_16, num_mb);
2764 test_mb_skcipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2765 speed_template_8_16, num_mb);
2769 test_mb_skcipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2770 speed_template_16_32, num_mb);
2771 test_mb_skcipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2772 speed_template_16_32, num_mb);
2773 test_mb_skcipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2774 speed_template_16_32, num_mb);
2775 test_mb_skcipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2776 speed_template_16_32, num_mb);
2777 test_mb_skcipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2778 speed_template_16_32, num_mb);
2779 test_mb_skcipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2780 speed_template_16_32, num_mb);
2781 test_mb_skcipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2782 speed_template_32_48, num_mb);
2783 test_mb_skcipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2784 speed_template_32_48, num_mb);
2785 test_mb_skcipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2786 speed_template_32_64, num_mb);
2787 test_mb_skcipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2788 speed_template_32_64, num_mb);
2792 test_mb_skcipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2793 speed_template_16_32, num_mb);
2794 test_mb_skcipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2795 speed_template_16_32, num_mb);
2796 test_mb_skcipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2797 speed_template_16_32, num_mb);
2798 test_mb_skcipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2799 speed_template_16_32, num_mb);
2800 test_mb_skcipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2801 speed_template_16_32, num_mb);
2802 test_mb_skcipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2803 speed_template_16_32, num_mb);
2804 test_mb_skcipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2805 speed_template_32_48, num_mb);
2806 test_mb_skcipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2807 speed_template_32_48, num_mb);
2808 test_mb_skcipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2809 speed_template_32_64, num_mb);
2810 test_mb_skcipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2811 speed_template_32_64, num_mb);
2815 test_mb_skcipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2816 speed_template_8_32, num_mb);
2817 test_mb_skcipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2818 speed_template_8_32, num_mb);
2819 test_mb_skcipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2820 speed_template_8_32, num_mb);
2821 test_mb_skcipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2822 speed_template_8_32, num_mb);
2823 test_mb_skcipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2824 speed_template_8_32, num_mb);
2825 test_mb_skcipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2826 speed_template_8_32, num_mb);
2837 static int __init tcrypt_mod_init(void)
2842 for (i = 0; i < TVMEMSIZE; i++) {
2843 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
2848 err = do_test(alg, type, mask, mode, num_mb);
2851 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
2854 pr_debug("all tests passed\n");
2857 /* We intentionaly return -EAGAIN to prevent keeping the module,
2858 * unless we're running in fips mode. It does all its work from
2859 * init() and doesn't offer any runtime functionality, but in
2860 * the fips case, checking for a successful load is helpful.
2861 * => we don't need it in the memory, do we?
2868 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
2869 free_page((unsigned long)tvmem[i]);
2875 * If an init function is provided, an exit function must also be provided
2876 * to allow module unload.
2878 static void __exit tcrypt_mod_fini(void) { }
2880 late_initcall(tcrypt_mod_init);
2881 module_exit(tcrypt_mod_fini);
2883 module_param(alg, charp, 0);
2884 module_param(type, uint, 0);
2885 module_param(mask, uint, 0);
2886 module_param(mode, int, 0);
2887 module_param(sec, uint, 0);
2888 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
2889 "(defaults to zero which uses CPU cycles instead)");
2890 module_param(num_mb, uint, 0000);
2891 MODULE_PARM_DESC(num_mb, "Number of concurrent requests to be used in mb speed tests (defaults to 8)");
2892 module_param(klen, uint, 0);
2893 MODULE_PARM_DESC(klen, "Key length (defaults to 0)");
2895 MODULE_LICENSE("GPL");
2896 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2897 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");