[CRYPTO] api: Get rid of flags argument to setkey
[linux-2.6.git] / crypto / tcrypt.c
blob60677707467174c75de8cffd09ecd7149b8d9802
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>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
13 * any later version.
15 * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>)
16 * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt
20 #include <linux/init.h>
21 #include <linux/module.h>
22 #include <linux/mm.h>
23 #include <linux/slab.h>
24 #include <linux/scatterlist.h>
25 #include <linux/string.h>
26 #include <linux/crypto.h>
27 #include <linux/highmem.h>
28 #include <linux/moduleparam.h>
29 #include <linux/jiffies.h>
30 #include <linux/timex.h>
31 #include <linux/interrupt.h>
32 #include "tcrypt.h"
35 * Need to kmalloc() memory for testing kmap().
37 #define TVMEMSIZE 16384
38 #define XBUFSIZE 32768
41 * Indexes into the xbuf to simulate cross-page access.
43 #define IDX1 37
44 #define IDX2 32400
45 #define IDX3 1
46 #define IDX4 8193
47 #define IDX5 22222
48 #define IDX6 17101
49 #define IDX7 27333
50 #define IDX8 3000
53 * Used by test_cipher()
55 #define ENCRYPT 1
56 #define DECRYPT 0
57 #define MODE_ECB 1
58 #define MODE_CBC 0
60 static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
63 * Used by test_cipher_speed()
65 static unsigned int sec;
67 static int mode;
68 static char *xbuf;
69 static char *tvmem;
71 static char *check[] = {
72 "des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish",
73 "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6",
74 "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
75 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", NULL
78 static void hexdump(unsigned char *buf, unsigned int len)
80 while (len--)
81 printk("%02x", *buf++);
83 printk("\n");
86 static void test_hash(char *algo, struct hash_testvec *template,
87 unsigned int tcount)
89 unsigned int i, j, k, temp;
90 struct scatterlist sg[8];
91 char result[64];
92 struct crypto_tfm *tfm;
93 struct hash_testvec *hash_tv;
94 unsigned int tsize;
96 printk("\ntesting %s\n", algo);
98 tsize = sizeof(struct hash_testvec);
99 tsize *= tcount;
101 if (tsize > TVMEMSIZE) {
102 printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE);
103 return;
106 memcpy(tvmem, template, tsize);
107 hash_tv = (void *)tvmem;
108 tfm = crypto_alloc_tfm(algo, 0);
109 if (tfm == NULL) {
110 printk("failed to load transform for %s\n", algo);
111 return;
114 for (i = 0; i < tcount; i++) {
115 printk("test %u:\n", i + 1);
116 memset(result, 0, 64);
118 sg_set_buf(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize);
120 crypto_digest_init(tfm);
121 crypto_digest_setkey(tfm, hash_tv[i].key, hash_tv[i].ksize);
122 crypto_digest_update(tfm, sg, 1);
123 crypto_digest_final(tfm, result);
125 hexdump(result, crypto_tfm_alg_digestsize(tfm));
126 printk("%s\n",
127 memcmp(result, hash_tv[i].digest,
128 crypto_tfm_alg_digestsize(tfm)) ?
129 "fail" : "pass");
132 printk("testing %s across pages\n", algo);
134 /* setup the dummy buffer first */
135 memset(xbuf, 0, XBUFSIZE);
137 j = 0;
138 for (i = 0; i < tcount; i++) {
139 if (hash_tv[i].np) {
140 j++;
141 printk("test %u:\n", j);
142 memset(result, 0, 64);
144 temp = 0;
145 for (k = 0; k < hash_tv[i].np; k++) {
146 memcpy(&xbuf[IDX[k]],
147 hash_tv[i].plaintext + temp,
148 hash_tv[i].tap[k]);
149 temp += hash_tv[i].tap[k];
150 sg_set_buf(&sg[k], &xbuf[IDX[k]],
151 hash_tv[i].tap[k]);
154 crypto_digest_digest(tfm, sg, hash_tv[i].np, result);
156 hexdump(result, crypto_tfm_alg_digestsize(tfm));
157 printk("%s\n",
158 memcmp(result, hash_tv[i].digest,
159 crypto_tfm_alg_digestsize(tfm)) ?
160 "fail" : "pass");
164 crypto_free_tfm(tfm);
168 #ifdef CONFIG_CRYPTO_HMAC
170 static void test_hmac(char *algo, struct hmac_testvec *template,
171 unsigned int tcount)
173 unsigned int i, j, k, temp;
174 struct scatterlist sg[8];
175 char result[64];
176 struct crypto_tfm *tfm;
177 struct hmac_testvec *hmac_tv;
178 unsigned int tsize, klen;
180 tfm = crypto_alloc_tfm(algo, 0);
181 if (tfm == NULL) {
182 printk("failed to load transform for %s\n", algo);
183 return;
186 printk("\ntesting hmac_%s\n", algo);
188 tsize = sizeof(struct hmac_testvec);
189 tsize *= tcount;
190 if (tsize > TVMEMSIZE) {
191 printk("template (%u) too big for tvmem (%u)\n", tsize,
192 TVMEMSIZE);
193 goto out;
196 memcpy(tvmem, template, tsize);
197 hmac_tv = (void *)tvmem;
199 for (i = 0; i < tcount; i++) {
200 printk("test %u:\n", i + 1);
201 memset(result, 0, sizeof (result));
203 klen = hmac_tv[i].ksize;
204 sg_set_buf(&sg[0], hmac_tv[i].plaintext, hmac_tv[i].psize);
206 crypto_hmac(tfm, hmac_tv[i].key, &klen, sg, 1, result);
208 hexdump(result, crypto_tfm_alg_digestsize(tfm));
209 printk("%s\n",
210 memcmp(result, hmac_tv[i].digest,
211 crypto_tfm_alg_digestsize(tfm)) ? "fail" :
212 "pass");
215 printk("\ntesting hmac_%s across pages\n", algo);
217 memset(xbuf, 0, XBUFSIZE);
219 j = 0;
220 for (i = 0; i < tcount; i++) {
221 if (hmac_tv[i].np) {
222 j++;
223 printk("test %u:\n",j);
224 memset(result, 0, 64);
226 temp = 0;
227 klen = hmac_tv[i].ksize;
228 for (k = 0; k < hmac_tv[i].np; k++) {
229 memcpy(&xbuf[IDX[k]],
230 hmac_tv[i].plaintext + temp,
231 hmac_tv[i].tap[k]);
232 temp += hmac_tv[i].tap[k];
233 sg_set_buf(&sg[k], &xbuf[IDX[k]],
234 hmac_tv[i].tap[k]);
237 crypto_hmac(tfm, hmac_tv[i].key, &klen, sg,
238 hmac_tv[i].np, result);
239 hexdump(result, crypto_tfm_alg_digestsize(tfm));
241 printk("%s\n",
242 memcmp(result, hmac_tv[i].digest,
243 crypto_tfm_alg_digestsize(tfm)) ?
244 "fail" : "pass");
247 out:
248 crypto_free_tfm(tfm);
251 #endif /* CONFIG_CRYPTO_HMAC */
253 static void test_cipher(char *algo, int mode, int enc,
254 struct cipher_testvec *template, unsigned int tcount)
256 unsigned int ret, i, j, k, temp;
257 unsigned int tsize;
258 char *q;
259 struct crypto_tfm *tfm;
260 char *key;
261 struct cipher_testvec *cipher_tv;
262 struct scatterlist sg[8];
263 const char *e, *m;
265 if (enc == ENCRYPT)
266 e = "encryption";
267 else
268 e = "decryption";
269 if (mode == MODE_ECB)
270 m = "ECB";
271 else
272 m = "CBC";
274 printk("\ntesting %s %s %s\n", algo, m, e);
276 tsize = sizeof (struct cipher_testvec);
277 tsize *= tcount;
279 if (tsize > TVMEMSIZE) {
280 printk("template (%u) too big for tvmem (%u)\n", tsize,
281 TVMEMSIZE);
282 return;
285 memcpy(tvmem, template, tsize);
286 cipher_tv = (void *)tvmem;
288 if (mode)
289 tfm = crypto_alloc_tfm(algo, 0);
290 else
291 tfm = crypto_alloc_tfm(algo, CRYPTO_TFM_MODE_CBC);
293 if (tfm == NULL) {
294 printk("failed to load transform for %s %s\n", algo, m);
295 return;
298 j = 0;
299 for (i = 0; i < tcount; i++) {
300 if (!(cipher_tv[i].np)) {
301 j++;
302 printk("test %u (%d bit key):\n",
303 j, cipher_tv[i].klen * 8);
305 tfm->crt_flags = 0;
306 if (cipher_tv[i].wk)
307 tfm->crt_flags |= CRYPTO_TFM_REQ_WEAK_KEY;
308 key = cipher_tv[i].key;
310 ret = crypto_cipher_setkey(tfm, key, cipher_tv[i].klen);
311 if (ret) {
312 printk("setkey() failed flags=%x\n", tfm->crt_flags);
314 if (!cipher_tv[i].fail)
315 goto out;
318 sg_set_buf(&sg[0], cipher_tv[i].input,
319 cipher_tv[i].ilen);
321 if (!mode) {
322 crypto_cipher_set_iv(tfm, cipher_tv[i].iv,
323 crypto_tfm_alg_ivsize(tfm));
326 if (enc)
327 ret = crypto_cipher_encrypt(tfm, sg, sg, cipher_tv[i].ilen);
328 else
329 ret = crypto_cipher_decrypt(tfm, sg, sg, cipher_tv[i].ilen);
332 if (ret) {
333 printk("%s () failed flags=%x\n", e, tfm->crt_flags);
334 goto out;
337 q = kmap(sg[0].page) + sg[0].offset;
338 hexdump(q, cipher_tv[i].rlen);
340 printk("%s\n",
341 memcmp(q, cipher_tv[i].result,
342 cipher_tv[i].rlen) ? "fail" : "pass");
346 printk("\ntesting %s %s %s across pages (chunking)\n", algo, m, e);
347 memset(xbuf, 0, XBUFSIZE);
349 j = 0;
350 for (i = 0; i < tcount; i++) {
351 if (cipher_tv[i].np) {
352 j++;
353 printk("test %u (%d bit key):\n",
354 j, cipher_tv[i].klen * 8);
356 tfm->crt_flags = 0;
357 if (cipher_tv[i].wk)
358 tfm->crt_flags |= CRYPTO_TFM_REQ_WEAK_KEY;
359 key = cipher_tv[i].key;
361 ret = crypto_cipher_setkey(tfm, key, cipher_tv[i].klen);
362 if (ret) {
363 printk("setkey() failed flags=%x\n", tfm->crt_flags);
365 if (!cipher_tv[i].fail)
366 goto out;
369 temp = 0;
370 for (k = 0; k < cipher_tv[i].np; k++) {
371 memcpy(&xbuf[IDX[k]],
372 cipher_tv[i].input + temp,
373 cipher_tv[i].tap[k]);
374 temp += cipher_tv[i].tap[k];
375 sg_set_buf(&sg[k], &xbuf[IDX[k]],
376 cipher_tv[i].tap[k]);
379 if (!mode) {
380 crypto_cipher_set_iv(tfm, cipher_tv[i].iv,
381 crypto_tfm_alg_ivsize(tfm));
384 if (enc)
385 ret = crypto_cipher_encrypt(tfm, sg, sg, cipher_tv[i].ilen);
386 else
387 ret = crypto_cipher_decrypt(tfm, sg, sg, cipher_tv[i].ilen);
389 if (ret) {
390 printk("%s () failed flags=%x\n", e, tfm->crt_flags);
391 goto out;
394 temp = 0;
395 for (k = 0; k < cipher_tv[i].np; k++) {
396 printk("page %u\n", k);
397 q = kmap(sg[k].page) + sg[k].offset;
398 hexdump(q, cipher_tv[i].tap[k]);
399 printk("%s\n",
400 memcmp(q, cipher_tv[i].result + temp,
401 cipher_tv[i].tap[k]) ? "fail" :
402 "pass");
403 temp += cipher_tv[i].tap[k];
408 out:
409 crypto_free_tfm(tfm);
412 static int test_cipher_jiffies(struct crypto_tfm *tfm, int enc, char *p,
413 int blen, int sec)
415 struct scatterlist sg[1];
416 unsigned long start, end;
417 int bcount;
418 int ret;
420 sg_set_buf(sg, p, blen);
422 for (start = jiffies, end = start + sec * HZ, bcount = 0;
423 time_before(jiffies, end); bcount++) {
424 if (enc)
425 ret = crypto_cipher_encrypt(tfm, sg, sg, blen);
426 else
427 ret = crypto_cipher_decrypt(tfm, sg, sg, blen);
429 if (ret)
430 return ret;
433 printk("%d operations in %d seconds (%ld bytes)\n",
434 bcount, sec, (long)bcount * blen);
435 return 0;
438 static int test_cipher_cycles(struct crypto_tfm *tfm, int enc, char *p,
439 int blen)
441 struct scatterlist sg[1];
442 unsigned long cycles = 0;
443 int ret = 0;
444 int i;
446 sg_set_buf(sg, p, blen);
448 local_bh_disable();
449 local_irq_disable();
451 /* Warm-up run. */
452 for (i = 0; i < 4; i++) {
453 if (enc)
454 ret = crypto_cipher_encrypt(tfm, sg, sg, blen);
455 else
456 ret = crypto_cipher_decrypt(tfm, sg, sg, blen);
458 if (ret)
459 goto out;
462 /* The real thing. */
463 for (i = 0; i < 8; i++) {
464 cycles_t start, end;
466 start = get_cycles();
467 if (enc)
468 ret = crypto_cipher_encrypt(tfm, sg, sg, blen);
469 else
470 ret = crypto_cipher_decrypt(tfm, sg, sg, blen);
471 end = get_cycles();
473 if (ret)
474 goto out;
476 cycles += end - start;
479 out:
480 local_irq_enable();
481 local_bh_enable();
483 if (ret == 0)
484 printk("1 operation in %lu cycles (%d bytes)\n",
485 (cycles + 4) / 8, blen);
487 return ret;
490 static void test_cipher_speed(char *algo, int mode, int enc, unsigned int sec,
491 struct cipher_testvec *template,
492 unsigned int tcount, struct cipher_speed *speed)
494 unsigned int ret, i, j, iv_len;
495 unsigned char *key, *p, iv[128];
496 struct crypto_tfm *tfm;
497 const char *e, *m;
499 if (enc == ENCRYPT)
500 e = "encryption";
501 else
502 e = "decryption";
503 if (mode == MODE_ECB)
504 m = "ECB";
505 else
506 m = "CBC";
508 printk("\ntesting speed of %s %s %s\n", algo, m, e);
510 if (mode)
511 tfm = crypto_alloc_tfm(algo, 0);
512 else
513 tfm = crypto_alloc_tfm(algo, CRYPTO_TFM_MODE_CBC);
515 if (tfm == NULL) {
516 printk("failed to load transform for %s %s\n", algo, m);
517 return;
520 for (i = 0; speed[i].klen != 0; i++) {
521 if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) {
522 printk("template (%u) too big for tvmem (%u)\n",
523 speed[i].blen + speed[i].klen, TVMEMSIZE);
524 goto out;
527 printk("test %u (%d bit key, %d byte blocks): ", i,
528 speed[i].klen * 8, speed[i].blen);
530 memset(tvmem, 0xff, speed[i].klen + speed[i].blen);
532 /* set key, plain text and IV */
533 key = (unsigned char *)tvmem;
534 for (j = 0; j < tcount; j++) {
535 if (template[j].klen == speed[i].klen) {
536 key = template[j].key;
537 break;
540 p = (unsigned char *)tvmem + speed[i].klen;
542 ret = crypto_cipher_setkey(tfm, key, speed[i].klen);
543 if (ret) {
544 printk("setkey() failed flags=%x\n", tfm->crt_flags);
545 goto out;
548 if (!mode) {
549 iv_len = crypto_tfm_alg_ivsize(tfm);
550 memset(&iv, 0xff, iv_len);
551 crypto_cipher_set_iv(tfm, iv, iv_len);
554 if (sec)
555 ret = test_cipher_jiffies(tfm, enc, p, speed[i].blen,
556 sec);
557 else
558 ret = test_cipher_cycles(tfm, enc, p, speed[i].blen);
560 if (ret) {
561 printk("%s() failed flags=%x\n", e, tfm->crt_flags);
562 break;
566 out:
567 crypto_free_tfm(tfm);
570 static void test_digest_jiffies(struct crypto_tfm *tfm, char *p, int blen,
571 int plen, char *out, int sec)
573 struct scatterlist sg[1];
574 unsigned long start, end;
575 int bcount, pcount;
577 for (start = jiffies, end = start + sec * HZ, bcount = 0;
578 time_before(jiffies, end); bcount++) {
579 crypto_digest_init(tfm);
580 for (pcount = 0; pcount < blen; pcount += plen) {
581 sg_set_buf(sg, p + pcount, plen);
582 crypto_digest_update(tfm, sg, 1);
584 /* we assume there is enough space in 'out' for the result */
585 crypto_digest_final(tfm, out);
588 printk("%6u opers/sec, %9lu bytes/sec\n",
589 bcount / sec, ((long)bcount * blen) / sec);
591 return;
594 static void test_digest_cycles(struct crypto_tfm *tfm, char *p, int blen,
595 int plen, char *out)
597 struct scatterlist sg[1];
598 unsigned long cycles = 0;
599 int i, pcount;
601 local_bh_disable();
602 local_irq_disable();
604 /* Warm-up run. */
605 for (i = 0; i < 4; i++) {
606 crypto_digest_init(tfm);
607 for (pcount = 0; pcount < blen; pcount += plen) {
608 sg_set_buf(sg, p + pcount, plen);
609 crypto_digest_update(tfm, sg, 1);
611 crypto_digest_final(tfm, out);
614 /* The real thing. */
615 for (i = 0; i < 8; i++) {
616 cycles_t start, end;
618 crypto_digest_init(tfm);
620 start = get_cycles();
622 for (pcount = 0; pcount < blen; pcount += plen) {
623 sg_set_buf(sg, p + pcount, plen);
624 crypto_digest_update(tfm, sg, 1);
626 crypto_digest_final(tfm, out);
628 end = get_cycles();
630 cycles += end - start;
633 local_irq_enable();
634 local_bh_enable();
636 printk("%6lu cycles/operation, %4lu cycles/byte\n",
637 cycles / 8, cycles / (8 * blen));
639 return;
642 static void test_digest_speed(char *algo, unsigned int sec,
643 struct digest_speed *speed)
645 struct crypto_tfm *tfm;
646 char output[1024];
647 int i;
649 printk("\ntesting speed of %s\n", algo);
651 tfm = crypto_alloc_tfm(algo, 0);
653 if (tfm == NULL) {
654 printk("failed to load transform for %s\n", algo);
655 return;
658 if (crypto_tfm_alg_digestsize(tfm) > sizeof(output)) {
659 printk("digestsize(%u) > outputbuffer(%zu)\n",
660 crypto_tfm_alg_digestsize(tfm), sizeof(output));
661 goto out;
664 for (i = 0; speed[i].blen != 0; i++) {
665 if (speed[i].blen > TVMEMSIZE) {
666 printk("template (%u) too big for tvmem (%u)\n",
667 speed[i].blen, TVMEMSIZE);
668 goto out;
671 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
672 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
674 memset(tvmem, 0xff, speed[i].blen);
676 if (sec)
677 test_digest_jiffies(tfm, tvmem, speed[i].blen, speed[i].plen, output, sec);
678 else
679 test_digest_cycles(tfm, tvmem, speed[i].blen, speed[i].plen, output);
682 out:
683 crypto_free_tfm(tfm);
686 static void test_deflate(void)
688 unsigned int i;
689 char result[COMP_BUF_SIZE];
690 struct crypto_tfm *tfm;
691 struct comp_testvec *tv;
692 unsigned int tsize;
694 printk("\ntesting deflate compression\n");
696 tsize = sizeof (deflate_comp_tv_template);
697 if (tsize > TVMEMSIZE) {
698 printk("template (%u) too big for tvmem (%u)\n", tsize,
699 TVMEMSIZE);
700 return;
703 memcpy(tvmem, deflate_comp_tv_template, tsize);
704 tv = (void *)tvmem;
706 tfm = crypto_alloc_tfm("deflate", 0);
707 if (tfm == NULL) {
708 printk("failed to load transform for deflate\n");
709 return;
712 for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) {
713 int ilen, ret, dlen = COMP_BUF_SIZE;
715 printk("test %u:\n", i + 1);
716 memset(result, 0, sizeof (result));
718 ilen = tv[i].inlen;
719 ret = crypto_comp_compress(tfm, tv[i].input,
720 ilen, result, &dlen);
721 if (ret) {
722 printk("fail: ret=%d\n", ret);
723 continue;
725 hexdump(result, dlen);
726 printk("%s (ratio %d:%d)\n",
727 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
728 ilen, dlen);
731 printk("\ntesting deflate decompression\n");
733 tsize = sizeof (deflate_decomp_tv_template);
734 if (tsize > TVMEMSIZE) {
735 printk("template (%u) too big for tvmem (%u)\n", tsize,
736 TVMEMSIZE);
737 goto out;
740 memcpy(tvmem, deflate_decomp_tv_template, tsize);
741 tv = (void *)tvmem;
743 for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) {
744 int ilen, ret, dlen = COMP_BUF_SIZE;
746 printk("test %u:\n", i + 1);
747 memset(result, 0, sizeof (result));
749 ilen = tv[i].inlen;
750 ret = crypto_comp_decompress(tfm, tv[i].input,
751 ilen, result, &dlen);
752 if (ret) {
753 printk("fail: ret=%d\n", ret);
754 continue;
756 hexdump(result, dlen);
757 printk("%s (ratio %d:%d)\n",
758 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
759 ilen, dlen);
761 out:
762 crypto_free_tfm(tfm);
765 static void test_crc32c(void)
767 #define NUMVEC 6
768 #define VECSIZE 40
770 int i, j, pass;
771 u32 crc;
772 u8 b, test_vec[NUMVEC][VECSIZE];
773 static u32 vec_results[NUMVEC] = {
774 0x0e2c157f, 0xe980ebf6, 0xde74bded,
775 0xd579c862, 0xba979ad0, 0x2b29d913
777 static u32 tot_vec_results = 0x24c5d375;
779 struct scatterlist sg[NUMVEC];
780 struct crypto_tfm *tfm;
781 char *fmtdata = "testing crc32c initialized to %08x: %s\n";
782 #define SEEDTESTVAL 0xedcba987
783 u32 seed;
785 printk("\ntesting crc32c\n");
787 tfm = crypto_alloc_tfm("crc32c", 0);
788 if (tfm == NULL) {
789 printk("failed to load transform for crc32c\n");
790 return;
793 crypto_digest_init(tfm);
794 crypto_digest_final(tfm, (u8*)&crc);
795 printk(fmtdata, crc, (crc == 0) ? "pass" : "ERROR");
798 * stuff test_vec with known values, simple incrementing
799 * byte values.
801 b = 0;
802 for (i = 0; i < NUMVEC; i++) {
803 for (j = 0; j < VECSIZE; j++)
804 test_vec[i][j] = ++b;
805 sg_set_buf(&sg[i], test_vec[i], VECSIZE);
808 seed = SEEDTESTVAL;
809 (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32));
810 crypto_digest_init(tfm);
811 crypto_digest_final(tfm, (u8*)&crc);
812 printk("testing crc32c setkey returns %08x : %s\n", crc, (crc == (SEEDTESTVAL ^ ~(u32)0)) ?
813 "pass" : "ERROR");
815 printk("testing crc32c using update/final:\n");
817 pass = 1; /* assume all is well */
819 for (i = 0; i < NUMVEC; i++) {
820 seed = ~(u32)0;
821 (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32));
822 crypto_digest_init(tfm);
823 crypto_digest_update(tfm, &sg[i], 1);
824 crypto_digest_final(tfm, (u8*)&crc);
825 if (crc == vec_results[i]) {
826 printk(" %08x:OK", crc);
827 } else {
828 printk(" %08x:BAD, wanted %08x\n", crc, vec_results[i]);
829 pass = 0;
833 printk("\ntesting crc32c using incremental accumulator:\n");
834 crc = 0;
835 for (i = 0; i < NUMVEC; i++) {
836 seed = (crc ^ ~(u32)0);
837 (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32));
838 crypto_digest_init(tfm);
839 crypto_digest_update(tfm, &sg[i], 1);
840 crypto_digest_final(tfm, (u8*)&crc);
842 if (crc == tot_vec_results) {
843 printk(" %08x:OK", crc);
844 } else {
845 printk(" %08x:BAD, wanted %08x\n", crc, tot_vec_results);
846 pass = 0;
849 printk("\ntesting crc32c using digest:\n");
850 seed = ~(u32)0;
851 (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32));
852 crypto_digest_init(tfm);
853 crypto_digest_digest(tfm, sg, NUMVEC, (u8*)&crc);
854 if (crc == tot_vec_results) {
855 printk(" %08x:OK", crc);
856 } else {
857 printk(" %08x:BAD, wanted %08x\n", crc, tot_vec_results);
858 pass = 0;
861 printk("\n%s\n", pass ? "pass" : "ERROR");
863 crypto_free_tfm(tfm);
864 printk("crc32c test complete\n");
867 static void test_available(void)
869 char **name = check;
871 while (*name) {
872 printk("alg %s ", *name);
873 printk((crypto_alg_available(*name, 0)) ?
874 "found\n" : "not found\n");
875 name++;
879 static void do_test(void)
881 switch (mode) {
883 case 0:
884 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
886 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
888 //DES
889 test_cipher ("des", MODE_ECB, ENCRYPT, des_enc_tv_template, DES_ENC_TEST_VECTORS);
890 test_cipher ("des", MODE_ECB, DECRYPT, des_dec_tv_template, DES_DEC_TEST_VECTORS);
891 test_cipher ("des", MODE_CBC, ENCRYPT, des_cbc_enc_tv_template, DES_CBC_ENC_TEST_VECTORS);
892 test_cipher ("des", MODE_CBC, DECRYPT, des_cbc_dec_tv_template, DES_CBC_DEC_TEST_VECTORS);
894 //DES3_EDE
895 test_cipher ("des3_ede", MODE_ECB, ENCRYPT, des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS);
896 test_cipher ("des3_ede", MODE_ECB, DECRYPT, des3_ede_dec_tv_template, DES3_EDE_DEC_TEST_VECTORS);
898 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
900 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
902 //BLOWFISH
903 test_cipher ("blowfish", MODE_ECB, ENCRYPT, bf_enc_tv_template, BF_ENC_TEST_VECTORS);
904 test_cipher ("blowfish", MODE_ECB, DECRYPT, bf_dec_tv_template, BF_DEC_TEST_VECTORS);
905 test_cipher ("blowfish", MODE_CBC, ENCRYPT, bf_cbc_enc_tv_template, BF_CBC_ENC_TEST_VECTORS);
906 test_cipher ("blowfish", MODE_CBC, DECRYPT, bf_cbc_dec_tv_template, BF_CBC_DEC_TEST_VECTORS);
908 //TWOFISH
909 test_cipher ("twofish", MODE_ECB, ENCRYPT, tf_enc_tv_template, TF_ENC_TEST_VECTORS);
910 test_cipher ("twofish", MODE_ECB, DECRYPT, tf_dec_tv_template, TF_DEC_TEST_VECTORS);
911 test_cipher ("twofish", MODE_CBC, ENCRYPT, tf_cbc_enc_tv_template, TF_CBC_ENC_TEST_VECTORS);
912 test_cipher ("twofish", MODE_CBC, DECRYPT, tf_cbc_dec_tv_template, TF_CBC_DEC_TEST_VECTORS);
914 //SERPENT
915 test_cipher ("serpent", MODE_ECB, ENCRYPT, serpent_enc_tv_template, SERPENT_ENC_TEST_VECTORS);
916 test_cipher ("serpent", MODE_ECB, DECRYPT, serpent_dec_tv_template, SERPENT_DEC_TEST_VECTORS);
918 //TNEPRES
919 test_cipher ("tnepres", MODE_ECB, ENCRYPT, tnepres_enc_tv_template, TNEPRES_ENC_TEST_VECTORS);
920 test_cipher ("tnepres", MODE_ECB, DECRYPT, tnepres_dec_tv_template, TNEPRES_DEC_TEST_VECTORS);
922 //AES
923 test_cipher ("aes", MODE_ECB, ENCRYPT, aes_enc_tv_template, AES_ENC_TEST_VECTORS);
924 test_cipher ("aes", MODE_ECB, DECRYPT, aes_dec_tv_template, AES_DEC_TEST_VECTORS);
925 test_cipher ("aes", MODE_CBC, ENCRYPT, aes_cbc_enc_tv_template, AES_CBC_ENC_TEST_VECTORS);
926 test_cipher ("aes", MODE_CBC, DECRYPT, aes_cbc_dec_tv_template, AES_CBC_DEC_TEST_VECTORS);
928 //CAST5
929 test_cipher ("cast5", MODE_ECB, ENCRYPT, cast5_enc_tv_template, CAST5_ENC_TEST_VECTORS);
930 test_cipher ("cast5", MODE_ECB, DECRYPT, cast5_dec_tv_template, CAST5_DEC_TEST_VECTORS);
932 //CAST6
933 test_cipher ("cast6", MODE_ECB, ENCRYPT, cast6_enc_tv_template, CAST6_ENC_TEST_VECTORS);
934 test_cipher ("cast6", MODE_ECB, DECRYPT, cast6_dec_tv_template, CAST6_DEC_TEST_VECTORS);
936 //ARC4
937 test_cipher ("arc4", MODE_ECB, ENCRYPT, arc4_enc_tv_template, ARC4_ENC_TEST_VECTORS);
938 test_cipher ("arc4", MODE_ECB, DECRYPT, arc4_dec_tv_template, ARC4_DEC_TEST_VECTORS);
940 //TEA
941 test_cipher ("tea", MODE_ECB, ENCRYPT, tea_enc_tv_template, TEA_ENC_TEST_VECTORS);
942 test_cipher ("tea", MODE_ECB, DECRYPT, tea_dec_tv_template, TEA_DEC_TEST_VECTORS);
945 //XTEA
946 test_cipher ("xtea", MODE_ECB, ENCRYPT, xtea_enc_tv_template, XTEA_ENC_TEST_VECTORS);
947 test_cipher ("xtea", MODE_ECB, DECRYPT, xtea_dec_tv_template, XTEA_DEC_TEST_VECTORS);
949 //KHAZAD
950 test_cipher ("khazad", MODE_ECB, ENCRYPT, khazad_enc_tv_template, KHAZAD_ENC_TEST_VECTORS);
951 test_cipher ("khazad", MODE_ECB, DECRYPT, khazad_dec_tv_template, KHAZAD_DEC_TEST_VECTORS);
953 //ANUBIS
954 test_cipher ("anubis", MODE_ECB, ENCRYPT, anubis_enc_tv_template, ANUBIS_ENC_TEST_VECTORS);
955 test_cipher ("anubis", MODE_ECB, DECRYPT, anubis_dec_tv_template, ANUBIS_DEC_TEST_VECTORS);
956 test_cipher ("anubis", MODE_CBC, ENCRYPT, anubis_cbc_enc_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS);
957 test_cipher ("anubis", MODE_CBC, DECRYPT, anubis_cbc_dec_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS);
959 //XETA
960 test_cipher ("xeta", MODE_ECB, ENCRYPT, xeta_enc_tv_template, XETA_ENC_TEST_VECTORS);
961 test_cipher ("xeta", MODE_ECB, DECRYPT, xeta_dec_tv_template, XETA_DEC_TEST_VECTORS);
963 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
964 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
965 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
966 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
967 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
968 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
969 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
970 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
971 test_deflate();
972 test_crc32c();
973 #ifdef CONFIG_CRYPTO_HMAC
974 test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS);
975 test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS);
976 test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS);
977 #endif
979 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
980 break;
982 case 1:
983 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
984 break;
986 case 2:
987 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
988 break;
990 case 3:
991 test_cipher ("des", MODE_ECB, ENCRYPT, des_enc_tv_template, DES_ENC_TEST_VECTORS);
992 test_cipher ("des", MODE_ECB, DECRYPT, des_dec_tv_template, DES_DEC_TEST_VECTORS);
993 test_cipher ("des", MODE_CBC, ENCRYPT, des_cbc_enc_tv_template, DES_CBC_ENC_TEST_VECTORS);
994 test_cipher ("des", MODE_CBC, DECRYPT, des_cbc_dec_tv_template, DES_CBC_DEC_TEST_VECTORS);
995 break;
997 case 4:
998 test_cipher ("des3_ede", MODE_ECB, ENCRYPT, des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS);
999 test_cipher ("des3_ede", MODE_ECB, DECRYPT, des3_ede_dec_tv_template, DES3_EDE_DEC_TEST_VECTORS);
1000 break;
1002 case 5:
1003 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1004 break;
1006 case 6:
1007 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1008 break;
1010 case 7:
1011 test_cipher ("blowfish", MODE_ECB, ENCRYPT, bf_enc_tv_template, BF_ENC_TEST_VECTORS);
1012 test_cipher ("blowfish", MODE_ECB, DECRYPT, bf_dec_tv_template, BF_DEC_TEST_VECTORS);
1013 test_cipher ("blowfish", MODE_CBC, ENCRYPT, bf_cbc_enc_tv_template, BF_CBC_ENC_TEST_VECTORS);
1014 test_cipher ("blowfish", MODE_CBC, DECRYPT, bf_cbc_dec_tv_template, BF_CBC_DEC_TEST_VECTORS);
1015 break;
1017 case 8:
1018 test_cipher ("twofish", MODE_ECB, ENCRYPT, tf_enc_tv_template, TF_ENC_TEST_VECTORS);
1019 test_cipher ("twofish", MODE_ECB, DECRYPT, tf_dec_tv_template, TF_DEC_TEST_VECTORS);
1020 test_cipher ("twofish", MODE_CBC, ENCRYPT, tf_cbc_enc_tv_template, TF_CBC_ENC_TEST_VECTORS);
1021 test_cipher ("twofish", MODE_CBC, DECRYPT, tf_cbc_dec_tv_template, TF_CBC_DEC_TEST_VECTORS);
1022 break;
1024 case 9:
1025 test_cipher ("serpent", MODE_ECB, ENCRYPT, serpent_enc_tv_template, SERPENT_ENC_TEST_VECTORS);
1026 test_cipher ("serpent", MODE_ECB, DECRYPT, serpent_dec_tv_template, SERPENT_DEC_TEST_VECTORS);
1027 break;
1029 case 10:
1030 test_cipher ("aes", MODE_ECB, ENCRYPT, aes_enc_tv_template, AES_ENC_TEST_VECTORS);
1031 test_cipher ("aes", MODE_ECB, DECRYPT, aes_dec_tv_template, AES_DEC_TEST_VECTORS);
1032 test_cipher ("aes", MODE_CBC, ENCRYPT, aes_cbc_enc_tv_template, AES_CBC_ENC_TEST_VECTORS);
1033 test_cipher ("aes", MODE_CBC, DECRYPT, aes_cbc_dec_tv_template, AES_CBC_DEC_TEST_VECTORS);
1034 break;
1036 case 11:
1037 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1038 break;
1040 case 12:
1041 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1042 break;
1044 case 13:
1045 test_deflate();
1046 break;
1048 case 14:
1049 test_cipher ("cast5", MODE_ECB, ENCRYPT, cast5_enc_tv_template, CAST5_ENC_TEST_VECTORS);
1050 test_cipher ("cast5", MODE_ECB, DECRYPT, cast5_dec_tv_template, CAST5_DEC_TEST_VECTORS);
1051 break;
1053 case 15:
1054 test_cipher ("cast6", MODE_ECB, ENCRYPT, cast6_enc_tv_template, CAST6_ENC_TEST_VECTORS);
1055 test_cipher ("cast6", MODE_ECB, DECRYPT, cast6_dec_tv_template, CAST6_DEC_TEST_VECTORS);
1056 break;
1058 case 16:
1059 test_cipher ("arc4", MODE_ECB, ENCRYPT, arc4_enc_tv_template, ARC4_ENC_TEST_VECTORS);
1060 test_cipher ("arc4", MODE_ECB, DECRYPT, arc4_dec_tv_template, ARC4_DEC_TEST_VECTORS);
1061 break;
1063 case 17:
1064 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1065 break;
1067 case 18:
1068 test_crc32c();
1069 break;
1071 case 19:
1072 test_cipher ("tea", MODE_ECB, ENCRYPT, tea_enc_tv_template, TEA_ENC_TEST_VECTORS);
1073 test_cipher ("tea", MODE_ECB, DECRYPT, tea_dec_tv_template, TEA_DEC_TEST_VECTORS);
1074 break;
1076 case 20:
1077 test_cipher ("xtea", MODE_ECB, ENCRYPT, xtea_enc_tv_template, XTEA_ENC_TEST_VECTORS);
1078 test_cipher ("xtea", MODE_ECB, DECRYPT, xtea_dec_tv_template, XTEA_DEC_TEST_VECTORS);
1079 break;
1081 case 21:
1082 test_cipher ("khazad", MODE_ECB, ENCRYPT, khazad_enc_tv_template, KHAZAD_ENC_TEST_VECTORS);
1083 test_cipher ("khazad", MODE_ECB, DECRYPT, khazad_dec_tv_template, KHAZAD_DEC_TEST_VECTORS);
1084 break;
1086 case 22:
1087 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1088 break;
1090 case 23:
1091 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1092 break;
1094 case 24:
1095 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1096 break;
1098 case 25:
1099 test_cipher ("tnepres", MODE_ECB, ENCRYPT, tnepres_enc_tv_template, TNEPRES_ENC_TEST_VECTORS);
1100 test_cipher ("tnepres", MODE_ECB, DECRYPT, tnepres_dec_tv_template, TNEPRES_DEC_TEST_VECTORS);
1101 break;
1103 case 26:
1104 test_cipher ("anubis", MODE_ECB, ENCRYPT, anubis_enc_tv_template, ANUBIS_ENC_TEST_VECTORS);
1105 test_cipher ("anubis", MODE_ECB, DECRYPT, anubis_dec_tv_template, ANUBIS_DEC_TEST_VECTORS);
1106 test_cipher ("anubis", MODE_CBC, ENCRYPT, anubis_cbc_enc_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS);
1107 test_cipher ("anubis", MODE_CBC, DECRYPT, anubis_cbc_dec_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS);
1108 break;
1110 case 27:
1111 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1112 break;
1114 case 28:
1116 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1117 break;
1119 case 29:
1120 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1121 break;
1123 case 30:
1124 test_cipher ("xeta", MODE_ECB, ENCRYPT, xeta_enc_tv_template, XETA_ENC_TEST_VECTORS);
1125 test_cipher ("xeta", MODE_ECB, DECRYPT, xeta_dec_tv_template, XETA_DEC_TEST_VECTORS);
1126 break;
1128 #ifdef CONFIG_CRYPTO_HMAC
1129 case 100:
1130 test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS);
1131 break;
1133 case 101:
1134 test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS);
1135 break;
1137 case 102:
1138 test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS);
1139 break;
1141 #endif
1143 case 200:
1144 test_cipher_speed("aes", MODE_ECB, ENCRYPT, sec, NULL, 0,
1145 aes_speed_template);
1146 test_cipher_speed("aes", MODE_ECB, DECRYPT, sec, NULL, 0,
1147 aes_speed_template);
1148 test_cipher_speed("aes", MODE_CBC, ENCRYPT, sec, NULL, 0,
1149 aes_speed_template);
1150 test_cipher_speed("aes", MODE_CBC, DECRYPT, sec, NULL, 0,
1151 aes_speed_template);
1152 break;
1154 case 201:
1155 test_cipher_speed("des3_ede", MODE_ECB, ENCRYPT, sec,
1156 des3_ede_enc_tv_template,
1157 DES3_EDE_ENC_TEST_VECTORS,
1158 des3_ede_speed_template);
1159 test_cipher_speed("des3_ede", MODE_ECB, DECRYPT, sec,
1160 des3_ede_dec_tv_template,
1161 DES3_EDE_DEC_TEST_VECTORS,
1162 des3_ede_speed_template);
1163 test_cipher_speed("des3_ede", MODE_CBC, ENCRYPT, sec,
1164 des3_ede_enc_tv_template,
1165 DES3_EDE_ENC_TEST_VECTORS,
1166 des3_ede_speed_template);
1167 test_cipher_speed("des3_ede", MODE_CBC, DECRYPT, sec,
1168 des3_ede_dec_tv_template,
1169 DES3_EDE_DEC_TEST_VECTORS,
1170 des3_ede_speed_template);
1171 break;
1173 case 202:
1174 test_cipher_speed("twofish", MODE_ECB, ENCRYPT, sec, NULL, 0,
1175 twofish_speed_template);
1176 test_cipher_speed("twofish", MODE_ECB, DECRYPT, sec, NULL, 0,
1177 twofish_speed_template);
1178 test_cipher_speed("twofish", MODE_CBC, ENCRYPT, sec, NULL, 0,
1179 twofish_speed_template);
1180 test_cipher_speed("twofish", MODE_CBC, DECRYPT, sec, NULL, 0,
1181 twofish_speed_template);
1182 break;
1184 case 203:
1185 test_cipher_speed("blowfish", MODE_ECB, ENCRYPT, sec, NULL, 0,
1186 blowfish_speed_template);
1187 test_cipher_speed("blowfish", MODE_ECB, DECRYPT, sec, NULL, 0,
1188 blowfish_speed_template);
1189 test_cipher_speed("blowfish", MODE_CBC, ENCRYPT, sec, NULL, 0,
1190 blowfish_speed_template);
1191 test_cipher_speed("blowfish", MODE_CBC, DECRYPT, sec, NULL, 0,
1192 blowfish_speed_template);
1193 break;
1195 case 204:
1196 test_cipher_speed("des", MODE_ECB, ENCRYPT, sec, NULL, 0,
1197 des_speed_template);
1198 test_cipher_speed("des", MODE_ECB, DECRYPT, sec, NULL, 0,
1199 des_speed_template);
1200 test_cipher_speed("des", MODE_CBC, ENCRYPT, sec, NULL, 0,
1201 des_speed_template);
1202 test_cipher_speed("des", MODE_CBC, DECRYPT, sec, NULL, 0,
1203 des_speed_template);
1204 break;
1206 case 300:
1207 /* fall through */
1209 case 301:
1210 test_digest_speed("md4", sec, generic_digest_speed_template);
1211 if (mode > 300 && mode < 400) break;
1213 case 302:
1214 test_digest_speed("md5", sec, generic_digest_speed_template);
1215 if (mode > 300 && mode < 400) break;
1217 case 303:
1218 test_digest_speed("sha1", sec, generic_digest_speed_template);
1219 if (mode > 300 && mode < 400) break;
1221 case 304:
1222 test_digest_speed("sha256", sec, generic_digest_speed_template);
1223 if (mode > 300 && mode < 400) break;
1225 case 305:
1226 test_digest_speed("sha384", sec, generic_digest_speed_template);
1227 if (mode > 300 && mode < 400) break;
1229 case 306:
1230 test_digest_speed("sha512", sec, generic_digest_speed_template);
1231 if (mode > 300 && mode < 400) break;
1233 case 307:
1234 test_digest_speed("wp256", sec, generic_digest_speed_template);
1235 if (mode > 300 && mode < 400) break;
1237 case 308:
1238 test_digest_speed("wp384", sec, generic_digest_speed_template);
1239 if (mode > 300 && mode < 400) break;
1241 case 309:
1242 test_digest_speed("wp512", sec, generic_digest_speed_template);
1243 if (mode > 300 && mode < 400) break;
1245 case 310:
1246 test_digest_speed("tgr128", sec, generic_digest_speed_template);
1247 if (mode > 300 && mode < 400) break;
1249 case 311:
1250 test_digest_speed("tgr160", sec, generic_digest_speed_template);
1251 if (mode > 300 && mode < 400) break;
1253 case 312:
1254 test_digest_speed("tgr192", sec, generic_digest_speed_template);
1255 if (mode > 300 && mode < 400) break;
1257 case 399:
1258 break;
1260 case 1000:
1261 test_available();
1262 break;
1264 default:
1265 /* useful for debugging */
1266 printk("not testing anything\n");
1267 break;
1271 static int __init init(void)
1273 tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
1274 if (tvmem == NULL)
1275 return -ENOMEM;
1277 xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1278 if (xbuf == NULL) {
1279 kfree(tvmem);
1280 return -ENOMEM;
1283 do_test();
1285 kfree(xbuf);
1286 kfree(tvmem);
1288 /* We intentionaly return -EAGAIN to prevent keeping
1289 * the module. It does all its work from init()
1290 * and doesn't offer any runtime functionality
1291 * => we don't need it in the memory, do we?
1292 * -- mludvig
1294 return -EAGAIN;
1298 * If an init function is provided, an exit function must also be provided
1299 * to allow module unload.
1301 static void __exit fini(void) { }
1303 module_init(init);
1304 module_exit(fini);
1306 module_param(mode, int, 0);
1307 module_param(sec, uint, 0);
1308 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
1309 "(defaults to zero which uses CPU cycles instead)");
1311 MODULE_LICENSE("GPL");
1312 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1313 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");