1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Quick & dirty crypto testing module.
5 * This will only exist until we have a better testing mechanism
6 * (e.g. a char device).
8 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
9 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
10 * Copyright (c) 2007 Nokia Siemens Networks
12 * Updated RFC4106 AES-GCM testing.
13 * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
14 * Adrian Hoban <adrian.hoban@intel.com>
15 * Gabriele Paoloni <gabriele.paoloni@intel.com>
16 * Tadeusz Struk (tadeusz.struk@intel.com)
17 * Copyright (c) 2010, Intel Corporation.
20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22 #include <crypto/aead.h>
23 #include <crypto/hash.h>
24 #include <crypto/skcipher.h>
25 #include <linux/err.h>
26 #include <linux/fips.h>
27 #include <linux/init.h>
28 #include <linux/gfp.h>
29 #include <linux/module.h>
30 #include <linux/scatterlist.h>
31 #include <linux/string.h>
32 #include <linux/moduleparam.h>
33 #include <linux/jiffies.h>
34 #include <linux/timex.h>
35 #include <linux/interrupt.h>
39 * Need slab memory for testing (size in number of pages).
44 * Used by test_cipher_speed()
49 #define MAX_DIGEST_SIZE 64
52 * return a string with the driver name
54 #define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm))
57 * Used by test_cipher_speed()
59 static unsigned int sec;
61 static char *alg = NULL;
65 static u32 num_mb = 8;
66 static unsigned int klen;
67 static char *tvmem[TVMEMSIZE];
69 static const char *check[] = {
70 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", "sm3",
71 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
72 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
73 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
74 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
75 "lzo", "lzo-rle", "cts", "sha3-224", "sha3-256", "sha3-384",
76 "sha3-512", "streebog256", "streebog512",
80 static u32 block_sizes[] = { 16, 64, 256, 1024, 1472, 8192, 0 };
81 static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
86 static int testmgr_alloc_buf(char *buf[XBUFSIZE])
90 for (i = 0; i < XBUFSIZE; i++) {
91 buf[i] = (void *)__get_free_page(GFP_KERNEL);
100 free_page((unsigned long)buf[i]);
105 static void testmgr_free_buf(char *buf[XBUFSIZE])
109 for (i = 0; i < XBUFSIZE; i++)
110 free_page((unsigned long)buf[i]);
113 static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],
114 unsigned int buflen, const void *assoc,
115 unsigned int aad_size)
117 int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
124 rem = buflen % PAGE_SIZE;
127 sg_init_table(sg, np + 1);
129 sg_set_buf(&sg[0], assoc, aad_size);
133 for (k = 0; k < np; k++)
134 sg_set_buf(&sg[k + 1], xbuf[k], PAGE_SIZE);
137 sg_set_buf(&sg[k + 1], xbuf[k], rem);
140 static inline int do_one_aead_op(struct aead_request *req, int ret)
142 struct crypto_wait *wait = req->base.data;
144 return crypto_wait_req(ret, wait);
147 struct test_mb_aead_data {
148 struct scatterlist sg[XBUFSIZE];
149 struct scatterlist sgout[XBUFSIZE];
150 struct aead_request *req;
151 struct crypto_wait wait;
152 char *xbuf[XBUFSIZE];
153 char *xoutbuf[XBUFSIZE];
154 char *axbuf[XBUFSIZE];
157 static int do_mult_aead_op(struct test_mb_aead_data *data, int enc,
162 /* Fire up a bunch of concurrent requests */
163 for (i = 0; i < num_mb; i++) {
165 rc[i] = crypto_aead_encrypt(data[i].req);
167 rc[i] = crypto_aead_decrypt(data[i].req);
170 /* Wait for all requests to finish */
171 for (i = 0; i < num_mb; i++) {
172 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
175 pr_info("concurrent request %d error %d\n", i, rc[i]);
183 static int test_mb_aead_jiffies(struct test_mb_aead_data *data, int enc,
184 int blen, int secs, u32 num_mb)
186 unsigned long start, end;
191 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
195 for (start = jiffies, end = start + secs * HZ, bcount = 0;
196 time_before(jiffies, end); bcount++) {
197 ret = do_mult_aead_op(data, enc, num_mb, rc);
202 pr_cont("%d operations in %d seconds (%ld bytes)\n",
203 bcount * num_mb, secs, (long)bcount * blen * num_mb);
210 static int test_mb_aead_cycles(struct test_mb_aead_data *data, int enc,
211 int blen, u32 num_mb)
213 unsigned long cycles = 0;
218 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
223 for (i = 0; i < 4; i++) {
224 ret = do_mult_aead_op(data, enc, num_mb, rc);
229 /* The real thing. */
230 for (i = 0; i < 8; i++) {
233 start = get_cycles();
234 ret = do_mult_aead_op(data, enc, num_mb, rc);
240 cycles += end - start;
243 pr_cont("1 operation in %lu cycles (%d bytes)\n",
244 (cycles + 4) / (8 * num_mb), blen);
251 static void test_mb_aead_speed(const char *algo, int enc, int secs,
252 struct aead_speed_template *template,
253 unsigned int tcount, u8 authsize,
254 unsigned int aad_size, u8 *keysize, u32 num_mb)
256 struct test_mb_aead_data *data;
257 struct crypto_aead *tfm;
258 unsigned int i, j, iv_len;
267 if (aad_size >= PAGE_SIZE) {
268 pr_err("associate data length (%u) too big\n", aad_size);
272 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
281 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
285 tfm = crypto_alloc_aead(algo, 0, 0);
287 pr_err("failed to load transform for %s: %ld\n",
292 ret = crypto_aead_setauthsize(tfm, authsize);
294 for (i = 0; i < num_mb; ++i)
295 if (testmgr_alloc_buf(data[i].xbuf)) {
297 testmgr_free_buf(data[i].xbuf);
301 for (i = 0; i < num_mb; ++i)
302 if (testmgr_alloc_buf(data[i].axbuf)) {
304 testmgr_free_buf(data[i].axbuf);
308 for (i = 0; i < num_mb; ++i)
309 if (testmgr_alloc_buf(data[i].xoutbuf)) {
311 testmgr_free_buf(data[i].xoutbuf);
315 for (i = 0; i < num_mb; ++i) {
316 data[i].req = aead_request_alloc(tfm, GFP_KERNEL);
318 pr_err("alg: skcipher: Failed to allocate request for %s\n",
321 aead_request_free(data[i].req);
322 goto out_free_xoutbuf;
326 for (i = 0; i < num_mb; ++i) {
327 crypto_init_wait(&data[i].wait);
328 aead_request_set_callback(data[i].req,
329 CRYPTO_TFM_REQ_MAY_BACKLOG,
330 crypto_req_done, &data[i].wait);
333 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo,
334 get_driver_name(crypto_aead, tfm), e);
340 if (*b_size + authsize > XBUFSIZE * PAGE_SIZE) {
341 pr_err("template (%u) too big for buffer (%lu)\n",
343 XBUFSIZE * PAGE_SIZE);
347 pr_info("test %u (%d bit key, %d byte blocks): ", i,
348 *keysize * 8, *b_size);
350 /* Set up tfm global state, i.e. the key */
352 memset(tvmem[0], 0xff, PAGE_SIZE);
354 for (j = 0; j < tcount; j++) {
355 if (template[j].klen == *keysize) {
356 key = template[j].key;
361 crypto_aead_clear_flags(tfm, ~0);
363 ret = crypto_aead_setkey(tfm, key, *keysize);
365 pr_err("setkey() failed flags=%x\n",
366 crypto_aead_get_flags(tfm));
370 iv_len = crypto_aead_ivsize(tfm);
372 memset(iv, 0xff, iv_len);
374 /* Now setup per request stuff, i.e. buffers */
376 for (j = 0; j < num_mb; ++j) {
377 struct test_mb_aead_data *cur = &data[j];
379 assoc = cur->axbuf[0];
380 memset(assoc, 0xff, aad_size);
382 sg_init_aead(cur->sg, cur->xbuf,
383 *b_size + (enc ? 0 : authsize),
386 sg_init_aead(cur->sgout, cur->xoutbuf,
387 *b_size + (enc ? authsize : 0),
390 aead_request_set_ad(cur->req, aad_size);
394 aead_request_set_crypt(cur->req,
398 ret = crypto_aead_encrypt(cur->req);
399 ret = do_one_aead_op(cur->req, ret);
402 pr_err("calculating auth failed (%d)\n",
408 aead_request_set_crypt(cur->req, cur->sg,
409 cur->sgout, *b_size +
410 (enc ? 0 : authsize),
416 ret = test_mb_aead_jiffies(data, enc, *b_size,
420 ret = test_mb_aead_cycles(data, enc, *b_size,
425 pr_err("%s() failed return code=%d\n", e, ret);
435 for (i = 0; i < num_mb; ++i)
436 aead_request_free(data[i].req);
438 for (i = 0; i < num_mb; ++i)
439 testmgr_free_buf(data[i].xoutbuf);
441 for (i = 0; i < num_mb; ++i)
442 testmgr_free_buf(data[i].axbuf);
444 for (i = 0; i < num_mb; ++i)
445 testmgr_free_buf(data[i].xbuf);
447 crypto_free_aead(tfm);
454 static int test_aead_jiffies(struct aead_request *req, int enc,
457 unsigned long start, end;
461 for (start = jiffies, end = start + secs * HZ, bcount = 0;
462 time_before(jiffies, end); bcount++) {
464 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
466 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
472 printk("%d operations in %d seconds (%ld bytes)\n",
473 bcount, secs, (long)bcount * blen);
477 static int test_aead_cycles(struct aead_request *req, int enc, int blen)
479 unsigned long cycles = 0;
484 for (i = 0; i < 4; i++) {
486 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
488 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
494 /* The real thing. */
495 for (i = 0; i < 8; i++) {
498 start = get_cycles();
500 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
502 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
508 cycles += end - start;
513 printk("1 operation in %lu cycles (%d bytes)\n",
514 (cycles + 4) / 8, blen);
519 static void test_aead_speed(const char *algo, int enc, unsigned int secs,
520 struct aead_speed_template *template,
521 unsigned int tcount, u8 authsize,
522 unsigned int aad_size, u8 *keysize)
525 struct crypto_aead *tfm;
528 struct aead_request *req;
529 struct scatterlist *sg;
530 struct scatterlist *sgout;
534 char *xbuf[XBUFSIZE];
535 char *xoutbuf[XBUFSIZE];
536 char *axbuf[XBUFSIZE];
537 unsigned int *b_size;
539 struct crypto_wait wait;
541 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
545 if (aad_size >= PAGE_SIZE) {
546 pr_err("associate data length (%u) too big\n", aad_size);
555 if (testmgr_alloc_buf(xbuf))
557 if (testmgr_alloc_buf(axbuf))
559 if (testmgr_alloc_buf(xoutbuf))
562 sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL);
567 tfm = crypto_alloc_aead(algo, 0, 0);
570 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
575 crypto_init_wait(&wait);
576 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
577 get_driver_name(crypto_aead, tfm), e);
579 req = aead_request_alloc(tfm, GFP_KERNEL);
581 pr_err("alg: aead: Failed to allocate request for %s\n",
586 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
587 crypto_req_done, &wait);
594 memset(assoc, 0xff, aad_size);
596 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
597 pr_err("template (%u) too big for tvmem (%lu)\n",
599 TVMEMSIZE * PAGE_SIZE);
604 for (j = 0; j < tcount; j++) {
605 if (template[j].klen == *keysize) {
606 key = template[j].key;
610 ret = crypto_aead_setkey(tfm, key, *keysize);
611 ret = crypto_aead_setauthsize(tfm, authsize);
613 iv_len = crypto_aead_ivsize(tfm);
615 memset(iv, 0xff, iv_len);
617 crypto_aead_clear_flags(tfm, ~0);
618 printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
619 i, *keysize * 8, *b_size);
622 memset(tvmem[0], 0xff, PAGE_SIZE);
625 pr_err("setkey() failed flags=%x\n",
626 crypto_aead_get_flags(tfm));
630 sg_init_aead(sg, xbuf, *b_size + (enc ? 0 : authsize),
633 sg_init_aead(sgout, xoutbuf,
634 *b_size + (enc ? authsize : 0), assoc,
637 aead_request_set_ad(req, aad_size);
642 * For decryption we need a proper auth so
643 * we do the encryption path once with buffers
644 * reversed (input <-> output) to calculate it
646 aead_request_set_crypt(req, sgout, sg,
648 ret = do_one_aead_op(req,
649 crypto_aead_encrypt(req));
652 pr_err("calculating auth failed (%d)\n",
658 aead_request_set_crypt(req, sg, sgout,
659 *b_size + (enc ? 0 : authsize),
663 ret = test_aead_jiffies(req, enc, *b_size,
667 ret = test_aead_cycles(req, enc, *b_size);
671 pr_err("%s() failed return code=%d\n", e, ret);
681 aead_request_free(req);
683 crypto_free_aead(tfm);
687 testmgr_free_buf(xoutbuf);
689 testmgr_free_buf(axbuf);
691 testmgr_free_buf(xbuf);
696 static void test_hash_sg_init(struct scatterlist *sg)
700 sg_init_table(sg, TVMEMSIZE);
701 for (i = 0; i < TVMEMSIZE; i++) {
702 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
703 memset(tvmem[i], 0xff, PAGE_SIZE);
707 static inline int do_one_ahash_op(struct ahash_request *req, int ret)
709 struct crypto_wait *wait = req->base.data;
711 return crypto_wait_req(ret, wait);
714 struct test_mb_ahash_data {
715 struct scatterlist sg[XBUFSIZE];
717 struct ahash_request *req;
718 struct crypto_wait wait;
719 char *xbuf[XBUFSIZE];
722 static inline int do_mult_ahash_op(struct test_mb_ahash_data *data, u32 num_mb,
727 /* Fire up a bunch of concurrent requests */
728 for (i = 0; i < num_mb; i++)
729 rc[i] = crypto_ahash_digest(data[i].req);
731 /* Wait for all requests to finish */
732 for (i = 0; i < num_mb; i++) {
733 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
736 pr_info("concurrent request %d error %d\n", i, rc[i]);
744 static int test_mb_ahash_jiffies(struct test_mb_ahash_data *data, int blen,
745 int secs, u32 num_mb)
747 unsigned long start, end;
752 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
756 for (start = jiffies, end = start + secs * HZ, bcount = 0;
757 time_before(jiffies, end); bcount++) {
758 ret = do_mult_ahash_op(data, num_mb, rc);
763 pr_cont("%d operations in %d seconds (%ld bytes)\n",
764 bcount * num_mb, secs, (long)bcount * blen * num_mb);
771 static int test_mb_ahash_cycles(struct test_mb_ahash_data *data, int blen,
774 unsigned long cycles = 0;
779 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
784 for (i = 0; i < 4; i++) {
785 ret = do_mult_ahash_op(data, num_mb, rc);
790 /* The real thing. */
791 for (i = 0; i < 8; i++) {
794 start = get_cycles();
795 ret = do_mult_ahash_op(data, num_mb, rc);
801 cycles += end - start;
804 pr_cont("1 operation in %lu cycles (%d bytes)\n",
805 (cycles + 4) / (8 * num_mb), blen);
812 static void test_mb_ahash_speed(const char *algo, unsigned int secs,
813 struct hash_speed *speed, u32 num_mb)
815 struct test_mb_ahash_data *data;
816 struct crypto_ahash *tfm;
817 unsigned int i, j, k;
820 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
824 tfm = crypto_alloc_ahash(algo, 0, 0);
826 pr_err("failed to load transform for %s: %ld\n",
831 for (i = 0; i < num_mb; ++i) {
832 if (testmgr_alloc_buf(data[i].xbuf))
835 crypto_init_wait(&data[i].wait);
837 data[i].req = ahash_request_alloc(tfm, GFP_KERNEL);
839 pr_err("alg: hash: Failed to allocate request for %s\n",
844 ahash_request_set_callback(data[i].req, 0, crypto_req_done,
847 sg_init_table(data[i].sg, XBUFSIZE);
848 for (j = 0; j < XBUFSIZE; j++) {
849 sg_set_buf(data[i].sg + j, data[i].xbuf[j], PAGE_SIZE);
850 memset(data[i].xbuf[j], 0xff, PAGE_SIZE);
854 pr_info("\ntesting speed of multibuffer %s (%s)\n", algo,
855 get_driver_name(crypto_ahash, tfm));
857 for (i = 0; speed[i].blen != 0; i++) {
858 /* For some reason this only tests digests. */
859 if (speed[i].blen != speed[i].plen)
862 if (speed[i].blen > XBUFSIZE * PAGE_SIZE) {
863 pr_err("template (%u) too big for tvmem (%lu)\n",
864 speed[i].blen, XBUFSIZE * PAGE_SIZE);
869 crypto_ahash_setkey(tfm, tvmem[0], klen);
871 for (k = 0; k < num_mb; k++)
872 ahash_request_set_crypt(data[k].req, data[k].sg,
873 data[k].result, speed[i].blen);
876 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
877 i, speed[i].blen, speed[i].plen,
878 speed[i].blen / speed[i].plen);
881 ret = test_mb_ahash_jiffies(data, speed[i].blen, secs,
885 ret = test_mb_ahash_cycles(data, speed[i].blen, num_mb);
890 pr_err("At least one hashing failed ret=%d\n", ret);
896 for (k = 0; k < num_mb; ++k)
897 ahash_request_free(data[k].req);
899 for (k = 0; k < num_mb; ++k)
900 testmgr_free_buf(data[k].xbuf);
902 crypto_free_ahash(tfm);
908 static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
911 unsigned long start, end;
915 for (start = jiffies, end = start + secs * HZ, bcount = 0;
916 time_before(jiffies, end); bcount++) {
917 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
922 printk("%6u opers/sec, %9lu bytes/sec\n",
923 bcount / secs, ((long)bcount * blen) / secs);
928 static int test_ahash_jiffies(struct ahash_request *req, int blen,
929 int plen, char *out, int secs)
931 unsigned long start, end;
936 return test_ahash_jiffies_digest(req, blen, out, secs);
938 for (start = jiffies, end = start + secs * HZ, bcount = 0;
939 time_before(jiffies, end); bcount++) {
940 ret = do_one_ahash_op(req, crypto_ahash_init(req));
943 for (pcount = 0; pcount < blen; pcount += plen) {
944 ret = do_one_ahash_op(req, crypto_ahash_update(req));
948 /* we assume there is enough space in 'out' for the result */
949 ret = do_one_ahash_op(req, crypto_ahash_final(req));
954 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
955 bcount / secs, ((long)bcount * blen) / secs);
960 static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
963 unsigned long cycles = 0;
967 for (i = 0; i < 4; i++) {
968 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
973 /* The real thing. */
974 for (i = 0; i < 8; i++) {
977 start = get_cycles();
979 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
985 cycles += end - start;
992 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
993 cycles / 8, cycles / (8 * blen));
998 static int test_ahash_cycles(struct ahash_request *req, int blen,
1001 unsigned long cycles = 0;
1005 return test_ahash_cycles_digest(req, blen, out);
1008 for (i = 0; i < 4; i++) {
1009 ret = do_one_ahash_op(req, crypto_ahash_init(req));
1012 for (pcount = 0; pcount < blen; pcount += plen) {
1013 ret = do_one_ahash_op(req, crypto_ahash_update(req));
1017 ret = do_one_ahash_op(req, crypto_ahash_final(req));
1022 /* The real thing. */
1023 for (i = 0; i < 8; i++) {
1024 cycles_t start, end;
1026 start = get_cycles();
1028 ret = do_one_ahash_op(req, crypto_ahash_init(req));
1031 for (pcount = 0; pcount < blen; pcount += plen) {
1032 ret = do_one_ahash_op(req, crypto_ahash_update(req));
1036 ret = do_one_ahash_op(req, crypto_ahash_final(req));
1042 cycles += end - start;
1049 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
1050 cycles / 8, cycles / (8 * blen));
1055 static void test_ahash_speed_common(const char *algo, unsigned int secs,
1056 struct hash_speed *speed, unsigned mask)
1058 struct scatterlist sg[TVMEMSIZE];
1059 struct crypto_wait wait;
1060 struct ahash_request *req;
1061 struct crypto_ahash *tfm;
1065 tfm = crypto_alloc_ahash(algo, 0, mask);
1067 pr_err("failed to load transform for %s: %ld\n",
1068 algo, PTR_ERR(tfm));
1072 printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
1073 get_driver_name(crypto_ahash, tfm));
1075 if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) {
1076 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm),
1081 test_hash_sg_init(sg);
1082 req = ahash_request_alloc(tfm, GFP_KERNEL);
1084 pr_err("ahash request allocation failure\n");
1088 crypto_init_wait(&wait);
1089 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1090 crypto_req_done, &wait);
1092 output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
1096 for (i = 0; speed[i].blen != 0; i++) {
1097 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
1098 pr_err("template (%u) too big for tvmem (%lu)\n",
1099 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
1104 crypto_ahash_setkey(tfm, tvmem[0], klen);
1107 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
1108 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
1110 ahash_request_set_crypt(req, sg, output, speed[i].plen);
1113 ret = test_ahash_jiffies(req, speed[i].blen,
1114 speed[i].plen, output, secs);
1117 ret = test_ahash_cycles(req, speed[i].blen,
1118 speed[i].plen, output);
1122 pr_err("hashing failed ret=%d\n", ret);
1130 ahash_request_free(req);
1133 crypto_free_ahash(tfm);
1136 static void test_ahash_speed(const char *algo, unsigned int secs,
1137 struct hash_speed *speed)
1139 return test_ahash_speed_common(algo, secs, speed, 0);
1142 static void test_hash_speed(const char *algo, unsigned int secs,
1143 struct hash_speed *speed)
1145 return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC);
1148 struct test_mb_skcipher_data {
1149 struct scatterlist sg[XBUFSIZE];
1150 struct skcipher_request *req;
1151 struct crypto_wait wait;
1152 char *xbuf[XBUFSIZE];
1155 static int do_mult_acipher_op(struct test_mb_skcipher_data *data, int enc,
1156 u32 num_mb, int *rc)
1160 /* Fire up a bunch of concurrent requests */
1161 for (i = 0; i < num_mb; i++) {
1163 rc[i] = crypto_skcipher_encrypt(data[i].req);
1165 rc[i] = crypto_skcipher_decrypt(data[i].req);
1168 /* Wait for all requests to finish */
1169 for (i = 0; i < num_mb; i++) {
1170 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
1173 pr_info("concurrent request %d error %d\n", i, rc[i]);
1181 static int test_mb_acipher_jiffies(struct test_mb_skcipher_data *data, int enc,
1182 int blen, int secs, u32 num_mb)
1184 unsigned long start, end;
1189 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
1193 for (start = jiffies, end = start + secs * HZ, bcount = 0;
1194 time_before(jiffies, end); bcount++) {
1195 ret = do_mult_acipher_op(data, enc, num_mb, rc);
1200 pr_cont("%d operations in %d seconds (%ld bytes)\n",
1201 bcount * num_mb, secs, (long)bcount * blen * num_mb);
1208 static int test_mb_acipher_cycles(struct test_mb_skcipher_data *data, int enc,
1209 int blen, u32 num_mb)
1211 unsigned long cycles = 0;
1216 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
1221 for (i = 0; i < 4; i++) {
1222 ret = do_mult_acipher_op(data, enc, num_mb, rc);
1227 /* The real thing. */
1228 for (i = 0; i < 8; i++) {
1229 cycles_t start, end;
1231 start = get_cycles();
1232 ret = do_mult_acipher_op(data, enc, num_mb, rc);
1238 cycles += end - start;
1241 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1242 (cycles + 4) / (8 * num_mb), blen);
1249 static void test_mb_skcipher_speed(const char *algo, int enc, int secs,
1250 struct cipher_speed_template *template,
1251 unsigned int tcount, u8 *keysize, u32 num_mb)
1253 struct test_mb_skcipher_data *data;
1254 struct crypto_skcipher *tfm;
1255 unsigned int i, j, iv_len;
1267 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
1271 tfm = crypto_alloc_skcipher(algo, 0, 0);
1273 pr_err("failed to load transform for %s: %ld\n",
1274 algo, PTR_ERR(tfm));
1278 for (i = 0; i < num_mb; ++i)
1279 if (testmgr_alloc_buf(data[i].xbuf)) {
1281 testmgr_free_buf(data[i].xbuf);
1286 for (i = 0; i < num_mb; ++i)
1287 if (testmgr_alloc_buf(data[i].xbuf)) {
1289 testmgr_free_buf(data[i].xbuf);
1294 for (i = 0; i < num_mb; ++i) {
1295 data[i].req = skcipher_request_alloc(tfm, GFP_KERNEL);
1297 pr_err("alg: skcipher: Failed to allocate request for %s\n",
1300 skcipher_request_free(data[i].req);
1305 for (i = 0; i < num_mb; ++i) {
1306 skcipher_request_set_callback(data[i].req,
1307 CRYPTO_TFM_REQ_MAY_BACKLOG,
1308 crypto_req_done, &data[i].wait);
1309 crypto_init_wait(&data[i].wait);
1312 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo,
1313 get_driver_name(crypto_skcipher, tfm), e);
1317 b_size = block_sizes;
1319 if (*b_size > XBUFSIZE * PAGE_SIZE) {
1320 pr_err("template (%u) too big for buffer (%lu)\n",
1321 *b_size, XBUFSIZE * PAGE_SIZE);
1325 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1326 *keysize * 8, *b_size);
1328 /* Set up tfm global state, i.e. the key */
1330 memset(tvmem[0], 0xff, PAGE_SIZE);
1332 for (j = 0; j < tcount; j++) {
1333 if (template[j].klen == *keysize) {
1334 key = template[j].key;
1339 crypto_skcipher_clear_flags(tfm, ~0);
1341 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1343 pr_err("setkey() failed flags=%x\n",
1344 crypto_skcipher_get_flags(tfm));
1348 iv_len = crypto_skcipher_ivsize(tfm);
1350 memset(&iv, 0xff, iv_len);
1352 /* Now setup per request stuff, i.e. buffers */
1354 for (j = 0; j < num_mb; ++j) {
1355 struct test_mb_skcipher_data *cur = &data[j];
1356 unsigned int k = *b_size;
1357 unsigned int pages = DIV_ROUND_UP(k, PAGE_SIZE);
1360 sg_init_table(cur->sg, pages);
1362 while (k > PAGE_SIZE) {
1363 sg_set_buf(cur->sg + p, cur->xbuf[p],
1365 memset(cur->xbuf[p], 0xff, PAGE_SIZE);
1370 sg_set_buf(cur->sg + p, cur->xbuf[p], k);
1371 memset(cur->xbuf[p], 0xff, k);
1373 skcipher_request_set_crypt(cur->req, cur->sg,
1379 ret = test_mb_acipher_jiffies(data, enc,
1384 ret = test_mb_acipher_cycles(data, enc,
1389 pr_err("%s() failed flags=%x\n", e,
1390 crypto_skcipher_get_flags(tfm));
1400 for (i = 0; i < num_mb; ++i)
1401 skcipher_request_free(data[i].req);
1403 for (i = 0; i < num_mb; ++i)
1404 testmgr_free_buf(data[i].xbuf);
1406 crypto_free_skcipher(tfm);
1411 static inline int do_one_acipher_op(struct skcipher_request *req, int ret)
1413 struct crypto_wait *wait = req->base.data;
1415 return crypto_wait_req(ret, wait);
1418 static int test_acipher_jiffies(struct skcipher_request *req, int enc,
1421 unsigned long start, end;
1425 for (start = jiffies, end = start + secs * HZ, bcount = 0;
1426 time_before(jiffies, end); bcount++) {
1428 ret = do_one_acipher_op(req,
1429 crypto_skcipher_encrypt(req));
1431 ret = do_one_acipher_op(req,
1432 crypto_skcipher_decrypt(req));
1438 pr_cont("%d operations in %d seconds (%ld bytes)\n",
1439 bcount, secs, (long)bcount * blen);
1443 static int test_acipher_cycles(struct skcipher_request *req, int enc,
1446 unsigned long cycles = 0;
1451 for (i = 0; i < 4; i++) {
1453 ret = do_one_acipher_op(req,
1454 crypto_skcipher_encrypt(req));
1456 ret = do_one_acipher_op(req,
1457 crypto_skcipher_decrypt(req));
1463 /* The real thing. */
1464 for (i = 0; i < 8; i++) {
1465 cycles_t start, end;
1467 start = get_cycles();
1469 ret = do_one_acipher_op(req,
1470 crypto_skcipher_encrypt(req));
1472 ret = do_one_acipher_op(req,
1473 crypto_skcipher_decrypt(req));
1479 cycles += end - start;
1484 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1485 (cycles + 4) / 8, blen);
1490 static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
1491 struct cipher_speed_template *template,
1492 unsigned int tcount, u8 *keysize, bool async)
1494 unsigned int ret, i, j, k, iv_len;
1495 struct crypto_wait wait;
1498 struct skcipher_request *req;
1499 struct crypto_skcipher *tfm;
1508 crypto_init_wait(&wait);
1510 tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC);
1513 pr_err("failed to load transform for %s: %ld\n", algo,
1518 pr_info("\ntesting speed of %s %s (%s) %s\n", async ? "async" : "sync",
1519 algo, get_driver_name(crypto_skcipher, tfm), e);
1521 req = skcipher_request_alloc(tfm, GFP_KERNEL);
1523 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1528 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1529 crypto_req_done, &wait);
1533 b_size = block_sizes;
1536 struct scatterlist sg[TVMEMSIZE];
1538 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
1539 pr_err("template (%u) too big for "
1540 "tvmem (%lu)\n", *keysize + *b_size,
1541 TVMEMSIZE * PAGE_SIZE);
1545 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1546 *keysize * 8, *b_size);
1548 memset(tvmem[0], 0xff, PAGE_SIZE);
1550 /* set key, plain text and IV */
1552 for (j = 0; j < tcount; j++) {
1553 if (template[j].klen == *keysize) {
1554 key = template[j].key;
1559 crypto_skcipher_clear_flags(tfm, ~0);
1561 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1563 pr_err("setkey() failed flags=%x\n",
1564 crypto_skcipher_get_flags(tfm));
1568 k = *keysize + *b_size;
1569 sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
1571 if (k > PAGE_SIZE) {
1572 sg_set_buf(sg, tvmem[0] + *keysize,
1573 PAGE_SIZE - *keysize);
1576 while (k > PAGE_SIZE) {
1577 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
1578 memset(tvmem[j], 0xff, PAGE_SIZE);
1582 sg_set_buf(sg + j, tvmem[j], k);
1583 memset(tvmem[j], 0xff, k);
1585 sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
1588 iv_len = crypto_skcipher_ivsize(tfm);
1590 memset(&iv, 0xff, iv_len);
1592 skcipher_request_set_crypt(req, sg, sg, *b_size, iv);
1595 ret = test_acipher_jiffies(req, enc,
1599 ret = test_acipher_cycles(req, enc,
1604 pr_err("%s() failed flags=%x\n", e,
1605 crypto_skcipher_get_flags(tfm));
1615 skcipher_request_free(req);
1617 crypto_free_skcipher(tfm);
1620 static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
1621 struct cipher_speed_template *template,
1622 unsigned int tcount, u8 *keysize)
1624 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1628 static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
1629 struct cipher_speed_template *template,
1630 unsigned int tcount, u8 *keysize)
1632 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1636 static void test_available(void)
1638 const char **name = check;
1641 printk("alg %s ", *name);
1642 printk(crypto_has_alg(*name, 0, 0) ?
1643 "found\n" : "not found\n");
1648 static inline int tcrypt_test(const char *alg)
1652 pr_debug("testing %s\n", alg);
1654 ret = alg_test(alg, alg, 0, 0);
1655 /* non-fips algs return -EINVAL in fips mode */
1656 if (fips_enabled && ret == -EINVAL)
1661 static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)
1669 if (!crypto_has_alg(alg, type,
1670 mask ?: CRYPTO_ALG_TYPE_MASK))
1675 for (i = 1; i < 200; i++)
1676 ret += do_test(NULL, 0, 0, i, num_mb);
1680 ret += tcrypt_test("md5");
1684 ret += tcrypt_test("sha1");
1688 ret += tcrypt_test("ecb(des)");
1689 ret += tcrypt_test("cbc(des)");
1690 ret += tcrypt_test("ctr(des)");
1694 ret += tcrypt_test("ecb(des3_ede)");
1695 ret += tcrypt_test("cbc(des3_ede)");
1696 ret += tcrypt_test("ctr(des3_ede)");
1700 ret += tcrypt_test("md4");
1704 ret += tcrypt_test("sha256");
1708 ret += tcrypt_test("ecb(blowfish)");
1709 ret += tcrypt_test("cbc(blowfish)");
1710 ret += tcrypt_test("ctr(blowfish)");
1714 ret += tcrypt_test("ecb(twofish)");
1715 ret += tcrypt_test("cbc(twofish)");
1716 ret += tcrypt_test("ctr(twofish)");
1717 ret += tcrypt_test("lrw(twofish)");
1718 ret += tcrypt_test("xts(twofish)");
1722 ret += tcrypt_test("ecb(serpent)");
1723 ret += tcrypt_test("cbc(serpent)");
1724 ret += tcrypt_test("ctr(serpent)");
1725 ret += tcrypt_test("lrw(serpent)");
1726 ret += tcrypt_test("xts(serpent)");
1730 ret += tcrypt_test("ecb(aes)");
1731 ret += tcrypt_test("cbc(aes)");
1732 ret += tcrypt_test("lrw(aes)");
1733 ret += tcrypt_test("xts(aes)");
1734 ret += tcrypt_test("ctr(aes)");
1735 ret += tcrypt_test("rfc3686(ctr(aes))");
1736 ret += tcrypt_test("ofb(aes)");
1737 ret += tcrypt_test("cfb(aes)");
1741 ret += tcrypt_test("sha384");
1745 ret += tcrypt_test("sha512");
1749 ret += tcrypt_test("deflate");
1753 ret += tcrypt_test("ecb(cast5)");
1754 ret += tcrypt_test("cbc(cast5)");
1755 ret += tcrypt_test("ctr(cast5)");
1759 ret += tcrypt_test("ecb(cast6)");
1760 ret += tcrypt_test("cbc(cast6)");
1761 ret += tcrypt_test("ctr(cast6)");
1762 ret += tcrypt_test("lrw(cast6)");
1763 ret += tcrypt_test("xts(cast6)");
1767 ret += tcrypt_test("ecb(arc4)");
1771 ret += tcrypt_test("michael_mic");
1775 ret += tcrypt_test("crc32c");
1779 ret += tcrypt_test("ecb(tea)");
1783 ret += tcrypt_test("ecb(xtea)");
1787 ret += tcrypt_test("ecb(khazad)");
1791 ret += tcrypt_test("wp512");
1795 ret += tcrypt_test("wp384");
1799 ret += tcrypt_test("wp256");
1803 ret += tcrypt_test("ecb(tnepres)");
1807 ret += tcrypt_test("ecb(anubis)");
1808 ret += tcrypt_test("cbc(anubis)");
1812 ret += tcrypt_test("tgr192");
1816 ret += tcrypt_test("tgr160");
1820 ret += tcrypt_test("tgr128");
1824 ret += tcrypt_test("ecb(xeta)");
1828 ret += tcrypt_test("pcbc(fcrypt)");
1832 ret += tcrypt_test("ecb(camellia)");
1833 ret += tcrypt_test("cbc(camellia)");
1834 ret += tcrypt_test("ctr(camellia)");
1835 ret += tcrypt_test("lrw(camellia)");
1836 ret += tcrypt_test("xts(camellia)");
1840 ret += tcrypt_test("sha224");
1844 ret += tcrypt_test("salsa20");
1848 ret += tcrypt_test("gcm(aes)");
1852 ret += tcrypt_test("lzo");
1856 ret += tcrypt_test("ccm(aes)");
1860 ret += tcrypt_test("cts(cbc(aes))");
1864 ret += tcrypt_test("rmd128");
1868 ret += tcrypt_test("rmd160");
1872 ret += tcrypt_test("rmd256");
1876 ret += tcrypt_test("rmd320");
1880 ret += tcrypt_test("ecb(seed)");
1884 ret += tcrypt_test("rfc4309(ccm(aes))");
1888 ret += tcrypt_test("ghash");
1892 ret += tcrypt_test("crct10dif");
1896 ret += tcrypt_test("sha3-224");
1900 ret += tcrypt_test("sha3-256");
1904 ret += tcrypt_test("sha3-384");
1908 ret += tcrypt_test("sha3-512");
1912 ret += tcrypt_test("sm3");
1916 ret += tcrypt_test("streebog256");
1920 ret += tcrypt_test("streebog512");
1924 ret += tcrypt_test("hmac(md5)");
1928 ret += tcrypt_test("hmac(sha1)");
1932 ret += tcrypt_test("hmac(sha256)");
1936 ret += tcrypt_test("hmac(sha384)");
1940 ret += tcrypt_test("hmac(sha512)");
1944 ret += tcrypt_test("hmac(sha224)");
1948 ret += tcrypt_test("xcbc(aes)");
1952 ret += tcrypt_test("hmac(rmd128)");
1956 ret += tcrypt_test("hmac(rmd160)");
1960 ret += tcrypt_test("vmac64(aes)");
1964 ret += tcrypt_test("hmac(sha3-224)");
1968 ret += tcrypt_test("hmac(sha3-256)");
1972 ret += tcrypt_test("hmac(sha3-384)");
1976 ret += tcrypt_test("hmac(sha3-512)");
1980 ret += tcrypt_test("hmac(streebog256)");
1984 ret += tcrypt_test("hmac(streebog512)");
1988 ret += tcrypt_test("ansi_cprng");
1992 ret += tcrypt_test("rfc4106(gcm(aes))");
1996 ret += tcrypt_test("rfc4543(gcm(aes))");
2000 ret += tcrypt_test("cmac(aes)");
2004 ret += tcrypt_test("cmac(des3_ede)");
2008 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
2012 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
2016 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
2019 ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
2022 ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
2025 ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
2028 ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
2031 ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
2034 ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
2037 ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
2040 ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
2043 ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
2046 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
2049 ret += tcrypt_test("ecb(sm4)");
2050 ret += tcrypt_test("cbc(sm4)");
2051 ret += tcrypt_test("ctr(sm4)");
2054 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2055 speed_template_16_24_32);
2056 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2057 speed_template_16_24_32);
2058 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2059 speed_template_16_24_32);
2060 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2061 speed_template_16_24_32);
2062 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2063 speed_template_32_40_48);
2064 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2065 speed_template_32_40_48);
2066 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2067 speed_template_32_64);
2068 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2069 speed_template_32_64);
2070 test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2071 speed_template_16_24_32);
2072 test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2073 speed_template_16_24_32);
2074 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2075 speed_template_16_24_32);
2076 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2077 speed_template_16_24_32);
2078 test_cipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2079 speed_template_16_24_32);
2080 test_cipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2081 speed_template_16_24_32);
2085 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2086 des3_speed_template, DES3_SPEED_VECTORS,
2088 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
2089 des3_speed_template, DES3_SPEED_VECTORS,
2091 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2092 des3_speed_template, DES3_SPEED_VECTORS,
2094 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
2095 des3_speed_template, DES3_SPEED_VECTORS,
2097 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
2098 des3_speed_template, DES3_SPEED_VECTORS,
2100 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
2101 des3_speed_template, DES3_SPEED_VECTORS,
2106 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2107 speed_template_16_24_32);
2108 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2109 speed_template_16_24_32);
2110 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2111 speed_template_16_24_32);
2112 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2113 speed_template_16_24_32);
2114 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2115 speed_template_16_24_32);
2116 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2117 speed_template_16_24_32);
2118 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2119 speed_template_32_40_48);
2120 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2121 speed_template_32_40_48);
2122 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2123 speed_template_32_48_64);
2124 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2125 speed_template_32_48_64);
2129 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2130 speed_template_8_32);
2131 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2132 speed_template_8_32);
2133 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2134 speed_template_8_32);
2135 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2136 speed_template_8_32);
2137 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2138 speed_template_8_32);
2139 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2140 speed_template_8_32);
2144 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2146 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2148 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2150 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2155 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2156 speed_template_16_24_32);
2157 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2158 speed_template_16_24_32);
2159 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2160 speed_template_16_24_32);
2161 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2162 speed_template_16_24_32);
2163 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2164 speed_template_16_24_32);
2165 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2166 speed_template_16_24_32);
2167 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2168 speed_template_32_40_48);
2169 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2170 speed_template_32_40_48);
2171 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2172 speed_template_32_48_64);
2173 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2174 speed_template_32_48_64);
2178 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
2179 speed_template_16_32);
2183 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2184 speed_template_16_32);
2185 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2186 speed_template_16_32);
2187 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2188 speed_template_16_32);
2189 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2190 speed_template_16_32);
2191 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2192 speed_template_16_32);
2193 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2194 speed_template_16_32);
2195 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2196 speed_template_32_48);
2197 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2198 speed_template_32_48);
2199 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2200 speed_template_32_64);
2201 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2202 speed_template_32_64);
2206 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2211 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2212 speed_template_8_16);
2213 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2214 speed_template_8_16);
2215 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2216 speed_template_8_16);
2217 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2218 speed_template_8_16);
2219 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2220 speed_template_8_16);
2221 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2222 speed_template_8_16);
2226 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2227 speed_template_16_32);
2228 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2229 speed_template_16_32);
2230 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2231 speed_template_16_32);
2232 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2233 speed_template_16_32);
2234 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2235 speed_template_16_32);
2236 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2237 speed_template_16_32);
2238 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2239 speed_template_32_48);
2240 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2241 speed_template_32_48);
2242 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2243 speed_template_32_64);
2244 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2245 speed_template_32_64);
2249 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
2250 NULL, 0, 16, 16, aead_speed_template_20);
2251 test_aead_speed("gcm(aes)", ENCRYPT, sec,
2252 NULL, 0, 16, 8, speed_template_16_24_32);
2253 test_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec,
2254 NULL, 0, 16, 16, aead_speed_template_20);
2255 test_aead_speed("gcm(aes)", DECRYPT, sec,
2256 NULL, 0, 16, 8, speed_template_16_24_32);
2260 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
2261 NULL, 0, 16, 16, aead_speed_template_19);
2262 test_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec,
2263 NULL, 0, 16, 16, aead_speed_template_19);
2267 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
2268 NULL, 0, 16, 8, aead_speed_template_36);
2269 test_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT, sec,
2270 NULL, 0, 16, 8, aead_speed_template_36);
2274 test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
2279 test_mb_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec, NULL,
2280 0, 16, 16, aead_speed_template_20, num_mb);
2281 test_mb_aead_speed("gcm(aes)", ENCRYPT, sec, NULL, 0, 16, 8,
2282 speed_template_16_24_32, num_mb);
2283 test_mb_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec, NULL,
2284 0, 16, 16, aead_speed_template_20, num_mb);
2285 test_mb_aead_speed("gcm(aes)", DECRYPT, sec, NULL, 0, 16, 8,
2286 speed_template_16_24_32, num_mb);
2290 test_mb_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec, NULL, 0,
2291 16, 16, aead_speed_template_19, num_mb);
2292 test_mb_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec, NULL, 0,
2293 16, 16, aead_speed_template_19, num_mb);
2297 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT,
2298 sec, NULL, 0, 16, 8, aead_speed_template_36,
2300 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT,
2301 sec, NULL, 0, 16, 8, aead_speed_template_36,
2306 test_cipher_speed("ecb(sm4)", ENCRYPT, sec, NULL, 0,
2308 test_cipher_speed("ecb(sm4)", DECRYPT, sec, NULL, 0,
2310 test_cipher_speed("cbc(sm4)", ENCRYPT, sec, NULL, 0,
2312 test_cipher_speed("cbc(sm4)", DECRYPT, sec, NULL, 0,
2314 test_cipher_speed("ctr(sm4)", ENCRYPT, sec, NULL, 0,
2316 test_cipher_speed("ctr(sm4)", DECRYPT, sec, NULL, 0,
2321 test_cipher_speed("adiantum(xchacha12,aes)", ENCRYPT, sec, NULL,
2322 0, speed_template_32);
2323 test_cipher_speed("adiantum(xchacha12,aes)", DECRYPT, sec, NULL,
2324 0, speed_template_32);
2325 test_cipher_speed("adiantum(xchacha20,aes)", ENCRYPT, sec, NULL,
2326 0, speed_template_32);
2327 test_cipher_speed("adiantum(xchacha20,aes)", DECRYPT, sec, NULL,
2328 0, speed_template_32);
2332 test_acipher_speed("essiv(cbc(aes),sha256)",
2333 ENCRYPT, sec, NULL, 0,
2334 speed_template_16_24_32);
2335 test_acipher_speed("essiv(cbc(aes),sha256)",
2336 DECRYPT, sec, NULL, 0,
2337 speed_template_16_24_32);
2341 test_aead_speed("aegis128", ENCRYPT, sec,
2342 NULL, 0, 16, 8, speed_template_16);
2343 test_aead_speed("aegis128", DECRYPT, sec,
2344 NULL, 0, 16, 8, speed_template_16);
2349 test_hash_speed(alg, sec, generic_hash_speed_template);
2354 test_hash_speed("md4", sec, generic_hash_speed_template);
2355 if (mode > 300 && mode < 400) break;
2358 test_hash_speed("md5", sec, generic_hash_speed_template);
2359 if (mode > 300 && mode < 400) break;
2362 test_hash_speed("sha1", sec, generic_hash_speed_template);
2363 if (mode > 300 && mode < 400) break;
2366 test_hash_speed("sha256", sec, generic_hash_speed_template);
2367 if (mode > 300 && mode < 400) break;
2370 test_hash_speed("sha384", sec, generic_hash_speed_template);
2371 if (mode > 300 && mode < 400) break;
2374 test_hash_speed("sha512", sec, generic_hash_speed_template);
2375 if (mode > 300 && mode < 400) break;
2378 test_hash_speed("wp256", sec, generic_hash_speed_template);
2379 if (mode > 300 && mode < 400) break;
2382 test_hash_speed("wp384", sec, generic_hash_speed_template);
2383 if (mode > 300 && mode < 400) break;
2386 test_hash_speed("wp512", sec, generic_hash_speed_template);
2387 if (mode > 300 && mode < 400) break;
2390 test_hash_speed("tgr128", sec, generic_hash_speed_template);
2391 if (mode > 300 && mode < 400) break;
2394 test_hash_speed("tgr160", sec, generic_hash_speed_template);
2395 if (mode > 300 && mode < 400) break;
2398 test_hash_speed("tgr192", sec, generic_hash_speed_template);
2399 if (mode > 300 && mode < 400) break;
2402 test_hash_speed("sha224", sec, generic_hash_speed_template);
2403 if (mode > 300 && mode < 400) break;
2406 test_hash_speed("rmd128", sec, generic_hash_speed_template);
2407 if (mode > 300 && mode < 400) break;
2410 test_hash_speed("rmd160", sec, generic_hash_speed_template);
2411 if (mode > 300 && mode < 400) break;
2414 test_hash_speed("rmd256", sec, generic_hash_speed_template);
2415 if (mode > 300 && mode < 400) break;
2418 test_hash_speed("rmd320", sec, generic_hash_speed_template);
2419 if (mode > 300 && mode < 400) break;
2423 test_hash_speed("ghash", sec, generic_hash_speed_template);
2424 if (mode > 300 && mode < 400) break;
2427 test_hash_speed("crc32c", sec, generic_hash_speed_template);
2428 if (mode > 300 && mode < 400) break;
2431 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
2432 if (mode > 300 && mode < 400) break;
2435 test_hash_speed("poly1305", sec, poly1305_speed_template);
2436 if (mode > 300 && mode < 400) break;
2439 test_hash_speed("sha3-224", sec, generic_hash_speed_template);
2440 if (mode > 300 && mode < 400) break;
2443 test_hash_speed("sha3-256", sec, generic_hash_speed_template);
2444 if (mode > 300 && mode < 400) break;
2447 test_hash_speed("sha3-384", sec, generic_hash_speed_template);
2448 if (mode > 300 && mode < 400) break;
2451 test_hash_speed("sha3-512", sec, generic_hash_speed_template);
2452 if (mode > 300 && mode < 400) break;
2455 test_hash_speed("sm3", sec, generic_hash_speed_template);
2456 if (mode > 300 && mode < 400) break;
2459 test_hash_speed("streebog256", sec,
2460 generic_hash_speed_template);
2461 if (mode > 300 && mode < 400) break;
2464 test_hash_speed("streebog512", sec,
2465 generic_hash_speed_template);
2466 if (mode > 300 && mode < 400) break;
2473 test_ahash_speed(alg, sec, generic_hash_speed_template);
2478 test_ahash_speed("md4", sec, generic_hash_speed_template);
2479 if (mode > 400 && mode < 500) break;
2482 test_ahash_speed("md5", sec, generic_hash_speed_template);
2483 if (mode > 400 && mode < 500) break;
2486 test_ahash_speed("sha1", sec, generic_hash_speed_template);
2487 if (mode > 400 && mode < 500) break;
2490 test_ahash_speed("sha256", sec, generic_hash_speed_template);
2491 if (mode > 400 && mode < 500) break;
2494 test_ahash_speed("sha384", sec, generic_hash_speed_template);
2495 if (mode > 400 && mode < 500) break;
2498 test_ahash_speed("sha512", sec, generic_hash_speed_template);
2499 if (mode > 400 && mode < 500) break;
2502 test_ahash_speed("wp256", sec, generic_hash_speed_template);
2503 if (mode > 400 && mode < 500) break;
2506 test_ahash_speed("wp384", sec, generic_hash_speed_template);
2507 if (mode > 400 && mode < 500) break;
2510 test_ahash_speed("wp512", sec, generic_hash_speed_template);
2511 if (mode > 400 && mode < 500) break;
2514 test_ahash_speed("tgr128", sec, generic_hash_speed_template);
2515 if (mode > 400 && mode < 500) break;
2518 test_ahash_speed("tgr160", sec, generic_hash_speed_template);
2519 if (mode > 400 && mode < 500) break;
2522 test_ahash_speed("tgr192", sec, generic_hash_speed_template);
2523 if (mode > 400 && mode < 500) break;
2526 test_ahash_speed("sha224", sec, generic_hash_speed_template);
2527 if (mode > 400 && mode < 500) break;
2530 test_ahash_speed("rmd128", sec, generic_hash_speed_template);
2531 if (mode > 400 && mode < 500) break;
2534 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
2535 if (mode > 400 && mode < 500) break;
2538 test_ahash_speed("rmd256", sec, generic_hash_speed_template);
2539 if (mode > 400 && mode < 500) break;
2542 test_ahash_speed("rmd320", sec, generic_hash_speed_template);
2543 if (mode > 400 && mode < 500) break;
2546 test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
2547 if (mode > 400 && mode < 500) break;
2550 test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
2551 if (mode > 400 && mode < 500) break;
2554 test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
2555 if (mode > 400 && mode < 500) break;
2558 test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
2559 if (mode > 400 && mode < 500) break;
2562 test_mb_ahash_speed("sha1", sec, generic_hash_speed_template,
2564 if (mode > 400 && mode < 500) break;
2567 test_mb_ahash_speed("sha256", sec, generic_hash_speed_template,
2569 if (mode > 400 && mode < 500) break;
2572 test_mb_ahash_speed("sha512", sec, generic_hash_speed_template,
2574 if (mode > 400 && mode < 500) break;
2577 test_mb_ahash_speed("sm3", sec, generic_hash_speed_template,
2579 if (mode > 400 && mode < 500) break;
2582 test_mb_ahash_speed("streebog256", sec,
2583 generic_hash_speed_template, num_mb);
2584 if (mode > 400 && mode < 500) break;
2587 test_mb_ahash_speed("streebog512", sec,
2588 generic_hash_speed_template, num_mb);
2589 if (mode > 400 && mode < 500) break;
2595 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2596 speed_template_16_24_32);
2597 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2598 speed_template_16_24_32);
2599 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2600 speed_template_16_24_32);
2601 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2602 speed_template_16_24_32);
2603 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2604 speed_template_32_40_48);
2605 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2606 speed_template_32_40_48);
2607 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2608 speed_template_32_64);
2609 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2610 speed_template_32_64);
2611 test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2612 speed_template_16_24_32);
2613 test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2614 speed_template_16_24_32);
2615 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2616 speed_template_16_24_32);
2617 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2618 speed_template_16_24_32);
2619 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2620 speed_template_16_24_32);
2621 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2622 speed_template_16_24_32);
2623 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2624 speed_template_16_24_32);
2625 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2626 speed_template_16_24_32);
2627 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
2628 speed_template_20_28_36);
2629 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
2630 speed_template_20_28_36);
2634 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2635 des3_speed_template, DES3_SPEED_VECTORS,
2637 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
2638 des3_speed_template, DES3_SPEED_VECTORS,
2640 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2641 des3_speed_template, DES3_SPEED_VECTORS,
2643 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
2644 des3_speed_template, DES3_SPEED_VECTORS,
2646 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2647 des3_speed_template, DES3_SPEED_VECTORS,
2649 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
2650 des3_speed_template, DES3_SPEED_VECTORS,
2652 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2653 des3_speed_template, DES3_SPEED_VECTORS,
2655 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
2656 des3_speed_template, DES3_SPEED_VECTORS,
2661 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2663 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2665 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2667 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2669 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2671 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2673 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2675 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2680 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2681 speed_template_16_32);
2682 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2683 speed_template_16_32);
2684 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2685 speed_template_16_32);
2686 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2687 speed_template_16_32);
2688 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2689 speed_template_16_32);
2690 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2691 speed_template_16_32);
2692 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2693 speed_template_32_48);
2694 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2695 speed_template_32_48);
2696 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2697 speed_template_32_64);
2698 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2699 speed_template_32_64);
2703 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2704 speed_template_16_24_32);
2705 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2706 speed_template_16_24_32);
2707 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2708 speed_template_16_24_32);
2709 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2710 speed_template_16_24_32);
2711 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2712 speed_template_16_24_32);
2713 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2714 speed_template_16_24_32);
2715 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2716 speed_template_32_40_48);
2717 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2718 speed_template_32_40_48);
2719 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2720 speed_template_32_48_64);
2721 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2722 speed_template_32_48_64);
2726 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2731 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2732 speed_template_8_16);
2733 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2734 speed_template_8_16);
2735 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2736 speed_template_8_16);
2737 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2738 speed_template_8_16);
2739 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2740 speed_template_8_16);
2741 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2742 speed_template_8_16);
2746 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2747 speed_template_16_32);
2748 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2749 speed_template_16_32);
2750 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2751 speed_template_16_32);
2752 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2753 speed_template_16_32);
2754 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2755 speed_template_16_32);
2756 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2757 speed_template_16_32);
2758 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2759 speed_template_32_48);
2760 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2761 speed_template_32_48);
2762 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2763 speed_template_32_64);
2764 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2765 speed_template_32_64);
2769 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2770 speed_template_16_32);
2771 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2772 speed_template_16_32);
2773 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2774 speed_template_16_32);
2775 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2776 speed_template_16_32);
2777 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2778 speed_template_16_32);
2779 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2780 speed_template_16_32);
2781 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2782 speed_template_32_48);
2783 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2784 speed_template_32_48);
2785 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2786 speed_template_32_64);
2787 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2788 speed_template_32_64);
2792 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2793 speed_template_8_32);
2794 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2795 speed_template_8_32);
2796 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2797 speed_template_8_32);
2798 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2799 speed_template_8_32);
2800 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2801 speed_template_8_32);
2802 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2803 speed_template_8_32);
2807 test_mb_skcipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2808 speed_template_16_24_32, num_mb);
2809 test_mb_skcipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2810 speed_template_16_24_32, num_mb);
2811 test_mb_skcipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2812 speed_template_16_24_32, num_mb);
2813 test_mb_skcipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2814 speed_template_16_24_32, num_mb);
2815 test_mb_skcipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2816 speed_template_32_40_48, num_mb);
2817 test_mb_skcipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2818 speed_template_32_40_48, num_mb);
2819 test_mb_skcipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2820 speed_template_32_64, num_mb);
2821 test_mb_skcipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2822 speed_template_32_64, num_mb);
2823 test_mb_skcipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2824 speed_template_16_24_32, num_mb);
2825 test_mb_skcipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2826 speed_template_16_24_32, num_mb);
2827 test_mb_skcipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2828 speed_template_16_24_32, num_mb);
2829 test_mb_skcipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2830 speed_template_16_24_32, num_mb);
2831 test_mb_skcipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2832 speed_template_16_24_32, num_mb);
2833 test_mb_skcipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2834 speed_template_16_24_32, num_mb);
2835 test_mb_skcipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2836 speed_template_16_24_32, num_mb);
2837 test_mb_skcipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2838 speed_template_16_24_32, num_mb);
2839 test_mb_skcipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL,
2840 0, speed_template_20_28_36, num_mb);
2841 test_mb_skcipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL,
2842 0, speed_template_20_28_36, num_mb);
2846 test_mb_skcipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2847 des3_speed_template, DES3_SPEED_VECTORS,
2848 speed_template_24, num_mb);
2849 test_mb_skcipher_speed("ecb(des3_ede)", DECRYPT, sec,
2850 des3_speed_template, DES3_SPEED_VECTORS,
2851 speed_template_24, num_mb);
2852 test_mb_skcipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2853 des3_speed_template, DES3_SPEED_VECTORS,
2854 speed_template_24, num_mb);
2855 test_mb_skcipher_speed("cbc(des3_ede)", DECRYPT, sec,
2856 des3_speed_template, DES3_SPEED_VECTORS,
2857 speed_template_24, num_mb);
2858 test_mb_skcipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2859 des3_speed_template, DES3_SPEED_VECTORS,
2860 speed_template_24, num_mb);
2861 test_mb_skcipher_speed("cfb(des3_ede)", DECRYPT, sec,
2862 des3_speed_template, DES3_SPEED_VECTORS,
2863 speed_template_24, num_mb);
2864 test_mb_skcipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2865 des3_speed_template, DES3_SPEED_VECTORS,
2866 speed_template_24, num_mb);
2867 test_mb_skcipher_speed("ofb(des3_ede)", DECRYPT, sec,
2868 des3_speed_template, DES3_SPEED_VECTORS,
2869 speed_template_24, num_mb);
2873 test_mb_skcipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2874 speed_template_8, num_mb);
2875 test_mb_skcipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2876 speed_template_8, num_mb);
2877 test_mb_skcipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2878 speed_template_8, num_mb);
2879 test_mb_skcipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2880 speed_template_8, num_mb);
2881 test_mb_skcipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2882 speed_template_8, num_mb);
2883 test_mb_skcipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2884 speed_template_8, num_mb);
2885 test_mb_skcipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2886 speed_template_8, num_mb);
2887 test_mb_skcipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2888 speed_template_8, num_mb);
2892 test_mb_skcipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2893 speed_template_16_32, num_mb);
2894 test_mb_skcipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2895 speed_template_16_32, num_mb);
2896 test_mb_skcipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2897 speed_template_16_32, num_mb);
2898 test_mb_skcipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2899 speed_template_16_32, num_mb);
2900 test_mb_skcipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2901 speed_template_16_32, num_mb);
2902 test_mb_skcipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2903 speed_template_16_32, num_mb);
2904 test_mb_skcipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2905 speed_template_32_48, num_mb);
2906 test_mb_skcipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2907 speed_template_32_48, num_mb);
2908 test_mb_skcipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2909 speed_template_32_64, num_mb);
2910 test_mb_skcipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2911 speed_template_32_64, num_mb);
2915 test_mb_skcipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2916 speed_template_16_24_32, num_mb);
2917 test_mb_skcipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2918 speed_template_16_24_32, num_mb);
2919 test_mb_skcipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2920 speed_template_16_24_32, num_mb);
2921 test_mb_skcipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2922 speed_template_16_24_32, num_mb);
2923 test_mb_skcipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2924 speed_template_16_24_32, num_mb);
2925 test_mb_skcipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2926 speed_template_16_24_32, num_mb);
2927 test_mb_skcipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2928 speed_template_32_40_48, num_mb);
2929 test_mb_skcipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2930 speed_template_32_40_48, num_mb);
2931 test_mb_skcipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2932 speed_template_32_48_64, num_mb);
2933 test_mb_skcipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2934 speed_template_32_48_64, num_mb);
2938 test_mb_skcipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2939 speed_template_8, num_mb);
2943 test_mb_skcipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2944 speed_template_8_16, num_mb);
2945 test_mb_skcipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2946 speed_template_8_16, num_mb);
2947 test_mb_skcipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2948 speed_template_8_16, num_mb);
2949 test_mb_skcipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2950 speed_template_8_16, num_mb);
2951 test_mb_skcipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2952 speed_template_8_16, num_mb);
2953 test_mb_skcipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2954 speed_template_8_16, num_mb);
2958 test_mb_skcipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2959 speed_template_16_32, num_mb);
2960 test_mb_skcipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2961 speed_template_16_32, num_mb);
2962 test_mb_skcipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2963 speed_template_16_32, num_mb);
2964 test_mb_skcipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2965 speed_template_16_32, num_mb);
2966 test_mb_skcipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2967 speed_template_16_32, num_mb);
2968 test_mb_skcipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2969 speed_template_16_32, num_mb);
2970 test_mb_skcipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2971 speed_template_32_48, num_mb);
2972 test_mb_skcipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2973 speed_template_32_48, num_mb);
2974 test_mb_skcipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2975 speed_template_32_64, num_mb);
2976 test_mb_skcipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2977 speed_template_32_64, num_mb);
2981 test_mb_skcipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2982 speed_template_16_32, num_mb);
2983 test_mb_skcipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2984 speed_template_16_32, num_mb);
2985 test_mb_skcipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2986 speed_template_16_32, num_mb);
2987 test_mb_skcipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2988 speed_template_16_32, num_mb);
2989 test_mb_skcipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2990 speed_template_16_32, num_mb);
2991 test_mb_skcipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2992 speed_template_16_32, num_mb);
2993 test_mb_skcipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2994 speed_template_32_48, num_mb);
2995 test_mb_skcipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2996 speed_template_32_48, num_mb);
2997 test_mb_skcipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2998 speed_template_32_64, num_mb);
2999 test_mb_skcipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
3000 speed_template_32_64, num_mb);
3004 test_mb_skcipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
3005 speed_template_8_32, num_mb);
3006 test_mb_skcipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
3007 speed_template_8_32, num_mb);
3008 test_mb_skcipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
3009 speed_template_8_32, num_mb);
3010 test_mb_skcipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
3011 speed_template_8_32, num_mb);
3012 test_mb_skcipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
3013 speed_template_8_32, num_mb);
3014 test_mb_skcipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
3015 speed_template_8_32, num_mb);
3026 static int __init tcrypt_mod_init(void)
3031 for (i = 0; i < TVMEMSIZE; i++) {
3032 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
3037 err = do_test(alg, type, mask, mode, num_mb);
3040 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
3043 pr_debug("all tests passed\n");
3046 /* We intentionaly return -EAGAIN to prevent keeping the module,
3047 * unless we're running in fips mode. It does all its work from
3048 * init() and doesn't offer any runtime functionality, but in
3049 * the fips case, checking for a successful load is helpful.
3050 * => we don't need it in the memory, do we?
3057 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
3058 free_page((unsigned long)tvmem[i]);
3064 * If an init function is provided, an exit function must also be provided
3065 * to allow module unload.
3067 static void __exit tcrypt_mod_fini(void) { }
3069 subsys_initcall(tcrypt_mod_init);
3070 module_exit(tcrypt_mod_fini);
3072 module_param(alg, charp, 0);
3073 module_param(type, uint, 0);
3074 module_param(mask, uint, 0);
3075 module_param(mode, int, 0);
3076 module_param(sec, uint, 0);
3077 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
3078 "(defaults to zero which uses CPU cycles instead)");
3079 module_param(num_mb, uint, 0000);
3080 MODULE_PARM_DESC(num_mb, "Number of concurrent requests to be used in mb speed tests (defaults to 8)");
3081 module_param(klen, uint, 0);
3082 MODULE_PARM_DESC(klen, "Key length (defaults to 0)");
3084 MODULE_LICENSE("GPL");
3085 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
3086 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");