2 * Quick & dirty crypto testing module.
4 * This will only exist until we have a better testing mechanism
5 * (e.g. a char device).
7 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
8 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
9 * Copyright (c) 2007 Nokia Siemens Networks
11 * Updated RFC4106 AES-GCM testing.
12 * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
13 * Adrian Hoban <adrian.hoban@intel.com>
14 * Gabriele Paoloni <gabriele.paoloni@intel.com>
15 * Tadeusz Struk (tadeusz.struk@intel.com)
16 * Copyright (c) 2010, Intel Corporation.
18 * This program is free software; you can redistribute it and/or modify it
19 * under the terms of the GNU General Public License as published by the Free
20 * Software Foundation; either version 2 of the License, or (at your option)
25 #include <crypto/aead.h>
26 #include <crypto/hash.h>
27 #include <linux/err.h>
28 #include <linux/fips.h>
29 #include <linux/init.h>
30 #include <linux/gfp.h>
31 #include <linux/module.h>
32 #include <linux/scatterlist.h>
33 #include <linux/string.h>
34 #include <linux/moduleparam.h>
35 #include <linux/jiffies.h>
36 #include <linux/timex.h>
37 #include <linux/interrupt.h>
41 * Need slab memory for testing (size in number of pages).
46 * Used by test_cipher_speed()
51 #define MAX_DIGEST_SIZE 64
54 * return a string with the driver name
56 #define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm))
59 * Used by test_cipher_speed()
61 static unsigned int sec;
63 static char *alg = NULL;
67 static char *tvmem[TVMEMSIZE];
69 static char *check[] = {
70 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
71 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
72 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
73 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
74 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
75 "lzo", "cts", "zlib", NULL
78 struct tcrypt_result {
79 struct completion completion;
83 static void tcrypt_complete(struct crypto_async_request *req, int err)
85 struct tcrypt_result *res = req->data;
87 if (err == -EINPROGRESS)
91 complete(&res->completion);
94 static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc,
95 struct scatterlist *sg, int blen, int secs)
97 unsigned long start, end;
101 for (start = jiffies, end = start + secs * HZ, bcount = 0;
102 time_before(jiffies, end); bcount++) {
104 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
106 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
112 printk("%d operations in %d seconds (%ld bytes)\n",
113 bcount, secs, (long)bcount * blen);
117 static int test_cipher_cycles(struct blkcipher_desc *desc, int enc,
118 struct scatterlist *sg, int blen)
120 unsigned long cycles = 0;
127 for (i = 0; i < 4; i++) {
129 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
131 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
137 /* The real thing. */
138 for (i = 0; i < 8; i++) {
141 start = get_cycles();
143 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
145 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
151 cycles += end - start;
158 printk("1 operation in %lu cycles (%d bytes)\n",
159 (cycles + 4) / 8, blen);
164 static inline int do_one_aead_op(struct aead_request *req, int ret)
166 if (ret == -EINPROGRESS || ret == -EBUSY) {
167 struct tcrypt_result *tr = req->base.data;
169 ret = wait_for_completion_interruptible(&tr->completion);
172 reinit_completion(&tr->completion);
178 static int test_aead_jiffies(struct aead_request *req, int enc,
181 unsigned long start, end;
185 for (start = jiffies, end = start + secs * HZ, bcount = 0;
186 time_before(jiffies, end); bcount++) {
188 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
190 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
196 printk("%d operations in %d seconds (%ld bytes)\n",
197 bcount, secs, (long)bcount * blen);
201 static int test_aead_cycles(struct aead_request *req, int enc, int blen)
203 unsigned long cycles = 0;
210 for (i = 0; i < 4; i++) {
212 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
214 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
220 /* The real thing. */
221 for (i = 0; i < 8; i++) {
224 start = get_cycles();
226 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
228 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
234 cycles += end - start;
241 printk("1 operation in %lu cycles (%d bytes)\n",
242 (cycles + 4) / 8, blen);
247 static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
248 static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
253 static int testmgr_alloc_buf(char *buf[XBUFSIZE])
257 for (i = 0; i < XBUFSIZE; i++) {
258 buf[i] = (void *)__get_free_page(GFP_KERNEL);
267 free_page((unsigned long)buf[i]);
272 static void testmgr_free_buf(char *buf[XBUFSIZE])
276 for (i = 0; i < XBUFSIZE; i++)
277 free_page((unsigned long)buf[i]);
280 static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],
283 int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
290 rem = buflen % PAGE_SIZE;
293 sg_init_table(sg, np + 1);
295 for (k = 0; k < np; k++)
296 sg_set_buf(&sg[k + 1], xbuf[k], PAGE_SIZE);
298 sg_set_buf(&sg[k + 1], xbuf[k], rem);
301 static void test_aead_speed(const char *algo, int enc, unsigned int secs,
302 struct aead_speed_template *template,
303 unsigned int tcount, u8 authsize,
304 unsigned int aad_size, u8 *keysize)
307 struct crypto_aead *tfm;
310 struct aead_request *req;
311 struct scatterlist *sg;
312 struct scatterlist *sgout;
316 char *xbuf[XBUFSIZE];
317 char *xoutbuf[XBUFSIZE];
318 char *axbuf[XBUFSIZE];
319 unsigned int *b_size;
321 struct tcrypt_result result;
323 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
327 if (aad_size >= PAGE_SIZE) {
328 pr_err("associate data length (%u) too big\n", aad_size);
337 if (testmgr_alloc_buf(xbuf))
339 if (testmgr_alloc_buf(axbuf))
341 if (testmgr_alloc_buf(xoutbuf))
344 sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL);
349 tfm = crypto_alloc_aead(algo, 0, 0);
352 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
357 init_completion(&result.completion);
358 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
359 get_driver_name(crypto_aead, tfm), e);
361 req = aead_request_alloc(tfm, GFP_KERNEL);
363 pr_err("alg: aead: Failed to allocate request for %s\n",
368 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
369 tcrypt_complete, &result);
376 memset(assoc, 0xff, aad_size);
378 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
379 pr_err("template (%u) too big for tvmem (%lu)\n",
381 TVMEMSIZE * PAGE_SIZE);
386 for (j = 0; j < tcount; j++) {
387 if (template[j].klen == *keysize) {
388 key = template[j].key;
392 ret = crypto_aead_setkey(tfm, key, *keysize);
393 ret = crypto_aead_setauthsize(tfm, authsize);
395 iv_len = crypto_aead_ivsize(tfm);
397 memset(iv, 0xff, iv_len);
399 crypto_aead_clear_flags(tfm, ~0);
400 printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
401 i, *keysize * 8, *b_size);
404 memset(tvmem[0], 0xff, PAGE_SIZE);
407 pr_err("setkey() failed flags=%x\n",
408 crypto_aead_get_flags(tfm));
412 sg_init_aead(sg, xbuf,
413 *b_size + (enc ? authsize : 0));
415 sg_init_aead(sgout, xoutbuf,
416 *b_size + (enc ? authsize : 0));
418 sg_set_buf(&sg[0], assoc, aad_size);
419 sg_set_buf(&sgout[0], assoc, aad_size);
421 aead_request_set_crypt(req, sg, sgout, *b_size, iv);
422 aead_request_set_ad(req, aad_size);
425 ret = test_aead_jiffies(req, enc, *b_size,
428 ret = test_aead_cycles(req, enc, *b_size);
431 pr_err("%s() failed return code=%d\n", e, ret);
441 aead_request_free(req);
443 crypto_free_aead(tfm);
447 testmgr_free_buf(xoutbuf);
449 testmgr_free_buf(axbuf);
451 testmgr_free_buf(xbuf);
457 static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
458 struct cipher_speed_template *template,
459 unsigned int tcount, u8 *keysize)
461 unsigned int ret, i, j, iv_len;
464 struct crypto_blkcipher *tfm;
465 struct blkcipher_desc desc;
474 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
477 printk("failed to load transform for %s: %ld\n", algo,
484 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
485 get_driver_name(crypto_blkcipher, tfm), e);
490 b_size = block_sizes;
492 struct scatterlist sg[TVMEMSIZE];
494 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
495 printk("template (%u) too big for "
496 "tvmem (%lu)\n", *keysize + *b_size,
497 TVMEMSIZE * PAGE_SIZE);
501 printk("test %u (%d bit key, %d byte blocks): ", i,
502 *keysize * 8, *b_size);
504 memset(tvmem[0], 0xff, PAGE_SIZE);
506 /* set key, plain text and IV */
508 for (j = 0; j < tcount; j++) {
509 if (template[j].klen == *keysize) {
510 key = template[j].key;
515 ret = crypto_blkcipher_setkey(tfm, key, *keysize);
517 printk("setkey() failed flags=%x\n",
518 crypto_blkcipher_get_flags(tfm));
522 sg_init_table(sg, TVMEMSIZE);
523 sg_set_buf(sg, tvmem[0] + *keysize,
524 PAGE_SIZE - *keysize);
525 for (j = 1; j < TVMEMSIZE; j++) {
526 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
527 memset (tvmem[j], 0xff, PAGE_SIZE);
530 iv_len = crypto_blkcipher_ivsize(tfm);
532 memset(&iv, 0xff, iv_len);
533 crypto_blkcipher_set_iv(tfm, iv, iv_len);
537 ret = test_cipher_jiffies(&desc, enc, sg,
540 ret = test_cipher_cycles(&desc, enc, sg,
544 printk("%s() failed flags=%x\n", e, desc.flags);
554 crypto_free_blkcipher(tfm);
557 static int test_hash_jiffies_digest(struct hash_desc *desc,
558 struct scatterlist *sg, int blen,
561 unsigned long start, end;
565 for (start = jiffies, end = start + secs * HZ, bcount = 0;
566 time_before(jiffies, end); bcount++) {
567 ret = crypto_hash_digest(desc, sg, blen, out);
572 printk("%6u opers/sec, %9lu bytes/sec\n",
573 bcount / secs, ((long)bcount * blen) / secs);
578 static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg,
579 int blen, int plen, char *out, int secs)
581 unsigned long start, end;
586 return test_hash_jiffies_digest(desc, sg, blen, out, secs);
588 for (start = jiffies, end = start + secs * HZ, bcount = 0;
589 time_before(jiffies, end); bcount++) {
590 ret = crypto_hash_init(desc);
593 for (pcount = 0; pcount < blen; pcount += plen) {
594 ret = crypto_hash_update(desc, sg, plen);
598 /* we assume there is enough space in 'out' for the result */
599 ret = crypto_hash_final(desc, out);
604 printk("%6u opers/sec, %9lu bytes/sec\n",
605 bcount / secs, ((long)bcount * blen) / secs);
610 static int test_hash_cycles_digest(struct hash_desc *desc,
611 struct scatterlist *sg, int blen, char *out)
613 unsigned long cycles = 0;
620 for (i = 0; i < 4; i++) {
621 ret = crypto_hash_digest(desc, sg, blen, out);
626 /* The real thing. */
627 for (i = 0; i < 8; i++) {
630 start = get_cycles();
632 ret = crypto_hash_digest(desc, sg, blen, out);
638 cycles += end - start;
647 printk("%6lu cycles/operation, %4lu cycles/byte\n",
648 cycles / 8, cycles / (8 * blen));
653 static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg,
654 int blen, int plen, char *out)
656 unsigned long cycles = 0;
661 return test_hash_cycles_digest(desc, sg, blen, out);
666 for (i = 0; i < 4; i++) {
667 ret = crypto_hash_init(desc);
670 for (pcount = 0; pcount < blen; pcount += plen) {
671 ret = crypto_hash_update(desc, sg, plen);
675 ret = crypto_hash_final(desc, out);
680 /* The real thing. */
681 for (i = 0; i < 8; i++) {
684 start = get_cycles();
686 ret = crypto_hash_init(desc);
689 for (pcount = 0; pcount < blen; pcount += plen) {
690 ret = crypto_hash_update(desc, sg, plen);
694 ret = crypto_hash_final(desc, out);
700 cycles += end - start;
709 printk("%6lu cycles/operation, %4lu cycles/byte\n",
710 cycles / 8, cycles / (8 * blen));
715 static void test_hash_sg_init(struct scatterlist *sg)
719 sg_init_table(sg, TVMEMSIZE);
720 for (i = 0; i < TVMEMSIZE; i++) {
721 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
722 memset(tvmem[i], 0xff, PAGE_SIZE);
726 static void test_hash_speed(const char *algo, unsigned int secs,
727 struct hash_speed *speed)
729 struct scatterlist sg[TVMEMSIZE];
730 struct crypto_hash *tfm;
731 struct hash_desc desc;
732 static char output[1024];
736 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
739 printk(KERN_ERR "failed to load transform for %s: %ld\n", algo,
744 printk(KERN_INFO "\ntesting speed of %s (%s)\n", algo,
745 get_driver_name(crypto_hash, tfm));
750 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
751 printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n",
752 crypto_hash_digestsize(tfm), sizeof(output));
756 test_hash_sg_init(sg);
757 for (i = 0; speed[i].blen != 0; i++) {
758 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
760 "template (%u) too big for tvmem (%lu)\n",
761 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
766 crypto_hash_setkey(tfm, tvmem[0], speed[i].klen);
768 printk(KERN_INFO "test%3u "
769 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
770 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
773 ret = test_hash_jiffies(&desc, sg, speed[i].blen,
774 speed[i].plen, output, secs);
776 ret = test_hash_cycles(&desc, sg, speed[i].blen,
777 speed[i].plen, output);
780 printk(KERN_ERR "hashing failed ret=%d\n", ret);
786 crypto_free_hash(tfm);
789 static inline int do_one_ahash_op(struct ahash_request *req, int ret)
791 if (ret == -EINPROGRESS || ret == -EBUSY) {
792 struct tcrypt_result *tr = req->base.data;
794 wait_for_completion(&tr->completion);
795 reinit_completion(&tr->completion);
801 static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
804 unsigned long start, end;
808 for (start = jiffies, end = start + secs * HZ, bcount = 0;
809 time_before(jiffies, end); bcount++) {
810 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
815 printk("%6u opers/sec, %9lu bytes/sec\n",
816 bcount / secs, ((long)bcount * blen) / secs);
821 static int test_ahash_jiffies(struct ahash_request *req, int blen,
822 int plen, char *out, int secs)
824 unsigned long start, end;
829 return test_ahash_jiffies_digest(req, blen, out, secs);
831 for (start = jiffies, end = start + secs * HZ, bcount = 0;
832 time_before(jiffies, end); bcount++) {
833 ret = do_one_ahash_op(req, crypto_ahash_init(req));
836 for (pcount = 0; pcount < blen; pcount += plen) {
837 ret = do_one_ahash_op(req, crypto_ahash_update(req));
841 /* we assume there is enough space in 'out' for the result */
842 ret = do_one_ahash_op(req, crypto_ahash_final(req));
847 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
848 bcount / secs, ((long)bcount * blen) / secs);
853 static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
856 unsigned long cycles = 0;
860 for (i = 0; i < 4; i++) {
861 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
866 /* The real thing. */
867 for (i = 0; i < 8; i++) {
870 start = get_cycles();
872 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
878 cycles += end - start;
885 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
886 cycles / 8, cycles / (8 * blen));
891 static int test_ahash_cycles(struct ahash_request *req, int blen,
894 unsigned long cycles = 0;
898 return test_ahash_cycles_digest(req, blen, out);
901 for (i = 0; i < 4; i++) {
902 ret = do_one_ahash_op(req, crypto_ahash_init(req));
905 for (pcount = 0; pcount < blen; pcount += plen) {
906 ret = do_one_ahash_op(req, crypto_ahash_update(req));
910 ret = do_one_ahash_op(req, crypto_ahash_final(req));
915 /* The real thing. */
916 for (i = 0; i < 8; i++) {
919 start = get_cycles();
921 ret = do_one_ahash_op(req, crypto_ahash_init(req));
924 for (pcount = 0; pcount < blen; pcount += plen) {
925 ret = do_one_ahash_op(req, crypto_ahash_update(req));
929 ret = do_one_ahash_op(req, crypto_ahash_final(req));
935 cycles += end - start;
942 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
943 cycles / 8, cycles / (8 * blen));
948 static void test_ahash_speed(const char *algo, unsigned int secs,
949 struct hash_speed *speed)
951 struct scatterlist sg[TVMEMSIZE];
952 struct tcrypt_result tresult;
953 struct ahash_request *req;
954 struct crypto_ahash *tfm;
958 tfm = crypto_alloc_ahash(algo, 0, 0);
960 pr_err("failed to load transform for %s: %ld\n",
965 printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
966 get_driver_name(crypto_ahash, tfm));
968 if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) {
969 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm),
974 test_hash_sg_init(sg);
975 req = ahash_request_alloc(tfm, GFP_KERNEL);
977 pr_err("ahash request allocation failure\n");
981 init_completion(&tresult.completion);
982 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
983 tcrypt_complete, &tresult);
985 output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
989 for (i = 0; speed[i].blen != 0; i++) {
990 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
991 pr_err("template (%u) too big for tvmem (%lu)\n",
992 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
997 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
998 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
1000 ahash_request_set_crypt(req, sg, output, speed[i].plen);
1003 ret = test_ahash_jiffies(req, speed[i].blen,
1004 speed[i].plen, output, secs);
1006 ret = test_ahash_cycles(req, speed[i].blen,
1007 speed[i].plen, output);
1010 pr_err("hashing failed ret=%d\n", ret);
1018 ahash_request_free(req);
1021 crypto_free_ahash(tfm);
1024 static inline int do_one_acipher_op(struct ablkcipher_request *req, int ret)
1026 if (ret == -EINPROGRESS || ret == -EBUSY) {
1027 struct tcrypt_result *tr = req->base.data;
1029 wait_for_completion(&tr->completion);
1030 reinit_completion(&tr->completion);
1037 static int test_acipher_jiffies(struct ablkcipher_request *req, int enc,
1040 unsigned long start, end;
1044 for (start = jiffies, end = start + secs * HZ, bcount = 0;
1045 time_before(jiffies, end); bcount++) {
1047 ret = do_one_acipher_op(req,
1048 crypto_ablkcipher_encrypt(req));
1050 ret = do_one_acipher_op(req,
1051 crypto_ablkcipher_decrypt(req));
1057 pr_cont("%d operations in %d seconds (%ld bytes)\n",
1058 bcount, secs, (long)bcount * blen);
1062 static int test_acipher_cycles(struct ablkcipher_request *req, int enc,
1065 unsigned long cycles = 0;
1070 for (i = 0; i < 4; i++) {
1072 ret = do_one_acipher_op(req,
1073 crypto_ablkcipher_encrypt(req));
1075 ret = do_one_acipher_op(req,
1076 crypto_ablkcipher_decrypt(req));
1082 /* The real thing. */
1083 for (i = 0; i < 8; i++) {
1084 cycles_t start, end;
1086 start = get_cycles();
1088 ret = do_one_acipher_op(req,
1089 crypto_ablkcipher_encrypt(req));
1091 ret = do_one_acipher_op(req,
1092 crypto_ablkcipher_decrypt(req));
1098 cycles += end - start;
1103 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1104 (cycles + 4) / 8, blen);
1109 static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
1110 struct cipher_speed_template *template,
1111 unsigned int tcount, u8 *keysize)
1113 unsigned int ret, i, j, k, iv_len;
1114 struct tcrypt_result tresult;
1117 struct ablkcipher_request *req;
1118 struct crypto_ablkcipher *tfm;
1127 init_completion(&tresult.completion);
1129 tfm = crypto_alloc_ablkcipher(algo, 0, 0);
1132 pr_err("failed to load transform for %s: %ld\n", algo,
1137 pr_info("\ntesting speed of async %s (%s) %s\n", algo,
1138 get_driver_name(crypto_ablkcipher, tfm), e);
1140 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
1142 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1147 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1148 tcrypt_complete, &tresult);
1152 b_size = block_sizes;
1155 struct scatterlist sg[TVMEMSIZE];
1157 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
1158 pr_err("template (%u) too big for "
1159 "tvmem (%lu)\n", *keysize + *b_size,
1160 TVMEMSIZE * PAGE_SIZE);
1164 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1165 *keysize * 8, *b_size);
1167 memset(tvmem[0], 0xff, PAGE_SIZE);
1169 /* set key, plain text and IV */
1171 for (j = 0; j < tcount; j++) {
1172 if (template[j].klen == *keysize) {
1173 key = template[j].key;
1178 crypto_ablkcipher_clear_flags(tfm, ~0);
1180 ret = crypto_ablkcipher_setkey(tfm, key, *keysize);
1182 pr_err("setkey() failed flags=%x\n",
1183 crypto_ablkcipher_get_flags(tfm));
1187 k = *keysize + *b_size;
1188 sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
1190 if (k > PAGE_SIZE) {
1191 sg_set_buf(sg, tvmem[0] + *keysize,
1192 PAGE_SIZE - *keysize);
1195 while (k > PAGE_SIZE) {
1196 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
1197 memset(tvmem[j], 0xff, PAGE_SIZE);
1201 sg_set_buf(sg + j, tvmem[j], k);
1202 memset(tvmem[j], 0xff, k);
1204 sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
1207 iv_len = crypto_ablkcipher_ivsize(tfm);
1209 memset(&iv, 0xff, iv_len);
1211 ablkcipher_request_set_crypt(req, sg, sg, *b_size, iv);
1214 ret = test_acipher_jiffies(req, enc,
1217 ret = test_acipher_cycles(req, enc,
1221 pr_err("%s() failed flags=%x\n", e,
1222 crypto_ablkcipher_get_flags(tfm));
1232 ablkcipher_request_free(req);
1234 crypto_free_ablkcipher(tfm);
1237 static void test_available(void)
1239 char **name = check;
1242 printk("alg %s ", *name);
1243 printk(crypto_has_alg(*name, 0, 0) ?
1244 "found\n" : "not found\n");
1249 static inline int tcrypt_test(const char *alg)
1253 ret = alg_test(alg, alg, 0, 0);
1254 /* non-fips algs return -EINVAL in fips mode */
1255 if (fips_enabled && ret == -EINVAL)
1260 static int do_test(const char *alg, u32 type, u32 mask, int m)
1268 if (!crypto_has_alg(alg, type,
1269 mask ?: CRYPTO_ALG_TYPE_MASK))
1274 for (i = 1; i < 200; i++)
1275 ret += do_test(NULL, 0, 0, i);
1279 ret += tcrypt_test("md5");
1283 ret += tcrypt_test("sha1");
1287 ret += tcrypt_test("ecb(des)");
1288 ret += tcrypt_test("cbc(des)");
1289 ret += tcrypt_test("ctr(des)");
1293 ret += tcrypt_test("ecb(des3_ede)");
1294 ret += tcrypt_test("cbc(des3_ede)");
1295 ret += tcrypt_test("ctr(des3_ede)");
1299 ret += tcrypt_test("md4");
1303 ret += tcrypt_test("sha256");
1307 ret += tcrypt_test("ecb(blowfish)");
1308 ret += tcrypt_test("cbc(blowfish)");
1309 ret += tcrypt_test("ctr(blowfish)");
1313 ret += tcrypt_test("ecb(twofish)");
1314 ret += tcrypt_test("cbc(twofish)");
1315 ret += tcrypt_test("ctr(twofish)");
1316 ret += tcrypt_test("lrw(twofish)");
1317 ret += tcrypt_test("xts(twofish)");
1321 ret += tcrypt_test("ecb(serpent)");
1322 ret += tcrypt_test("cbc(serpent)");
1323 ret += tcrypt_test("ctr(serpent)");
1324 ret += tcrypt_test("lrw(serpent)");
1325 ret += tcrypt_test("xts(serpent)");
1329 ret += tcrypt_test("ecb(aes)");
1330 ret += tcrypt_test("cbc(aes)");
1331 ret += tcrypt_test("lrw(aes)");
1332 ret += tcrypt_test("xts(aes)");
1333 ret += tcrypt_test("ctr(aes)");
1334 ret += tcrypt_test("rfc3686(ctr(aes))");
1338 ret += tcrypt_test("sha384");
1342 ret += tcrypt_test("sha512");
1346 ret += tcrypt_test("deflate");
1350 ret += tcrypt_test("ecb(cast5)");
1351 ret += tcrypt_test("cbc(cast5)");
1352 ret += tcrypt_test("ctr(cast5)");
1356 ret += tcrypt_test("ecb(cast6)");
1357 ret += tcrypt_test("cbc(cast6)");
1358 ret += tcrypt_test("ctr(cast6)");
1359 ret += tcrypt_test("lrw(cast6)");
1360 ret += tcrypt_test("xts(cast6)");
1364 ret += tcrypt_test("ecb(arc4)");
1368 ret += tcrypt_test("michael_mic");
1372 ret += tcrypt_test("crc32c");
1376 ret += tcrypt_test("ecb(tea)");
1380 ret += tcrypt_test("ecb(xtea)");
1384 ret += tcrypt_test("ecb(khazad)");
1388 ret += tcrypt_test("wp512");
1392 ret += tcrypt_test("wp384");
1396 ret += tcrypt_test("wp256");
1400 ret += tcrypt_test("ecb(tnepres)");
1404 ret += tcrypt_test("ecb(anubis)");
1405 ret += tcrypt_test("cbc(anubis)");
1409 ret += tcrypt_test("tgr192");
1413 ret += tcrypt_test("tgr160");
1417 ret += tcrypt_test("tgr128");
1421 ret += tcrypt_test("ecb(xeta)");
1425 ret += tcrypt_test("pcbc(fcrypt)");
1429 ret += tcrypt_test("ecb(camellia)");
1430 ret += tcrypt_test("cbc(camellia)");
1431 ret += tcrypt_test("ctr(camellia)");
1432 ret += tcrypt_test("lrw(camellia)");
1433 ret += tcrypt_test("xts(camellia)");
1437 ret += tcrypt_test("sha224");
1441 ret += tcrypt_test("salsa20");
1445 ret += tcrypt_test("gcm(aes)");
1449 ret += tcrypt_test("lzo");
1453 ret += tcrypt_test("ccm(aes)");
1457 ret += tcrypt_test("cts(cbc(aes))");
1461 ret += tcrypt_test("rmd128");
1465 ret += tcrypt_test("rmd160");
1469 ret += tcrypt_test("rmd256");
1473 ret += tcrypt_test("rmd320");
1477 ret += tcrypt_test("ecb(seed)");
1481 ret += tcrypt_test("zlib");
1485 ret += tcrypt_test("rfc4309(ccm(aes))");
1489 ret += tcrypt_test("ghash");
1493 ret += tcrypt_test("crct10dif");
1497 ret += tcrypt_test("hmac(md5)");
1501 ret += tcrypt_test("hmac(sha1)");
1505 ret += tcrypt_test("hmac(sha256)");
1509 ret += tcrypt_test("hmac(sha384)");
1513 ret += tcrypt_test("hmac(sha512)");
1517 ret += tcrypt_test("hmac(sha224)");
1521 ret += tcrypt_test("xcbc(aes)");
1525 ret += tcrypt_test("hmac(rmd128)");
1529 ret += tcrypt_test("hmac(rmd160)");
1533 ret += tcrypt_test("vmac(aes)");
1537 ret += tcrypt_test("hmac(crc32)");
1541 ret += tcrypt_test("ansi_cprng");
1545 ret += tcrypt_test("rfc4106(gcm(aes))");
1549 ret += tcrypt_test("rfc4543(gcm(aes))");
1553 ret += tcrypt_test("cmac(aes)");
1557 ret += tcrypt_test("cmac(des3_ede)");
1561 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1565 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1569 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1572 ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
1575 ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
1578 ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
1581 ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
1584 ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
1587 ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
1590 ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
1593 ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
1596 ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
1599 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
1602 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1603 speed_template_16_24_32);
1604 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1605 speed_template_16_24_32);
1606 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1607 speed_template_16_24_32);
1608 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1609 speed_template_16_24_32);
1610 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1611 speed_template_32_40_48);
1612 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1613 speed_template_32_40_48);
1614 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1615 speed_template_32_48_64);
1616 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1617 speed_template_32_48_64);
1618 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1619 speed_template_16_24_32);
1620 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1621 speed_template_16_24_32);
1625 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1626 des3_speed_template, DES3_SPEED_VECTORS,
1628 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1629 des3_speed_template, DES3_SPEED_VECTORS,
1631 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1632 des3_speed_template, DES3_SPEED_VECTORS,
1634 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1635 des3_speed_template, DES3_SPEED_VECTORS,
1637 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
1638 des3_speed_template, DES3_SPEED_VECTORS,
1640 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
1641 des3_speed_template, DES3_SPEED_VECTORS,
1646 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1647 speed_template_16_24_32);
1648 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1649 speed_template_16_24_32);
1650 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1651 speed_template_16_24_32);
1652 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1653 speed_template_16_24_32);
1654 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1655 speed_template_16_24_32);
1656 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1657 speed_template_16_24_32);
1658 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1659 speed_template_32_40_48);
1660 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1661 speed_template_32_40_48);
1662 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1663 speed_template_32_48_64);
1664 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1665 speed_template_32_48_64);
1669 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1670 speed_template_8_32);
1671 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1672 speed_template_8_32);
1673 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1674 speed_template_8_32);
1675 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1676 speed_template_8_32);
1677 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
1678 speed_template_8_32);
1679 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
1680 speed_template_8_32);
1684 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1686 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1688 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1690 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1695 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1696 speed_template_16_24_32);
1697 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1698 speed_template_16_24_32);
1699 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1700 speed_template_16_24_32);
1701 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1702 speed_template_16_24_32);
1703 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
1704 speed_template_16_24_32);
1705 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
1706 speed_template_16_24_32);
1707 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
1708 speed_template_32_40_48);
1709 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
1710 speed_template_32_40_48);
1711 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
1712 speed_template_32_48_64);
1713 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
1714 speed_template_32_48_64);
1718 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
1719 speed_template_16_32);
1723 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1724 speed_template_16_32);
1725 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1726 speed_template_16_32);
1727 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1728 speed_template_16_32);
1729 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1730 speed_template_16_32);
1731 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1732 speed_template_16_32);
1733 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1734 speed_template_16_32);
1735 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1736 speed_template_32_48);
1737 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1738 speed_template_32_48);
1739 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1740 speed_template_32_64);
1741 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
1742 speed_template_32_64);
1746 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
1751 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
1752 speed_template_8_16);
1753 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
1754 speed_template_8_16);
1755 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
1756 speed_template_8_16);
1757 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
1758 speed_template_8_16);
1759 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
1760 speed_template_8_16);
1761 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
1762 speed_template_8_16);
1766 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
1767 speed_template_16_32);
1768 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
1769 speed_template_16_32);
1770 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
1771 speed_template_16_32);
1772 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
1773 speed_template_16_32);
1774 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
1775 speed_template_16_32);
1776 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
1777 speed_template_16_32);
1778 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
1779 speed_template_32_48);
1780 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
1781 speed_template_32_48);
1782 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
1783 speed_template_32_64);
1784 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
1785 speed_template_32_64);
1789 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
1790 NULL, 0, 16, 16, aead_speed_template_20);
1791 test_aead_speed("gcm(aes)", ENCRYPT, sec,
1792 NULL, 0, 16, 8, aead_speed_template_20);
1796 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
1797 NULL, 0, 16, 16, aead_speed_template_19);
1801 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
1802 NULL, 0, 16, 8, aead_speed_template_36);
1806 test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
1813 test_hash_speed(alg, sec, generic_hash_speed_template);
1820 test_hash_speed("md4", sec, generic_hash_speed_template);
1821 if (mode > 300 && mode < 400) break;
1824 test_hash_speed("md5", sec, generic_hash_speed_template);
1825 if (mode > 300 && mode < 400) break;
1828 test_hash_speed("sha1", sec, generic_hash_speed_template);
1829 if (mode > 300 && mode < 400) break;
1832 test_hash_speed("sha256", sec, generic_hash_speed_template);
1833 if (mode > 300 && mode < 400) break;
1836 test_hash_speed("sha384", sec, generic_hash_speed_template);
1837 if (mode > 300 && mode < 400) break;
1840 test_hash_speed("sha512", sec, generic_hash_speed_template);
1841 if (mode > 300 && mode < 400) break;
1844 test_hash_speed("wp256", sec, generic_hash_speed_template);
1845 if (mode > 300 && mode < 400) break;
1848 test_hash_speed("wp384", sec, generic_hash_speed_template);
1849 if (mode > 300 && mode < 400) break;
1852 test_hash_speed("wp512", sec, generic_hash_speed_template);
1853 if (mode > 300 && mode < 400) break;
1856 test_hash_speed("tgr128", sec, generic_hash_speed_template);
1857 if (mode > 300 && mode < 400) break;
1860 test_hash_speed("tgr160", sec, generic_hash_speed_template);
1861 if (mode > 300 && mode < 400) break;
1864 test_hash_speed("tgr192", sec, generic_hash_speed_template);
1865 if (mode > 300 && mode < 400) break;
1868 test_hash_speed("sha224", sec, generic_hash_speed_template);
1869 if (mode > 300 && mode < 400) break;
1872 test_hash_speed("rmd128", sec, generic_hash_speed_template);
1873 if (mode > 300 && mode < 400) break;
1876 test_hash_speed("rmd160", sec, generic_hash_speed_template);
1877 if (mode > 300 && mode < 400) break;
1880 test_hash_speed("rmd256", sec, generic_hash_speed_template);
1881 if (mode > 300 && mode < 400) break;
1884 test_hash_speed("rmd320", sec, generic_hash_speed_template);
1885 if (mode > 300 && mode < 400) break;
1888 test_hash_speed("ghash-generic", sec, hash_speed_template_16);
1889 if (mode > 300 && mode < 400) break;
1892 test_hash_speed("crc32c", sec, generic_hash_speed_template);
1893 if (mode > 300 && mode < 400) break;
1896 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
1897 if (mode > 300 && mode < 400) break;
1900 test_hash_speed("poly1305", sec, poly1305_speed_template);
1901 if (mode > 300 && mode < 400) break;
1908 test_ahash_speed(alg, sec, generic_hash_speed_template);
1915 test_ahash_speed("md4", sec, generic_hash_speed_template);
1916 if (mode > 400 && mode < 500) break;
1919 test_ahash_speed("md5", sec, generic_hash_speed_template);
1920 if (mode > 400 && mode < 500) break;
1923 test_ahash_speed("sha1", sec, generic_hash_speed_template);
1924 if (mode > 400 && mode < 500) break;
1927 test_ahash_speed("sha256", sec, generic_hash_speed_template);
1928 if (mode > 400 && mode < 500) break;
1931 test_ahash_speed("sha384", sec, generic_hash_speed_template);
1932 if (mode > 400 && mode < 500) break;
1935 test_ahash_speed("sha512", sec, generic_hash_speed_template);
1936 if (mode > 400 && mode < 500) break;
1939 test_ahash_speed("wp256", sec, generic_hash_speed_template);
1940 if (mode > 400 && mode < 500) break;
1943 test_ahash_speed("wp384", sec, generic_hash_speed_template);
1944 if (mode > 400 && mode < 500) break;
1947 test_ahash_speed("wp512", sec, generic_hash_speed_template);
1948 if (mode > 400 && mode < 500) break;
1951 test_ahash_speed("tgr128", sec, generic_hash_speed_template);
1952 if (mode > 400 && mode < 500) break;
1955 test_ahash_speed("tgr160", sec, generic_hash_speed_template);
1956 if (mode > 400 && mode < 500) break;
1959 test_ahash_speed("tgr192", sec, generic_hash_speed_template);
1960 if (mode > 400 && mode < 500) break;
1963 test_ahash_speed("sha224", sec, generic_hash_speed_template);
1964 if (mode > 400 && mode < 500) break;
1967 test_ahash_speed("rmd128", sec, generic_hash_speed_template);
1968 if (mode > 400 && mode < 500) break;
1971 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
1972 if (mode > 400 && mode < 500) break;
1975 test_ahash_speed("rmd256", sec, generic_hash_speed_template);
1976 if (mode > 400 && mode < 500) break;
1979 test_ahash_speed("rmd320", sec, generic_hash_speed_template);
1980 if (mode > 400 && mode < 500) break;
1986 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1987 speed_template_16_24_32);
1988 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1989 speed_template_16_24_32);
1990 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1991 speed_template_16_24_32);
1992 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1993 speed_template_16_24_32);
1994 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1995 speed_template_32_40_48);
1996 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1997 speed_template_32_40_48);
1998 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1999 speed_template_32_48_64);
2000 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2001 speed_template_32_48_64);
2002 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2003 speed_template_16_24_32);
2004 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2005 speed_template_16_24_32);
2006 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2007 speed_template_16_24_32);
2008 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2009 speed_template_16_24_32);
2010 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2011 speed_template_16_24_32);
2012 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2013 speed_template_16_24_32);
2014 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
2015 speed_template_20_28_36);
2016 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
2017 speed_template_20_28_36);
2021 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2022 des3_speed_template, DES3_SPEED_VECTORS,
2024 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
2025 des3_speed_template, DES3_SPEED_VECTORS,
2027 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2028 des3_speed_template, DES3_SPEED_VECTORS,
2030 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
2031 des3_speed_template, DES3_SPEED_VECTORS,
2033 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2034 des3_speed_template, DES3_SPEED_VECTORS,
2036 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
2037 des3_speed_template, DES3_SPEED_VECTORS,
2039 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2040 des3_speed_template, DES3_SPEED_VECTORS,
2042 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
2043 des3_speed_template, DES3_SPEED_VECTORS,
2048 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2050 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2052 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2054 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2056 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2058 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2060 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2062 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2067 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2068 speed_template_16_32);
2069 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2070 speed_template_16_32);
2071 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2072 speed_template_16_32);
2073 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2074 speed_template_16_32);
2075 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2076 speed_template_16_32);
2077 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2078 speed_template_16_32);
2079 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2080 speed_template_32_48);
2081 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2082 speed_template_32_48);
2083 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2084 speed_template_32_64);
2085 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2086 speed_template_32_64);
2090 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2091 speed_template_16_24_32);
2092 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2093 speed_template_16_24_32);
2094 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2095 speed_template_16_24_32);
2096 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2097 speed_template_16_24_32);
2098 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2099 speed_template_16_24_32);
2100 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2101 speed_template_16_24_32);
2102 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2103 speed_template_32_40_48);
2104 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2105 speed_template_32_40_48);
2106 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2107 speed_template_32_48_64);
2108 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2109 speed_template_32_48_64);
2113 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2118 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2119 speed_template_8_16);
2120 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2121 speed_template_8_16);
2122 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2123 speed_template_8_16);
2124 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2125 speed_template_8_16);
2126 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2127 speed_template_8_16);
2128 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2129 speed_template_8_16);
2133 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2134 speed_template_16_32);
2135 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2136 speed_template_16_32);
2137 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2138 speed_template_16_32);
2139 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2140 speed_template_16_32);
2141 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2142 speed_template_16_32);
2143 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2144 speed_template_16_32);
2145 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2146 speed_template_32_48);
2147 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2148 speed_template_32_48);
2149 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2150 speed_template_32_64);
2151 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2152 speed_template_32_64);
2156 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2157 speed_template_16_32);
2158 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2159 speed_template_16_32);
2160 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2161 speed_template_16_32);
2162 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2163 speed_template_16_32);
2164 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2165 speed_template_16_32);
2166 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2167 speed_template_16_32);
2168 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2169 speed_template_32_48);
2170 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2171 speed_template_32_48);
2172 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2173 speed_template_32_64);
2174 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2175 speed_template_32_64);
2179 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2180 speed_template_8_32);
2181 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2182 speed_template_8_32);
2183 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2184 speed_template_8_32);
2185 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2186 speed_template_8_32);
2187 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2188 speed_template_8_32);
2189 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2190 speed_template_8_32);
2201 static int __init tcrypt_mod_init(void)
2206 for (i = 0; i < TVMEMSIZE; i++) {
2207 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
2212 err = do_test(alg, type, mask, mode);
2215 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
2219 /* We intentionaly return -EAGAIN to prevent keeping the module,
2220 * unless we're running in fips mode. It does all its work from
2221 * init() and doesn't offer any runtime functionality, but in
2222 * the fips case, checking for a successful load is helpful.
2223 * => we don't need it in the memory, do we?
2230 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
2231 free_page((unsigned long)tvmem[i]);
2237 * If an init function is provided, an exit function must also be provided
2238 * to allow module unload.
2240 static void __exit tcrypt_mod_fini(void) { }
2242 module_init(tcrypt_mod_init);
2243 module_exit(tcrypt_mod_fini);
2245 module_param(alg, charp, 0);
2246 module_param(type, uint, 0);
2247 module_param(mask, uint, 0);
2248 module_param(mode, int, 0);
2249 module_param(sec, uint, 0);
2250 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
2251 "(defaults to zero which uses CPU cycles instead)");
2253 MODULE_LICENSE("GPL");
2254 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2255 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");