2 * Quick & dirty crypto testing module.
4 * This will only exist until we have a better testing mechanism
5 * (e.g. a char device).
7 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
8 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
9 * Copyright (c) 2007 Nokia Siemens Networks
11 * Updated RFC4106 AES-GCM testing.
12 * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
13 * Adrian Hoban <adrian.hoban@intel.com>
14 * Gabriele Paoloni <gabriele.paoloni@intel.com>
15 * Tadeusz Struk (tadeusz.struk@intel.com)
16 * Copyright (c) 2010, Intel Corporation.
18 * This program is free software; you can redistribute it and/or modify it
19 * under the terms of the GNU General Public License as published by the Free
20 * Software Foundation; either version 2 of the License, or (at your option)
25 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27 #include <crypto/aead.h>
28 #include <crypto/hash.h>
29 #include <crypto/skcipher.h>
30 #include <linux/err.h>
31 #include <linux/fips.h>
32 #include <linux/init.h>
33 #include <linux/gfp.h>
34 #include <linux/module.h>
35 #include <linux/scatterlist.h>
36 #include <linux/string.h>
37 #include <linux/moduleparam.h>
38 #include <linux/jiffies.h>
39 #include <linux/timex.h>
40 #include <linux/interrupt.h>
44 * Need slab memory for testing (size in number of pages).
49 * Used by test_cipher_speed()
54 #define MAX_DIGEST_SIZE 64
57 * return a string with the driver name
59 #define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm))
62 * Used by test_cipher_speed()
64 static unsigned int sec;
66 static char *alg = NULL;
70 static u32 num_mb = 8;
71 static char *tvmem[TVMEMSIZE];
73 static char *check[] = {
74 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", "sm3",
75 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
76 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
77 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
78 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
79 "lzo", "cts", "zlib", "sha3-224", "sha3-256", "sha3-384", "sha3-512",
83 static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
84 static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
89 static int testmgr_alloc_buf(char *buf[XBUFSIZE])
93 for (i = 0; i < XBUFSIZE; i++) {
94 buf[i] = (void *)__get_free_page(GFP_KERNEL);
103 free_page((unsigned long)buf[i]);
108 static void testmgr_free_buf(char *buf[XBUFSIZE])
112 for (i = 0; i < XBUFSIZE; i++)
113 free_page((unsigned long)buf[i]);
116 static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],
117 unsigned int buflen, const void *assoc,
118 unsigned int aad_size)
120 int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
127 rem = buflen % PAGE_SIZE;
130 sg_init_table(sg, np + 1);
132 sg_set_buf(&sg[0], assoc, aad_size);
136 for (k = 0; k < np; k++)
137 sg_set_buf(&sg[k + 1], xbuf[k], PAGE_SIZE);
140 sg_set_buf(&sg[k + 1], xbuf[k], rem);
143 static inline int do_one_aead_op(struct aead_request *req, int ret)
145 struct crypto_wait *wait = req->base.data;
147 return crypto_wait_req(ret, wait);
150 struct test_mb_aead_data {
151 struct scatterlist sg[XBUFSIZE];
152 struct scatterlist sgout[XBUFSIZE];
153 struct aead_request *req;
154 struct crypto_wait wait;
155 char *xbuf[XBUFSIZE];
156 char *xoutbuf[XBUFSIZE];
157 char *axbuf[XBUFSIZE];
160 static int do_mult_aead_op(struct test_mb_aead_data *data, int enc,
165 /* Fire up a bunch of concurrent requests */
166 for (i = 0; i < num_mb; i++) {
168 rc[i] = crypto_aead_encrypt(data[i].req);
170 rc[i] = crypto_aead_decrypt(data[i].req);
173 /* Wait for all requests to finish */
174 for (i = 0; i < num_mb; i++) {
175 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
178 pr_info("concurrent request %d error %d\n", i, rc[i]);
186 static int test_mb_aead_jiffies(struct test_mb_aead_data *data, int enc,
187 int blen, int secs, u32 num_mb)
189 unsigned long start, end;
194 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
198 for (start = jiffies, end = start + secs * HZ, bcount = 0;
199 time_before(jiffies, end); bcount++) {
200 ret = do_mult_aead_op(data, enc, num_mb, rc);
205 pr_cont("%d operations in %d seconds (%llu bytes)\n",
206 bcount * num_mb, secs, (u64)bcount * blen * num_mb);
213 static int test_mb_aead_cycles(struct test_mb_aead_data *data, int enc,
214 int blen, u32 num_mb)
216 unsigned long cycles = 0;
221 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
226 for (i = 0; i < 4; i++) {
227 ret = do_mult_aead_op(data, enc, num_mb, rc);
232 /* The real thing. */
233 for (i = 0; i < 8; i++) {
236 start = get_cycles();
237 ret = do_mult_aead_op(data, enc, num_mb, rc);
243 cycles += end - start;
246 pr_cont("1 operation in %lu cycles (%d bytes)\n",
247 (cycles + 4) / (8 * num_mb), blen);
254 static void test_mb_aead_speed(const char *algo, int enc, int secs,
255 struct aead_speed_template *template,
256 unsigned int tcount, u8 authsize,
257 unsigned int aad_size, u8 *keysize, u32 num_mb)
259 struct test_mb_aead_data *data;
260 struct crypto_aead *tfm;
261 unsigned int i, j, iv_len;
270 if (aad_size >= PAGE_SIZE) {
271 pr_err("associate data length (%u) too big\n", aad_size);
275 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
284 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
288 tfm = crypto_alloc_aead(algo, 0, 0);
290 pr_err("failed to load transform for %s: %ld\n",
295 ret = crypto_aead_setauthsize(tfm, authsize);
297 for (i = 0; i < num_mb; ++i)
298 if (testmgr_alloc_buf(data[i].xbuf)) {
300 testmgr_free_buf(data[i].xbuf);
304 for (i = 0; i < num_mb; ++i)
305 if (testmgr_alloc_buf(data[i].axbuf)) {
307 testmgr_free_buf(data[i].axbuf);
311 for (i = 0; i < num_mb; ++i)
312 if (testmgr_alloc_buf(data[i].xoutbuf)) {
314 testmgr_free_buf(data[i].xoutbuf);
318 for (i = 0; i < num_mb; ++i) {
319 data[i].req = aead_request_alloc(tfm, GFP_KERNEL);
321 pr_err("alg: skcipher: Failed to allocate request for %s\n",
324 aead_request_free(data[i].req);
325 goto out_free_xoutbuf;
329 for (i = 0; i < num_mb; ++i) {
330 crypto_init_wait(&data[i].wait);
331 aead_request_set_callback(data[i].req,
332 CRYPTO_TFM_REQ_MAY_BACKLOG,
333 crypto_req_done, &data[i].wait);
336 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo,
337 get_driver_name(crypto_aead, tfm), e);
343 if (*b_size + authsize > XBUFSIZE * PAGE_SIZE) {
344 pr_err("template (%u) too big for buffer (%lu)\n",
346 XBUFSIZE * PAGE_SIZE);
350 pr_info("test %u (%d bit key, %d byte blocks): ", i,
351 *keysize * 8, *b_size);
353 /* Set up tfm global state, i.e. the key */
355 memset(tvmem[0], 0xff, PAGE_SIZE);
357 for (j = 0; j < tcount; j++) {
358 if (template[j].klen == *keysize) {
359 key = template[j].key;
364 crypto_aead_clear_flags(tfm, ~0);
366 ret = crypto_aead_setkey(tfm, key, *keysize);
368 pr_err("setkey() failed flags=%x\n",
369 crypto_aead_get_flags(tfm));
373 iv_len = crypto_aead_ivsize(tfm);
375 memset(iv, 0xff, iv_len);
377 /* Now setup per request stuff, i.e. buffers */
379 for (j = 0; j < num_mb; ++j) {
380 struct test_mb_aead_data *cur = &data[j];
382 assoc = cur->axbuf[0];
383 memset(assoc, 0xff, aad_size);
385 sg_init_aead(cur->sg, cur->xbuf,
386 *b_size + (enc ? 0 : authsize),
389 sg_init_aead(cur->sgout, cur->xoutbuf,
390 *b_size + (enc ? authsize : 0),
393 aead_request_set_ad(cur->req, aad_size);
397 aead_request_set_crypt(cur->req,
401 ret = crypto_aead_encrypt(cur->req);
402 ret = do_one_aead_op(cur->req, ret);
405 pr_err("calculating auth failed failed (%d)\n",
411 aead_request_set_crypt(cur->req, cur->sg,
412 cur->sgout, *b_size +
413 (enc ? 0 : authsize),
419 ret = test_mb_aead_jiffies(data, enc, *b_size,
423 ret = test_mb_aead_cycles(data, enc, *b_size,
428 pr_err("%s() failed return code=%d\n", e, ret);
438 for (i = 0; i < num_mb; ++i)
439 aead_request_free(data[i].req);
441 for (i = 0; i < num_mb; ++i)
442 testmgr_free_buf(data[i].xoutbuf);
444 for (i = 0; i < num_mb; ++i)
445 testmgr_free_buf(data[i].axbuf);
447 for (i = 0; i < num_mb; ++i)
448 testmgr_free_buf(data[i].xbuf);
450 crypto_free_aead(tfm);
457 static int test_aead_jiffies(struct aead_request *req, int enc,
460 unsigned long start, end;
464 for (start = jiffies, end = start + secs * HZ, bcount = 0;
465 time_before(jiffies, end); bcount++) {
467 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
469 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
475 pr_cont("%d operations in %d seconds (%llu bytes)\n",
476 bcount, secs, (u64)bcount * blen);
480 static int test_aead_cycles(struct aead_request *req, int enc, int blen)
482 unsigned long cycles = 0;
487 for (i = 0; i < 4; i++) {
489 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
491 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
497 /* The real thing. */
498 for (i = 0; i < 8; i++) {
501 start = get_cycles();
503 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
505 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
511 cycles += end - start;
516 printk("1 operation in %lu cycles (%d bytes)\n",
517 (cycles + 4) / 8, blen);
522 static void test_aead_speed(const char *algo, int enc, unsigned int secs,
523 struct aead_speed_template *template,
524 unsigned int tcount, u8 authsize,
525 unsigned int aad_size, u8 *keysize)
528 struct crypto_aead *tfm;
531 struct aead_request *req;
532 struct scatterlist *sg;
533 struct scatterlist *sgout;
537 char *xbuf[XBUFSIZE];
538 char *xoutbuf[XBUFSIZE];
539 char *axbuf[XBUFSIZE];
540 unsigned int *b_size;
542 struct crypto_wait wait;
544 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
548 if (aad_size >= PAGE_SIZE) {
549 pr_err("associate data length (%u) too big\n", aad_size);
558 if (testmgr_alloc_buf(xbuf))
560 if (testmgr_alloc_buf(axbuf))
562 if (testmgr_alloc_buf(xoutbuf))
565 sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL);
570 tfm = crypto_alloc_aead(algo, 0, 0);
573 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
578 crypto_init_wait(&wait);
579 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
580 get_driver_name(crypto_aead, tfm), e);
582 req = aead_request_alloc(tfm, GFP_KERNEL);
584 pr_err("alg: aead: Failed to allocate request for %s\n",
589 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
590 crypto_req_done, &wait);
597 memset(assoc, 0xff, aad_size);
599 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
600 pr_err("template (%u) too big for tvmem (%lu)\n",
602 TVMEMSIZE * PAGE_SIZE);
607 for (j = 0; j < tcount; j++) {
608 if (template[j].klen == *keysize) {
609 key = template[j].key;
613 ret = crypto_aead_setkey(tfm, key, *keysize);
614 ret = crypto_aead_setauthsize(tfm, authsize);
616 iv_len = crypto_aead_ivsize(tfm);
618 memset(iv, 0xff, iv_len);
620 crypto_aead_clear_flags(tfm, ~0);
621 printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
622 i, *keysize * 8, *b_size);
625 memset(tvmem[0], 0xff, PAGE_SIZE);
628 pr_err("setkey() failed flags=%x\n",
629 crypto_aead_get_flags(tfm));
633 sg_init_aead(sg, xbuf, *b_size + (enc ? 0 : authsize),
636 sg_init_aead(sgout, xoutbuf,
637 *b_size + (enc ? authsize : 0), assoc,
640 aead_request_set_ad(req, aad_size);
645 * For decryption we need a proper auth so
646 * we do the encryption path once with buffers
647 * reversed (input <-> output) to calculate it
649 aead_request_set_crypt(req, sgout, sg,
651 ret = do_one_aead_op(req,
652 crypto_aead_encrypt(req));
655 pr_err("calculating auth failed failed (%d)\n",
661 aead_request_set_crypt(req, sg, sgout,
662 *b_size + (enc ? 0 : authsize),
666 ret = test_aead_jiffies(req, enc, *b_size,
670 ret = test_aead_cycles(req, enc, *b_size);
674 pr_err("%s() failed return code=%d\n", e, ret);
684 aead_request_free(req);
686 crypto_free_aead(tfm);
690 testmgr_free_buf(xoutbuf);
692 testmgr_free_buf(axbuf);
694 testmgr_free_buf(xbuf);
699 static void test_hash_sg_init(struct scatterlist *sg)
703 sg_init_table(sg, TVMEMSIZE);
704 for (i = 0; i < TVMEMSIZE; i++) {
705 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
706 memset(tvmem[i], 0xff, PAGE_SIZE);
710 static inline int do_one_ahash_op(struct ahash_request *req, int ret)
712 struct crypto_wait *wait = req->base.data;
714 return crypto_wait_req(ret, wait);
717 struct test_mb_ahash_data {
718 struct scatterlist sg[XBUFSIZE];
720 struct ahash_request *req;
721 struct crypto_wait wait;
722 char *xbuf[XBUFSIZE];
725 static inline int do_mult_ahash_op(struct test_mb_ahash_data *data, u32 num_mb,
730 /* Fire up a bunch of concurrent requests */
731 for (i = 0; i < num_mb; i++)
732 rc[i] = crypto_ahash_digest(data[i].req);
734 /* Wait for all requests to finish */
735 for (i = 0; i < num_mb; i++) {
736 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
739 pr_info("concurrent request %d error %d\n", i, rc[i]);
747 static int test_mb_ahash_jiffies(struct test_mb_ahash_data *data, int blen,
748 int secs, u32 num_mb)
750 unsigned long start, end;
755 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
759 for (start = jiffies, end = start + secs * HZ, bcount = 0;
760 time_before(jiffies, end); bcount++) {
761 ret = do_mult_ahash_op(data, num_mb, rc);
766 pr_cont("%d operations in %d seconds (%llu bytes)\n",
767 bcount * num_mb, secs, (u64)bcount * blen * num_mb);
774 static int test_mb_ahash_cycles(struct test_mb_ahash_data *data, int blen,
777 unsigned long cycles = 0;
782 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
787 for (i = 0; i < 4; i++) {
788 ret = do_mult_ahash_op(data, num_mb, rc);
793 /* The real thing. */
794 for (i = 0; i < 8; i++) {
797 start = get_cycles();
798 ret = do_mult_ahash_op(data, num_mb, rc);
804 cycles += end - start;
807 pr_cont("1 operation in %lu cycles (%d bytes)\n",
808 (cycles + 4) / (8 * num_mb), blen);
815 static void test_mb_ahash_speed(const char *algo, unsigned int secs,
816 struct hash_speed *speed, u32 num_mb)
818 struct test_mb_ahash_data *data;
819 struct crypto_ahash *tfm;
820 unsigned int i, j, k;
823 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
827 tfm = crypto_alloc_ahash(algo, 0, 0);
829 pr_err("failed to load transform for %s: %ld\n",
834 for (i = 0; i < num_mb; ++i) {
835 if (testmgr_alloc_buf(data[i].xbuf))
838 crypto_init_wait(&data[i].wait);
840 data[i].req = ahash_request_alloc(tfm, GFP_KERNEL);
842 pr_err("alg: hash: Failed to allocate request for %s\n",
847 ahash_request_set_callback(data[i].req, 0, crypto_req_done,
850 sg_init_table(data[i].sg, XBUFSIZE);
851 for (j = 0; j < XBUFSIZE; j++) {
852 sg_set_buf(data[i].sg + j, data[i].xbuf[j], PAGE_SIZE);
853 memset(data[i].xbuf[j], 0xff, PAGE_SIZE);
857 pr_info("\ntesting speed of multibuffer %s (%s)\n", algo,
858 get_driver_name(crypto_ahash, tfm));
860 for (i = 0; speed[i].blen != 0; i++) {
861 /* For some reason this only tests digests. */
862 if (speed[i].blen != speed[i].plen)
865 if (speed[i].blen > XBUFSIZE * PAGE_SIZE) {
866 pr_err("template (%u) too big for tvmem (%lu)\n",
867 speed[i].blen, XBUFSIZE * PAGE_SIZE);
872 crypto_ahash_setkey(tfm, tvmem[0], speed[i].klen);
874 for (k = 0; k < num_mb; k++)
875 ahash_request_set_crypt(data[k].req, data[k].sg,
876 data[k].result, speed[i].blen);
879 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
880 i, speed[i].blen, speed[i].plen,
881 speed[i].blen / speed[i].plen);
884 ret = test_mb_ahash_jiffies(data, speed[i].blen, secs,
888 ret = test_mb_ahash_cycles(data, speed[i].blen, num_mb);
893 pr_err("At least one hashing failed ret=%d\n", ret);
899 for (k = 0; k < num_mb; ++k)
900 ahash_request_free(data[k].req);
902 for (k = 0; k < num_mb; ++k)
903 testmgr_free_buf(data[k].xbuf);
905 crypto_free_ahash(tfm);
911 static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
914 unsigned long start, end;
918 for (start = jiffies, end = start + secs * HZ, bcount = 0;
919 time_before(jiffies, end); bcount++) {
920 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
925 printk("%6u opers/sec, %9lu bytes/sec\n",
926 bcount / secs, ((long)bcount * blen) / secs);
931 static int test_ahash_jiffies(struct ahash_request *req, int blen,
932 int plen, char *out, int secs)
934 unsigned long start, end;
939 return test_ahash_jiffies_digest(req, blen, out, secs);
941 for (start = jiffies, end = start + secs * HZ, bcount = 0;
942 time_before(jiffies, end); bcount++) {
943 ret = do_one_ahash_op(req, crypto_ahash_init(req));
946 for (pcount = 0; pcount < blen; pcount += plen) {
947 ret = do_one_ahash_op(req, crypto_ahash_update(req));
951 /* we assume there is enough space in 'out' for the result */
952 ret = do_one_ahash_op(req, crypto_ahash_final(req));
957 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
958 bcount / secs, ((long)bcount * blen) / secs);
963 static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
966 unsigned long cycles = 0;
970 for (i = 0; i < 4; i++) {
971 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
976 /* The real thing. */
977 for (i = 0; i < 8; i++) {
980 start = get_cycles();
982 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
988 cycles += end - start;
995 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
996 cycles / 8, cycles / (8 * blen));
1001 static int test_ahash_cycles(struct ahash_request *req, int blen,
1002 int plen, char *out)
1004 unsigned long cycles = 0;
1008 return test_ahash_cycles_digest(req, blen, out);
1011 for (i = 0; i < 4; i++) {
1012 ret = do_one_ahash_op(req, crypto_ahash_init(req));
1015 for (pcount = 0; pcount < blen; pcount += plen) {
1016 ret = do_one_ahash_op(req, crypto_ahash_update(req));
1020 ret = do_one_ahash_op(req, crypto_ahash_final(req));
1025 /* The real thing. */
1026 for (i = 0; i < 8; i++) {
1027 cycles_t start, end;
1029 start = get_cycles();
1031 ret = do_one_ahash_op(req, crypto_ahash_init(req));
1034 for (pcount = 0; pcount < blen; pcount += plen) {
1035 ret = do_one_ahash_op(req, crypto_ahash_update(req));
1039 ret = do_one_ahash_op(req, crypto_ahash_final(req));
1045 cycles += end - start;
1052 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
1053 cycles / 8, cycles / (8 * blen));
1058 static void test_ahash_speed_common(const char *algo, unsigned int secs,
1059 struct hash_speed *speed, unsigned mask)
1061 struct scatterlist sg[TVMEMSIZE];
1062 struct crypto_wait wait;
1063 struct ahash_request *req;
1064 struct crypto_ahash *tfm;
1068 tfm = crypto_alloc_ahash(algo, 0, mask);
1070 pr_err("failed to load transform for %s: %ld\n",
1071 algo, PTR_ERR(tfm));
1075 printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
1076 get_driver_name(crypto_ahash, tfm));
1078 if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) {
1079 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm),
1084 test_hash_sg_init(sg);
1085 req = ahash_request_alloc(tfm, GFP_KERNEL);
1087 pr_err("ahash request allocation failure\n");
1091 crypto_init_wait(&wait);
1092 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1093 crypto_req_done, &wait);
1095 output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
1099 for (i = 0; speed[i].blen != 0; i++) {
1100 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
1101 pr_err("template (%u) too big for tvmem (%lu)\n",
1102 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
1107 crypto_ahash_setkey(tfm, tvmem[0], speed[i].klen);
1110 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
1111 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
1113 ahash_request_set_crypt(req, sg, output, speed[i].plen);
1116 ret = test_ahash_jiffies(req, speed[i].blen,
1117 speed[i].plen, output, secs);
1120 ret = test_ahash_cycles(req, speed[i].blen,
1121 speed[i].plen, output);
1125 pr_err("hashing failed ret=%d\n", ret);
1133 ahash_request_free(req);
1136 crypto_free_ahash(tfm);
1139 static void test_ahash_speed(const char *algo, unsigned int secs,
1140 struct hash_speed *speed)
1142 return test_ahash_speed_common(algo, secs, speed, 0);
1145 static void test_hash_speed(const char *algo, unsigned int secs,
1146 struct hash_speed *speed)
1148 return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC);
1151 struct test_mb_skcipher_data {
1152 struct scatterlist sg[XBUFSIZE];
1153 struct skcipher_request *req;
1154 struct crypto_wait wait;
1155 char *xbuf[XBUFSIZE];
1158 static int do_mult_acipher_op(struct test_mb_skcipher_data *data, int enc,
1159 u32 num_mb, int *rc)
1163 /* Fire up a bunch of concurrent requests */
1164 for (i = 0; i < num_mb; i++) {
1166 rc[i] = crypto_skcipher_encrypt(data[i].req);
1168 rc[i] = crypto_skcipher_decrypt(data[i].req);
1171 /* Wait for all requests to finish */
1172 for (i = 0; i < num_mb; i++) {
1173 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
1176 pr_info("concurrent request %d error %d\n", i, rc[i]);
1184 static int test_mb_acipher_jiffies(struct test_mb_skcipher_data *data, int enc,
1185 int blen, int secs, u32 num_mb)
1187 unsigned long start, end;
1192 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
1196 for (start = jiffies, end = start + secs * HZ, bcount = 0;
1197 time_before(jiffies, end); bcount++) {
1198 ret = do_mult_acipher_op(data, enc, num_mb, rc);
1203 pr_cont("%d operations in %d seconds (%llu bytes)\n",
1204 bcount * num_mb, secs, (u64)bcount * blen * num_mb);
1211 static int test_mb_acipher_cycles(struct test_mb_skcipher_data *data, int enc,
1212 int blen, u32 num_mb)
1214 unsigned long cycles = 0;
1219 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
1224 for (i = 0; i < 4; i++) {
1225 ret = do_mult_acipher_op(data, enc, num_mb, rc);
1230 /* The real thing. */
1231 for (i = 0; i < 8; i++) {
1232 cycles_t start, end;
1234 start = get_cycles();
1235 ret = do_mult_acipher_op(data, enc, num_mb, rc);
1241 cycles += end - start;
1244 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1245 (cycles + 4) / (8 * num_mb), blen);
1252 static void test_mb_skcipher_speed(const char *algo, int enc, int secs,
1253 struct cipher_speed_template *template,
1254 unsigned int tcount, u8 *keysize, u32 num_mb)
1256 struct test_mb_skcipher_data *data;
1257 struct crypto_skcipher *tfm;
1258 unsigned int i, j, iv_len;
1270 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
1274 tfm = crypto_alloc_skcipher(algo, 0, 0);
1276 pr_err("failed to load transform for %s: %ld\n",
1277 algo, PTR_ERR(tfm));
1281 for (i = 0; i < num_mb; ++i)
1282 if (testmgr_alloc_buf(data[i].xbuf)) {
1284 testmgr_free_buf(data[i].xbuf);
1289 for (i = 0; i < num_mb; ++i)
1290 if (testmgr_alloc_buf(data[i].xbuf)) {
1292 testmgr_free_buf(data[i].xbuf);
1297 for (i = 0; i < num_mb; ++i) {
1298 data[i].req = skcipher_request_alloc(tfm, GFP_KERNEL);
1300 pr_err("alg: skcipher: Failed to allocate request for %s\n",
1303 skcipher_request_free(data[i].req);
1308 for (i = 0; i < num_mb; ++i) {
1309 skcipher_request_set_callback(data[i].req,
1310 CRYPTO_TFM_REQ_MAY_BACKLOG,
1311 crypto_req_done, &data[i].wait);
1312 crypto_init_wait(&data[i].wait);
1315 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo,
1316 get_driver_name(crypto_skcipher, tfm), e);
1320 b_size = block_sizes;
1322 if (*b_size > XBUFSIZE * PAGE_SIZE) {
1323 pr_err("template (%u) too big for buffer (%lu)\n",
1324 *b_size, XBUFSIZE * PAGE_SIZE);
1328 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1329 *keysize * 8, *b_size);
1331 /* Set up tfm global state, i.e. the key */
1333 memset(tvmem[0], 0xff, PAGE_SIZE);
1335 for (j = 0; j < tcount; j++) {
1336 if (template[j].klen == *keysize) {
1337 key = template[j].key;
1342 crypto_skcipher_clear_flags(tfm, ~0);
1344 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1346 pr_err("setkey() failed flags=%x\n",
1347 crypto_skcipher_get_flags(tfm));
1351 iv_len = crypto_skcipher_ivsize(tfm);
1353 memset(&iv, 0xff, iv_len);
1355 /* Now setup per request stuff, i.e. buffers */
1357 for (j = 0; j < num_mb; ++j) {
1358 struct test_mb_skcipher_data *cur = &data[j];
1359 unsigned int k = *b_size;
1360 unsigned int pages = DIV_ROUND_UP(k, PAGE_SIZE);
1363 sg_init_table(cur->sg, pages);
1365 while (k > PAGE_SIZE) {
1366 sg_set_buf(cur->sg + p, cur->xbuf[p],
1368 memset(cur->xbuf[p], 0xff, PAGE_SIZE);
1373 sg_set_buf(cur->sg + p, cur->xbuf[p], k);
1374 memset(cur->xbuf[p], 0xff, k);
1376 skcipher_request_set_crypt(cur->req, cur->sg,
1382 ret = test_mb_acipher_jiffies(data, enc,
1387 ret = test_mb_acipher_cycles(data, enc,
1392 pr_err("%s() failed flags=%x\n", e,
1393 crypto_skcipher_get_flags(tfm));
1403 for (i = 0; i < num_mb; ++i)
1404 skcipher_request_free(data[i].req);
1406 for (i = 0; i < num_mb; ++i)
1407 testmgr_free_buf(data[i].xbuf);
1409 crypto_free_skcipher(tfm);
1414 static inline int do_one_acipher_op(struct skcipher_request *req, int ret)
1416 struct crypto_wait *wait = req->base.data;
1418 return crypto_wait_req(ret, wait);
1421 static int test_acipher_jiffies(struct skcipher_request *req, int enc,
1424 unsigned long start, end;
1428 for (start = jiffies, end = start + secs * HZ, bcount = 0;
1429 time_before(jiffies, end); bcount++) {
1431 ret = do_one_acipher_op(req,
1432 crypto_skcipher_encrypt(req));
1434 ret = do_one_acipher_op(req,
1435 crypto_skcipher_decrypt(req));
1441 pr_cont("%d operations in %d seconds (%llu bytes)\n",
1442 bcount, secs, (u64)bcount * blen);
1446 static int test_acipher_cycles(struct skcipher_request *req, int enc,
1449 unsigned long cycles = 0;
1454 for (i = 0; i < 4; i++) {
1456 ret = do_one_acipher_op(req,
1457 crypto_skcipher_encrypt(req));
1459 ret = do_one_acipher_op(req,
1460 crypto_skcipher_decrypt(req));
1466 /* The real thing. */
1467 for (i = 0; i < 8; i++) {
1468 cycles_t start, end;
1470 start = get_cycles();
1472 ret = do_one_acipher_op(req,
1473 crypto_skcipher_encrypt(req));
1475 ret = do_one_acipher_op(req,
1476 crypto_skcipher_decrypt(req));
1482 cycles += end - start;
1487 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1488 (cycles + 4) / 8, blen);
1493 static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
1494 struct cipher_speed_template *template,
1495 unsigned int tcount, u8 *keysize, bool async)
1497 unsigned int ret, i, j, k, iv_len;
1498 struct crypto_wait wait;
1501 struct skcipher_request *req;
1502 struct crypto_skcipher *tfm;
1511 crypto_init_wait(&wait);
1513 tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC);
1516 pr_err("failed to load transform for %s: %ld\n", algo,
1521 pr_info("\ntesting speed of async %s (%s) %s\n", algo,
1522 get_driver_name(crypto_skcipher, tfm), e);
1524 req = skcipher_request_alloc(tfm, GFP_KERNEL);
1526 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1531 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1532 crypto_req_done, &wait);
1536 b_size = block_sizes;
1539 struct scatterlist sg[TVMEMSIZE];
1541 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
1542 pr_err("template (%u) too big for "
1543 "tvmem (%lu)\n", *keysize + *b_size,
1544 TVMEMSIZE * PAGE_SIZE);
1548 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1549 *keysize * 8, *b_size);
1551 memset(tvmem[0], 0xff, PAGE_SIZE);
1553 /* set key, plain text and IV */
1555 for (j = 0; j < tcount; j++) {
1556 if (template[j].klen == *keysize) {
1557 key = template[j].key;
1562 crypto_skcipher_clear_flags(tfm, ~0);
1564 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1566 pr_err("setkey() failed flags=%x\n",
1567 crypto_skcipher_get_flags(tfm));
1571 k = *keysize + *b_size;
1572 sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
1574 if (k > PAGE_SIZE) {
1575 sg_set_buf(sg, tvmem[0] + *keysize,
1576 PAGE_SIZE - *keysize);
1579 while (k > PAGE_SIZE) {
1580 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
1581 memset(tvmem[j], 0xff, PAGE_SIZE);
1585 sg_set_buf(sg + j, tvmem[j], k);
1586 memset(tvmem[j], 0xff, k);
1588 sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
1591 iv_len = crypto_skcipher_ivsize(tfm);
1593 memset(&iv, 0xff, iv_len);
1595 skcipher_request_set_crypt(req, sg, sg, *b_size, iv);
1598 ret = test_acipher_jiffies(req, enc,
1602 ret = test_acipher_cycles(req, enc,
1607 pr_err("%s() failed flags=%x\n", e,
1608 crypto_skcipher_get_flags(tfm));
1618 skcipher_request_free(req);
1620 crypto_free_skcipher(tfm);
1623 static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
1624 struct cipher_speed_template *template,
1625 unsigned int tcount, u8 *keysize)
1627 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1631 static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
1632 struct cipher_speed_template *template,
1633 unsigned int tcount, u8 *keysize)
1635 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1639 static void test_available(void)
1641 char **name = check;
1644 printk("alg %s ", *name);
1645 printk(crypto_has_alg(*name, 0, 0) ?
1646 "found\n" : "not found\n");
1651 static inline int tcrypt_test(const char *alg)
1655 pr_debug("testing %s\n", alg);
1657 ret = alg_test(alg, alg, 0, 0);
1658 /* non-fips algs return -EINVAL in fips mode */
1659 if (fips_enabled && ret == -EINVAL)
1664 static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)
1672 if (!crypto_has_alg(alg, type,
1673 mask ?: CRYPTO_ALG_TYPE_MASK))
1678 for (i = 1; i < 200; i++)
1679 ret += do_test(NULL, 0, 0, i, num_mb);
1683 ret += tcrypt_test("md5");
1687 ret += tcrypt_test("sha1");
1691 ret += tcrypt_test("ecb(des)");
1692 ret += tcrypt_test("cbc(des)");
1693 ret += tcrypt_test("ctr(des)");
1697 ret += tcrypt_test("ecb(des3_ede)");
1698 ret += tcrypt_test("cbc(des3_ede)");
1699 ret += tcrypt_test("ctr(des3_ede)");
1703 ret += tcrypt_test("md4");
1707 ret += tcrypt_test("sha256");
1711 ret += tcrypt_test("ecb(blowfish)");
1712 ret += tcrypt_test("cbc(blowfish)");
1713 ret += tcrypt_test("ctr(blowfish)");
1717 ret += tcrypt_test("ecb(twofish)");
1718 ret += tcrypt_test("cbc(twofish)");
1719 ret += tcrypt_test("ctr(twofish)");
1720 ret += tcrypt_test("lrw(twofish)");
1721 ret += tcrypt_test("xts(twofish)");
1725 ret += tcrypt_test("ecb(serpent)");
1726 ret += tcrypt_test("cbc(serpent)");
1727 ret += tcrypt_test("ctr(serpent)");
1728 ret += tcrypt_test("lrw(serpent)");
1729 ret += tcrypt_test("xts(serpent)");
1733 ret += tcrypt_test("ecb(aes)");
1734 ret += tcrypt_test("cbc(aes)");
1735 ret += tcrypt_test("lrw(aes)");
1736 ret += tcrypt_test("xts(aes)");
1737 ret += tcrypt_test("ctr(aes)");
1738 ret += tcrypt_test("rfc3686(ctr(aes))");
1739 ret += tcrypt_test("cfb(aes)");
1743 ret += tcrypt_test("sha384");
1747 ret += tcrypt_test("sha512");
1751 ret += tcrypt_test("deflate");
1755 ret += tcrypt_test("ecb(cast5)");
1756 ret += tcrypt_test("cbc(cast5)");
1757 ret += tcrypt_test("ctr(cast5)");
1761 ret += tcrypt_test("ecb(cast6)");
1762 ret += tcrypt_test("cbc(cast6)");
1763 ret += tcrypt_test("ctr(cast6)");
1764 ret += tcrypt_test("lrw(cast6)");
1765 ret += tcrypt_test("xts(cast6)");
1769 ret += tcrypt_test("ecb(arc4)");
1773 ret += tcrypt_test("michael_mic");
1777 ret += tcrypt_test("crc32c");
1781 ret += tcrypt_test("ecb(tea)");
1785 ret += tcrypt_test("ecb(xtea)");
1789 ret += tcrypt_test("ecb(khazad)");
1793 ret += tcrypt_test("wp512");
1797 ret += tcrypt_test("wp384");
1801 ret += tcrypt_test("wp256");
1805 ret += tcrypt_test("ecb(tnepres)");
1809 ret += tcrypt_test("ecb(anubis)");
1810 ret += tcrypt_test("cbc(anubis)");
1814 ret += tcrypt_test("tgr192");
1818 ret += tcrypt_test("tgr160");
1822 ret += tcrypt_test("tgr128");
1826 ret += tcrypt_test("ecb(xeta)");
1830 ret += tcrypt_test("pcbc(fcrypt)");
1834 ret += tcrypt_test("ecb(camellia)");
1835 ret += tcrypt_test("cbc(camellia)");
1836 ret += tcrypt_test("ctr(camellia)");
1837 ret += tcrypt_test("lrw(camellia)");
1838 ret += tcrypt_test("xts(camellia)");
1842 ret += tcrypt_test("sha224");
1846 ret += tcrypt_test("salsa20");
1850 ret += tcrypt_test("gcm(aes)");
1854 ret += tcrypt_test("lzo");
1858 ret += tcrypt_test("ccm(aes)");
1862 ret += tcrypt_test("cts(cbc(aes))");
1866 ret += tcrypt_test("rmd128");
1870 ret += tcrypt_test("rmd160");
1874 ret += tcrypt_test("rmd256");
1878 ret += tcrypt_test("rmd320");
1882 ret += tcrypt_test("ecb(seed)");
1886 ret += tcrypt_test("zlib");
1890 ret += tcrypt_test("rfc4309(ccm(aes))");
1894 ret += tcrypt_test("ghash");
1898 ret += tcrypt_test("crct10dif");
1902 ret += tcrypt_test("sha3-224");
1906 ret += tcrypt_test("sha3-256");
1910 ret += tcrypt_test("sha3-384");
1914 ret += tcrypt_test("sha3-512");
1918 ret += tcrypt_test("sm3");
1922 ret += tcrypt_test("hmac(md5)");
1926 ret += tcrypt_test("hmac(sha1)");
1930 ret += tcrypt_test("hmac(sha256)");
1934 ret += tcrypt_test("hmac(sha384)");
1938 ret += tcrypt_test("hmac(sha512)");
1942 ret += tcrypt_test("hmac(sha224)");
1946 ret += tcrypt_test("xcbc(aes)");
1950 ret += tcrypt_test("hmac(rmd128)");
1954 ret += tcrypt_test("hmac(rmd160)");
1958 ret += tcrypt_test("vmac64(aes)");
1962 ret += tcrypt_test("hmac(sha3-224)");
1966 ret += tcrypt_test("hmac(sha3-256)");
1970 ret += tcrypt_test("hmac(sha3-384)");
1974 ret += tcrypt_test("hmac(sha3-512)");
1978 ret += tcrypt_test("ansi_cprng");
1982 ret += tcrypt_test("rfc4106(gcm(aes))");
1986 ret += tcrypt_test("rfc4543(gcm(aes))");
1990 ret += tcrypt_test("cmac(aes)");
1994 ret += tcrypt_test("cmac(des3_ede)");
1998 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
2002 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
2006 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
2009 ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
2012 ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
2015 ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
2018 ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
2021 ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
2024 ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
2027 ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
2030 ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
2033 ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
2036 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
2039 ret += tcrypt_test("ecb(sm4)");
2042 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2043 speed_template_16_24_32);
2044 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2045 speed_template_16_24_32);
2046 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2047 speed_template_16_24_32);
2048 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2049 speed_template_16_24_32);
2050 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2051 speed_template_32_40_48);
2052 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2053 speed_template_32_40_48);
2054 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2055 speed_template_32_64);
2056 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2057 speed_template_32_64);
2058 test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2059 speed_template_16_24_32);
2060 test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2061 speed_template_16_24_32);
2062 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2063 speed_template_16_24_32);
2064 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2065 speed_template_16_24_32);
2066 test_cipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2067 speed_template_16_24_32);
2068 test_cipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2069 speed_template_16_24_32);
2073 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2074 des3_speed_template, DES3_SPEED_VECTORS,
2076 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
2077 des3_speed_template, DES3_SPEED_VECTORS,
2079 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2080 des3_speed_template, DES3_SPEED_VECTORS,
2082 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
2083 des3_speed_template, DES3_SPEED_VECTORS,
2085 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
2086 des3_speed_template, DES3_SPEED_VECTORS,
2088 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
2089 des3_speed_template, DES3_SPEED_VECTORS,
2094 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2095 speed_template_16_24_32);
2096 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2097 speed_template_16_24_32);
2098 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2099 speed_template_16_24_32);
2100 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2101 speed_template_16_24_32);
2102 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2103 speed_template_16_24_32);
2104 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2105 speed_template_16_24_32);
2106 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2107 speed_template_32_40_48);
2108 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2109 speed_template_32_40_48);
2110 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2111 speed_template_32_48_64);
2112 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2113 speed_template_32_48_64);
2117 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2118 speed_template_8_32);
2119 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2120 speed_template_8_32);
2121 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2122 speed_template_8_32);
2123 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2124 speed_template_8_32);
2125 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2126 speed_template_8_32);
2127 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2128 speed_template_8_32);
2132 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2134 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2136 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2138 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2143 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2144 speed_template_16_24_32);
2145 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2146 speed_template_16_24_32);
2147 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2148 speed_template_16_24_32);
2149 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2150 speed_template_16_24_32);
2151 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2152 speed_template_16_24_32);
2153 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2154 speed_template_16_24_32);
2155 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2156 speed_template_32_40_48);
2157 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2158 speed_template_32_40_48);
2159 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2160 speed_template_32_48_64);
2161 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2162 speed_template_32_48_64);
2166 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
2167 speed_template_16_32);
2171 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2172 speed_template_16_32);
2173 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2174 speed_template_16_32);
2175 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2176 speed_template_16_32);
2177 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2178 speed_template_16_32);
2179 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2180 speed_template_16_32);
2181 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2182 speed_template_16_32);
2183 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2184 speed_template_32_48);
2185 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2186 speed_template_32_48);
2187 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2188 speed_template_32_64);
2189 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2190 speed_template_32_64);
2194 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2199 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2200 speed_template_8_16);
2201 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2202 speed_template_8_16);
2203 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2204 speed_template_8_16);
2205 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2206 speed_template_8_16);
2207 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2208 speed_template_8_16);
2209 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2210 speed_template_8_16);
2214 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2215 speed_template_16_32);
2216 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2217 speed_template_16_32);
2218 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2219 speed_template_16_32);
2220 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2221 speed_template_16_32);
2222 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2223 speed_template_16_32);
2224 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2225 speed_template_16_32);
2226 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2227 speed_template_32_48);
2228 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2229 speed_template_32_48);
2230 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2231 speed_template_32_64);
2232 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2233 speed_template_32_64);
2237 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
2238 NULL, 0, 16, 16, aead_speed_template_20);
2239 test_aead_speed("gcm(aes)", ENCRYPT, sec,
2240 NULL, 0, 16, 8, speed_template_16_24_32);
2241 test_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec,
2242 NULL, 0, 16, 16, aead_speed_template_20);
2243 test_aead_speed("gcm(aes)", DECRYPT, sec,
2244 NULL, 0, 16, 8, speed_template_16_24_32);
2248 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
2249 NULL, 0, 16, 16, aead_speed_template_19);
2250 test_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec,
2251 NULL, 0, 16, 16, aead_speed_template_19);
2255 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
2256 NULL, 0, 16, 8, aead_speed_template_36);
2257 test_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT, sec,
2258 NULL, 0, 16, 8, aead_speed_template_36);
2262 test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
2267 test_mb_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec, NULL,
2268 0, 16, 16, aead_speed_template_20, num_mb);
2269 test_mb_aead_speed("gcm(aes)", ENCRYPT, sec, NULL, 0, 16, 8,
2270 speed_template_16_24_32, num_mb);
2271 test_mb_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec, NULL,
2272 0, 16, 16, aead_speed_template_20, num_mb);
2273 test_mb_aead_speed("gcm(aes)", DECRYPT, sec, NULL, 0, 16, 8,
2274 speed_template_16_24_32, num_mb);
2278 test_mb_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec, NULL, 0,
2279 16, 16, aead_speed_template_19, num_mb);
2280 test_mb_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec, NULL, 0,
2281 16, 16, aead_speed_template_19, num_mb);
2285 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT,
2286 sec, NULL, 0, 16, 8, aead_speed_template_36,
2288 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT,
2289 sec, NULL, 0, 16, 8, aead_speed_template_36,
2295 test_hash_speed(alg, sec, generic_hash_speed_template);
2300 test_hash_speed("md4", sec, generic_hash_speed_template);
2301 if (mode > 300 && mode < 400) break;
2304 test_hash_speed("md5", sec, generic_hash_speed_template);
2305 if (mode > 300 && mode < 400) break;
2308 test_hash_speed("sha1", sec, generic_hash_speed_template);
2309 if (mode > 300 && mode < 400) break;
2312 test_hash_speed("sha256", sec, generic_hash_speed_template);
2313 if (mode > 300 && mode < 400) break;
2316 test_hash_speed("sha384", sec, generic_hash_speed_template);
2317 if (mode > 300 && mode < 400) break;
2320 test_hash_speed("sha512", sec, generic_hash_speed_template);
2321 if (mode > 300 && mode < 400) break;
2324 test_hash_speed("wp256", sec, generic_hash_speed_template);
2325 if (mode > 300 && mode < 400) break;
2328 test_hash_speed("wp384", sec, generic_hash_speed_template);
2329 if (mode > 300 && mode < 400) break;
2332 test_hash_speed("wp512", sec, generic_hash_speed_template);
2333 if (mode > 300 && mode < 400) break;
2336 test_hash_speed("tgr128", sec, generic_hash_speed_template);
2337 if (mode > 300 && mode < 400) break;
2340 test_hash_speed("tgr160", sec, generic_hash_speed_template);
2341 if (mode > 300 && mode < 400) break;
2344 test_hash_speed("tgr192", sec, generic_hash_speed_template);
2345 if (mode > 300 && mode < 400) break;
2348 test_hash_speed("sha224", sec, generic_hash_speed_template);
2349 if (mode > 300 && mode < 400) break;
2352 test_hash_speed("rmd128", sec, generic_hash_speed_template);
2353 if (mode > 300 && mode < 400) break;
2356 test_hash_speed("rmd160", sec, generic_hash_speed_template);
2357 if (mode > 300 && mode < 400) break;
2360 test_hash_speed("rmd256", sec, generic_hash_speed_template);
2361 if (mode > 300 && mode < 400) break;
2364 test_hash_speed("rmd320", sec, generic_hash_speed_template);
2365 if (mode > 300 && mode < 400) break;
2368 test_hash_speed("ghash-generic", sec, hash_speed_template_16);
2369 if (mode > 300 && mode < 400) break;
2372 test_hash_speed("crc32c", sec, generic_hash_speed_template);
2373 if (mode > 300 && mode < 400) break;
2376 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
2377 if (mode > 300 && mode < 400) break;
2380 test_hash_speed("poly1305", sec, poly1305_speed_template);
2381 if (mode > 300 && mode < 400) break;
2384 test_hash_speed("sha3-224", sec, generic_hash_speed_template);
2385 if (mode > 300 && mode < 400) break;
2388 test_hash_speed("sha3-256", sec, generic_hash_speed_template);
2389 if (mode > 300 && mode < 400) break;
2392 test_hash_speed("sha3-384", sec, generic_hash_speed_template);
2393 if (mode > 300 && mode < 400) break;
2396 test_hash_speed("sha3-512", sec, generic_hash_speed_template);
2397 if (mode > 300 && mode < 400) break;
2400 test_hash_speed("sm3", sec, generic_hash_speed_template);
2401 if (mode > 300 && mode < 400) break;
2408 test_ahash_speed(alg, sec, generic_hash_speed_template);
2413 test_ahash_speed("md4", sec, generic_hash_speed_template);
2414 if (mode > 400 && mode < 500) break;
2417 test_ahash_speed("md5", sec, generic_hash_speed_template);
2418 if (mode > 400 && mode < 500) break;
2421 test_ahash_speed("sha1", sec, generic_hash_speed_template);
2422 if (mode > 400 && mode < 500) break;
2425 test_ahash_speed("sha256", sec, generic_hash_speed_template);
2426 if (mode > 400 && mode < 500) break;
2429 test_ahash_speed("sha384", sec, generic_hash_speed_template);
2430 if (mode > 400 && mode < 500) break;
2433 test_ahash_speed("sha512", sec, generic_hash_speed_template);
2434 if (mode > 400 && mode < 500) break;
2437 test_ahash_speed("wp256", sec, generic_hash_speed_template);
2438 if (mode > 400 && mode < 500) break;
2441 test_ahash_speed("wp384", sec, generic_hash_speed_template);
2442 if (mode > 400 && mode < 500) break;
2445 test_ahash_speed("wp512", sec, generic_hash_speed_template);
2446 if (mode > 400 && mode < 500) break;
2449 test_ahash_speed("tgr128", sec, generic_hash_speed_template);
2450 if (mode > 400 && mode < 500) break;
2453 test_ahash_speed("tgr160", sec, generic_hash_speed_template);
2454 if (mode > 400 && mode < 500) break;
2457 test_ahash_speed("tgr192", sec, generic_hash_speed_template);
2458 if (mode > 400 && mode < 500) break;
2461 test_ahash_speed("sha224", sec, generic_hash_speed_template);
2462 if (mode > 400 && mode < 500) break;
2465 test_ahash_speed("rmd128", sec, generic_hash_speed_template);
2466 if (mode > 400 && mode < 500) break;
2469 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
2470 if (mode > 400 && mode < 500) break;
2473 test_ahash_speed("rmd256", sec, generic_hash_speed_template);
2474 if (mode > 400 && mode < 500) break;
2477 test_ahash_speed("rmd320", sec, generic_hash_speed_template);
2478 if (mode > 400 && mode < 500) break;
2481 test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
2482 if (mode > 400 && mode < 500) break;
2485 test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
2486 if (mode > 400 && mode < 500) break;
2489 test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
2490 if (mode > 400 && mode < 500) break;
2493 test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
2494 if (mode > 400 && mode < 500) break;
2497 test_mb_ahash_speed("sha1", sec, generic_hash_speed_template,
2499 if (mode > 400 && mode < 500) break;
2502 test_mb_ahash_speed("sha256", sec, generic_hash_speed_template,
2504 if (mode > 400 && mode < 500) break;
2507 test_mb_ahash_speed("sha512", sec, generic_hash_speed_template,
2509 if (mode > 400 && mode < 500) break;
2512 test_mb_ahash_speed("sm3", sec, generic_hash_speed_template,
2514 if (mode > 400 && mode < 500) break;
2520 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2521 speed_template_16_24_32);
2522 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2523 speed_template_16_24_32);
2524 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2525 speed_template_16_24_32);
2526 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2527 speed_template_16_24_32);
2528 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2529 speed_template_32_40_48);
2530 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2531 speed_template_32_40_48);
2532 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2533 speed_template_32_64);
2534 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2535 speed_template_32_64);
2536 test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2537 speed_template_16_24_32);
2538 test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2539 speed_template_16_24_32);
2540 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2541 speed_template_16_24_32);
2542 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2543 speed_template_16_24_32);
2544 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2545 speed_template_16_24_32);
2546 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2547 speed_template_16_24_32);
2548 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2549 speed_template_16_24_32);
2550 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2551 speed_template_16_24_32);
2552 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
2553 speed_template_20_28_36);
2554 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
2555 speed_template_20_28_36);
2559 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2560 des3_speed_template, DES3_SPEED_VECTORS,
2562 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
2563 des3_speed_template, DES3_SPEED_VECTORS,
2565 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2566 des3_speed_template, DES3_SPEED_VECTORS,
2568 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
2569 des3_speed_template, DES3_SPEED_VECTORS,
2571 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2572 des3_speed_template, DES3_SPEED_VECTORS,
2574 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
2575 des3_speed_template, DES3_SPEED_VECTORS,
2577 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2578 des3_speed_template, DES3_SPEED_VECTORS,
2580 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
2581 des3_speed_template, DES3_SPEED_VECTORS,
2586 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2588 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2590 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2592 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2594 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2596 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2598 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2600 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2605 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2606 speed_template_16_32);
2607 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2608 speed_template_16_32);
2609 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2610 speed_template_16_32);
2611 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2612 speed_template_16_32);
2613 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2614 speed_template_16_32);
2615 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2616 speed_template_16_32);
2617 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2618 speed_template_32_48);
2619 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2620 speed_template_32_48);
2621 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2622 speed_template_32_64);
2623 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2624 speed_template_32_64);
2628 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2629 speed_template_16_24_32);
2630 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2631 speed_template_16_24_32);
2632 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2633 speed_template_16_24_32);
2634 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2635 speed_template_16_24_32);
2636 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2637 speed_template_16_24_32);
2638 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2639 speed_template_16_24_32);
2640 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2641 speed_template_32_40_48);
2642 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2643 speed_template_32_40_48);
2644 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2645 speed_template_32_48_64);
2646 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2647 speed_template_32_48_64);
2651 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2656 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2657 speed_template_8_16);
2658 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2659 speed_template_8_16);
2660 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2661 speed_template_8_16);
2662 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2663 speed_template_8_16);
2664 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2665 speed_template_8_16);
2666 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2667 speed_template_8_16);
2671 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2672 speed_template_16_32);
2673 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2674 speed_template_16_32);
2675 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2676 speed_template_16_32);
2677 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2678 speed_template_16_32);
2679 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2680 speed_template_16_32);
2681 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2682 speed_template_16_32);
2683 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2684 speed_template_32_48);
2685 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2686 speed_template_32_48);
2687 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2688 speed_template_32_64);
2689 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2690 speed_template_32_64);
2694 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2695 speed_template_16_32);
2696 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2697 speed_template_16_32);
2698 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2699 speed_template_16_32);
2700 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2701 speed_template_16_32);
2702 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2703 speed_template_16_32);
2704 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2705 speed_template_16_32);
2706 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2707 speed_template_32_48);
2708 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2709 speed_template_32_48);
2710 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2711 speed_template_32_64);
2712 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2713 speed_template_32_64);
2717 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2718 speed_template_8_32);
2719 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2720 speed_template_8_32);
2721 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2722 speed_template_8_32);
2723 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2724 speed_template_8_32);
2725 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2726 speed_template_8_32);
2727 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2728 speed_template_8_32);
2732 test_mb_skcipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2733 speed_template_16_24_32, num_mb);
2734 test_mb_skcipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2735 speed_template_16_24_32, num_mb);
2736 test_mb_skcipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2737 speed_template_16_24_32, num_mb);
2738 test_mb_skcipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2739 speed_template_16_24_32, num_mb);
2740 test_mb_skcipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2741 speed_template_32_40_48, num_mb);
2742 test_mb_skcipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2743 speed_template_32_40_48, num_mb);
2744 test_mb_skcipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2745 speed_template_32_64, num_mb);
2746 test_mb_skcipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2747 speed_template_32_64, num_mb);
2748 test_mb_skcipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2749 speed_template_16_24_32, num_mb);
2750 test_mb_skcipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2751 speed_template_16_24_32, num_mb);
2752 test_mb_skcipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2753 speed_template_16_24_32, num_mb);
2754 test_mb_skcipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2755 speed_template_16_24_32, num_mb);
2756 test_mb_skcipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2757 speed_template_16_24_32, num_mb);
2758 test_mb_skcipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2759 speed_template_16_24_32, num_mb);
2760 test_mb_skcipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2761 speed_template_16_24_32, num_mb);
2762 test_mb_skcipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2763 speed_template_16_24_32, num_mb);
2764 test_mb_skcipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL,
2765 0, speed_template_20_28_36, num_mb);
2766 test_mb_skcipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL,
2767 0, speed_template_20_28_36, num_mb);
2771 test_mb_skcipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2772 des3_speed_template, DES3_SPEED_VECTORS,
2773 speed_template_24, num_mb);
2774 test_mb_skcipher_speed("ecb(des3_ede)", DECRYPT, sec,
2775 des3_speed_template, DES3_SPEED_VECTORS,
2776 speed_template_24, num_mb);
2777 test_mb_skcipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2778 des3_speed_template, DES3_SPEED_VECTORS,
2779 speed_template_24, num_mb);
2780 test_mb_skcipher_speed("cbc(des3_ede)", DECRYPT, sec,
2781 des3_speed_template, DES3_SPEED_VECTORS,
2782 speed_template_24, num_mb);
2783 test_mb_skcipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2784 des3_speed_template, DES3_SPEED_VECTORS,
2785 speed_template_24, num_mb);
2786 test_mb_skcipher_speed("cfb(des3_ede)", DECRYPT, sec,
2787 des3_speed_template, DES3_SPEED_VECTORS,
2788 speed_template_24, num_mb);
2789 test_mb_skcipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2790 des3_speed_template, DES3_SPEED_VECTORS,
2791 speed_template_24, num_mb);
2792 test_mb_skcipher_speed("ofb(des3_ede)", DECRYPT, sec,
2793 des3_speed_template, DES3_SPEED_VECTORS,
2794 speed_template_24, num_mb);
2798 test_mb_skcipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2799 speed_template_8, num_mb);
2800 test_mb_skcipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2801 speed_template_8, num_mb);
2802 test_mb_skcipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2803 speed_template_8, num_mb);
2804 test_mb_skcipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2805 speed_template_8, num_mb);
2806 test_mb_skcipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2807 speed_template_8, num_mb);
2808 test_mb_skcipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2809 speed_template_8, num_mb);
2810 test_mb_skcipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2811 speed_template_8, num_mb);
2812 test_mb_skcipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2813 speed_template_8, num_mb);
2817 test_mb_skcipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2818 speed_template_16_32, num_mb);
2819 test_mb_skcipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2820 speed_template_16_32, num_mb);
2821 test_mb_skcipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2822 speed_template_16_32, num_mb);
2823 test_mb_skcipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2824 speed_template_16_32, num_mb);
2825 test_mb_skcipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2826 speed_template_16_32, num_mb);
2827 test_mb_skcipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2828 speed_template_16_32, num_mb);
2829 test_mb_skcipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2830 speed_template_32_48, num_mb);
2831 test_mb_skcipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2832 speed_template_32_48, num_mb);
2833 test_mb_skcipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2834 speed_template_32_64, num_mb);
2835 test_mb_skcipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2836 speed_template_32_64, num_mb);
2840 test_mb_skcipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2841 speed_template_16_24_32, num_mb);
2842 test_mb_skcipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2843 speed_template_16_24_32, num_mb);
2844 test_mb_skcipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2845 speed_template_16_24_32, num_mb);
2846 test_mb_skcipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2847 speed_template_16_24_32, num_mb);
2848 test_mb_skcipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2849 speed_template_16_24_32, num_mb);
2850 test_mb_skcipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2851 speed_template_16_24_32, num_mb);
2852 test_mb_skcipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2853 speed_template_32_40_48, num_mb);
2854 test_mb_skcipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2855 speed_template_32_40_48, num_mb);
2856 test_mb_skcipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2857 speed_template_32_48_64, num_mb);
2858 test_mb_skcipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2859 speed_template_32_48_64, num_mb);
2863 test_mb_skcipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2864 speed_template_8, num_mb);
2868 test_mb_skcipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2869 speed_template_8_16, num_mb);
2870 test_mb_skcipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2871 speed_template_8_16, num_mb);
2872 test_mb_skcipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2873 speed_template_8_16, num_mb);
2874 test_mb_skcipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2875 speed_template_8_16, num_mb);
2876 test_mb_skcipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2877 speed_template_8_16, num_mb);
2878 test_mb_skcipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2879 speed_template_8_16, num_mb);
2883 test_mb_skcipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2884 speed_template_16_32, num_mb);
2885 test_mb_skcipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2886 speed_template_16_32, num_mb);
2887 test_mb_skcipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2888 speed_template_16_32, num_mb);
2889 test_mb_skcipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2890 speed_template_16_32, num_mb);
2891 test_mb_skcipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2892 speed_template_16_32, num_mb);
2893 test_mb_skcipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2894 speed_template_16_32, num_mb);
2895 test_mb_skcipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2896 speed_template_32_48, num_mb);
2897 test_mb_skcipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2898 speed_template_32_48, num_mb);
2899 test_mb_skcipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2900 speed_template_32_64, num_mb);
2901 test_mb_skcipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2902 speed_template_32_64, num_mb);
2906 test_mb_skcipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2907 speed_template_16_32, num_mb);
2908 test_mb_skcipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2909 speed_template_16_32, num_mb);
2910 test_mb_skcipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2911 speed_template_16_32, num_mb);
2912 test_mb_skcipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2913 speed_template_16_32, num_mb);
2914 test_mb_skcipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2915 speed_template_16_32, num_mb);
2916 test_mb_skcipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2917 speed_template_16_32, num_mb);
2918 test_mb_skcipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2919 speed_template_32_48, num_mb);
2920 test_mb_skcipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2921 speed_template_32_48, num_mb);
2922 test_mb_skcipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2923 speed_template_32_64, num_mb);
2924 test_mb_skcipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2925 speed_template_32_64, num_mb);
2929 test_mb_skcipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2930 speed_template_8_32, num_mb);
2931 test_mb_skcipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2932 speed_template_8_32, num_mb);
2933 test_mb_skcipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2934 speed_template_8_32, num_mb);
2935 test_mb_skcipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2936 speed_template_8_32, num_mb);
2937 test_mb_skcipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2938 speed_template_8_32, num_mb);
2939 test_mb_skcipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2940 speed_template_8_32, num_mb);
2951 static int __init tcrypt_mod_init(void)
2956 for (i = 0; i < TVMEMSIZE; i++) {
2957 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
2962 err = do_test(alg, type, mask, mode, num_mb);
2965 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
2968 pr_debug("all tests passed\n");
2971 /* We intentionaly return -EAGAIN to prevent keeping the module,
2972 * unless we're running in fips mode. It does all its work from
2973 * init() and doesn't offer any runtime functionality, but in
2974 * the fips case, checking for a successful load is helpful.
2975 * => we don't need it in the memory, do we?
2982 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
2983 free_page((unsigned long)tvmem[i]);
2989 * If an init function is provided, an exit function must also be provided
2990 * to allow module unload.
2992 static void __exit tcrypt_mod_fini(void) { }
2994 module_init(tcrypt_mod_init);
2995 module_exit(tcrypt_mod_fini);
2997 module_param(alg, charp, 0);
2998 module_param(type, uint, 0);
2999 module_param(mask, uint, 0);
3000 module_param(mode, int, 0);
3001 module_param(sec, uint, 0);
3002 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
3003 "(defaults to zero which uses CPU cycles instead)");
3004 module_param(num_mb, uint, 0000);
3005 MODULE_PARM_DESC(num_mb, "Number of concurrent requests to be used in mb speed tests (defaults to 8)");
3007 MODULE_LICENSE("GPL");
3008 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
3009 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");