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;
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", "aria",
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)");
1559 ret += tcrypt_test("xctr(aes)");
1563 ret += tcrypt_test("sha384");
1567 ret += tcrypt_test("sha512");
1571 ret += tcrypt_test("deflate");
1575 ret += tcrypt_test("ecb(cast5)");
1576 ret += tcrypt_test("cbc(cast5)");
1577 ret += tcrypt_test("ctr(cast5)");
1581 ret += tcrypt_test("ecb(cast6)");
1582 ret += tcrypt_test("cbc(cast6)");
1583 ret += tcrypt_test("ctr(cast6)");
1584 ret += tcrypt_test("lrw(cast6)");
1585 ret += tcrypt_test("xts(cast6)");
1589 ret += tcrypt_test("ecb(arc4)");
1593 ret += tcrypt_test("michael_mic");
1597 ret += tcrypt_test("crc32c");
1601 ret += tcrypt_test("ecb(tea)");
1605 ret += tcrypt_test("ecb(xtea)");
1609 ret += tcrypt_test("ecb(khazad)");
1613 ret += tcrypt_test("wp512");
1617 ret += tcrypt_test("wp384");
1621 ret += tcrypt_test("wp256");
1625 ret += tcrypt_test("ecb(anubis)");
1626 ret += tcrypt_test("cbc(anubis)");
1630 ret += tcrypt_test("ecb(xeta)");
1634 ret += tcrypt_test("pcbc(fcrypt)");
1638 ret += tcrypt_test("ecb(camellia)");
1639 ret += tcrypt_test("cbc(camellia)");
1640 ret += tcrypt_test("ctr(camellia)");
1641 ret += tcrypt_test("lrw(camellia)");
1642 ret += tcrypt_test("xts(camellia)");
1646 ret += tcrypt_test("sha224");
1650 ret += tcrypt_test("gcm(aes)");
1654 ret += tcrypt_test("lzo");
1658 ret += tcrypt_test("ccm(aes)");
1662 ret += tcrypt_test("cts(cbc(aes))");
1666 ret += tcrypt_test("xxhash64");
1670 ret += tcrypt_test("rmd160");
1674 ret += tcrypt_test("blake2b-512");
1678 ret += tcrypt_test("ecb(seed)");
1682 ret += tcrypt_test("rfc4309(ccm(aes))");
1686 ret += tcrypt_test("ghash");
1690 ret += tcrypt_test("crct10dif");
1694 ret += tcrypt_test("sha3-224");
1698 ret += tcrypt_test("sha3-256");
1702 ret += tcrypt_test("sha3-384");
1706 ret += tcrypt_test("sha3-512");
1710 ret += tcrypt_test("sm3");
1714 ret += tcrypt_test("streebog256");
1718 ret += tcrypt_test("streebog512");
1722 ret += tcrypt_test("gcm(sm4)");
1726 ret += tcrypt_test("ccm(sm4)");
1730 ret += tcrypt_test("polyval");
1734 ret += tcrypt_test("gcm(aria)");
1738 ret += tcrypt_test("hmac(md5)");
1742 ret += tcrypt_test("hmac(sha1)");
1746 ret += tcrypt_test("hmac(sha256)");
1750 ret += tcrypt_test("hmac(sha384)");
1754 ret += tcrypt_test("hmac(sha512)");
1758 ret += tcrypt_test("hmac(sha224)");
1762 ret += tcrypt_test("xcbc(aes)");
1766 ret += tcrypt_test("hmac(rmd160)");
1770 ret += tcrypt_test("vmac64(aes)");
1774 ret += tcrypt_test("hmac(sha3-224)");
1778 ret += tcrypt_test("hmac(sha3-256)");
1782 ret += tcrypt_test("hmac(sha3-384)");
1786 ret += tcrypt_test("hmac(sha3-512)");
1790 ret += tcrypt_test("hmac(streebog256)");
1794 ret += tcrypt_test("hmac(streebog512)");
1798 ret += tcrypt_test("ansi_cprng");
1802 ret += tcrypt_test("rfc4106(gcm(aes))");
1806 ret += tcrypt_test("rfc4543(gcm(aes))");
1810 ret += tcrypt_test("cmac(aes)");
1814 ret += tcrypt_test("cmac(des3_ede)");
1818 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1822 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1826 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1830 ret += tcrypt_test("cbcmac(sm4)");
1834 ret += tcrypt_test("cmac(sm4)");
1838 ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
1841 ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
1844 ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
1847 ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
1850 ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
1853 ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
1856 ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
1859 ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
1862 ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
1865 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
1868 ret += tcrypt_test("ecb(sm4)");
1869 ret += tcrypt_test("cbc(sm4)");
1870 ret += tcrypt_test("cfb(sm4)");
1871 ret += tcrypt_test("ctr(sm4)");
1874 ret += tcrypt_test("ecb(aria)");
1875 ret += tcrypt_test("cbc(aria)");
1876 ret += tcrypt_test("cfb(aria)");
1877 ret += tcrypt_test("ctr(aria)");
1880 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1881 speed_template_16_24_32);
1882 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1883 speed_template_16_24_32);
1884 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1885 speed_template_16_24_32);
1886 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1887 speed_template_16_24_32);
1888 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1889 speed_template_32_40_48);
1890 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1891 speed_template_32_40_48);
1892 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1893 speed_template_32_64);
1894 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1895 speed_template_32_64);
1896 test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
1897 speed_template_16_24_32);
1898 test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
1899 speed_template_16_24_32);
1900 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1901 speed_template_16_24_32);
1902 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1903 speed_template_16_24_32);
1904 test_cipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
1905 speed_template_16_24_32);
1906 test_cipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
1907 speed_template_16_24_32);
1911 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1912 des3_speed_template, DES3_SPEED_VECTORS,
1914 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1915 des3_speed_template, DES3_SPEED_VECTORS,
1917 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1918 des3_speed_template, DES3_SPEED_VECTORS,
1920 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1921 des3_speed_template, DES3_SPEED_VECTORS,
1923 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
1924 des3_speed_template, DES3_SPEED_VECTORS,
1926 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
1927 des3_speed_template, DES3_SPEED_VECTORS,
1932 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1933 speed_template_16_24_32);
1934 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1935 speed_template_16_24_32);
1936 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1937 speed_template_16_24_32);
1938 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1939 speed_template_16_24_32);
1940 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1941 speed_template_16_24_32);
1942 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1943 speed_template_16_24_32);
1944 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1945 speed_template_32_40_48);
1946 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1947 speed_template_32_40_48);
1948 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1949 speed_template_32_48_64);
1950 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1951 speed_template_32_48_64);
1955 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1956 speed_template_8_32);
1957 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1958 speed_template_8_32);
1959 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1960 speed_template_8_32);
1961 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1962 speed_template_8_32);
1963 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
1964 speed_template_8_32);
1965 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
1966 speed_template_8_32);
1970 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1972 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1974 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1976 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1981 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1982 speed_template_16_24_32);
1983 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1984 speed_template_16_24_32);
1985 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1986 speed_template_16_24_32);
1987 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1988 speed_template_16_24_32);
1989 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
1990 speed_template_16_24_32);
1991 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
1992 speed_template_16_24_32);
1993 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
1994 speed_template_32_40_48);
1995 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
1996 speed_template_32_40_48);
1997 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
1998 speed_template_32_48_64);
1999 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2000 speed_template_32_48_64);
2004 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2005 speed_template_16_32);
2006 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2007 speed_template_16_32);
2008 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2009 speed_template_16_32);
2010 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2011 speed_template_16_32);
2012 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2013 speed_template_16_32);
2014 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2015 speed_template_16_32);
2016 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2017 speed_template_32_48);
2018 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2019 speed_template_32_48);
2020 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2021 speed_template_32_64);
2022 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2023 speed_template_32_64);
2027 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2032 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2033 speed_template_8_16);
2034 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2035 speed_template_8_16);
2036 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2037 speed_template_8_16);
2038 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2039 speed_template_8_16);
2040 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2041 speed_template_8_16);
2042 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2043 speed_template_8_16);
2047 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2048 speed_template_16_32);
2049 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2050 speed_template_16_32);
2051 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2052 speed_template_16_32);
2053 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2054 speed_template_16_32);
2055 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2056 speed_template_16_32);
2057 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2058 speed_template_16_32);
2059 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2060 speed_template_32_48);
2061 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2062 speed_template_32_48);
2063 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2064 speed_template_32_64);
2065 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2066 speed_template_32_64);
2070 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
2071 NULL, 0, 16, 16, aead_speed_template_20);
2072 test_aead_speed("gcm(aes)", ENCRYPT, sec,
2073 NULL, 0, 16, 8, speed_template_16_24_32);
2074 test_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec,
2075 NULL, 0, 16, 16, aead_speed_template_20);
2076 test_aead_speed("gcm(aes)", DECRYPT, sec,
2077 NULL, 0, 16, 8, speed_template_16_24_32);
2081 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
2082 NULL, 0, 16, 16, aead_speed_template_19);
2083 test_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec,
2084 NULL, 0, 16, 16, aead_speed_template_19);
2088 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
2089 NULL, 0, 16, 8, aead_speed_template_36);
2090 test_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT, sec,
2091 NULL, 0, 16, 8, aead_speed_template_36);
2095 test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
2100 test_mb_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec, NULL,
2101 0, 16, 16, aead_speed_template_20, num_mb);
2102 test_mb_aead_speed("gcm(aes)", ENCRYPT, sec, NULL, 0, 16, 8,
2103 speed_template_16_24_32, num_mb);
2104 test_mb_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec, NULL,
2105 0, 16, 16, aead_speed_template_20, num_mb);
2106 test_mb_aead_speed("gcm(aes)", DECRYPT, sec, NULL, 0, 16, 8,
2107 speed_template_16_24_32, num_mb);
2111 test_mb_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec, NULL, 0,
2112 16, 16, aead_speed_template_19, num_mb);
2113 test_mb_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec, NULL, 0,
2114 16, 16, aead_speed_template_19, num_mb);
2118 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT,
2119 sec, NULL, 0, 16, 8, aead_speed_template_36,
2121 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT,
2122 sec, NULL, 0, 16, 8, aead_speed_template_36,
2127 test_cipher_speed("ecb(sm4)", ENCRYPT, sec, NULL, 0,
2129 test_cipher_speed("ecb(sm4)", DECRYPT, sec, NULL, 0,
2131 test_cipher_speed("cbc(sm4)", ENCRYPT, sec, NULL, 0,
2133 test_cipher_speed("cbc(sm4)", DECRYPT, sec, NULL, 0,
2135 test_cipher_speed("cfb(sm4)", ENCRYPT, sec, NULL, 0,
2137 test_cipher_speed("cfb(sm4)", DECRYPT, sec, NULL, 0,
2139 test_cipher_speed("ctr(sm4)", ENCRYPT, sec, NULL, 0,
2141 test_cipher_speed("ctr(sm4)", DECRYPT, sec, NULL, 0,
2146 test_cipher_speed("adiantum(xchacha12,aes)", ENCRYPT, sec, NULL,
2147 0, speed_template_32);
2148 test_cipher_speed("adiantum(xchacha12,aes)", DECRYPT, sec, NULL,
2149 0, speed_template_32);
2150 test_cipher_speed("adiantum(xchacha20,aes)", ENCRYPT, sec, NULL,
2151 0, speed_template_32);
2152 test_cipher_speed("adiantum(xchacha20,aes)", DECRYPT, sec, NULL,
2153 0, speed_template_32);
2157 test_acipher_speed("essiv(cbc(aes),sha256)",
2158 ENCRYPT, sec, NULL, 0,
2159 speed_template_16_24_32);
2160 test_acipher_speed("essiv(cbc(aes),sha256)",
2161 DECRYPT, sec, NULL, 0,
2162 speed_template_16_24_32);
2166 test_aead_speed("aegis128", ENCRYPT, sec,
2167 NULL, 0, 16, 8, speed_template_16);
2168 test_aead_speed("aegis128", DECRYPT, sec,
2169 NULL, 0, 16, 8, speed_template_16);
2173 test_aead_speed("gcm(sm4)", ENCRYPT, sec,
2174 NULL, 0, 16, 8, speed_template_16);
2175 test_aead_speed("gcm(sm4)", DECRYPT, sec,
2176 NULL, 0, 16, 8, speed_template_16);
2180 test_aead_speed("rfc4309(ccm(sm4))", ENCRYPT, sec,
2181 NULL, 0, 16, 16, aead_speed_template_19);
2182 test_aead_speed("rfc4309(ccm(sm4))", DECRYPT, sec,
2183 NULL, 0, 16, 16, aead_speed_template_19);
2187 test_mb_aead_speed("gcm(sm4)", ENCRYPT, sec, NULL, 0, 16, 8,
2188 speed_template_16, num_mb);
2189 test_mb_aead_speed("gcm(sm4)", DECRYPT, sec, NULL, 0, 16, 8,
2190 speed_template_16, num_mb);
2194 test_mb_aead_speed("rfc4309(ccm(sm4))", ENCRYPT, sec, NULL, 0,
2195 16, 16, aead_speed_template_19, num_mb);
2196 test_mb_aead_speed("rfc4309(ccm(sm4))", DECRYPT, sec, NULL, 0,
2197 16, 16, aead_speed_template_19, num_mb);
2201 test_cipher_speed("hctr2(aes)", ENCRYPT, sec, NULL,
2202 0, speed_template_32);
2206 test_cipher_speed("ecb(aria)", ENCRYPT, sec, NULL, 0,
2207 speed_template_16_24_32);
2208 test_cipher_speed("ecb(aria)", DECRYPT, sec, NULL, 0,
2209 speed_template_16_24_32);
2210 test_cipher_speed("cbc(aria)", ENCRYPT, sec, NULL, 0,
2211 speed_template_16_24_32);
2212 test_cipher_speed("cbc(aria)", DECRYPT, sec, NULL, 0,
2213 speed_template_16_24_32);
2214 test_cipher_speed("cfb(aria)", ENCRYPT, sec, NULL, 0,
2215 speed_template_16_24_32);
2216 test_cipher_speed("cfb(aria)", DECRYPT, sec, NULL, 0,
2217 speed_template_16_24_32);
2218 test_cipher_speed("ctr(aria)", ENCRYPT, sec, NULL, 0,
2219 speed_template_16_24_32);
2220 test_cipher_speed("ctr(aria)", DECRYPT, sec, NULL, 0,
2221 speed_template_16_24_32);
2225 test_aead_speed("gcm(aria)", ENCRYPT, sec,
2226 NULL, 0, 16, 8, speed_template_16_24_32);
2227 test_aead_speed("gcm(aria)", DECRYPT, sec,
2228 NULL, 0, 16, 8, speed_template_16_24_32);
2233 test_hash_speed(alg, sec, generic_hash_speed_template);
2238 test_hash_speed("md4", sec, generic_hash_speed_template);
2239 if (mode > 300 && mode < 400) break;
2242 test_hash_speed("md5", sec, generic_hash_speed_template);
2243 if (mode > 300 && mode < 400) break;
2246 test_hash_speed("sha1", sec, generic_hash_speed_template);
2247 if (mode > 300 && mode < 400) break;
2250 test_hash_speed("sha256", sec, generic_hash_speed_template);
2251 if (mode > 300 && mode < 400) break;
2254 test_hash_speed("sha384", sec, generic_hash_speed_template);
2255 if (mode > 300 && mode < 400) break;
2258 test_hash_speed("sha512", sec, generic_hash_speed_template);
2259 if (mode > 300 && mode < 400) break;
2262 test_hash_speed("wp256", sec, generic_hash_speed_template);
2263 if (mode > 300 && mode < 400) break;
2266 test_hash_speed("wp384", sec, generic_hash_speed_template);
2267 if (mode > 300 && mode < 400) break;
2270 test_hash_speed("wp512", sec, generic_hash_speed_template);
2271 if (mode > 300 && mode < 400) break;
2274 test_hash_speed("sha224", sec, generic_hash_speed_template);
2275 if (mode > 300 && mode < 400) break;
2278 test_hash_speed("xxhash64", sec, generic_hash_speed_template);
2279 if (mode > 300 && mode < 400) break;
2282 test_hash_speed("rmd160", sec, generic_hash_speed_template);
2283 if (mode > 300 && mode < 400) break;
2286 test_hash_speed("blake2b-512", sec, generic_hash_speed_template);
2287 if (mode > 300 && mode < 400) break;
2291 test_hash_speed("ghash", sec, generic_hash_speed_template);
2292 if (mode > 300 && mode < 400) break;
2295 test_hash_speed("crc32c", sec, generic_hash_speed_template);
2296 if (mode > 300 && mode < 400) break;
2299 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
2300 if (mode > 300 && mode < 400) break;
2303 test_hash_speed("poly1305", sec, poly1305_speed_template);
2304 if (mode > 300 && mode < 400) break;
2307 test_hash_speed("sha3-224", sec, generic_hash_speed_template);
2308 if (mode > 300 && mode < 400) break;
2311 test_hash_speed("sha3-256", sec, generic_hash_speed_template);
2312 if (mode > 300 && mode < 400) break;
2315 test_hash_speed("sha3-384", sec, generic_hash_speed_template);
2316 if (mode > 300 && mode < 400) break;
2319 test_hash_speed("sha3-512", sec, generic_hash_speed_template);
2320 if (mode > 300 && mode < 400) break;
2323 test_hash_speed("sm3", sec, generic_hash_speed_template);
2324 if (mode > 300 && mode < 400) break;
2327 test_hash_speed("streebog256", sec,
2328 generic_hash_speed_template);
2329 if (mode > 300 && mode < 400) break;
2332 test_hash_speed("streebog512", sec,
2333 generic_hash_speed_template);
2334 if (mode > 300 && mode < 400) break;
2341 test_ahash_speed(alg, sec, generic_hash_speed_template);
2346 test_ahash_speed("md4", sec, generic_hash_speed_template);
2347 if (mode > 400 && mode < 500) break;
2350 test_ahash_speed("md5", sec, generic_hash_speed_template);
2351 if (mode > 400 && mode < 500) break;
2354 test_ahash_speed("sha1", sec, generic_hash_speed_template);
2355 if (mode > 400 && mode < 500) break;
2358 test_ahash_speed("sha256", sec, generic_hash_speed_template);
2359 if (mode > 400 && mode < 500) break;
2362 test_ahash_speed("sha384", sec, generic_hash_speed_template);
2363 if (mode > 400 && mode < 500) break;
2366 test_ahash_speed("sha512", sec, generic_hash_speed_template);
2367 if (mode > 400 && mode < 500) break;
2370 test_ahash_speed("wp256", sec, generic_hash_speed_template);
2371 if (mode > 400 && mode < 500) break;
2374 test_ahash_speed("wp384", sec, generic_hash_speed_template);
2375 if (mode > 400 && mode < 500) break;
2378 test_ahash_speed("wp512", sec, generic_hash_speed_template);
2379 if (mode > 400 && mode < 500) break;
2382 test_ahash_speed("sha224", sec, generic_hash_speed_template);
2383 if (mode > 400 && mode < 500) break;
2386 test_ahash_speed("xxhash64", sec, generic_hash_speed_template);
2387 if (mode > 400 && mode < 500) break;
2390 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
2391 if (mode > 400 && mode < 500) break;
2394 test_ahash_speed("blake2b-512", sec, generic_hash_speed_template);
2395 if (mode > 400 && mode < 500) break;
2398 test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
2399 if (mode > 400 && mode < 500) break;
2402 test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
2403 if (mode > 400 && mode < 500) break;
2406 test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
2407 if (mode > 400 && mode < 500) break;
2410 test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
2411 if (mode > 400 && mode < 500) break;
2414 test_ahash_speed("sm3", sec, generic_hash_speed_template);
2415 if (mode > 400 && mode < 500) break;
2421 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2422 speed_template_16_24_32);
2423 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2424 speed_template_16_24_32);
2425 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2426 speed_template_16_24_32);
2427 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2428 speed_template_16_24_32);
2429 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2430 speed_template_32_40_48);
2431 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2432 speed_template_32_40_48);
2433 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2434 speed_template_32_64);
2435 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2436 speed_template_32_64);
2437 test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2438 speed_template_16_24_32);
2439 test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2440 speed_template_16_24_32);
2441 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2442 speed_template_16_24_32);
2443 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2444 speed_template_16_24_32);
2445 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2446 speed_template_16_24_32);
2447 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2448 speed_template_16_24_32);
2449 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2450 speed_template_16_24_32);
2451 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2452 speed_template_16_24_32);
2453 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
2454 speed_template_20_28_36);
2455 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
2456 speed_template_20_28_36);
2460 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2461 des3_speed_template, DES3_SPEED_VECTORS,
2463 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
2464 des3_speed_template, DES3_SPEED_VECTORS,
2466 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2467 des3_speed_template, DES3_SPEED_VECTORS,
2469 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
2470 des3_speed_template, DES3_SPEED_VECTORS,
2472 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2473 des3_speed_template, DES3_SPEED_VECTORS,
2475 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
2476 des3_speed_template, DES3_SPEED_VECTORS,
2478 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2479 des3_speed_template, DES3_SPEED_VECTORS,
2481 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
2482 des3_speed_template, DES3_SPEED_VECTORS,
2487 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2489 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2491 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2493 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2495 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2497 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2499 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2501 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2506 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2507 speed_template_16_32);
2508 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2509 speed_template_16_32);
2510 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2511 speed_template_16_32);
2512 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2513 speed_template_16_32);
2514 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2515 speed_template_16_32);
2516 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2517 speed_template_16_32);
2518 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2519 speed_template_32_48);
2520 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2521 speed_template_32_48);
2522 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2523 speed_template_32_64);
2524 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2525 speed_template_32_64);
2529 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2530 speed_template_16_24_32);
2531 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2532 speed_template_16_24_32);
2533 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2534 speed_template_16_24_32);
2535 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2536 speed_template_16_24_32);
2537 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2538 speed_template_16_24_32);
2539 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2540 speed_template_16_24_32);
2541 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2542 speed_template_32_40_48);
2543 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2544 speed_template_32_40_48);
2545 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2546 speed_template_32_48_64);
2547 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2548 speed_template_32_48_64);
2552 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2557 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2558 speed_template_8_16);
2559 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2560 speed_template_8_16);
2561 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2562 speed_template_8_16);
2563 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2564 speed_template_8_16);
2565 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2566 speed_template_8_16);
2567 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2568 speed_template_8_16);
2572 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2573 speed_template_16_32);
2574 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2575 speed_template_16_32);
2576 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2577 speed_template_16_32);
2578 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2579 speed_template_16_32);
2580 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2581 speed_template_16_32);
2582 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2583 speed_template_16_32);
2584 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2585 speed_template_32_48);
2586 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2587 speed_template_32_48);
2588 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2589 speed_template_32_64);
2590 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2591 speed_template_32_64);
2595 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2596 speed_template_16_32);
2597 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2598 speed_template_16_32);
2599 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2600 speed_template_16_32);
2601 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2602 speed_template_16_32);
2603 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2604 speed_template_16_32);
2605 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2606 speed_template_16_32);
2607 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2608 speed_template_32_48);
2609 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2610 speed_template_32_48);
2611 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2612 speed_template_32_64);
2613 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2614 speed_template_32_64);
2618 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2619 speed_template_8_32);
2620 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2621 speed_template_8_32);
2622 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2623 speed_template_8_32);
2624 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2625 speed_template_8_32);
2626 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2627 speed_template_8_32);
2628 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2629 speed_template_8_32);
2633 test_acipher_speed("ecb(sm4)", ENCRYPT, sec, NULL, 0,
2635 test_acipher_speed("ecb(sm4)", DECRYPT, sec, NULL, 0,
2637 test_acipher_speed("cbc(sm4)", ENCRYPT, sec, NULL, 0,
2639 test_acipher_speed("cbc(sm4)", DECRYPT, sec, NULL, 0,
2641 test_acipher_speed("cfb(sm4)", ENCRYPT, sec, NULL, 0,
2643 test_acipher_speed("cfb(sm4)", DECRYPT, sec, NULL, 0,
2645 test_acipher_speed("ctr(sm4)", ENCRYPT, sec, NULL, 0,
2647 test_acipher_speed("ctr(sm4)", DECRYPT, sec, NULL, 0,
2652 test_mb_skcipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2653 speed_template_16_24_32, num_mb);
2654 test_mb_skcipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2655 speed_template_16_24_32, num_mb);
2656 test_mb_skcipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2657 speed_template_16_24_32, num_mb);
2658 test_mb_skcipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2659 speed_template_16_24_32, num_mb);
2660 test_mb_skcipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2661 speed_template_32_40_48, num_mb);
2662 test_mb_skcipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2663 speed_template_32_40_48, num_mb);
2664 test_mb_skcipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2665 speed_template_32_64, num_mb);
2666 test_mb_skcipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2667 speed_template_32_64, num_mb);
2668 test_mb_skcipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2669 speed_template_16_24_32, num_mb);
2670 test_mb_skcipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2671 speed_template_16_24_32, num_mb);
2672 test_mb_skcipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2673 speed_template_16_24_32, num_mb);
2674 test_mb_skcipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2675 speed_template_16_24_32, num_mb);
2676 test_mb_skcipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2677 speed_template_16_24_32, num_mb);
2678 test_mb_skcipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2679 speed_template_16_24_32, num_mb);
2680 test_mb_skcipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2681 speed_template_16_24_32, num_mb);
2682 test_mb_skcipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2683 speed_template_16_24_32, num_mb);
2684 test_mb_skcipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL,
2685 0, speed_template_20_28_36, num_mb);
2686 test_mb_skcipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL,
2687 0, speed_template_20_28_36, num_mb);
2691 test_mb_skcipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2692 des3_speed_template, DES3_SPEED_VECTORS,
2693 speed_template_24, num_mb);
2694 test_mb_skcipher_speed("ecb(des3_ede)", DECRYPT, sec,
2695 des3_speed_template, DES3_SPEED_VECTORS,
2696 speed_template_24, num_mb);
2697 test_mb_skcipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2698 des3_speed_template, DES3_SPEED_VECTORS,
2699 speed_template_24, num_mb);
2700 test_mb_skcipher_speed("cbc(des3_ede)", DECRYPT, sec,
2701 des3_speed_template, DES3_SPEED_VECTORS,
2702 speed_template_24, num_mb);
2703 test_mb_skcipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2704 des3_speed_template, DES3_SPEED_VECTORS,
2705 speed_template_24, num_mb);
2706 test_mb_skcipher_speed("cfb(des3_ede)", DECRYPT, sec,
2707 des3_speed_template, DES3_SPEED_VECTORS,
2708 speed_template_24, num_mb);
2709 test_mb_skcipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2710 des3_speed_template, DES3_SPEED_VECTORS,
2711 speed_template_24, num_mb);
2712 test_mb_skcipher_speed("ofb(des3_ede)", DECRYPT, sec,
2713 des3_speed_template, DES3_SPEED_VECTORS,
2714 speed_template_24, num_mb);
2718 test_mb_skcipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2719 speed_template_8, num_mb);
2720 test_mb_skcipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2721 speed_template_8, num_mb);
2722 test_mb_skcipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2723 speed_template_8, num_mb);
2724 test_mb_skcipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2725 speed_template_8, num_mb);
2726 test_mb_skcipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2727 speed_template_8, num_mb);
2728 test_mb_skcipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2729 speed_template_8, num_mb);
2730 test_mb_skcipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2731 speed_template_8, num_mb);
2732 test_mb_skcipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2733 speed_template_8, num_mb);
2737 test_mb_skcipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2738 speed_template_16_32, num_mb);
2739 test_mb_skcipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2740 speed_template_16_32, num_mb);
2741 test_mb_skcipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2742 speed_template_16_32, num_mb);
2743 test_mb_skcipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2744 speed_template_16_32, num_mb);
2745 test_mb_skcipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2746 speed_template_16_32, num_mb);
2747 test_mb_skcipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2748 speed_template_16_32, num_mb);
2749 test_mb_skcipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2750 speed_template_32_48, num_mb);
2751 test_mb_skcipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2752 speed_template_32_48, num_mb);
2753 test_mb_skcipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2754 speed_template_32_64, num_mb);
2755 test_mb_skcipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2756 speed_template_32_64, num_mb);
2760 test_mb_skcipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2761 speed_template_16_24_32, num_mb);
2762 test_mb_skcipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2763 speed_template_16_24_32, num_mb);
2764 test_mb_skcipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2765 speed_template_16_24_32, num_mb);
2766 test_mb_skcipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2767 speed_template_16_24_32, num_mb);
2768 test_mb_skcipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2769 speed_template_16_24_32, num_mb);
2770 test_mb_skcipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2771 speed_template_16_24_32, num_mb);
2772 test_mb_skcipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2773 speed_template_32_40_48, num_mb);
2774 test_mb_skcipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2775 speed_template_32_40_48, num_mb);
2776 test_mb_skcipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2777 speed_template_32_48_64, num_mb);
2778 test_mb_skcipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2779 speed_template_32_48_64, num_mb);
2783 test_mb_skcipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2784 speed_template_8, num_mb);
2788 test_mb_skcipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2789 speed_template_8_16, num_mb);
2790 test_mb_skcipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2791 speed_template_8_16, num_mb);
2792 test_mb_skcipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2793 speed_template_8_16, num_mb);
2794 test_mb_skcipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2795 speed_template_8_16, num_mb);
2796 test_mb_skcipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2797 speed_template_8_16, num_mb);
2798 test_mb_skcipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2799 speed_template_8_16, num_mb);
2803 test_mb_skcipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2804 speed_template_16_32, num_mb);
2805 test_mb_skcipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2806 speed_template_16_32, num_mb);
2807 test_mb_skcipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2808 speed_template_16_32, num_mb);
2809 test_mb_skcipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2810 speed_template_16_32, num_mb);
2811 test_mb_skcipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2812 speed_template_16_32, num_mb);
2813 test_mb_skcipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2814 speed_template_16_32, num_mb);
2815 test_mb_skcipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2816 speed_template_32_48, num_mb);
2817 test_mb_skcipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2818 speed_template_32_48, num_mb);
2819 test_mb_skcipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2820 speed_template_32_64, num_mb);
2821 test_mb_skcipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2822 speed_template_32_64, num_mb);
2826 test_mb_skcipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2827 speed_template_16_32, num_mb);
2828 test_mb_skcipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2829 speed_template_16_32, num_mb);
2830 test_mb_skcipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2831 speed_template_16_32, num_mb);
2832 test_mb_skcipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2833 speed_template_16_32, num_mb);
2834 test_mb_skcipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2835 speed_template_16_32, num_mb);
2836 test_mb_skcipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2837 speed_template_16_32, num_mb);
2838 test_mb_skcipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2839 speed_template_32_48, num_mb);
2840 test_mb_skcipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2841 speed_template_32_48, num_mb);
2842 test_mb_skcipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2843 speed_template_32_64, num_mb);
2844 test_mb_skcipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2845 speed_template_32_64, num_mb);
2849 test_mb_skcipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2850 speed_template_8_32, num_mb);
2851 test_mb_skcipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2852 speed_template_8_32, num_mb);
2853 test_mb_skcipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2854 speed_template_8_32, num_mb);
2855 test_mb_skcipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2856 speed_template_8_32, num_mb);
2857 test_mb_skcipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2858 speed_template_8_32, num_mb);
2859 test_mb_skcipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2860 speed_template_8_32, num_mb);
2871 static int __init tcrypt_mod_init(void)
2876 for (i = 0; i < TVMEMSIZE; i++) {
2877 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
2882 err = do_test(alg, type, mask, mode, num_mb);
2885 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
2888 pr_debug("all tests passed\n");
2891 /* We intentionaly return -EAGAIN to prevent keeping the module,
2892 * unless we're running in fips mode. It does all its work from
2893 * init() and doesn't offer any runtime functionality, but in
2894 * the fips case, checking for a successful load is helpful.
2895 * => we don't need it in the memory, do we?
2902 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
2903 free_page((unsigned long)tvmem[i]);
2909 * If an init function is provided, an exit function must also be provided
2910 * to allow module unload.
2912 static void __exit tcrypt_mod_fini(void) { }
2914 late_initcall(tcrypt_mod_init);
2915 module_exit(tcrypt_mod_fini);
2917 module_param(alg, charp, 0);
2918 module_param(type, uint, 0);
2919 module_param(mask, uint, 0);
2920 module_param(mode, int, 0);
2921 module_param(sec, uint, 0);
2922 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
2923 "(defaults to zero which uses CPU cycles instead)");
2924 module_param(num_mb, uint, 0000);
2925 MODULE_PARM_DESC(num_mb, "Number of concurrent requests to be used in mb speed tests (defaults to 8)");
2926 module_param(klen, uint, 0);
2927 MODULE_PARM_DESC(klen, "Key length (defaults to 0)");
2929 MODULE_LICENSE("GPL");
2930 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2931 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");