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("testing 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 pr_cont("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 pr_info("testing 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 pr_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 pr_cont("%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 pr_info("testing 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);
1093 for (i = 0; i < num_mb; ++i) {
1094 data[i].req = skcipher_request_alloc(tfm, GFP_KERNEL);
1096 pr_err("alg: skcipher: Failed to allocate request for %s\n",
1099 skcipher_request_free(data[i].req);
1104 for (i = 0; i < num_mb; ++i) {
1105 skcipher_request_set_callback(data[i].req,
1106 CRYPTO_TFM_REQ_MAY_BACKLOG,
1107 crypto_req_done, &data[i].wait);
1108 crypto_init_wait(&data[i].wait);
1111 pr_info("testing speed of multibuffer %s (%s) %s\n", algo,
1112 get_driver_name(crypto_skcipher, tfm), e);
1116 b_size = block_sizes;
1118 u32 bs = round_up(*b_size, crypto_skcipher_blocksize(tfm));
1120 if (bs > XBUFSIZE * PAGE_SIZE) {
1121 pr_err("template (%u) too big for buffer (%lu)\n",
1122 bs, XBUFSIZE * PAGE_SIZE);
1126 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1129 /* Set up tfm global state, i.e. the key */
1131 memset(tvmem[0], 0xff, PAGE_SIZE);
1133 for (j = 0; j < tcount; j++) {
1134 if (template[j].klen == *keysize) {
1135 key = template[j].key;
1140 crypto_skcipher_clear_flags(tfm, ~0);
1142 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1144 pr_err("setkey() failed flags=%x\n",
1145 crypto_skcipher_get_flags(tfm));
1149 iv_len = crypto_skcipher_ivsize(tfm);
1151 memset(&iv, 0xff, iv_len);
1153 /* Now setup per request stuff, i.e. buffers */
1155 for (j = 0; j < num_mb; ++j) {
1156 struct test_mb_skcipher_data *cur = &data[j];
1157 unsigned int k = bs;
1158 unsigned int pages = DIV_ROUND_UP(k, PAGE_SIZE);
1161 sg_init_table(cur->sg, pages);
1163 while (k > PAGE_SIZE) {
1164 sg_set_buf(cur->sg + p, cur->xbuf[p],
1166 memset(cur->xbuf[p], 0xff, PAGE_SIZE);
1171 sg_set_buf(cur->sg + p, cur->xbuf[p], k);
1172 memset(cur->xbuf[p], 0xff, k);
1174 skcipher_request_set_crypt(cur->req, cur->sg,
1179 ret = test_mb_acipher_jiffies(data, enc,
1184 ret = test_mb_acipher_cycles(data, enc,
1189 pr_err("%s() failed flags=%x\n", e,
1190 crypto_skcipher_get_flags(tfm));
1200 for (i = 0; i < num_mb; ++i)
1201 skcipher_request_free(data[i].req);
1203 for (i = 0; i < num_mb; ++i)
1204 testmgr_free_buf(data[i].xbuf);
1206 crypto_free_skcipher(tfm);
1211 static inline int do_one_acipher_op(struct skcipher_request *req, int ret)
1213 struct crypto_wait *wait = req->base.data;
1215 return crypto_wait_req(ret, wait);
1218 static int test_acipher_jiffies(struct skcipher_request *req, int enc,
1221 unsigned long start, end;
1225 for (start = jiffies, end = start + secs * HZ, bcount = 0;
1226 time_before(jiffies, end); bcount++) {
1228 ret = do_one_acipher_op(req,
1229 crypto_skcipher_encrypt(req));
1231 ret = do_one_acipher_op(req,
1232 crypto_skcipher_decrypt(req));
1238 pr_cont("%d operations in %d seconds (%llu bytes)\n",
1239 bcount, secs, (u64)bcount * blen);
1243 static int test_acipher_cycles(struct skcipher_request *req, int enc,
1246 unsigned long cycles = 0;
1251 for (i = 0; i < 4; i++) {
1253 ret = do_one_acipher_op(req,
1254 crypto_skcipher_encrypt(req));
1256 ret = do_one_acipher_op(req,
1257 crypto_skcipher_decrypt(req));
1263 /* The real thing. */
1264 for (i = 0; i < 8; i++) {
1265 cycles_t start, end;
1267 start = get_cycles();
1269 ret = do_one_acipher_op(req,
1270 crypto_skcipher_encrypt(req));
1272 ret = do_one_acipher_op(req,
1273 crypto_skcipher_decrypt(req));
1279 cycles += end - start;
1284 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1285 (cycles + 4) / 8, blen);
1290 static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
1291 struct cipher_speed_template *template,
1292 unsigned int tcount, u8 *keysize, bool async)
1294 unsigned int ret, i, j, k, iv_len;
1295 struct crypto_wait wait;
1298 struct skcipher_request *req;
1299 struct crypto_skcipher *tfm;
1308 crypto_init_wait(&wait);
1310 tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC);
1313 pr_err("failed to load transform for %s: %ld\n", algo,
1318 pr_info("testing speed of %s %s (%s) %s\n", async ? "async" : "sync",
1319 algo, get_driver_name(crypto_skcipher, tfm), e);
1321 req = skcipher_request_alloc(tfm, GFP_KERNEL);
1323 pr_err("skcipher: Failed to allocate request for %s\n", algo);
1327 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1328 crypto_req_done, &wait);
1332 b_size = block_sizes;
1335 u32 bs = round_up(*b_size, crypto_skcipher_blocksize(tfm));
1336 struct scatterlist sg[TVMEMSIZE];
1338 if ((*keysize + bs) > TVMEMSIZE * PAGE_SIZE) {
1339 pr_err("template (%u) too big for "
1340 "tvmem (%lu)\n", *keysize + bs,
1341 TVMEMSIZE * PAGE_SIZE);
1345 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1348 memset(tvmem[0], 0xff, PAGE_SIZE);
1350 /* set key, plain text and IV */
1352 for (j = 0; j < tcount; j++) {
1353 if (template[j].klen == *keysize) {
1354 key = template[j].key;
1359 crypto_skcipher_clear_flags(tfm, ~0);
1361 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1363 pr_err("setkey() failed flags=%x\n",
1364 crypto_skcipher_get_flags(tfm));
1369 sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
1371 if (k > PAGE_SIZE) {
1372 sg_set_buf(sg, tvmem[0] + *keysize,
1373 PAGE_SIZE - *keysize);
1376 while (k > PAGE_SIZE) {
1377 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
1378 memset(tvmem[j], 0xff, PAGE_SIZE);
1382 sg_set_buf(sg + j, tvmem[j], k);
1383 memset(tvmem[j], 0xff, k);
1385 sg_set_buf(sg, tvmem[0] + *keysize, bs);
1388 iv_len = crypto_skcipher_ivsize(tfm);
1390 memset(&iv, 0xff, iv_len);
1392 skcipher_request_set_crypt(req, sg, sg, bs, iv);
1395 ret = test_acipher_jiffies(req, enc,
1399 ret = test_acipher_cycles(req, enc,
1404 pr_err("%s() failed flags=%x\n", e,
1405 crypto_skcipher_get_flags(tfm));
1415 skcipher_request_free(req);
1417 crypto_free_skcipher(tfm);
1420 static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
1421 struct cipher_speed_template *template,
1422 unsigned int tcount, u8 *keysize)
1424 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1428 static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
1429 struct cipher_speed_template *template,
1430 unsigned int tcount, u8 *keysize)
1432 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1436 static inline int tcrypt_test(const char *alg)
1440 pr_debug("testing %s\n", alg);
1442 ret = alg_test(alg, alg, 0, 0);
1443 /* non-fips algs return -EINVAL or -ECANCELED in fips mode */
1444 if (fips_enabled && (ret == -EINVAL || ret == -ECANCELED))
1449 static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)
1457 if (!crypto_has_alg(alg, type,
1458 mask ?: CRYPTO_ALG_TYPE_MASK))
1463 for (i = 1; i < 200; i++)
1464 ret = min(ret, do_test(NULL, 0, 0, i, num_mb));
1468 ret = min(ret, tcrypt_test("md5"));
1472 ret = min(ret, tcrypt_test("sha1"));
1476 ret = min(ret, tcrypt_test("ecb(des)"));
1477 ret = min(ret, tcrypt_test("cbc(des)"));
1478 ret = min(ret, tcrypt_test("ctr(des)"));
1482 ret = min(ret, tcrypt_test("ecb(des3_ede)"));
1483 ret = min(ret, tcrypt_test("cbc(des3_ede)"));
1484 ret = min(ret, tcrypt_test("ctr(des3_ede)"));
1488 ret = min(ret, tcrypt_test("md4"));
1492 ret = min(ret, tcrypt_test("sha256"));
1496 ret = min(ret, tcrypt_test("ecb(blowfish)"));
1497 ret = min(ret, tcrypt_test("cbc(blowfish)"));
1498 ret = min(ret, tcrypt_test("ctr(blowfish)"));
1502 ret = min(ret, tcrypt_test("ecb(twofish)"));
1503 ret = min(ret, tcrypt_test("cbc(twofish)"));
1504 ret = min(ret, tcrypt_test("ctr(twofish)"));
1505 ret = min(ret, tcrypt_test("lrw(twofish)"));
1506 ret = min(ret, tcrypt_test("xts(twofish)"));
1510 ret = min(ret, tcrypt_test("ecb(serpent)"));
1511 ret = min(ret, tcrypt_test("cbc(serpent)"));
1512 ret = min(ret, tcrypt_test("ctr(serpent)"));
1513 ret = min(ret, tcrypt_test("lrw(serpent)"));
1514 ret = min(ret, tcrypt_test("xts(serpent)"));
1518 ret = min(ret, tcrypt_test("ecb(aes)"));
1519 ret = min(ret, tcrypt_test("cbc(aes)"));
1520 ret = min(ret, tcrypt_test("lrw(aes)"));
1521 ret = min(ret, tcrypt_test("xts(aes)"));
1522 ret = min(ret, tcrypt_test("ctr(aes)"));
1523 ret = min(ret, tcrypt_test("rfc3686(ctr(aes))"));
1524 ret = min(ret, tcrypt_test("ofb(aes)"));
1525 ret = min(ret, tcrypt_test("cfb(aes)"));
1526 ret = min(ret, tcrypt_test("xctr(aes)"));
1530 ret = min(ret, tcrypt_test("sha384"));
1534 ret = min(ret, tcrypt_test("sha512"));
1538 ret = min(ret, tcrypt_test("deflate"));
1542 ret = min(ret, tcrypt_test("ecb(cast5)"));
1543 ret = min(ret, tcrypt_test("cbc(cast5)"));
1544 ret = min(ret, tcrypt_test("ctr(cast5)"));
1548 ret = min(ret, tcrypt_test("ecb(cast6)"));
1549 ret = min(ret, tcrypt_test("cbc(cast6)"));
1550 ret = min(ret, tcrypt_test("ctr(cast6)"));
1551 ret = min(ret, tcrypt_test("lrw(cast6)"));
1552 ret = min(ret, tcrypt_test("xts(cast6)"));
1556 ret = min(ret, tcrypt_test("ecb(arc4)"));
1560 ret = min(ret, tcrypt_test("michael_mic"));
1564 ret = min(ret, tcrypt_test("crc32c"));
1568 ret = min(ret, tcrypt_test("ecb(tea)"));
1572 ret = min(ret, tcrypt_test("ecb(xtea)"));
1576 ret = min(ret, tcrypt_test("ecb(khazad)"));
1580 ret = min(ret, tcrypt_test("wp512"));
1584 ret = min(ret, tcrypt_test("wp384"));
1588 ret = min(ret, tcrypt_test("wp256"));
1592 ret = min(ret, tcrypt_test("ecb(anubis)"));
1593 ret = min(ret, tcrypt_test("cbc(anubis)"));
1597 ret = min(ret, tcrypt_test("ecb(xeta)"));
1601 ret = min(ret, tcrypt_test("pcbc(fcrypt)"));
1605 ret = min(ret, tcrypt_test("ecb(camellia)"));
1606 ret = min(ret, tcrypt_test("cbc(camellia)"));
1607 ret = min(ret, tcrypt_test("ctr(camellia)"));
1608 ret = min(ret, tcrypt_test("lrw(camellia)"));
1609 ret = min(ret, tcrypt_test("xts(camellia)"));
1613 ret = min(ret, tcrypt_test("sha224"));
1617 ret = min(ret, tcrypt_test("gcm(aes)"));
1621 ret = min(ret, tcrypt_test("lzo"));
1625 ret = min(ret, tcrypt_test("ccm(aes)"));
1629 ret = min(ret, tcrypt_test("cts(cbc(aes))"));
1633 ret = min(ret, tcrypt_test("xxhash64"));
1637 ret = min(ret, tcrypt_test("rmd160"));
1641 ret = min(ret, tcrypt_test("blake2b-512"));
1645 ret = min(ret, tcrypt_test("ecb(seed)"));
1649 ret = min(ret, tcrypt_test("rfc4309(ccm(aes))"));
1653 ret = min(ret, tcrypt_test("ghash"));
1657 ret = min(ret, tcrypt_test("crct10dif"));
1661 ret = min(ret, tcrypt_test("sha3-224"));
1665 ret = min(ret, tcrypt_test("sha3-256"));
1669 ret = min(ret, tcrypt_test("sha3-384"));
1673 ret = min(ret, tcrypt_test("sha3-512"));
1677 ret = min(ret, tcrypt_test("sm3"));
1681 ret = min(ret, tcrypt_test("streebog256"));
1685 ret = min(ret, tcrypt_test("streebog512"));
1689 ret = min(ret, tcrypt_test("gcm(sm4)"));
1693 ret = min(ret, tcrypt_test("ccm(sm4)"));
1697 ret = min(ret, tcrypt_test("polyval"));
1701 ret = min(ret, tcrypt_test("gcm(aria)"));
1705 ret = min(ret, tcrypt_test("cts(cbc(sm4))"));
1709 ret = min(ret, tcrypt_test("hmac(md5)"));
1713 ret = min(ret, tcrypt_test("hmac(sha1)"));
1717 ret = min(ret, tcrypt_test("hmac(sha256)"));
1721 ret = min(ret, tcrypt_test("hmac(sha384)"));
1725 ret = min(ret, tcrypt_test("hmac(sha512)"));
1729 ret = min(ret, tcrypt_test("hmac(sha224)"));
1733 ret = min(ret, tcrypt_test("xcbc(aes)"));
1737 ret = min(ret, tcrypt_test("hmac(rmd160)"));
1741 ret = min(ret, tcrypt_test("vmac64(aes)"));
1745 ret = min(ret, tcrypt_test("hmac(sha3-224)"));
1749 ret = min(ret, tcrypt_test("hmac(sha3-256)"));
1753 ret = min(ret, tcrypt_test("hmac(sha3-384)"));
1757 ret = min(ret, tcrypt_test("hmac(sha3-512)"));
1761 ret = min(ret, tcrypt_test("hmac(streebog256)"));
1765 ret = min(ret, tcrypt_test("hmac(streebog512)"));
1769 ret = min(ret, tcrypt_test("ansi_cprng"));
1773 ret = min(ret, tcrypt_test("rfc4106(gcm(aes))"));
1777 ret = min(ret, tcrypt_test("rfc4543(gcm(aes))"));
1781 ret = min(ret, tcrypt_test("cmac(aes)"));
1785 ret = min(ret, tcrypt_test("cmac(des3_ede)"));
1789 ret = min(ret, tcrypt_test("authenc(hmac(sha1),cbc(aes))"));
1793 ret = min(ret, tcrypt_test("authenc(hmac(md5),ecb(cipher_null))"));
1797 ret = min(ret, tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))"));
1801 ret = min(ret, tcrypt_test("cbcmac(sm4)"));
1805 ret = min(ret, tcrypt_test("cmac(sm4)"));
1809 ret = min(ret, tcrypt_test("xcbc(sm4)"));
1813 ret = min(ret, tcrypt_test("authenc(hmac(sha1),cbc(des))"));
1816 ret = min(ret, tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))"));
1819 ret = min(ret, tcrypt_test("authenc(hmac(sha224),cbc(des))"));
1822 ret = min(ret, tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))"));
1825 ret = min(ret, tcrypt_test("authenc(hmac(sha256),cbc(des))"));
1828 ret = min(ret, tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))"));
1831 ret = min(ret, tcrypt_test("authenc(hmac(sha384),cbc(des))"));
1834 ret = min(ret, tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))"));
1837 ret = min(ret, tcrypt_test("authenc(hmac(sha512),cbc(des))"));
1840 ret = min(ret, tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))"));
1843 ret = min(ret, tcrypt_test("ecb(sm4)"));
1844 ret = min(ret, tcrypt_test("cbc(sm4)"));
1845 ret = min(ret, tcrypt_test("cfb(sm4)"));
1846 ret = min(ret, tcrypt_test("ctr(sm4)"));
1847 ret = min(ret, tcrypt_test("xts(sm4)"));
1850 ret = min(ret, tcrypt_test("ecb(aria)"));
1851 ret = min(ret, tcrypt_test("cbc(aria)"));
1852 ret = min(ret, tcrypt_test("cfb(aria)"));
1853 ret = min(ret, tcrypt_test("ctr(aria)"));
1856 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1857 speed_template_16_24_32);
1858 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1859 speed_template_16_24_32);
1860 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1861 speed_template_16_24_32);
1862 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1863 speed_template_16_24_32);
1864 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1865 speed_template_32_40_48);
1866 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1867 speed_template_32_40_48);
1868 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1869 speed_template_32_64);
1870 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1871 speed_template_32_64);
1872 test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
1873 speed_template_16_24_32);
1874 test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
1875 speed_template_16_24_32);
1876 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1877 speed_template_16_24_32);
1878 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1879 speed_template_16_24_32);
1880 test_cipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
1881 speed_template_16_24_32);
1882 test_cipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
1883 speed_template_16_24_32);
1887 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1888 des3_speed_template, DES3_SPEED_VECTORS,
1890 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1891 des3_speed_template, DES3_SPEED_VECTORS,
1893 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1894 des3_speed_template, DES3_SPEED_VECTORS,
1896 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1897 des3_speed_template, DES3_SPEED_VECTORS,
1899 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
1900 des3_speed_template, DES3_SPEED_VECTORS,
1902 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
1903 des3_speed_template, DES3_SPEED_VECTORS,
1908 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1909 speed_template_16_24_32);
1910 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1911 speed_template_16_24_32);
1912 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1913 speed_template_16_24_32);
1914 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1915 speed_template_16_24_32);
1916 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1917 speed_template_16_24_32);
1918 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1919 speed_template_16_24_32);
1920 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1921 speed_template_32_40_48);
1922 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1923 speed_template_32_40_48);
1924 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1925 speed_template_32_48_64);
1926 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1927 speed_template_32_48_64);
1931 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1932 speed_template_8_32);
1933 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1934 speed_template_8_32);
1935 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1936 speed_template_8_32);
1937 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1938 speed_template_8_32);
1939 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
1940 speed_template_8_32);
1941 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
1942 speed_template_8_32);
1946 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1948 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1950 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1952 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1957 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1958 speed_template_16_24_32);
1959 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1960 speed_template_16_24_32);
1961 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1962 speed_template_16_24_32);
1963 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1964 speed_template_16_24_32);
1965 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
1966 speed_template_16_24_32);
1967 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
1968 speed_template_16_24_32);
1969 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
1970 speed_template_32_40_48);
1971 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
1972 speed_template_32_40_48);
1973 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
1974 speed_template_32_48_64);
1975 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
1976 speed_template_32_48_64);
1980 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1981 speed_template_16_32);
1982 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1983 speed_template_16_32);
1984 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1985 speed_template_16_32);
1986 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1987 speed_template_16_32);
1988 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1989 speed_template_16_32);
1990 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1991 speed_template_16_32);
1992 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1993 speed_template_32_48);
1994 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1995 speed_template_32_48);
1996 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1997 speed_template_32_64);
1998 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
1999 speed_template_32_64);
2003 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2008 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2009 speed_template_8_16);
2010 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2011 speed_template_8_16);
2012 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2013 speed_template_8_16);
2014 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2015 speed_template_8_16);
2016 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2017 speed_template_8_16);
2018 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2019 speed_template_8_16);
2023 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2024 speed_template_16_32);
2025 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2026 speed_template_16_32);
2027 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2028 speed_template_16_32);
2029 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2030 speed_template_16_32);
2031 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2032 speed_template_16_32);
2033 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2034 speed_template_16_32);
2035 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2036 speed_template_32_48);
2037 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2038 speed_template_32_48);
2039 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2040 speed_template_32_64);
2041 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2042 speed_template_32_64);
2046 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
2047 NULL, 0, 16, 16, aead_speed_template_20);
2048 test_aead_speed("gcm(aes)", ENCRYPT, sec,
2049 NULL, 0, 16, 8, speed_template_16_24_32);
2050 test_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec,
2051 NULL, 0, 16, 16, aead_speed_template_20);
2052 test_aead_speed("gcm(aes)", DECRYPT, sec,
2053 NULL, 0, 16, 8, speed_template_16_24_32);
2057 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
2058 NULL, 0, 16, 16, aead_speed_template_19);
2059 test_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec,
2060 NULL, 0, 16, 16, aead_speed_template_19);
2064 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
2065 NULL, 0, 16, 8, aead_speed_template_36);
2066 test_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT, sec,
2067 NULL, 0, 16, 8, aead_speed_template_36);
2071 test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
2076 test_mb_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec, NULL,
2077 0, 16, 16, aead_speed_template_20, num_mb);
2078 test_mb_aead_speed("gcm(aes)", ENCRYPT, sec, NULL, 0, 16, 8,
2079 speed_template_16_24_32, num_mb);
2080 test_mb_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec, NULL,
2081 0, 16, 16, aead_speed_template_20, num_mb);
2082 test_mb_aead_speed("gcm(aes)", DECRYPT, sec, NULL, 0, 16, 8,
2083 speed_template_16_24_32, num_mb);
2087 test_mb_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec, NULL, 0,
2088 16, 16, aead_speed_template_19, num_mb);
2089 test_mb_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec, NULL, 0,
2090 16, 16, aead_speed_template_19, num_mb);
2094 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT,
2095 sec, NULL, 0, 16, 8, aead_speed_template_36,
2097 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT,
2098 sec, NULL, 0, 16, 8, aead_speed_template_36,
2103 test_cipher_speed("ecb(sm4)", ENCRYPT, sec, NULL, 0,
2105 test_cipher_speed("ecb(sm4)", DECRYPT, sec, NULL, 0,
2107 test_cipher_speed("cbc(sm4)", ENCRYPT, sec, NULL, 0,
2109 test_cipher_speed("cbc(sm4)", DECRYPT, sec, NULL, 0,
2111 test_cipher_speed("cts(cbc(sm4))", ENCRYPT, sec, NULL, 0,
2113 test_cipher_speed("cts(cbc(sm4))", DECRYPT, sec, NULL, 0,
2115 test_cipher_speed("cfb(sm4)", ENCRYPT, sec, NULL, 0,
2117 test_cipher_speed("cfb(sm4)", DECRYPT, sec, NULL, 0,
2119 test_cipher_speed("ctr(sm4)", ENCRYPT, sec, NULL, 0,
2121 test_cipher_speed("ctr(sm4)", DECRYPT, sec, NULL, 0,
2123 test_cipher_speed("xts(sm4)", ENCRYPT, sec, NULL, 0,
2125 test_cipher_speed("xts(sm4)", DECRYPT, sec, NULL, 0,
2130 test_cipher_speed("adiantum(xchacha12,aes)", ENCRYPT, sec, NULL,
2131 0, speed_template_32);
2132 test_cipher_speed("adiantum(xchacha12,aes)", DECRYPT, sec, NULL,
2133 0, speed_template_32);
2134 test_cipher_speed("adiantum(xchacha20,aes)", ENCRYPT, sec, NULL,
2135 0, speed_template_32);
2136 test_cipher_speed("adiantum(xchacha20,aes)", DECRYPT, sec, NULL,
2137 0, speed_template_32);
2141 test_acipher_speed("essiv(cbc(aes),sha256)",
2142 ENCRYPT, sec, NULL, 0,
2143 speed_template_16_24_32);
2144 test_acipher_speed("essiv(cbc(aes),sha256)",
2145 DECRYPT, sec, NULL, 0,
2146 speed_template_16_24_32);
2150 test_aead_speed("aegis128", ENCRYPT, sec,
2151 NULL, 0, 16, 8, speed_template_16);
2152 test_aead_speed("aegis128", DECRYPT, sec,
2153 NULL, 0, 16, 8, speed_template_16);
2157 test_aead_speed("gcm(sm4)", ENCRYPT, sec,
2158 NULL, 0, 16, 8, speed_template_16);
2159 test_aead_speed("gcm(sm4)", DECRYPT, sec,
2160 NULL, 0, 16, 8, speed_template_16);
2164 test_aead_speed("rfc4309(ccm(sm4))", ENCRYPT, sec,
2165 NULL, 0, 16, 16, aead_speed_template_19);
2166 test_aead_speed("rfc4309(ccm(sm4))", DECRYPT, sec,
2167 NULL, 0, 16, 16, aead_speed_template_19);
2171 test_mb_aead_speed("gcm(sm4)", ENCRYPT, sec, NULL, 0, 16, 8,
2172 speed_template_16, num_mb);
2173 test_mb_aead_speed("gcm(sm4)", DECRYPT, sec, NULL, 0, 16, 8,
2174 speed_template_16, num_mb);
2178 test_mb_aead_speed("rfc4309(ccm(sm4))", ENCRYPT, sec, NULL, 0,
2179 16, 16, aead_speed_template_19, num_mb);
2180 test_mb_aead_speed("rfc4309(ccm(sm4))", DECRYPT, sec, NULL, 0,
2181 16, 16, aead_speed_template_19, num_mb);
2185 test_cipher_speed("hctr2(aes)", ENCRYPT, sec, NULL,
2186 0, speed_template_32);
2190 test_cipher_speed("ecb(aria)", ENCRYPT, sec, NULL, 0,
2191 speed_template_16_24_32);
2192 test_cipher_speed("ecb(aria)", DECRYPT, sec, NULL, 0,
2193 speed_template_16_24_32);
2194 test_cipher_speed("cbc(aria)", ENCRYPT, sec, NULL, 0,
2195 speed_template_16_24_32);
2196 test_cipher_speed("cbc(aria)", DECRYPT, sec, NULL, 0,
2197 speed_template_16_24_32);
2198 test_cipher_speed("cfb(aria)", ENCRYPT, sec, NULL, 0,
2199 speed_template_16_24_32);
2200 test_cipher_speed("cfb(aria)", DECRYPT, sec, NULL, 0,
2201 speed_template_16_24_32);
2202 test_cipher_speed("ctr(aria)", ENCRYPT, sec, NULL, 0,
2203 speed_template_16_24_32);
2204 test_cipher_speed("ctr(aria)", DECRYPT, sec, NULL, 0,
2205 speed_template_16_24_32);
2209 test_aead_speed("gcm(aria)", ENCRYPT, sec,
2210 NULL, 0, 16, 8, speed_template_16_24_32);
2211 test_aead_speed("gcm(aria)", DECRYPT, sec,
2212 NULL, 0, 16, 8, speed_template_16_24_32);
2216 test_mb_aead_speed("gcm(aria)", ENCRYPT, sec, NULL, 0, 16, 8,
2217 speed_template_16, num_mb);
2218 test_mb_aead_speed("gcm(aria)", DECRYPT, sec, NULL, 0, 16, 8,
2219 speed_template_16, num_mb);
2224 test_hash_speed(alg, sec, generic_hash_speed_template);
2229 test_hash_speed("md4", sec, generic_hash_speed_template);
2230 if (mode > 300 && mode < 400) break;
2233 test_hash_speed("md5", sec, generic_hash_speed_template);
2234 if (mode > 300 && mode < 400) break;
2237 test_hash_speed("sha1", sec, generic_hash_speed_template);
2238 if (mode > 300 && mode < 400) break;
2241 test_hash_speed("sha256", sec, generic_hash_speed_template);
2242 if (mode > 300 && mode < 400) break;
2245 test_hash_speed("sha384", sec, generic_hash_speed_template);
2246 if (mode > 300 && mode < 400) break;
2249 test_hash_speed("sha512", sec, generic_hash_speed_template);
2250 if (mode > 300 && mode < 400) break;
2253 test_hash_speed("wp256", sec, generic_hash_speed_template);
2254 if (mode > 300 && mode < 400) break;
2257 test_hash_speed("wp384", sec, generic_hash_speed_template);
2258 if (mode > 300 && mode < 400) break;
2261 test_hash_speed("wp512", sec, generic_hash_speed_template);
2262 if (mode > 300 && mode < 400) break;
2265 test_hash_speed("sha224", sec, generic_hash_speed_template);
2266 if (mode > 300 && mode < 400) break;
2269 test_hash_speed("xxhash64", sec, generic_hash_speed_template);
2270 if (mode > 300 && mode < 400) break;
2273 test_hash_speed("rmd160", sec, generic_hash_speed_template);
2274 if (mode > 300 && mode < 400) break;
2277 test_hash_speed("blake2b-512", sec, generic_hash_speed_template);
2278 if (mode > 300 && mode < 400) break;
2282 test_hash_speed("ghash", sec, generic_hash_speed_template);
2283 if (mode > 300 && mode < 400) break;
2286 test_hash_speed("crc32c", sec, generic_hash_speed_template);
2287 if (mode > 300 && mode < 400) break;
2290 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
2291 if (mode > 300 && mode < 400) break;
2294 test_hash_speed("poly1305", sec, poly1305_speed_template);
2295 if (mode > 300 && mode < 400) break;
2298 test_hash_speed("sha3-224", sec, generic_hash_speed_template);
2299 if (mode > 300 && mode < 400) break;
2302 test_hash_speed("sha3-256", sec, generic_hash_speed_template);
2303 if (mode > 300 && mode < 400) break;
2306 test_hash_speed("sha3-384", sec, generic_hash_speed_template);
2307 if (mode > 300 && mode < 400) break;
2310 test_hash_speed("sha3-512", sec, generic_hash_speed_template);
2311 if (mode > 300 && mode < 400) break;
2314 test_hash_speed("sm3", sec, generic_hash_speed_template);
2315 if (mode > 300 && mode < 400) break;
2318 test_hash_speed("streebog256", sec,
2319 generic_hash_speed_template);
2320 if (mode > 300 && mode < 400) break;
2323 test_hash_speed("streebog512", sec,
2324 generic_hash_speed_template);
2325 if (mode > 300 && mode < 400) break;
2332 test_ahash_speed(alg, sec, generic_hash_speed_template);
2337 test_ahash_speed("md4", sec, generic_hash_speed_template);
2338 if (mode > 400 && mode < 500) break;
2341 test_ahash_speed("md5", sec, generic_hash_speed_template);
2342 if (mode > 400 && mode < 500) break;
2345 test_ahash_speed("sha1", sec, generic_hash_speed_template);
2346 if (mode > 400 && mode < 500) break;
2349 test_ahash_speed("sha256", sec, generic_hash_speed_template);
2350 if (mode > 400 && mode < 500) break;
2353 test_ahash_speed("sha384", sec, generic_hash_speed_template);
2354 if (mode > 400 && mode < 500) break;
2357 test_ahash_speed("sha512", sec, generic_hash_speed_template);
2358 if (mode > 400 && mode < 500) break;
2361 test_ahash_speed("wp256", sec, generic_hash_speed_template);
2362 if (mode > 400 && mode < 500) break;
2365 test_ahash_speed("wp384", sec, generic_hash_speed_template);
2366 if (mode > 400 && mode < 500) break;
2369 test_ahash_speed("wp512", sec, generic_hash_speed_template);
2370 if (mode > 400 && mode < 500) break;
2373 test_ahash_speed("sha224", sec, generic_hash_speed_template);
2374 if (mode > 400 && mode < 500) break;
2377 test_ahash_speed("xxhash64", sec, generic_hash_speed_template);
2378 if (mode > 400 && mode < 500) break;
2381 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
2382 if (mode > 400 && mode < 500) break;
2385 test_ahash_speed("blake2b-512", sec, generic_hash_speed_template);
2386 if (mode > 400 && mode < 500) break;
2389 test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
2390 if (mode > 400 && mode < 500) break;
2393 test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
2394 if (mode > 400 && mode < 500) break;
2397 test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
2398 if (mode > 400 && mode < 500) break;
2401 test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
2402 if (mode > 400 && mode < 500) break;
2405 test_ahash_speed("sm3", sec, generic_hash_speed_template);
2406 if (mode > 400 && mode < 500) break;
2412 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2413 speed_template_16_24_32);
2414 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2415 speed_template_16_24_32);
2416 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2417 speed_template_16_24_32);
2418 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2419 speed_template_16_24_32);
2420 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2421 speed_template_32_40_48);
2422 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2423 speed_template_32_40_48);
2424 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2425 speed_template_32_64);
2426 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2427 speed_template_32_64);
2428 test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2429 speed_template_16_24_32);
2430 test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2431 speed_template_16_24_32);
2432 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2433 speed_template_16_24_32);
2434 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2435 speed_template_16_24_32);
2436 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2437 speed_template_16_24_32);
2438 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2439 speed_template_16_24_32);
2440 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2441 speed_template_16_24_32);
2442 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2443 speed_template_16_24_32);
2444 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
2445 speed_template_20_28_36);
2446 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
2447 speed_template_20_28_36);
2451 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2452 des3_speed_template, DES3_SPEED_VECTORS,
2454 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
2455 des3_speed_template, DES3_SPEED_VECTORS,
2457 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2458 des3_speed_template, DES3_SPEED_VECTORS,
2460 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
2461 des3_speed_template, DES3_SPEED_VECTORS,
2463 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2464 des3_speed_template, DES3_SPEED_VECTORS,
2466 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
2467 des3_speed_template, DES3_SPEED_VECTORS,
2469 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2470 des3_speed_template, DES3_SPEED_VECTORS,
2472 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
2473 des3_speed_template, DES3_SPEED_VECTORS,
2478 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2480 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2482 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2484 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2486 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2488 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2490 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2492 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2497 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2498 speed_template_16_32);
2499 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2500 speed_template_16_32);
2501 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2502 speed_template_16_32);
2503 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2504 speed_template_16_32);
2505 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2506 speed_template_16_32);
2507 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2508 speed_template_16_32);
2509 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2510 speed_template_32_48);
2511 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2512 speed_template_32_48);
2513 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2514 speed_template_32_64);
2515 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2516 speed_template_32_64);
2520 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2521 speed_template_16_24_32);
2522 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2523 speed_template_16_24_32);
2524 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2525 speed_template_16_24_32);
2526 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2527 speed_template_16_24_32);
2528 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2529 speed_template_16_24_32);
2530 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2531 speed_template_16_24_32);
2532 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2533 speed_template_32_40_48);
2534 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2535 speed_template_32_40_48);
2536 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2537 speed_template_32_48_64);
2538 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2539 speed_template_32_48_64);
2543 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2548 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2549 speed_template_8_16);
2550 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2551 speed_template_8_16);
2552 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2553 speed_template_8_16);
2554 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2555 speed_template_8_16);
2556 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2557 speed_template_8_16);
2558 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2559 speed_template_8_16);
2563 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2564 speed_template_16_32);
2565 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2566 speed_template_16_32);
2567 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2568 speed_template_16_32);
2569 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2570 speed_template_16_32);
2571 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2572 speed_template_16_32);
2573 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2574 speed_template_16_32);
2575 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2576 speed_template_32_48);
2577 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2578 speed_template_32_48);
2579 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2580 speed_template_32_64);
2581 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2582 speed_template_32_64);
2586 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2587 speed_template_16_32);
2588 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2589 speed_template_16_32);
2590 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2591 speed_template_16_32);
2592 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2593 speed_template_16_32);
2594 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2595 speed_template_16_32);
2596 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2597 speed_template_16_32);
2598 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2599 speed_template_32_48);
2600 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2601 speed_template_32_48);
2602 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2603 speed_template_32_64);
2604 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2605 speed_template_32_64);
2609 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2610 speed_template_8_32);
2611 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2612 speed_template_8_32);
2613 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2614 speed_template_8_32);
2615 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2616 speed_template_8_32);
2617 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2618 speed_template_8_32);
2619 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2620 speed_template_8_32);
2624 test_acipher_speed("ecb(sm4)", ENCRYPT, sec, NULL, 0,
2626 test_acipher_speed("ecb(sm4)", DECRYPT, sec, NULL, 0,
2628 test_acipher_speed("cbc(sm4)", ENCRYPT, sec, NULL, 0,
2630 test_acipher_speed("cbc(sm4)", DECRYPT, sec, NULL, 0,
2632 test_acipher_speed("cfb(sm4)", ENCRYPT, sec, NULL, 0,
2634 test_acipher_speed("cfb(sm4)", DECRYPT, sec, NULL, 0,
2636 test_acipher_speed("ctr(sm4)", ENCRYPT, sec, NULL, 0,
2638 test_acipher_speed("ctr(sm4)", DECRYPT, sec, NULL, 0,
2640 test_acipher_speed("xts(sm4)", ENCRYPT, sec, NULL, 0,
2642 test_acipher_speed("xts(sm4)", DECRYPT, sec, NULL, 0,
2647 test_acipher_speed("ecb(aria)", ENCRYPT, sec, NULL, 0,
2648 speed_template_16_24_32);
2649 test_acipher_speed("ecb(aria)", DECRYPT, sec, NULL, 0,
2650 speed_template_16_24_32);
2651 test_acipher_speed("ctr(aria)", ENCRYPT, sec, NULL, 0,
2652 speed_template_16_24_32);
2653 test_acipher_speed("ctr(aria)", DECRYPT, sec, NULL, 0,
2654 speed_template_16_24_32);
2658 test_mb_skcipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2659 speed_template_16_24_32, num_mb);
2660 test_mb_skcipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2661 speed_template_16_24_32, num_mb);
2662 test_mb_skcipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2663 speed_template_16_24_32, num_mb);
2664 test_mb_skcipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2665 speed_template_16_24_32, num_mb);
2666 test_mb_skcipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2667 speed_template_32_40_48, num_mb);
2668 test_mb_skcipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2669 speed_template_32_40_48, num_mb);
2670 test_mb_skcipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2671 speed_template_32_64, num_mb);
2672 test_mb_skcipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2673 speed_template_32_64, num_mb);
2674 test_mb_skcipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2675 speed_template_16_24_32, num_mb);
2676 test_mb_skcipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2677 speed_template_16_24_32, num_mb);
2678 test_mb_skcipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2679 speed_template_16_24_32, num_mb);
2680 test_mb_skcipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2681 speed_template_16_24_32, num_mb);
2682 test_mb_skcipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2683 speed_template_16_24_32, num_mb);
2684 test_mb_skcipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2685 speed_template_16_24_32, num_mb);
2686 test_mb_skcipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2687 speed_template_16_24_32, num_mb);
2688 test_mb_skcipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2689 speed_template_16_24_32, num_mb);
2690 test_mb_skcipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL,
2691 0, speed_template_20_28_36, num_mb);
2692 test_mb_skcipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL,
2693 0, speed_template_20_28_36, num_mb);
2697 test_mb_skcipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2698 des3_speed_template, DES3_SPEED_VECTORS,
2699 speed_template_24, num_mb);
2700 test_mb_skcipher_speed("ecb(des3_ede)", DECRYPT, sec,
2701 des3_speed_template, DES3_SPEED_VECTORS,
2702 speed_template_24, num_mb);
2703 test_mb_skcipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2704 des3_speed_template, DES3_SPEED_VECTORS,
2705 speed_template_24, num_mb);
2706 test_mb_skcipher_speed("cbc(des3_ede)", DECRYPT, sec,
2707 des3_speed_template, DES3_SPEED_VECTORS,
2708 speed_template_24, num_mb);
2709 test_mb_skcipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2710 des3_speed_template, DES3_SPEED_VECTORS,
2711 speed_template_24, num_mb);
2712 test_mb_skcipher_speed("cfb(des3_ede)", DECRYPT, sec,
2713 des3_speed_template, DES3_SPEED_VECTORS,
2714 speed_template_24, num_mb);
2715 test_mb_skcipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2716 des3_speed_template, DES3_SPEED_VECTORS,
2717 speed_template_24, num_mb);
2718 test_mb_skcipher_speed("ofb(des3_ede)", DECRYPT, sec,
2719 des3_speed_template, DES3_SPEED_VECTORS,
2720 speed_template_24, num_mb);
2724 test_mb_skcipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2725 speed_template_8, num_mb);
2726 test_mb_skcipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2727 speed_template_8, num_mb);
2728 test_mb_skcipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2729 speed_template_8, num_mb);
2730 test_mb_skcipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2731 speed_template_8, num_mb);
2732 test_mb_skcipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2733 speed_template_8, num_mb);
2734 test_mb_skcipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2735 speed_template_8, num_mb);
2736 test_mb_skcipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2737 speed_template_8, num_mb);
2738 test_mb_skcipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2739 speed_template_8, num_mb);
2743 test_mb_skcipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2744 speed_template_16_32, num_mb);
2745 test_mb_skcipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2746 speed_template_16_32, num_mb);
2747 test_mb_skcipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2748 speed_template_16_32, num_mb);
2749 test_mb_skcipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2750 speed_template_16_32, num_mb);
2751 test_mb_skcipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2752 speed_template_16_32, num_mb);
2753 test_mb_skcipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2754 speed_template_16_32, num_mb);
2755 test_mb_skcipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2756 speed_template_32_48, num_mb);
2757 test_mb_skcipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2758 speed_template_32_48, num_mb);
2759 test_mb_skcipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2760 speed_template_32_64, num_mb);
2761 test_mb_skcipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2762 speed_template_32_64, num_mb);
2766 test_mb_skcipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2767 speed_template_16_24_32, num_mb);
2768 test_mb_skcipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2769 speed_template_16_24_32, num_mb);
2770 test_mb_skcipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2771 speed_template_16_24_32, num_mb);
2772 test_mb_skcipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2773 speed_template_16_24_32, num_mb);
2774 test_mb_skcipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2775 speed_template_16_24_32, num_mb);
2776 test_mb_skcipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2777 speed_template_16_24_32, num_mb);
2778 test_mb_skcipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2779 speed_template_32_40_48, num_mb);
2780 test_mb_skcipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2781 speed_template_32_40_48, num_mb);
2782 test_mb_skcipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2783 speed_template_32_48_64, num_mb);
2784 test_mb_skcipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2785 speed_template_32_48_64, num_mb);
2789 test_mb_skcipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2790 speed_template_8, num_mb);
2794 test_mb_skcipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2795 speed_template_8_16, num_mb);
2796 test_mb_skcipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2797 speed_template_8_16, num_mb);
2798 test_mb_skcipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2799 speed_template_8_16, num_mb);
2800 test_mb_skcipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2801 speed_template_8_16, num_mb);
2802 test_mb_skcipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2803 speed_template_8_16, num_mb);
2804 test_mb_skcipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2805 speed_template_8_16, num_mb);
2809 test_mb_skcipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2810 speed_template_16_32, num_mb);
2811 test_mb_skcipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2812 speed_template_16_32, num_mb);
2813 test_mb_skcipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2814 speed_template_16_32, num_mb);
2815 test_mb_skcipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2816 speed_template_16_32, num_mb);
2817 test_mb_skcipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2818 speed_template_16_32, num_mb);
2819 test_mb_skcipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2820 speed_template_16_32, num_mb);
2821 test_mb_skcipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2822 speed_template_32_48, num_mb);
2823 test_mb_skcipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2824 speed_template_32_48, num_mb);
2825 test_mb_skcipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2826 speed_template_32_64, num_mb);
2827 test_mb_skcipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2828 speed_template_32_64, num_mb);
2832 test_mb_skcipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2833 speed_template_16_32, num_mb);
2834 test_mb_skcipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2835 speed_template_16_32, num_mb);
2836 test_mb_skcipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2837 speed_template_16_32, num_mb);
2838 test_mb_skcipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2839 speed_template_16_32, num_mb);
2840 test_mb_skcipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2841 speed_template_16_32, num_mb);
2842 test_mb_skcipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2843 speed_template_16_32, num_mb);
2844 test_mb_skcipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2845 speed_template_32_48, num_mb);
2846 test_mb_skcipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2847 speed_template_32_48, num_mb);
2848 test_mb_skcipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2849 speed_template_32_64, num_mb);
2850 test_mb_skcipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2851 speed_template_32_64, num_mb);
2855 test_mb_skcipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2856 speed_template_8_32, num_mb);
2857 test_mb_skcipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2858 speed_template_8_32, num_mb);
2859 test_mb_skcipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2860 speed_template_8_32, num_mb);
2861 test_mb_skcipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2862 speed_template_8_32, num_mb);
2863 test_mb_skcipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2864 speed_template_8_32, num_mb);
2865 test_mb_skcipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2866 speed_template_8_32, num_mb);
2870 test_mb_skcipher_speed("ecb(aria)", ENCRYPT, sec, NULL, 0,
2871 speed_template_16_32, num_mb);
2872 test_mb_skcipher_speed("ecb(aria)", DECRYPT, sec, NULL, 0,
2873 speed_template_16_32, num_mb);
2874 test_mb_skcipher_speed("ctr(aria)", ENCRYPT, sec, NULL, 0,
2875 speed_template_16_32, num_mb);
2876 test_mb_skcipher_speed("ctr(aria)", DECRYPT, sec, NULL, 0,
2877 speed_template_16_32, num_mb);
2885 static int __init tcrypt_mod_init(void)
2890 for (i = 0; i < TVMEMSIZE; i++) {
2891 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
2896 err = do_test(alg, type, mask, mode, num_mb);
2899 pr_err("one or more tests failed!\n");
2902 pr_debug("all tests passed\n");
2905 /* We intentionaly return -EAGAIN to prevent keeping the module,
2906 * unless we're running in fips mode. It does all its work from
2907 * init() and doesn't offer any runtime functionality, but in
2908 * the fips case, checking for a successful load is helpful.
2909 * => we don't need it in the memory, do we?
2916 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
2917 free_page((unsigned long)tvmem[i]);
2923 * If an init function is provided, an exit function must also be provided
2924 * to allow module unload.
2926 static void __exit tcrypt_mod_fini(void) { }
2928 late_initcall(tcrypt_mod_init);
2929 module_exit(tcrypt_mod_fini);
2931 module_param(alg, charp, 0);
2932 module_param(type, uint, 0);
2933 module_param(mask, uint, 0);
2934 module_param(mode, int, 0);
2935 module_param(sec, uint, 0);
2936 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
2937 "(defaults to zero which uses CPU cycles instead)");
2938 module_param(num_mb, uint, 0000);
2939 MODULE_PARM_DESC(num_mb, "Number of concurrent requests to be used in mb speed tests (defaults to 8)");
2940 module_param(klen, uint, 0);
2941 MODULE_PARM_DESC(klen, "Key length (defaults to 0)");
2943 MODULE_LICENSE("GPL");
2944 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2945 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");