crypto: testmgr - Add ctr(aes) test vectors
[GitHub/moto-9609/android_kernel_motorola_exynos9610.git] / crypto / tcrypt.c
1 /*
2 * Quick & dirty crypto testing module.
3 *
4 * This will only exist until we have a better testing mechanism
5 * (e.g. a char device).
6 *
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
10 *
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.
15 *
16 */
17
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
31 /*
32 * Need slab memory for testing (size in number of pages).
33 */
34 #define TVMEMSIZE 4
35
36 /*
37 * Used by test_cipher_speed()
38 */
39 #define ENCRYPT 1
40 #define DECRYPT 0
41
42 /*
43 * Used by test_cipher_speed()
44 */
45 static unsigned int sec;
46
47 static int mode;
48 static char *tvmem[TVMEMSIZE];
49
50 static char *check[] = {
51 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
52 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
53 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
54 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
55 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
56 "lzo", "cts", "zlib", NULL
57 };
58
59 static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc,
60 struct scatterlist *sg, int blen, int sec)
61 {
62 unsigned long start, end;
63 int bcount;
64 int ret;
65
66 for (start = jiffies, end = start + sec * HZ, bcount = 0;
67 time_before(jiffies, end); bcount++) {
68 if (enc)
69 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
70 else
71 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
72
73 if (ret)
74 return ret;
75 }
76
77 printk("%d operations in %d seconds (%ld bytes)\n",
78 bcount, sec, (long)bcount * blen);
79 return 0;
80 }
81
82 static int test_cipher_cycles(struct blkcipher_desc *desc, int enc,
83 struct scatterlist *sg, int blen)
84 {
85 unsigned long cycles = 0;
86 int ret = 0;
87 int i;
88
89 local_bh_disable();
90 local_irq_disable();
91
92 /* Warm-up run. */
93 for (i = 0; i < 4; i++) {
94 if (enc)
95 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
96 else
97 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
98
99 if (ret)
100 goto out;
101 }
102
103 /* The real thing. */
104 for (i = 0; i < 8; i++) {
105 cycles_t start, end;
106
107 start = get_cycles();
108 if (enc)
109 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
110 else
111 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
112 end = get_cycles();
113
114 if (ret)
115 goto out;
116
117 cycles += end - start;
118 }
119
120 out:
121 local_irq_enable();
122 local_bh_enable();
123
124 if (ret == 0)
125 printk("1 operation in %lu cycles (%d bytes)\n",
126 (cycles + 4) / 8, blen);
127
128 return ret;
129 }
130
131 static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
132
133 static void test_cipher_speed(const char *algo, int enc, unsigned int sec,
134 struct cipher_speed_template *template,
135 unsigned int tcount, u8 *keysize)
136 {
137 unsigned int ret, i, j, iv_len;
138 const char *key, iv[128];
139 struct crypto_blkcipher *tfm;
140 struct blkcipher_desc desc;
141 const char *e;
142 u32 *b_size;
143
144 if (enc == ENCRYPT)
145 e = "encryption";
146 else
147 e = "decryption";
148
149 printk("\ntesting speed of %s %s\n", algo, e);
150
151 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
152
153 if (IS_ERR(tfm)) {
154 printk("failed to load transform for %s: %ld\n", algo,
155 PTR_ERR(tfm));
156 return;
157 }
158 desc.tfm = tfm;
159 desc.flags = 0;
160
161 i = 0;
162 do {
163
164 b_size = block_sizes;
165 do {
166 struct scatterlist sg[TVMEMSIZE];
167
168 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
169 printk("template (%u) too big for "
170 "tvmem (%lu)\n", *keysize + *b_size,
171 TVMEMSIZE * PAGE_SIZE);
172 goto out;
173 }
174
175 printk("test %u (%d bit key, %d byte blocks): ", i,
176 *keysize * 8, *b_size);
177
178 memset(tvmem[0], 0xff, PAGE_SIZE);
179
180 /* set key, plain text and IV */
181 key = tvmem[0];
182 for (j = 0; j < tcount; j++) {
183 if (template[j].klen == *keysize) {
184 key = template[j].key;
185 break;
186 }
187 }
188
189 ret = crypto_blkcipher_setkey(tfm, key, *keysize);
190 if (ret) {
191 printk("setkey() failed flags=%x\n",
192 crypto_blkcipher_get_flags(tfm));
193 goto out;
194 }
195
196 sg_init_table(sg, TVMEMSIZE);
197 sg_set_buf(sg, tvmem[0] + *keysize,
198 PAGE_SIZE - *keysize);
199 for (j = 1; j < TVMEMSIZE; j++) {
200 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
201 memset (tvmem[j], 0xff, PAGE_SIZE);
202 }
203
204 iv_len = crypto_blkcipher_ivsize(tfm);
205 if (iv_len) {
206 memset(&iv, 0xff, iv_len);
207 crypto_blkcipher_set_iv(tfm, iv, iv_len);
208 }
209
210 if (sec)
211 ret = test_cipher_jiffies(&desc, enc, sg,
212 *b_size, sec);
213 else
214 ret = test_cipher_cycles(&desc, enc, sg,
215 *b_size);
216
217 if (ret) {
218 printk("%s() failed flags=%x\n", e, desc.flags);
219 break;
220 }
221 b_size++;
222 i++;
223 } while (*b_size);
224 keysize++;
225 } while (*keysize);
226
227 out:
228 crypto_free_blkcipher(tfm);
229 }
230
231 static int test_hash_jiffies_digest(struct hash_desc *desc,
232 struct scatterlist *sg, int blen,
233 char *out, int sec)
234 {
235 unsigned long start, end;
236 int bcount;
237 int ret;
238
239 for (start = jiffies, end = start + sec * HZ, bcount = 0;
240 time_before(jiffies, end); bcount++) {
241 ret = crypto_hash_digest(desc, sg, blen, out);
242 if (ret)
243 return ret;
244 }
245
246 printk("%6u opers/sec, %9lu bytes/sec\n",
247 bcount / sec, ((long)bcount * blen) / sec);
248
249 return 0;
250 }
251
252 static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg,
253 int blen, int plen, char *out, int sec)
254 {
255 unsigned long start, end;
256 int bcount, pcount;
257 int ret;
258
259 if (plen == blen)
260 return test_hash_jiffies_digest(desc, sg, blen, out, sec);
261
262 for (start = jiffies, end = start + sec * HZ, bcount = 0;
263 time_before(jiffies, end); bcount++) {
264 ret = crypto_hash_init(desc);
265 if (ret)
266 return ret;
267 for (pcount = 0; pcount < blen; pcount += plen) {
268 ret = crypto_hash_update(desc, sg, plen);
269 if (ret)
270 return ret;
271 }
272 /* we assume there is enough space in 'out' for the result */
273 ret = crypto_hash_final(desc, out);
274 if (ret)
275 return ret;
276 }
277
278 printk("%6u opers/sec, %9lu bytes/sec\n",
279 bcount / sec, ((long)bcount * blen) / sec);
280
281 return 0;
282 }
283
284 static int test_hash_cycles_digest(struct hash_desc *desc,
285 struct scatterlist *sg, int blen, char *out)
286 {
287 unsigned long cycles = 0;
288 int i;
289 int ret;
290
291 local_bh_disable();
292 local_irq_disable();
293
294 /* Warm-up run. */
295 for (i = 0; i < 4; i++) {
296 ret = crypto_hash_digest(desc, sg, blen, out);
297 if (ret)
298 goto out;
299 }
300
301 /* The real thing. */
302 for (i = 0; i < 8; i++) {
303 cycles_t start, end;
304
305 start = get_cycles();
306
307 ret = crypto_hash_digest(desc, sg, blen, out);
308 if (ret)
309 goto out;
310
311 end = get_cycles();
312
313 cycles += end - start;
314 }
315
316 out:
317 local_irq_enable();
318 local_bh_enable();
319
320 if (ret)
321 return ret;
322
323 printk("%6lu cycles/operation, %4lu cycles/byte\n",
324 cycles / 8, cycles / (8 * blen));
325
326 return 0;
327 }
328
329 static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg,
330 int blen, int plen, char *out)
331 {
332 unsigned long cycles = 0;
333 int i, pcount;
334 int ret;
335
336 if (plen == blen)
337 return test_hash_cycles_digest(desc, sg, blen, out);
338
339 local_bh_disable();
340 local_irq_disable();
341
342 /* Warm-up run. */
343 for (i = 0; i < 4; i++) {
344 ret = crypto_hash_init(desc);
345 if (ret)
346 goto out;
347 for (pcount = 0; pcount < blen; pcount += plen) {
348 ret = crypto_hash_update(desc, sg, plen);
349 if (ret)
350 goto out;
351 }
352 ret = crypto_hash_final(desc, out);
353 if (ret)
354 goto out;
355 }
356
357 /* The real thing. */
358 for (i = 0; i < 8; i++) {
359 cycles_t start, end;
360
361 start = get_cycles();
362
363 ret = crypto_hash_init(desc);
364 if (ret)
365 goto out;
366 for (pcount = 0; pcount < blen; pcount += plen) {
367 ret = crypto_hash_update(desc, sg, plen);
368 if (ret)
369 goto out;
370 }
371 ret = crypto_hash_final(desc, out);
372 if (ret)
373 goto out;
374
375 end = get_cycles();
376
377 cycles += end - start;
378 }
379
380 out:
381 local_irq_enable();
382 local_bh_enable();
383
384 if (ret)
385 return ret;
386
387 printk("%6lu cycles/operation, %4lu cycles/byte\n",
388 cycles / 8, cycles / (8 * blen));
389
390 return 0;
391 }
392
393 static void test_hash_speed(const char *algo, unsigned int sec,
394 struct hash_speed *speed)
395 {
396 struct scatterlist sg[TVMEMSIZE];
397 struct crypto_hash *tfm;
398 struct hash_desc desc;
399 static char output[1024];
400 int i;
401 int ret;
402
403 printk(KERN_INFO "\ntesting speed of %s\n", algo);
404
405 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
406
407 if (IS_ERR(tfm)) {
408 printk(KERN_ERR "failed to load transform for %s: %ld\n", algo,
409 PTR_ERR(tfm));
410 return;
411 }
412
413 desc.tfm = tfm;
414 desc.flags = 0;
415
416 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
417 printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n",
418 crypto_hash_digestsize(tfm), sizeof(output));
419 goto out;
420 }
421
422 sg_init_table(sg, TVMEMSIZE);
423 for (i = 0; i < TVMEMSIZE; i++) {
424 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
425 memset(tvmem[i], 0xff, PAGE_SIZE);
426 }
427
428 for (i = 0; speed[i].blen != 0; i++) {
429 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
430 printk(KERN_ERR
431 "template (%u) too big for tvmem (%lu)\n",
432 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
433 goto out;
434 }
435
436 printk(KERN_INFO "test%3u "
437 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
438 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
439
440 if (sec)
441 ret = test_hash_jiffies(&desc, sg, speed[i].blen,
442 speed[i].plen, output, sec);
443 else
444 ret = test_hash_cycles(&desc, sg, speed[i].blen,
445 speed[i].plen, output);
446
447 if (ret) {
448 printk(KERN_ERR "hashing failed ret=%d\n", ret);
449 break;
450 }
451 }
452
453 out:
454 crypto_free_hash(tfm);
455 }
456
457 static void test_available(void)
458 {
459 char **name = check;
460
461 while (*name) {
462 printk("alg %s ", *name);
463 printk(crypto_has_alg(*name, 0, 0) ?
464 "found\n" : "not found\n");
465 name++;
466 }
467 }
468
469 static inline int tcrypt_test(const char *alg)
470 {
471 return alg_test(alg, alg, 0, 0);
472 }
473
474 static void do_test(int m)
475 {
476 int i;
477
478 switch (m) {
479 case 0:
480 for (i = 1; i < 200; i++)
481 do_test(i);
482 break;
483
484 case 1:
485 tcrypt_test("md5");
486 break;
487
488 case 2:
489 tcrypt_test("sha1");
490 break;
491
492 case 3:
493 tcrypt_test("ecb(des)");
494 tcrypt_test("cbc(des)");
495 break;
496
497 case 4:
498 tcrypt_test("ecb(des3_ede)");
499 tcrypt_test("cbc(des3_ede)");
500 break;
501
502 case 5:
503 tcrypt_test("md4");
504 break;
505
506 case 6:
507 tcrypt_test("sha256");
508 break;
509
510 case 7:
511 tcrypt_test("ecb(blowfish)");
512 tcrypt_test("cbc(blowfish)");
513 break;
514
515 case 8:
516 tcrypt_test("ecb(twofish)");
517 tcrypt_test("cbc(twofish)");
518 break;
519
520 case 9:
521 tcrypt_test("ecb(serpent)");
522 break;
523
524 case 10:
525 tcrypt_test("ecb(aes)");
526 tcrypt_test("cbc(aes)");
527 tcrypt_test("lrw(aes)");
528 tcrypt_test("xts(aes)");
529 tcrypt_test("ctr(aes)");
530 tcrypt_test("rfc3686(ctr(aes))");
531 break;
532
533 case 11:
534 tcrypt_test("sha384");
535 break;
536
537 case 12:
538 tcrypt_test("sha512");
539 break;
540
541 case 13:
542 tcrypt_test("deflate");
543 break;
544
545 case 14:
546 tcrypt_test("ecb(cast5)");
547 break;
548
549 case 15:
550 tcrypt_test("ecb(cast6)");
551 break;
552
553 case 16:
554 tcrypt_test("ecb(arc4)");
555 break;
556
557 case 17:
558 tcrypt_test("michael_mic");
559 break;
560
561 case 18:
562 tcrypt_test("crc32c");
563 break;
564
565 case 19:
566 tcrypt_test("ecb(tea)");
567 break;
568
569 case 20:
570 tcrypt_test("ecb(xtea)");
571 break;
572
573 case 21:
574 tcrypt_test("ecb(khazad)");
575 break;
576
577 case 22:
578 tcrypt_test("wp512");
579 break;
580
581 case 23:
582 tcrypt_test("wp384");
583 break;
584
585 case 24:
586 tcrypt_test("wp256");
587 break;
588
589 case 25:
590 tcrypt_test("ecb(tnepres)");
591 break;
592
593 case 26:
594 tcrypt_test("ecb(anubis)");
595 tcrypt_test("cbc(anubis)");
596 break;
597
598 case 27:
599 tcrypt_test("tgr192");
600 break;
601
602 case 28:
603
604 tcrypt_test("tgr160");
605 break;
606
607 case 29:
608 tcrypt_test("tgr128");
609 break;
610
611 case 30:
612 tcrypt_test("ecb(xeta)");
613 break;
614
615 case 31:
616 tcrypt_test("pcbc(fcrypt)");
617 break;
618
619 case 32:
620 tcrypt_test("ecb(camellia)");
621 tcrypt_test("cbc(camellia)");
622 break;
623 case 33:
624 tcrypt_test("sha224");
625 break;
626
627 case 34:
628 tcrypt_test("salsa20");
629 break;
630
631 case 35:
632 tcrypt_test("gcm(aes)");
633 break;
634
635 case 36:
636 tcrypt_test("lzo");
637 break;
638
639 case 37:
640 tcrypt_test("ccm(aes)");
641 break;
642
643 case 38:
644 tcrypt_test("cts(cbc(aes))");
645 break;
646
647 case 39:
648 tcrypt_test("rmd128");
649 break;
650
651 case 40:
652 tcrypt_test("rmd160");
653 break;
654
655 case 41:
656 tcrypt_test("rmd256");
657 break;
658
659 case 42:
660 tcrypt_test("rmd320");
661 break;
662
663 case 43:
664 tcrypt_test("ecb(seed)");
665 break;
666
667 case 44:
668 tcrypt_test("zlib");
669 break;
670
671 case 45:
672 tcrypt_test("rfc4309(ccm(aes))");
673 break;
674
675 case 100:
676 tcrypt_test("hmac(md5)");
677 break;
678
679 case 101:
680 tcrypt_test("hmac(sha1)");
681 break;
682
683 case 102:
684 tcrypt_test("hmac(sha256)");
685 break;
686
687 case 103:
688 tcrypt_test("hmac(sha384)");
689 break;
690
691 case 104:
692 tcrypt_test("hmac(sha512)");
693 break;
694
695 case 105:
696 tcrypt_test("hmac(sha224)");
697 break;
698
699 case 106:
700 tcrypt_test("xcbc(aes)");
701 break;
702
703 case 107:
704 tcrypt_test("hmac(rmd128)");
705 break;
706
707 case 108:
708 tcrypt_test("hmac(rmd160)");
709 break;
710
711 case 150:
712 tcrypt_test("ansi_cprng");
713 break;
714
715 case 200:
716 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
717 speed_template_16_24_32);
718 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
719 speed_template_16_24_32);
720 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
721 speed_template_16_24_32);
722 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
723 speed_template_16_24_32);
724 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
725 speed_template_32_40_48);
726 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
727 speed_template_32_40_48);
728 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
729 speed_template_32_48_64);
730 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
731 speed_template_32_48_64);
732 break;
733
734 case 201:
735 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
736 des3_speed_template, DES3_SPEED_VECTORS,
737 speed_template_24);
738 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
739 des3_speed_template, DES3_SPEED_VECTORS,
740 speed_template_24);
741 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
742 des3_speed_template, DES3_SPEED_VECTORS,
743 speed_template_24);
744 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
745 des3_speed_template, DES3_SPEED_VECTORS,
746 speed_template_24);
747 break;
748
749 case 202:
750 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
751 speed_template_16_24_32);
752 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
753 speed_template_16_24_32);
754 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
755 speed_template_16_24_32);
756 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
757 speed_template_16_24_32);
758 break;
759
760 case 203:
761 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
762 speed_template_8_32);
763 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
764 speed_template_8_32);
765 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
766 speed_template_8_32);
767 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
768 speed_template_8_32);
769 break;
770
771 case 204:
772 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
773 speed_template_8);
774 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
775 speed_template_8);
776 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
777 speed_template_8);
778 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
779 speed_template_8);
780 break;
781
782 case 205:
783 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
784 speed_template_16_24_32);
785 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
786 speed_template_16_24_32);
787 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
788 speed_template_16_24_32);
789 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
790 speed_template_16_24_32);
791 break;
792
793 case 206:
794 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
795 speed_template_16_32);
796 break;
797
798 case 300:
799 /* fall through */
800
801 case 301:
802 test_hash_speed("md4", sec, generic_hash_speed_template);
803 if (mode > 300 && mode < 400) break;
804
805 case 302:
806 test_hash_speed("md5", sec, generic_hash_speed_template);
807 if (mode > 300 && mode < 400) break;
808
809 case 303:
810 test_hash_speed("sha1", sec, generic_hash_speed_template);
811 if (mode > 300 && mode < 400) break;
812
813 case 304:
814 test_hash_speed("sha256", sec, generic_hash_speed_template);
815 if (mode > 300 && mode < 400) break;
816
817 case 305:
818 test_hash_speed("sha384", sec, generic_hash_speed_template);
819 if (mode > 300 && mode < 400) break;
820
821 case 306:
822 test_hash_speed("sha512", sec, generic_hash_speed_template);
823 if (mode > 300 && mode < 400) break;
824
825 case 307:
826 test_hash_speed("wp256", sec, generic_hash_speed_template);
827 if (mode > 300 && mode < 400) break;
828
829 case 308:
830 test_hash_speed("wp384", sec, generic_hash_speed_template);
831 if (mode > 300 && mode < 400) break;
832
833 case 309:
834 test_hash_speed("wp512", sec, generic_hash_speed_template);
835 if (mode > 300 && mode < 400) break;
836
837 case 310:
838 test_hash_speed("tgr128", sec, generic_hash_speed_template);
839 if (mode > 300 && mode < 400) break;
840
841 case 311:
842 test_hash_speed("tgr160", sec, generic_hash_speed_template);
843 if (mode > 300 && mode < 400) break;
844
845 case 312:
846 test_hash_speed("tgr192", sec, generic_hash_speed_template);
847 if (mode > 300 && mode < 400) break;
848
849 case 313:
850 test_hash_speed("sha224", sec, generic_hash_speed_template);
851 if (mode > 300 && mode < 400) break;
852
853 case 314:
854 test_hash_speed("rmd128", sec, generic_hash_speed_template);
855 if (mode > 300 && mode < 400) break;
856
857 case 315:
858 test_hash_speed("rmd160", sec, generic_hash_speed_template);
859 if (mode > 300 && mode < 400) break;
860
861 case 316:
862 test_hash_speed("rmd256", sec, generic_hash_speed_template);
863 if (mode > 300 && mode < 400) break;
864
865 case 317:
866 test_hash_speed("rmd320", sec, generic_hash_speed_template);
867 if (mode > 300 && mode < 400) break;
868
869 case 399:
870 break;
871
872 case 1000:
873 test_available();
874 break;
875 }
876 }
877
878 static int __init tcrypt_mod_init(void)
879 {
880 int err = -ENOMEM;
881 int i;
882
883 for (i = 0; i < TVMEMSIZE; i++) {
884 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
885 if (!tvmem[i])
886 goto err_free_tv;
887 }
888
889 do_test(mode);
890
891 /* We intentionaly return -EAGAIN to prevent keeping
892 * the module. It does all its work from init()
893 * and doesn't offer any runtime functionality
894 * => we don't need it in the memory, do we?
895 * -- mludvig
896 */
897 err = -EAGAIN;
898
899 err_free_tv:
900 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
901 free_page((unsigned long)tvmem[i]);
902
903 return err;
904 }
905
906 /*
907 * If an init function is provided, an exit function must also be provided
908 * to allow module unload.
909 */
910 static void __exit tcrypt_mod_fini(void) { }
911
912 module_init(tcrypt_mod_init);
913 module_exit(tcrypt_mod_fini);
914
915 module_param(mode, int, 0);
916 module_param(sec, uint, 0);
917 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
918 "(defaults to zero which uses CPU cycles instead)");
919
920 MODULE_LICENSE("GPL");
921 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
922 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");