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", "sha3-224", "sha3-256", "sha3-384", "sha3-512", NULL
82 static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
83 static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
88 static int testmgr_alloc_buf(char *buf[XBUFSIZE])
92 for (i = 0; i < XBUFSIZE; i++) {
93 buf[i] = (void *)__get_free_page(GFP_KERNEL);
102 free_page((unsigned long)buf[i]);
107 static void testmgr_free_buf(char *buf[XBUFSIZE])
111 for (i = 0; i < XBUFSIZE; i++)
112 free_page((unsigned long)buf[i]);
115 static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],
116 unsigned int buflen, const void *assoc,
117 unsigned int aad_size)
119 int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
126 rem = buflen % PAGE_SIZE;
129 sg_init_table(sg, np + 1);
131 sg_set_buf(&sg[0], assoc, aad_size);
135 for (k = 0; k < np; k++)
136 sg_set_buf(&sg[k + 1], xbuf[k], PAGE_SIZE);
139 sg_set_buf(&sg[k + 1], xbuf[k], rem);
142 static inline int do_one_aead_op(struct aead_request *req, int ret)
144 struct crypto_wait *wait = req->base.data;
146 return crypto_wait_req(ret, wait);
149 struct test_mb_aead_data {
150 struct scatterlist sg[XBUFSIZE];
151 struct scatterlist sgout[XBUFSIZE];
152 struct aead_request *req;
153 struct crypto_wait wait;
154 char *xbuf[XBUFSIZE];
155 char *xoutbuf[XBUFSIZE];
156 char *axbuf[XBUFSIZE];
159 static int do_mult_aead_op(struct test_mb_aead_data *data, int enc,
164 /* Fire up a bunch of concurrent requests */
165 for (i = 0; i < num_mb; i++) {
167 rc[i] = crypto_aead_encrypt(data[i].req);
169 rc[i] = crypto_aead_decrypt(data[i].req);
172 /* Wait for all requests to finish */
173 for (i = 0; i < num_mb; i++) {
174 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
177 pr_info("concurrent request %d error %d\n", i, rc[i]);
185 static int test_mb_aead_jiffies(struct test_mb_aead_data *data, int enc,
186 int blen, int secs, u32 num_mb)
188 unsigned long start, end;
193 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
197 for (start = jiffies, end = start + secs * HZ, bcount = 0;
198 time_before(jiffies, end); bcount++) {
199 ret = do_mult_aead_op(data, enc, num_mb, rc);
204 pr_cont("%d operations in %d seconds (%ld bytes)\n",
205 bcount * num_mb, secs, (long)bcount * blen * num_mb);
212 static int test_mb_aead_cycles(struct test_mb_aead_data *data, int enc,
213 int blen, u32 num_mb)
215 unsigned long cycles = 0;
220 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
225 for (i = 0; i < 4; i++) {
226 ret = do_mult_aead_op(data, enc, num_mb, rc);
231 /* The real thing. */
232 for (i = 0; i < 8; i++) {
235 start = get_cycles();
236 ret = do_mult_aead_op(data, enc, num_mb, rc);
242 cycles += end - start;
245 pr_cont("1 operation in %lu cycles (%d bytes)\n",
246 (cycles + 4) / (8 * num_mb), blen);
253 static void test_mb_aead_speed(const char *algo, int enc, int secs,
254 struct aead_speed_template *template,
255 unsigned int tcount, u8 authsize,
256 unsigned int aad_size, u8 *keysize, u32 num_mb)
258 struct test_mb_aead_data *data;
259 struct crypto_aead *tfm;
260 unsigned int i, j, iv_len;
269 if (aad_size >= PAGE_SIZE) {
270 pr_err("associate data length (%u) too big\n", aad_size);
274 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
283 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
287 tfm = crypto_alloc_aead(algo, 0, 0);
289 pr_err("failed to load transform for %s: %ld\n",
294 ret = crypto_aead_setauthsize(tfm, authsize);
296 for (i = 0; i < num_mb; ++i)
297 if (testmgr_alloc_buf(data[i].xbuf)) {
299 testmgr_free_buf(data[i].xbuf);
303 for (i = 0; i < num_mb; ++i)
304 if (testmgr_alloc_buf(data[i].axbuf)) {
306 testmgr_free_buf(data[i].axbuf);
310 for (i = 0; i < num_mb; ++i)
311 if (testmgr_alloc_buf(data[i].xoutbuf)) {
313 testmgr_free_buf(data[i].xoutbuf);
317 for (i = 0; i < num_mb; ++i) {
318 data[i].req = aead_request_alloc(tfm, GFP_KERNEL);
320 pr_err("alg: skcipher: Failed to allocate request for %s\n",
323 aead_request_free(data[i].req);
324 goto out_free_xoutbuf;
328 for (i = 0; i < num_mb; ++i) {
329 crypto_init_wait(&data[i].wait);
330 aead_request_set_callback(data[i].req,
331 CRYPTO_TFM_REQ_MAY_BACKLOG,
332 crypto_req_done, &data[i].wait);
335 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo,
336 get_driver_name(crypto_aead, tfm), e);
342 if (*b_size + authsize > XBUFSIZE * PAGE_SIZE) {
343 pr_err("template (%u) too big for buffer (%lu)\n",
345 XBUFSIZE * PAGE_SIZE);
349 pr_info("test %u (%d bit key, %d byte blocks): ", i,
350 *keysize * 8, *b_size);
352 /* Set up tfm global state, i.e. the key */
354 memset(tvmem[0], 0xff, PAGE_SIZE);
356 for (j = 0; j < tcount; j++) {
357 if (template[j].klen == *keysize) {
358 key = template[j].key;
363 crypto_aead_clear_flags(tfm, ~0);
365 ret = crypto_aead_setkey(tfm, key, *keysize);
367 pr_err("setkey() failed flags=%x\n",
368 crypto_aead_get_flags(tfm));
372 iv_len = crypto_aead_ivsize(tfm);
374 memset(iv, 0xff, iv_len);
376 /* Now setup per request stuff, i.e. buffers */
378 for (j = 0; j < num_mb; ++j) {
379 struct test_mb_aead_data *cur = &data[j];
381 assoc = cur->axbuf[0];
382 memset(assoc, 0xff, aad_size);
384 sg_init_aead(cur->sg, cur->xbuf,
385 *b_size + (enc ? 0 : authsize),
388 sg_init_aead(cur->sgout, cur->xoutbuf,
389 *b_size + (enc ? authsize : 0),
392 aead_request_set_ad(cur->req, aad_size);
396 aead_request_set_crypt(cur->req,
400 ret = crypto_aead_encrypt(cur->req);
401 ret = do_one_aead_op(cur->req, ret);
404 pr_err("calculating auth failed failed (%d)\n",
410 aead_request_set_crypt(cur->req, cur->sg,
411 cur->sgout, *b_size +
412 (enc ? 0 : authsize),
418 ret = test_mb_aead_jiffies(data, enc, *b_size,
422 ret = test_mb_aead_cycles(data, enc, *b_size,
427 pr_err("%s() failed return code=%d\n", e, ret);
437 for (i = 0; i < num_mb; ++i)
438 aead_request_free(data[i].req);
440 for (i = 0; i < num_mb; ++i)
441 testmgr_free_buf(data[i].xoutbuf);
443 for (i = 0; i < num_mb; ++i)
444 testmgr_free_buf(data[i].axbuf);
446 for (i = 0; i < num_mb; ++i)
447 testmgr_free_buf(data[i].xbuf);
449 crypto_free_aead(tfm);
456 static int test_aead_jiffies(struct aead_request *req, int enc,
459 unsigned long start, end;
463 for (start = jiffies, end = start + secs * HZ, bcount = 0;
464 time_before(jiffies, end); bcount++) {
466 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
468 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
474 printk("%d operations in %d seconds (%ld bytes)\n",
475 bcount, secs, (long)bcount * blen);
479 static int test_aead_cycles(struct aead_request *req, int enc, int blen)
481 unsigned long cycles = 0;
486 for (i = 0; i < 4; i++) {
488 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
490 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
496 /* The real thing. */
497 for (i = 0; i < 8; i++) {
500 start = get_cycles();
502 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
504 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
510 cycles += end - start;
515 printk("1 operation in %lu cycles (%d bytes)\n",
516 (cycles + 4) / 8, blen);
521 static void test_aead_speed(const char *algo, int enc, unsigned int secs,
522 struct aead_speed_template *template,
523 unsigned int tcount, u8 authsize,
524 unsigned int aad_size, u8 *keysize)
527 struct crypto_aead *tfm;
530 struct aead_request *req;
531 struct scatterlist *sg;
532 struct scatterlist *sgout;
536 char *xbuf[XBUFSIZE];
537 char *xoutbuf[XBUFSIZE];
538 char *axbuf[XBUFSIZE];
539 unsigned int *b_size;
541 struct crypto_wait wait;
543 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
547 if (aad_size >= PAGE_SIZE) {
548 pr_err("associate data length (%u) too big\n", aad_size);
557 if (testmgr_alloc_buf(xbuf))
559 if (testmgr_alloc_buf(axbuf))
561 if (testmgr_alloc_buf(xoutbuf))
564 sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL);
569 tfm = crypto_alloc_aead(algo, 0, 0);
572 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
577 crypto_init_wait(&wait);
578 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
579 get_driver_name(crypto_aead, tfm), e);
581 req = aead_request_alloc(tfm, GFP_KERNEL);
583 pr_err("alg: aead: Failed to allocate request for %s\n",
588 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
589 crypto_req_done, &wait);
596 memset(assoc, 0xff, aad_size);
598 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
599 pr_err("template (%u) too big for tvmem (%lu)\n",
601 TVMEMSIZE * PAGE_SIZE);
606 for (j = 0; j < tcount; j++) {
607 if (template[j].klen == *keysize) {
608 key = template[j].key;
612 ret = crypto_aead_setkey(tfm, key, *keysize);
613 ret = crypto_aead_setauthsize(tfm, authsize);
615 iv_len = crypto_aead_ivsize(tfm);
617 memset(iv, 0xff, iv_len);
619 crypto_aead_clear_flags(tfm, ~0);
620 printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
621 i, *keysize * 8, *b_size);
624 memset(tvmem[0], 0xff, PAGE_SIZE);
627 pr_err("setkey() failed flags=%x\n",
628 crypto_aead_get_flags(tfm));
632 sg_init_aead(sg, xbuf, *b_size + (enc ? 0 : authsize),
635 sg_init_aead(sgout, xoutbuf,
636 *b_size + (enc ? authsize : 0), assoc,
639 aead_request_set_ad(req, aad_size);
644 * For decryption we need a proper auth so
645 * we do the encryption path once with buffers
646 * reversed (input <-> output) to calculate it
648 aead_request_set_crypt(req, sgout, sg,
650 ret = do_one_aead_op(req,
651 crypto_aead_encrypt(req));
654 pr_err("calculating auth failed failed (%d)\n",
660 aead_request_set_crypt(req, sg, sgout,
661 *b_size + (enc ? 0 : authsize),
665 ret = test_aead_jiffies(req, enc, *b_size,
669 ret = test_aead_cycles(req, enc, *b_size);
673 pr_err("%s() failed return code=%d\n", e, ret);
683 aead_request_free(req);
685 crypto_free_aead(tfm);
689 testmgr_free_buf(xoutbuf);
691 testmgr_free_buf(axbuf);
693 testmgr_free_buf(xbuf);
698 static void test_hash_sg_init(struct scatterlist *sg)
702 sg_init_table(sg, TVMEMSIZE);
703 for (i = 0; i < TVMEMSIZE; i++) {
704 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
705 memset(tvmem[i], 0xff, PAGE_SIZE);
709 static inline int do_one_ahash_op(struct ahash_request *req, int ret)
711 struct crypto_wait *wait = req->base.data;
713 return crypto_wait_req(ret, wait);
716 struct test_mb_ahash_data {
717 struct scatterlist sg[XBUFSIZE];
719 struct ahash_request *req;
720 struct crypto_wait wait;
721 char *xbuf[XBUFSIZE];
724 static inline int do_mult_ahash_op(struct test_mb_ahash_data *data, u32 num_mb,
729 /* Fire up a bunch of concurrent requests */
730 for (i = 0; i < num_mb; i++)
731 rc[i] = crypto_ahash_digest(data[i].req);
733 /* Wait for all requests to finish */
734 for (i = 0; i < num_mb; i++) {
735 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
738 pr_info("concurrent request %d error %d\n", i, rc[i]);
746 static int test_mb_ahash_jiffies(struct test_mb_ahash_data *data, int blen,
747 int secs, u32 num_mb)
749 unsigned long start, end;
754 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
758 for (start = jiffies, end = start + secs * HZ, bcount = 0;
759 time_before(jiffies, end); bcount++) {
760 ret = do_mult_ahash_op(data, num_mb, rc);
765 pr_cont("%d operations in %d seconds (%ld bytes)\n",
766 bcount * num_mb, secs, (long)bcount * blen * num_mb);
773 static int test_mb_ahash_cycles(struct test_mb_ahash_data *data, int blen,
776 unsigned long cycles = 0;
781 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
786 for (i = 0; i < 4; i++) {
787 ret = do_mult_ahash_op(data, num_mb, rc);
792 /* The real thing. */
793 for (i = 0; i < 8; i++) {
796 start = get_cycles();
797 ret = do_mult_ahash_op(data, num_mb, rc);
803 cycles += end - start;
806 pr_cont("1 operation in %lu cycles (%d bytes)\n",
807 (cycles + 4) / (8 * num_mb), blen);
814 static void test_mb_ahash_speed(const char *algo, unsigned int secs,
815 struct hash_speed *speed, u32 num_mb)
817 struct test_mb_ahash_data *data;
818 struct crypto_ahash *tfm;
819 unsigned int i, j, k;
822 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
826 tfm = crypto_alloc_ahash(algo, 0, 0);
828 pr_err("failed to load transform for %s: %ld\n",
833 for (i = 0; i < num_mb; ++i) {
834 if (testmgr_alloc_buf(data[i].xbuf))
837 crypto_init_wait(&data[i].wait);
839 data[i].req = ahash_request_alloc(tfm, GFP_KERNEL);
841 pr_err("alg: hash: Failed to allocate request for %s\n",
846 ahash_request_set_callback(data[i].req, 0, crypto_req_done,
849 sg_init_table(data[i].sg, XBUFSIZE);
850 for (j = 0; j < XBUFSIZE; j++) {
851 sg_set_buf(data[i].sg + j, data[i].xbuf[j], PAGE_SIZE);
852 memset(data[i].xbuf[j], 0xff, PAGE_SIZE);
856 pr_info("\ntesting speed of multibuffer %s (%s)\n", algo,
857 get_driver_name(crypto_ahash, tfm));
859 for (i = 0; speed[i].blen != 0; i++) {
860 /* For some reason this only tests digests. */
861 if (speed[i].blen != speed[i].plen)
864 if (speed[i].blen > XBUFSIZE * PAGE_SIZE) {
865 pr_err("template (%u) too big for tvmem (%lu)\n",
866 speed[i].blen, XBUFSIZE * PAGE_SIZE);
871 crypto_ahash_setkey(tfm, tvmem[0], speed[i].klen);
873 for (k = 0; k < num_mb; k++)
874 ahash_request_set_crypt(data[k].req, data[k].sg,
875 data[k].result, speed[i].blen);
878 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
879 i, speed[i].blen, speed[i].plen,
880 speed[i].blen / speed[i].plen);
883 ret = test_mb_ahash_jiffies(data, speed[i].blen, secs,
887 ret = test_mb_ahash_cycles(data, speed[i].blen, num_mb);
892 pr_err("At least one hashing failed ret=%d\n", ret);
898 for (k = 0; k < num_mb; ++k)
899 ahash_request_free(data[k].req);
901 for (k = 0; k < num_mb; ++k)
902 testmgr_free_buf(data[k].xbuf);
904 crypto_free_ahash(tfm);
910 static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
913 unsigned long start, end;
917 for (start = jiffies, end = start + secs * HZ, bcount = 0;
918 time_before(jiffies, end); bcount++) {
919 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
924 printk("%6u opers/sec, %9lu bytes/sec\n",
925 bcount / secs, ((long)bcount * blen) / secs);
930 static int test_ahash_jiffies(struct ahash_request *req, int blen,
931 int plen, char *out, int secs)
933 unsigned long start, end;
938 return test_ahash_jiffies_digest(req, blen, out, secs);
940 for (start = jiffies, end = start + secs * HZ, bcount = 0;
941 time_before(jiffies, end); bcount++) {
942 ret = do_one_ahash_op(req, crypto_ahash_init(req));
945 for (pcount = 0; pcount < blen; pcount += plen) {
946 ret = do_one_ahash_op(req, crypto_ahash_update(req));
950 /* we assume there is enough space in 'out' for the result */
951 ret = do_one_ahash_op(req, crypto_ahash_final(req));
956 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
957 bcount / secs, ((long)bcount * blen) / secs);
962 static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
965 unsigned long cycles = 0;
969 for (i = 0; i < 4; i++) {
970 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
975 /* The real thing. */
976 for (i = 0; i < 8; i++) {
979 start = get_cycles();
981 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
987 cycles += end - start;
994 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
995 cycles / 8, cycles / (8 * blen));
1000 static int test_ahash_cycles(struct ahash_request *req, int blen,
1001 int plen, char *out)
1003 unsigned long cycles = 0;
1007 return test_ahash_cycles_digest(req, blen, out);
1010 for (i = 0; i < 4; i++) {
1011 ret = do_one_ahash_op(req, crypto_ahash_init(req));
1014 for (pcount = 0; pcount < blen; pcount += plen) {
1015 ret = do_one_ahash_op(req, crypto_ahash_update(req));
1019 ret = do_one_ahash_op(req, crypto_ahash_final(req));
1024 /* The real thing. */
1025 for (i = 0; i < 8; i++) {
1026 cycles_t start, end;
1028 start = get_cycles();
1030 ret = do_one_ahash_op(req, crypto_ahash_init(req));
1033 for (pcount = 0; pcount < blen; pcount += plen) {
1034 ret = do_one_ahash_op(req, crypto_ahash_update(req));
1038 ret = do_one_ahash_op(req, crypto_ahash_final(req));
1044 cycles += end - start;
1051 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
1052 cycles / 8, cycles / (8 * blen));
1057 static void test_ahash_speed_common(const char *algo, unsigned int secs,
1058 struct hash_speed *speed, unsigned mask)
1060 struct scatterlist sg[TVMEMSIZE];
1061 struct crypto_wait wait;
1062 struct ahash_request *req;
1063 struct crypto_ahash *tfm;
1067 tfm = crypto_alloc_ahash(algo, 0, mask);
1069 pr_err("failed to load transform for %s: %ld\n",
1070 algo, PTR_ERR(tfm));
1074 printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
1075 get_driver_name(crypto_ahash, tfm));
1077 if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) {
1078 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm),
1083 test_hash_sg_init(sg);
1084 req = ahash_request_alloc(tfm, GFP_KERNEL);
1086 pr_err("ahash request allocation failure\n");
1090 crypto_init_wait(&wait);
1091 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1092 crypto_req_done, &wait);
1094 output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
1098 for (i = 0; speed[i].blen != 0; i++) {
1099 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
1100 pr_err("template (%u) too big for tvmem (%lu)\n",
1101 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
1106 crypto_ahash_setkey(tfm, tvmem[0], speed[i].klen);
1109 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
1110 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
1112 ahash_request_set_crypt(req, sg, output, speed[i].plen);
1115 ret = test_ahash_jiffies(req, speed[i].blen,
1116 speed[i].plen, output, secs);
1119 ret = test_ahash_cycles(req, speed[i].blen,
1120 speed[i].plen, output);
1124 pr_err("hashing failed ret=%d\n", ret);
1132 ahash_request_free(req);
1135 crypto_free_ahash(tfm);
1138 static void test_ahash_speed(const char *algo, unsigned int secs,
1139 struct hash_speed *speed)
1141 return test_ahash_speed_common(algo, secs, speed, 0);
1144 static void test_hash_speed(const char *algo, unsigned int secs,
1145 struct hash_speed *speed)
1147 return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC);
1150 struct test_mb_skcipher_data {
1151 struct scatterlist sg[XBUFSIZE];
1152 struct skcipher_request *req;
1153 struct crypto_wait wait;
1154 char *xbuf[XBUFSIZE];
1157 static int do_mult_acipher_op(struct test_mb_skcipher_data *data, int enc,
1158 u32 num_mb, int *rc)
1162 /* Fire up a bunch of concurrent requests */
1163 for (i = 0; i < num_mb; i++) {
1165 rc[i] = crypto_skcipher_encrypt(data[i].req);
1167 rc[i] = crypto_skcipher_decrypt(data[i].req);
1170 /* Wait for all requests to finish */
1171 for (i = 0; i < num_mb; i++) {
1172 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
1175 pr_info("concurrent request %d error %d\n", i, rc[i]);
1183 static int test_mb_acipher_jiffies(struct test_mb_skcipher_data *data, int enc,
1184 int blen, int secs, u32 num_mb)
1186 unsigned long start, end;
1191 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
1195 for (start = jiffies, end = start + secs * HZ, bcount = 0;
1196 time_before(jiffies, end); bcount++) {
1197 ret = do_mult_acipher_op(data, enc, num_mb, rc);
1202 pr_cont("%d operations in %d seconds (%ld bytes)\n",
1203 bcount * num_mb, secs, (long)bcount * blen * num_mb);
1210 static int test_mb_acipher_cycles(struct test_mb_skcipher_data *data, int enc,
1211 int blen, u32 num_mb)
1213 unsigned long cycles = 0;
1218 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
1223 for (i = 0; i < 4; i++) {
1224 ret = do_mult_acipher_op(data, enc, num_mb, rc);
1229 /* The real thing. */
1230 for (i = 0; i < 8; i++) {
1231 cycles_t start, end;
1233 start = get_cycles();
1234 ret = do_mult_acipher_op(data, enc, num_mb, rc);
1240 cycles += end - start;
1243 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1244 (cycles + 4) / (8 * num_mb), blen);
1251 static void test_mb_skcipher_speed(const char *algo, int enc, int secs,
1252 struct cipher_speed_template *template,
1253 unsigned int tcount, u8 *keysize, u32 num_mb)
1255 struct test_mb_skcipher_data *data;
1256 struct crypto_skcipher *tfm;
1257 unsigned int i, j, iv_len;
1269 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
1273 tfm = crypto_alloc_skcipher(algo, 0, 0);
1275 pr_err("failed to load transform for %s: %ld\n",
1276 algo, PTR_ERR(tfm));
1280 for (i = 0; i < num_mb; ++i)
1281 if (testmgr_alloc_buf(data[i].xbuf)) {
1283 testmgr_free_buf(data[i].xbuf);
1288 for (i = 0; i < num_mb; ++i)
1289 if (testmgr_alloc_buf(data[i].xbuf)) {
1291 testmgr_free_buf(data[i].xbuf);
1296 for (i = 0; i < num_mb; ++i) {
1297 data[i].req = skcipher_request_alloc(tfm, GFP_KERNEL);
1299 pr_err("alg: skcipher: Failed to allocate request for %s\n",
1302 skcipher_request_free(data[i].req);
1307 for (i = 0; i < num_mb; ++i) {
1308 skcipher_request_set_callback(data[i].req,
1309 CRYPTO_TFM_REQ_MAY_BACKLOG,
1310 crypto_req_done, &data[i].wait);
1311 crypto_init_wait(&data[i].wait);
1314 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo,
1315 get_driver_name(crypto_skcipher, tfm), e);
1319 b_size = block_sizes;
1321 if (*b_size > XBUFSIZE * PAGE_SIZE) {
1322 pr_err("template (%u) too big for buffer (%lu)\n",
1323 *b_size, XBUFSIZE * PAGE_SIZE);
1327 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1328 *keysize * 8, *b_size);
1330 /* Set up tfm global state, i.e. the key */
1332 memset(tvmem[0], 0xff, PAGE_SIZE);
1334 for (j = 0; j < tcount; j++) {
1335 if (template[j].klen == *keysize) {
1336 key = template[j].key;
1341 crypto_skcipher_clear_flags(tfm, ~0);
1343 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1345 pr_err("setkey() failed flags=%x\n",
1346 crypto_skcipher_get_flags(tfm));
1350 iv_len = crypto_skcipher_ivsize(tfm);
1352 memset(&iv, 0xff, iv_len);
1354 /* Now setup per request stuff, i.e. buffers */
1356 for (j = 0; j < num_mb; ++j) {
1357 struct test_mb_skcipher_data *cur = &data[j];
1358 unsigned int k = *b_size;
1359 unsigned int pages = DIV_ROUND_UP(k, PAGE_SIZE);
1362 sg_init_table(cur->sg, pages);
1364 while (k > PAGE_SIZE) {
1365 sg_set_buf(cur->sg + p, cur->xbuf[p],
1367 memset(cur->xbuf[p], 0xff, PAGE_SIZE);
1372 sg_set_buf(cur->sg + p, cur->xbuf[p], k);
1373 memset(cur->xbuf[p], 0xff, k);
1375 skcipher_request_set_crypt(cur->req, cur->sg,
1381 ret = test_mb_acipher_jiffies(data, enc,
1386 ret = test_mb_acipher_cycles(data, enc,
1391 pr_err("%s() failed flags=%x\n", e,
1392 crypto_skcipher_get_flags(tfm));
1402 for (i = 0; i < num_mb; ++i)
1403 skcipher_request_free(data[i].req);
1405 for (i = 0; i < num_mb; ++i)
1406 testmgr_free_buf(data[i].xbuf);
1408 crypto_free_skcipher(tfm);
1413 static inline int do_one_acipher_op(struct skcipher_request *req, int ret)
1415 struct crypto_wait *wait = req->base.data;
1417 return crypto_wait_req(ret, wait);
1420 static int test_acipher_jiffies(struct skcipher_request *req, int enc,
1423 unsigned long start, end;
1427 for (start = jiffies, end = start + secs * HZ, bcount = 0;
1428 time_before(jiffies, end); bcount++) {
1430 ret = do_one_acipher_op(req,
1431 crypto_skcipher_encrypt(req));
1433 ret = do_one_acipher_op(req,
1434 crypto_skcipher_decrypt(req));
1440 pr_cont("%d operations in %d seconds (%ld bytes)\n",
1441 bcount, secs, (long)bcount * blen);
1445 static int test_acipher_cycles(struct skcipher_request *req, int enc,
1448 unsigned long cycles = 0;
1453 for (i = 0; i < 4; i++) {
1455 ret = do_one_acipher_op(req,
1456 crypto_skcipher_encrypt(req));
1458 ret = do_one_acipher_op(req,
1459 crypto_skcipher_decrypt(req));
1465 /* The real thing. */
1466 for (i = 0; i < 8; i++) {
1467 cycles_t start, end;
1469 start = get_cycles();
1471 ret = do_one_acipher_op(req,
1472 crypto_skcipher_encrypt(req));
1474 ret = do_one_acipher_op(req,
1475 crypto_skcipher_decrypt(req));
1481 cycles += end - start;
1486 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1487 (cycles + 4) / 8, blen);
1492 static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
1493 struct cipher_speed_template *template,
1494 unsigned int tcount, u8 *keysize, bool async)
1496 unsigned int ret, i, j, k, iv_len;
1497 struct crypto_wait wait;
1500 struct skcipher_request *req;
1501 struct crypto_skcipher *tfm;
1510 crypto_init_wait(&wait);
1512 tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC);
1515 pr_err("failed to load transform for %s: %ld\n", algo,
1520 pr_info("\ntesting speed of async %s (%s) %s\n", algo,
1521 get_driver_name(crypto_skcipher, tfm), e);
1523 req = skcipher_request_alloc(tfm, GFP_KERNEL);
1525 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1530 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1531 crypto_req_done, &wait);
1535 b_size = block_sizes;
1538 struct scatterlist sg[TVMEMSIZE];
1540 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
1541 pr_err("template (%u) too big for "
1542 "tvmem (%lu)\n", *keysize + *b_size,
1543 TVMEMSIZE * PAGE_SIZE);
1547 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1548 *keysize * 8, *b_size);
1550 memset(tvmem[0], 0xff, PAGE_SIZE);
1552 /* set key, plain text and IV */
1554 for (j = 0; j < tcount; j++) {
1555 if (template[j].klen == *keysize) {
1556 key = template[j].key;
1561 crypto_skcipher_clear_flags(tfm, ~0);
1563 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1565 pr_err("setkey() failed flags=%x\n",
1566 crypto_skcipher_get_flags(tfm));
1570 k = *keysize + *b_size;
1571 sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
1573 if (k > PAGE_SIZE) {
1574 sg_set_buf(sg, tvmem[0] + *keysize,
1575 PAGE_SIZE - *keysize);
1578 while (k > PAGE_SIZE) {
1579 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
1580 memset(tvmem[j], 0xff, PAGE_SIZE);
1584 sg_set_buf(sg + j, tvmem[j], k);
1585 memset(tvmem[j], 0xff, k);
1587 sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
1590 iv_len = crypto_skcipher_ivsize(tfm);
1592 memset(&iv, 0xff, iv_len);
1594 skcipher_request_set_crypt(req, sg, sg, *b_size, iv);
1597 ret = test_acipher_jiffies(req, enc,
1601 ret = test_acipher_cycles(req, enc,
1606 pr_err("%s() failed flags=%x\n", e,
1607 crypto_skcipher_get_flags(tfm));
1617 skcipher_request_free(req);
1619 crypto_free_skcipher(tfm);
1622 static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
1623 struct cipher_speed_template *template,
1624 unsigned int tcount, u8 *keysize)
1626 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1630 static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
1631 struct cipher_speed_template *template,
1632 unsigned int tcount, u8 *keysize)
1634 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1638 static void test_available(void)
1640 char **name = check;
1643 printk("alg %s ", *name);
1644 printk(crypto_has_alg(*name, 0, 0) ?
1645 "found\n" : "not found\n");
1650 static inline int tcrypt_test(const char *alg)
1654 pr_debug("testing %s\n", alg);
1656 ret = alg_test(alg, alg, 0, 0);
1657 /* non-fips algs return -EINVAL in fips mode */
1658 if (fips_enabled && ret == -EINVAL)
1663 static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)
1671 if (!crypto_has_alg(alg, type,
1672 mask ?: CRYPTO_ALG_TYPE_MASK))
1677 for (i = 1; i < 200; i++)
1678 ret += do_test(NULL, 0, 0, i, num_mb);
1682 ret += tcrypt_test("md5");
1686 ret += tcrypt_test("sha1");
1690 ret += tcrypt_test("ecb(des)");
1691 ret += tcrypt_test("cbc(des)");
1692 ret += tcrypt_test("ctr(des)");
1696 ret += tcrypt_test("ecb(des3_ede)");
1697 ret += tcrypt_test("cbc(des3_ede)");
1698 ret += tcrypt_test("ctr(des3_ede)");
1702 ret += tcrypt_test("md4");
1706 ret += tcrypt_test("sha256");
1710 ret += tcrypt_test("ecb(blowfish)");
1711 ret += tcrypt_test("cbc(blowfish)");
1712 ret += tcrypt_test("ctr(blowfish)");
1716 ret += tcrypt_test("ecb(twofish)");
1717 ret += tcrypt_test("cbc(twofish)");
1718 ret += tcrypt_test("ctr(twofish)");
1719 ret += tcrypt_test("lrw(twofish)");
1720 ret += tcrypt_test("xts(twofish)");
1724 ret += tcrypt_test("ecb(serpent)");
1725 ret += tcrypt_test("cbc(serpent)");
1726 ret += tcrypt_test("ctr(serpent)");
1727 ret += tcrypt_test("lrw(serpent)");
1728 ret += tcrypt_test("xts(serpent)");
1732 ret += tcrypt_test("ecb(aes)");
1733 ret += tcrypt_test("cbc(aes)");
1734 ret += tcrypt_test("lrw(aes)");
1735 ret += tcrypt_test("xts(aes)");
1736 ret += tcrypt_test("ctr(aes)");
1737 ret += tcrypt_test("rfc3686(ctr(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("hmac(md5)");
1920 ret += tcrypt_test("hmac(sha1)");
1924 ret += tcrypt_test("hmac(sha256)");
1928 ret += tcrypt_test("hmac(sha384)");
1932 ret += tcrypt_test("hmac(sha512)");
1936 ret += tcrypt_test("hmac(sha224)");
1940 ret += tcrypt_test("xcbc(aes)");
1944 ret += tcrypt_test("hmac(rmd128)");
1948 ret += tcrypt_test("hmac(rmd160)");
1952 ret += tcrypt_test("vmac64(aes)");
1956 ret += tcrypt_test("hmac(sha3-224)");
1960 ret += tcrypt_test("hmac(sha3-256)");
1964 ret += tcrypt_test("hmac(sha3-384)");
1968 ret += tcrypt_test("hmac(sha3-512)");
1972 ret += tcrypt_test("ansi_cprng");
1976 ret += tcrypt_test("rfc4106(gcm(aes))");
1980 ret += tcrypt_test("rfc4543(gcm(aes))");
1984 ret += tcrypt_test("cmac(aes)");
1988 ret += tcrypt_test("cmac(des3_ede)");
1992 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1996 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
2000 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
2003 ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
2006 ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
2009 ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
2012 ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
2015 ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
2018 ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
2021 ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
2024 ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
2027 ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
2030 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
2033 ret += tcrypt_test("ecb(sm4)");
2034 ret += tcrypt_test("cbc(sm4)");
2035 ret += tcrypt_test("ctr(sm4)");
2038 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2039 speed_template_16_24_32);
2040 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2041 speed_template_16_24_32);
2042 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2043 speed_template_16_24_32);
2044 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2045 speed_template_16_24_32);
2046 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2047 speed_template_32_40_48);
2048 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2049 speed_template_32_40_48);
2050 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2051 speed_template_32_64);
2052 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2053 speed_template_32_64);
2054 test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2055 speed_template_16_24_32);
2056 test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2057 speed_template_16_24_32);
2058 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2059 speed_template_16_24_32);
2060 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2061 speed_template_16_24_32);
2065 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2066 des3_speed_template, DES3_SPEED_VECTORS,
2068 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
2069 des3_speed_template, DES3_SPEED_VECTORS,
2071 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2072 des3_speed_template, DES3_SPEED_VECTORS,
2074 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
2075 des3_speed_template, DES3_SPEED_VECTORS,
2077 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
2078 des3_speed_template, DES3_SPEED_VECTORS,
2080 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
2081 des3_speed_template, DES3_SPEED_VECTORS,
2086 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2087 speed_template_16_24_32);
2088 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2089 speed_template_16_24_32);
2090 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2091 speed_template_16_24_32);
2092 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2093 speed_template_16_24_32);
2094 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2095 speed_template_16_24_32);
2096 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2097 speed_template_16_24_32);
2098 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2099 speed_template_32_40_48);
2100 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2101 speed_template_32_40_48);
2102 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2103 speed_template_32_48_64);
2104 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2105 speed_template_32_48_64);
2109 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2110 speed_template_8_32);
2111 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2112 speed_template_8_32);
2113 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2114 speed_template_8_32);
2115 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2116 speed_template_8_32);
2117 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2118 speed_template_8_32);
2119 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2120 speed_template_8_32);
2124 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2126 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2128 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2130 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2135 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2136 speed_template_16_24_32);
2137 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2138 speed_template_16_24_32);
2139 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2140 speed_template_16_24_32);
2141 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2142 speed_template_16_24_32);
2143 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2144 speed_template_16_24_32);
2145 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2146 speed_template_16_24_32);
2147 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2148 speed_template_32_40_48);
2149 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2150 speed_template_32_40_48);
2151 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2152 speed_template_32_48_64);
2153 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2154 speed_template_32_48_64);
2158 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
2159 speed_template_16_32);
2163 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2164 speed_template_16_32);
2165 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2166 speed_template_16_32);
2167 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2168 speed_template_16_32);
2169 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2170 speed_template_16_32);
2171 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2172 speed_template_16_32);
2173 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2174 speed_template_16_32);
2175 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2176 speed_template_32_48);
2177 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2178 speed_template_32_48);
2179 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2180 speed_template_32_64);
2181 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2182 speed_template_32_64);
2186 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2191 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2192 speed_template_8_16);
2193 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2194 speed_template_8_16);
2195 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2196 speed_template_8_16);
2197 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2198 speed_template_8_16);
2199 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2200 speed_template_8_16);
2201 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2202 speed_template_8_16);
2206 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2207 speed_template_16_32);
2208 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2209 speed_template_16_32);
2210 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2211 speed_template_16_32);
2212 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2213 speed_template_16_32);
2214 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2215 speed_template_16_32);
2216 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2217 speed_template_16_32);
2218 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2219 speed_template_32_48);
2220 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2221 speed_template_32_48);
2222 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2223 speed_template_32_64);
2224 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2225 speed_template_32_64);
2229 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
2230 NULL, 0, 16, 16, aead_speed_template_20);
2231 test_aead_speed("gcm(aes)", ENCRYPT, sec,
2232 NULL, 0, 16, 8, speed_template_16_24_32);
2233 test_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec,
2234 NULL, 0, 16, 16, aead_speed_template_20);
2235 test_aead_speed("gcm(aes)", DECRYPT, sec,
2236 NULL, 0, 16, 8, speed_template_16_24_32);
2240 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
2241 NULL, 0, 16, 16, aead_speed_template_19);
2242 test_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec,
2243 NULL, 0, 16, 16, aead_speed_template_19);
2247 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
2248 NULL, 0, 16, 8, aead_speed_template_36);
2249 test_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT, sec,
2250 NULL, 0, 16, 8, aead_speed_template_36);
2254 test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
2259 test_mb_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec, NULL,
2260 0, 16, 16, aead_speed_template_20, num_mb);
2261 test_mb_aead_speed("gcm(aes)", ENCRYPT, sec, NULL, 0, 16, 8,
2262 speed_template_16_24_32, num_mb);
2263 test_mb_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec, NULL,
2264 0, 16, 16, aead_speed_template_20, num_mb);
2265 test_mb_aead_speed("gcm(aes)", DECRYPT, sec, NULL, 0, 16, 8,
2266 speed_template_16_24_32, num_mb);
2270 test_mb_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec, NULL, 0,
2271 16, 16, aead_speed_template_19, num_mb);
2272 test_mb_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec, NULL, 0,
2273 16, 16, aead_speed_template_19, num_mb);
2277 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT,
2278 sec, NULL, 0, 16, 8, aead_speed_template_36,
2280 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT,
2281 sec, NULL, 0, 16, 8, aead_speed_template_36,
2286 test_cipher_speed("ecb(sm4)", ENCRYPT, sec, NULL, 0,
2288 test_cipher_speed("ecb(sm4)", DECRYPT, sec, NULL, 0,
2290 test_cipher_speed("cbc(sm4)", ENCRYPT, sec, NULL, 0,
2292 test_cipher_speed("cbc(sm4)", DECRYPT, sec, NULL, 0,
2294 test_cipher_speed("ctr(sm4)", ENCRYPT, sec, NULL, 0,
2296 test_cipher_speed("ctr(sm4)", DECRYPT, sec, NULL, 0,
2301 test_hash_speed(alg, sec, generic_hash_speed_template);
2306 test_hash_speed("md4", sec, generic_hash_speed_template);
2307 if (mode > 300 && mode < 400) break;
2310 test_hash_speed("md5", sec, generic_hash_speed_template);
2311 if (mode > 300 && mode < 400) break;
2314 test_hash_speed("sha1", sec, generic_hash_speed_template);
2315 if (mode > 300 && mode < 400) break;
2318 test_hash_speed("sha256", sec, generic_hash_speed_template);
2319 if (mode > 300 && mode < 400) break;
2322 test_hash_speed("sha384", sec, generic_hash_speed_template);
2323 if (mode > 300 && mode < 400) break;
2326 test_hash_speed("sha512", sec, generic_hash_speed_template);
2327 if (mode > 300 && mode < 400) break;
2330 test_hash_speed("wp256", sec, generic_hash_speed_template);
2331 if (mode > 300 && mode < 400) break;
2334 test_hash_speed("wp384", sec, generic_hash_speed_template);
2335 if (mode > 300 && mode < 400) break;
2338 test_hash_speed("wp512", sec, generic_hash_speed_template);
2339 if (mode > 300 && mode < 400) break;
2342 test_hash_speed("tgr128", sec, generic_hash_speed_template);
2343 if (mode > 300 && mode < 400) break;
2346 test_hash_speed("tgr160", sec, generic_hash_speed_template);
2347 if (mode > 300 && mode < 400) break;
2350 test_hash_speed("tgr192", sec, generic_hash_speed_template);
2351 if (mode > 300 && mode < 400) break;
2354 test_hash_speed("sha224", sec, generic_hash_speed_template);
2355 if (mode > 300 && mode < 400) break;
2358 test_hash_speed("rmd128", sec, generic_hash_speed_template);
2359 if (mode > 300 && mode < 400) break;
2362 test_hash_speed("rmd160", sec, generic_hash_speed_template);
2363 if (mode > 300 && mode < 400) break;
2366 test_hash_speed("rmd256", sec, generic_hash_speed_template);
2367 if (mode > 300 && mode < 400) break;
2370 test_hash_speed("rmd320", sec, generic_hash_speed_template);
2371 if (mode > 300 && mode < 400) break;
2374 test_hash_speed("ghash-generic", sec, hash_speed_template_16);
2375 if (mode > 300 && mode < 400) break;
2378 test_hash_speed("crc32c", sec, generic_hash_speed_template);
2379 if (mode > 300 && mode < 400) break;
2382 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
2383 if (mode > 300 && mode < 400) break;
2386 test_hash_speed("poly1305", sec, poly1305_speed_template);
2387 if (mode > 300 && mode < 400) break;
2390 test_hash_speed("sha3-224", sec, generic_hash_speed_template);
2391 if (mode > 300 && mode < 400) break;
2394 test_hash_speed("sha3-256", sec, generic_hash_speed_template);
2395 if (mode > 300 && mode < 400) break;
2398 test_hash_speed("sha3-384", sec, generic_hash_speed_template);
2399 if (mode > 300 && mode < 400) break;
2402 test_hash_speed("sha3-512", sec, generic_hash_speed_template);
2403 if (mode > 300 && mode < 400) break;
2406 test_hash_speed("sm3", sec, generic_hash_speed_template);
2407 if (mode > 300 && mode < 400) break;
2414 test_ahash_speed(alg, sec, generic_hash_speed_template);
2419 test_ahash_speed("md4", sec, generic_hash_speed_template);
2420 if (mode > 400 && mode < 500) break;
2423 test_ahash_speed("md5", sec, generic_hash_speed_template);
2424 if (mode > 400 && mode < 500) break;
2427 test_ahash_speed("sha1", sec, generic_hash_speed_template);
2428 if (mode > 400 && mode < 500) break;
2431 test_ahash_speed("sha256", sec, generic_hash_speed_template);
2432 if (mode > 400 && mode < 500) break;
2435 test_ahash_speed("sha384", sec, generic_hash_speed_template);
2436 if (mode > 400 && mode < 500) break;
2439 test_ahash_speed("sha512", sec, generic_hash_speed_template);
2440 if (mode > 400 && mode < 500) break;
2443 test_ahash_speed("wp256", sec, generic_hash_speed_template);
2444 if (mode > 400 && mode < 500) break;
2447 test_ahash_speed("wp384", sec, generic_hash_speed_template);
2448 if (mode > 400 && mode < 500) break;
2451 test_ahash_speed("wp512", sec, generic_hash_speed_template);
2452 if (mode > 400 && mode < 500) break;
2455 test_ahash_speed("tgr128", sec, generic_hash_speed_template);
2456 if (mode > 400 && mode < 500) break;
2459 test_ahash_speed("tgr160", sec, generic_hash_speed_template);
2460 if (mode > 400 && mode < 500) break;
2463 test_ahash_speed("tgr192", sec, generic_hash_speed_template);
2464 if (mode > 400 && mode < 500) break;
2467 test_ahash_speed("sha224", sec, generic_hash_speed_template);
2468 if (mode > 400 && mode < 500) break;
2471 test_ahash_speed("rmd128", sec, generic_hash_speed_template);
2472 if (mode > 400 && mode < 500) break;
2475 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
2476 if (mode > 400 && mode < 500) break;
2479 test_ahash_speed("rmd256", sec, generic_hash_speed_template);
2480 if (mode > 400 && mode < 500) break;
2483 test_ahash_speed("rmd320", sec, generic_hash_speed_template);
2484 if (mode > 400 && mode < 500) break;
2487 test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
2488 if (mode > 400 && mode < 500) break;
2491 test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
2492 if (mode > 400 && mode < 500) break;
2495 test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
2496 if (mode > 400 && mode < 500) break;
2499 test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
2500 if (mode > 400 && mode < 500) break;
2503 test_mb_ahash_speed("sha1", sec, generic_hash_speed_template,
2505 if (mode > 400 && mode < 500) break;
2508 test_mb_ahash_speed("sha256", sec, generic_hash_speed_template,
2510 if (mode > 400 && mode < 500) break;
2513 test_mb_ahash_speed("sha512", sec, generic_hash_speed_template,
2515 if (mode > 400 && mode < 500) break;
2518 test_mb_ahash_speed("sm3", sec, generic_hash_speed_template,
2520 if (mode > 400 && mode < 500) break;
2526 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2527 speed_template_16_24_32);
2528 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2529 speed_template_16_24_32);
2530 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2531 speed_template_16_24_32);
2532 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2533 speed_template_16_24_32);
2534 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2535 speed_template_32_40_48);
2536 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2537 speed_template_32_40_48);
2538 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2539 speed_template_32_64);
2540 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2541 speed_template_32_64);
2542 test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2543 speed_template_16_24_32);
2544 test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2545 speed_template_16_24_32);
2546 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2547 speed_template_16_24_32);
2548 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2549 speed_template_16_24_32);
2550 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2551 speed_template_16_24_32);
2552 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2553 speed_template_16_24_32);
2554 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2555 speed_template_16_24_32);
2556 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2557 speed_template_16_24_32);
2558 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
2559 speed_template_20_28_36);
2560 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
2561 speed_template_20_28_36);
2565 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2566 des3_speed_template, DES3_SPEED_VECTORS,
2568 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
2569 des3_speed_template, DES3_SPEED_VECTORS,
2571 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2572 des3_speed_template, DES3_SPEED_VECTORS,
2574 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
2575 des3_speed_template, DES3_SPEED_VECTORS,
2577 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2578 des3_speed_template, DES3_SPEED_VECTORS,
2580 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
2581 des3_speed_template, DES3_SPEED_VECTORS,
2583 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2584 des3_speed_template, DES3_SPEED_VECTORS,
2586 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
2587 des3_speed_template, DES3_SPEED_VECTORS,
2592 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2594 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2596 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2598 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2600 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2602 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2604 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2606 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2611 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2612 speed_template_16_32);
2613 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2614 speed_template_16_32);
2615 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2616 speed_template_16_32);
2617 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2618 speed_template_16_32);
2619 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2620 speed_template_16_32);
2621 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2622 speed_template_16_32);
2623 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2624 speed_template_32_48);
2625 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2626 speed_template_32_48);
2627 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2628 speed_template_32_64);
2629 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2630 speed_template_32_64);
2634 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2635 speed_template_16_24_32);
2636 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2637 speed_template_16_24_32);
2638 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2639 speed_template_16_24_32);
2640 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2641 speed_template_16_24_32);
2642 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2643 speed_template_16_24_32);
2644 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2645 speed_template_16_24_32);
2646 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2647 speed_template_32_40_48);
2648 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2649 speed_template_32_40_48);
2650 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2651 speed_template_32_48_64);
2652 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2653 speed_template_32_48_64);
2657 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2662 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2663 speed_template_8_16);
2664 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2665 speed_template_8_16);
2666 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2667 speed_template_8_16);
2668 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2669 speed_template_8_16);
2670 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2671 speed_template_8_16);
2672 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2673 speed_template_8_16);
2677 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2678 speed_template_16_32);
2679 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2680 speed_template_16_32);
2681 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2682 speed_template_16_32);
2683 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2684 speed_template_16_32);
2685 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2686 speed_template_16_32);
2687 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2688 speed_template_16_32);
2689 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2690 speed_template_32_48);
2691 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2692 speed_template_32_48);
2693 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2694 speed_template_32_64);
2695 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2696 speed_template_32_64);
2700 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2701 speed_template_16_32);
2702 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2703 speed_template_16_32);
2704 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2705 speed_template_16_32);
2706 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2707 speed_template_16_32);
2708 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2709 speed_template_16_32);
2710 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2711 speed_template_16_32);
2712 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2713 speed_template_32_48);
2714 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2715 speed_template_32_48);
2716 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2717 speed_template_32_64);
2718 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2719 speed_template_32_64);
2723 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2724 speed_template_8_32);
2725 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2726 speed_template_8_32);
2727 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2728 speed_template_8_32);
2729 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2730 speed_template_8_32);
2731 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2732 speed_template_8_32);
2733 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2734 speed_template_8_32);
2738 test_mb_skcipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2739 speed_template_16_24_32, num_mb);
2740 test_mb_skcipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2741 speed_template_16_24_32, num_mb);
2742 test_mb_skcipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2743 speed_template_16_24_32, num_mb);
2744 test_mb_skcipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2745 speed_template_16_24_32, num_mb);
2746 test_mb_skcipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2747 speed_template_32_40_48, num_mb);
2748 test_mb_skcipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2749 speed_template_32_40_48, num_mb);
2750 test_mb_skcipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2751 speed_template_32_64, num_mb);
2752 test_mb_skcipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2753 speed_template_32_64, num_mb);
2754 test_mb_skcipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2755 speed_template_16_24_32, num_mb);
2756 test_mb_skcipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2757 speed_template_16_24_32, num_mb);
2758 test_mb_skcipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2759 speed_template_16_24_32, num_mb);
2760 test_mb_skcipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2761 speed_template_16_24_32, num_mb);
2762 test_mb_skcipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2763 speed_template_16_24_32, num_mb);
2764 test_mb_skcipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2765 speed_template_16_24_32, num_mb);
2766 test_mb_skcipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2767 speed_template_16_24_32, num_mb);
2768 test_mb_skcipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2769 speed_template_16_24_32, num_mb);
2770 test_mb_skcipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL,
2771 0, speed_template_20_28_36, num_mb);
2772 test_mb_skcipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL,
2773 0, speed_template_20_28_36, num_mb);
2777 test_mb_skcipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2778 des3_speed_template, DES3_SPEED_VECTORS,
2779 speed_template_24, num_mb);
2780 test_mb_skcipher_speed("ecb(des3_ede)", DECRYPT, sec,
2781 des3_speed_template, DES3_SPEED_VECTORS,
2782 speed_template_24, num_mb);
2783 test_mb_skcipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2784 des3_speed_template, DES3_SPEED_VECTORS,
2785 speed_template_24, num_mb);
2786 test_mb_skcipher_speed("cbc(des3_ede)", DECRYPT, sec,
2787 des3_speed_template, DES3_SPEED_VECTORS,
2788 speed_template_24, num_mb);
2789 test_mb_skcipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2790 des3_speed_template, DES3_SPEED_VECTORS,
2791 speed_template_24, num_mb);
2792 test_mb_skcipher_speed("cfb(des3_ede)", DECRYPT, sec,
2793 des3_speed_template, DES3_SPEED_VECTORS,
2794 speed_template_24, num_mb);
2795 test_mb_skcipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2796 des3_speed_template, DES3_SPEED_VECTORS,
2797 speed_template_24, num_mb);
2798 test_mb_skcipher_speed("ofb(des3_ede)", DECRYPT, sec,
2799 des3_speed_template, DES3_SPEED_VECTORS,
2800 speed_template_24, num_mb);
2804 test_mb_skcipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2805 speed_template_8, num_mb);
2806 test_mb_skcipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2807 speed_template_8, num_mb);
2808 test_mb_skcipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2809 speed_template_8, num_mb);
2810 test_mb_skcipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2811 speed_template_8, num_mb);
2812 test_mb_skcipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2813 speed_template_8, num_mb);
2814 test_mb_skcipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2815 speed_template_8, num_mb);
2816 test_mb_skcipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2817 speed_template_8, num_mb);
2818 test_mb_skcipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2819 speed_template_8, num_mb);
2823 test_mb_skcipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2824 speed_template_16_32, num_mb);
2825 test_mb_skcipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2826 speed_template_16_32, num_mb);
2827 test_mb_skcipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2828 speed_template_16_32, num_mb);
2829 test_mb_skcipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2830 speed_template_16_32, num_mb);
2831 test_mb_skcipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2832 speed_template_16_32, num_mb);
2833 test_mb_skcipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2834 speed_template_16_32, num_mb);
2835 test_mb_skcipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2836 speed_template_32_48, num_mb);
2837 test_mb_skcipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2838 speed_template_32_48, num_mb);
2839 test_mb_skcipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2840 speed_template_32_64, num_mb);
2841 test_mb_skcipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2842 speed_template_32_64, num_mb);
2846 test_mb_skcipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2847 speed_template_16_24_32, num_mb);
2848 test_mb_skcipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2849 speed_template_16_24_32, num_mb);
2850 test_mb_skcipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2851 speed_template_16_24_32, num_mb);
2852 test_mb_skcipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2853 speed_template_16_24_32, num_mb);
2854 test_mb_skcipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2855 speed_template_16_24_32, num_mb);
2856 test_mb_skcipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2857 speed_template_16_24_32, num_mb);
2858 test_mb_skcipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2859 speed_template_32_40_48, num_mb);
2860 test_mb_skcipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2861 speed_template_32_40_48, num_mb);
2862 test_mb_skcipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2863 speed_template_32_48_64, num_mb);
2864 test_mb_skcipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2865 speed_template_32_48_64, num_mb);
2869 test_mb_skcipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2870 speed_template_8, num_mb);
2874 test_mb_skcipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2875 speed_template_8_16, num_mb);
2876 test_mb_skcipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2877 speed_template_8_16, num_mb);
2878 test_mb_skcipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2879 speed_template_8_16, num_mb);
2880 test_mb_skcipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2881 speed_template_8_16, num_mb);
2882 test_mb_skcipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2883 speed_template_8_16, num_mb);
2884 test_mb_skcipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2885 speed_template_8_16, num_mb);
2889 test_mb_skcipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2890 speed_template_16_32, num_mb);
2891 test_mb_skcipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2892 speed_template_16_32, num_mb);
2893 test_mb_skcipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2894 speed_template_16_32, num_mb);
2895 test_mb_skcipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2896 speed_template_16_32, num_mb);
2897 test_mb_skcipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2898 speed_template_16_32, num_mb);
2899 test_mb_skcipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2900 speed_template_16_32, num_mb);
2901 test_mb_skcipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2902 speed_template_32_48, num_mb);
2903 test_mb_skcipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2904 speed_template_32_48, num_mb);
2905 test_mb_skcipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2906 speed_template_32_64, num_mb);
2907 test_mb_skcipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2908 speed_template_32_64, num_mb);
2912 test_mb_skcipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2913 speed_template_16_32, num_mb);
2914 test_mb_skcipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2915 speed_template_16_32, num_mb);
2916 test_mb_skcipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2917 speed_template_16_32, num_mb);
2918 test_mb_skcipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2919 speed_template_16_32, num_mb);
2920 test_mb_skcipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2921 speed_template_16_32, num_mb);
2922 test_mb_skcipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2923 speed_template_16_32, num_mb);
2924 test_mb_skcipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2925 speed_template_32_48, num_mb);
2926 test_mb_skcipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2927 speed_template_32_48, num_mb);
2928 test_mb_skcipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2929 speed_template_32_64, num_mb);
2930 test_mb_skcipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2931 speed_template_32_64, num_mb);
2935 test_mb_skcipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2936 speed_template_8_32, num_mb);
2937 test_mb_skcipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2938 speed_template_8_32, num_mb);
2939 test_mb_skcipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2940 speed_template_8_32, num_mb);
2941 test_mb_skcipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2942 speed_template_8_32, num_mb);
2943 test_mb_skcipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2944 speed_template_8_32, num_mb);
2945 test_mb_skcipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2946 speed_template_8_32, num_mb);
2957 static int __init tcrypt_mod_init(void)
2962 for (i = 0; i < TVMEMSIZE; i++) {
2963 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
2968 err = do_test(alg, type, mask, mode, num_mb);
2971 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
2974 pr_debug("all tests passed\n");
2977 /* We intentionaly return -EAGAIN to prevent keeping the module,
2978 * unless we're running in fips mode. It does all its work from
2979 * init() and doesn't offer any runtime functionality, but in
2980 * the fips case, checking for a successful load is helpful.
2981 * => we don't need it in the memory, do we?
2988 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
2989 free_page((unsigned long)tvmem[i]);
2995 * If an init function is provided, an exit function must also be provided
2996 * to allow module unload.
2998 static void __exit tcrypt_mod_fini(void) { }
3000 module_init(tcrypt_mod_init);
3001 module_exit(tcrypt_mod_fini);
3003 module_param(alg, charp, 0);
3004 module_param(type, uint, 0);
3005 module_param(mask, uint, 0);
3006 module_param(mode, int, 0);
3007 module_param(sec, uint, 0);
3008 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
3009 "(defaults to zero which uses CPU cycles instead)");
3010 module_param(num_mb, uint, 0000);
3011 MODULE_PARM_DESC(num_mb, "Number of concurrent requests to be used in mb speed tests (defaults to 8)");
3013 MODULE_LICENSE("GPL");
3014 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
3015 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");