btrfs: tree-checker: Fix misleading group system information
[linux/fpc-iii.git] / crypto / tcrypt.c
blob1d92b5d2d6bd491c71b94a68985fb97de5cc1dbe
1 /*
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)
21 * any later version.
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>
38 #include "tcrypt.h"
41 * Need slab memory for testing (size in number of pages).
43 #define TVMEMSIZE 4
46 * Used by test_cipher_speed()
48 #define ENCRYPT 1
49 #define DECRYPT 0
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;
64 static u32 type;
65 static u32 mask;
66 static int mode;
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;
80 int err;
83 static void tcrypt_complete(struct crypto_async_request *req, int err)
85 struct tcrypt_result *res = req->data;
87 if (err == -EINPROGRESS)
88 return;
90 res->err = err;
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;
98 int bcount;
99 int ret;
101 for (start = jiffies, end = start + secs * HZ, bcount = 0;
102 time_before(jiffies, end); bcount++) {
103 if (enc)
104 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
105 else
106 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
108 if (ret)
109 return ret;
112 printk("%d operations in %d seconds (%ld bytes)\n",
113 bcount, secs, (long)bcount * blen);
114 return 0;
117 static int test_cipher_cycles(struct blkcipher_desc *desc, int enc,
118 struct scatterlist *sg, int blen)
120 unsigned long cycles = 0;
121 int ret = 0;
122 int i;
124 local_irq_disable();
126 /* Warm-up run. */
127 for (i = 0; i < 4; i++) {
128 if (enc)
129 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
130 else
131 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
133 if (ret)
134 goto out;
137 /* The real thing. */
138 for (i = 0; i < 8; i++) {
139 cycles_t start, end;
141 start = get_cycles();
142 if (enc)
143 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
144 else
145 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
146 end = get_cycles();
148 if (ret)
149 goto out;
151 cycles += end - start;
154 out:
155 local_irq_enable();
157 if (ret == 0)
158 printk("1 operation in %lu cycles (%d bytes)\n",
159 (cycles + 4) / 8, blen);
161 return ret;
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);
170 if (!ret)
171 ret = tr->err;
172 reinit_completion(&tr->completion);
175 return ret;
178 static int test_aead_jiffies(struct aead_request *req, int enc,
179 int blen, int secs)
181 unsigned long start, end;
182 int bcount;
183 int ret;
185 for (start = jiffies, end = start + secs * HZ, bcount = 0;
186 time_before(jiffies, end); bcount++) {
187 if (enc)
188 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
189 else
190 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
192 if (ret)
193 return ret;
196 printk("%d operations in %d seconds (%ld bytes)\n",
197 bcount, secs, (long)bcount * blen);
198 return 0;
201 static int test_aead_cycles(struct aead_request *req, int enc, int blen)
203 unsigned long cycles = 0;
204 int ret = 0;
205 int i;
207 local_irq_disable();
209 /* Warm-up run. */
210 for (i = 0; i < 4; i++) {
211 if (enc)
212 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
213 else
214 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
216 if (ret)
217 goto out;
220 /* The real thing. */
221 for (i = 0; i < 8; i++) {
222 cycles_t start, end;
224 start = get_cycles();
225 if (enc)
226 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
227 else
228 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
229 end = get_cycles();
231 if (ret)
232 goto out;
234 cycles += end - start;
237 out:
238 local_irq_enable();
240 if (ret == 0)
241 printk("1 operation in %lu cycles (%d bytes)\n",
242 (cycles + 4) / 8, blen);
244 return ret;
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 };
250 #define XBUFSIZE 8
251 #define MAX_IVLEN 32
253 static int testmgr_alloc_buf(char *buf[XBUFSIZE])
255 int i;
257 for (i = 0; i < XBUFSIZE; i++) {
258 buf[i] = (void *)__get_free_page(GFP_KERNEL);
259 if (!buf[i])
260 goto err_free_buf;
263 return 0;
265 err_free_buf:
266 while (i-- > 0)
267 free_page((unsigned long)buf[i]);
269 return -ENOMEM;
272 static void testmgr_free_buf(char *buf[XBUFSIZE])
274 int i;
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],
281 unsigned int buflen)
283 int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
284 int k, rem;
286 if (np > XBUFSIZE) {
287 rem = PAGE_SIZE;
288 np = XBUFSIZE;
289 } else {
290 rem = buflen % PAGE_SIZE;
293 sg_init_table(sg, np + 1);
294 if (rem)
295 np--;
296 for (k = 0; k < np; k++)
297 sg_set_buf(&sg[k + 1], xbuf[k], PAGE_SIZE);
299 if (rem)
300 sg_set_buf(&sg[k + 1], xbuf[k], rem);
303 static void test_aead_speed(const char *algo, int enc, unsigned int secs,
304 struct aead_speed_template *template,
305 unsigned int tcount, u8 authsize,
306 unsigned int aad_size, u8 *keysize)
308 unsigned int i, j;
309 struct crypto_aead *tfm;
310 int ret = -ENOMEM;
311 const char *key;
312 struct aead_request *req;
313 struct scatterlist *sg;
314 struct scatterlist *sgout;
315 const char *e;
316 void *assoc;
317 char *iv;
318 char *xbuf[XBUFSIZE];
319 char *xoutbuf[XBUFSIZE];
320 char *axbuf[XBUFSIZE];
321 unsigned int *b_size;
322 unsigned int iv_len;
323 struct tcrypt_result result;
325 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
326 if (!iv)
327 return;
329 if (aad_size >= PAGE_SIZE) {
330 pr_err("associate data length (%u) too big\n", aad_size);
331 goto out_noxbuf;
334 if (enc == ENCRYPT)
335 e = "encryption";
336 else
337 e = "decryption";
339 if (testmgr_alloc_buf(xbuf))
340 goto out_noxbuf;
341 if (testmgr_alloc_buf(axbuf))
342 goto out_noaxbuf;
343 if (testmgr_alloc_buf(xoutbuf))
344 goto out_nooutbuf;
346 sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL);
347 if (!sg)
348 goto out_nosg;
349 sgout = &sg[9];
351 tfm = crypto_alloc_aead(algo, 0, 0);
353 if (IS_ERR(tfm)) {
354 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
355 PTR_ERR(tfm));
356 goto out_notfm;
359 init_completion(&result.completion);
360 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
361 get_driver_name(crypto_aead, tfm), e);
363 req = aead_request_alloc(tfm, GFP_KERNEL);
364 if (!req) {
365 pr_err("alg: aead: Failed to allocate request for %s\n",
366 algo);
367 goto out_noreq;
370 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
371 tcrypt_complete, &result);
373 i = 0;
374 do {
375 b_size = aead_sizes;
376 do {
377 assoc = axbuf[0];
378 memset(assoc, 0xff, aad_size);
380 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
381 pr_err("template (%u) too big for tvmem (%lu)\n",
382 *keysize + *b_size,
383 TVMEMSIZE * PAGE_SIZE);
384 goto out;
387 key = tvmem[0];
388 for (j = 0; j < tcount; j++) {
389 if (template[j].klen == *keysize) {
390 key = template[j].key;
391 break;
394 ret = crypto_aead_setkey(tfm, key, *keysize);
395 ret = crypto_aead_setauthsize(tfm, authsize);
397 iv_len = crypto_aead_ivsize(tfm);
398 if (iv_len)
399 memset(iv, 0xff, iv_len);
401 crypto_aead_clear_flags(tfm, ~0);
402 printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
403 i, *keysize * 8, *b_size);
406 memset(tvmem[0], 0xff, PAGE_SIZE);
408 if (ret) {
409 pr_err("setkey() failed flags=%x\n",
410 crypto_aead_get_flags(tfm));
411 goto out;
414 sg_init_aead(sg, xbuf,
415 *b_size + (enc ? 0 : authsize));
417 sg_init_aead(sgout, xoutbuf,
418 *b_size + (enc ? authsize : 0));
420 sg_set_buf(&sg[0], assoc, aad_size);
421 sg_set_buf(&sgout[0], assoc, aad_size);
423 aead_request_set_crypt(req, sg, sgout,
424 *b_size + (enc ? 0 : authsize),
425 iv);
426 aead_request_set_ad(req, aad_size);
428 if (secs)
429 ret = test_aead_jiffies(req, enc, *b_size,
430 secs);
431 else
432 ret = test_aead_cycles(req, enc, *b_size);
434 if (ret) {
435 pr_err("%s() failed return code=%d\n", e, ret);
436 break;
438 b_size++;
439 i++;
440 } while (*b_size);
441 keysize++;
442 } while (*keysize);
444 out:
445 aead_request_free(req);
446 out_noreq:
447 crypto_free_aead(tfm);
448 out_notfm:
449 kfree(sg);
450 out_nosg:
451 testmgr_free_buf(xoutbuf);
452 out_nooutbuf:
453 testmgr_free_buf(axbuf);
454 out_noaxbuf:
455 testmgr_free_buf(xbuf);
456 out_noxbuf:
457 kfree(iv);
458 return;
461 static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
462 struct cipher_speed_template *template,
463 unsigned int tcount, u8 *keysize)
465 unsigned int ret, i, j, iv_len;
466 const char *key;
467 char iv[128];
468 struct crypto_blkcipher *tfm;
469 struct blkcipher_desc desc;
470 const char *e;
471 u32 *b_size;
473 if (enc == ENCRYPT)
474 e = "encryption";
475 else
476 e = "decryption";
478 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
480 if (IS_ERR(tfm)) {
481 printk("failed to load transform for %s: %ld\n", algo,
482 PTR_ERR(tfm));
483 return;
485 desc.tfm = tfm;
486 desc.flags = 0;
488 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
489 get_driver_name(crypto_blkcipher, tfm), e);
491 i = 0;
492 do {
494 b_size = block_sizes;
495 do {
496 struct scatterlist sg[TVMEMSIZE];
498 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
499 printk("template (%u) too big for "
500 "tvmem (%lu)\n", *keysize + *b_size,
501 TVMEMSIZE * PAGE_SIZE);
502 goto out;
505 printk("test %u (%d bit key, %d byte blocks): ", i,
506 *keysize * 8, *b_size);
508 memset(tvmem[0], 0xff, PAGE_SIZE);
510 /* set key, plain text and IV */
511 key = tvmem[0];
512 for (j = 0; j < tcount; j++) {
513 if (template[j].klen == *keysize) {
514 key = template[j].key;
515 break;
519 ret = crypto_blkcipher_setkey(tfm, key, *keysize);
520 if (ret) {
521 printk("setkey() failed flags=%x\n",
522 crypto_blkcipher_get_flags(tfm));
523 goto out;
526 sg_init_table(sg, TVMEMSIZE);
527 sg_set_buf(sg, tvmem[0] + *keysize,
528 PAGE_SIZE - *keysize);
529 for (j = 1; j < TVMEMSIZE; j++) {
530 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
531 memset (tvmem[j], 0xff, PAGE_SIZE);
534 iv_len = crypto_blkcipher_ivsize(tfm);
535 if (iv_len) {
536 memset(&iv, 0xff, iv_len);
537 crypto_blkcipher_set_iv(tfm, iv, iv_len);
540 if (secs)
541 ret = test_cipher_jiffies(&desc, enc, sg,
542 *b_size, secs);
543 else
544 ret = test_cipher_cycles(&desc, enc, sg,
545 *b_size);
547 if (ret) {
548 printk("%s() failed flags=%x\n", e, desc.flags);
549 break;
551 b_size++;
552 i++;
553 } while (*b_size);
554 keysize++;
555 } while (*keysize);
557 out:
558 crypto_free_blkcipher(tfm);
561 static int test_hash_jiffies_digest(struct hash_desc *desc,
562 struct scatterlist *sg, int blen,
563 char *out, int secs)
565 unsigned long start, end;
566 int bcount;
567 int ret;
569 for (start = jiffies, end = start + secs * HZ, bcount = 0;
570 time_before(jiffies, end); bcount++) {
571 ret = crypto_hash_digest(desc, sg, blen, out);
572 if (ret)
573 return ret;
576 printk("%6u opers/sec, %9lu bytes/sec\n",
577 bcount / secs, ((long)bcount * blen) / secs);
579 return 0;
582 static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg,
583 int blen, int plen, char *out, int secs)
585 unsigned long start, end;
586 int bcount, pcount;
587 int ret;
589 if (plen == blen)
590 return test_hash_jiffies_digest(desc, sg, blen, out, secs);
592 for (start = jiffies, end = start + secs * HZ, bcount = 0;
593 time_before(jiffies, end); bcount++) {
594 ret = crypto_hash_init(desc);
595 if (ret)
596 return ret;
597 for (pcount = 0; pcount < blen; pcount += plen) {
598 ret = crypto_hash_update(desc, sg, plen);
599 if (ret)
600 return ret;
602 /* we assume there is enough space in 'out' for the result */
603 ret = crypto_hash_final(desc, out);
604 if (ret)
605 return ret;
608 printk("%6u opers/sec, %9lu bytes/sec\n",
609 bcount / secs, ((long)bcount * blen) / secs);
611 return 0;
614 static int test_hash_cycles_digest(struct hash_desc *desc,
615 struct scatterlist *sg, int blen, char *out)
617 unsigned long cycles = 0;
618 int i;
619 int ret;
621 local_irq_disable();
623 /* Warm-up run. */
624 for (i = 0; i < 4; i++) {
625 ret = crypto_hash_digest(desc, sg, blen, out);
626 if (ret)
627 goto out;
630 /* The real thing. */
631 for (i = 0; i < 8; i++) {
632 cycles_t start, end;
634 start = get_cycles();
636 ret = crypto_hash_digest(desc, sg, blen, out);
637 if (ret)
638 goto out;
640 end = get_cycles();
642 cycles += end - start;
645 out:
646 local_irq_enable();
648 if (ret)
649 return ret;
651 printk("%6lu cycles/operation, %4lu cycles/byte\n",
652 cycles / 8, cycles / (8 * blen));
654 return 0;
657 static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg,
658 int blen, int plen, char *out)
660 unsigned long cycles = 0;
661 int i, pcount;
662 int ret;
664 if (plen == blen)
665 return test_hash_cycles_digest(desc, sg, blen, out);
667 local_irq_disable();
669 /* Warm-up run. */
670 for (i = 0; i < 4; i++) {
671 ret = crypto_hash_init(desc);
672 if (ret)
673 goto out;
674 for (pcount = 0; pcount < blen; pcount += plen) {
675 ret = crypto_hash_update(desc, sg, plen);
676 if (ret)
677 goto out;
679 ret = crypto_hash_final(desc, out);
680 if (ret)
681 goto out;
684 /* The real thing. */
685 for (i = 0; i < 8; i++) {
686 cycles_t start, end;
688 start = get_cycles();
690 ret = crypto_hash_init(desc);
691 if (ret)
692 goto out;
693 for (pcount = 0; pcount < blen; pcount += plen) {
694 ret = crypto_hash_update(desc, sg, plen);
695 if (ret)
696 goto out;
698 ret = crypto_hash_final(desc, out);
699 if (ret)
700 goto out;
702 end = get_cycles();
704 cycles += end - start;
707 out:
708 local_irq_enable();
710 if (ret)
711 return ret;
713 printk("%6lu cycles/operation, %4lu cycles/byte\n",
714 cycles / 8, cycles / (8 * blen));
716 return 0;
719 static void test_hash_sg_init(struct scatterlist *sg)
721 int i;
723 sg_init_table(sg, TVMEMSIZE);
724 for (i = 0; i < TVMEMSIZE; i++) {
725 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
726 memset(tvmem[i], 0xff, PAGE_SIZE);
730 static void test_hash_speed(const char *algo, unsigned int secs,
731 struct hash_speed *speed)
733 struct scatterlist sg[TVMEMSIZE];
734 struct crypto_hash *tfm;
735 struct hash_desc desc;
736 static char output[1024];
737 int i;
738 int ret;
740 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
742 if (IS_ERR(tfm)) {
743 printk(KERN_ERR "failed to load transform for %s: %ld\n", algo,
744 PTR_ERR(tfm));
745 return;
748 printk(KERN_INFO "\ntesting speed of %s (%s)\n", algo,
749 get_driver_name(crypto_hash, tfm));
751 desc.tfm = tfm;
752 desc.flags = 0;
754 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
755 printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n",
756 crypto_hash_digestsize(tfm), sizeof(output));
757 goto out;
760 test_hash_sg_init(sg);
761 for (i = 0; speed[i].blen != 0; i++) {
762 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
763 printk(KERN_ERR
764 "template (%u) too big for tvmem (%lu)\n",
765 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
766 goto out;
769 if (speed[i].klen)
770 crypto_hash_setkey(tfm, tvmem[0], speed[i].klen);
772 printk(KERN_INFO "test%3u "
773 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
774 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
776 if (secs)
777 ret = test_hash_jiffies(&desc, sg, speed[i].blen,
778 speed[i].plen, output, secs);
779 else
780 ret = test_hash_cycles(&desc, sg, speed[i].blen,
781 speed[i].plen, output);
783 if (ret) {
784 printk(KERN_ERR "hashing failed ret=%d\n", ret);
785 break;
789 out:
790 crypto_free_hash(tfm);
793 static inline int do_one_ahash_op(struct ahash_request *req, int ret)
795 if (ret == -EINPROGRESS || ret == -EBUSY) {
796 struct tcrypt_result *tr = req->base.data;
798 wait_for_completion(&tr->completion);
799 reinit_completion(&tr->completion);
800 ret = tr->err;
802 return ret;
805 static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
806 char *out, int secs)
808 unsigned long start, end;
809 int bcount;
810 int ret;
812 for (start = jiffies, end = start + secs * HZ, bcount = 0;
813 time_before(jiffies, end); bcount++) {
814 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
815 if (ret)
816 return ret;
819 printk("%6u opers/sec, %9lu bytes/sec\n",
820 bcount / secs, ((long)bcount * blen) / secs);
822 return 0;
825 static int test_ahash_jiffies(struct ahash_request *req, int blen,
826 int plen, char *out, int secs)
828 unsigned long start, end;
829 int bcount, pcount;
830 int ret;
832 if (plen == blen)
833 return test_ahash_jiffies_digest(req, blen, out, secs);
835 for (start = jiffies, end = start + secs * HZ, bcount = 0;
836 time_before(jiffies, end); bcount++) {
837 ret = do_one_ahash_op(req, crypto_ahash_init(req));
838 if (ret)
839 return ret;
840 for (pcount = 0; pcount < blen; pcount += plen) {
841 ret = do_one_ahash_op(req, crypto_ahash_update(req));
842 if (ret)
843 return ret;
845 /* we assume there is enough space in 'out' for the result */
846 ret = do_one_ahash_op(req, crypto_ahash_final(req));
847 if (ret)
848 return ret;
851 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
852 bcount / secs, ((long)bcount * blen) / secs);
854 return 0;
857 static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
858 char *out)
860 unsigned long cycles = 0;
861 int ret, i;
863 /* Warm-up run. */
864 for (i = 0; i < 4; i++) {
865 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
866 if (ret)
867 goto out;
870 /* The real thing. */
871 for (i = 0; i < 8; i++) {
872 cycles_t start, end;
874 start = get_cycles();
876 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
877 if (ret)
878 goto out;
880 end = get_cycles();
882 cycles += end - start;
885 out:
886 if (ret)
887 return ret;
889 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
890 cycles / 8, cycles / (8 * blen));
892 return 0;
895 static int test_ahash_cycles(struct ahash_request *req, int blen,
896 int plen, char *out)
898 unsigned long cycles = 0;
899 int i, pcount, ret;
901 if (plen == blen)
902 return test_ahash_cycles_digest(req, blen, out);
904 /* Warm-up run. */
905 for (i = 0; i < 4; i++) {
906 ret = do_one_ahash_op(req, crypto_ahash_init(req));
907 if (ret)
908 goto out;
909 for (pcount = 0; pcount < blen; pcount += plen) {
910 ret = do_one_ahash_op(req, crypto_ahash_update(req));
911 if (ret)
912 goto out;
914 ret = do_one_ahash_op(req, crypto_ahash_final(req));
915 if (ret)
916 goto out;
919 /* The real thing. */
920 for (i = 0; i < 8; i++) {
921 cycles_t start, end;
923 start = get_cycles();
925 ret = do_one_ahash_op(req, crypto_ahash_init(req));
926 if (ret)
927 goto out;
928 for (pcount = 0; pcount < blen; pcount += plen) {
929 ret = do_one_ahash_op(req, crypto_ahash_update(req));
930 if (ret)
931 goto out;
933 ret = do_one_ahash_op(req, crypto_ahash_final(req));
934 if (ret)
935 goto out;
937 end = get_cycles();
939 cycles += end - start;
942 out:
943 if (ret)
944 return ret;
946 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
947 cycles / 8, cycles / (8 * blen));
949 return 0;
952 static void test_ahash_speed(const char *algo, unsigned int secs,
953 struct hash_speed *speed)
955 struct scatterlist sg[TVMEMSIZE];
956 struct tcrypt_result tresult;
957 struct ahash_request *req;
958 struct crypto_ahash *tfm;
959 char *output;
960 int i, ret;
962 tfm = crypto_alloc_ahash(algo, 0, 0);
963 if (IS_ERR(tfm)) {
964 pr_err("failed to load transform for %s: %ld\n",
965 algo, PTR_ERR(tfm));
966 return;
969 printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
970 get_driver_name(crypto_ahash, tfm));
972 if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) {
973 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm),
974 MAX_DIGEST_SIZE);
975 goto out;
978 test_hash_sg_init(sg);
979 req = ahash_request_alloc(tfm, GFP_KERNEL);
980 if (!req) {
981 pr_err("ahash request allocation failure\n");
982 goto out;
985 init_completion(&tresult.completion);
986 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
987 tcrypt_complete, &tresult);
989 output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
990 if (!output)
991 goto out_nomem;
993 for (i = 0; speed[i].blen != 0; i++) {
994 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
995 pr_err("template (%u) too big for tvmem (%lu)\n",
996 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
997 break;
1000 pr_info("test%3u "
1001 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
1002 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
1004 ahash_request_set_crypt(req, sg, output, speed[i].plen);
1006 if (secs)
1007 ret = test_ahash_jiffies(req, speed[i].blen,
1008 speed[i].plen, output, secs);
1009 else
1010 ret = test_ahash_cycles(req, speed[i].blen,
1011 speed[i].plen, output);
1013 if (ret) {
1014 pr_err("hashing failed ret=%d\n", ret);
1015 break;
1019 kfree(output);
1021 out_nomem:
1022 ahash_request_free(req);
1024 out:
1025 crypto_free_ahash(tfm);
1028 static inline int do_one_acipher_op(struct ablkcipher_request *req, int ret)
1030 if (ret == -EINPROGRESS || ret == -EBUSY) {
1031 struct tcrypt_result *tr = req->base.data;
1033 wait_for_completion(&tr->completion);
1034 reinit_completion(&tr->completion);
1035 ret = tr->err;
1038 return ret;
1041 static int test_acipher_jiffies(struct ablkcipher_request *req, int enc,
1042 int blen, int secs)
1044 unsigned long start, end;
1045 int bcount;
1046 int ret;
1048 for (start = jiffies, end = start + secs * HZ, bcount = 0;
1049 time_before(jiffies, end); bcount++) {
1050 if (enc)
1051 ret = do_one_acipher_op(req,
1052 crypto_ablkcipher_encrypt(req));
1053 else
1054 ret = do_one_acipher_op(req,
1055 crypto_ablkcipher_decrypt(req));
1057 if (ret)
1058 return ret;
1061 pr_cont("%d operations in %d seconds (%ld bytes)\n",
1062 bcount, secs, (long)bcount * blen);
1063 return 0;
1066 static int test_acipher_cycles(struct ablkcipher_request *req, int enc,
1067 int blen)
1069 unsigned long cycles = 0;
1070 int ret = 0;
1071 int i;
1073 /* Warm-up run. */
1074 for (i = 0; i < 4; i++) {
1075 if (enc)
1076 ret = do_one_acipher_op(req,
1077 crypto_ablkcipher_encrypt(req));
1078 else
1079 ret = do_one_acipher_op(req,
1080 crypto_ablkcipher_decrypt(req));
1082 if (ret)
1083 goto out;
1086 /* The real thing. */
1087 for (i = 0; i < 8; i++) {
1088 cycles_t start, end;
1090 start = get_cycles();
1091 if (enc)
1092 ret = do_one_acipher_op(req,
1093 crypto_ablkcipher_encrypt(req));
1094 else
1095 ret = do_one_acipher_op(req,
1096 crypto_ablkcipher_decrypt(req));
1097 end = get_cycles();
1099 if (ret)
1100 goto out;
1102 cycles += end - start;
1105 out:
1106 if (ret == 0)
1107 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1108 (cycles + 4) / 8, blen);
1110 return ret;
1113 static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
1114 struct cipher_speed_template *template,
1115 unsigned int tcount, u8 *keysize)
1117 unsigned int ret, i, j, k, iv_len;
1118 struct tcrypt_result tresult;
1119 const char *key;
1120 char iv[128];
1121 struct ablkcipher_request *req;
1122 struct crypto_ablkcipher *tfm;
1123 const char *e;
1124 u32 *b_size;
1126 if (enc == ENCRYPT)
1127 e = "encryption";
1128 else
1129 e = "decryption";
1131 init_completion(&tresult.completion);
1133 tfm = crypto_alloc_ablkcipher(algo, 0, 0);
1135 if (IS_ERR(tfm)) {
1136 pr_err("failed to load transform for %s: %ld\n", algo,
1137 PTR_ERR(tfm));
1138 return;
1141 pr_info("\ntesting speed of async %s (%s) %s\n", algo,
1142 get_driver_name(crypto_ablkcipher, tfm), e);
1144 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
1145 if (!req) {
1146 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1147 algo);
1148 goto out;
1151 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1152 tcrypt_complete, &tresult);
1154 i = 0;
1155 do {
1156 b_size = block_sizes;
1158 do {
1159 struct scatterlist sg[TVMEMSIZE];
1161 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
1162 pr_err("template (%u) too big for "
1163 "tvmem (%lu)\n", *keysize + *b_size,
1164 TVMEMSIZE * PAGE_SIZE);
1165 goto out_free_req;
1168 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1169 *keysize * 8, *b_size);
1171 memset(tvmem[0], 0xff, PAGE_SIZE);
1173 /* set key, plain text and IV */
1174 key = tvmem[0];
1175 for (j = 0; j < tcount; j++) {
1176 if (template[j].klen == *keysize) {
1177 key = template[j].key;
1178 break;
1182 crypto_ablkcipher_clear_flags(tfm, ~0);
1184 ret = crypto_ablkcipher_setkey(tfm, key, *keysize);
1185 if (ret) {
1186 pr_err("setkey() failed flags=%x\n",
1187 crypto_ablkcipher_get_flags(tfm));
1188 goto out_free_req;
1191 k = *keysize + *b_size;
1192 sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
1194 if (k > PAGE_SIZE) {
1195 sg_set_buf(sg, tvmem[0] + *keysize,
1196 PAGE_SIZE - *keysize);
1197 k -= PAGE_SIZE;
1198 j = 1;
1199 while (k > PAGE_SIZE) {
1200 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
1201 memset(tvmem[j], 0xff, PAGE_SIZE);
1202 j++;
1203 k -= PAGE_SIZE;
1205 sg_set_buf(sg + j, tvmem[j], k);
1206 memset(tvmem[j], 0xff, k);
1207 } else {
1208 sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
1211 iv_len = crypto_ablkcipher_ivsize(tfm);
1212 if (iv_len)
1213 memset(&iv, 0xff, iv_len);
1215 ablkcipher_request_set_crypt(req, sg, sg, *b_size, iv);
1217 if (secs)
1218 ret = test_acipher_jiffies(req, enc,
1219 *b_size, secs);
1220 else
1221 ret = test_acipher_cycles(req, enc,
1222 *b_size);
1224 if (ret) {
1225 pr_err("%s() failed flags=%x\n", e,
1226 crypto_ablkcipher_get_flags(tfm));
1227 break;
1229 b_size++;
1230 i++;
1231 } while (*b_size);
1232 keysize++;
1233 } while (*keysize);
1235 out_free_req:
1236 ablkcipher_request_free(req);
1237 out:
1238 crypto_free_ablkcipher(tfm);
1241 static void test_available(void)
1243 char **name = check;
1245 while (*name) {
1246 printk("alg %s ", *name);
1247 printk(crypto_has_alg(*name, 0, 0) ?
1248 "found\n" : "not found\n");
1249 name++;
1253 static inline int tcrypt_test(const char *alg)
1255 int ret;
1257 ret = alg_test(alg, alg, 0, 0);
1258 /* non-fips algs return -EINVAL in fips mode */
1259 if (fips_enabled && ret == -EINVAL)
1260 ret = 0;
1261 return ret;
1264 static int do_test(const char *alg, u32 type, u32 mask, int m)
1266 int i;
1267 int ret = 0;
1269 switch (m) {
1270 case 0:
1271 if (alg) {
1272 if (!crypto_has_alg(alg, type,
1273 mask ?: CRYPTO_ALG_TYPE_MASK))
1274 ret = -ENOENT;
1275 break;
1278 for (i = 1; i < 200; i++)
1279 ret += do_test(NULL, 0, 0, i);
1280 break;
1282 case 1:
1283 ret += tcrypt_test("md5");
1284 break;
1286 case 2:
1287 ret += tcrypt_test("sha1");
1288 break;
1290 case 3:
1291 ret += tcrypt_test("ecb(des)");
1292 ret += tcrypt_test("cbc(des)");
1293 ret += tcrypt_test("ctr(des)");
1294 break;
1296 case 4:
1297 ret += tcrypt_test("ecb(des3_ede)");
1298 ret += tcrypt_test("cbc(des3_ede)");
1299 ret += tcrypt_test("ctr(des3_ede)");
1300 break;
1302 case 5:
1303 ret += tcrypt_test("md4");
1304 break;
1306 case 6:
1307 ret += tcrypt_test("sha256");
1308 break;
1310 case 7:
1311 ret += tcrypt_test("ecb(blowfish)");
1312 ret += tcrypt_test("cbc(blowfish)");
1313 ret += tcrypt_test("ctr(blowfish)");
1314 break;
1316 case 8:
1317 ret += tcrypt_test("ecb(twofish)");
1318 ret += tcrypt_test("cbc(twofish)");
1319 ret += tcrypt_test("ctr(twofish)");
1320 ret += tcrypt_test("lrw(twofish)");
1321 ret += tcrypt_test("xts(twofish)");
1322 break;
1324 case 9:
1325 ret += tcrypt_test("ecb(serpent)");
1326 ret += tcrypt_test("cbc(serpent)");
1327 ret += tcrypt_test("ctr(serpent)");
1328 ret += tcrypt_test("lrw(serpent)");
1329 ret += tcrypt_test("xts(serpent)");
1330 break;
1332 case 10:
1333 ret += tcrypt_test("ecb(aes)");
1334 ret += tcrypt_test("cbc(aes)");
1335 ret += tcrypt_test("lrw(aes)");
1336 ret += tcrypt_test("xts(aes)");
1337 ret += tcrypt_test("ctr(aes)");
1338 ret += tcrypt_test("rfc3686(ctr(aes))");
1339 break;
1341 case 11:
1342 ret += tcrypt_test("sha384");
1343 break;
1345 case 12:
1346 ret += tcrypt_test("sha512");
1347 break;
1349 case 13:
1350 ret += tcrypt_test("deflate");
1351 break;
1353 case 14:
1354 ret += tcrypt_test("ecb(cast5)");
1355 ret += tcrypt_test("cbc(cast5)");
1356 ret += tcrypt_test("ctr(cast5)");
1357 break;
1359 case 15:
1360 ret += tcrypt_test("ecb(cast6)");
1361 ret += tcrypt_test("cbc(cast6)");
1362 ret += tcrypt_test("ctr(cast6)");
1363 ret += tcrypt_test("lrw(cast6)");
1364 ret += tcrypt_test("xts(cast6)");
1365 break;
1367 case 16:
1368 ret += tcrypt_test("ecb(arc4)");
1369 break;
1371 case 17:
1372 ret += tcrypt_test("michael_mic");
1373 break;
1375 case 18:
1376 ret += tcrypt_test("crc32c");
1377 break;
1379 case 19:
1380 ret += tcrypt_test("ecb(tea)");
1381 break;
1383 case 20:
1384 ret += tcrypt_test("ecb(xtea)");
1385 break;
1387 case 21:
1388 ret += tcrypt_test("ecb(khazad)");
1389 break;
1391 case 22:
1392 ret += tcrypt_test("wp512");
1393 break;
1395 case 23:
1396 ret += tcrypt_test("wp384");
1397 break;
1399 case 24:
1400 ret += tcrypt_test("wp256");
1401 break;
1403 case 25:
1404 ret += tcrypt_test("ecb(tnepres)");
1405 break;
1407 case 26:
1408 ret += tcrypt_test("ecb(anubis)");
1409 ret += tcrypt_test("cbc(anubis)");
1410 break;
1412 case 27:
1413 ret += tcrypt_test("tgr192");
1414 break;
1416 case 28:
1417 ret += tcrypt_test("tgr160");
1418 break;
1420 case 29:
1421 ret += tcrypt_test("tgr128");
1422 break;
1424 case 30:
1425 ret += tcrypt_test("ecb(xeta)");
1426 break;
1428 case 31:
1429 ret += tcrypt_test("pcbc(fcrypt)");
1430 break;
1432 case 32:
1433 ret += tcrypt_test("ecb(camellia)");
1434 ret += tcrypt_test("cbc(camellia)");
1435 ret += tcrypt_test("ctr(camellia)");
1436 ret += tcrypt_test("lrw(camellia)");
1437 ret += tcrypt_test("xts(camellia)");
1438 break;
1440 case 33:
1441 ret += tcrypt_test("sha224");
1442 break;
1444 case 34:
1445 ret += tcrypt_test("salsa20");
1446 break;
1448 case 35:
1449 ret += tcrypt_test("gcm(aes)");
1450 break;
1452 case 36:
1453 ret += tcrypt_test("lzo");
1454 break;
1456 case 37:
1457 ret += tcrypt_test("ccm(aes)");
1458 break;
1460 case 38:
1461 ret += tcrypt_test("cts(cbc(aes))");
1462 break;
1464 case 39:
1465 ret += tcrypt_test("rmd128");
1466 break;
1468 case 40:
1469 ret += tcrypt_test("rmd160");
1470 break;
1472 case 41:
1473 ret += tcrypt_test("rmd256");
1474 break;
1476 case 42:
1477 ret += tcrypt_test("rmd320");
1478 break;
1480 case 43:
1481 ret += tcrypt_test("ecb(seed)");
1482 break;
1484 case 44:
1485 ret += tcrypt_test("zlib");
1486 break;
1488 case 45:
1489 ret += tcrypt_test("rfc4309(ccm(aes))");
1490 break;
1492 case 46:
1493 ret += tcrypt_test("ghash");
1494 break;
1496 case 47:
1497 ret += tcrypt_test("crct10dif");
1498 break;
1500 case 100:
1501 ret += tcrypt_test("hmac(md5)");
1502 break;
1504 case 101:
1505 ret += tcrypt_test("hmac(sha1)");
1506 break;
1508 case 102:
1509 ret += tcrypt_test("hmac(sha256)");
1510 break;
1512 case 103:
1513 ret += tcrypt_test("hmac(sha384)");
1514 break;
1516 case 104:
1517 ret += tcrypt_test("hmac(sha512)");
1518 break;
1520 case 105:
1521 ret += tcrypt_test("hmac(sha224)");
1522 break;
1524 case 106:
1525 ret += tcrypt_test("xcbc(aes)");
1526 break;
1528 case 107:
1529 ret += tcrypt_test("hmac(rmd128)");
1530 break;
1532 case 108:
1533 ret += tcrypt_test("hmac(rmd160)");
1534 break;
1536 case 109:
1537 ret += tcrypt_test("vmac(aes)");
1538 break;
1540 case 110:
1541 ret += tcrypt_test("hmac(crc32)");
1542 break;
1544 case 150:
1545 ret += tcrypt_test("ansi_cprng");
1546 break;
1548 case 151:
1549 ret += tcrypt_test("rfc4106(gcm(aes))");
1550 break;
1552 case 152:
1553 ret += tcrypt_test("rfc4543(gcm(aes))");
1554 break;
1556 case 153:
1557 ret += tcrypt_test("cmac(aes)");
1558 break;
1560 case 154:
1561 ret += tcrypt_test("cmac(des3_ede)");
1562 break;
1564 case 155:
1565 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1566 break;
1568 case 156:
1569 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1570 break;
1572 case 157:
1573 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1574 break;
1575 case 181:
1576 ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
1577 break;
1578 case 182:
1579 ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
1580 break;
1581 case 183:
1582 ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
1583 break;
1584 case 184:
1585 ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
1586 break;
1587 case 185:
1588 ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
1589 break;
1590 case 186:
1591 ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
1592 break;
1593 case 187:
1594 ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
1595 break;
1596 case 188:
1597 ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
1598 break;
1599 case 189:
1600 ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
1601 break;
1602 case 190:
1603 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
1604 break;
1605 case 200:
1606 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1607 speed_template_16_24_32);
1608 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1609 speed_template_16_24_32);
1610 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1611 speed_template_16_24_32);
1612 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1613 speed_template_16_24_32);
1614 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1615 speed_template_32_40_48);
1616 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1617 speed_template_32_40_48);
1618 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1619 speed_template_32_48_64);
1620 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1621 speed_template_32_48_64);
1622 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1623 speed_template_16_24_32);
1624 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1625 speed_template_16_24_32);
1626 break;
1628 case 201:
1629 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1630 des3_speed_template, DES3_SPEED_VECTORS,
1631 speed_template_24);
1632 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1633 des3_speed_template, DES3_SPEED_VECTORS,
1634 speed_template_24);
1635 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1636 des3_speed_template, DES3_SPEED_VECTORS,
1637 speed_template_24);
1638 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1639 des3_speed_template, DES3_SPEED_VECTORS,
1640 speed_template_24);
1641 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
1642 des3_speed_template, DES3_SPEED_VECTORS,
1643 speed_template_24);
1644 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
1645 des3_speed_template, DES3_SPEED_VECTORS,
1646 speed_template_24);
1647 break;
1649 case 202:
1650 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1651 speed_template_16_24_32);
1652 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1653 speed_template_16_24_32);
1654 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1655 speed_template_16_24_32);
1656 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1657 speed_template_16_24_32);
1658 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1659 speed_template_16_24_32);
1660 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1661 speed_template_16_24_32);
1662 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1663 speed_template_32_40_48);
1664 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1665 speed_template_32_40_48);
1666 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1667 speed_template_32_48_64);
1668 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1669 speed_template_32_48_64);
1670 break;
1672 case 203:
1673 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1674 speed_template_8_32);
1675 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1676 speed_template_8_32);
1677 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1678 speed_template_8_32);
1679 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1680 speed_template_8_32);
1681 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
1682 speed_template_8_32);
1683 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
1684 speed_template_8_32);
1685 break;
1687 case 204:
1688 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1689 speed_template_8);
1690 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1691 speed_template_8);
1692 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1693 speed_template_8);
1694 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1695 speed_template_8);
1696 break;
1698 case 205:
1699 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1700 speed_template_16_24_32);
1701 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1702 speed_template_16_24_32);
1703 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1704 speed_template_16_24_32);
1705 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1706 speed_template_16_24_32);
1707 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
1708 speed_template_16_24_32);
1709 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
1710 speed_template_16_24_32);
1711 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
1712 speed_template_32_40_48);
1713 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
1714 speed_template_32_40_48);
1715 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
1716 speed_template_32_48_64);
1717 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
1718 speed_template_32_48_64);
1719 break;
1721 case 206:
1722 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
1723 speed_template_16_32);
1724 break;
1726 case 207:
1727 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1728 speed_template_16_32);
1729 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1730 speed_template_16_32);
1731 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1732 speed_template_16_32);
1733 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1734 speed_template_16_32);
1735 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1736 speed_template_16_32);
1737 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1738 speed_template_16_32);
1739 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1740 speed_template_32_48);
1741 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1742 speed_template_32_48);
1743 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1744 speed_template_32_64);
1745 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
1746 speed_template_32_64);
1747 break;
1749 case 208:
1750 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
1751 speed_template_8);
1752 break;
1754 case 209:
1755 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
1756 speed_template_8_16);
1757 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
1758 speed_template_8_16);
1759 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
1760 speed_template_8_16);
1761 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
1762 speed_template_8_16);
1763 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
1764 speed_template_8_16);
1765 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
1766 speed_template_8_16);
1767 break;
1769 case 210:
1770 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
1771 speed_template_16_32);
1772 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
1773 speed_template_16_32);
1774 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
1775 speed_template_16_32);
1776 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
1777 speed_template_16_32);
1778 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
1779 speed_template_16_32);
1780 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
1781 speed_template_16_32);
1782 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
1783 speed_template_32_48);
1784 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
1785 speed_template_32_48);
1786 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
1787 speed_template_32_64);
1788 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
1789 speed_template_32_64);
1790 break;
1792 case 211:
1793 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
1794 NULL, 0, 16, 16, aead_speed_template_20);
1795 test_aead_speed("gcm(aes)", ENCRYPT, sec,
1796 NULL, 0, 16, 8, aead_speed_template_20);
1797 break;
1799 case 212:
1800 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
1801 NULL, 0, 16, 16, aead_speed_template_19);
1802 break;
1804 case 213:
1805 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
1806 NULL, 0, 16, 8, aead_speed_template_36);
1807 break;
1809 case 214:
1810 test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
1811 speed_template_32);
1812 break;
1815 case 300:
1816 if (alg) {
1817 test_hash_speed(alg, sec, generic_hash_speed_template);
1818 break;
1821 /* fall through */
1823 case 301:
1824 test_hash_speed("md4", sec, generic_hash_speed_template);
1825 if (mode > 300 && mode < 400) break;
1827 case 302:
1828 test_hash_speed("md5", sec, generic_hash_speed_template);
1829 if (mode > 300 && mode < 400) break;
1831 case 303:
1832 test_hash_speed("sha1", sec, generic_hash_speed_template);
1833 if (mode > 300 && mode < 400) break;
1835 case 304:
1836 test_hash_speed("sha256", sec, generic_hash_speed_template);
1837 if (mode > 300 && mode < 400) break;
1839 case 305:
1840 test_hash_speed("sha384", sec, generic_hash_speed_template);
1841 if (mode > 300 && mode < 400) break;
1843 case 306:
1844 test_hash_speed("sha512", sec, generic_hash_speed_template);
1845 if (mode > 300 && mode < 400) break;
1847 case 307:
1848 test_hash_speed("wp256", sec, generic_hash_speed_template);
1849 if (mode > 300 && mode < 400) break;
1851 case 308:
1852 test_hash_speed("wp384", sec, generic_hash_speed_template);
1853 if (mode > 300 && mode < 400) break;
1855 case 309:
1856 test_hash_speed("wp512", sec, generic_hash_speed_template);
1857 if (mode > 300 && mode < 400) break;
1859 case 310:
1860 test_hash_speed("tgr128", sec, generic_hash_speed_template);
1861 if (mode > 300 && mode < 400) break;
1863 case 311:
1864 test_hash_speed("tgr160", sec, generic_hash_speed_template);
1865 if (mode > 300 && mode < 400) break;
1867 case 312:
1868 test_hash_speed("tgr192", sec, generic_hash_speed_template);
1869 if (mode > 300 && mode < 400) break;
1871 case 313:
1872 test_hash_speed("sha224", sec, generic_hash_speed_template);
1873 if (mode > 300 && mode < 400) break;
1875 case 314:
1876 test_hash_speed("rmd128", sec, generic_hash_speed_template);
1877 if (mode > 300 && mode < 400) break;
1879 case 315:
1880 test_hash_speed("rmd160", sec, generic_hash_speed_template);
1881 if (mode > 300 && mode < 400) break;
1883 case 316:
1884 test_hash_speed("rmd256", sec, generic_hash_speed_template);
1885 if (mode > 300 && mode < 400) break;
1887 case 317:
1888 test_hash_speed("rmd320", sec, generic_hash_speed_template);
1889 if (mode > 300 && mode < 400) break;
1891 case 318:
1892 test_hash_speed("ghash-generic", sec, hash_speed_template_16);
1893 if (mode > 300 && mode < 400) break;
1895 case 319:
1896 test_hash_speed("crc32c", sec, generic_hash_speed_template);
1897 if (mode > 300 && mode < 400) break;
1899 case 320:
1900 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
1901 if (mode > 300 && mode < 400) break;
1903 case 321:
1904 test_hash_speed("poly1305", sec, poly1305_speed_template);
1905 if (mode > 300 && mode < 400) break;
1907 case 399:
1908 break;
1910 case 400:
1911 if (alg) {
1912 test_ahash_speed(alg, sec, generic_hash_speed_template);
1913 break;
1916 /* fall through */
1918 case 401:
1919 test_ahash_speed("md4", sec, generic_hash_speed_template);
1920 if (mode > 400 && mode < 500) break;
1922 case 402:
1923 test_ahash_speed("md5", sec, generic_hash_speed_template);
1924 if (mode > 400 && mode < 500) break;
1926 case 403:
1927 test_ahash_speed("sha1", sec, generic_hash_speed_template);
1928 if (mode > 400 && mode < 500) break;
1930 case 404:
1931 test_ahash_speed("sha256", sec, generic_hash_speed_template);
1932 if (mode > 400 && mode < 500) break;
1934 case 405:
1935 test_ahash_speed("sha384", sec, generic_hash_speed_template);
1936 if (mode > 400 && mode < 500) break;
1938 case 406:
1939 test_ahash_speed("sha512", sec, generic_hash_speed_template);
1940 if (mode > 400 && mode < 500) break;
1942 case 407:
1943 test_ahash_speed("wp256", sec, generic_hash_speed_template);
1944 if (mode > 400 && mode < 500) break;
1946 case 408:
1947 test_ahash_speed("wp384", sec, generic_hash_speed_template);
1948 if (mode > 400 && mode < 500) break;
1950 case 409:
1951 test_ahash_speed("wp512", sec, generic_hash_speed_template);
1952 if (mode > 400 && mode < 500) break;
1954 case 410:
1955 test_ahash_speed("tgr128", sec, generic_hash_speed_template);
1956 if (mode > 400 && mode < 500) break;
1958 case 411:
1959 test_ahash_speed("tgr160", sec, generic_hash_speed_template);
1960 if (mode > 400 && mode < 500) break;
1962 case 412:
1963 test_ahash_speed("tgr192", sec, generic_hash_speed_template);
1964 if (mode > 400 && mode < 500) break;
1966 case 413:
1967 test_ahash_speed("sha224", sec, generic_hash_speed_template);
1968 if (mode > 400 && mode < 500) break;
1970 case 414:
1971 test_ahash_speed("rmd128", sec, generic_hash_speed_template);
1972 if (mode > 400 && mode < 500) break;
1974 case 415:
1975 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
1976 if (mode > 400 && mode < 500) break;
1978 case 416:
1979 test_ahash_speed("rmd256", sec, generic_hash_speed_template);
1980 if (mode > 400 && mode < 500) break;
1982 case 417:
1983 test_ahash_speed("rmd320", sec, generic_hash_speed_template);
1984 if (mode > 400 && mode < 500) break;
1986 case 499:
1987 break;
1989 case 500:
1990 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1991 speed_template_16_24_32);
1992 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1993 speed_template_16_24_32);
1994 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1995 speed_template_16_24_32);
1996 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1997 speed_template_16_24_32);
1998 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1999 speed_template_32_40_48);
2000 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2001 speed_template_32_40_48);
2002 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2003 speed_template_32_48_64);
2004 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2005 speed_template_32_48_64);
2006 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2007 speed_template_16_24_32);
2008 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2009 speed_template_16_24_32);
2010 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2011 speed_template_16_24_32);
2012 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2013 speed_template_16_24_32);
2014 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2015 speed_template_16_24_32);
2016 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2017 speed_template_16_24_32);
2018 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
2019 speed_template_20_28_36);
2020 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
2021 speed_template_20_28_36);
2022 break;
2024 case 501:
2025 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2026 des3_speed_template, DES3_SPEED_VECTORS,
2027 speed_template_24);
2028 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
2029 des3_speed_template, DES3_SPEED_VECTORS,
2030 speed_template_24);
2031 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2032 des3_speed_template, DES3_SPEED_VECTORS,
2033 speed_template_24);
2034 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
2035 des3_speed_template, DES3_SPEED_VECTORS,
2036 speed_template_24);
2037 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2038 des3_speed_template, DES3_SPEED_VECTORS,
2039 speed_template_24);
2040 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
2041 des3_speed_template, DES3_SPEED_VECTORS,
2042 speed_template_24);
2043 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2044 des3_speed_template, DES3_SPEED_VECTORS,
2045 speed_template_24);
2046 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
2047 des3_speed_template, DES3_SPEED_VECTORS,
2048 speed_template_24);
2049 break;
2051 case 502:
2052 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2053 speed_template_8);
2054 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2055 speed_template_8);
2056 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2057 speed_template_8);
2058 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2059 speed_template_8);
2060 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2061 speed_template_8);
2062 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2063 speed_template_8);
2064 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2065 speed_template_8);
2066 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2067 speed_template_8);
2068 break;
2070 case 503:
2071 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2072 speed_template_16_32);
2073 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2074 speed_template_16_32);
2075 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2076 speed_template_16_32);
2077 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2078 speed_template_16_32);
2079 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2080 speed_template_16_32);
2081 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2082 speed_template_16_32);
2083 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2084 speed_template_32_48);
2085 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2086 speed_template_32_48);
2087 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2088 speed_template_32_64);
2089 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2090 speed_template_32_64);
2091 break;
2093 case 504:
2094 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2095 speed_template_16_24_32);
2096 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2097 speed_template_16_24_32);
2098 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2099 speed_template_16_24_32);
2100 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2101 speed_template_16_24_32);
2102 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2103 speed_template_16_24_32);
2104 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2105 speed_template_16_24_32);
2106 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2107 speed_template_32_40_48);
2108 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2109 speed_template_32_40_48);
2110 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2111 speed_template_32_48_64);
2112 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2113 speed_template_32_48_64);
2114 break;
2116 case 505:
2117 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2118 speed_template_8);
2119 break;
2121 case 506:
2122 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2123 speed_template_8_16);
2124 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2125 speed_template_8_16);
2126 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2127 speed_template_8_16);
2128 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2129 speed_template_8_16);
2130 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2131 speed_template_8_16);
2132 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2133 speed_template_8_16);
2134 break;
2136 case 507:
2137 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2138 speed_template_16_32);
2139 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2140 speed_template_16_32);
2141 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2142 speed_template_16_32);
2143 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2144 speed_template_16_32);
2145 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2146 speed_template_16_32);
2147 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2148 speed_template_16_32);
2149 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2150 speed_template_32_48);
2151 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2152 speed_template_32_48);
2153 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2154 speed_template_32_64);
2155 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2156 speed_template_32_64);
2157 break;
2159 case 508:
2160 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2161 speed_template_16_32);
2162 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2163 speed_template_16_32);
2164 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2165 speed_template_16_32);
2166 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2167 speed_template_16_32);
2168 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2169 speed_template_16_32);
2170 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2171 speed_template_16_32);
2172 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2173 speed_template_32_48);
2174 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2175 speed_template_32_48);
2176 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2177 speed_template_32_64);
2178 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2179 speed_template_32_64);
2180 break;
2182 case 509:
2183 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2184 speed_template_8_32);
2185 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2186 speed_template_8_32);
2187 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2188 speed_template_8_32);
2189 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2190 speed_template_8_32);
2191 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2192 speed_template_8_32);
2193 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2194 speed_template_8_32);
2195 break;
2197 case 1000:
2198 test_available();
2199 break;
2202 return ret;
2205 static int __init tcrypt_mod_init(void)
2207 int err = -ENOMEM;
2208 int i;
2210 for (i = 0; i < TVMEMSIZE; i++) {
2211 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
2212 if (!tvmem[i])
2213 goto err_free_tv;
2216 err = do_test(alg, type, mask, mode);
2218 if (err) {
2219 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
2220 goto err_free_tv;
2223 /* We intentionaly return -EAGAIN to prevent keeping the module,
2224 * unless we're running in fips mode. It does all its work from
2225 * init() and doesn't offer any runtime functionality, but in
2226 * the fips case, checking for a successful load is helpful.
2227 * => we don't need it in the memory, do we?
2228 * -- mludvig
2230 if (!fips_enabled)
2231 err = -EAGAIN;
2233 err_free_tv:
2234 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
2235 free_page((unsigned long)tvmem[i]);
2237 return err;
2241 * If an init function is provided, an exit function must also be provided
2242 * to allow module unload.
2244 static void __exit tcrypt_mod_fini(void) { }
2246 module_init(tcrypt_mod_init);
2247 module_exit(tcrypt_mod_fini);
2249 module_param(alg, charp, 0);
2250 module_param(type, uint, 0);
2251 module_param(mask, uint, 0);
2252 module_param(mode, int, 0);
2253 module_param(sec, uint, 0);
2254 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
2255 "(defaults to zero which uses CPU cycles instead)");
2257 MODULE_LICENSE("GPL");
2258 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2259 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");