1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Quick & dirty crypto testing module.
5 * This will only exist until we have a better testing mechanism
6 * (e.g. a char device).
8 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
9 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
10 * Copyright (c) 2007 Nokia Siemens Networks
12 * Updated RFC4106 AES-GCM testing.
13 * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
14 * Adrian Hoban <adrian.hoban@intel.com>
15 * Gabriele Paoloni <gabriele.paoloni@intel.com>
16 * Tadeusz Struk (tadeusz.struk@intel.com)
17 * Copyright (c) 2010, Intel Corporation.
20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22 #include <crypto/aead.h>
23 #include <crypto/hash.h>
24 #include <crypto/skcipher.h>
25 #include <linux/err.h>
26 #include <linux/fips.h>
27 #include <linux/init.h>
28 #include <linux/gfp.h>
29 #include <linux/module.h>
30 #include <linux/scatterlist.h>
31 #include <linux/string.h>
32 #include <linux/moduleparam.h>
33 #include <linux/jiffies.h>
34 #include <linux/timex.h>
35 #include <linux/interrupt.h>
39 * Need slab memory for testing (size in number of pages).
44 * Used by test_cipher_speed()
49 #define MAX_DIGEST_SIZE 64
52 * return a string with the driver name
54 #define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm))
57 * Used by test_cipher_speed()
59 static unsigned int sec;
61 static char *alg = NULL;
65 static u32 num_mb = 8;
66 static char *tvmem[TVMEMSIZE];
68 static char *check[] = {
69 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", "sm3",
70 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
71 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
72 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
73 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
74 "lzo", "lzo-rle", "cts", "sha3-224", "sha3-256", "sha3-384",
75 "sha3-512", "streebog256", "streebog512",
79 static u32 block_sizes[] = { 16, 64, 256, 1024, 1472, 8192, 0 };
80 static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
85 static int testmgr_alloc_buf(char *buf[XBUFSIZE])
89 for (i = 0; i < XBUFSIZE; i++) {
90 buf[i] = (void *)__get_free_page(GFP_KERNEL);
99 free_page((unsigned long)buf[i]);
104 static void testmgr_free_buf(char *buf[XBUFSIZE])
108 for (i = 0; i < XBUFSIZE; i++)
109 free_page((unsigned long)buf[i]);
112 static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],
113 unsigned int buflen, const void *assoc,
114 unsigned int aad_size)
116 int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
123 rem = buflen % PAGE_SIZE;
126 sg_init_table(sg, np + 1);
128 sg_set_buf(&sg[0], assoc, aad_size);
132 for (k = 0; k < np; k++)
133 sg_set_buf(&sg[k + 1], xbuf[k], PAGE_SIZE);
136 sg_set_buf(&sg[k + 1], xbuf[k], rem);
139 static inline int do_one_aead_op(struct aead_request *req, int ret)
141 struct crypto_wait *wait = req->base.data;
143 return crypto_wait_req(ret, wait);
146 struct test_mb_aead_data {
147 struct scatterlist sg[XBUFSIZE];
148 struct scatterlist sgout[XBUFSIZE];
149 struct aead_request *req;
150 struct crypto_wait wait;
151 char *xbuf[XBUFSIZE];
152 char *xoutbuf[XBUFSIZE];
153 char *axbuf[XBUFSIZE];
156 static int do_mult_aead_op(struct test_mb_aead_data *data, int enc,
161 /* Fire up a bunch of concurrent requests */
162 for (i = 0; i < num_mb; i++) {
164 rc[i] = crypto_aead_encrypt(data[i].req);
166 rc[i] = crypto_aead_decrypt(data[i].req);
169 /* Wait for all requests to finish */
170 for (i = 0; i < num_mb; i++) {
171 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
174 pr_info("concurrent request %d error %d\n", i, rc[i]);
182 static int test_mb_aead_jiffies(struct test_mb_aead_data *data, int enc,
183 int blen, int secs, u32 num_mb)
185 unsigned long start, end;
190 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
194 for (start = jiffies, end = start + secs * HZ, bcount = 0;
195 time_before(jiffies, end); bcount++) {
196 ret = do_mult_aead_op(data, enc, num_mb, rc);
201 pr_cont("%d operations in %d seconds (%ld bytes)\n",
202 bcount * num_mb, secs, (long)bcount * blen * num_mb);
209 static int test_mb_aead_cycles(struct test_mb_aead_data *data, int enc,
210 int blen, u32 num_mb)
212 unsigned long cycles = 0;
217 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
222 for (i = 0; i < 4; i++) {
223 ret = do_mult_aead_op(data, enc, num_mb, rc);
228 /* The real thing. */
229 for (i = 0; i < 8; i++) {
232 start = get_cycles();
233 ret = do_mult_aead_op(data, enc, num_mb, rc);
239 cycles += end - start;
242 pr_cont("1 operation in %lu cycles (%d bytes)\n",
243 (cycles + 4) / (8 * num_mb), blen);
250 static void test_mb_aead_speed(const char *algo, int enc, int secs,
251 struct aead_speed_template *template,
252 unsigned int tcount, u8 authsize,
253 unsigned int aad_size, u8 *keysize, u32 num_mb)
255 struct test_mb_aead_data *data;
256 struct crypto_aead *tfm;
257 unsigned int i, j, iv_len;
266 if (aad_size >= PAGE_SIZE) {
267 pr_err("associate data length (%u) too big\n", aad_size);
271 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
280 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
284 tfm = crypto_alloc_aead(algo, 0, 0);
286 pr_err("failed to load transform for %s: %ld\n",
291 ret = crypto_aead_setauthsize(tfm, authsize);
293 for (i = 0; i < num_mb; ++i)
294 if (testmgr_alloc_buf(data[i].xbuf)) {
296 testmgr_free_buf(data[i].xbuf);
300 for (i = 0; i < num_mb; ++i)
301 if (testmgr_alloc_buf(data[i].axbuf)) {
303 testmgr_free_buf(data[i].axbuf);
307 for (i = 0; i < num_mb; ++i)
308 if (testmgr_alloc_buf(data[i].xoutbuf)) {
310 testmgr_free_buf(data[i].xoutbuf);
314 for (i = 0; i < num_mb; ++i) {
315 data[i].req = aead_request_alloc(tfm, GFP_KERNEL);
317 pr_err("alg: skcipher: Failed to allocate request for %s\n",
320 aead_request_free(data[i].req);
321 goto out_free_xoutbuf;
325 for (i = 0; i < num_mb; ++i) {
326 crypto_init_wait(&data[i].wait);
327 aead_request_set_callback(data[i].req,
328 CRYPTO_TFM_REQ_MAY_BACKLOG,
329 crypto_req_done, &data[i].wait);
332 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo,
333 get_driver_name(crypto_aead, tfm), e);
339 if (*b_size + authsize > XBUFSIZE * PAGE_SIZE) {
340 pr_err("template (%u) too big for buffer (%lu)\n",
342 XBUFSIZE * PAGE_SIZE);
346 pr_info("test %u (%d bit key, %d byte blocks): ", i,
347 *keysize * 8, *b_size);
349 /* Set up tfm global state, i.e. the key */
351 memset(tvmem[0], 0xff, PAGE_SIZE);
353 for (j = 0; j < tcount; j++) {
354 if (template[j].klen == *keysize) {
355 key = template[j].key;
360 crypto_aead_clear_flags(tfm, ~0);
362 ret = crypto_aead_setkey(tfm, key, *keysize);
364 pr_err("setkey() failed flags=%x\n",
365 crypto_aead_get_flags(tfm));
369 iv_len = crypto_aead_ivsize(tfm);
371 memset(iv, 0xff, iv_len);
373 /* Now setup per request stuff, i.e. buffers */
375 for (j = 0; j < num_mb; ++j) {
376 struct test_mb_aead_data *cur = &data[j];
378 assoc = cur->axbuf[0];
379 memset(assoc, 0xff, aad_size);
381 sg_init_aead(cur->sg, cur->xbuf,
382 *b_size + (enc ? 0 : authsize),
385 sg_init_aead(cur->sgout, cur->xoutbuf,
386 *b_size + (enc ? authsize : 0),
389 aead_request_set_ad(cur->req, aad_size);
393 aead_request_set_crypt(cur->req,
397 ret = crypto_aead_encrypt(cur->req);
398 ret = do_one_aead_op(cur->req, ret);
401 pr_err("calculating auth failed failed (%d)\n",
407 aead_request_set_crypt(cur->req, cur->sg,
408 cur->sgout, *b_size +
409 (enc ? 0 : authsize),
415 ret = test_mb_aead_jiffies(data, enc, *b_size,
419 ret = test_mb_aead_cycles(data, enc, *b_size,
424 pr_err("%s() failed return code=%d\n", e, ret);
434 for (i = 0; i < num_mb; ++i)
435 aead_request_free(data[i].req);
437 for (i = 0; i < num_mb; ++i)
438 testmgr_free_buf(data[i].xoutbuf);
440 for (i = 0; i < num_mb; ++i)
441 testmgr_free_buf(data[i].axbuf);
443 for (i = 0; i < num_mb; ++i)
444 testmgr_free_buf(data[i].xbuf);
446 crypto_free_aead(tfm);
453 static int test_aead_jiffies(struct aead_request *req, int enc,
456 unsigned long start, end;
460 for (start = jiffies, end = start + secs * HZ, bcount = 0;
461 time_before(jiffies, end); bcount++) {
463 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
465 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
471 printk("%d operations in %d seconds (%ld bytes)\n",
472 bcount, secs, (long)bcount * blen);
476 static int test_aead_cycles(struct aead_request *req, int enc, int blen)
478 unsigned long cycles = 0;
483 for (i = 0; i < 4; i++) {
485 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
487 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
493 /* The real thing. */
494 for (i = 0; i < 8; i++) {
497 start = get_cycles();
499 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
501 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
507 cycles += end - start;
512 printk("1 operation in %lu cycles (%d bytes)\n",
513 (cycles + 4) / 8, blen);
518 static void test_aead_speed(const char *algo, int enc, unsigned int secs,
519 struct aead_speed_template *template,
520 unsigned int tcount, u8 authsize,
521 unsigned int aad_size, u8 *keysize)
524 struct crypto_aead *tfm;
527 struct aead_request *req;
528 struct scatterlist *sg;
529 struct scatterlist *sgout;
533 char *xbuf[XBUFSIZE];
534 char *xoutbuf[XBUFSIZE];
535 char *axbuf[XBUFSIZE];
536 unsigned int *b_size;
538 struct crypto_wait wait;
540 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
544 if (aad_size >= PAGE_SIZE) {
545 pr_err("associate data length (%u) too big\n", aad_size);
554 if (testmgr_alloc_buf(xbuf))
556 if (testmgr_alloc_buf(axbuf))
558 if (testmgr_alloc_buf(xoutbuf))
561 sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL);
566 tfm = crypto_alloc_aead(algo, 0, 0);
569 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
574 crypto_init_wait(&wait);
575 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
576 get_driver_name(crypto_aead, tfm), e);
578 req = aead_request_alloc(tfm, GFP_KERNEL);
580 pr_err("alg: aead: Failed to allocate request for %s\n",
585 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
586 crypto_req_done, &wait);
593 memset(assoc, 0xff, aad_size);
595 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
596 pr_err("template (%u) too big for tvmem (%lu)\n",
598 TVMEMSIZE * PAGE_SIZE);
603 for (j = 0; j < tcount; j++) {
604 if (template[j].klen == *keysize) {
605 key = template[j].key;
609 ret = crypto_aead_setkey(tfm, key, *keysize);
610 ret = crypto_aead_setauthsize(tfm, authsize);
612 iv_len = crypto_aead_ivsize(tfm);
614 memset(iv, 0xff, iv_len);
616 crypto_aead_clear_flags(tfm, ~0);
617 printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
618 i, *keysize * 8, *b_size);
621 memset(tvmem[0], 0xff, PAGE_SIZE);
624 pr_err("setkey() failed flags=%x\n",
625 crypto_aead_get_flags(tfm));
629 sg_init_aead(sg, xbuf, *b_size + (enc ? 0 : authsize),
632 sg_init_aead(sgout, xoutbuf,
633 *b_size + (enc ? authsize : 0), assoc,
636 aead_request_set_ad(req, aad_size);
641 * For decryption we need a proper auth so
642 * we do the encryption path once with buffers
643 * reversed (input <-> output) to calculate it
645 aead_request_set_crypt(req, sgout, sg,
647 ret = do_one_aead_op(req,
648 crypto_aead_encrypt(req));
651 pr_err("calculating auth failed failed (%d)\n",
657 aead_request_set_crypt(req, sg, sgout,
658 *b_size + (enc ? 0 : authsize),
662 ret = test_aead_jiffies(req, enc, *b_size,
666 ret = test_aead_cycles(req, enc, *b_size);
670 pr_err("%s() failed return code=%d\n", e, ret);
680 aead_request_free(req);
682 crypto_free_aead(tfm);
686 testmgr_free_buf(xoutbuf);
688 testmgr_free_buf(axbuf);
690 testmgr_free_buf(xbuf);
695 static void test_hash_sg_init(struct scatterlist *sg)
699 sg_init_table(sg, TVMEMSIZE);
700 for (i = 0; i < TVMEMSIZE; i++) {
701 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
702 memset(tvmem[i], 0xff, PAGE_SIZE);
706 static inline int do_one_ahash_op(struct ahash_request *req, int ret)
708 struct crypto_wait *wait = req->base.data;
710 return crypto_wait_req(ret, wait);
713 struct test_mb_ahash_data {
714 struct scatterlist sg[XBUFSIZE];
716 struct ahash_request *req;
717 struct crypto_wait wait;
718 char *xbuf[XBUFSIZE];
721 static inline int do_mult_ahash_op(struct test_mb_ahash_data *data, u32 num_mb,
726 /* Fire up a bunch of concurrent requests */
727 for (i = 0; i < num_mb; i++)
728 rc[i] = crypto_ahash_digest(data[i].req);
730 /* Wait for all requests to finish */
731 for (i = 0; i < num_mb; i++) {
732 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
735 pr_info("concurrent request %d error %d\n", i, rc[i]);
743 static int test_mb_ahash_jiffies(struct test_mb_ahash_data *data, int blen,
744 int secs, u32 num_mb)
746 unsigned long start, end;
751 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
755 for (start = jiffies, end = start + secs * HZ, bcount = 0;
756 time_before(jiffies, end); bcount++) {
757 ret = do_mult_ahash_op(data, num_mb, rc);
762 pr_cont("%d operations in %d seconds (%ld bytes)\n",
763 bcount * num_mb, secs, (long)bcount * blen * num_mb);
770 static int test_mb_ahash_cycles(struct test_mb_ahash_data *data, int blen,
773 unsigned long cycles = 0;
778 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
783 for (i = 0; i < 4; i++) {
784 ret = do_mult_ahash_op(data, num_mb, rc);
789 /* The real thing. */
790 for (i = 0; i < 8; i++) {
793 start = get_cycles();
794 ret = do_mult_ahash_op(data, num_mb, rc);
800 cycles += end - start;
803 pr_cont("1 operation in %lu cycles (%d bytes)\n",
804 (cycles + 4) / (8 * num_mb), blen);
811 static void test_mb_ahash_speed(const char *algo, unsigned int secs,
812 struct hash_speed *speed, u32 num_mb)
814 struct test_mb_ahash_data *data;
815 struct crypto_ahash *tfm;
816 unsigned int i, j, k;
819 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
823 tfm = crypto_alloc_ahash(algo, 0, 0);
825 pr_err("failed to load transform for %s: %ld\n",
830 for (i = 0; i < num_mb; ++i) {
831 if (testmgr_alloc_buf(data[i].xbuf))
834 crypto_init_wait(&data[i].wait);
836 data[i].req = ahash_request_alloc(tfm, GFP_KERNEL);
838 pr_err("alg: hash: Failed to allocate request for %s\n",
843 ahash_request_set_callback(data[i].req, 0, crypto_req_done,
846 sg_init_table(data[i].sg, XBUFSIZE);
847 for (j = 0; j < XBUFSIZE; j++) {
848 sg_set_buf(data[i].sg + j, data[i].xbuf[j], PAGE_SIZE);
849 memset(data[i].xbuf[j], 0xff, PAGE_SIZE);
853 pr_info("\ntesting speed of multibuffer %s (%s)\n", algo,
854 get_driver_name(crypto_ahash, tfm));
856 for (i = 0; speed[i].blen != 0; i++) {
857 /* For some reason this only tests digests. */
858 if (speed[i].blen != speed[i].plen)
861 if (speed[i].blen > XBUFSIZE * PAGE_SIZE) {
862 pr_err("template (%u) too big for tvmem (%lu)\n",
863 speed[i].blen, XBUFSIZE * PAGE_SIZE);
868 crypto_ahash_setkey(tfm, tvmem[0], speed[i].klen);
870 for (k = 0; k < num_mb; k++)
871 ahash_request_set_crypt(data[k].req, data[k].sg,
872 data[k].result, speed[i].blen);
875 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
876 i, speed[i].blen, speed[i].plen,
877 speed[i].blen / speed[i].plen);
880 ret = test_mb_ahash_jiffies(data, speed[i].blen, secs,
884 ret = test_mb_ahash_cycles(data, speed[i].blen, num_mb);
889 pr_err("At least one hashing failed ret=%d\n", ret);
895 for (k = 0; k < num_mb; ++k)
896 ahash_request_free(data[k].req);
898 for (k = 0; k < num_mb; ++k)
899 testmgr_free_buf(data[k].xbuf);
901 crypto_free_ahash(tfm);
907 static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
910 unsigned long start, end;
914 for (start = jiffies, end = start + secs * HZ, bcount = 0;
915 time_before(jiffies, end); bcount++) {
916 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
921 printk("%6u opers/sec, %9lu bytes/sec\n",
922 bcount / secs, ((long)bcount * blen) / secs);
927 static int test_ahash_jiffies(struct ahash_request *req, int blen,
928 int plen, char *out, int secs)
930 unsigned long start, end;
935 return test_ahash_jiffies_digest(req, blen, out, secs);
937 for (start = jiffies, end = start + secs * HZ, bcount = 0;
938 time_before(jiffies, end); bcount++) {
939 ret = do_one_ahash_op(req, crypto_ahash_init(req));
942 for (pcount = 0; pcount < blen; pcount += plen) {
943 ret = do_one_ahash_op(req, crypto_ahash_update(req));
947 /* we assume there is enough space in 'out' for the result */
948 ret = do_one_ahash_op(req, crypto_ahash_final(req));
953 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
954 bcount / secs, ((long)bcount * blen) / secs);
959 static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
962 unsigned long cycles = 0;
966 for (i = 0; i < 4; i++) {
967 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
972 /* The real thing. */
973 for (i = 0; i < 8; i++) {
976 start = get_cycles();
978 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
984 cycles += end - start;
991 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
992 cycles / 8, cycles / (8 * blen));
997 static int test_ahash_cycles(struct ahash_request *req, int blen,
1000 unsigned long cycles = 0;
1004 return test_ahash_cycles_digest(req, blen, out);
1007 for (i = 0; i < 4; i++) {
1008 ret = do_one_ahash_op(req, crypto_ahash_init(req));
1011 for (pcount = 0; pcount < blen; pcount += plen) {
1012 ret = do_one_ahash_op(req, crypto_ahash_update(req));
1016 ret = do_one_ahash_op(req, crypto_ahash_final(req));
1021 /* The real thing. */
1022 for (i = 0; i < 8; i++) {
1023 cycles_t start, end;
1025 start = get_cycles();
1027 ret = do_one_ahash_op(req, crypto_ahash_init(req));
1030 for (pcount = 0; pcount < blen; pcount += plen) {
1031 ret = do_one_ahash_op(req, crypto_ahash_update(req));
1035 ret = do_one_ahash_op(req, crypto_ahash_final(req));
1041 cycles += end - start;
1048 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
1049 cycles / 8, cycles / (8 * blen));
1054 static void test_ahash_speed_common(const char *algo, unsigned int secs,
1055 struct hash_speed *speed, unsigned mask)
1057 struct scatterlist sg[TVMEMSIZE];
1058 struct crypto_wait wait;
1059 struct ahash_request *req;
1060 struct crypto_ahash *tfm;
1064 tfm = crypto_alloc_ahash(algo, 0, mask);
1066 pr_err("failed to load transform for %s: %ld\n",
1067 algo, PTR_ERR(tfm));
1071 printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
1072 get_driver_name(crypto_ahash, tfm));
1074 if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) {
1075 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm),
1080 test_hash_sg_init(sg);
1081 req = ahash_request_alloc(tfm, GFP_KERNEL);
1083 pr_err("ahash request allocation failure\n");
1087 crypto_init_wait(&wait);
1088 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1089 crypto_req_done, &wait);
1091 output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
1095 for (i = 0; speed[i].blen != 0; i++) {
1096 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
1097 pr_err("template (%u) too big for tvmem (%lu)\n",
1098 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
1103 crypto_ahash_setkey(tfm, tvmem[0], speed[i].klen);
1106 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
1107 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
1109 ahash_request_set_crypt(req, sg, output, speed[i].plen);
1112 ret = test_ahash_jiffies(req, speed[i].blen,
1113 speed[i].plen, output, secs);
1116 ret = test_ahash_cycles(req, speed[i].blen,
1117 speed[i].plen, output);
1121 pr_err("hashing failed ret=%d\n", ret);
1129 ahash_request_free(req);
1132 crypto_free_ahash(tfm);
1135 static void test_ahash_speed(const char *algo, unsigned int secs,
1136 struct hash_speed *speed)
1138 return test_ahash_speed_common(algo, secs, speed, 0);
1141 static void test_hash_speed(const char *algo, unsigned int secs,
1142 struct hash_speed *speed)
1144 return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC);
1147 struct test_mb_skcipher_data {
1148 struct scatterlist sg[XBUFSIZE];
1149 struct skcipher_request *req;
1150 struct crypto_wait wait;
1151 char *xbuf[XBUFSIZE];
1154 static int do_mult_acipher_op(struct test_mb_skcipher_data *data, int enc,
1155 u32 num_mb, int *rc)
1159 /* Fire up a bunch of concurrent requests */
1160 for (i = 0; i < num_mb; i++) {
1162 rc[i] = crypto_skcipher_encrypt(data[i].req);
1164 rc[i] = crypto_skcipher_decrypt(data[i].req);
1167 /* Wait for all requests to finish */
1168 for (i = 0; i < num_mb; i++) {
1169 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
1172 pr_info("concurrent request %d error %d\n", i, rc[i]);
1180 static int test_mb_acipher_jiffies(struct test_mb_skcipher_data *data, int enc,
1181 int blen, int secs, u32 num_mb)
1183 unsigned long start, end;
1188 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
1192 for (start = jiffies, end = start + secs * HZ, bcount = 0;
1193 time_before(jiffies, end); bcount++) {
1194 ret = do_mult_acipher_op(data, enc, num_mb, rc);
1199 pr_cont("%d operations in %d seconds (%ld bytes)\n",
1200 bcount * num_mb, secs, (long)bcount * blen * num_mb);
1207 static int test_mb_acipher_cycles(struct test_mb_skcipher_data *data, int enc,
1208 int blen, u32 num_mb)
1210 unsigned long cycles = 0;
1215 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
1220 for (i = 0; i < 4; i++) {
1221 ret = do_mult_acipher_op(data, enc, num_mb, rc);
1226 /* The real thing. */
1227 for (i = 0; i < 8; i++) {
1228 cycles_t start, end;
1230 start = get_cycles();
1231 ret = do_mult_acipher_op(data, enc, num_mb, rc);
1237 cycles += end - start;
1240 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1241 (cycles + 4) / (8 * num_mb), blen);
1248 static void test_mb_skcipher_speed(const char *algo, int enc, int secs,
1249 struct cipher_speed_template *template,
1250 unsigned int tcount, u8 *keysize, u32 num_mb)
1252 struct test_mb_skcipher_data *data;
1253 struct crypto_skcipher *tfm;
1254 unsigned int i, j, iv_len;
1266 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
1270 tfm = crypto_alloc_skcipher(algo, 0, 0);
1272 pr_err("failed to load transform for %s: %ld\n",
1273 algo, PTR_ERR(tfm));
1277 for (i = 0; i < num_mb; ++i)
1278 if (testmgr_alloc_buf(data[i].xbuf)) {
1280 testmgr_free_buf(data[i].xbuf);
1285 for (i = 0; i < num_mb; ++i)
1286 if (testmgr_alloc_buf(data[i].xbuf)) {
1288 testmgr_free_buf(data[i].xbuf);
1293 for (i = 0; i < num_mb; ++i) {
1294 data[i].req = skcipher_request_alloc(tfm, GFP_KERNEL);
1296 pr_err("alg: skcipher: Failed to allocate request for %s\n",
1299 skcipher_request_free(data[i].req);
1304 for (i = 0; i < num_mb; ++i) {
1305 skcipher_request_set_callback(data[i].req,
1306 CRYPTO_TFM_REQ_MAY_BACKLOG,
1307 crypto_req_done, &data[i].wait);
1308 crypto_init_wait(&data[i].wait);
1311 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo,
1312 get_driver_name(crypto_skcipher, tfm), e);
1316 b_size = block_sizes;
1318 if (*b_size > XBUFSIZE * PAGE_SIZE) {
1319 pr_err("template (%u) too big for buffer (%lu)\n",
1320 *b_size, XBUFSIZE * PAGE_SIZE);
1324 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1325 *keysize * 8, *b_size);
1327 /* Set up tfm global state, i.e. the key */
1329 memset(tvmem[0], 0xff, PAGE_SIZE);
1331 for (j = 0; j < tcount; j++) {
1332 if (template[j].klen == *keysize) {
1333 key = template[j].key;
1338 crypto_skcipher_clear_flags(tfm, ~0);
1340 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1342 pr_err("setkey() failed flags=%x\n",
1343 crypto_skcipher_get_flags(tfm));
1347 iv_len = crypto_skcipher_ivsize(tfm);
1349 memset(&iv, 0xff, iv_len);
1351 /* Now setup per request stuff, i.e. buffers */
1353 for (j = 0; j < num_mb; ++j) {
1354 struct test_mb_skcipher_data *cur = &data[j];
1355 unsigned int k = *b_size;
1356 unsigned int pages = DIV_ROUND_UP(k, PAGE_SIZE);
1359 sg_init_table(cur->sg, pages);
1361 while (k > PAGE_SIZE) {
1362 sg_set_buf(cur->sg + p, cur->xbuf[p],
1364 memset(cur->xbuf[p], 0xff, PAGE_SIZE);
1369 sg_set_buf(cur->sg + p, cur->xbuf[p], k);
1370 memset(cur->xbuf[p], 0xff, k);
1372 skcipher_request_set_crypt(cur->req, cur->sg,
1378 ret = test_mb_acipher_jiffies(data, enc,
1383 ret = test_mb_acipher_cycles(data, enc,
1388 pr_err("%s() failed flags=%x\n", e,
1389 crypto_skcipher_get_flags(tfm));
1399 for (i = 0; i < num_mb; ++i)
1400 skcipher_request_free(data[i].req);
1402 for (i = 0; i < num_mb; ++i)
1403 testmgr_free_buf(data[i].xbuf);
1405 crypto_free_skcipher(tfm);
1410 static inline int do_one_acipher_op(struct skcipher_request *req, int ret)
1412 struct crypto_wait *wait = req->base.data;
1414 return crypto_wait_req(ret, wait);
1417 static int test_acipher_jiffies(struct skcipher_request *req, int enc,
1420 unsigned long start, end;
1424 for (start = jiffies, end = start + secs * HZ, bcount = 0;
1425 time_before(jiffies, end); bcount++) {
1427 ret = do_one_acipher_op(req,
1428 crypto_skcipher_encrypt(req));
1430 ret = do_one_acipher_op(req,
1431 crypto_skcipher_decrypt(req));
1437 pr_cont("%d operations in %d seconds (%ld bytes)\n",
1438 bcount, secs, (long)bcount * blen);
1442 static int test_acipher_cycles(struct skcipher_request *req, int enc,
1445 unsigned long cycles = 0;
1450 for (i = 0; i < 4; i++) {
1452 ret = do_one_acipher_op(req,
1453 crypto_skcipher_encrypt(req));
1455 ret = do_one_acipher_op(req,
1456 crypto_skcipher_decrypt(req));
1462 /* The real thing. */
1463 for (i = 0; i < 8; i++) {
1464 cycles_t start, end;
1466 start = get_cycles();
1468 ret = do_one_acipher_op(req,
1469 crypto_skcipher_encrypt(req));
1471 ret = do_one_acipher_op(req,
1472 crypto_skcipher_decrypt(req));
1478 cycles += end - start;
1483 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1484 (cycles + 4) / 8, blen);
1489 static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
1490 struct cipher_speed_template *template,
1491 unsigned int tcount, u8 *keysize, bool async)
1493 unsigned int ret, i, j, k, iv_len;
1494 struct crypto_wait wait;
1497 struct skcipher_request *req;
1498 struct crypto_skcipher *tfm;
1507 crypto_init_wait(&wait);
1509 tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC);
1512 pr_err("failed to load transform for %s: %ld\n", algo,
1517 pr_info("\ntesting speed of async %s (%s) %s\n", algo,
1518 get_driver_name(crypto_skcipher, tfm), e);
1520 req = skcipher_request_alloc(tfm, GFP_KERNEL);
1522 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1527 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1528 crypto_req_done, &wait);
1532 b_size = block_sizes;
1535 struct scatterlist sg[TVMEMSIZE];
1537 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
1538 pr_err("template (%u) too big for "
1539 "tvmem (%lu)\n", *keysize + *b_size,
1540 TVMEMSIZE * PAGE_SIZE);
1544 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1545 *keysize * 8, *b_size);
1547 memset(tvmem[0], 0xff, PAGE_SIZE);
1549 /* set key, plain text and IV */
1551 for (j = 0; j < tcount; j++) {
1552 if (template[j].klen == *keysize) {
1553 key = template[j].key;
1558 crypto_skcipher_clear_flags(tfm, ~0);
1560 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1562 pr_err("setkey() failed flags=%x\n",
1563 crypto_skcipher_get_flags(tfm));
1567 k = *keysize + *b_size;
1568 sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
1570 if (k > PAGE_SIZE) {
1571 sg_set_buf(sg, tvmem[0] + *keysize,
1572 PAGE_SIZE - *keysize);
1575 while (k > PAGE_SIZE) {
1576 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
1577 memset(tvmem[j], 0xff, PAGE_SIZE);
1581 sg_set_buf(sg + j, tvmem[j], k);
1582 memset(tvmem[j], 0xff, k);
1584 sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
1587 iv_len = crypto_skcipher_ivsize(tfm);
1589 memset(&iv, 0xff, iv_len);
1591 skcipher_request_set_crypt(req, sg, sg, *b_size, iv);
1594 ret = test_acipher_jiffies(req, enc,
1598 ret = test_acipher_cycles(req, enc,
1603 pr_err("%s() failed flags=%x\n", e,
1604 crypto_skcipher_get_flags(tfm));
1614 skcipher_request_free(req);
1616 crypto_free_skcipher(tfm);
1619 static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
1620 struct cipher_speed_template *template,
1621 unsigned int tcount, u8 *keysize)
1623 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1627 static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
1628 struct cipher_speed_template *template,
1629 unsigned int tcount, u8 *keysize)
1631 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1635 static void test_available(void)
1637 char **name = check;
1640 printk("alg %s ", *name);
1641 printk(crypto_has_alg(*name, 0, 0) ?
1642 "found\n" : "not found\n");
1647 static inline int tcrypt_test(const char *alg)
1651 pr_debug("testing %s\n", alg);
1653 ret = alg_test(alg, alg, 0, 0);
1654 /* non-fips algs return -EINVAL in fips mode */
1655 if (fips_enabled && ret == -EINVAL)
1660 static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)
1668 if (!crypto_has_alg(alg, type,
1669 mask ?: CRYPTO_ALG_TYPE_MASK))
1674 for (i = 1; i < 200; i++)
1675 ret += do_test(NULL, 0, 0, i, num_mb);
1679 ret += tcrypt_test("md5");
1683 ret += tcrypt_test("sha1");
1687 ret += tcrypt_test("ecb(des)");
1688 ret += tcrypt_test("cbc(des)");
1689 ret += tcrypt_test("ctr(des)");
1693 ret += tcrypt_test("ecb(des3_ede)");
1694 ret += tcrypt_test("cbc(des3_ede)");
1695 ret += tcrypt_test("ctr(des3_ede)");
1699 ret += tcrypt_test("md4");
1703 ret += tcrypt_test("sha256");
1707 ret += tcrypt_test("ecb(blowfish)");
1708 ret += tcrypt_test("cbc(blowfish)");
1709 ret += tcrypt_test("ctr(blowfish)");
1713 ret += tcrypt_test("ecb(twofish)");
1714 ret += tcrypt_test("cbc(twofish)");
1715 ret += tcrypt_test("ctr(twofish)");
1716 ret += tcrypt_test("lrw(twofish)");
1717 ret += tcrypt_test("xts(twofish)");
1721 ret += tcrypt_test("ecb(serpent)");
1722 ret += tcrypt_test("cbc(serpent)");
1723 ret += tcrypt_test("ctr(serpent)");
1724 ret += tcrypt_test("lrw(serpent)");
1725 ret += tcrypt_test("xts(serpent)");
1729 ret += tcrypt_test("ecb(aes)");
1730 ret += tcrypt_test("cbc(aes)");
1731 ret += tcrypt_test("lrw(aes)");
1732 ret += tcrypt_test("xts(aes)");
1733 ret += tcrypt_test("ctr(aes)");
1734 ret += tcrypt_test("rfc3686(ctr(aes))");
1735 ret += tcrypt_test("ofb(aes)");
1736 ret += tcrypt_test("cfb(aes)");
1740 ret += tcrypt_test("sha384");
1744 ret += tcrypt_test("sha512");
1748 ret += tcrypt_test("deflate");
1752 ret += tcrypt_test("ecb(cast5)");
1753 ret += tcrypt_test("cbc(cast5)");
1754 ret += tcrypt_test("ctr(cast5)");
1758 ret += tcrypt_test("ecb(cast6)");
1759 ret += tcrypt_test("cbc(cast6)");
1760 ret += tcrypt_test("ctr(cast6)");
1761 ret += tcrypt_test("lrw(cast6)");
1762 ret += tcrypt_test("xts(cast6)");
1766 ret += tcrypt_test("ecb(arc4)");
1770 ret += tcrypt_test("michael_mic");
1774 ret += tcrypt_test("crc32c");
1778 ret += tcrypt_test("ecb(tea)");
1782 ret += tcrypt_test("ecb(xtea)");
1786 ret += tcrypt_test("ecb(khazad)");
1790 ret += tcrypt_test("wp512");
1794 ret += tcrypt_test("wp384");
1798 ret += tcrypt_test("wp256");
1802 ret += tcrypt_test("ecb(tnepres)");
1806 ret += tcrypt_test("ecb(anubis)");
1807 ret += tcrypt_test("cbc(anubis)");
1811 ret += tcrypt_test("tgr192");
1815 ret += tcrypt_test("tgr160");
1819 ret += tcrypt_test("tgr128");
1823 ret += tcrypt_test("ecb(xeta)");
1827 ret += tcrypt_test("pcbc(fcrypt)");
1831 ret += tcrypt_test("ecb(camellia)");
1832 ret += tcrypt_test("cbc(camellia)");
1833 ret += tcrypt_test("ctr(camellia)");
1834 ret += tcrypt_test("lrw(camellia)");
1835 ret += tcrypt_test("xts(camellia)");
1839 ret += tcrypt_test("sha224");
1843 ret += tcrypt_test("salsa20");
1847 ret += tcrypt_test("gcm(aes)");
1851 ret += tcrypt_test("lzo");
1855 ret += tcrypt_test("ccm(aes)");
1859 ret += tcrypt_test("cts(cbc(aes))");
1863 ret += tcrypt_test("rmd128");
1867 ret += tcrypt_test("rmd160");
1871 ret += tcrypt_test("rmd256");
1875 ret += tcrypt_test("rmd320");
1879 ret += tcrypt_test("ecb(seed)");
1883 ret += tcrypt_test("rfc4309(ccm(aes))");
1887 ret += tcrypt_test("ghash");
1891 ret += tcrypt_test("crct10dif");
1895 ret += tcrypt_test("sha3-224");
1899 ret += tcrypt_test("sha3-256");
1903 ret += tcrypt_test("sha3-384");
1907 ret += tcrypt_test("sha3-512");
1911 ret += tcrypt_test("sm3");
1915 ret += tcrypt_test("streebog256");
1919 ret += tcrypt_test("streebog512");
1923 ret += tcrypt_test("hmac(md5)");
1927 ret += tcrypt_test("hmac(sha1)");
1931 ret += tcrypt_test("hmac(sha256)");
1935 ret += tcrypt_test("hmac(sha384)");
1939 ret += tcrypt_test("hmac(sha512)");
1943 ret += tcrypt_test("hmac(sha224)");
1947 ret += tcrypt_test("xcbc(aes)");
1951 ret += tcrypt_test("hmac(rmd128)");
1955 ret += tcrypt_test("hmac(rmd160)");
1959 ret += tcrypt_test("vmac64(aes)");
1963 ret += tcrypt_test("hmac(sha3-224)");
1967 ret += tcrypt_test("hmac(sha3-256)");
1971 ret += tcrypt_test("hmac(sha3-384)");
1975 ret += tcrypt_test("hmac(sha3-512)");
1979 ret += tcrypt_test("hmac(streebog256)");
1983 ret += tcrypt_test("hmac(streebog512)");
1987 ret += tcrypt_test("ansi_cprng");
1991 ret += tcrypt_test("rfc4106(gcm(aes))");
1995 ret += tcrypt_test("rfc4543(gcm(aes))");
1999 ret += tcrypt_test("cmac(aes)");
2003 ret += tcrypt_test("cmac(des3_ede)");
2007 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
2011 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
2015 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
2018 ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
2021 ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
2024 ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
2027 ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
2030 ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
2033 ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
2036 ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
2039 ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
2042 ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
2045 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
2048 ret += tcrypt_test("ecb(sm4)");
2049 ret += tcrypt_test("cbc(sm4)");
2050 ret += tcrypt_test("ctr(sm4)");
2053 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2054 speed_template_16_24_32);
2055 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2056 speed_template_16_24_32);
2057 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2058 speed_template_16_24_32);
2059 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2060 speed_template_16_24_32);
2061 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2062 speed_template_32_40_48);
2063 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2064 speed_template_32_40_48);
2065 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2066 speed_template_32_64);
2067 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2068 speed_template_32_64);
2069 test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2070 speed_template_16_24_32);
2071 test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2072 speed_template_16_24_32);
2073 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2074 speed_template_16_24_32);
2075 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2076 speed_template_16_24_32);
2077 test_cipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2078 speed_template_16_24_32);
2079 test_cipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2080 speed_template_16_24_32);
2084 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2085 des3_speed_template, DES3_SPEED_VECTORS,
2087 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
2088 des3_speed_template, DES3_SPEED_VECTORS,
2090 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2091 des3_speed_template, DES3_SPEED_VECTORS,
2093 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
2094 des3_speed_template, DES3_SPEED_VECTORS,
2096 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
2097 des3_speed_template, DES3_SPEED_VECTORS,
2099 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
2100 des3_speed_template, DES3_SPEED_VECTORS,
2105 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2106 speed_template_16_24_32);
2107 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2108 speed_template_16_24_32);
2109 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2110 speed_template_16_24_32);
2111 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2112 speed_template_16_24_32);
2113 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2114 speed_template_16_24_32);
2115 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2116 speed_template_16_24_32);
2117 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2118 speed_template_32_40_48);
2119 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2120 speed_template_32_40_48);
2121 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2122 speed_template_32_48_64);
2123 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2124 speed_template_32_48_64);
2128 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2129 speed_template_8_32);
2130 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2131 speed_template_8_32);
2132 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2133 speed_template_8_32);
2134 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2135 speed_template_8_32);
2136 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2137 speed_template_8_32);
2138 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2139 speed_template_8_32);
2143 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2145 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2147 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2149 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2154 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2155 speed_template_16_24_32);
2156 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2157 speed_template_16_24_32);
2158 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2159 speed_template_16_24_32);
2160 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2161 speed_template_16_24_32);
2162 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2163 speed_template_16_24_32);
2164 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2165 speed_template_16_24_32);
2166 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2167 speed_template_32_40_48);
2168 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2169 speed_template_32_40_48);
2170 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2171 speed_template_32_48_64);
2172 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2173 speed_template_32_48_64);
2177 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
2178 speed_template_16_32);
2182 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2183 speed_template_16_32);
2184 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2185 speed_template_16_32);
2186 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2187 speed_template_16_32);
2188 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2189 speed_template_16_32);
2190 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2191 speed_template_16_32);
2192 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2193 speed_template_16_32);
2194 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2195 speed_template_32_48);
2196 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2197 speed_template_32_48);
2198 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2199 speed_template_32_64);
2200 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2201 speed_template_32_64);
2205 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2210 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2211 speed_template_8_16);
2212 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2213 speed_template_8_16);
2214 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2215 speed_template_8_16);
2216 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2217 speed_template_8_16);
2218 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2219 speed_template_8_16);
2220 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2221 speed_template_8_16);
2225 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2226 speed_template_16_32);
2227 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2228 speed_template_16_32);
2229 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2230 speed_template_16_32);
2231 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2232 speed_template_16_32);
2233 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2234 speed_template_16_32);
2235 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2236 speed_template_16_32);
2237 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2238 speed_template_32_48);
2239 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2240 speed_template_32_48);
2241 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2242 speed_template_32_64);
2243 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2244 speed_template_32_64);
2248 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
2249 NULL, 0, 16, 16, aead_speed_template_20);
2250 test_aead_speed("gcm(aes)", ENCRYPT, sec,
2251 NULL, 0, 16, 8, speed_template_16_24_32);
2252 test_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec,
2253 NULL, 0, 16, 16, aead_speed_template_20);
2254 test_aead_speed("gcm(aes)", DECRYPT, sec,
2255 NULL, 0, 16, 8, speed_template_16_24_32);
2259 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
2260 NULL, 0, 16, 16, aead_speed_template_19);
2261 test_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec,
2262 NULL, 0, 16, 16, aead_speed_template_19);
2266 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
2267 NULL, 0, 16, 8, aead_speed_template_36);
2268 test_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT, sec,
2269 NULL, 0, 16, 8, aead_speed_template_36);
2273 test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
2278 test_mb_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec, NULL,
2279 0, 16, 16, aead_speed_template_20, num_mb);
2280 test_mb_aead_speed("gcm(aes)", ENCRYPT, sec, NULL, 0, 16, 8,
2281 speed_template_16_24_32, num_mb);
2282 test_mb_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec, NULL,
2283 0, 16, 16, aead_speed_template_20, num_mb);
2284 test_mb_aead_speed("gcm(aes)", DECRYPT, sec, NULL, 0, 16, 8,
2285 speed_template_16_24_32, num_mb);
2289 test_mb_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec, NULL, 0,
2290 16, 16, aead_speed_template_19, num_mb);
2291 test_mb_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec, NULL, 0,
2292 16, 16, aead_speed_template_19, num_mb);
2296 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT,
2297 sec, NULL, 0, 16, 8, aead_speed_template_36,
2299 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT,
2300 sec, NULL, 0, 16, 8, aead_speed_template_36,
2305 test_cipher_speed("ecb(sm4)", ENCRYPT, sec, NULL, 0,
2307 test_cipher_speed("ecb(sm4)", DECRYPT, sec, NULL, 0,
2309 test_cipher_speed("cbc(sm4)", ENCRYPT, sec, NULL, 0,
2311 test_cipher_speed("cbc(sm4)", DECRYPT, sec, NULL, 0,
2313 test_cipher_speed("ctr(sm4)", ENCRYPT, sec, NULL, 0,
2315 test_cipher_speed("ctr(sm4)", DECRYPT, sec, NULL, 0,
2320 test_cipher_speed("adiantum(xchacha12,aes)", ENCRYPT, sec, NULL,
2321 0, speed_template_32);
2322 test_cipher_speed("adiantum(xchacha12,aes)", DECRYPT, sec, NULL,
2323 0, speed_template_32);
2324 test_cipher_speed("adiantum(xchacha20,aes)", ENCRYPT, sec, NULL,
2325 0, speed_template_32);
2326 test_cipher_speed("adiantum(xchacha20,aes)", DECRYPT, sec, NULL,
2327 0, speed_template_32);
2331 test_acipher_speed("essiv(cbc(aes),sha256)",
2332 ENCRYPT, sec, NULL, 0,
2333 speed_template_16_24_32);
2334 test_acipher_speed("essiv(cbc(aes),sha256)",
2335 DECRYPT, sec, NULL, 0,
2336 speed_template_16_24_32);
2340 test_aead_speed("aegis128", ENCRYPT, sec,
2341 NULL, 0, 16, 8, speed_template_16);
2342 test_aead_speed("aegis128", DECRYPT, sec,
2343 NULL, 0, 16, 8, speed_template_16);
2348 test_hash_speed(alg, sec, generic_hash_speed_template);
2353 test_hash_speed("md4", sec, generic_hash_speed_template);
2354 if (mode > 300 && mode < 400) break;
2357 test_hash_speed("md5", sec, generic_hash_speed_template);
2358 if (mode > 300 && mode < 400) break;
2361 test_hash_speed("sha1", sec, generic_hash_speed_template);
2362 if (mode > 300 && mode < 400) break;
2365 test_hash_speed("sha256", sec, generic_hash_speed_template);
2366 if (mode > 300 && mode < 400) break;
2369 test_hash_speed("sha384", sec, generic_hash_speed_template);
2370 if (mode > 300 && mode < 400) break;
2373 test_hash_speed("sha512", sec, generic_hash_speed_template);
2374 if (mode > 300 && mode < 400) break;
2377 test_hash_speed("wp256", sec, generic_hash_speed_template);
2378 if (mode > 300 && mode < 400) break;
2381 test_hash_speed("wp384", sec, generic_hash_speed_template);
2382 if (mode > 300 && mode < 400) break;
2385 test_hash_speed("wp512", sec, generic_hash_speed_template);
2386 if (mode > 300 && mode < 400) break;
2389 test_hash_speed("tgr128", sec, generic_hash_speed_template);
2390 if (mode > 300 && mode < 400) break;
2393 test_hash_speed("tgr160", sec, generic_hash_speed_template);
2394 if (mode > 300 && mode < 400) break;
2397 test_hash_speed("tgr192", sec, generic_hash_speed_template);
2398 if (mode > 300 && mode < 400) break;
2401 test_hash_speed("sha224", sec, generic_hash_speed_template);
2402 if (mode > 300 && mode < 400) break;
2405 test_hash_speed("rmd128", sec, generic_hash_speed_template);
2406 if (mode > 300 && mode < 400) break;
2409 test_hash_speed("rmd160", sec, generic_hash_speed_template);
2410 if (mode > 300 && mode < 400) break;
2413 test_hash_speed("rmd256", sec, generic_hash_speed_template);
2414 if (mode > 300 && mode < 400) break;
2417 test_hash_speed("rmd320", sec, generic_hash_speed_template);
2418 if (mode > 300 && mode < 400) break;
2421 test_hash_speed("ghash-generic", sec, hash_speed_template_16);
2422 if (mode > 300 && mode < 400) break;
2425 test_hash_speed("crc32c", sec, generic_hash_speed_template);
2426 if (mode > 300 && mode < 400) break;
2429 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
2430 if (mode > 300 && mode < 400) break;
2433 test_hash_speed("poly1305", sec, poly1305_speed_template);
2434 if (mode > 300 && mode < 400) break;
2437 test_hash_speed("sha3-224", sec, generic_hash_speed_template);
2438 if (mode > 300 && mode < 400) break;
2441 test_hash_speed("sha3-256", sec, generic_hash_speed_template);
2442 if (mode > 300 && mode < 400) break;
2445 test_hash_speed("sha3-384", sec, generic_hash_speed_template);
2446 if (mode > 300 && mode < 400) break;
2449 test_hash_speed("sha3-512", sec, generic_hash_speed_template);
2450 if (mode > 300 && mode < 400) break;
2453 test_hash_speed("sm3", sec, generic_hash_speed_template);
2454 if (mode > 300 && mode < 400) break;
2457 test_hash_speed("streebog256", sec,
2458 generic_hash_speed_template);
2459 if (mode > 300 && mode < 400) break;
2462 test_hash_speed("streebog512", sec,
2463 generic_hash_speed_template);
2464 if (mode > 300 && mode < 400) break;
2471 test_ahash_speed(alg, sec, generic_hash_speed_template);
2476 test_ahash_speed("md4", sec, generic_hash_speed_template);
2477 if (mode > 400 && mode < 500) break;
2480 test_ahash_speed("md5", sec, generic_hash_speed_template);
2481 if (mode > 400 && mode < 500) break;
2484 test_ahash_speed("sha1", sec, generic_hash_speed_template);
2485 if (mode > 400 && mode < 500) break;
2488 test_ahash_speed("sha256", sec, generic_hash_speed_template);
2489 if (mode > 400 && mode < 500) break;
2492 test_ahash_speed("sha384", sec, generic_hash_speed_template);
2493 if (mode > 400 && mode < 500) break;
2496 test_ahash_speed("sha512", sec, generic_hash_speed_template);
2497 if (mode > 400 && mode < 500) break;
2500 test_ahash_speed("wp256", sec, generic_hash_speed_template);
2501 if (mode > 400 && mode < 500) break;
2504 test_ahash_speed("wp384", sec, generic_hash_speed_template);
2505 if (mode > 400 && mode < 500) break;
2508 test_ahash_speed("wp512", sec, generic_hash_speed_template);
2509 if (mode > 400 && mode < 500) break;
2512 test_ahash_speed("tgr128", sec, generic_hash_speed_template);
2513 if (mode > 400 && mode < 500) break;
2516 test_ahash_speed("tgr160", sec, generic_hash_speed_template);
2517 if (mode > 400 && mode < 500) break;
2520 test_ahash_speed("tgr192", sec, generic_hash_speed_template);
2521 if (mode > 400 && mode < 500) break;
2524 test_ahash_speed("sha224", sec, generic_hash_speed_template);
2525 if (mode > 400 && mode < 500) break;
2528 test_ahash_speed("rmd128", sec, generic_hash_speed_template);
2529 if (mode > 400 && mode < 500) break;
2532 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
2533 if (mode > 400 && mode < 500) break;
2536 test_ahash_speed("rmd256", sec, generic_hash_speed_template);
2537 if (mode > 400 && mode < 500) break;
2540 test_ahash_speed("rmd320", sec, generic_hash_speed_template);
2541 if (mode > 400 && mode < 500) break;
2544 test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
2545 if (mode > 400 && mode < 500) break;
2548 test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
2549 if (mode > 400 && mode < 500) break;
2552 test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
2553 if (mode > 400 && mode < 500) break;
2556 test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
2557 if (mode > 400 && mode < 500) break;
2560 test_mb_ahash_speed("sha1", sec, generic_hash_speed_template,
2562 if (mode > 400 && mode < 500) break;
2565 test_mb_ahash_speed("sha256", sec, generic_hash_speed_template,
2567 if (mode > 400 && mode < 500) break;
2570 test_mb_ahash_speed("sha512", sec, generic_hash_speed_template,
2572 if (mode > 400 && mode < 500) break;
2575 test_mb_ahash_speed("sm3", sec, generic_hash_speed_template,
2577 if (mode > 400 && mode < 500) break;
2580 test_mb_ahash_speed("streebog256", sec,
2581 generic_hash_speed_template, num_mb);
2582 if (mode > 400 && mode < 500) break;
2585 test_mb_ahash_speed("streebog512", sec,
2586 generic_hash_speed_template, num_mb);
2587 if (mode > 400 && mode < 500) break;
2593 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2594 speed_template_16_24_32);
2595 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2596 speed_template_16_24_32);
2597 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2598 speed_template_16_24_32);
2599 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2600 speed_template_16_24_32);
2601 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2602 speed_template_32_40_48);
2603 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2604 speed_template_32_40_48);
2605 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2606 speed_template_32_64);
2607 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2608 speed_template_32_64);
2609 test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2610 speed_template_16_24_32);
2611 test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2612 speed_template_16_24_32);
2613 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2614 speed_template_16_24_32);
2615 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2616 speed_template_16_24_32);
2617 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2618 speed_template_16_24_32);
2619 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2620 speed_template_16_24_32);
2621 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2622 speed_template_16_24_32);
2623 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2624 speed_template_16_24_32);
2625 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
2626 speed_template_20_28_36);
2627 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
2628 speed_template_20_28_36);
2632 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2633 des3_speed_template, DES3_SPEED_VECTORS,
2635 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
2636 des3_speed_template, DES3_SPEED_VECTORS,
2638 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2639 des3_speed_template, DES3_SPEED_VECTORS,
2641 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
2642 des3_speed_template, DES3_SPEED_VECTORS,
2644 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2645 des3_speed_template, DES3_SPEED_VECTORS,
2647 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
2648 des3_speed_template, DES3_SPEED_VECTORS,
2650 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2651 des3_speed_template, DES3_SPEED_VECTORS,
2653 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
2654 des3_speed_template, DES3_SPEED_VECTORS,
2659 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2661 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2663 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2665 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2667 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2669 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2671 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2673 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2678 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2679 speed_template_16_32);
2680 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2681 speed_template_16_32);
2682 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2683 speed_template_16_32);
2684 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2685 speed_template_16_32);
2686 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2687 speed_template_16_32);
2688 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2689 speed_template_16_32);
2690 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2691 speed_template_32_48);
2692 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2693 speed_template_32_48);
2694 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2695 speed_template_32_64);
2696 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2697 speed_template_32_64);
2701 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2702 speed_template_16_24_32);
2703 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2704 speed_template_16_24_32);
2705 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2706 speed_template_16_24_32);
2707 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2708 speed_template_16_24_32);
2709 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2710 speed_template_16_24_32);
2711 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2712 speed_template_16_24_32);
2713 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2714 speed_template_32_40_48);
2715 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2716 speed_template_32_40_48);
2717 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2718 speed_template_32_48_64);
2719 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2720 speed_template_32_48_64);
2724 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2729 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2730 speed_template_8_16);
2731 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2732 speed_template_8_16);
2733 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2734 speed_template_8_16);
2735 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2736 speed_template_8_16);
2737 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2738 speed_template_8_16);
2739 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2740 speed_template_8_16);
2744 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2745 speed_template_16_32);
2746 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2747 speed_template_16_32);
2748 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2749 speed_template_16_32);
2750 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2751 speed_template_16_32);
2752 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2753 speed_template_16_32);
2754 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2755 speed_template_16_32);
2756 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2757 speed_template_32_48);
2758 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2759 speed_template_32_48);
2760 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2761 speed_template_32_64);
2762 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2763 speed_template_32_64);
2767 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2768 speed_template_16_32);
2769 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2770 speed_template_16_32);
2771 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2772 speed_template_16_32);
2773 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2774 speed_template_16_32);
2775 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2776 speed_template_16_32);
2777 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2778 speed_template_16_32);
2779 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2780 speed_template_32_48);
2781 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2782 speed_template_32_48);
2783 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2784 speed_template_32_64);
2785 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2786 speed_template_32_64);
2790 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2791 speed_template_8_32);
2792 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2793 speed_template_8_32);
2794 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2795 speed_template_8_32);
2796 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2797 speed_template_8_32);
2798 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2799 speed_template_8_32);
2800 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2801 speed_template_8_32);
2805 test_mb_skcipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2806 speed_template_16_24_32, num_mb);
2807 test_mb_skcipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2808 speed_template_16_24_32, num_mb);
2809 test_mb_skcipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2810 speed_template_16_24_32, num_mb);
2811 test_mb_skcipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2812 speed_template_16_24_32, num_mb);
2813 test_mb_skcipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2814 speed_template_32_40_48, num_mb);
2815 test_mb_skcipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2816 speed_template_32_40_48, num_mb);
2817 test_mb_skcipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2818 speed_template_32_64, num_mb);
2819 test_mb_skcipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2820 speed_template_32_64, num_mb);
2821 test_mb_skcipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2822 speed_template_16_24_32, num_mb);
2823 test_mb_skcipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2824 speed_template_16_24_32, num_mb);
2825 test_mb_skcipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2826 speed_template_16_24_32, num_mb);
2827 test_mb_skcipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2828 speed_template_16_24_32, num_mb);
2829 test_mb_skcipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2830 speed_template_16_24_32, num_mb);
2831 test_mb_skcipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2832 speed_template_16_24_32, num_mb);
2833 test_mb_skcipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2834 speed_template_16_24_32, num_mb);
2835 test_mb_skcipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2836 speed_template_16_24_32, num_mb);
2837 test_mb_skcipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL,
2838 0, speed_template_20_28_36, num_mb);
2839 test_mb_skcipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL,
2840 0, speed_template_20_28_36, num_mb);
2844 test_mb_skcipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2845 des3_speed_template, DES3_SPEED_VECTORS,
2846 speed_template_24, num_mb);
2847 test_mb_skcipher_speed("ecb(des3_ede)", DECRYPT, sec,
2848 des3_speed_template, DES3_SPEED_VECTORS,
2849 speed_template_24, num_mb);
2850 test_mb_skcipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2851 des3_speed_template, DES3_SPEED_VECTORS,
2852 speed_template_24, num_mb);
2853 test_mb_skcipher_speed("cbc(des3_ede)", DECRYPT, sec,
2854 des3_speed_template, DES3_SPEED_VECTORS,
2855 speed_template_24, num_mb);
2856 test_mb_skcipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2857 des3_speed_template, DES3_SPEED_VECTORS,
2858 speed_template_24, num_mb);
2859 test_mb_skcipher_speed("cfb(des3_ede)", DECRYPT, sec,
2860 des3_speed_template, DES3_SPEED_VECTORS,
2861 speed_template_24, num_mb);
2862 test_mb_skcipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2863 des3_speed_template, DES3_SPEED_VECTORS,
2864 speed_template_24, num_mb);
2865 test_mb_skcipher_speed("ofb(des3_ede)", DECRYPT, sec,
2866 des3_speed_template, DES3_SPEED_VECTORS,
2867 speed_template_24, num_mb);
2871 test_mb_skcipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2872 speed_template_8, num_mb);
2873 test_mb_skcipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2874 speed_template_8, num_mb);
2875 test_mb_skcipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2876 speed_template_8, num_mb);
2877 test_mb_skcipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2878 speed_template_8, num_mb);
2879 test_mb_skcipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2880 speed_template_8, num_mb);
2881 test_mb_skcipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2882 speed_template_8, num_mb);
2883 test_mb_skcipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2884 speed_template_8, num_mb);
2885 test_mb_skcipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2886 speed_template_8, num_mb);
2890 test_mb_skcipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2891 speed_template_16_32, num_mb);
2892 test_mb_skcipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2893 speed_template_16_32, num_mb);
2894 test_mb_skcipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2895 speed_template_16_32, num_mb);
2896 test_mb_skcipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2897 speed_template_16_32, num_mb);
2898 test_mb_skcipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2899 speed_template_16_32, num_mb);
2900 test_mb_skcipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2901 speed_template_16_32, num_mb);
2902 test_mb_skcipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2903 speed_template_32_48, num_mb);
2904 test_mb_skcipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2905 speed_template_32_48, num_mb);
2906 test_mb_skcipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2907 speed_template_32_64, num_mb);
2908 test_mb_skcipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2909 speed_template_32_64, num_mb);
2913 test_mb_skcipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2914 speed_template_16_24_32, num_mb);
2915 test_mb_skcipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2916 speed_template_16_24_32, num_mb);
2917 test_mb_skcipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2918 speed_template_16_24_32, num_mb);
2919 test_mb_skcipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2920 speed_template_16_24_32, num_mb);
2921 test_mb_skcipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2922 speed_template_16_24_32, num_mb);
2923 test_mb_skcipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2924 speed_template_16_24_32, num_mb);
2925 test_mb_skcipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2926 speed_template_32_40_48, num_mb);
2927 test_mb_skcipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2928 speed_template_32_40_48, num_mb);
2929 test_mb_skcipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2930 speed_template_32_48_64, num_mb);
2931 test_mb_skcipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2932 speed_template_32_48_64, num_mb);
2936 test_mb_skcipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2937 speed_template_8, num_mb);
2941 test_mb_skcipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2942 speed_template_8_16, num_mb);
2943 test_mb_skcipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2944 speed_template_8_16, num_mb);
2945 test_mb_skcipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2946 speed_template_8_16, num_mb);
2947 test_mb_skcipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2948 speed_template_8_16, num_mb);
2949 test_mb_skcipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2950 speed_template_8_16, num_mb);
2951 test_mb_skcipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2952 speed_template_8_16, num_mb);
2956 test_mb_skcipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2957 speed_template_16_32, num_mb);
2958 test_mb_skcipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2959 speed_template_16_32, num_mb);
2960 test_mb_skcipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2961 speed_template_16_32, num_mb);
2962 test_mb_skcipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2963 speed_template_16_32, num_mb);
2964 test_mb_skcipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2965 speed_template_16_32, num_mb);
2966 test_mb_skcipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2967 speed_template_16_32, num_mb);
2968 test_mb_skcipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2969 speed_template_32_48, num_mb);
2970 test_mb_skcipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2971 speed_template_32_48, num_mb);
2972 test_mb_skcipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2973 speed_template_32_64, num_mb);
2974 test_mb_skcipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2975 speed_template_32_64, num_mb);
2979 test_mb_skcipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2980 speed_template_16_32, num_mb);
2981 test_mb_skcipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2982 speed_template_16_32, num_mb);
2983 test_mb_skcipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2984 speed_template_16_32, num_mb);
2985 test_mb_skcipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2986 speed_template_16_32, num_mb);
2987 test_mb_skcipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2988 speed_template_16_32, num_mb);
2989 test_mb_skcipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2990 speed_template_16_32, num_mb);
2991 test_mb_skcipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2992 speed_template_32_48, num_mb);
2993 test_mb_skcipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2994 speed_template_32_48, num_mb);
2995 test_mb_skcipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2996 speed_template_32_64, num_mb);
2997 test_mb_skcipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2998 speed_template_32_64, num_mb);
3002 test_mb_skcipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
3003 speed_template_8_32, num_mb);
3004 test_mb_skcipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
3005 speed_template_8_32, num_mb);
3006 test_mb_skcipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
3007 speed_template_8_32, num_mb);
3008 test_mb_skcipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
3009 speed_template_8_32, num_mb);
3010 test_mb_skcipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
3011 speed_template_8_32, num_mb);
3012 test_mb_skcipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
3013 speed_template_8_32, num_mb);
3024 static int __init tcrypt_mod_init(void)
3029 for (i = 0; i < TVMEMSIZE; i++) {
3030 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
3035 err = do_test(alg, type, mask, mode, num_mb);
3038 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
3041 pr_debug("all tests passed\n");
3044 /* We intentionaly return -EAGAIN to prevent keeping the module,
3045 * unless we're running in fips mode. It does all its work from
3046 * init() and doesn't offer any runtime functionality, but in
3047 * the fips case, checking for a successful load is helpful.
3048 * => we don't need it in the memory, do we?
3055 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
3056 free_page((unsigned long)tvmem[i]);
3062 * If an init function is provided, an exit function must also be provided
3063 * to allow module unload.
3065 static void __exit tcrypt_mod_fini(void) { }
3067 subsys_initcall(tcrypt_mod_init);
3068 module_exit(tcrypt_mod_fini);
3070 module_param(alg, charp, 0);
3071 module_param(type, uint, 0);
3072 module_param(mask, uint, 0);
3073 module_param(mode, int, 0);
3074 module_param(sec, uint, 0);
3075 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
3076 "(defaults to zero which uses CPU cycles instead)");
3077 module_param(num_mb, uint, 0000);
3078 MODULE_PARM_DESC(num_mb, "Number of concurrent requests to be used in mb speed tests (defaults to 8)");
3080 MODULE_LICENSE("GPL");
3081 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
3082 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");