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 (%llu bytes)\n",
202 bcount * num_mb, secs, (u64)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 pr_cont("%d operations in %d seconds (%llu bytes)\n",
472 bcount, secs, (u64)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 (%llu bytes)\n",
763 bcount * num_mb, secs, (u64)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 (%llu bytes)\n",
1200 bcount * num_mb, secs, (u64)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);
1284 for (i = 0; i < num_mb; ++i) {
1285 data[i].req = skcipher_request_alloc(tfm, GFP_KERNEL);
1287 pr_err("alg: skcipher: Failed to allocate request for %s\n",
1290 skcipher_request_free(data[i].req);
1295 for (i = 0; i < num_mb; ++i) {
1296 skcipher_request_set_callback(data[i].req,
1297 CRYPTO_TFM_REQ_MAY_BACKLOG,
1298 crypto_req_done, &data[i].wait);
1299 crypto_init_wait(&data[i].wait);
1302 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo,
1303 get_driver_name(crypto_skcipher, tfm), e);
1307 b_size = block_sizes;
1309 if (*b_size > XBUFSIZE * PAGE_SIZE) {
1310 pr_err("template (%u) too big for buffer (%lu)\n",
1311 *b_size, XBUFSIZE * PAGE_SIZE);
1315 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1316 *keysize * 8, *b_size);
1318 /* Set up tfm global state, i.e. the key */
1320 memset(tvmem[0], 0xff, PAGE_SIZE);
1322 for (j = 0; j < tcount; j++) {
1323 if (template[j].klen == *keysize) {
1324 key = template[j].key;
1329 crypto_skcipher_clear_flags(tfm, ~0);
1331 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1333 pr_err("setkey() failed flags=%x\n",
1334 crypto_skcipher_get_flags(tfm));
1338 iv_len = crypto_skcipher_ivsize(tfm);
1340 memset(&iv, 0xff, iv_len);
1342 /* Now setup per request stuff, i.e. buffers */
1344 for (j = 0; j < num_mb; ++j) {
1345 struct test_mb_skcipher_data *cur = &data[j];
1346 unsigned int k = *b_size;
1347 unsigned int pages = DIV_ROUND_UP(k, PAGE_SIZE);
1350 sg_init_table(cur->sg, pages);
1352 while (k > PAGE_SIZE) {
1353 sg_set_buf(cur->sg + p, cur->xbuf[p],
1355 memset(cur->xbuf[p], 0xff, PAGE_SIZE);
1360 sg_set_buf(cur->sg + p, cur->xbuf[p], k);
1361 memset(cur->xbuf[p], 0xff, k);
1363 skcipher_request_set_crypt(cur->req, cur->sg,
1369 ret = test_mb_acipher_jiffies(data, enc,
1374 ret = test_mb_acipher_cycles(data, enc,
1379 pr_err("%s() failed flags=%x\n", e,
1380 crypto_skcipher_get_flags(tfm));
1390 for (i = 0; i < num_mb; ++i)
1391 skcipher_request_free(data[i].req);
1393 for (i = 0; i < num_mb; ++i)
1394 testmgr_free_buf(data[i].xbuf);
1396 crypto_free_skcipher(tfm);
1401 static inline int do_one_acipher_op(struct skcipher_request *req, int ret)
1403 struct crypto_wait *wait = req->base.data;
1405 return crypto_wait_req(ret, wait);
1408 static int test_acipher_jiffies(struct skcipher_request *req, int enc,
1411 unsigned long start, end;
1415 for (start = jiffies, end = start + secs * HZ, bcount = 0;
1416 time_before(jiffies, end); bcount++) {
1418 ret = do_one_acipher_op(req,
1419 crypto_skcipher_encrypt(req));
1421 ret = do_one_acipher_op(req,
1422 crypto_skcipher_decrypt(req));
1428 pr_cont("%d operations in %d seconds (%llu bytes)\n",
1429 bcount, secs, (u64)bcount * blen);
1433 static int test_acipher_cycles(struct skcipher_request *req, int enc,
1436 unsigned long cycles = 0;
1441 for (i = 0; i < 4; i++) {
1443 ret = do_one_acipher_op(req,
1444 crypto_skcipher_encrypt(req));
1446 ret = do_one_acipher_op(req,
1447 crypto_skcipher_decrypt(req));
1453 /* The real thing. */
1454 for (i = 0; i < 8; i++) {
1455 cycles_t start, end;
1457 start = get_cycles();
1459 ret = do_one_acipher_op(req,
1460 crypto_skcipher_encrypt(req));
1462 ret = do_one_acipher_op(req,
1463 crypto_skcipher_decrypt(req));
1469 cycles += end - start;
1474 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1475 (cycles + 4) / 8, blen);
1480 static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
1481 struct cipher_speed_template *template,
1482 unsigned int tcount, u8 *keysize, bool async)
1484 unsigned int ret, i, j, k, iv_len;
1485 struct crypto_wait wait;
1488 struct skcipher_request *req;
1489 struct crypto_skcipher *tfm;
1498 crypto_init_wait(&wait);
1500 tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC);
1503 pr_err("failed to load transform for %s: %ld\n", algo,
1508 pr_info("\ntesting speed of async %s (%s) %s\n", algo,
1509 get_driver_name(crypto_skcipher, tfm), e);
1511 req = skcipher_request_alloc(tfm, GFP_KERNEL);
1513 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1518 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1519 crypto_req_done, &wait);
1523 b_size = block_sizes;
1526 struct scatterlist sg[TVMEMSIZE];
1528 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
1529 pr_err("template (%u) too big for "
1530 "tvmem (%lu)\n", *keysize + *b_size,
1531 TVMEMSIZE * PAGE_SIZE);
1535 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1536 *keysize * 8, *b_size);
1538 memset(tvmem[0], 0xff, PAGE_SIZE);
1540 /* set key, plain text and IV */
1542 for (j = 0; j < tcount; j++) {
1543 if (template[j].klen == *keysize) {
1544 key = template[j].key;
1549 crypto_skcipher_clear_flags(tfm, ~0);
1551 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1553 pr_err("setkey() failed flags=%x\n",
1554 crypto_skcipher_get_flags(tfm));
1558 k = *keysize + *b_size;
1559 sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
1561 if (k > PAGE_SIZE) {
1562 sg_set_buf(sg, tvmem[0] + *keysize,
1563 PAGE_SIZE - *keysize);
1566 while (k > PAGE_SIZE) {
1567 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
1568 memset(tvmem[j], 0xff, PAGE_SIZE);
1572 sg_set_buf(sg + j, tvmem[j], k);
1573 memset(tvmem[j], 0xff, k);
1575 sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
1578 iv_len = crypto_skcipher_ivsize(tfm);
1580 memset(&iv, 0xff, iv_len);
1582 skcipher_request_set_crypt(req, sg, sg, *b_size, iv);
1585 ret = test_acipher_jiffies(req, enc,
1589 ret = test_acipher_cycles(req, enc,
1594 pr_err("%s() failed flags=%x\n", e,
1595 crypto_skcipher_get_flags(tfm));
1605 skcipher_request_free(req);
1607 crypto_free_skcipher(tfm);
1610 static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
1611 struct cipher_speed_template *template,
1612 unsigned int tcount, u8 *keysize)
1614 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1618 static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
1619 struct cipher_speed_template *template,
1620 unsigned int tcount, u8 *keysize)
1622 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1626 static void test_available(void)
1628 char **name = check;
1631 printk("alg %s ", *name);
1632 printk(crypto_has_alg(*name, 0, 0) ?
1633 "found\n" : "not found\n");
1638 static inline int tcrypt_test(const char *alg)
1642 pr_debug("testing %s\n", alg);
1644 ret = alg_test(alg, alg, 0, 0);
1645 /* non-fips algs return -EINVAL in fips mode */
1646 if (fips_enabled && ret == -EINVAL)
1651 static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)
1659 if (!crypto_has_alg(alg, type,
1660 mask ?: CRYPTO_ALG_TYPE_MASK))
1665 for (i = 1; i < 200; i++)
1666 ret += do_test(NULL, 0, 0, i, num_mb);
1670 ret += tcrypt_test("md5");
1674 ret += tcrypt_test("sha1");
1678 ret += tcrypt_test("ecb(des)");
1679 ret += tcrypt_test("cbc(des)");
1680 ret += tcrypt_test("ctr(des)");
1684 ret += tcrypt_test("ecb(des3_ede)");
1685 ret += tcrypt_test("cbc(des3_ede)");
1686 ret += tcrypt_test("ctr(des3_ede)");
1690 ret += tcrypt_test("md4");
1694 ret += tcrypt_test("sha256");
1698 ret += tcrypt_test("ecb(blowfish)");
1699 ret += tcrypt_test("cbc(blowfish)");
1700 ret += tcrypt_test("ctr(blowfish)");
1704 ret += tcrypt_test("ecb(twofish)");
1705 ret += tcrypt_test("cbc(twofish)");
1706 ret += tcrypt_test("ctr(twofish)");
1707 ret += tcrypt_test("lrw(twofish)");
1708 ret += tcrypt_test("xts(twofish)");
1712 ret += tcrypt_test("ecb(serpent)");
1713 ret += tcrypt_test("cbc(serpent)");
1714 ret += tcrypt_test("ctr(serpent)");
1715 ret += tcrypt_test("lrw(serpent)");
1716 ret += tcrypt_test("xts(serpent)");
1720 ret += tcrypt_test("ecb(aes)");
1721 ret += tcrypt_test("cbc(aes)");
1722 ret += tcrypt_test("lrw(aes)");
1723 ret += tcrypt_test("xts(aes)");
1724 ret += tcrypt_test("ctr(aes)");
1725 ret += tcrypt_test("rfc3686(ctr(aes))");
1726 ret += tcrypt_test("ofb(aes)");
1727 ret += tcrypt_test("cfb(aes)");
1731 ret += tcrypt_test("sha384");
1735 ret += tcrypt_test("sha512");
1739 ret += tcrypt_test("deflate");
1743 ret += tcrypt_test("ecb(cast5)");
1744 ret += tcrypt_test("cbc(cast5)");
1745 ret += tcrypt_test("ctr(cast5)");
1749 ret += tcrypt_test("ecb(cast6)");
1750 ret += tcrypt_test("cbc(cast6)");
1751 ret += tcrypt_test("ctr(cast6)");
1752 ret += tcrypt_test("lrw(cast6)");
1753 ret += tcrypt_test("xts(cast6)");
1757 ret += tcrypt_test("ecb(arc4)");
1761 ret += tcrypt_test("michael_mic");
1765 ret += tcrypt_test("crc32c");
1769 ret += tcrypt_test("ecb(tea)");
1773 ret += tcrypt_test("ecb(xtea)");
1777 ret += tcrypt_test("ecb(khazad)");
1781 ret += tcrypt_test("wp512");
1785 ret += tcrypt_test("wp384");
1789 ret += tcrypt_test("wp256");
1793 ret += tcrypt_test("ecb(tnepres)");
1797 ret += tcrypt_test("ecb(anubis)");
1798 ret += tcrypt_test("cbc(anubis)");
1802 ret += tcrypt_test("tgr192");
1806 ret += tcrypt_test("tgr160");
1810 ret += tcrypt_test("tgr128");
1814 ret += tcrypt_test("ecb(xeta)");
1818 ret += tcrypt_test("pcbc(fcrypt)");
1822 ret += tcrypt_test("ecb(camellia)");
1823 ret += tcrypt_test("cbc(camellia)");
1824 ret += tcrypt_test("ctr(camellia)");
1825 ret += tcrypt_test("lrw(camellia)");
1826 ret += tcrypt_test("xts(camellia)");
1830 ret += tcrypt_test("sha224");
1834 ret += tcrypt_test("salsa20");
1838 ret += tcrypt_test("gcm(aes)");
1842 ret += tcrypt_test("lzo");
1846 ret += tcrypt_test("ccm(aes)");
1850 ret += tcrypt_test("cts(cbc(aes))");
1854 ret += tcrypt_test("rmd128");
1858 ret += tcrypt_test("rmd160");
1862 ret += tcrypt_test("rmd256");
1866 ret += tcrypt_test("rmd320");
1870 ret += tcrypt_test("ecb(seed)");
1874 ret += tcrypt_test("rfc4309(ccm(aes))");
1878 ret += tcrypt_test("ghash");
1882 ret += tcrypt_test("crct10dif");
1886 ret += tcrypt_test("sha3-224");
1890 ret += tcrypt_test("sha3-256");
1894 ret += tcrypt_test("sha3-384");
1898 ret += tcrypt_test("sha3-512");
1902 ret += tcrypt_test("sm3");
1906 ret += tcrypt_test("streebog256");
1910 ret += tcrypt_test("streebog512");
1914 ret += tcrypt_test("hmac(md5)");
1918 ret += tcrypt_test("hmac(sha1)");
1922 ret += tcrypt_test("hmac(sha256)");
1926 ret += tcrypt_test("hmac(sha384)");
1930 ret += tcrypt_test("hmac(sha512)");
1934 ret += tcrypt_test("hmac(sha224)");
1938 ret += tcrypt_test("xcbc(aes)");
1942 ret += tcrypt_test("hmac(rmd128)");
1946 ret += tcrypt_test("hmac(rmd160)");
1950 ret += tcrypt_test("vmac64(aes)");
1954 ret += tcrypt_test("hmac(sha3-224)");
1958 ret += tcrypt_test("hmac(sha3-256)");
1962 ret += tcrypt_test("hmac(sha3-384)");
1966 ret += tcrypt_test("hmac(sha3-512)");
1970 ret += tcrypt_test("hmac(streebog256)");
1974 ret += tcrypt_test("hmac(streebog512)");
1978 ret += tcrypt_test("ansi_cprng");
1982 ret += tcrypt_test("rfc4106(gcm(aes))");
1986 ret += tcrypt_test("rfc4543(gcm(aes))");
1990 ret += tcrypt_test("cmac(aes)");
1994 ret += tcrypt_test("cmac(des3_ede)");
1998 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
2002 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
2006 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
2009 ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
2012 ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
2015 ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
2018 ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
2021 ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
2024 ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
2027 ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
2030 ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
2033 ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
2036 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
2039 ret += tcrypt_test("ecb(sm4)");
2040 ret += tcrypt_test("cbc(sm4)");
2041 ret += tcrypt_test("ctr(sm4)");
2044 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2045 speed_template_16_24_32);
2046 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2047 speed_template_16_24_32);
2048 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2049 speed_template_16_24_32);
2050 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2051 speed_template_16_24_32);
2052 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2053 speed_template_32_40_48);
2054 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2055 speed_template_32_40_48);
2056 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2057 speed_template_32_64);
2058 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2059 speed_template_32_64);
2060 test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2061 speed_template_16_24_32);
2062 test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2063 speed_template_16_24_32);
2064 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2065 speed_template_16_24_32);
2066 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2067 speed_template_16_24_32);
2068 test_cipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2069 speed_template_16_24_32);
2070 test_cipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2071 speed_template_16_24_32);
2075 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2076 des3_speed_template, DES3_SPEED_VECTORS,
2078 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
2079 des3_speed_template, DES3_SPEED_VECTORS,
2081 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2082 des3_speed_template, DES3_SPEED_VECTORS,
2084 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
2085 des3_speed_template, DES3_SPEED_VECTORS,
2087 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
2088 des3_speed_template, DES3_SPEED_VECTORS,
2090 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
2091 des3_speed_template, DES3_SPEED_VECTORS,
2096 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2097 speed_template_16_24_32);
2098 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2099 speed_template_16_24_32);
2100 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2101 speed_template_16_24_32);
2102 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2103 speed_template_16_24_32);
2104 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2105 speed_template_16_24_32);
2106 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2107 speed_template_16_24_32);
2108 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2109 speed_template_32_40_48);
2110 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2111 speed_template_32_40_48);
2112 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2113 speed_template_32_48_64);
2114 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2115 speed_template_32_48_64);
2119 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2120 speed_template_8_32);
2121 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2122 speed_template_8_32);
2123 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2124 speed_template_8_32);
2125 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2126 speed_template_8_32);
2127 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2128 speed_template_8_32);
2129 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2130 speed_template_8_32);
2134 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2136 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2138 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2140 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2145 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2146 speed_template_16_24_32);
2147 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2148 speed_template_16_24_32);
2149 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2150 speed_template_16_24_32);
2151 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2152 speed_template_16_24_32);
2153 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2154 speed_template_16_24_32);
2155 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2156 speed_template_16_24_32);
2157 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2158 speed_template_32_40_48);
2159 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2160 speed_template_32_40_48);
2161 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2162 speed_template_32_48_64);
2163 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2164 speed_template_32_48_64);
2168 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
2169 speed_template_16_32);
2173 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2174 speed_template_16_32);
2175 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2176 speed_template_16_32);
2177 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2178 speed_template_16_32);
2179 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2180 speed_template_16_32);
2181 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2182 speed_template_16_32);
2183 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2184 speed_template_16_32);
2185 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2186 speed_template_32_48);
2187 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2188 speed_template_32_48);
2189 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2190 speed_template_32_64);
2191 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2192 speed_template_32_64);
2196 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2201 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2202 speed_template_8_16);
2203 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2204 speed_template_8_16);
2205 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2206 speed_template_8_16);
2207 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2208 speed_template_8_16);
2209 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2210 speed_template_8_16);
2211 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2212 speed_template_8_16);
2216 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2217 speed_template_16_32);
2218 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2219 speed_template_16_32);
2220 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2221 speed_template_16_32);
2222 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2223 speed_template_16_32);
2224 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2225 speed_template_16_32);
2226 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2227 speed_template_16_32);
2228 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2229 speed_template_32_48);
2230 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2231 speed_template_32_48);
2232 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2233 speed_template_32_64);
2234 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2235 speed_template_32_64);
2239 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
2240 NULL, 0, 16, 16, aead_speed_template_20);
2241 test_aead_speed("gcm(aes)", ENCRYPT, sec,
2242 NULL, 0, 16, 8, speed_template_16_24_32);
2243 test_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec,
2244 NULL, 0, 16, 16, aead_speed_template_20);
2245 test_aead_speed("gcm(aes)", DECRYPT, sec,
2246 NULL, 0, 16, 8, speed_template_16_24_32);
2250 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
2251 NULL, 0, 16, 16, aead_speed_template_19);
2252 test_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec,
2253 NULL, 0, 16, 16, aead_speed_template_19);
2257 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
2258 NULL, 0, 16, 8, aead_speed_template_36);
2259 test_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT, sec,
2260 NULL, 0, 16, 8, aead_speed_template_36);
2264 test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
2269 test_mb_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec, NULL,
2270 0, 16, 16, aead_speed_template_20, num_mb);
2271 test_mb_aead_speed("gcm(aes)", ENCRYPT, sec, NULL, 0, 16, 8,
2272 speed_template_16_24_32, num_mb);
2273 test_mb_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec, NULL,
2274 0, 16, 16, aead_speed_template_20, num_mb);
2275 test_mb_aead_speed("gcm(aes)", DECRYPT, sec, NULL, 0, 16, 8,
2276 speed_template_16_24_32, num_mb);
2280 test_mb_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec, NULL, 0,
2281 16, 16, aead_speed_template_19, num_mb);
2282 test_mb_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec, NULL, 0,
2283 16, 16, aead_speed_template_19, num_mb);
2287 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT,
2288 sec, NULL, 0, 16, 8, aead_speed_template_36,
2290 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT,
2291 sec, NULL, 0, 16, 8, aead_speed_template_36,
2296 test_cipher_speed("ecb(sm4)", ENCRYPT, sec, NULL, 0,
2298 test_cipher_speed("ecb(sm4)", DECRYPT, sec, NULL, 0,
2300 test_cipher_speed("cbc(sm4)", ENCRYPT, sec, NULL, 0,
2302 test_cipher_speed("cbc(sm4)", DECRYPT, sec, NULL, 0,
2304 test_cipher_speed("ctr(sm4)", ENCRYPT, sec, NULL, 0,
2306 test_cipher_speed("ctr(sm4)", DECRYPT, sec, NULL, 0,
2311 test_cipher_speed("adiantum(xchacha12,aes)", ENCRYPT, sec, NULL,
2312 0, speed_template_32);
2313 test_cipher_speed("adiantum(xchacha12,aes)", DECRYPT, sec, NULL,
2314 0, speed_template_32);
2315 test_cipher_speed("adiantum(xchacha20,aes)", ENCRYPT, sec, NULL,
2316 0, speed_template_32);
2317 test_cipher_speed("adiantum(xchacha20,aes)", DECRYPT, sec, NULL,
2318 0, speed_template_32);
2322 test_acipher_speed("essiv(cbc(aes),sha256)",
2323 ENCRYPT, sec, NULL, 0,
2324 speed_template_16_24_32);
2325 test_acipher_speed("essiv(cbc(aes),sha256)",
2326 DECRYPT, sec, NULL, 0,
2327 speed_template_16_24_32);
2331 test_aead_speed("aegis128", ENCRYPT, sec,
2332 NULL, 0, 16, 8, speed_template_16);
2333 test_aead_speed("aegis128", DECRYPT, sec,
2334 NULL, 0, 16, 8, speed_template_16);
2339 test_hash_speed(alg, sec, generic_hash_speed_template);
2344 test_hash_speed("md4", sec, generic_hash_speed_template);
2345 if (mode > 300 && mode < 400) break;
2348 test_hash_speed("md5", sec, generic_hash_speed_template);
2349 if (mode > 300 && mode < 400) break;
2352 test_hash_speed("sha1", sec, generic_hash_speed_template);
2353 if (mode > 300 && mode < 400) break;
2356 test_hash_speed("sha256", sec, generic_hash_speed_template);
2357 if (mode > 300 && mode < 400) break;
2360 test_hash_speed("sha384", sec, generic_hash_speed_template);
2361 if (mode > 300 && mode < 400) break;
2364 test_hash_speed("sha512", sec, generic_hash_speed_template);
2365 if (mode > 300 && mode < 400) break;
2368 test_hash_speed("wp256", sec, generic_hash_speed_template);
2369 if (mode > 300 && mode < 400) break;
2372 test_hash_speed("wp384", sec, generic_hash_speed_template);
2373 if (mode > 300 && mode < 400) break;
2376 test_hash_speed("wp512", sec, generic_hash_speed_template);
2377 if (mode > 300 && mode < 400) break;
2380 test_hash_speed("tgr128", sec, generic_hash_speed_template);
2381 if (mode > 300 && mode < 400) break;
2384 test_hash_speed("tgr160", sec, generic_hash_speed_template);
2385 if (mode > 300 && mode < 400) break;
2388 test_hash_speed("tgr192", sec, generic_hash_speed_template);
2389 if (mode > 300 && mode < 400) break;
2392 test_hash_speed("sha224", sec, generic_hash_speed_template);
2393 if (mode > 300 && mode < 400) break;
2396 test_hash_speed("rmd128", sec, generic_hash_speed_template);
2397 if (mode > 300 && mode < 400) break;
2400 test_hash_speed("rmd160", sec, generic_hash_speed_template);
2401 if (mode > 300 && mode < 400) break;
2404 test_hash_speed("rmd256", sec, generic_hash_speed_template);
2405 if (mode > 300 && mode < 400) break;
2408 test_hash_speed("rmd320", sec, generic_hash_speed_template);
2409 if (mode > 300 && mode < 400) break;
2412 test_hash_speed("ghash-generic", sec, hash_speed_template_16);
2413 if (mode > 300 && mode < 400) break;
2416 test_hash_speed("crc32c", sec, generic_hash_speed_template);
2417 if (mode > 300 && mode < 400) break;
2420 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
2421 if (mode > 300 && mode < 400) break;
2424 test_hash_speed("poly1305", sec, poly1305_speed_template);
2425 if (mode > 300 && mode < 400) break;
2428 test_hash_speed("sha3-224", sec, generic_hash_speed_template);
2429 if (mode > 300 && mode < 400) break;
2432 test_hash_speed("sha3-256", sec, generic_hash_speed_template);
2433 if (mode > 300 && mode < 400) break;
2436 test_hash_speed("sha3-384", sec, generic_hash_speed_template);
2437 if (mode > 300 && mode < 400) break;
2440 test_hash_speed("sha3-512", sec, generic_hash_speed_template);
2441 if (mode > 300 && mode < 400) break;
2444 test_hash_speed("sm3", sec, generic_hash_speed_template);
2445 if (mode > 300 && mode < 400) break;
2448 test_hash_speed("streebog256", sec,
2449 generic_hash_speed_template);
2450 if (mode > 300 && mode < 400) break;
2453 test_hash_speed("streebog512", sec,
2454 generic_hash_speed_template);
2455 if (mode > 300 && mode < 400) break;
2462 test_ahash_speed(alg, sec, generic_hash_speed_template);
2467 test_ahash_speed("md4", sec, generic_hash_speed_template);
2468 if (mode > 400 && mode < 500) break;
2471 test_ahash_speed("md5", sec, generic_hash_speed_template);
2472 if (mode > 400 && mode < 500) break;
2475 test_ahash_speed("sha1", sec, generic_hash_speed_template);
2476 if (mode > 400 && mode < 500) break;
2479 test_ahash_speed("sha256", sec, generic_hash_speed_template);
2480 if (mode > 400 && mode < 500) break;
2483 test_ahash_speed("sha384", sec, generic_hash_speed_template);
2484 if (mode > 400 && mode < 500) break;
2487 test_ahash_speed("sha512", sec, generic_hash_speed_template);
2488 if (mode > 400 && mode < 500) break;
2491 test_ahash_speed("wp256", sec, generic_hash_speed_template);
2492 if (mode > 400 && mode < 500) break;
2495 test_ahash_speed("wp384", sec, generic_hash_speed_template);
2496 if (mode > 400 && mode < 500) break;
2499 test_ahash_speed("wp512", sec, generic_hash_speed_template);
2500 if (mode > 400 && mode < 500) break;
2503 test_ahash_speed("tgr128", sec, generic_hash_speed_template);
2504 if (mode > 400 && mode < 500) break;
2507 test_ahash_speed("tgr160", sec, generic_hash_speed_template);
2508 if (mode > 400 && mode < 500) break;
2511 test_ahash_speed("tgr192", sec, generic_hash_speed_template);
2512 if (mode > 400 && mode < 500) break;
2515 test_ahash_speed("sha224", sec, generic_hash_speed_template);
2516 if (mode > 400 && mode < 500) break;
2519 test_ahash_speed("rmd128", sec, generic_hash_speed_template);
2520 if (mode > 400 && mode < 500) break;
2523 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
2524 if (mode > 400 && mode < 500) break;
2527 test_ahash_speed("rmd256", sec, generic_hash_speed_template);
2528 if (mode > 400 && mode < 500) break;
2531 test_ahash_speed("rmd320", sec, generic_hash_speed_template);
2532 if (mode > 400 && mode < 500) break;
2535 test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
2536 if (mode > 400 && mode < 500) break;
2539 test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
2540 if (mode > 400 && mode < 500) break;
2543 test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
2544 if (mode > 400 && mode < 500) break;
2547 test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
2548 if (mode > 400 && mode < 500) break;
2551 test_mb_ahash_speed("sha1", sec, generic_hash_speed_template,
2553 if (mode > 400 && mode < 500) break;
2556 test_mb_ahash_speed("sha256", sec, generic_hash_speed_template,
2558 if (mode > 400 && mode < 500) break;
2561 test_mb_ahash_speed("sha512", sec, generic_hash_speed_template,
2563 if (mode > 400 && mode < 500) break;
2566 test_mb_ahash_speed("sm3", sec, generic_hash_speed_template,
2568 if (mode > 400 && mode < 500) break;
2571 test_mb_ahash_speed("streebog256", sec,
2572 generic_hash_speed_template, num_mb);
2573 if (mode > 400 && mode < 500) break;
2576 test_mb_ahash_speed("streebog512", sec,
2577 generic_hash_speed_template, num_mb);
2578 if (mode > 400 && mode < 500) break;
2584 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2585 speed_template_16_24_32);
2586 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2587 speed_template_16_24_32);
2588 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2589 speed_template_16_24_32);
2590 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2591 speed_template_16_24_32);
2592 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2593 speed_template_32_40_48);
2594 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2595 speed_template_32_40_48);
2596 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2597 speed_template_32_64);
2598 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2599 speed_template_32_64);
2600 test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2601 speed_template_16_24_32);
2602 test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2603 speed_template_16_24_32);
2604 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2605 speed_template_16_24_32);
2606 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2607 speed_template_16_24_32);
2608 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2609 speed_template_16_24_32);
2610 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2611 speed_template_16_24_32);
2612 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2613 speed_template_16_24_32);
2614 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2615 speed_template_16_24_32);
2616 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
2617 speed_template_20_28_36);
2618 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
2619 speed_template_20_28_36);
2623 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2624 des3_speed_template, DES3_SPEED_VECTORS,
2626 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
2627 des3_speed_template, DES3_SPEED_VECTORS,
2629 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2630 des3_speed_template, DES3_SPEED_VECTORS,
2632 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
2633 des3_speed_template, DES3_SPEED_VECTORS,
2635 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2636 des3_speed_template, DES3_SPEED_VECTORS,
2638 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
2639 des3_speed_template, DES3_SPEED_VECTORS,
2641 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2642 des3_speed_template, DES3_SPEED_VECTORS,
2644 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
2645 des3_speed_template, DES3_SPEED_VECTORS,
2650 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2652 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2654 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2656 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2658 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2660 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2662 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2664 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2669 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2670 speed_template_16_32);
2671 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2672 speed_template_16_32);
2673 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2674 speed_template_16_32);
2675 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2676 speed_template_16_32);
2677 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2678 speed_template_16_32);
2679 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2680 speed_template_16_32);
2681 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2682 speed_template_32_48);
2683 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2684 speed_template_32_48);
2685 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2686 speed_template_32_64);
2687 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2688 speed_template_32_64);
2692 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2693 speed_template_16_24_32);
2694 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2695 speed_template_16_24_32);
2696 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2697 speed_template_16_24_32);
2698 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2699 speed_template_16_24_32);
2700 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2701 speed_template_16_24_32);
2702 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2703 speed_template_16_24_32);
2704 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2705 speed_template_32_40_48);
2706 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2707 speed_template_32_40_48);
2708 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2709 speed_template_32_48_64);
2710 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2711 speed_template_32_48_64);
2715 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2720 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2721 speed_template_8_16);
2722 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2723 speed_template_8_16);
2724 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2725 speed_template_8_16);
2726 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2727 speed_template_8_16);
2728 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2729 speed_template_8_16);
2730 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2731 speed_template_8_16);
2735 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2736 speed_template_16_32);
2737 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2738 speed_template_16_32);
2739 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2740 speed_template_16_32);
2741 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2742 speed_template_16_32);
2743 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2744 speed_template_16_32);
2745 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2746 speed_template_16_32);
2747 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2748 speed_template_32_48);
2749 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2750 speed_template_32_48);
2751 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2752 speed_template_32_64);
2753 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2754 speed_template_32_64);
2758 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2759 speed_template_16_32);
2760 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2761 speed_template_16_32);
2762 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2763 speed_template_16_32);
2764 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2765 speed_template_16_32);
2766 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2767 speed_template_16_32);
2768 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2769 speed_template_16_32);
2770 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2771 speed_template_32_48);
2772 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2773 speed_template_32_48);
2774 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2775 speed_template_32_64);
2776 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2777 speed_template_32_64);
2781 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2782 speed_template_8_32);
2783 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2784 speed_template_8_32);
2785 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2786 speed_template_8_32);
2787 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2788 speed_template_8_32);
2789 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2790 speed_template_8_32);
2791 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2792 speed_template_8_32);
2796 test_mb_skcipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2797 speed_template_16_24_32, num_mb);
2798 test_mb_skcipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2799 speed_template_16_24_32, num_mb);
2800 test_mb_skcipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2801 speed_template_16_24_32, num_mb);
2802 test_mb_skcipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2803 speed_template_16_24_32, num_mb);
2804 test_mb_skcipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2805 speed_template_32_40_48, num_mb);
2806 test_mb_skcipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2807 speed_template_32_40_48, num_mb);
2808 test_mb_skcipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2809 speed_template_32_64, num_mb);
2810 test_mb_skcipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2811 speed_template_32_64, num_mb);
2812 test_mb_skcipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2813 speed_template_16_24_32, num_mb);
2814 test_mb_skcipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2815 speed_template_16_24_32, num_mb);
2816 test_mb_skcipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2817 speed_template_16_24_32, num_mb);
2818 test_mb_skcipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2819 speed_template_16_24_32, num_mb);
2820 test_mb_skcipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2821 speed_template_16_24_32, num_mb);
2822 test_mb_skcipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2823 speed_template_16_24_32, num_mb);
2824 test_mb_skcipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2825 speed_template_16_24_32, num_mb);
2826 test_mb_skcipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2827 speed_template_16_24_32, num_mb);
2828 test_mb_skcipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL,
2829 0, speed_template_20_28_36, num_mb);
2830 test_mb_skcipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL,
2831 0, speed_template_20_28_36, num_mb);
2835 test_mb_skcipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2836 des3_speed_template, DES3_SPEED_VECTORS,
2837 speed_template_24, num_mb);
2838 test_mb_skcipher_speed("ecb(des3_ede)", DECRYPT, sec,
2839 des3_speed_template, DES3_SPEED_VECTORS,
2840 speed_template_24, num_mb);
2841 test_mb_skcipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2842 des3_speed_template, DES3_SPEED_VECTORS,
2843 speed_template_24, num_mb);
2844 test_mb_skcipher_speed("cbc(des3_ede)", DECRYPT, sec,
2845 des3_speed_template, DES3_SPEED_VECTORS,
2846 speed_template_24, num_mb);
2847 test_mb_skcipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2848 des3_speed_template, DES3_SPEED_VECTORS,
2849 speed_template_24, num_mb);
2850 test_mb_skcipher_speed("cfb(des3_ede)", DECRYPT, sec,
2851 des3_speed_template, DES3_SPEED_VECTORS,
2852 speed_template_24, num_mb);
2853 test_mb_skcipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2854 des3_speed_template, DES3_SPEED_VECTORS,
2855 speed_template_24, num_mb);
2856 test_mb_skcipher_speed("ofb(des3_ede)", DECRYPT, sec,
2857 des3_speed_template, DES3_SPEED_VECTORS,
2858 speed_template_24, num_mb);
2862 test_mb_skcipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2863 speed_template_8, num_mb);
2864 test_mb_skcipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2865 speed_template_8, num_mb);
2866 test_mb_skcipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2867 speed_template_8, num_mb);
2868 test_mb_skcipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2869 speed_template_8, num_mb);
2870 test_mb_skcipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2871 speed_template_8, num_mb);
2872 test_mb_skcipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2873 speed_template_8, num_mb);
2874 test_mb_skcipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2875 speed_template_8, num_mb);
2876 test_mb_skcipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2877 speed_template_8, num_mb);
2881 test_mb_skcipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2882 speed_template_16_32, num_mb);
2883 test_mb_skcipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2884 speed_template_16_32, num_mb);
2885 test_mb_skcipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2886 speed_template_16_32, num_mb);
2887 test_mb_skcipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2888 speed_template_16_32, num_mb);
2889 test_mb_skcipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2890 speed_template_16_32, num_mb);
2891 test_mb_skcipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2892 speed_template_16_32, num_mb);
2893 test_mb_skcipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2894 speed_template_32_48, num_mb);
2895 test_mb_skcipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2896 speed_template_32_48, num_mb);
2897 test_mb_skcipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2898 speed_template_32_64, num_mb);
2899 test_mb_skcipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2900 speed_template_32_64, num_mb);
2904 test_mb_skcipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2905 speed_template_16_24_32, num_mb);
2906 test_mb_skcipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2907 speed_template_16_24_32, num_mb);
2908 test_mb_skcipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2909 speed_template_16_24_32, num_mb);
2910 test_mb_skcipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2911 speed_template_16_24_32, num_mb);
2912 test_mb_skcipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2913 speed_template_16_24_32, num_mb);
2914 test_mb_skcipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2915 speed_template_16_24_32, num_mb);
2916 test_mb_skcipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2917 speed_template_32_40_48, num_mb);
2918 test_mb_skcipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2919 speed_template_32_40_48, num_mb);
2920 test_mb_skcipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2921 speed_template_32_48_64, num_mb);
2922 test_mb_skcipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2923 speed_template_32_48_64, num_mb);
2927 test_mb_skcipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2928 speed_template_8, num_mb);
2932 test_mb_skcipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2933 speed_template_8_16, num_mb);
2934 test_mb_skcipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2935 speed_template_8_16, num_mb);
2936 test_mb_skcipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2937 speed_template_8_16, num_mb);
2938 test_mb_skcipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2939 speed_template_8_16, num_mb);
2940 test_mb_skcipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2941 speed_template_8_16, num_mb);
2942 test_mb_skcipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2943 speed_template_8_16, num_mb);
2947 test_mb_skcipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2948 speed_template_16_32, num_mb);
2949 test_mb_skcipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2950 speed_template_16_32, num_mb);
2951 test_mb_skcipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2952 speed_template_16_32, num_mb);
2953 test_mb_skcipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2954 speed_template_16_32, num_mb);
2955 test_mb_skcipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2956 speed_template_16_32, num_mb);
2957 test_mb_skcipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2958 speed_template_16_32, num_mb);
2959 test_mb_skcipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2960 speed_template_32_48, num_mb);
2961 test_mb_skcipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2962 speed_template_32_48, num_mb);
2963 test_mb_skcipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2964 speed_template_32_64, num_mb);
2965 test_mb_skcipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2966 speed_template_32_64, num_mb);
2970 test_mb_skcipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2971 speed_template_16_32, num_mb);
2972 test_mb_skcipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2973 speed_template_16_32, num_mb);
2974 test_mb_skcipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2975 speed_template_16_32, num_mb);
2976 test_mb_skcipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2977 speed_template_16_32, num_mb);
2978 test_mb_skcipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2979 speed_template_16_32, num_mb);
2980 test_mb_skcipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2981 speed_template_16_32, num_mb);
2982 test_mb_skcipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2983 speed_template_32_48, num_mb);
2984 test_mb_skcipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2985 speed_template_32_48, num_mb);
2986 test_mb_skcipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2987 speed_template_32_64, num_mb);
2988 test_mb_skcipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2989 speed_template_32_64, num_mb);
2993 test_mb_skcipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2994 speed_template_8_32, num_mb);
2995 test_mb_skcipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2996 speed_template_8_32, num_mb);
2997 test_mb_skcipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2998 speed_template_8_32, num_mb);
2999 test_mb_skcipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
3000 speed_template_8_32, num_mb);
3001 test_mb_skcipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
3002 speed_template_8_32, num_mb);
3003 test_mb_skcipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
3004 speed_template_8_32, num_mb);
3015 static int __init tcrypt_mod_init(void)
3020 for (i = 0; i < TVMEMSIZE; i++) {
3021 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
3026 err = do_test(alg, type, mask, mode, num_mb);
3029 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
3032 pr_debug("all tests passed\n");
3035 /* We intentionaly return -EAGAIN to prevent keeping the module,
3036 * unless we're running in fips mode. It does all its work from
3037 * init() and doesn't offer any runtime functionality, but in
3038 * the fips case, checking for a successful load is helpful.
3039 * => we don't need it in the memory, do we?
3046 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
3047 free_page((unsigned long)tvmem[i]);
3053 * If an init function is provided, an exit function must also be provided
3054 * to allow module unload.
3056 static void __exit tcrypt_mod_fini(void) { }
3058 subsys_initcall(tcrypt_mod_init);
3059 module_exit(tcrypt_mod_fini);
3061 module_param(alg, charp, 0);
3062 module_param(type, uint, 0);
3063 module_param(mask, uint, 0);
3064 module_param(mode, int, 0);
3065 module_param(sec, uint, 0);
3066 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
3067 "(defaults to zero which uses CPU cycles instead)");
3068 module_param(num_mb, uint, 0000);
3069 MODULE_PARM_DESC(num_mb, "Number of concurrent requests to be used in mb speed tests (defaults to 8)");
3071 MODULE_LICENSE("GPL");
3072 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
3073 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");