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/hash.h>
26 #include <linux/err.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>
40 * Need slab memory for testing (size in number of pages).
45 * Used by test_cipher_speed()
51 * return a string with the driver name
53 #define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm))
56 * Used by test_cipher_speed()
58 static unsigned int sec;
60 static char *alg = NULL;
64 static char *tvmem[TVMEMSIZE];
66 static char *check[] = {
67 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
68 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
69 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
70 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
71 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
72 "lzo", "cts", "zlib", NULL
75 static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc,
76 struct scatterlist *sg, int blen, int sec)
78 unsigned long start, end;
82 for (start = jiffies, end = start + sec * HZ, bcount = 0;
83 time_before(jiffies, end); bcount++) {
85 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
87 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
93 printk("%d operations in %d seconds (%ld bytes)\n",
94 bcount, sec, (long)bcount * blen);
98 static int test_cipher_cycles(struct blkcipher_desc *desc, int enc,
99 struct scatterlist *sg, int blen)
101 unsigned long cycles = 0;
108 for (i = 0; i < 4; i++) {
110 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
112 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
118 /* The real thing. */
119 for (i = 0; i < 8; i++) {
122 start = get_cycles();
124 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
126 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
132 cycles += end - start;
139 printk("1 operation in %lu cycles (%d bytes)\n",
140 (cycles + 4) / 8, blen);
145 static int test_aead_jiffies(struct aead_request *req, int enc,
148 unsigned long start, end;
152 for (start = jiffies, end = start + sec * HZ, bcount = 0;
153 time_before(jiffies, end); bcount++) {
155 ret = crypto_aead_encrypt(req);
157 ret = crypto_aead_decrypt(req);
163 printk("%d operations in %d seconds (%ld bytes)\n",
164 bcount, sec, (long)bcount * blen);
168 static int test_aead_cycles(struct aead_request *req, int enc, int blen)
170 unsigned long cycles = 0;
177 for (i = 0; i < 4; i++) {
179 ret = crypto_aead_encrypt(req);
181 ret = crypto_aead_decrypt(req);
187 /* The real thing. */
188 for (i = 0; i < 8; i++) {
191 start = get_cycles();
193 ret = crypto_aead_encrypt(req);
195 ret = crypto_aead_decrypt(req);
201 cycles += end - start;
208 printk("1 operation in %lu cycles (%d bytes)\n",
209 (cycles + 4) / 8, blen);
214 static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
215 static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
220 static int testmgr_alloc_buf(char *buf[XBUFSIZE])
224 for (i = 0; i < XBUFSIZE; i++) {
225 buf[i] = (void *)__get_free_page(GFP_KERNEL);
234 free_page((unsigned long)buf[i]);
239 static void testmgr_free_buf(char *buf[XBUFSIZE])
243 for (i = 0; i < XBUFSIZE; i++)
244 free_page((unsigned long)buf[i]);
247 static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],
250 int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
253 np = (np > XBUFSIZE) ? XBUFSIZE : np;
254 rem = buflen % PAGE_SIZE;
259 sg_init_table(sg, np);
260 for (k = 0; k < np; ++k) {
262 sg_set_buf(&sg[k], xbuf[k], rem);
264 sg_set_buf(&sg[k], xbuf[k], PAGE_SIZE);
268 static void test_aead_speed(const char *algo, int enc, unsigned int sec,
269 struct aead_speed_template *template,
270 unsigned int tcount, u8 authsize,
271 unsigned int aad_size, u8 *keysize)
274 struct crypto_aead *tfm;
277 struct aead_request *req;
278 struct scatterlist *sg;
279 struct scatterlist *asg;
280 struct scatterlist *sgout;
284 char *xbuf[XBUFSIZE];
285 char *xoutbuf[XBUFSIZE];
286 char *axbuf[XBUFSIZE];
287 unsigned int *b_size;
290 if (aad_size >= PAGE_SIZE) {
291 pr_err("associate data length (%u) too big\n", aad_size);
300 if (testmgr_alloc_buf(xbuf))
302 if (testmgr_alloc_buf(axbuf))
304 if (testmgr_alloc_buf(xoutbuf))
307 sg = kmalloc(sizeof(*sg) * 8 * 3, GFP_KERNEL);
313 tfm = crypto_alloc_aead(algo, 0, 0);
316 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
321 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
322 get_driver_name(crypto_aead, tfm), e);
324 req = aead_request_alloc(tfm, GFP_KERNEL);
326 pr_err("alg: aead: Failed to allocate request for %s\n",
336 memset(assoc, 0xff, aad_size);
337 sg_init_one(&asg[0], assoc, aad_size);
339 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
340 pr_err("template (%u) too big for tvmem (%lu)\n",
342 TVMEMSIZE * PAGE_SIZE);
347 for (j = 0; j < tcount; j++) {
348 if (template[j].klen == *keysize) {
349 key = template[j].key;
353 ret = crypto_aead_setkey(tfm, key, *keysize);
354 ret = crypto_aead_setauthsize(tfm, authsize);
356 iv_len = crypto_aead_ivsize(tfm);
358 memset(&iv, 0xff, iv_len);
360 crypto_aead_clear_flags(tfm, ~0);
361 printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
362 i, *keysize * 8, *b_size);
365 memset(tvmem[0], 0xff, PAGE_SIZE);
368 pr_err("setkey() failed flags=%x\n",
369 crypto_aead_get_flags(tfm));
373 sg_init_aead(&sg[0], xbuf,
374 *b_size + (enc ? authsize : 0));
376 sg_init_aead(&sgout[0], xoutbuf,
377 *b_size + (enc ? authsize : 0));
379 aead_request_set_crypt(req, sg, sgout, *b_size, iv);
380 aead_request_set_assoc(req, asg, aad_size);
383 ret = test_aead_jiffies(req, enc, *b_size, sec);
385 ret = test_aead_cycles(req, enc, *b_size);
388 pr_err("%s() failed return code=%d\n", e, ret);
398 aead_request_free(req);
400 crypto_free_aead(tfm);
404 testmgr_free_buf(xoutbuf);
406 testmgr_free_buf(axbuf);
408 testmgr_free_buf(xbuf);
413 static void test_cipher_speed(const char *algo, int enc, unsigned int sec,
414 struct cipher_speed_template *template,
415 unsigned int tcount, u8 *keysize)
417 unsigned int ret, i, j, iv_len;
420 struct crypto_blkcipher *tfm;
421 struct blkcipher_desc desc;
430 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
433 printk("failed to load transform for %s: %ld\n", algo,
440 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
441 get_driver_name(crypto_blkcipher, tfm), e);
446 b_size = block_sizes;
448 struct scatterlist sg[TVMEMSIZE];
450 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
451 printk("template (%u) too big for "
452 "tvmem (%lu)\n", *keysize + *b_size,
453 TVMEMSIZE * PAGE_SIZE);
457 printk("test %u (%d bit key, %d byte blocks): ", i,
458 *keysize * 8, *b_size);
460 memset(tvmem[0], 0xff, PAGE_SIZE);
462 /* set key, plain text and IV */
464 for (j = 0; j < tcount; j++) {
465 if (template[j].klen == *keysize) {
466 key = template[j].key;
471 ret = crypto_blkcipher_setkey(tfm, key, *keysize);
473 printk("setkey() failed flags=%x\n",
474 crypto_blkcipher_get_flags(tfm));
478 sg_init_table(sg, TVMEMSIZE);
479 sg_set_buf(sg, tvmem[0] + *keysize,
480 PAGE_SIZE - *keysize);
481 for (j = 1; j < TVMEMSIZE; j++) {
482 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
483 memset (tvmem[j], 0xff, PAGE_SIZE);
486 iv_len = crypto_blkcipher_ivsize(tfm);
488 memset(&iv, 0xff, iv_len);
489 crypto_blkcipher_set_iv(tfm, iv, iv_len);
493 ret = test_cipher_jiffies(&desc, enc, sg,
496 ret = test_cipher_cycles(&desc, enc, sg,
500 printk("%s() failed flags=%x\n", e, desc.flags);
510 crypto_free_blkcipher(tfm);
513 static int test_hash_jiffies_digest(struct hash_desc *desc,
514 struct scatterlist *sg, int blen,
517 unsigned long start, end;
521 for (start = jiffies, end = start + sec * HZ, bcount = 0;
522 time_before(jiffies, end); bcount++) {
523 ret = crypto_hash_digest(desc, sg, blen, out);
528 printk("%6u opers/sec, %9lu bytes/sec\n",
529 bcount / sec, ((long)bcount * blen) / sec);
534 static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg,
535 int blen, int plen, char *out, int sec)
537 unsigned long start, end;
542 return test_hash_jiffies_digest(desc, sg, blen, out, sec);
544 for (start = jiffies, end = start + sec * HZ, bcount = 0;
545 time_before(jiffies, end); bcount++) {
546 ret = crypto_hash_init(desc);
549 for (pcount = 0; pcount < blen; pcount += plen) {
550 ret = crypto_hash_update(desc, sg, plen);
554 /* we assume there is enough space in 'out' for the result */
555 ret = crypto_hash_final(desc, out);
560 printk("%6u opers/sec, %9lu bytes/sec\n",
561 bcount / sec, ((long)bcount * blen) / sec);
566 static int test_hash_cycles_digest(struct hash_desc *desc,
567 struct scatterlist *sg, int blen, char *out)
569 unsigned long cycles = 0;
576 for (i = 0; i < 4; i++) {
577 ret = crypto_hash_digest(desc, sg, blen, out);
582 /* The real thing. */
583 for (i = 0; i < 8; i++) {
586 start = get_cycles();
588 ret = crypto_hash_digest(desc, sg, blen, out);
594 cycles += end - start;
603 printk("%6lu cycles/operation, %4lu cycles/byte\n",
604 cycles / 8, cycles / (8 * blen));
609 static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg,
610 int blen, int plen, char *out)
612 unsigned long cycles = 0;
617 return test_hash_cycles_digest(desc, sg, blen, out);
622 for (i = 0; i < 4; i++) {
623 ret = crypto_hash_init(desc);
626 for (pcount = 0; pcount < blen; pcount += plen) {
627 ret = crypto_hash_update(desc, sg, plen);
631 ret = crypto_hash_final(desc, out);
636 /* The real thing. */
637 for (i = 0; i < 8; i++) {
640 start = get_cycles();
642 ret = crypto_hash_init(desc);
645 for (pcount = 0; pcount < blen; pcount += plen) {
646 ret = crypto_hash_update(desc, sg, plen);
650 ret = crypto_hash_final(desc, out);
656 cycles += end - start;
665 printk("%6lu cycles/operation, %4lu cycles/byte\n",
666 cycles / 8, cycles / (8 * blen));
671 static void test_hash_sg_init(struct scatterlist *sg)
675 sg_init_table(sg, TVMEMSIZE);
676 for (i = 0; i < TVMEMSIZE; i++) {
677 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
678 memset(tvmem[i], 0xff, PAGE_SIZE);
682 static void test_hash_speed(const char *algo, unsigned int sec,
683 struct hash_speed *speed)
685 struct scatterlist sg[TVMEMSIZE];
686 struct crypto_hash *tfm;
687 struct hash_desc desc;
688 static char output[1024];
692 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
695 printk(KERN_ERR "failed to load transform for %s: %ld\n", algo,
700 printk(KERN_INFO "\ntesting speed of %s (%s)\n", algo,
701 get_driver_name(crypto_hash, tfm));
706 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
707 printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n",
708 crypto_hash_digestsize(tfm), sizeof(output));
712 test_hash_sg_init(sg);
713 for (i = 0; speed[i].blen != 0; i++) {
714 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
716 "template (%u) too big for tvmem (%lu)\n",
717 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
722 crypto_hash_setkey(tfm, tvmem[0], speed[i].klen);
724 printk(KERN_INFO "test%3u "
725 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
726 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
729 ret = test_hash_jiffies(&desc, sg, speed[i].blen,
730 speed[i].plen, output, sec);
732 ret = test_hash_cycles(&desc, sg, speed[i].blen,
733 speed[i].plen, output);
736 printk(KERN_ERR "hashing failed ret=%d\n", ret);
742 crypto_free_hash(tfm);
745 struct tcrypt_result {
746 struct completion completion;
750 static void tcrypt_complete(struct crypto_async_request *req, int err)
752 struct tcrypt_result *res = req->data;
754 if (err == -EINPROGRESS)
758 complete(&res->completion);
761 static inline int do_one_ahash_op(struct ahash_request *req, int ret)
763 if (ret == -EINPROGRESS || ret == -EBUSY) {
764 struct tcrypt_result *tr = req->base.data;
766 ret = wait_for_completion_interruptible(&tr->completion);
769 reinit_completion(&tr->completion);
774 static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
777 unsigned long start, end;
781 for (start = jiffies, end = start + sec * HZ, bcount = 0;
782 time_before(jiffies, end); bcount++) {
783 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
788 printk("%6u opers/sec, %9lu bytes/sec\n",
789 bcount / sec, ((long)bcount * blen) / sec);
794 static int test_ahash_jiffies(struct ahash_request *req, int blen,
795 int plen, char *out, int sec)
797 unsigned long start, end;
802 return test_ahash_jiffies_digest(req, blen, out, sec);
804 for (start = jiffies, end = start + sec * HZ, bcount = 0;
805 time_before(jiffies, end); bcount++) {
806 ret = crypto_ahash_init(req);
809 for (pcount = 0; pcount < blen; pcount += plen) {
810 ret = do_one_ahash_op(req, crypto_ahash_update(req));
814 /* we assume there is enough space in 'out' for the result */
815 ret = do_one_ahash_op(req, crypto_ahash_final(req));
820 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
821 bcount / sec, ((long)bcount * blen) / sec);
826 static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
829 unsigned long cycles = 0;
833 for (i = 0; i < 4; i++) {
834 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
839 /* The real thing. */
840 for (i = 0; i < 8; i++) {
843 start = get_cycles();
845 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
851 cycles += end - start;
858 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
859 cycles / 8, cycles / (8 * blen));
864 static int test_ahash_cycles(struct ahash_request *req, int blen,
867 unsigned long cycles = 0;
871 return test_ahash_cycles_digest(req, blen, out);
874 for (i = 0; i < 4; i++) {
875 ret = crypto_ahash_init(req);
878 for (pcount = 0; pcount < blen; pcount += plen) {
879 ret = do_one_ahash_op(req, crypto_ahash_update(req));
883 ret = do_one_ahash_op(req, crypto_ahash_final(req));
888 /* The real thing. */
889 for (i = 0; i < 8; i++) {
892 start = get_cycles();
894 ret = crypto_ahash_init(req);
897 for (pcount = 0; pcount < blen; pcount += plen) {
898 ret = do_one_ahash_op(req, crypto_ahash_update(req));
902 ret = do_one_ahash_op(req, crypto_ahash_final(req));
908 cycles += end - start;
915 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
916 cycles / 8, cycles / (8 * blen));
921 static void test_ahash_speed(const char *algo, unsigned int sec,
922 struct hash_speed *speed)
924 struct scatterlist sg[TVMEMSIZE];
925 struct tcrypt_result tresult;
926 struct ahash_request *req;
927 struct crypto_ahash *tfm;
928 static char output[1024];
931 tfm = crypto_alloc_ahash(algo, 0, 0);
933 pr_err("failed to load transform for %s: %ld\n",
938 printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
939 get_driver_name(crypto_ahash, tfm));
941 if (crypto_ahash_digestsize(tfm) > sizeof(output)) {
942 pr_err("digestsize(%u) > outputbuffer(%zu)\n",
943 crypto_ahash_digestsize(tfm), sizeof(output));
947 test_hash_sg_init(sg);
948 req = ahash_request_alloc(tfm, GFP_KERNEL);
950 pr_err("ahash request allocation failure\n");
954 init_completion(&tresult.completion);
955 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
956 tcrypt_complete, &tresult);
958 for (i = 0; speed[i].blen != 0; i++) {
959 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
960 pr_err("template (%u) too big for tvmem (%lu)\n",
961 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
966 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
967 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
969 ahash_request_set_crypt(req, sg, output, speed[i].plen);
972 ret = test_ahash_jiffies(req, speed[i].blen,
973 speed[i].plen, output, sec);
975 ret = test_ahash_cycles(req, speed[i].blen,
976 speed[i].plen, output);
979 pr_err("hashing failed ret=%d\n", ret);
984 ahash_request_free(req);
987 crypto_free_ahash(tfm);
990 static inline int do_one_acipher_op(struct ablkcipher_request *req, int ret)
992 if (ret == -EINPROGRESS || ret == -EBUSY) {
993 struct tcrypt_result *tr = req->base.data;
995 ret = wait_for_completion_interruptible(&tr->completion);
998 reinit_completion(&tr->completion);
1004 static int test_acipher_jiffies(struct ablkcipher_request *req, int enc,
1007 unsigned long start, end;
1011 for (start = jiffies, end = start + sec * HZ, bcount = 0;
1012 time_before(jiffies, end); bcount++) {
1014 ret = do_one_acipher_op(req,
1015 crypto_ablkcipher_encrypt(req));
1017 ret = do_one_acipher_op(req,
1018 crypto_ablkcipher_decrypt(req));
1024 pr_cont("%d operations in %d seconds (%ld bytes)\n",
1025 bcount, sec, (long)bcount * blen);
1029 static int test_acipher_cycles(struct ablkcipher_request *req, int enc,
1032 unsigned long cycles = 0;
1037 for (i = 0; i < 4; i++) {
1039 ret = do_one_acipher_op(req,
1040 crypto_ablkcipher_encrypt(req));
1042 ret = do_one_acipher_op(req,
1043 crypto_ablkcipher_decrypt(req));
1049 /* The real thing. */
1050 for (i = 0; i < 8; i++) {
1051 cycles_t start, end;
1053 start = get_cycles();
1055 ret = do_one_acipher_op(req,
1056 crypto_ablkcipher_encrypt(req));
1058 ret = do_one_acipher_op(req,
1059 crypto_ablkcipher_decrypt(req));
1065 cycles += end - start;
1070 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1071 (cycles + 4) / 8, blen);
1076 static void test_acipher_speed(const char *algo, int enc, unsigned int sec,
1077 struct cipher_speed_template *template,
1078 unsigned int tcount, u8 *keysize)
1080 unsigned int ret, i, j, k, iv_len;
1081 struct tcrypt_result tresult;
1084 struct ablkcipher_request *req;
1085 struct crypto_ablkcipher *tfm;
1094 init_completion(&tresult.completion);
1096 tfm = crypto_alloc_ablkcipher(algo, 0, 0);
1099 pr_err("failed to load transform for %s: %ld\n", algo,
1104 pr_info("\ntesting speed of async %s (%s) %s\n", algo,
1105 get_driver_name(crypto_ablkcipher, tfm), e);
1107 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
1109 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1114 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1115 tcrypt_complete, &tresult);
1119 b_size = block_sizes;
1122 struct scatterlist sg[TVMEMSIZE];
1124 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
1125 pr_err("template (%u) too big for "
1126 "tvmem (%lu)\n", *keysize + *b_size,
1127 TVMEMSIZE * PAGE_SIZE);
1131 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1132 *keysize * 8, *b_size);
1134 memset(tvmem[0], 0xff, PAGE_SIZE);
1136 /* set key, plain text and IV */
1138 for (j = 0; j < tcount; j++) {
1139 if (template[j].klen == *keysize) {
1140 key = template[j].key;
1145 crypto_ablkcipher_clear_flags(tfm, ~0);
1147 ret = crypto_ablkcipher_setkey(tfm, key, *keysize);
1149 pr_err("setkey() failed flags=%x\n",
1150 crypto_ablkcipher_get_flags(tfm));
1154 sg_init_table(sg, TVMEMSIZE);
1156 k = *keysize + *b_size;
1157 if (k > PAGE_SIZE) {
1158 sg_set_buf(sg, tvmem[0] + *keysize,
1159 PAGE_SIZE - *keysize);
1162 while (k > PAGE_SIZE) {
1163 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
1164 memset(tvmem[j], 0xff, PAGE_SIZE);
1168 sg_set_buf(sg + j, tvmem[j], k);
1169 memset(tvmem[j], 0xff, k);
1171 sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
1174 iv_len = crypto_ablkcipher_ivsize(tfm);
1176 memset(&iv, 0xff, iv_len);
1178 ablkcipher_request_set_crypt(req, sg, sg, *b_size, iv);
1181 ret = test_acipher_jiffies(req, enc,
1184 ret = test_acipher_cycles(req, enc,
1188 pr_err("%s() failed flags=%x\n", e,
1189 crypto_ablkcipher_get_flags(tfm));
1199 ablkcipher_request_free(req);
1201 crypto_free_ablkcipher(tfm);
1204 static void test_available(void)
1206 char **name = check;
1209 printk("alg %s ", *name);
1210 printk(crypto_has_alg(*name, 0, 0) ?
1211 "found\n" : "not found\n");
1216 static inline int tcrypt_test(const char *alg)
1220 ret = alg_test(alg, alg, 0, 0);
1221 /* non-fips algs return -EINVAL in fips mode */
1222 if (fips_enabled && ret == -EINVAL)
1227 static int do_test(int m)
1234 for (i = 1; i < 200; i++)
1239 ret += tcrypt_test("md5");
1243 ret += tcrypt_test("sha1");
1247 ret += tcrypt_test("ecb(des)");
1248 ret += tcrypt_test("cbc(des)");
1249 ret += tcrypt_test("ctr(des)");
1253 ret += tcrypt_test("ecb(des3_ede)");
1254 ret += tcrypt_test("cbc(des3_ede)");
1255 ret += tcrypt_test("ctr(des3_ede)");
1259 ret += tcrypt_test("md4");
1263 ret += tcrypt_test("sha256");
1267 ret += tcrypt_test("ecb(blowfish)");
1268 ret += tcrypt_test("cbc(blowfish)");
1269 ret += tcrypt_test("ctr(blowfish)");
1273 ret += tcrypt_test("ecb(twofish)");
1274 ret += tcrypt_test("cbc(twofish)");
1275 ret += tcrypt_test("ctr(twofish)");
1276 ret += tcrypt_test("lrw(twofish)");
1277 ret += tcrypt_test("xts(twofish)");
1281 ret += tcrypt_test("ecb(serpent)");
1282 ret += tcrypt_test("cbc(serpent)");
1283 ret += tcrypt_test("ctr(serpent)");
1284 ret += tcrypt_test("lrw(serpent)");
1285 ret += tcrypt_test("xts(serpent)");
1289 ret += tcrypt_test("ecb(aes)");
1290 ret += tcrypt_test("cbc(aes)");
1291 ret += tcrypt_test("lrw(aes)");
1292 ret += tcrypt_test("xts(aes)");
1293 ret += tcrypt_test("ctr(aes)");
1294 ret += tcrypt_test("rfc3686(ctr(aes))");
1298 ret += tcrypt_test("sha384");
1302 ret += tcrypt_test("sha512");
1306 ret += tcrypt_test("deflate");
1310 ret += tcrypt_test("ecb(cast5)");
1311 ret += tcrypt_test("cbc(cast5)");
1312 ret += tcrypt_test("ctr(cast5)");
1316 ret += tcrypt_test("ecb(cast6)");
1317 ret += tcrypt_test("cbc(cast6)");
1318 ret += tcrypt_test("ctr(cast6)");
1319 ret += tcrypt_test("lrw(cast6)");
1320 ret += tcrypt_test("xts(cast6)");
1324 ret += tcrypt_test("ecb(arc4)");
1328 ret += tcrypt_test("michael_mic");
1332 ret += tcrypt_test("crc32c");
1336 ret += tcrypt_test("ecb(tea)");
1340 ret += tcrypt_test("ecb(xtea)");
1344 ret += tcrypt_test("ecb(khazad)");
1348 ret += tcrypt_test("wp512");
1352 ret += tcrypt_test("wp384");
1356 ret += tcrypt_test("wp256");
1360 ret += tcrypt_test("ecb(tnepres)");
1364 ret += tcrypt_test("ecb(anubis)");
1365 ret += tcrypt_test("cbc(anubis)");
1369 ret += tcrypt_test("tgr192");
1373 ret += tcrypt_test("tgr160");
1377 ret += tcrypt_test("tgr128");
1381 ret += tcrypt_test("ecb(xeta)");
1385 ret += tcrypt_test("pcbc(fcrypt)");
1389 ret += tcrypt_test("ecb(camellia)");
1390 ret += tcrypt_test("cbc(camellia)");
1391 ret += tcrypt_test("ctr(camellia)");
1392 ret += tcrypt_test("lrw(camellia)");
1393 ret += tcrypt_test("xts(camellia)");
1397 ret += tcrypt_test("sha224");
1401 ret += tcrypt_test("salsa20");
1405 ret += tcrypt_test("gcm(aes)");
1409 ret += tcrypt_test("lzo");
1413 ret += tcrypt_test("ccm(aes)");
1417 ret += tcrypt_test("cts(cbc(aes))");
1421 ret += tcrypt_test("rmd128");
1425 ret += tcrypt_test("rmd160");
1429 ret += tcrypt_test("rmd256");
1433 ret += tcrypt_test("rmd320");
1437 ret += tcrypt_test("ecb(seed)");
1441 ret += tcrypt_test("zlib");
1445 ret += tcrypt_test("rfc4309(ccm(aes))");
1449 ret += tcrypt_test("ghash");
1453 ret += tcrypt_test("crct10dif");
1457 ret += tcrypt_test("hmac(md5)");
1461 ret += tcrypt_test("hmac(sha1)");
1465 ret += tcrypt_test("hmac(sha256)");
1469 ret += tcrypt_test("hmac(sha384)");
1473 ret += tcrypt_test("hmac(sha512)");
1477 ret += tcrypt_test("hmac(sha224)");
1481 ret += tcrypt_test("xcbc(aes)");
1485 ret += tcrypt_test("hmac(rmd128)");
1489 ret += tcrypt_test("hmac(rmd160)");
1493 ret += tcrypt_test("vmac(aes)");
1497 ret += tcrypt_test("hmac(crc32)");
1501 ret += tcrypt_test("ansi_cprng");
1505 ret += tcrypt_test("rfc4106(gcm(aes))");
1509 ret += tcrypt_test("rfc4543(gcm(aes))");
1513 ret += tcrypt_test("cmac(aes)");
1517 ret += tcrypt_test("cmac(des3_ede)");
1521 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1525 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1529 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1532 ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
1535 ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
1538 ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
1541 ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
1544 ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
1547 ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
1550 ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
1553 ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
1556 ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
1559 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
1562 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1563 speed_template_16_24_32);
1564 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1565 speed_template_16_24_32);
1566 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1567 speed_template_16_24_32);
1568 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1569 speed_template_16_24_32);
1570 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1571 speed_template_32_40_48);
1572 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1573 speed_template_32_40_48);
1574 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1575 speed_template_32_48_64);
1576 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1577 speed_template_32_48_64);
1578 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1579 speed_template_16_24_32);
1580 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1581 speed_template_16_24_32);
1585 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1586 des3_speed_template, DES3_SPEED_VECTORS,
1588 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1589 des3_speed_template, DES3_SPEED_VECTORS,
1591 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1592 des3_speed_template, DES3_SPEED_VECTORS,
1594 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1595 des3_speed_template, DES3_SPEED_VECTORS,
1597 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
1598 des3_speed_template, DES3_SPEED_VECTORS,
1600 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
1601 des3_speed_template, DES3_SPEED_VECTORS,
1606 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1607 speed_template_16_24_32);
1608 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1609 speed_template_16_24_32);
1610 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1611 speed_template_16_24_32);
1612 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1613 speed_template_16_24_32);
1614 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1615 speed_template_16_24_32);
1616 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1617 speed_template_16_24_32);
1618 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1619 speed_template_32_40_48);
1620 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1621 speed_template_32_40_48);
1622 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1623 speed_template_32_48_64);
1624 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1625 speed_template_32_48_64);
1629 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1630 speed_template_8_32);
1631 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1632 speed_template_8_32);
1633 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1634 speed_template_8_32);
1635 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1636 speed_template_8_32);
1637 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
1638 speed_template_8_32);
1639 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
1640 speed_template_8_32);
1644 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1646 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1648 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1650 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1655 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1656 speed_template_16_24_32);
1657 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1658 speed_template_16_24_32);
1659 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1660 speed_template_16_24_32);
1661 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1662 speed_template_16_24_32);
1663 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
1664 speed_template_16_24_32);
1665 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
1666 speed_template_16_24_32);
1667 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
1668 speed_template_32_40_48);
1669 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
1670 speed_template_32_40_48);
1671 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
1672 speed_template_32_48_64);
1673 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
1674 speed_template_32_48_64);
1678 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
1679 speed_template_16_32);
1683 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1684 speed_template_16_32);
1685 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1686 speed_template_16_32);
1687 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1688 speed_template_16_32);
1689 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1690 speed_template_16_32);
1691 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1692 speed_template_16_32);
1693 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1694 speed_template_16_32);
1695 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1696 speed_template_32_48);
1697 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1698 speed_template_32_48);
1699 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1700 speed_template_32_64);
1701 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
1702 speed_template_32_64);
1706 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
1711 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
1712 speed_template_8_16);
1713 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
1714 speed_template_8_16);
1715 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
1716 speed_template_8_16);
1717 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
1718 speed_template_8_16);
1719 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
1720 speed_template_8_16);
1721 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
1722 speed_template_8_16);
1726 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
1727 speed_template_16_32);
1728 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
1729 speed_template_16_32);
1730 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
1731 speed_template_16_32);
1732 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
1733 speed_template_16_32);
1734 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
1735 speed_template_16_32);
1736 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
1737 speed_template_16_32);
1738 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
1739 speed_template_32_48);
1740 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
1741 speed_template_32_48);
1742 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
1743 speed_template_32_64);
1744 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
1745 speed_template_32_64);
1749 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
1750 NULL, 0, 16, 8, aead_speed_template_20);
1757 test_hash_speed("md4", sec, generic_hash_speed_template);
1758 if (mode > 300 && mode < 400) break;
1761 test_hash_speed("md5", sec, generic_hash_speed_template);
1762 if (mode > 300 && mode < 400) break;
1765 test_hash_speed("sha1", sec, generic_hash_speed_template);
1766 if (mode > 300 && mode < 400) break;
1769 test_hash_speed("sha256", sec, generic_hash_speed_template);
1770 if (mode > 300 && mode < 400) break;
1773 test_hash_speed("sha384", sec, generic_hash_speed_template);
1774 if (mode > 300 && mode < 400) break;
1777 test_hash_speed("sha512", sec, generic_hash_speed_template);
1778 if (mode > 300 && mode < 400) break;
1781 test_hash_speed("wp256", sec, generic_hash_speed_template);
1782 if (mode > 300 && mode < 400) break;
1785 test_hash_speed("wp384", sec, generic_hash_speed_template);
1786 if (mode > 300 && mode < 400) break;
1789 test_hash_speed("wp512", sec, generic_hash_speed_template);
1790 if (mode > 300 && mode < 400) break;
1793 test_hash_speed("tgr128", sec, generic_hash_speed_template);
1794 if (mode > 300 && mode < 400) break;
1797 test_hash_speed("tgr160", sec, generic_hash_speed_template);
1798 if (mode > 300 && mode < 400) break;
1801 test_hash_speed("tgr192", sec, generic_hash_speed_template);
1802 if (mode > 300 && mode < 400) break;
1805 test_hash_speed("sha224", sec, generic_hash_speed_template);
1806 if (mode > 300 && mode < 400) break;
1809 test_hash_speed("rmd128", sec, generic_hash_speed_template);
1810 if (mode > 300 && mode < 400) break;
1813 test_hash_speed("rmd160", sec, generic_hash_speed_template);
1814 if (mode > 300 && mode < 400) break;
1817 test_hash_speed("rmd256", sec, generic_hash_speed_template);
1818 if (mode > 300 && mode < 400) break;
1821 test_hash_speed("rmd320", sec, generic_hash_speed_template);
1822 if (mode > 300 && mode < 400) break;
1825 test_hash_speed("ghash-generic", sec, hash_speed_template_16);
1826 if (mode > 300 && mode < 400) break;
1829 test_hash_speed("crc32c", sec, generic_hash_speed_template);
1830 if (mode > 300 && mode < 400) break;
1833 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
1834 if (mode > 300 && mode < 400) break;
1843 test_ahash_speed("md4", sec, generic_hash_speed_template);
1844 if (mode > 400 && mode < 500) break;
1847 test_ahash_speed("md5", sec, generic_hash_speed_template);
1848 if (mode > 400 && mode < 500) break;
1851 test_ahash_speed("sha1", sec, generic_hash_speed_template);
1852 if (mode > 400 && mode < 500) break;
1855 test_ahash_speed("sha256", sec, generic_hash_speed_template);
1856 if (mode > 400 && mode < 500) break;
1859 test_ahash_speed("sha384", sec, generic_hash_speed_template);
1860 if (mode > 400 && mode < 500) break;
1863 test_ahash_speed("sha512", sec, generic_hash_speed_template);
1864 if (mode > 400 && mode < 500) break;
1867 test_ahash_speed("wp256", sec, generic_hash_speed_template);
1868 if (mode > 400 && mode < 500) break;
1871 test_ahash_speed("wp384", sec, generic_hash_speed_template);
1872 if (mode > 400 && mode < 500) break;
1875 test_ahash_speed("wp512", sec, generic_hash_speed_template);
1876 if (mode > 400 && mode < 500) break;
1879 test_ahash_speed("tgr128", sec, generic_hash_speed_template);
1880 if (mode > 400 && mode < 500) break;
1883 test_ahash_speed("tgr160", sec, generic_hash_speed_template);
1884 if (mode > 400 && mode < 500) break;
1887 test_ahash_speed("tgr192", sec, generic_hash_speed_template);
1888 if (mode > 400 && mode < 500) break;
1891 test_ahash_speed("sha224", sec, generic_hash_speed_template);
1892 if (mode > 400 && mode < 500) break;
1895 test_ahash_speed("rmd128", sec, generic_hash_speed_template);
1896 if (mode > 400 && mode < 500) break;
1899 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
1900 if (mode > 400 && mode < 500) break;
1903 test_ahash_speed("rmd256", sec, generic_hash_speed_template);
1904 if (mode > 400 && mode < 500) break;
1907 test_ahash_speed("rmd320", sec, generic_hash_speed_template);
1908 if (mode > 400 && mode < 500) break;
1914 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1915 speed_template_16_24_32);
1916 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1917 speed_template_16_24_32);
1918 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1919 speed_template_16_24_32);
1920 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1921 speed_template_16_24_32);
1922 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1923 speed_template_32_40_48);
1924 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1925 speed_template_32_40_48);
1926 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1927 speed_template_32_48_64);
1928 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1929 speed_template_32_48_64);
1930 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1931 speed_template_16_24_32);
1932 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1933 speed_template_16_24_32);
1934 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
1935 speed_template_16_24_32);
1936 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
1937 speed_template_16_24_32);
1938 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
1939 speed_template_16_24_32);
1940 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
1941 speed_template_16_24_32);
1942 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
1943 speed_template_20_28_36);
1944 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
1945 speed_template_20_28_36);
1949 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1950 des3_speed_template, DES3_SPEED_VECTORS,
1952 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
1953 des3_speed_template, DES3_SPEED_VECTORS,
1955 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1956 des3_speed_template, DES3_SPEED_VECTORS,
1958 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
1959 des3_speed_template, DES3_SPEED_VECTORS,
1961 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
1962 des3_speed_template, DES3_SPEED_VECTORS,
1964 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
1965 des3_speed_template, DES3_SPEED_VECTORS,
1967 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
1968 des3_speed_template, DES3_SPEED_VECTORS,
1970 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
1971 des3_speed_template, DES3_SPEED_VECTORS,
1976 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1978 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1980 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1982 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1984 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
1986 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
1988 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
1990 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
1995 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1996 speed_template_16_32);
1997 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1998 speed_template_16_32);
1999 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2000 speed_template_16_32);
2001 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2002 speed_template_16_32);
2003 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2004 speed_template_16_32);
2005 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2006 speed_template_16_32);
2007 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2008 speed_template_32_48);
2009 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2010 speed_template_32_48);
2011 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2012 speed_template_32_64);
2013 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2014 speed_template_32_64);
2018 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2019 speed_template_16_24_32);
2020 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2021 speed_template_16_24_32);
2022 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2023 speed_template_16_24_32);
2024 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2025 speed_template_16_24_32);
2026 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2027 speed_template_16_24_32);
2028 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2029 speed_template_16_24_32);
2030 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2031 speed_template_32_40_48);
2032 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2033 speed_template_32_40_48);
2034 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2035 speed_template_32_48_64);
2036 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2037 speed_template_32_48_64);
2041 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2046 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2047 speed_template_8_16);
2048 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2049 speed_template_8_16);
2050 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2051 speed_template_8_16);
2052 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2053 speed_template_8_16);
2054 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2055 speed_template_8_16);
2056 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2057 speed_template_8_16);
2061 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2062 speed_template_16_32);
2063 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2064 speed_template_16_32);
2065 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2066 speed_template_16_32);
2067 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2068 speed_template_16_32);
2069 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2070 speed_template_16_32);
2071 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2072 speed_template_16_32);
2073 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2074 speed_template_32_48);
2075 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2076 speed_template_32_48);
2077 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2078 speed_template_32_64);
2079 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2080 speed_template_32_64);
2084 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2085 speed_template_16_32);
2086 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2087 speed_template_16_32);
2088 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2089 speed_template_16_32);
2090 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2091 speed_template_16_32);
2092 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2093 speed_template_16_32);
2094 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2095 speed_template_16_32);
2096 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2097 speed_template_32_48);
2098 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2099 speed_template_32_48);
2100 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2101 speed_template_32_64);
2102 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2103 speed_template_32_64);
2107 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2108 speed_template_8_32);
2109 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2110 speed_template_8_32);
2111 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2112 speed_template_8_32);
2113 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2114 speed_template_8_32);
2115 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2116 speed_template_8_32);
2117 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2118 speed_template_8_32);
2129 static int do_alg_test(const char *alg, u32 type, u32 mask)
2131 return crypto_has_alg(alg, type, mask ?: CRYPTO_ALG_TYPE_MASK) ?
2135 static int __init tcrypt_mod_init(void)
2140 for (i = 0; i < TVMEMSIZE; i++) {
2141 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
2147 err = do_alg_test(alg, type, mask);
2149 err = do_test(mode);
2152 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
2156 /* We intentionaly return -EAGAIN to prevent keeping the module,
2157 * unless we're running in fips mode. It does all its work from
2158 * init() and doesn't offer any runtime functionality, but in
2159 * the fips case, checking for a successful load is helpful.
2160 * => we don't need it in the memory, do we?
2167 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
2168 free_page((unsigned long)tvmem[i]);
2174 * If an init function is provided, an exit function must also be provided
2175 * to allow module unload.
2177 static void __exit tcrypt_mod_fini(void) { }
2179 module_init(tcrypt_mod_init);
2180 module_exit(tcrypt_mod_fini);
2182 module_param(alg, charp, 0);
2183 module_param(type, uint, 0);
2184 module_param(mask, uint, 0);
2185 module_param(mode, int, 0);
2186 module_param(sec, uint, 0);
2187 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
2188 "(defaults to zero which uses CPU cycles instead)");
2190 MODULE_LICENSE("GPL");
2191 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2192 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");