drm/i915: FIFO watermark calculation fixes
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / crypto / tcrypt.c
blobd59ba5079d14617a51554b5042ea7a10f5ab8235
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 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License, or (at your option)
14 * any later version.
18 #include <crypto/hash.h>
19 #include <linux/err.h>
20 #include <linux/init.h>
21 #include <linux/module.h>
22 #include <linux/slab.h>
23 #include <linux/scatterlist.h>
24 #include <linux/string.h>
25 #include <linux/moduleparam.h>
26 #include <linux/jiffies.h>
27 #include <linux/timex.h>
28 #include <linux/interrupt.h>
29 #include "tcrypt.h"
30 #include "internal.h"
33 * Need slab memory for testing (size in number of pages).
35 #define TVMEMSIZE 4
38 * Used by test_cipher_speed()
40 #define ENCRYPT 1
41 #define DECRYPT 0
44 * Used by test_cipher_speed()
46 static unsigned int sec;
48 static int mode;
49 static char *tvmem[TVMEMSIZE];
51 static char *check[] = {
52 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
53 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
54 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
55 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
56 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
57 "lzo", "cts", "zlib", NULL
60 static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc,
61 struct scatterlist *sg, int blen, int sec)
63 unsigned long start, end;
64 int bcount;
65 int ret;
67 for (start = jiffies, end = start + sec * HZ, bcount = 0;
68 time_before(jiffies, end); bcount++) {
69 if (enc)
70 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
71 else
72 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
74 if (ret)
75 return ret;
78 printk("%d operations in %d seconds (%ld bytes)\n",
79 bcount, sec, (long)bcount * blen);
80 return 0;
83 static int test_cipher_cycles(struct blkcipher_desc *desc, int enc,
84 struct scatterlist *sg, int blen)
86 unsigned long cycles = 0;
87 int ret = 0;
88 int i;
90 local_bh_disable();
91 local_irq_disable();
93 /* Warm-up run. */
94 for (i = 0; i < 4; i++) {
95 if (enc)
96 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
97 else
98 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
100 if (ret)
101 goto out;
104 /* The real thing. */
105 for (i = 0; i < 8; i++) {
106 cycles_t start, end;
108 start = get_cycles();
109 if (enc)
110 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
111 else
112 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
113 end = get_cycles();
115 if (ret)
116 goto out;
118 cycles += end - start;
121 out:
122 local_irq_enable();
123 local_bh_enable();
125 if (ret == 0)
126 printk("1 operation in %lu cycles (%d bytes)\n",
127 (cycles + 4) / 8, blen);
129 return ret;
132 static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
134 static void test_cipher_speed(const char *algo, int enc, unsigned int sec,
135 struct cipher_speed_template *template,
136 unsigned int tcount, u8 *keysize)
138 unsigned int ret, i, j, iv_len;
139 const char *key, iv[128];
140 struct crypto_blkcipher *tfm;
141 struct blkcipher_desc desc;
142 const char *e;
143 u32 *b_size;
145 if (enc == ENCRYPT)
146 e = "encryption";
147 else
148 e = "decryption";
150 printk("\ntesting speed of %s %s\n", algo, e);
152 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
154 if (IS_ERR(tfm)) {
155 printk("failed to load transform for %s: %ld\n", algo,
156 PTR_ERR(tfm));
157 return;
159 desc.tfm = tfm;
160 desc.flags = 0;
162 i = 0;
163 do {
165 b_size = block_sizes;
166 do {
167 struct scatterlist sg[TVMEMSIZE];
169 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
170 printk("template (%u) too big for "
171 "tvmem (%lu)\n", *keysize + *b_size,
172 TVMEMSIZE * PAGE_SIZE);
173 goto out;
176 printk("test %u (%d bit key, %d byte blocks): ", i,
177 *keysize * 8, *b_size);
179 memset(tvmem[0], 0xff, PAGE_SIZE);
181 /* set key, plain text and IV */
182 key = tvmem[0];
183 for (j = 0; j < tcount; j++) {
184 if (template[j].klen == *keysize) {
185 key = template[j].key;
186 break;
190 ret = crypto_blkcipher_setkey(tfm, key, *keysize);
191 if (ret) {
192 printk("setkey() failed flags=%x\n",
193 crypto_blkcipher_get_flags(tfm));
194 goto out;
197 sg_init_table(sg, TVMEMSIZE);
198 sg_set_buf(sg, tvmem[0] + *keysize,
199 PAGE_SIZE - *keysize);
200 for (j = 1; j < TVMEMSIZE; j++) {
201 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
202 memset (tvmem[j], 0xff, PAGE_SIZE);
205 iv_len = crypto_blkcipher_ivsize(tfm);
206 if (iv_len) {
207 memset(&iv, 0xff, iv_len);
208 crypto_blkcipher_set_iv(tfm, iv, iv_len);
211 if (sec)
212 ret = test_cipher_jiffies(&desc, enc, sg,
213 *b_size, sec);
214 else
215 ret = test_cipher_cycles(&desc, enc, sg,
216 *b_size);
218 if (ret) {
219 printk("%s() failed flags=%x\n", e, desc.flags);
220 break;
222 b_size++;
223 i++;
224 } while (*b_size);
225 keysize++;
226 } while (*keysize);
228 out:
229 crypto_free_blkcipher(tfm);
232 static int test_hash_jiffies_digest(struct hash_desc *desc,
233 struct scatterlist *sg, int blen,
234 char *out, int sec)
236 unsigned long start, end;
237 int bcount;
238 int ret;
240 for (start = jiffies, end = start + sec * HZ, bcount = 0;
241 time_before(jiffies, end); bcount++) {
242 ret = crypto_hash_digest(desc, sg, blen, out);
243 if (ret)
244 return ret;
247 printk("%6u opers/sec, %9lu bytes/sec\n",
248 bcount / sec, ((long)bcount * blen) / sec);
250 return 0;
253 static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg,
254 int blen, int plen, char *out, int sec)
256 unsigned long start, end;
257 int bcount, pcount;
258 int ret;
260 if (plen == blen)
261 return test_hash_jiffies_digest(desc, sg, blen, out, sec);
263 for (start = jiffies, end = start + sec * HZ, bcount = 0;
264 time_before(jiffies, end); bcount++) {
265 ret = crypto_hash_init(desc);
266 if (ret)
267 return ret;
268 for (pcount = 0; pcount < blen; pcount += plen) {
269 ret = crypto_hash_update(desc, sg, plen);
270 if (ret)
271 return ret;
273 /* we assume there is enough space in 'out' for the result */
274 ret = crypto_hash_final(desc, out);
275 if (ret)
276 return ret;
279 printk("%6u opers/sec, %9lu bytes/sec\n",
280 bcount / sec, ((long)bcount * blen) / sec);
282 return 0;
285 static int test_hash_cycles_digest(struct hash_desc *desc,
286 struct scatterlist *sg, int blen, char *out)
288 unsigned long cycles = 0;
289 int i;
290 int ret;
292 local_bh_disable();
293 local_irq_disable();
295 /* Warm-up run. */
296 for (i = 0; i < 4; i++) {
297 ret = crypto_hash_digest(desc, sg, blen, out);
298 if (ret)
299 goto out;
302 /* The real thing. */
303 for (i = 0; i < 8; i++) {
304 cycles_t start, end;
306 start = get_cycles();
308 ret = crypto_hash_digest(desc, sg, blen, out);
309 if (ret)
310 goto out;
312 end = get_cycles();
314 cycles += end - start;
317 out:
318 local_irq_enable();
319 local_bh_enable();
321 if (ret)
322 return ret;
324 printk("%6lu cycles/operation, %4lu cycles/byte\n",
325 cycles / 8, cycles / (8 * blen));
327 return 0;
330 static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg,
331 int blen, int plen, char *out)
333 unsigned long cycles = 0;
334 int i, pcount;
335 int ret;
337 if (plen == blen)
338 return test_hash_cycles_digest(desc, sg, blen, out);
340 local_bh_disable();
341 local_irq_disable();
343 /* Warm-up run. */
344 for (i = 0; i < 4; i++) {
345 ret = crypto_hash_init(desc);
346 if (ret)
347 goto out;
348 for (pcount = 0; pcount < blen; pcount += plen) {
349 ret = crypto_hash_update(desc, sg, plen);
350 if (ret)
351 goto out;
353 ret = crypto_hash_final(desc, out);
354 if (ret)
355 goto out;
358 /* The real thing. */
359 for (i = 0; i < 8; i++) {
360 cycles_t start, end;
362 start = get_cycles();
364 ret = crypto_hash_init(desc);
365 if (ret)
366 goto out;
367 for (pcount = 0; pcount < blen; pcount += plen) {
368 ret = crypto_hash_update(desc, sg, plen);
369 if (ret)
370 goto out;
372 ret = crypto_hash_final(desc, out);
373 if (ret)
374 goto out;
376 end = get_cycles();
378 cycles += end - start;
381 out:
382 local_irq_enable();
383 local_bh_enable();
385 if (ret)
386 return ret;
388 printk("%6lu cycles/operation, %4lu cycles/byte\n",
389 cycles / 8, cycles / (8 * blen));
391 return 0;
394 static void test_hash_speed(const char *algo, unsigned int sec,
395 struct hash_speed *speed)
397 struct scatterlist sg[TVMEMSIZE];
398 struct crypto_hash *tfm;
399 struct hash_desc desc;
400 static char output[1024];
401 int i;
402 int ret;
404 printk(KERN_INFO "\ntesting speed of %s\n", algo);
406 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
408 if (IS_ERR(tfm)) {
409 printk(KERN_ERR "failed to load transform for %s: %ld\n", algo,
410 PTR_ERR(tfm));
411 return;
414 desc.tfm = tfm;
415 desc.flags = 0;
417 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
418 printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n",
419 crypto_hash_digestsize(tfm), sizeof(output));
420 goto out;
423 sg_init_table(sg, TVMEMSIZE);
424 for (i = 0; i < TVMEMSIZE; i++) {
425 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
426 memset(tvmem[i], 0xff, PAGE_SIZE);
429 for (i = 0; speed[i].blen != 0; i++) {
430 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
431 printk(KERN_ERR
432 "template (%u) too big for tvmem (%lu)\n",
433 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
434 goto out;
437 printk(KERN_INFO "test%3u "
438 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
439 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
441 if (sec)
442 ret = test_hash_jiffies(&desc, sg, speed[i].blen,
443 speed[i].plen, output, sec);
444 else
445 ret = test_hash_cycles(&desc, sg, speed[i].blen,
446 speed[i].plen, output);
448 if (ret) {
449 printk(KERN_ERR "hashing failed ret=%d\n", ret);
450 break;
454 out:
455 crypto_free_hash(tfm);
458 static void test_available(void)
460 char **name = check;
462 while (*name) {
463 printk("alg %s ", *name);
464 printk(crypto_has_alg(*name, 0, 0) ?
465 "found\n" : "not found\n");
466 name++;
470 static inline int tcrypt_test(const char *alg)
472 int ret;
474 ret = alg_test(alg, alg, 0, 0);
475 /* non-fips algs return -EINVAL in fips mode */
476 if (fips_enabled && ret == -EINVAL)
477 ret = 0;
478 return ret;
481 static int do_test(int m)
483 int i;
484 int ret = 0;
486 switch (m) {
487 case 0:
488 for (i = 1; i < 200; i++)
489 ret += do_test(i);
490 break;
492 case 1:
493 ret += tcrypt_test("md5");
494 break;
496 case 2:
497 ret += tcrypt_test("sha1");
498 break;
500 case 3:
501 ret += tcrypt_test("ecb(des)");
502 ret += tcrypt_test("cbc(des)");
503 break;
505 case 4:
506 ret += tcrypt_test("ecb(des3_ede)");
507 ret += tcrypt_test("cbc(des3_ede)");
508 break;
510 case 5:
511 ret += tcrypt_test("md4");
512 break;
514 case 6:
515 ret += tcrypt_test("sha256");
516 break;
518 case 7:
519 ret += tcrypt_test("ecb(blowfish)");
520 ret += tcrypt_test("cbc(blowfish)");
521 break;
523 case 8:
524 ret += tcrypt_test("ecb(twofish)");
525 ret += tcrypt_test("cbc(twofish)");
526 break;
528 case 9:
529 ret += tcrypt_test("ecb(serpent)");
530 break;
532 case 10:
533 ret += tcrypt_test("ecb(aes)");
534 ret += tcrypt_test("cbc(aes)");
535 ret += tcrypt_test("lrw(aes)");
536 ret += tcrypt_test("xts(aes)");
537 ret += tcrypt_test("ctr(aes)");
538 ret += tcrypt_test("rfc3686(ctr(aes))");
539 break;
541 case 11:
542 ret += tcrypt_test("sha384");
543 break;
545 case 12:
546 ret += tcrypt_test("sha512");
547 break;
549 case 13:
550 ret += tcrypt_test("deflate");
551 break;
553 case 14:
554 ret += tcrypt_test("ecb(cast5)");
555 break;
557 case 15:
558 ret += tcrypt_test("ecb(cast6)");
559 break;
561 case 16:
562 ret += tcrypt_test("ecb(arc4)");
563 break;
565 case 17:
566 ret += tcrypt_test("michael_mic");
567 break;
569 case 18:
570 ret += tcrypt_test("crc32c");
571 break;
573 case 19:
574 ret += tcrypt_test("ecb(tea)");
575 break;
577 case 20:
578 ret += tcrypt_test("ecb(xtea)");
579 break;
581 case 21:
582 ret += tcrypt_test("ecb(khazad)");
583 break;
585 case 22:
586 ret += tcrypt_test("wp512");
587 break;
589 case 23:
590 ret += tcrypt_test("wp384");
591 break;
593 case 24:
594 ret += tcrypt_test("wp256");
595 break;
597 case 25:
598 ret += tcrypt_test("ecb(tnepres)");
599 break;
601 case 26:
602 ret += tcrypt_test("ecb(anubis)");
603 ret += tcrypt_test("cbc(anubis)");
604 break;
606 case 27:
607 ret += tcrypt_test("tgr192");
608 break;
610 case 28:
612 ret += tcrypt_test("tgr160");
613 break;
615 case 29:
616 ret += tcrypt_test("tgr128");
617 break;
619 case 30:
620 ret += tcrypt_test("ecb(xeta)");
621 break;
623 case 31:
624 ret += tcrypt_test("pcbc(fcrypt)");
625 break;
627 case 32:
628 ret += tcrypt_test("ecb(camellia)");
629 ret += tcrypt_test("cbc(camellia)");
630 break;
631 case 33:
632 ret += tcrypt_test("sha224");
633 break;
635 case 34:
636 ret += tcrypt_test("salsa20");
637 break;
639 case 35:
640 ret += tcrypt_test("gcm(aes)");
641 break;
643 case 36:
644 ret += tcrypt_test("lzo");
645 break;
647 case 37:
648 ret += tcrypt_test("ccm(aes)");
649 break;
651 case 38:
652 ret += tcrypt_test("cts(cbc(aes))");
653 break;
655 case 39:
656 ret += tcrypt_test("rmd128");
657 break;
659 case 40:
660 ret += tcrypt_test("rmd160");
661 break;
663 case 41:
664 ret += tcrypt_test("rmd256");
665 break;
667 case 42:
668 ret += tcrypt_test("rmd320");
669 break;
671 case 43:
672 ret += tcrypt_test("ecb(seed)");
673 break;
675 case 44:
676 ret += tcrypt_test("zlib");
677 break;
679 case 45:
680 ret += tcrypt_test("rfc4309(ccm(aes))");
681 break;
683 case 100:
684 ret += tcrypt_test("hmac(md5)");
685 break;
687 case 101:
688 ret += tcrypt_test("hmac(sha1)");
689 break;
691 case 102:
692 ret += tcrypt_test("hmac(sha256)");
693 break;
695 case 103:
696 ret += tcrypt_test("hmac(sha384)");
697 break;
699 case 104:
700 ret += tcrypt_test("hmac(sha512)");
701 break;
703 case 105:
704 ret += tcrypt_test("hmac(sha224)");
705 break;
707 case 106:
708 ret += tcrypt_test("xcbc(aes)");
709 break;
711 case 107:
712 ret += tcrypt_test("hmac(rmd128)");
713 break;
715 case 108:
716 ret += tcrypt_test("hmac(rmd160)");
717 break;
719 case 150:
720 ret += tcrypt_test("ansi_cprng");
721 break;
723 case 200:
724 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
725 speed_template_16_24_32);
726 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
727 speed_template_16_24_32);
728 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
729 speed_template_16_24_32);
730 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
731 speed_template_16_24_32);
732 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
733 speed_template_32_40_48);
734 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
735 speed_template_32_40_48);
736 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
737 speed_template_32_48_64);
738 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
739 speed_template_32_48_64);
740 break;
742 case 201:
743 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
744 des3_speed_template, DES3_SPEED_VECTORS,
745 speed_template_24);
746 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
747 des3_speed_template, DES3_SPEED_VECTORS,
748 speed_template_24);
749 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
750 des3_speed_template, DES3_SPEED_VECTORS,
751 speed_template_24);
752 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
753 des3_speed_template, DES3_SPEED_VECTORS,
754 speed_template_24);
755 break;
757 case 202:
758 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
759 speed_template_16_24_32);
760 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
761 speed_template_16_24_32);
762 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
763 speed_template_16_24_32);
764 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
765 speed_template_16_24_32);
766 break;
768 case 203:
769 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
770 speed_template_8_32);
771 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
772 speed_template_8_32);
773 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
774 speed_template_8_32);
775 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
776 speed_template_8_32);
777 break;
779 case 204:
780 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
781 speed_template_8);
782 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
783 speed_template_8);
784 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
785 speed_template_8);
786 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
787 speed_template_8);
788 break;
790 case 205:
791 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
792 speed_template_16_24_32);
793 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
794 speed_template_16_24_32);
795 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
796 speed_template_16_24_32);
797 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
798 speed_template_16_24_32);
799 break;
801 case 206:
802 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
803 speed_template_16_32);
804 break;
806 case 300:
807 /* fall through */
809 case 301:
810 test_hash_speed("md4", sec, generic_hash_speed_template);
811 if (mode > 300 && mode < 400) break;
813 case 302:
814 test_hash_speed("md5", sec, generic_hash_speed_template);
815 if (mode > 300 && mode < 400) break;
817 case 303:
818 test_hash_speed("sha1", sec, generic_hash_speed_template);
819 if (mode > 300 && mode < 400) break;
821 case 304:
822 test_hash_speed("sha256", sec, generic_hash_speed_template);
823 if (mode > 300 && mode < 400) break;
825 case 305:
826 test_hash_speed("sha384", sec, generic_hash_speed_template);
827 if (mode > 300 && mode < 400) break;
829 case 306:
830 test_hash_speed("sha512", sec, generic_hash_speed_template);
831 if (mode > 300 && mode < 400) break;
833 case 307:
834 test_hash_speed("wp256", sec, generic_hash_speed_template);
835 if (mode > 300 && mode < 400) break;
837 case 308:
838 test_hash_speed("wp384", sec, generic_hash_speed_template);
839 if (mode > 300 && mode < 400) break;
841 case 309:
842 test_hash_speed("wp512", sec, generic_hash_speed_template);
843 if (mode > 300 && mode < 400) break;
845 case 310:
846 test_hash_speed("tgr128", sec, generic_hash_speed_template);
847 if (mode > 300 && mode < 400) break;
849 case 311:
850 test_hash_speed("tgr160", sec, generic_hash_speed_template);
851 if (mode > 300 && mode < 400) break;
853 case 312:
854 test_hash_speed("tgr192", sec, generic_hash_speed_template);
855 if (mode > 300 && mode < 400) break;
857 case 313:
858 test_hash_speed("sha224", sec, generic_hash_speed_template);
859 if (mode > 300 && mode < 400) break;
861 case 314:
862 test_hash_speed("rmd128", sec, generic_hash_speed_template);
863 if (mode > 300 && mode < 400) break;
865 case 315:
866 test_hash_speed("rmd160", sec, generic_hash_speed_template);
867 if (mode > 300 && mode < 400) break;
869 case 316:
870 test_hash_speed("rmd256", sec, generic_hash_speed_template);
871 if (mode > 300 && mode < 400) break;
873 case 317:
874 test_hash_speed("rmd320", sec, generic_hash_speed_template);
875 if (mode > 300 && mode < 400) break;
877 case 399:
878 break;
880 case 1000:
881 test_available();
882 break;
885 return ret;
888 static int __init tcrypt_mod_init(void)
890 int err = -ENOMEM;
891 int i;
893 for (i = 0; i < TVMEMSIZE; i++) {
894 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
895 if (!tvmem[i])
896 goto err_free_tv;
899 err = do_test(mode);
900 if (err) {
901 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
902 goto err_free_tv;
905 /* We intentionaly return -EAGAIN to prevent keeping the module,
906 * unless we're running in fips mode. It does all its work from
907 * init() and doesn't offer any runtime functionality, but in
908 * the fips case, checking for a successful load is helpful.
909 * => we don't need it in the memory, do we?
910 * -- mludvig
912 if (!fips_enabled)
913 err = -EAGAIN;
915 err_free_tv:
916 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
917 free_page((unsigned long)tvmem[i]);
919 return err;
923 * If an init function is provided, an exit function must also be provided
924 * to allow module unload.
926 static void __exit tcrypt_mod_fini(void) { }
928 module_init(tcrypt_mod_init);
929 module_exit(tcrypt_mod_fini);
931 module_param(mode, int, 0);
932 module_param(sec, uint, 0);
933 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
934 "(defaults to zero which uses CPU cycles instead)");
936 MODULE_LICENSE("GPL");
937 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
938 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");