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 int block_sizes[] = { 16, 64, 128, 256, 1024, 1420, 4096, 0 };
70 static const int aead_sizes[] = { 16, 64, 256, 512, 1024, 1420, 4096, 8192, 0 };
75 static int testmgr_alloc_buf(char *buf[XBUFSIZE])
79 for (i = 0; i < XBUFSIZE; i++) {
80 buf[i] = (void *)__get_free_page(GFP_KERNEL);
89 free_page((unsigned long)buf[i]);
94 static void testmgr_free_buf(char *buf[XBUFSIZE])
98 for (i = 0; i < XBUFSIZE; i++)
99 free_page((unsigned long)buf[i]);
102 static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],
103 unsigned int buflen, const void *assoc,
104 unsigned int aad_size)
106 int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
113 rem = buflen % PAGE_SIZE;
116 sg_init_table(sg, np + 1);
118 sg_set_buf(&sg[0], assoc, aad_size);
122 for (k = 0; k < np; k++)
123 sg_set_buf(&sg[k + 1], xbuf[k], PAGE_SIZE);
126 sg_set_buf(&sg[k + 1], xbuf[k], rem);
129 static inline int do_one_aead_op(struct aead_request *req, int ret)
131 struct crypto_wait *wait = req->base.data;
133 return crypto_wait_req(ret, wait);
136 struct test_mb_aead_data {
137 struct scatterlist sg[XBUFSIZE];
138 struct scatterlist sgout[XBUFSIZE];
139 struct aead_request *req;
140 struct crypto_wait wait;
141 char *xbuf[XBUFSIZE];
142 char *xoutbuf[XBUFSIZE];
143 char *axbuf[XBUFSIZE];
146 static int do_mult_aead_op(struct test_mb_aead_data *data, int enc,
151 /* Fire up a bunch of concurrent requests */
152 for (i = 0; i < num_mb; i++) {
154 rc[i] = crypto_aead_encrypt(data[i].req);
156 rc[i] = crypto_aead_decrypt(data[i].req);
159 /* Wait for all requests to finish */
160 for (i = 0; i < num_mb; i++) {
161 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
164 pr_info("concurrent request %d error %d\n", i, rc[i]);
172 static int test_mb_aead_jiffies(struct test_mb_aead_data *data, int enc,
173 int blen, int secs, u32 num_mb)
175 unsigned long start, end;
180 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
184 for (start = jiffies, end = start + secs * HZ, bcount = 0;
185 time_before(jiffies, end); bcount++) {
186 ret = do_mult_aead_op(data, enc, num_mb, rc);
191 pr_cont("%d operations in %d seconds (%llu bytes)\n",
192 bcount * num_mb, secs, (u64)bcount * blen * num_mb);
199 static int test_mb_aead_cycles(struct test_mb_aead_data *data, int enc,
200 int blen, u32 num_mb)
202 unsigned long cycles = 0;
207 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
212 for (i = 0; i < 4; i++) {
213 ret = do_mult_aead_op(data, enc, num_mb, rc);
218 /* The real thing. */
219 for (i = 0; i < 8; i++) {
222 start = get_cycles();
223 ret = do_mult_aead_op(data, enc, num_mb, rc);
229 cycles += end - start;
232 pr_cont("1 operation in %lu cycles (%d bytes)\n",
233 (cycles + 4) / (8 * num_mb), blen);
240 static void test_mb_aead_speed(const char *algo, int enc, int secs,
241 struct aead_speed_template *template,
242 unsigned int tcount, u8 authsize,
243 unsigned int aad_size, u8 *keysize, u32 num_mb)
245 struct test_mb_aead_data *data;
246 struct crypto_aead *tfm;
247 unsigned int i, j, iv_len;
256 if (aad_size >= PAGE_SIZE) {
257 pr_err("associate data length (%u) too big\n", aad_size);
261 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
270 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
274 tfm = crypto_alloc_aead(algo, 0, 0);
276 pr_err("failed to load transform for %s: %ld\n",
281 ret = crypto_aead_setauthsize(tfm, authsize);
283 pr_err("alg: aead: Failed to setauthsize for %s: %d\n", algo,
288 for (i = 0; i < num_mb; ++i)
289 if (testmgr_alloc_buf(data[i].xbuf)) {
291 testmgr_free_buf(data[i].xbuf);
295 for (i = 0; i < num_mb; ++i)
296 if (testmgr_alloc_buf(data[i].axbuf)) {
298 testmgr_free_buf(data[i].axbuf);
302 for (i = 0; i < num_mb; ++i)
303 if (testmgr_alloc_buf(data[i].xoutbuf)) {
305 testmgr_free_buf(data[i].xoutbuf);
309 for (i = 0; i < num_mb; ++i) {
310 data[i].req = aead_request_alloc(tfm, GFP_KERNEL);
312 pr_err("alg: aead: Failed to allocate request for %s\n",
315 aead_request_free(data[i].req);
316 goto out_free_xoutbuf;
320 for (i = 0; i < num_mb; ++i) {
321 crypto_init_wait(&data[i].wait);
322 aead_request_set_callback(data[i].req,
323 CRYPTO_TFM_REQ_MAY_BACKLOG,
324 crypto_req_done, &data[i].wait);
327 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo,
328 get_driver_name(crypto_aead, tfm), e);
334 int bs = round_up(*b_size, crypto_aead_blocksize(tfm));
336 if (bs + authsize > XBUFSIZE * PAGE_SIZE) {
337 pr_err("template (%u) too big for buffer (%lu)\n",
339 XBUFSIZE * PAGE_SIZE);
343 pr_info("test %u (%d bit key, %d byte blocks): ", i,
346 /* Set up tfm global state, i.e. the key */
348 memset(tvmem[0], 0xff, PAGE_SIZE);
350 for (j = 0; j < tcount; j++) {
351 if (template[j].klen == *keysize) {
352 key = template[j].key;
357 crypto_aead_clear_flags(tfm, ~0);
359 ret = crypto_aead_setkey(tfm, key, *keysize);
361 pr_err("setkey() failed flags=%x\n",
362 crypto_aead_get_flags(tfm));
366 iv_len = crypto_aead_ivsize(tfm);
368 memset(iv, 0xff, iv_len);
370 /* Now setup per request stuff, i.e. buffers */
372 for (j = 0; j < num_mb; ++j) {
373 struct test_mb_aead_data *cur = &data[j];
375 assoc = cur->axbuf[0];
376 memset(assoc, 0xff, aad_size);
378 sg_init_aead(cur->sg, cur->xbuf,
379 bs + (enc ? 0 : authsize),
382 sg_init_aead(cur->sgout, cur->xoutbuf,
383 bs + (enc ? authsize : 0),
386 aead_request_set_ad(cur->req, aad_size);
390 aead_request_set_crypt(cur->req,
394 ret = crypto_aead_encrypt(cur->req);
395 ret = do_one_aead_op(cur->req, ret);
398 pr_err("calculating auth failed (%d)\n",
404 aead_request_set_crypt(cur->req, cur->sg,
406 (enc ? 0 : authsize),
412 ret = test_mb_aead_jiffies(data, enc, bs,
416 ret = test_mb_aead_cycles(data, enc, bs,
421 pr_err("%s() failed return code=%d\n", e, ret);
431 for (i = 0; i < num_mb; ++i)
432 aead_request_free(data[i].req);
434 for (i = 0; i < num_mb; ++i)
435 testmgr_free_buf(data[i].xoutbuf);
437 for (i = 0; i < num_mb; ++i)
438 testmgr_free_buf(data[i].axbuf);
440 for (i = 0; i < num_mb; ++i)
441 testmgr_free_buf(data[i].xbuf);
443 crypto_free_aead(tfm);
450 static int test_aead_jiffies(struct aead_request *req, int enc,
453 unsigned long start, end;
457 for (start = jiffies, end = start + secs * HZ, bcount = 0;
458 time_before(jiffies, end); bcount++) {
460 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
462 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
468 pr_cont("%d operations in %d seconds (%llu bytes)\n",
469 bcount, secs, (u64)bcount * blen);
473 static int test_aead_cycles(struct aead_request *req, int enc, int blen)
475 unsigned long cycles = 0;
480 for (i = 0; i < 4; i++) {
482 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
484 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
490 /* The real thing. */
491 for (i = 0; i < 8; i++) {
494 start = get_cycles();
496 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
498 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
504 cycles += end - start;
509 printk("1 operation in %lu cycles (%d bytes)\n",
510 (cycles + 4) / 8, blen);
515 static void test_aead_speed(const char *algo, int enc, unsigned int secs,
516 struct aead_speed_template *template,
517 unsigned int tcount, u8 authsize,
518 unsigned int aad_size, u8 *keysize)
521 struct crypto_aead *tfm;
524 struct aead_request *req;
525 struct scatterlist *sg;
526 struct scatterlist *sgout;
530 char *xbuf[XBUFSIZE];
531 char *xoutbuf[XBUFSIZE];
532 char *axbuf[XBUFSIZE];
535 struct crypto_wait wait;
537 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
541 if (aad_size >= PAGE_SIZE) {
542 pr_err("associate data length (%u) too big\n", aad_size);
551 if (testmgr_alloc_buf(xbuf))
553 if (testmgr_alloc_buf(axbuf))
555 if (testmgr_alloc_buf(xoutbuf))
558 sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL);
563 tfm = crypto_alloc_aead(algo, 0, 0);
565 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
570 ret = crypto_aead_setauthsize(tfm, authsize);
572 pr_err("alg: aead: Failed to setauthsize for %s: %d\n", algo,
577 crypto_init_wait(&wait);
578 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
579 get_driver_name(crypto_aead, tfm), e);
581 req = aead_request_alloc(tfm, GFP_KERNEL);
583 pr_err("alg: aead: Failed to allocate request for %s\n",
588 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
589 crypto_req_done, &wait);
595 u32 bs = round_up(*b_size, crypto_aead_blocksize(tfm));
598 memset(assoc, 0xff, aad_size);
600 if ((*keysize + bs) > TVMEMSIZE * PAGE_SIZE) {
601 pr_err("template (%u) too big for tvmem (%lu)\n",
603 TVMEMSIZE * PAGE_SIZE);
608 for (j = 0; j < tcount; j++) {
609 if (template[j].klen == *keysize) {
610 key = template[j].key;
615 ret = crypto_aead_setkey(tfm, key, *keysize);
617 pr_err("setkey() failed flags=%x: %d\n",
618 crypto_aead_get_flags(tfm), ret);
622 iv_len = crypto_aead_ivsize(tfm);
624 memset(iv, 0xff, iv_len);
626 crypto_aead_clear_flags(tfm, ~0);
627 printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
628 i, *keysize * 8, bs);
630 memset(tvmem[0], 0xff, PAGE_SIZE);
632 sg_init_aead(sg, xbuf, bs + (enc ? 0 : authsize),
635 sg_init_aead(sgout, xoutbuf,
636 bs + (enc ? authsize : 0), assoc,
639 aead_request_set_ad(req, aad_size);
644 * For decryption we need a proper auth so
645 * we do the encryption path once with buffers
646 * reversed (input <-> output) to calculate it
648 aead_request_set_crypt(req, sgout, sg,
650 ret = do_one_aead_op(req,
651 crypto_aead_encrypt(req));
654 pr_err("calculating auth failed (%d)\n",
660 aead_request_set_crypt(req, sg, sgout,
661 bs + (enc ? 0 : authsize),
665 ret = test_aead_jiffies(req, enc, bs,
669 ret = test_aead_cycles(req, enc, bs);
673 pr_err("%s() failed return code=%d\n", e, ret);
683 aead_request_free(req);
685 crypto_free_aead(tfm);
689 testmgr_free_buf(xoutbuf);
691 testmgr_free_buf(axbuf);
693 testmgr_free_buf(xbuf);
698 static void test_hash_sg_init(struct scatterlist *sg)
702 sg_init_table(sg, TVMEMSIZE);
703 for (i = 0; i < TVMEMSIZE; i++) {
704 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
705 memset(tvmem[i], 0xff, PAGE_SIZE);
709 static inline int do_one_ahash_op(struct ahash_request *req, int ret)
711 struct crypto_wait *wait = req->base.data;
713 return crypto_wait_req(ret, wait);
716 static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
719 unsigned long start, end;
723 for (start = jiffies, end = start + secs * HZ, bcount = 0;
724 time_before(jiffies, end); bcount++) {
725 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
730 printk("%6u opers/sec, %9lu bytes/sec\n",
731 bcount / secs, ((long)bcount * blen) / secs);
736 static int test_ahash_jiffies(struct ahash_request *req, int blen,
737 int plen, char *out, int secs)
739 unsigned long start, end;
744 return test_ahash_jiffies_digest(req, blen, out, secs);
746 for (start = jiffies, end = start + secs * HZ, bcount = 0;
747 time_before(jiffies, end); bcount++) {
748 ret = do_one_ahash_op(req, crypto_ahash_init(req));
751 for (pcount = 0; pcount < blen; pcount += plen) {
752 ret = do_one_ahash_op(req, crypto_ahash_update(req));
756 /* we assume there is enough space in 'out' for the result */
757 ret = do_one_ahash_op(req, crypto_ahash_final(req));
762 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
763 bcount / secs, ((long)bcount * blen) / secs);
768 static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
771 unsigned long cycles = 0;
775 for (i = 0; i < 4; i++) {
776 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
781 /* The real thing. */
782 for (i = 0; i < 8; i++) {
785 start = get_cycles();
787 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
793 cycles += end - start;
800 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
801 cycles / 8, cycles / (8 * blen));
806 static int test_ahash_cycles(struct ahash_request *req, int blen,
809 unsigned long cycles = 0;
813 return test_ahash_cycles_digest(req, blen, out);
816 for (i = 0; i < 4; i++) {
817 ret = do_one_ahash_op(req, crypto_ahash_init(req));
820 for (pcount = 0; pcount < blen; pcount += plen) {
821 ret = do_one_ahash_op(req, crypto_ahash_update(req));
825 ret = do_one_ahash_op(req, crypto_ahash_final(req));
830 /* The real thing. */
831 for (i = 0; i < 8; i++) {
834 start = get_cycles();
836 ret = do_one_ahash_op(req, crypto_ahash_init(req));
839 for (pcount = 0; pcount < blen; pcount += plen) {
840 ret = do_one_ahash_op(req, crypto_ahash_update(req));
844 ret = do_one_ahash_op(req, crypto_ahash_final(req));
850 cycles += end - start;
857 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
858 cycles / 8, cycles / (8 * blen));
863 static void test_ahash_speed_common(const char *algo, unsigned int secs,
864 struct hash_speed *speed, unsigned mask)
866 struct scatterlist sg[TVMEMSIZE];
867 struct crypto_wait wait;
868 struct ahash_request *req;
869 struct crypto_ahash *tfm;
873 tfm = crypto_alloc_ahash(algo, 0, mask);
875 pr_err("failed to load transform for %s: %ld\n",
880 printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
881 get_driver_name(crypto_ahash, tfm));
883 if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) {
884 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm),
889 test_hash_sg_init(sg);
890 req = ahash_request_alloc(tfm, GFP_KERNEL);
892 pr_err("ahash request allocation failure\n");
896 crypto_init_wait(&wait);
897 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
898 crypto_req_done, &wait);
900 output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
904 for (i = 0; speed[i].blen != 0; i++) {
905 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
906 pr_err("template (%u) too big for tvmem (%lu)\n",
907 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
912 crypto_ahash_setkey(tfm, tvmem[0], klen);
915 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
916 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
918 ahash_request_set_crypt(req, sg, output, speed[i].plen);
921 ret = test_ahash_jiffies(req, speed[i].blen,
922 speed[i].plen, output, secs);
925 ret = test_ahash_cycles(req, speed[i].blen,
926 speed[i].plen, output);
930 pr_err("hashing failed ret=%d\n", ret);
938 ahash_request_free(req);
941 crypto_free_ahash(tfm);
944 static void test_ahash_speed(const char *algo, unsigned int secs,
945 struct hash_speed *speed)
947 return test_ahash_speed_common(algo, secs, speed, 0);
950 static void test_hash_speed(const char *algo, unsigned int secs,
951 struct hash_speed *speed)
953 return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC);
956 struct test_mb_skcipher_data {
957 struct scatterlist sg[XBUFSIZE];
958 struct skcipher_request *req;
959 struct crypto_wait wait;
960 char *xbuf[XBUFSIZE];
963 static int do_mult_acipher_op(struct test_mb_skcipher_data *data, int enc,
968 /* Fire up a bunch of concurrent requests */
969 for (i = 0; i < num_mb; i++) {
971 rc[i] = crypto_skcipher_encrypt(data[i].req);
973 rc[i] = crypto_skcipher_decrypt(data[i].req);
976 /* Wait for all requests to finish */
977 for (i = 0; i < num_mb; i++) {
978 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
981 pr_info("concurrent request %d error %d\n", i, rc[i]);
989 static int test_mb_acipher_jiffies(struct test_mb_skcipher_data *data, int enc,
990 int blen, int secs, u32 num_mb)
992 unsigned long start, end;
997 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
1001 for (start = jiffies, end = start + secs * HZ, bcount = 0;
1002 time_before(jiffies, end); bcount++) {
1003 ret = do_mult_acipher_op(data, enc, num_mb, rc);
1008 pr_cont("%d operations in %d seconds (%llu bytes)\n",
1009 bcount * num_mb, secs, (u64)bcount * blen * num_mb);
1016 static int test_mb_acipher_cycles(struct test_mb_skcipher_data *data, int enc,
1017 int blen, u32 num_mb)
1019 unsigned long cycles = 0;
1024 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
1029 for (i = 0; i < 4; i++) {
1030 ret = do_mult_acipher_op(data, enc, num_mb, rc);
1035 /* The real thing. */
1036 for (i = 0; i < 8; i++) {
1037 cycles_t start, end;
1039 start = get_cycles();
1040 ret = do_mult_acipher_op(data, enc, num_mb, rc);
1046 cycles += end - start;
1049 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1050 (cycles + 4) / (8 * num_mb), blen);
1057 static void test_mb_skcipher_speed(const char *algo, int enc, int secs,
1058 struct cipher_speed_template *template,
1059 unsigned int tcount, u8 *keysize, u32 num_mb)
1061 struct test_mb_skcipher_data *data;
1062 struct crypto_skcipher *tfm;
1063 unsigned int i, j, iv_len;
1075 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
1079 tfm = crypto_alloc_skcipher(algo, 0, 0);
1081 pr_err("failed to load transform for %s: %ld\n",
1082 algo, PTR_ERR(tfm));
1086 for (i = 0; i < num_mb; ++i)
1087 if (testmgr_alloc_buf(data[i].xbuf)) {
1089 testmgr_free_buf(data[i].xbuf);
1094 for (i = 0; i < num_mb; ++i)
1095 if (testmgr_alloc_buf(data[i].xbuf)) {
1097 testmgr_free_buf(data[i].xbuf);
1102 for (i = 0; i < num_mb; ++i) {
1103 data[i].req = skcipher_request_alloc(tfm, GFP_KERNEL);
1105 pr_err("alg: skcipher: Failed to allocate request for %s\n",
1108 skcipher_request_free(data[i].req);
1113 for (i = 0; i < num_mb; ++i) {
1114 skcipher_request_set_callback(data[i].req,
1115 CRYPTO_TFM_REQ_MAY_BACKLOG,
1116 crypto_req_done, &data[i].wait);
1117 crypto_init_wait(&data[i].wait);
1120 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo,
1121 get_driver_name(crypto_skcipher, tfm), e);
1125 b_size = block_sizes;
1127 u32 bs = round_up(*b_size, crypto_skcipher_blocksize(tfm));
1129 if (bs > XBUFSIZE * PAGE_SIZE) {
1130 pr_err("template (%u) too big for buffer (%lu)\n",
1131 bs, XBUFSIZE * PAGE_SIZE);
1135 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1138 /* Set up tfm global state, i.e. the key */
1140 memset(tvmem[0], 0xff, PAGE_SIZE);
1142 for (j = 0; j < tcount; j++) {
1143 if (template[j].klen == *keysize) {
1144 key = template[j].key;
1149 crypto_skcipher_clear_flags(tfm, ~0);
1151 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1153 pr_err("setkey() failed flags=%x\n",
1154 crypto_skcipher_get_flags(tfm));
1158 iv_len = crypto_skcipher_ivsize(tfm);
1160 memset(&iv, 0xff, iv_len);
1162 /* Now setup per request stuff, i.e. buffers */
1164 for (j = 0; j < num_mb; ++j) {
1165 struct test_mb_skcipher_data *cur = &data[j];
1166 unsigned int k = bs;
1167 unsigned int pages = DIV_ROUND_UP(k, PAGE_SIZE);
1170 sg_init_table(cur->sg, pages);
1172 while (k > PAGE_SIZE) {
1173 sg_set_buf(cur->sg + p, cur->xbuf[p],
1175 memset(cur->xbuf[p], 0xff, PAGE_SIZE);
1180 sg_set_buf(cur->sg + p, cur->xbuf[p], k);
1181 memset(cur->xbuf[p], 0xff, k);
1183 skcipher_request_set_crypt(cur->req, cur->sg,
1188 ret = test_mb_acipher_jiffies(data, enc,
1193 ret = test_mb_acipher_cycles(data, enc,
1198 pr_err("%s() failed flags=%x\n", e,
1199 crypto_skcipher_get_flags(tfm));
1209 for (i = 0; i < num_mb; ++i)
1210 skcipher_request_free(data[i].req);
1212 for (i = 0; i < num_mb; ++i)
1213 testmgr_free_buf(data[i].xbuf);
1215 crypto_free_skcipher(tfm);
1220 static inline int do_one_acipher_op(struct skcipher_request *req, int ret)
1222 struct crypto_wait *wait = req->base.data;
1224 return crypto_wait_req(ret, wait);
1227 static int test_acipher_jiffies(struct skcipher_request *req, int enc,
1230 unsigned long start, end;
1234 for (start = jiffies, end = start + secs * HZ, bcount = 0;
1235 time_before(jiffies, end); bcount++) {
1237 ret = do_one_acipher_op(req,
1238 crypto_skcipher_encrypt(req));
1240 ret = do_one_acipher_op(req,
1241 crypto_skcipher_decrypt(req));
1247 pr_cont("%d operations in %d seconds (%llu bytes)\n",
1248 bcount, secs, (u64)bcount * blen);
1252 static int test_acipher_cycles(struct skcipher_request *req, int enc,
1255 unsigned long cycles = 0;
1260 for (i = 0; i < 4; i++) {
1262 ret = do_one_acipher_op(req,
1263 crypto_skcipher_encrypt(req));
1265 ret = do_one_acipher_op(req,
1266 crypto_skcipher_decrypt(req));
1272 /* The real thing. */
1273 for (i = 0; i < 8; i++) {
1274 cycles_t start, end;
1276 start = get_cycles();
1278 ret = do_one_acipher_op(req,
1279 crypto_skcipher_encrypt(req));
1281 ret = do_one_acipher_op(req,
1282 crypto_skcipher_decrypt(req));
1288 cycles += end - start;
1293 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1294 (cycles + 4) / 8, blen);
1299 static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
1300 struct cipher_speed_template *template,
1301 unsigned int tcount, u8 *keysize, bool async)
1303 unsigned int ret, i, j, k, iv_len;
1304 struct crypto_wait wait;
1307 struct skcipher_request *req;
1308 struct crypto_skcipher *tfm;
1317 crypto_init_wait(&wait);
1319 tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC);
1322 pr_err("failed to load transform for %s: %ld\n", algo,
1327 pr_info("\ntesting speed of %s %s (%s) %s\n", async ? "async" : "sync",
1328 algo, get_driver_name(crypto_skcipher, tfm), e);
1330 req = skcipher_request_alloc(tfm, GFP_KERNEL);
1332 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1337 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1338 crypto_req_done, &wait);
1342 b_size = block_sizes;
1345 u32 bs = round_up(*b_size, crypto_skcipher_blocksize(tfm));
1346 struct scatterlist sg[TVMEMSIZE];
1348 if ((*keysize + bs) > TVMEMSIZE * PAGE_SIZE) {
1349 pr_err("template (%u) too big for "
1350 "tvmem (%lu)\n", *keysize + bs,
1351 TVMEMSIZE * PAGE_SIZE);
1355 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1358 memset(tvmem[0], 0xff, PAGE_SIZE);
1360 /* set key, plain text and IV */
1362 for (j = 0; j < tcount; j++) {
1363 if (template[j].klen == *keysize) {
1364 key = template[j].key;
1369 crypto_skcipher_clear_flags(tfm, ~0);
1371 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1373 pr_err("setkey() failed flags=%x\n",
1374 crypto_skcipher_get_flags(tfm));
1379 sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
1381 if (k > PAGE_SIZE) {
1382 sg_set_buf(sg, tvmem[0] + *keysize,
1383 PAGE_SIZE - *keysize);
1386 while (k > PAGE_SIZE) {
1387 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
1388 memset(tvmem[j], 0xff, PAGE_SIZE);
1392 sg_set_buf(sg + j, tvmem[j], k);
1393 memset(tvmem[j], 0xff, k);
1395 sg_set_buf(sg, tvmem[0] + *keysize, bs);
1398 iv_len = crypto_skcipher_ivsize(tfm);
1400 memset(&iv, 0xff, iv_len);
1402 skcipher_request_set_crypt(req, sg, sg, bs, iv);
1405 ret = test_acipher_jiffies(req, enc,
1409 ret = test_acipher_cycles(req, enc,
1414 pr_err("%s() failed flags=%x\n", e,
1415 crypto_skcipher_get_flags(tfm));
1425 skcipher_request_free(req);
1427 crypto_free_skcipher(tfm);
1430 static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
1431 struct cipher_speed_template *template,
1432 unsigned int tcount, u8 *keysize)
1434 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1438 static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
1439 struct cipher_speed_template *template,
1440 unsigned int tcount, u8 *keysize)
1442 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1446 static inline int tcrypt_test(const char *alg)
1450 pr_debug("testing %s\n", alg);
1452 ret = alg_test(alg, alg, 0, 0);
1453 /* non-fips algs return -EINVAL or -ECANCELED in fips mode */
1454 if (fips_enabled && (ret == -EINVAL || ret == -ECANCELED))
1459 static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)
1467 if (!crypto_has_alg(alg, type,
1468 mask ?: CRYPTO_ALG_TYPE_MASK))
1473 for (i = 1; i < 200; i++)
1474 ret += do_test(NULL, 0, 0, i, num_mb);
1478 ret += tcrypt_test("md5");
1482 ret += tcrypt_test("sha1");
1486 ret += tcrypt_test("ecb(des)");
1487 ret += tcrypt_test("cbc(des)");
1488 ret += tcrypt_test("ctr(des)");
1492 ret += tcrypt_test("ecb(des3_ede)");
1493 ret += tcrypt_test("cbc(des3_ede)");
1494 ret += tcrypt_test("ctr(des3_ede)");
1498 ret += tcrypt_test("md4");
1502 ret += tcrypt_test("sha256");
1506 ret += tcrypt_test("ecb(blowfish)");
1507 ret += tcrypt_test("cbc(blowfish)");
1508 ret += tcrypt_test("ctr(blowfish)");
1512 ret += tcrypt_test("ecb(twofish)");
1513 ret += tcrypt_test("cbc(twofish)");
1514 ret += tcrypt_test("ctr(twofish)");
1515 ret += tcrypt_test("lrw(twofish)");
1516 ret += tcrypt_test("xts(twofish)");
1520 ret += tcrypt_test("ecb(serpent)");
1521 ret += tcrypt_test("cbc(serpent)");
1522 ret += tcrypt_test("ctr(serpent)");
1523 ret += tcrypt_test("lrw(serpent)");
1524 ret += tcrypt_test("xts(serpent)");
1528 ret += tcrypt_test("ecb(aes)");
1529 ret += tcrypt_test("cbc(aes)");
1530 ret += tcrypt_test("lrw(aes)");
1531 ret += tcrypt_test("xts(aes)");
1532 ret += tcrypt_test("ctr(aes)");
1533 ret += tcrypt_test("rfc3686(ctr(aes))");
1534 ret += tcrypt_test("ofb(aes)");
1535 ret += tcrypt_test("cfb(aes)");
1536 ret += tcrypt_test("xctr(aes)");
1540 ret += tcrypt_test("sha384");
1544 ret += tcrypt_test("sha512");
1548 ret += tcrypt_test("deflate");
1552 ret += tcrypt_test("ecb(cast5)");
1553 ret += tcrypt_test("cbc(cast5)");
1554 ret += tcrypt_test("ctr(cast5)");
1558 ret += tcrypt_test("ecb(cast6)");
1559 ret += tcrypt_test("cbc(cast6)");
1560 ret += tcrypt_test("ctr(cast6)");
1561 ret += tcrypt_test("lrw(cast6)");
1562 ret += tcrypt_test("xts(cast6)");
1566 ret += tcrypt_test("ecb(arc4)");
1570 ret += tcrypt_test("michael_mic");
1574 ret += tcrypt_test("crc32c");
1578 ret += tcrypt_test("ecb(tea)");
1582 ret += tcrypt_test("ecb(xtea)");
1586 ret += tcrypt_test("ecb(khazad)");
1590 ret += tcrypt_test("wp512");
1594 ret += tcrypt_test("wp384");
1598 ret += tcrypt_test("wp256");
1602 ret += tcrypt_test("ecb(anubis)");
1603 ret += tcrypt_test("cbc(anubis)");
1607 ret += tcrypt_test("ecb(xeta)");
1611 ret += tcrypt_test("pcbc(fcrypt)");
1615 ret += tcrypt_test("ecb(camellia)");
1616 ret += tcrypt_test("cbc(camellia)");
1617 ret += tcrypt_test("ctr(camellia)");
1618 ret += tcrypt_test("lrw(camellia)");
1619 ret += tcrypt_test("xts(camellia)");
1623 ret += tcrypt_test("sha224");
1627 ret += tcrypt_test("gcm(aes)");
1631 ret += tcrypt_test("lzo");
1635 ret += tcrypt_test("ccm(aes)");
1639 ret += tcrypt_test("cts(cbc(aes))");
1643 ret += tcrypt_test("xxhash64");
1647 ret += tcrypt_test("rmd160");
1651 ret += tcrypt_test("blake2b-512");
1655 ret += tcrypt_test("ecb(seed)");
1659 ret += tcrypt_test("rfc4309(ccm(aes))");
1663 ret += tcrypt_test("ghash");
1667 ret += tcrypt_test("crct10dif");
1671 ret += tcrypt_test("sha3-224");
1675 ret += tcrypt_test("sha3-256");
1679 ret += tcrypt_test("sha3-384");
1683 ret += tcrypt_test("sha3-512");
1687 ret += tcrypt_test("sm3");
1691 ret += tcrypt_test("streebog256");
1695 ret += tcrypt_test("streebog512");
1699 ret += tcrypt_test("gcm(sm4)");
1703 ret += tcrypt_test("ccm(sm4)");
1707 ret += tcrypt_test("polyval");
1711 ret += tcrypt_test("gcm(aria)");
1715 ret += tcrypt_test("hmac(md5)");
1719 ret += tcrypt_test("hmac(sha1)");
1723 ret += tcrypt_test("hmac(sha256)");
1727 ret += tcrypt_test("hmac(sha384)");
1731 ret += tcrypt_test("hmac(sha512)");
1735 ret += tcrypt_test("hmac(sha224)");
1739 ret += tcrypt_test("xcbc(aes)");
1743 ret += tcrypt_test("hmac(rmd160)");
1747 ret += tcrypt_test("vmac64(aes)");
1751 ret += tcrypt_test("hmac(sha3-224)");
1755 ret += tcrypt_test("hmac(sha3-256)");
1759 ret += tcrypt_test("hmac(sha3-384)");
1763 ret += tcrypt_test("hmac(sha3-512)");
1767 ret += tcrypt_test("hmac(streebog256)");
1771 ret += tcrypt_test("hmac(streebog512)");
1775 ret += tcrypt_test("ansi_cprng");
1779 ret += tcrypt_test("rfc4106(gcm(aes))");
1783 ret += tcrypt_test("rfc4543(gcm(aes))");
1787 ret += tcrypt_test("cmac(aes)");
1791 ret += tcrypt_test("cmac(des3_ede)");
1795 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1799 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1803 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1807 ret += tcrypt_test("cbcmac(sm4)");
1811 ret += tcrypt_test("cmac(sm4)");
1815 ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
1818 ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
1821 ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
1824 ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
1827 ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
1830 ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
1833 ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
1836 ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
1839 ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
1842 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
1845 ret += tcrypt_test("ecb(sm4)");
1846 ret += tcrypt_test("cbc(sm4)");
1847 ret += tcrypt_test("cfb(sm4)");
1848 ret += tcrypt_test("ctr(sm4)");
1851 ret += tcrypt_test("ecb(aria)");
1852 ret += tcrypt_test("cbc(aria)");
1853 ret += tcrypt_test("cfb(aria)");
1854 ret += tcrypt_test("ctr(aria)");
1857 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1858 speed_template_16_24_32);
1859 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1860 speed_template_16_24_32);
1861 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1862 speed_template_16_24_32);
1863 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1864 speed_template_16_24_32);
1865 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1866 speed_template_32_40_48);
1867 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1868 speed_template_32_40_48);
1869 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1870 speed_template_32_64);
1871 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1872 speed_template_32_64);
1873 test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
1874 speed_template_16_24_32);
1875 test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
1876 speed_template_16_24_32);
1877 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1878 speed_template_16_24_32);
1879 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1880 speed_template_16_24_32);
1881 test_cipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
1882 speed_template_16_24_32);
1883 test_cipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
1884 speed_template_16_24_32);
1888 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1889 des3_speed_template, DES3_SPEED_VECTORS,
1891 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1892 des3_speed_template, DES3_SPEED_VECTORS,
1894 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1895 des3_speed_template, DES3_SPEED_VECTORS,
1897 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1898 des3_speed_template, DES3_SPEED_VECTORS,
1900 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
1901 des3_speed_template, DES3_SPEED_VECTORS,
1903 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
1904 des3_speed_template, DES3_SPEED_VECTORS,
1909 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1910 speed_template_16_24_32);
1911 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1912 speed_template_16_24_32);
1913 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1914 speed_template_16_24_32);
1915 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1916 speed_template_16_24_32);
1917 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1918 speed_template_16_24_32);
1919 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1920 speed_template_16_24_32);
1921 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1922 speed_template_32_40_48);
1923 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1924 speed_template_32_40_48);
1925 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1926 speed_template_32_48_64);
1927 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1928 speed_template_32_48_64);
1932 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1933 speed_template_8_32);
1934 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1935 speed_template_8_32);
1936 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1937 speed_template_8_32);
1938 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1939 speed_template_8_32);
1940 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
1941 speed_template_8_32);
1942 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
1943 speed_template_8_32);
1947 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1949 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1951 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1953 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1958 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1959 speed_template_16_24_32);
1960 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1961 speed_template_16_24_32);
1962 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1963 speed_template_16_24_32);
1964 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1965 speed_template_16_24_32);
1966 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
1967 speed_template_16_24_32);
1968 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
1969 speed_template_16_24_32);
1970 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
1971 speed_template_32_40_48);
1972 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
1973 speed_template_32_40_48);
1974 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
1975 speed_template_32_48_64);
1976 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
1977 speed_template_32_48_64);
1981 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1982 speed_template_16_32);
1983 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1984 speed_template_16_32);
1985 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1986 speed_template_16_32);
1987 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1988 speed_template_16_32);
1989 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1990 speed_template_16_32);
1991 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1992 speed_template_16_32);
1993 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1994 speed_template_32_48);
1995 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1996 speed_template_32_48);
1997 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1998 speed_template_32_64);
1999 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2000 speed_template_32_64);
2004 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2009 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2010 speed_template_8_16);
2011 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2012 speed_template_8_16);
2013 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2014 speed_template_8_16);
2015 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2016 speed_template_8_16);
2017 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2018 speed_template_8_16);
2019 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2020 speed_template_8_16);
2024 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2025 speed_template_16_32);
2026 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2027 speed_template_16_32);
2028 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2029 speed_template_16_32);
2030 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2031 speed_template_16_32);
2032 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2033 speed_template_16_32);
2034 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2035 speed_template_16_32);
2036 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2037 speed_template_32_48);
2038 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2039 speed_template_32_48);
2040 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2041 speed_template_32_64);
2042 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2043 speed_template_32_64);
2047 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
2048 NULL, 0, 16, 16, aead_speed_template_20);
2049 test_aead_speed("gcm(aes)", ENCRYPT, sec,
2050 NULL, 0, 16, 8, speed_template_16_24_32);
2051 test_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec,
2052 NULL, 0, 16, 16, aead_speed_template_20);
2053 test_aead_speed("gcm(aes)", DECRYPT, sec,
2054 NULL, 0, 16, 8, speed_template_16_24_32);
2058 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
2059 NULL, 0, 16, 16, aead_speed_template_19);
2060 test_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec,
2061 NULL, 0, 16, 16, aead_speed_template_19);
2065 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
2066 NULL, 0, 16, 8, aead_speed_template_36);
2067 test_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT, sec,
2068 NULL, 0, 16, 8, aead_speed_template_36);
2072 test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
2077 test_mb_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec, NULL,
2078 0, 16, 16, aead_speed_template_20, num_mb);
2079 test_mb_aead_speed("gcm(aes)", ENCRYPT, sec, NULL, 0, 16, 8,
2080 speed_template_16_24_32, num_mb);
2081 test_mb_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec, NULL,
2082 0, 16, 16, aead_speed_template_20, num_mb);
2083 test_mb_aead_speed("gcm(aes)", DECRYPT, sec, NULL, 0, 16, 8,
2084 speed_template_16_24_32, num_mb);
2088 test_mb_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec, NULL, 0,
2089 16, 16, aead_speed_template_19, num_mb);
2090 test_mb_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec, NULL, 0,
2091 16, 16, aead_speed_template_19, num_mb);
2095 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT,
2096 sec, NULL, 0, 16, 8, aead_speed_template_36,
2098 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT,
2099 sec, NULL, 0, 16, 8, aead_speed_template_36,
2104 test_cipher_speed("ecb(sm4)", ENCRYPT, sec, NULL, 0,
2106 test_cipher_speed("ecb(sm4)", DECRYPT, sec, NULL, 0,
2108 test_cipher_speed("cbc(sm4)", ENCRYPT, sec, NULL, 0,
2110 test_cipher_speed("cbc(sm4)", DECRYPT, sec, NULL, 0,
2112 test_cipher_speed("cfb(sm4)", ENCRYPT, sec, NULL, 0,
2114 test_cipher_speed("cfb(sm4)", DECRYPT, sec, NULL, 0,
2116 test_cipher_speed("ctr(sm4)", ENCRYPT, sec, NULL, 0,
2118 test_cipher_speed("ctr(sm4)", DECRYPT, sec, NULL, 0,
2123 test_cipher_speed("adiantum(xchacha12,aes)", ENCRYPT, sec, NULL,
2124 0, speed_template_32);
2125 test_cipher_speed("adiantum(xchacha12,aes)", DECRYPT, sec, NULL,
2126 0, speed_template_32);
2127 test_cipher_speed("adiantum(xchacha20,aes)", ENCRYPT, sec, NULL,
2128 0, speed_template_32);
2129 test_cipher_speed("adiantum(xchacha20,aes)", DECRYPT, sec, NULL,
2130 0, speed_template_32);
2134 test_acipher_speed("essiv(cbc(aes),sha256)",
2135 ENCRYPT, sec, NULL, 0,
2136 speed_template_16_24_32);
2137 test_acipher_speed("essiv(cbc(aes),sha256)",
2138 DECRYPT, sec, NULL, 0,
2139 speed_template_16_24_32);
2143 test_aead_speed("aegis128", ENCRYPT, sec,
2144 NULL, 0, 16, 8, speed_template_16);
2145 test_aead_speed("aegis128", DECRYPT, sec,
2146 NULL, 0, 16, 8, speed_template_16);
2150 test_aead_speed("gcm(sm4)", ENCRYPT, sec,
2151 NULL, 0, 16, 8, speed_template_16);
2152 test_aead_speed("gcm(sm4)", DECRYPT, sec,
2153 NULL, 0, 16, 8, speed_template_16);
2157 test_aead_speed("rfc4309(ccm(sm4))", ENCRYPT, sec,
2158 NULL, 0, 16, 16, aead_speed_template_19);
2159 test_aead_speed("rfc4309(ccm(sm4))", DECRYPT, sec,
2160 NULL, 0, 16, 16, aead_speed_template_19);
2164 test_mb_aead_speed("gcm(sm4)", ENCRYPT, sec, NULL, 0, 16, 8,
2165 speed_template_16, num_mb);
2166 test_mb_aead_speed("gcm(sm4)", DECRYPT, sec, NULL, 0, 16, 8,
2167 speed_template_16, num_mb);
2171 test_mb_aead_speed("rfc4309(ccm(sm4))", ENCRYPT, sec, NULL, 0,
2172 16, 16, aead_speed_template_19, num_mb);
2173 test_mb_aead_speed("rfc4309(ccm(sm4))", DECRYPT, sec, NULL, 0,
2174 16, 16, aead_speed_template_19, num_mb);
2178 test_cipher_speed("hctr2(aes)", ENCRYPT, sec, NULL,
2179 0, speed_template_32);
2183 test_cipher_speed("ecb(aria)", ENCRYPT, sec, NULL, 0,
2184 speed_template_16_24_32);
2185 test_cipher_speed("ecb(aria)", DECRYPT, sec, NULL, 0,
2186 speed_template_16_24_32);
2187 test_cipher_speed("cbc(aria)", ENCRYPT, sec, NULL, 0,
2188 speed_template_16_24_32);
2189 test_cipher_speed("cbc(aria)", DECRYPT, sec, NULL, 0,
2190 speed_template_16_24_32);
2191 test_cipher_speed("cfb(aria)", ENCRYPT, sec, NULL, 0,
2192 speed_template_16_24_32);
2193 test_cipher_speed("cfb(aria)", DECRYPT, sec, NULL, 0,
2194 speed_template_16_24_32);
2195 test_cipher_speed("ctr(aria)", ENCRYPT, sec, NULL, 0,
2196 speed_template_16_24_32);
2197 test_cipher_speed("ctr(aria)", DECRYPT, sec, NULL, 0,
2198 speed_template_16_24_32);
2202 test_aead_speed("gcm(aria)", ENCRYPT, sec,
2203 NULL, 0, 16, 8, speed_template_16_24_32);
2204 test_aead_speed("gcm(aria)", DECRYPT, sec,
2205 NULL, 0, 16, 8, speed_template_16_24_32);
2209 test_mb_aead_speed("gcm(aria)", ENCRYPT, sec, NULL, 0, 16, 8,
2210 speed_template_16, num_mb);
2211 test_mb_aead_speed("gcm(aria)", DECRYPT, sec, NULL, 0, 16, 8,
2212 speed_template_16, num_mb);
2217 test_hash_speed(alg, sec, generic_hash_speed_template);
2222 test_hash_speed("md4", sec, generic_hash_speed_template);
2223 if (mode > 300 && mode < 400) break;
2226 test_hash_speed("md5", sec, generic_hash_speed_template);
2227 if (mode > 300 && mode < 400) break;
2230 test_hash_speed("sha1", sec, generic_hash_speed_template);
2231 if (mode > 300 && mode < 400) break;
2234 test_hash_speed("sha256", sec, generic_hash_speed_template);
2235 if (mode > 300 && mode < 400) break;
2238 test_hash_speed("sha384", sec, generic_hash_speed_template);
2239 if (mode > 300 && mode < 400) break;
2242 test_hash_speed("sha512", sec, generic_hash_speed_template);
2243 if (mode > 300 && mode < 400) break;
2246 test_hash_speed("wp256", sec, generic_hash_speed_template);
2247 if (mode > 300 && mode < 400) break;
2250 test_hash_speed("wp384", sec, generic_hash_speed_template);
2251 if (mode > 300 && mode < 400) break;
2254 test_hash_speed("wp512", sec, generic_hash_speed_template);
2255 if (mode > 300 && mode < 400) break;
2258 test_hash_speed("sha224", sec, generic_hash_speed_template);
2259 if (mode > 300 && mode < 400) break;
2262 test_hash_speed("xxhash64", sec, generic_hash_speed_template);
2263 if (mode > 300 && mode < 400) break;
2266 test_hash_speed("rmd160", sec, generic_hash_speed_template);
2267 if (mode > 300 && mode < 400) break;
2270 test_hash_speed("blake2b-512", sec, generic_hash_speed_template);
2271 if (mode > 300 && mode < 400) break;
2275 test_hash_speed("ghash", sec, generic_hash_speed_template);
2276 if (mode > 300 && mode < 400) break;
2279 test_hash_speed("crc32c", sec, generic_hash_speed_template);
2280 if (mode > 300 && mode < 400) break;
2283 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
2284 if (mode > 300 && mode < 400) break;
2287 test_hash_speed("poly1305", sec, poly1305_speed_template);
2288 if (mode > 300 && mode < 400) break;
2291 test_hash_speed("sha3-224", sec, generic_hash_speed_template);
2292 if (mode > 300 && mode < 400) break;
2295 test_hash_speed("sha3-256", sec, generic_hash_speed_template);
2296 if (mode > 300 && mode < 400) break;
2299 test_hash_speed("sha3-384", sec, generic_hash_speed_template);
2300 if (mode > 300 && mode < 400) break;
2303 test_hash_speed("sha3-512", sec, generic_hash_speed_template);
2304 if (mode > 300 && mode < 400) break;
2307 test_hash_speed("sm3", sec, generic_hash_speed_template);
2308 if (mode > 300 && mode < 400) break;
2311 test_hash_speed("streebog256", sec,
2312 generic_hash_speed_template);
2313 if (mode > 300 && mode < 400) break;
2316 test_hash_speed("streebog512", sec,
2317 generic_hash_speed_template);
2318 if (mode > 300 && mode < 400) break;
2325 test_ahash_speed(alg, sec, generic_hash_speed_template);
2330 test_ahash_speed("md4", sec, generic_hash_speed_template);
2331 if (mode > 400 && mode < 500) break;
2334 test_ahash_speed("md5", sec, generic_hash_speed_template);
2335 if (mode > 400 && mode < 500) break;
2338 test_ahash_speed("sha1", sec, generic_hash_speed_template);
2339 if (mode > 400 && mode < 500) break;
2342 test_ahash_speed("sha256", sec, generic_hash_speed_template);
2343 if (mode > 400 && mode < 500) break;
2346 test_ahash_speed("sha384", sec, generic_hash_speed_template);
2347 if (mode > 400 && mode < 500) break;
2350 test_ahash_speed("sha512", sec, generic_hash_speed_template);
2351 if (mode > 400 && mode < 500) break;
2354 test_ahash_speed("wp256", sec, generic_hash_speed_template);
2355 if (mode > 400 && mode < 500) break;
2358 test_ahash_speed("wp384", sec, generic_hash_speed_template);
2359 if (mode > 400 && mode < 500) break;
2362 test_ahash_speed("wp512", sec, generic_hash_speed_template);
2363 if (mode > 400 && mode < 500) break;
2366 test_ahash_speed("sha224", sec, generic_hash_speed_template);
2367 if (mode > 400 && mode < 500) break;
2370 test_ahash_speed("xxhash64", sec, generic_hash_speed_template);
2371 if (mode > 400 && mode < 500) break;
2374 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
2375 if (mode > 400 && mode < 500) break;
2378 test_ahash_speed("blake2b-512", sec, generic_hash_speed_template);
2379 if (mode > 400 && mode < 500) break;
2382 test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
2383 if (mode > 400 && mode < 500) break;
2386 test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
2387 if (mode > 400 && mode < 500) break;
2390 test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
2391 if (mode > 400 && mode < 500) break;
2394 test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
2395 if (mode > 400 && mode < 500) break;
2398 test_ahash_speed("sm3", sec, generic_hash_speed_template);
2399 if (mode > 400 && mode < 500) break;
2405 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2406 speed_template_16_24_32);
2407 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2408 speed_template_16_24_32);
2409 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2410 speed_template_16_24_32);
2411 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2412 speed_template_16_24_32);
2413 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2414 speed_template_32_40_48);
2415 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2416 speed_template_32_40_48);
2417 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2418 speed_template_32_64);
2419 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2420 speed_template_32_64);
2421 test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2422 speed_template_16_24_32);
2423 test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2424 speed_template_16_24_32);
2425 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2426 speed_template_16_24_32);
2427 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2428 speed_template_16_24_32);
2429 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2430 speed_template_16_24_32);
2431 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2432 speed_template_16_24_32);
2433 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2434 speed_template_16_24_32);
2435 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2436 speed_template_16_24_32);
2437 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
2438 speed_template_20_28_36);
2439 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
2440 speed_template_20_28_36);
2444 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2445 des3_speed_template, DES3_SPEED_VECTORS,
2447 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
2448 des3_speed_template, DES3_SPEED_VECTORS,
2450 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2451 des3_speed_template, DES3_SPEED_VECTORS,
2453 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
2454 des3_speed_template, DES3_SPEED_VECTORS,
2456 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2457 des3_speed_template, DES3_SPEED_VECTORS,
2459 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
2460 des3_speed_template, DES3_SPEED_VECTORS,
2462 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2463 des3_speed_template, DES3_SPEED_VECTORS,
2465 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
2466 des3_speed_template, DES3_SPEED_VECTORS,
2471 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2473 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2475 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2477 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2479 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2481 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2483 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2485 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2490 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2491 speed_template_16_32);
2492 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2493 speed_template_16_32);
2494 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2495 speed_template_16_32);
2496 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2497 speed_template_16_32);
2498 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2499 speed_template_16_32);
2500 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2501 speed_template_16_32);
2502 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2503 speed_template_32_48);
2504 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2505 speed_template_32_48);
2506 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2507 speed_template_32_64);
2508 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2509 speed_template_32_64);
2513 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2514 speed_template_16_24_32);
2515 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2516 speed_template_16_24_32);
2517 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2518 speed_template_16_24_32);
2519 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2520 speed_template_16_24_32);
2521 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2522 speed_template_16_24_32);
2523 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2524 speed_template_16_24_32);
2525 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2526 speed_template_32_40_48);
2527 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2528 speed_template_32_40_48);
2529 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2530 speed_template_32_48_64);
2531 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2532 speed_template_32_48_64);
2536 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2541 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2542 speed_template_8_16);
2543 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2544 speed_template_8_16);
2545 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2546 speed_template_8_16);
2547 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2548 speed_template_8_16);
2549 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2550 speed_template_8_16);
2551 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2552 speed_template_8_16);
2556 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2557 speed_template_16_32);
2558 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2559 speed_template_16_32);
2560 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2561 speed_template_16_32);
2562 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2563 speed_template_16_32);
2564 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2565 speed_template_16_32);
2566 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2567 speed_template_16_32);
2568 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2569 speed_template_32_48);
2570 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2571 speed_template_32_48);
2572 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2573 speed_template_32_64);
2574 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2575 speed_template_32_64);
2579 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2580 speed_template_16_32);
2581 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2582 speed_template_16_32);
2583 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2584 speed_template_16_32);
2585 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2586 speed_template_16_32);
2587 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2588 speed_template_16_32);
2589 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2590 speed_template_16_32);
2591 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2592 speed_template_32_48);
2593 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2594 speed_template_32_48);
2595 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2596 speed_template_32_64);
2597 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2598 speed_template_32_64);
2602 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2603 speed_template_8_32);
2604 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2605 speed_template_8_32);
2606 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2607 speed_template_8_32);
2608 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2609 speed_template_8_32);
2610 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2611 speed_template_8_32);
2612 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2613 speed_template_8_32);
2617 test_acipher_speed("ecb(sm4)", ENCRYPT, sec, NULL, 0,
2619 test_acipher_speed("ecb(sm4)", DECRYPT, sec, NULL, 0,
2621 test_acipher_speed("cbc(sm4)", ENCRYPT, sec, NULL, 0,
2623 test_acipher_speed("cbc(sm4)", DECRYPT, sec, NULL, 0,
2625 test_acipher_speed("cfb(sm4)", ENCRYPT, sec, NULL, 0,
2627 test_acipher_speed("cfb(sm4)", DECRYPT, sec, NULL, 0,
2629 test_acipher_speed("ctr(sm4)", ENCRYPT, sec, NULL, 0,
2631 test_acipher_speed("ctr(sm4)", DECRYPT, sec, NULL, 0,
2636 test_acipher_speed("ecb(aria)", ENCRYPT, sec, NULL, 0,
2637 speed_template_16_24_32);
2638 test_acipher_speed("ecb(aria)", DECRYPT, sec, NULL, 0,
2639 speed_template_16_24_32);
2640 test_acipher_speed("ctr(aria)", ENCRYPT, sec, NULL, 0,
2641 speed_template_16_24_32);
2642 test_acipher_speed("ctr(aria)", DECRYPT, sec, NULL, 0,
2643 speed_template_16_24_32);
2647 test_mb_skcipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2648 speed_template_16_24_32, num_mb);
2649 test_mb_skcipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2650 speed_template_16_24_32, num_mb);
2651 test_mb_skcipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2652 speed_template_16_24_32, num_mb);
2653 test_mb_skcipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2654 speed_template_16_24_32, num_mb);
2655 test_mb_skcipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2656 speed_template_32_40_48, num_mb);
2657 test_mb_skcipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2658 speed_template_32_40_48, num_mb);
2659 test_mb_skcipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2660 speed_template_32_64, num_mb);
2661 test_mb_skcipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2662 speed_template_32_64, num_mb);
2663 test_mb_skcipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2664 speed_template_16_24_32, num_mb);
2665 test_mb_skcipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2666 speed_template_16_24_32, num_mb);
2667 test_mb_skcipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2668 speed_template_16_24_32, num_mb);
2669 test_mb_skcipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2670 speed_template_16_24_32, num_mb);
2671 test_mb_skcipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2672 speed_template_16_24_32, num_mb);
2673 test_mb_skcipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2674 speed_template_16_24_32, num_mb);
2675 test_mb_skcipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2676 speed_template_16_24_32, num_mb);
2677 test_mb_skcipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2678 speed_template_16_24_32, num_mb);
2679 test_mb_skcipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL,
2680 0, speed_template_20_28_36, num_mb);
2681 test_mb_skcipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL,
2682 0, speed_template_20_28_36, num_mb);
2686 test_mb_skcipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2687 des3_speed_template, DES3_SPEED_VECTORS,
2688 speed_template_24, num_mb);
2689 test_mb_skcipher_speed("ecb(des3_ede)", DECRYPT, sec,
2690 des3_speed_template, DES3_SPEED_VECTORS,
2691 speed_template_24, num_mb);
2692 test_mb_skcipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2693 des3_speed_template, DES3_SPEED_VECTORS,
2694 speed_template_24, num_mb);
2695 test_mb_skcipher_speed("cbc(des3_ede)", DECRYPT, sec,
2696 des3_speed_template, DES3_SPEED_VECTORS,
2697 speed_template_24, num_mb);
2698 test_mb_skcipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2699 des3_speed_template, DES3_SPEED_VECTORS,
2700 speed_template_24, num_mb);
2701 test_mb_skcipher_speed("cfb(des3_ede)", DECRYPT, sec,
2702 des3_speed_template, DES3_SPEED_VECTORS,
2703 speed_template_24, num_mb);
2704 test_mb_skcipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2705 des3_speed_template, DES3_SPEED_VECTORS,
2706 speed_template_24, num_mb);
2707 test_mb_skcipher_speed("ofb(des3_ede)", DECRYPT, sec,
2708 des3_speed_template, DES3_SPEED_VECTORS,
2709 speed_template_24, num_mb);
2713 test_mb_skcipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2714 speed_template_8, num_mb);
2715 test_mb_skcipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2716 speed_template_8, num_mb);
2717 test_mb_skcipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2718 speed_template_8, num_mb);
2719 test_mb_skcipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2720 speed_template_8, num_mb);
2721 test_mb_skcipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2722 speed_template_8, num_mb);
2723 test_mb_skcipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2724 speed_template_8, num_mb);
2725 test_mb_skcipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2726 speed_template_8, num_mb);
2727 test_mb_skcipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2728 speed_template_8, num_mb);
2732 test_mb_skcipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2733 speed_template_16_32, num_mb);
2734 test_mb_skcipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2735 speed_template_16_32, num_mb);
2736 test_mb_skcipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2737 speed_template_16_32, num_mb);
2738 test_mb_skcipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2739 speed_template_16_32, num_mb);
2740 test_mb_skcipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2741 speed_template_16_32, num_mb);
2742 test_mb_skcipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2743 speed_template_16_32, num_mb);
2744 test_mb_skcipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2745 speed_template_32_48, num_mb);
2746 test_mb_skcipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2747 speed_template_32_48, num_mb);
2748 test_mb_skcipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2749 speed_template_32_64, num_mb);
2750 test_mb_skcipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2751 speed_template_32_64, num_mb);
2755 test_mb_skcipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2756 speed_template_16_24_32, num_mb);
2757 test_mb_skcipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2758 speed_template_16_24_32, num_mb);
2759 test_mb_skcipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2760 speed_template_16_24_32, num_mb);
2761 test_mb_skcipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2762 speed_template_16_24_32, num_mb);
2763 test_mb_skcipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2764 speed_template_16_24_32, num_mb);
2765 test_mb_skcipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2766 speed_template_16_24_32, num_mb);
2767 test_mb_skcipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2768 speed_template_32_40_48, num_mb);
2769 test_mb_skcipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2770 speed_template_32_40_48, num_mb);
2771 test_mb_skcipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2772 speed_template_32_48_64, num_mb);
2773 test_mb_skcipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2774 speed_template_32_48_64, num_mb);
2778 test_mb_skcipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2779 speed_template_8, num_mb);
2783 test_mb_skcipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2784 speed_template_8_16, num_mb);
2785 test_mb_skcipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2786 speed_template_8_16, num_mb);
2787 test_mb_skcipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2788 speed_template_8_16, num_mb);
2789 test_mb_skcipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2790 speed_template_8_16, num_mb);
2791 test_mb_skcipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2792 speed_template_8_16, num_mb);
2793 test_mb_skcipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2794 speed_template_8_16, num_mb);
2798 test_mb_skcipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2799 speed_template_16_32, num_mb);
2800 test_mb_skcipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2801 speed_template_16_32, num_mb);
2802 test_mb_skcipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2803 speed_template_16_32, num_mb);
2804 test_mb_skcipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2805 speed_template_16_32, num_mb);
2806 test_mb_skcipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2807 speed_template_16_32, num_mb);
2808 test_mb_skcipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2809 speed_template_16_32, num_mb);
2810 test_mb_skcipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2811 speed_template_32_48, num_mb);
2812 test_mb_skcipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2813 speed_template_32_48, num_mb);
2814 test_mb_skcipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2815 speed_template_32_64, num_mb);
2816 test_mb_skcipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2817 speed_template_32_64, num_mb);
2821 test_mb_skcipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2822 speed_template_16_32, num_mb);
2823 test_mb_skcipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2824 speed_template_16_32, num_mb);
2825 test_mb_skcipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2826 speed_template_16_32, num_mb);
2827 test_mb_skcipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2828 speed_template_16_32, num_mb);
2829 test_mb_skcipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2830 speed_template_16_32, num_mb);
2831 test_mb_skcipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2832 speed_template_16_32, num_mb);
2833 test_mb_skcipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2834 speed_template_32_48, num_mb);
2835 test_mb_skcipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2836 speed_template_32_48, num_mb);
2837 test_mb_skcipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2838 speed_template_32_64, num_mb);
2839 test_mb_skcipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2840 speed_template_32_64, num_mb);
2844 test_mb_skcipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2845 speed_template_8_32, num_mb);
2846 test_mb_skcipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2847 speed_template_8_32, num_mb);
2848 test_mb_skcipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2849 speed_template_8_32, num_mb);
2850 test_mb_skcipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2851 speed_template_8_32, num_mb);
2852 test_mb_skcipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2853 speed_template_8_32, num_mb);
2854 test_mb_skcipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2855 speed_template_8_32, num_mb);
2859 test_mb_skcipher_speed("ecb(aria)", ENCRYPT, sec, NULL, 0,
2860 speed_template_16_32, num_mb);
2861 test_mb_skcipher_speed("ecb(aria)", DECRYPT, sec, NULL, 0,
2862 speed_template_16_32, num_mb);
2863 test_mb_skcipher_speed("ctr(aria)", ENCRYPT, sec, NULL, 0,
2864 speed_template_16_32, num_mb);
2865 test_mb_skcipher_speed("ctr(aria)", DECRYPT, sec, NULL, 0,
2866 speed_template_16_32, num_mb);
2874 static int __init tcrypt_mod_init(void)
2879 for (i = 0; i < TVMEMSIZE; i++) {
2880 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
2885 err = do_test(alg, type, mask, mode, num_mb);
2888 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
2891 pr_debug("all tests passed\n");
2894 /* We intentionaly return -EAGAIN to prevent keeping the module,
2895 * unless we're running in fips mode. It does all its work from
2896 * init() and doesn't offer any runtime functionality, but in
2897 * the fips case, checking for a successful load is helpful.
2898 * => we don't need it in the memory, do we?
2905 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
2906 free_page((unsigned long)tvmem[i]);
2912 * If an init function is provided, an exit function must also be provided
2913 * to allow module unload.
2915 static void __exit tcrypt_mod_fini(void) { }
2917 late_initcall(tcrypt_mod_init);
2918 module_exit(tcrypt_mod_fini);
2920 module_param(alg, charp, 0);
2921 module_param(type, uint, 0);
2922 module_param(mask, uint, 0);
2923 module_param(mode, int, 0);
2924 module_param(sec, uint, 0);
2925 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
2926 "(defaults to zero which uses CPU cycles instead)");
2927 module_param(num_mb, uint, 0000);
2928 MODULE_PARM_DESC(num_mb, "Number of concurrent requests to be used in mb speed tests (defaults to 8)");
2929 module_param(klen, uint, 0);
2930 MODULE_PARM_DESC(klen, "Key length (defaults to 0)");
2932 MODULE_LICENSE("GPL");
2933 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2934 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");