[CRYPTO] tcrypt: Catch cipher destination memory corruption
[linux-2.6.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 <linux/err.h>
19 #include <linux/init.h>
20 #include <linux/module.h>
21 #include <linux/mm.h>
22 #include <linux/slab.h>
23 #include <linux/scatterlist.h>
24 #include <linux/string.h>
25 #include <linux/crypto.h>
26 #include <linux/highmem.h>
27 #include <linux/moduleparam.h>
28 #include <linux/jiffies.h>
29 #include <linux/timex.h>
30 #include <linux/interrupt.h>
31 #include "tcrypt.h"
32
33 /*
34  * Need to kmalloc() memory for testing kmap().
35  */
36 #define TVMEMSIZE       16384
37 #define XBUFSIZE        32768
38
39 /*
40  * Indexes into the xbuf to simulate cross-page access.
41  */
42 #define IDX1            32
43 #define IDX2            32400
44 #define IDX3            1
45 #define IDX4            8193
46 #define IDX5            22222
47 #define IDX6            17101
48 #define IDX7            27333
49 #define IDX8            3000
50
51 /*
52 * Used by test_cipher()
53 */
54 #define ENCRYPT 1
55 #define DECRYPT 0
56
57 struct tcrypt_result {
58         struct completion completion;
59         int err;
60 };
61
62 static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
63
64 /*
65  * Used by test_cipher_speed()
66  */
67 static unsigned int sec;
68
69 static int mode;
70 static char *xbuf;
71 static char *axbuf;
72 static char *tvmem;
73
74 static char *check[] = {
75         "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
76         "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
77         "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
78         "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta",  "fcrypt",
79         "camellia", "seed", "salsa20", "rmd128", "rmd160", "lzo", "cts", NULL
80 };
81
82 static void hexdump(unsigned char *buf, unsigned int len)
83 {
84         print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
85                         16, 1,
86                         buf, len, false);
87 }
88
89 static void tcrypt_complete(struct crypto_async_request *req, int err)
90 {
91         struct tcrypt_result *res = req->data;
92
93         if (err == -EINPROGRESS)
94                 return;
95
96         res->err = err;
97         complete(&res->completion);
98 }
99
100 static void test_hash(char *algo, struct hash_testvec *template,
101                       unsigned int tcount)
102 {
103         unsigned int i, j, k, temp;
104         struct scatterlist sg[8];
105         char result[64];
106         struct crypto_hash *tfm;
107         struct hash_desc desc;
108         int ret;
109         void *hash_buff;
110
111         printk("\ntesting %s\n", algo);
112
113         tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
114         if (IS_ERR(tfm)) {
115                 printk("failed to load transform for %s: %ld\n", algo,
116                        PTR_ERR(tfm));
117                 return;
118         }
119
120         desc.tfm = tfm;
121         desc.flags = 0;
122
123         for (i = 0; i < tcount; i++) {
124                 printk("test %u:\n", i + 1);
125                 memset(result, 0, 64);
126
127                 hash_buff = kzalloc(template[i].psize, GFP_KERNEL);
128                 if (!hash_buff)
129                         continue;
130
131                 memcpy(hash_buff, template[i].plaintext, template[i].psize);
132                 sg_init_one(&sg[0], hash_buff, template[i].psize);
133
134                 if (template[i].ksize) {
135                         ret = crypto_hash_setkey(tfm, template[i].key,
136                                                  template[i].ksize);
137                         if (ret) {
138                                 printk("setkey() failed ret=%d\n", ret);
139                                 kfree(hash_buff);
140                                 goto out;
141                         }
142                 }
143
144                 ret = crypto_hash_digest(&desc, sg, template[i].psize, result);
145                 if (ret) {
146                         printk("digest () failed ret=%d\n", ret);
147                         kfree(hash_buff);
148                         goto out;
149                 }
150
151                 hexdump(result, crypto_hash_digestsize(tfm));
152                 printk("%s\n",
153                        memcmp(result, template[i].digest,
154                               crypto_hash_digestsize(tfm)) ?
155                        "fail" : "pass");
156                 kfree(hash_buff);
157         }
158
159         printk("testing %s across pages\n", algo);
160
161         /* setup the dummy buffer first */
162         memset(xbuf, 0, XBUFSIZE);
163
164         j = 0;
165         for (i = 0; i < tcount; i++) {
166                 if (template[i].np) {
167                         j++;
168                         printk("test %u:\n", j);
169                         memset(result, 0, 64);
170
171                         temp = 0;
172                         sg_init_table(sg, template[i].np);
173                         for (k = 0; k < template[i].np; k++) {
174                                 memcpy(&xbuf[IDX[k]],
175                                        template[i].plaintext + temp,
176                                        template[i].tap[k]);
177                                 temp += template[i].tap[k];
178                                 sg_set_buf(&sg[k], &xbuf[IDX[k]],
179                                             template[i].tap[k]);
180                         }
181
182                         if (template[i].ksize) {
183                                 ret = crypto_hash_setkey(tfm, template[i].key,
184                                                          template[i].ksize);
185
186                                 if (ret) {
187                                         printk("setkey() failed ret=%d\n", ret);
188                                         goto out;
189                                 }
190                         }
191
192                         ret = crypto_hash_digest(&desc, sg, template[i].psize,
193                                                  result);
194                         if (ret) {
195                                 printk("digest () failed ret=%d\n", ret);
196                                 goto out;
197                         }
198
199                         hexdump(result, crypto_hash_digestsize(tfm));
200                         printk("%s\n",
201                                memcmp(result, template[i].digest,
202                                       crypto_hash_digestsize(tfm)) ?
203                                "fail" : "pass");
204                 }
205         }
206
207 out:
208         crypto_free_hash(tfm);
209 }
210
211 static void test_aead(char *algo, int enc, struct aead_testvec *template,
212                       unsigned int tcount)
213 {
214         unsigned int ret, i, j, k, n, temp;
215         char *q;
216         struct crypto_aead *tfm;
217         char *key;
218         struct aead_request *req;
219         struct scatterlist sg[8];
220         struct scatterlist asg[8];
221         const char *e;
222         struct tcrypt_result result;
223         unsigned int authsize;
224         void *input;
225         void *assoc;
226         char iv[MAX_IVLEN];
227
228         if (enc == ENCRYPT)
229                 e = "encryption";
230         else
231                 e = "decryption";
232
233         printk(KERN_INFO "\ntesting %s %s\n", algo, e);
234
235         init_completion(&result.completion);
236
237         tfm = crypto_alloc_aead(algo, 0, 0);
238
239         if (IS_ERR(tfm)) {
240                 printk(KERN_INFO "failed to load transform for %s: %ld\n",
241                        algo, PTR_ERR(tfm));
242                 return;
243         }
244
245         req = aead_request_alloc(tfm, GFP_KERNEL);
246         if (!req) {
247                 printk(KERN_INFO "failed to allocate request for %s\n", algo);
248                 goto out;
249         }
250
251         aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
252                                   tcrypt_complete, &result);
253
254         for (i = 0, j = 0; i < tcount; i++) {
255                 if (!template[i].np) {
256                         printk(KERN_INFO "test %u (%d bit key):\n",
257                                ++j, template[i].klen * 8);
258
259                         /* some tepmplates have no input data but they will
260                          * touch input
261                          */
262                         input = kzalloc(template[i].ilen + template[i].rlen, GFP_KERNEL);
263                         if (!input)
264                                 continue;
265
266                         assoc = kzalloc(template[i].alen, GFP_KERNEL);
267                         if (!assoc) {
268                                 kfree(input);
269                                 continue;
270                         }
271
272                         memcpy(input, template[i].input, template[i].ilen);
273                         memcpy(assoc, template[i].assoc, template[i].alen);
274                         if (template[i].iv)
275                                 memcpy(iv, template[i].iv, MAX_IVLEN);
276                         else
277                                 memset(iv, 0, MAX_IVLEN);
278
279                         crypto_aead_clear_flags(tfm, ~0);
280                         if (template[i].wk)
281                                 crypto_aead_set_flags(
282                                         tfm, CRYPTO_TFM_REQ_WEAK_KEY);
283
284                         if (template[i].key)
285                                 key = template[i].key;
286                         else
287                                 key = kzalloc(template[i].klen, GFP_KERNEL);
288
289                         ret = crypto_aead_setkey(tfm, key,
290                                                  template[i].klen);
291                         if (ret) {
292                                 printk(KERN_INFO "setkey() failed flags=%x\n",
293                                        crypto_aead_get_flags(tfm));
294
295                                 if (!template[i].fail)
296                                         goto next_one;
297                         }
298
299                         authsize = abs(template[i].rlen - template[i].ilen);
300                         ret = crypto_aead_setauthsize(tfm, authsize);
301                         if (ret) {
302                                 printk(KERN_INFO
303                                        "failed to set authsize = %u\n",
304                                        authsize);
305                                 goto next_one;
306                         }
307
308                         sg_init_one(&sg[0], input,
309                                     template[i].ilen + (enc ? authsize : 0));
310
311                         sg_init_one(&asg[0], assoc, template[i].alen);
312
313                         aead_request_set_crypt(req, sg, sg,
314                                                template[i].ilen, iv);
315
316                         aead_request_set_assoc(req, asg, template[i].alen);
317
318                         ret = enc ?
319                                 crypto_aead_encrypt(req) :
320                                 crypto_aead_decrypt(req);
321
322                         switch (ret) {
323                         case 0:
324                                 break;
325                         case -EINPROGRESS:
326                         case -EBUSY:
327                                 ret = wait_for_completion_interruptible(
328                                         &result.completion);
329                                 if (!ret && !(ret = result.err)) {
330                                         INIT_COMPLETION(result.completion);
331                                         break;
332                                 }
333                                 /* fall through */
334                         default:
335                                 printk(KERN_INFO "%s () failed err=%d\n",
336                                        e, -ret);
337                                 goto next_one;
338                         }
339
340                         q = kmap(sg_page(&sg[0])) + sg[0].offset;
341                         hexdump(q, template[i].rlen);
342
343                         printk(KERN_INFO "enc/dec: %s\n",
344                                memcmp(q, template[i].result,
345                                       template[i].rlen) ? "fail" : "pass");
346                         kunmap(sg_page(&sg[0]));
347 next_one:
348                         if (!template[i].key)
349                                 kfree(key);
350                         kfree(assoc);
351                         kfree(input);
352                 }
353         }
354
355         printk(KERN_INFO "\ntesting %s %s across pages (chunking)\n", algo, e);
356         memset(axbuf, 0, XBUFSIZE);
357
358         for (i = 0, j = 0; i < tcount; i++) {
359                 if (template[i].np) {
360                         printk(KERN_INFO "test %u (%d bit key):\n",
361                                ++j, template[i].klen * 8);
362
363                         if (template[i].iv)
364                                 memcpy(iv, template[i].iv, MAX_IVLEN);
365                         else
366                                 memset(iv, 0, MAX_IVLEN);
367
368                         crypto_aead_clear_flags(tfm, ~0);
369                         if (template[i].wk)
370                                 crypto_aead_set_flags(
371                                         tfm, CRYPTO_TFM_REQ_WEAK_KEY);
372                         key = template[i].key;
373
374                         ret = crypto_aead_setkey(tfm, key, template[i].klen);
375                         if (ret) {
376                                 printk(KERN_INFO "setkey() failed flags=%x\n",
377                                        crypto_aead_get_flags(tfm));
378
379                                 if (!template[i].fail)
380                                         goto out;
381                         }
382
383                         memset(xbuf, 0, XBUFSIZE);
384                         sg_init_table(sg, template[i].np);
385                         for (k = 0, temp = 0; k < template[i].np; k++) {
386                                 memcpy(&xbuf[IDX[k]],
387                                        template[i].input + temp,
388                                        template[i].tap[k]);
389                                 temp += template[i].tap[k];
390                                 sg_set_buf(&sg[k], &xbuf[IDX[k]],
391                                            template[i].tap[k]);
392                         }
393
394                         authsize = abs(template[i].rlen - template[i].ilen);
395                         ret = crypto_aead_setauthsize(tfm, authsize);
396                         if (ret) {
397                                 printk(KERN_INFO
398                                        "failed to set authsize = %u\n",
399                                        authsize);
400                                 goto out;
401                         }
402
403                         if (enc)
404                                 sg[k - 1].length += authsize;
405
406                         sg_init_table(asg, template[i].anp);
407                         for (k = 0, temp = 0; k < template[i].anp; k++) {
408                                 memcpy(&axbuf[IDX[k]],
409                                        template[i].assoc + temp,
410                                        template[i].atap[k]);
411                                 temp += template[i].atap[k];
412                                 sg_set_buf(&asg[k], &axbuf[IDX[k]],
413                                            template[i].atap[k]);
414                         }
415
416                         aead_request_set_crypt(req, sg, sg,
417                                                template[i].ilen,
418                                                iv);
419
420                         aead_request_set_assoc(req, asg, template[i].alen);
421
422                         ret = enc ?
423                                 crypto_aead_encrypt(req) :
424                                 crypto_aead_decrypt(req);
425
426                         switch (ret) {
427                         case 0:
428                                 break;
429                         case -EINPROGRESS:
430                         case -EBUSY:
431                                 ret = wait_for_completion_interruptible(
432                                         &result.completion);
433                                 if (!ret && !(ret = result.err)) {
434                                         INIT_COMPLETION(result.completion);
435                                         break;
436                                 }
437                                 /* fall through */
438                         default:
439                                 printk(KERN_INFO "%s () failed err=%d\n",
440                                        e, -ret);
441                                 goto out;
442                         }
443
444                         for (k = 0, temp = 0; k < template[i].np; k++) {
445                                 printk(KERN_INFO "page %u\n", k);
446                                 q = kmap(sg_page(&sg[k])) + sg[k].offset;
447                                 hexdump(q, template[i].tap[k]);
448                                 printk(KERN_INFO "%s\n",
449                                        memcmp(q, template[i].result + temp,
450                                               template[i].tap[k] -
451                                               (k < template[i].np - 1 || enc ?
452                                                0 : authsize)) ?
453                                        "fail" : "pass");
454
455                                 for (n = 0; q[template[i].tap[k] + n]; n++)
456                                         ;
457                                 if (n) {
458                                         printk("Result buffer corruption %u "
459                                                "bytes:\n", n);
460                                         hexdump(&q[template[i].tap[k]], n);
461                                 }
462
463                                 temp += template[i].tap[k];
464                                 kunmap(sg_page(&sg[k]));
465                         }
466                 }
467         }
468
469 out:
470         crypto_free_aead(tfm);
471         aead_request_free(req);
472 }
473
474 static void test_cipher(char *algo, int enc,
475                         struct cipher_testvec *template, unsigned int tcount)
476 {
477         unsigned int ret, i, j, k, n, temp;
478         char *q;
479         struct crypto_ablkcipher *tfm;
480         struct ablkcipher_request *req;
481         struct scatterlist sg[8];
482         const char *e;
483         struct tcrypt_result result;
484         void *data;
485         char iv[MAX_IVLEN];
486
487         if (enc == ENCRYPT)
488                 e = "encryption";
489         else
490                 e = "decryption";
491
492         printk("\ntesting %s %s\n", algo, e);
493
494         init_completion(&result.completion);
495         tfm = crypto_alloc_ablkcipher(algo, 0, 0);
496
497         if (IS_ERR(tfm)) {
498                 printk("failed to load transform for %s: %ld\n", algo,
499                        PTR_ERR(tfm));
500                 return;
501         }
502
503         req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
504         if (!req) {
505                 printk("failed to allocate request for %s\n", algo);
506                 goto out;
507         }
508
509         ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
510                                         tcrypt_complete, &result);
511
512         j = 0;
513         for (i = 0; i < tcount; i++) {
514
515                 data = kzalloc(template[i].ilen, GFP_KERNEL);
516                 if (!data)
517                         continue;
518
519                 memcpy(data, template[i].input, template[i].ilen);
520                 if (template[i].iv)
521                         memcpy(iv, template[i].iv, MAX_IVLEN);
522                 else
523                         memset(iv, 0, MAX_IVLEN);
524
525                 if (!(template[i].np)) {
526                         j++;
527                         printk("test %u (%d bit key):\n",
528                         j, template[i].klen * 8);
529
530                         crypto_ablkcipher_clear_flags(tfm, ~0);
531                         if (template[i].wk)
532                                 crypto_ablkcipher_set_flags(
533                                         tfm, CRYPTO_TFM_REQ_WEAK_KEY);
534
535                         ret = crypto_ablkcipher_setkey(tfm, template[i].key,
536                                                        template[i].klen);
537                         if (ret) {
538                                 printk("setkey() failed flags=%x\n",
539                                        crypto_ablkcipher_get_flags(tfm));
540
541                                 if (!template[i].fail) {
542                                         kfree(data);
543                                         goto out;
544                                 }
545                         }
546
547                         sg_init_one(&sg[0], data, template[i].ilen);
548
549                         ablkcipher_request_set_crypt(req, sg, sg,
550                                                      template[i].ilen, iv);
551                         ret = enc ?
552                                 crypto_ablkcipher_encrypt(req) :
553                                 crypto_ablkcipher_decrypt(req);
554
555                         switch (ret) {
556                         case 0:
557                                 break;
558                         case -EINPROGRESS:
559                         case -EBUSY:
560                                 ret = wait_for_completion_interruptible(
561                                         &result.completion);
562                                 if (!ret && !((ret = result.err))) {
563                                         INIT_COMPLETION(result.completion);
564                                         break;
565                                 }
566                                 /* fall through */
567                         default:
568                                 printk("%s () failed err=%d\n", e, -ret);
569                                 kfree(data);
570                                 goto out;
571                         }
572
573                         q = kmap(sg_page(&sg[0])) + sg[0].offset;
574                         hexdump(q, template[i].rlen);
575
576                         printk("%s\n",
577                                memcmp(q, template[i].result,
578                                       template[i].rlen) ? "fail" : "pass");
579                         kunmap(sg_page(&sg[0]));
580                 }
581                 kfree(data);
582         }
583
584         printk("\ntesting %s %s across pages (chunking)\n", algo, e);
585
586         j = 0;
587         for (i = 0; i < tcount; i++) {
588
589                 if (template[i].iv)
590                         memcpy(iv, template[i].iv, MAX_IVLEN);
591                 else
592                         memset(iv, 0, MAX_IVLEN);
593
594                 if (template[i].np) {
595                         j++;
596                         printk("test %u (%d bit key):\n",
597                         j, template[i].klen * 8);
598
599                         memset(xbuf, 0, XBUFSIZE);
600                         crypto_ablkcipher_clear_flags(tfm, ~0);
601                         if (template[i].wk)
602                                 crypto_ablkcipher_set_flags(
603                                         tfm, CRYPTO_TFM_REQ_WEAK_KEY);
604
605                         ret = crypto_ablkcipher_setkey(tfm, template[i].key,
606                                                        template[i].klen);
607                         if (ret) {
608                                 printk("setkey() failed flags=%x\n",
609                                                 crypto_ablkcipher_get_flags(tfm));
610
611                                 if (!template[i].fail)
612                                         goto out;
613                         }
614
615                         temp = 0;
616                         sg_init_table(sg, template[i].np);
617                         for (k = 0; k < template[i].np; k++) {
618                                 memcpy(&xbuf[IDX[k]],
619                                                 template[i].input + temp,
620                                                 template[i].tap[k]);
621                                 temp += template[i].tap[k];
622                                 sg_set_buf(&sg[k], &xbuf[IDX[k]],
623                                                 template[i].tap[k]);
624                         }
625
626                         ablkcipher_request_set_crypt(req, sg, sg,
627                                         template[i].ilen, iv);
628
629                         ret = enc ?
630                                 crypto_ablkcipher_encrypt(req) :
631                                 crypto_ablkcipher_decrypt(req);
632
633                         switch (ret) {
634                         case 0:
635                                 break;
636                         case -EINPROGRESS:
637                         case -EBUSY:
638                                 ret = wait_for_completion_interruptible(
639                                         &result.completion);
640                                 if (!ret && !((ret = result.err))) {
641                                         INIT_COMPLETION(result.completion);
642                                         break;
643                                 }
644                                 /* fall through */
645                         default:
646                                 printk("%s () failed err=%d\n", e, -ret);
647                                 goto out;
648                         }
649
650                         temp = 0;
651                         for (k = 0; k < template[i].np; k++) {
652                                 printk("page %u\n", k);
653                                 q = kmap(sg_page(&sg[k])) + sg[k].offset;
654                                 hexdump(q, template[i].tap[k]);
655                                 printk("%s\n",
656                                         memcmp(q, template[i].result + temp,
657                                                 template[i].tap[k]) ? "fail" :
658                                         "pass");
659
660                                 for (n = 0; q[template[i].tap[k] + n]; n++)
661                                         ;
662                                 if (n) {
663                                         printk("Result buffer corruption %u "
664                                                "bytes:\n", n);
665                                         hexdump(&q[template[i].tap[k]], n);
666                                 }
667                                 temp += template[i].tap[k];
668                                 kunmap(sg_page(&sg[k]));
669                         }
670                 }
671         }
672 out:
673         crypto_free_ablkcipher(tfm);
674         ablkcipher_request_free(req);
675 }
676
677 static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
678                                int blen, int sec)
679 {
680         struct scatterlist sg[1];
681         unsigned long start, end;
682         int bcount;
683         int ret;
684
685         sg_init_one(sg, p, blen);
686
687         for (start = jiffies, end = start + sec * HZ, bcount = 0;
688              time_before(jiffies, end); bcount++) {
689                 if (enc)
690                         ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
691                 else
692                         ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
693
694                 if (ret)
695                         return ret;
696         }
697
698         printk("%d operations in %d seconds (%ld bytes)\n",
699                bcount, sec, (long)bcount * blen);
700         return 0;
701 }
702
703 static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p,
704                               int blen)
705 {
706         struct scatterlist sg[1];
707         unsigned long cycles = 0;
708         int ret = 0;
709         int i;
710
711         sg_init_one(sg, p, blen);
712
713         local_bh_disable();
714         local_irq_disable();
715
716         /* Warm-up run. */
717         for (i = 0; i < 4; i++) {
718                 if (enc)
719                         ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
720                 else
721                         ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
722
723                 if (ret)
724                         goto out;
725         }
726
727         /* The real thing. */
728         for (i = 0; i < 8; i++) {
729                 cycles_t start, end;
730
731                 start = get_cycles();
732                 if (enc)
733                         ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
734                 else
735                         ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
736                 end = get_cycles();
737
738                 if (ret)
739                         goto out;
740
741                 cycles += end - start;
742         }
743
744 out:
745         local_irq_enable();
746         local_bh_enable();
747
748         if (ret == 0)
749                 printk("1 operation in %lu cycles (%d bytes)\n",
750                        (cycles + 4) / 8, blen);
751
752         return ret;
753 }
754
755 static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
756
757 static void test_cipher_speed(char *algo, int enc, unsigned int sec,
758                               struct cipher_testvec *template,
759                               unsigned int tcount, u8 *keysize)
760 {
761         unsigned int ret, i, j, iv_len;
762         unsigned char *key, *p, iv[128];
763         struct crypto_blkcipher *tfm;
764         struct blkcipher_desc desc;
765         const char *e;
766         u32 *b_size;
767
768         if (enc == ENCRYPT)
769                 e = "encryption";
770         else
771                 e = "decryption";
772
773         printk("\ntesting speed of %s %s\n", algo, e);
774
775         tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
776
777         if (IS_ERR(tfm)) {
778                 printk("failed to load transform for %s: %ld\n", algo,
779                        PTR_ERR(tfm));
780                 return;
781         }
782         desc.tfm = tfm;
783         desc.flags = 0;
784
785         i = 0;
786         do {
787
788                 b_size = block_sizes;
789                 do {
790
791                         if ((*keysize + *b_size) > TVMEMSIZE) {
792                                 printk("template (%u) too big for tvmem (%u)\n",
793                                                 *keysize + *b_size, TVMEMSIZE);
794                                 goto out;
795                         }
796
797                         printk("test %u (%d bit key, %d byte blocks): ", i,
798                                         *keysize * 8, *b_size);
799
800                         memset(tvmem, 0xff, *keysize + *b_size);
801
802                         /* set key, plain text and IV */
803                         key = (unsigned char *)tvmem;
804                         for (j = 0; j < tcount; j++) {
805                                 if (template[j].klen == *keysize) {
806                                         key = template[j].key;
807                                         break;
808                                 }
809                         }
810                         p = (unsigned char *)tvmem + *keysize;
811
812                         ret = crypto_blkcipher_setkey(tfm, key, *keysize);
813                         if (ret) {
814                                 printk("setkey() failed flags=%x\n",
815                                                 crypto_blkcipher_get_flags(tfm));
816                                 goto out;
817                         }
818
819                         iv_len = crypto_blkcipher_ivsize(tfm);
820                         if (iv_len) {
821                                 memset(&iv, 0xff, iv_len);
822                                 crypto_blkcipher_set_iv(tfm, iv, iv_len);
823                         }
824
825                         if (sec)
826                                 ret = test_cipher_jiffies(&desc, enc, p, *b_size, sec);
827                         else
828                                 ret = test_cipher_cycles(&desc, enc, p, *b_size);
829
830                         if (ret) {
831                                 printk("%s() failed flags=%x\n", e, desc.flags);
832                                 break;
833                         }
834                         b_size++;
835                         i++;
836                 } while (*b_size);
837                 keysize++;
838         } while (*keysize);
839
840 out:
841         crypto_free_blkcipher(tfm);
842 }
843
844 static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen,
845                                     char *out, int sec)
846 {
847         struct scatterlist sg[1];
848         unsigned long start, end;
849         int bcount;
850         int ret;
851
852         sg_init_table(sg, 1);
853
854         for (start = jiffies, end = start + sec * HZ, bcount = 0;
855              time_before(jiffies, end); bcount++) {
856                 sg_set_buf(sg, p, blen);
857                 ret = crypto_hash_digest(desc, sg, blen, out);
858                 if (ret)
859                         return ret;
860         }
861
862         printk("%6u opers/sec, %9lu bytes/sec\n",
863                bcount / sec, ((long)bcount * blen) / sec);
864
865         return 0;
866 }
867
868 static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen,
869                              int plen, char *out, int sec)
870 {
871         struct scatterlist sg[1];
872         unsigned long start, end;
873         int bcount, pcount;
874         int ret;
875
876         if (plen == blen)
877                 return test_hash_jiffies_digest(desc, p, blen, out, sec);
878
879         sg_init_table(sg, 1);
880
881         for (start = jiffies, end = start + sec * HZ, bcount = 0;
882              time_before(jiffies, end); bcount++) {
883                 ret = crypto_hash_init(desc);
884                 if (ret)
885                         return ret;
886                 for (pcount = 0; pcount < blen; pcount += plen) {
887                         sg_set_buf(sg, p + pcount, plen);
888                         ret = crypto_hash_update(desc, sg, plen);
889                         if (ret)
890                                 return ret;
891                 }
892                 /* we assume there is enough space in 'out' for the result */
893                 ret = crypto_hash_final(desc, out);
894                 if (ret)
895                         return ret;
896         }
897
898         printk("%6u opers/sec, %9lu bytes/sec\n",
899                bcount / sec, ((long)bcount * blen) / sec);
900
901         return 0;
902 }
903
904 static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen,
905                                    char *out)
906 {
907         struct scatterlist sg[1];
908         unsigned long cycles = 0;
909         int i;
910         int ret;
911
912         sg_init_table(sg, 1);
913
914         local_bh_disable();
915         local_irq_disable();
916
917         /* Warm-up run. */
918         for (i = 0; i < 4; i++) {
919                 sg_set_buf(sg, p, blen);
920                 ret = crypto_hash_digest(desc, sg, blen, out);
921                 if (ret)
922                         goto out;
923         }
924
925         /* The real thing. */
926         for (i = 0; i < 8; i++) {
927                 cycles_t start, end;
928
929                 start = get_cycles();
930
931                 sg_set_buf(sg, p, blen);
932                 ret = crypto_hash_digest(desc, sg, blen, out);
933                 if (ret)
934                         goto out;
935
936                 end = get_cycles();
937
938                 cycles += end - start;
939         }
940
941 out:
942         local_irq_enable();
943         local_bh_enable();
944
945         if (ret)
946                 return ret;
947
948         printk("%6lu cycles/operation, %4lu cycles/byte\n",
949                cycles / 8, cycles / (8 * blen));
950
951         return 0;
952 }
953
954 static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
955                             int plen, char *out)
956 {
957         struct scatterlist sg[1];
958         unsigned long cycles = 0;
959         int i, pcount;
960         int ret;
961
962         if (plen == blen)
963                 return test_hash_cycles_digest(desc, p, blen, out);
964
965         sg_init_table(sg, 1);
966
967         local_bh_disable();
968         local_irq_disable();
969
970         /* Warm-up run. */
971         for (i = 0; i < 4; i++) {
972                 ret = crypto_hash_init(desc);
973                 if (ret)
974                         goto out;
975                 for (pcount = 0; pcount < blen; pcount += plen) {
976                         sg_set_buf(sg, p + pcount, plen);
977                         ret = crypto_hash_update(desc, sg, plen);
978                         if (ret)
979                                 goto out;
980                 }
981                 ret = crypto_hash_final(desc, out);
982                 if (ret)
983                         goto out;
984         }
985
986         /* The real thing. */
987         for (i = 0; i < 8; i++) {
988                 cycles_t start, end;
989
990                 start = get_cycles();
991
992                 ret = crypto_hash_init(desc);
993                 if (ret)
994                         goto out;
995                 for (pcount = 0; pcount < blen; pcount += plen) {
996                         sg_set_buf(sg, p + pcount, plen);
997                         ret = crypto_hash_update(desc, sg, plen);
998                         if (ret)
999                                 goto out;
1000                 }
1001                 ret = crypto_hash_final(desc, out);
1002                 if (ret)
1003                         goto out;
1004
1005                 end = get_cycles();
1006
1007                 cycles += end - start;
1008         }
1009
1010 out:
1011         local_irq_enable();
1012         local_bh_enable();
1013
1014         if (ret)
1015                 return ret;
1016
1017         printk("%6lu cycles/operation, %4lu cycles/byte\n",
1018                cycles / 8, cycles / (8 * blen));
1019
1020         return 0;
1021 }
1022
1023 static void test_hash_speed(char *algo, unsigned int sec,
1024                               struct hash_speed *speed)
1025 {
1026         struct crypto_hash *tfm;
1027         struct hash_desc desc;
1028         char output[1024];
1029         int i;
1030         int ret;
1031
1032         printk("\ntesting speed of %s\n", algo);
1033
1034         tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
1035
1036         if (IS_ERR(tfm)) {
1037                 printk("failed to load transform for %s: %ld\n", algo,
1038                        PTR_ERR(tfm));
1039                 return;
1040         }
1041
1042         desc.tfm = tfm;
1043         desc.flags = 0;
1044
1045         if (crypto_hash_digestsize(tfm) > sizeof(output)) {
1046                 printk("digestsize(%u) > outputbuffer(%zu)\n",
1047                        crypto_hash_digestsize(tfm), sizeof(output));
1048                 goto out;
1049         }
1050
1051         for (i = 0; speed[i].blen != 0; i++) {
1052                 if (speed[i].blen > TVMEMSIZE) {
1053                         printk("template (%u) too big for tvmem (%u)\n",
1054                                speed[i].blen, TVMEMSIZE);
1055                         goto out;
1056                 }
1057
1058                 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
1059                        i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
1060
1061                 memset(tvmem, 0xff, speed[i].blen);
1062
1063                 if (sec)
1064                         ret = test_hash_jiffies(&desc, tvmem, speed[i].blen,
1065                                                 speed[i].plen, output, sec);
1066                 else
1067                         ret = test_hash_cycles(&desc, tvmem, speed[i].blen,
1068                                                speed[i].plen, output);
1069
1070                 if (ret) {
1071                         printk("hashing failed ret=%d\n", ret);
1072                         break;
1073                 }
1074         }
1075
1076 out:
1077         crypto_free_hash(tfm);
1078 }
1079
1080 static void test_comp(char *algo, struct comp_testvec *ctemplate,
1081                        struct comp_testvec *dtemplate, int ctcount, int dtcount)
1082 {
1083         unsigned int i;
1084         char result[COMP_BUF_SIZE];
1085         struct crypto_comp *tfm;
1086         unsigned int tsize;
1087
1088         printk("\ntesting %s compression\n", algo);
1089
1090         tfm = crypto_alloc_comp(algo, 0, CRYPTO_ALG_ASYNC);
1091         if (IS_ERR(tfm)) {
1092                 printk("failed to load transform for %s\n", algo);
1093                 return;
1094         }
1095
1096         for (i = 0; i < ctcount; i++) {
1097                 int ilen, ret, dlen = COMP_BUF_SIZE;
1098
1099                 printk("test %u:\n", i + 1);
1100                 memset(result, 0, sizeof (result));
1101
1102                 ilen = ctemplate[i].inlen;
1103                 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1104                                            ilen, result, &dlen);
1105                 if (ret) {
1106                         printk("fail: ret=%d\n", ret);
1107                         continue;
1108                 }
1109                 hexdump(result, dlen);
1110                 printk("%s (ratio %d:%d)\n",
1111                        memcmp(result, ctemplate[i].output, dlen) ? "fail" : "pass",
1112                        ilen, dlen);
1113         }
1114
1115         printk("\ntesting %s decompression\n", algo);
1116
1117         tsize = sizeof(struct comp_testvec);
1118         tsize *= dtcount;
1119         if (tsize > TVMEMSIZE) {
1120                 printk("template (%u) too big for tvmem (%u)\n", tsize,
1121                        TVMEMSIZE);
1122                 goto out;
1123         }
1124
1125         for (i = 0; i < dtcount; i++) {
1126                 int ilen, ret, dlen = COMP_BUF_SIZE;
1127
1128                 printk("test %u:\n", i + 1);
1129                 memset(result, 0, sizeof (result));
1130
1131                 ilen = dtemplate[i].inlen;
1132                 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1133                                              ilen, result, &dlen);
1134                 if (ret) {
1135                         printk("fail: ret=%d\n", ret);
1136                         continue;
1137                 }
1138                 hexdump(result, dlen);
1139                 printk("%s (ratio %d:%d)\n",
1140                        memcmp(result, dtemplate[i].output, dlen) ? "fail" : "pass",
1141                        ilen, dlen);
1142         }
1143 out:
1144         crypto_free_comp(tfm);
1145 }
1146
1147 static void test_available(void)
1148 {
1149         char **name = check;
1150
1151         while (*name) {
1152                 printk("alg %s ", *name);
1153                 printk(crypto_has_alg(*name, 0, 0) ?
1154                        "found\n" : "not found\n");
1155                 name++;
1156         }
1157 }
1158
1159 static void do_test(void)
1160 {
1161         switch (mode) {
1162
1163         case 0:
1164                 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
1165
1166                 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
1167
1168                 //DES
1169                 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
1170                             DES_ENC_TEST_VECTORS);
1171                 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
1172                             DES_DEC_TEST_VECTORS);
1173                 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
1174                             DES_CBC_ENC_TEST_VECTORS);
1175                 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
1176                             DES_CBC_DEC_TEST_VECTORS);
1177
1178                 //DES3_EDE
1179                 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
1180                             DES3_EDE_ENC_TEST_VECTORS);
1181                 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1182                             DES3_EDE_DEC_TEST_VECTORS);
1183
1184                 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1185
1186                 test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
1187
1188                 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1189
1190                 //BLOWFISH
1191                 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
1192                             BF_ENC_TEST_VECTORS);
1193                 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
1194                             BF_DEC_TEST_VECTORS);
1195                 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
1196                             BF_CBC_ENC_TEST_VECTORS);
1197                 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
1198                             BF_CBC_DEC_TEST_VECTORS);
1199
1200                 //TWOFISH
1201                 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
1202                             TF_ENC_TEST_VECTORS);
1203                 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
1204                             TF_DEC_TEST_VECTORS);
1205                 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
1206                             TF_CBC_ENC_TEST_VECTORS);
1207                 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
1208                             TF_CBC_DEC_TEST_VECTORS);
1209
1210                 //SERPENT
1211                 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
1212                             SERPENT_ENC_TEST_VECTORS);
1213                 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
1214                             SERPENT_DEC_TEST_VECTORS);
1215
1216                 //TNEPRES
1217                 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1218                             TNEPRES_ENC_TEST_VECTORS);
1219                 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1220                             TNEPRES_DEC_TEST_VECTORS);
1221
1222                 //AES
1223                 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
1224                             AES_ENC_TEST_VECTORS);
1225                 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
1226                             AES_DEC_TEST_VECTORS);
1227                 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
1228                             AES_CBC_ENC_TEST_VECTORS);
1229                 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
1230                             AES_CBC_DEC_TEST_VECTORS);
1231                 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
1232                             AES_LRW_ENC_TEST_VECTORS);
1233                 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
1234                             AES_LRW_DEC_TEST_VECTORS);
1235                 test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
1236                             AES_XTS_ENC_TEST_VECTORS);
1237                 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
1238                             AES_XTS_DEC_TEST_VECTORS);
1239                 test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
1240                             AES_CTR_ENC_TEST_VECTORS);
1241                 test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
1242                             AES_CTR_DEC_TEST_VECTORS);
1243                 test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
1244                           AES_GCM_ENC_TEST_VECTORS);
1245                 test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
1246                           AES_GCM_DEC_TEST_VECTORS);
1247                 test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template,
1248                           AES_CCM_ENC_TEST_VECTORS);
1249                 test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template,
1250                           AES_CCM_DEC_TEST_VECTORS);
1251
1252                 //CAST5
1253                 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1254                             CAST5_ENC_TEST_VECTORS);
1255                 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1256                             CAST5_DEC_TEST_VECTORS);
1257
1258                 //CAST6
1259                 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1260                             CAST6_ENC_TEST_VECTORS);
1261                 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1262                             CAST6_DEC_TEST_VECTORS);
1263
1264                 //ARC4
1265                 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1266                             ARC4_ENC_TEST_VECTORS);
1267                 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1268                             ARC4_DEC_TEST_VECTORS);
1269
1270                 //TEA
1271                 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1272                             TEA_ENC_TEST_VECTORS);
1273                 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1274                             TEA_DEC_TEST_VECTORS);
1275
1276
1277                 //XTEA
1278                 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1279                             XTEA_ENC_TEST_VECTORS);
1280                 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1281                             XTEA_DEC_TEST_VECTORS);
1282
1283                 //KHAZAD
1284                 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1285                             KHAZAD_ENC_TEST_VECTORS);
1286                 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1287                             KHAZAD_DEC_TEST_VECTORS);
1288
1289                 //ANUBIS
1290                 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1291                             ANUBIS_ENC_TEST_VECTORS);
1292                 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1293                             ANUBIS_DEC_TEST_VECTORS);
1294                 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1295                             ANUBIS_CBC_ENC_TEST_VECTORS);
1296                 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1297                             ANUBIS_CBC_ENC_TEST_VECTORS);
1298
1299                 //XETA
1300                 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1301                             XETA_ENC_TEST_VECTORS);
1302                 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1303                             XETA_DEC_TEST_VECTORS);
1304
1305                 //FCrypt
1306                 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1307                             FCRYPT_ENC_TEST_VECTORS);
1308                 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1309                             FCRYPT_DEC_TEST_VECTORS);
1310
1311                 //CAMELLIA
1312                 test_cipher("ecb(camellia)", ENCRYPT,
1313                             camellia_enc_tv_template,
1314                             CAMELLIA_ENC_TEST_VECTORS);
1315                 test_cipher("ecb(camellia)", DECRYPT,
1316                             camellia_dec_tv_template,
1317                             CAMELLIA_DEC_TEST_VECTORS);
1318                 test_cipher("cbc(camellia)", ENCRYPT,
1319                             camellia_cbc_enc_tv_template,
1320                             CAMELLIA_CBC_ENC_TEST_VECTORS);
1321                 test_cipher("cbc(camellia)", DECRYPT,
1322                             camellia_cbc_dec_tv_template,
1323                             CAMELLIA_CBC_DEC_TEST_VECTORS);
1324
1325                 //SEED
1326                 test_cipher("ecb(seed)", ENCRYPT, seed_enc_tv_template,
1327                             SEED_ENC_TEST_VECTORS);
1328                 test_cipher("ecb(seed)", DECRYPT, seed_dec_tv_template,
1329                             SEED_DEC_TEST_VECTORS);
1330
1331                 //CTS
1332                 test_cipher("cts(cbc(aes))", ENCRYPT, cts_mode_enc_tv_template,
1333                             CTS_MODE_ENC_TEST_VECTORS);
1334                 test_cipher("cts(cbc(aes))", DECRYPT, cts_mode_dec_tv_template,
1335                             CTS_MODE_DEC_TEST_VECTORS);
1336
1337                 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1338                 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1339                 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1340                 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1341                 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1342                 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1343                 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1344                 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1345                 test_comp("deflate", deflate_comp_tv_template,
1346                           deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
1347                           DEFLATE_DECOMP_TEST_VECTORS);
1348                 test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template,
1349                           LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
1350                 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1351                 test_hash("hmac(md5)", hmac_md5_tv_template,
1352                           HMAC_MD5_TEST_VECTORS);
1353                 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1354                           HMAC_SHA1_TEST_VECTORS);
1355                 test_hash("hmac(sha224)", hmac_sha224_tv_template,
1356                           HMAC_SHA224_TEST_VECTORS);
1357                 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1358                           HMAC_SHA256_TEST_VECTORS);
1359                 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1360                           HMAC_SHA384_TEST_VECTORS);
1361                 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1362                           HMAC_SHA512_TEST_VECTORS);
1363
1364                 test_hash("xcbc(aes)", aes_xcbc128_tv_template,
1365                           XCBC_AES_TEST_VECTORS);
1366
1367                 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1368                 break;
1369
1370         case 1:
1371                 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
1372                 break;
1373
1374         case 2:
1375                 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
1376                 break;
1377
1378         case 3:
1379                 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
1380                             DES_ENC_TEST_VECTORS);
1381                 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
1382                             DES_DEC_TEST_VECTORS);
1383                 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
1384                             DES_CBC_ENC_TEST_VECTORS);
1385                 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
1386                             DES_CBC_DEC_TEST_VECTORS);
1387                 break;
1388
1389         case 4:
1390                 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
1391                             DES3_EDE_ENC_TEST_VECTORS);
1392                 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1393                             DES3_EDE_DEC_TEST_VECTORS);
1394                 break;
1395
1396         case 5:
1397                 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1398                 break;
1399
1400         case 6:
1401                 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1402                 break;
1403
1404         case 7:
1405                 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
1406                             BF_ENC_TEST_VECTORS);
1407                 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
1408                             BF_DEC_TEST_VECTORS);
1409                 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
1410                             BF_CBC_ENC_TEST_VECTORS);
1411                 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
1412                             BF_CBC_DEC_TEST_VECTORS);
1413                 break;
1414
1415         case 8:
1416                 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
1417                             TF_ENC_TEST_VECTORS);
1418                 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
1419                             TF_DEC_TEST_VECTORS);
1420                 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
1421                             TF_CBC_ENC_TEST_VECTORS);
1422                 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
1423                             TF_CBC_DEC_TEST_VECTORS);
1424                 break;
1425
1426         case 9:
1427                 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
1428                             SERPENT_ENC_TEST_VECTORS);
1429                 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
1430                             SERPENT_DEC_TEST_VECTORS);
1431                 break;
1432
1433         case 10:
1434                 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
1435                             AES_ENC_TEST_VECTORS);
1436                 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
1437                             AES_DEC_TEST_VECTORS);
1438                 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
1439                             AES_CBC_ENC_TEST_VECTORS);
1440                 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
1441                             AES_CBC_DEC_TEST_VECTORS);
1442                 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
1443                             AES_LRW_ENC_TEST_VECTORS);
1444                 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
1445                             AES_LRW_DEC_TEST_VECTORS);
1446                 test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
1447                             AES_XTS_ENC_TEST_VECTORS);
1448                 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
1449                             AES_XTS_DEC_TEST_VECTORS);
1450                 test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
1451                             AES_CTR_ENC_TEST_VECTORS);
1452                 test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
1453                             AES_CTR_DEC_TEST_VECTORS);
1454                 break;
1455
1456         case 11:
1457                 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1458                 break;
1459
1460         case 12:
1461                 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1462                 break;
1463
1464         case 13:
1465                 test_comp("deflate", deflate_comp_tv_template,
1466                           deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
1467                           DEFLATE_DECOMP_TEST_VECTORS);
1468                 break;
1469
1470         case 14:
1471                 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1472                             CAST5_ENC_TEST_VECTORS);
1473                 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1474                             CAST5_DEC_TEST_VECTORS);
1475                 break;
1476
1477         case 15:
1478                 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1479                             CAST6_ENC_TEST_VECTORS);
1480                 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1481                             CAST6_DEC_TEST_VECTORS);
1482                 break;
1483
1484         case 16:
1485                 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1486                             ARC4_ENC_TEST_VECTORS);
1487                 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1488                             ARC4_DEC_TEST_VECTORS);
1489                 break;
1490
1491         case 17:
1492                 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1493                 break;
1494
1495         case 18:
1496                 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1497                 break;
1498
1499         case 19:
1500                 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1501                             TEA_ENC_TEST_VECTORS);
1502                 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1503                             TEA_DEC_TEST_VECTORS);
1504                 break;
1505
1506         case 20:
1507                 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1508                             XTEA_ENC_TEST_VECTORS);
1509                 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1510                             XTEA_DEC_TEST_VECTORS);
1511                 break;
1512
1513         case 21:
1514                 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1515                             KHAZAD_ENC_TEST_VECTORS);
1516                 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1517                             KHAZAD_DEC_TEST_VECTORS);
1518                 break;
1519
1520         case 22:
1521                 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1522                 break;
1523
1524         case 23:
1525                 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1526                 break;
1527
1528         case 24:
1529                 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1530                 break;
1531
1532         case 25:
1533                 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1534                             TNEPRES_ENC_TEST_VECTORS);
1535                 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1536                             TNEPRES_DEC_TEST_VECTORS);
1537                 break;
1538
1539         case 26:
1540                 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1541                             ANUBIS_ENC_TEST_VECTORS);
1542                 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1543                             ANUBIS_DEC_TEST_VECTORS);
1544                 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1545                             ANUBIS_CBC_ENC_TEST_VECTORS);
1546                 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1547                             ANUBIS_CBC_ENC_TEST_VECTORS);
1548                 break;
1549
1550         case 27:
1551                 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1552                 break;
1553
1554         case 28:
1555
1556                 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1557                 break;
1558
1559         case 29:
1560                 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1561                 break;
1562                 
1563         case 30:
1564                 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1565                             XETA_ENC_TEST_VECTORS);
1566                 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1567                             XETA_DEC_TEST_VECTORS);
1568                 break;
1569
1570         case 31:
1571                 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1572                             FCRYPT_ENC_TEST_VECTORS);
1573                 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1574                             FCRYPT_DEC_TEST_VECTORS);
1575                 break;
1576
1577         case 32:
1578                 test_cipher("ecb(camellia)", ENCRYPT,
1579                             camellia_enc_tv_template,
1580                             CAMELLIA_ENC_TEST_VECTORS);
1581                 test_cipher("ecb(camellia)", DECRYPT,
1582                             camellia_dec_tv_template,
1583                             CAMELLIA_DEC_TEST_VECTORS);
1584                 test_cipher("cbc(camellia)", ENCRYPT,
1585                             camellia_cbc_enc_tv_template,
1586                             CAMELLIA_CBC_ENC_TEST_VECTORS);
1587                 test_cipher("cbc(camellia)", DECRYPT,
1588                             camellia_cbc_dec_tv_template,
1589                             CAMELLIA_CBC_DEC_TEST_VECTORS);
1590                 break;
1591         case 33:
1592                 test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
1593                 break;
1594
1595         case 34:
1596                 test_cipher("salsa20", ENCRYPT,
1597                             salsa20_stream_enc_tv_template,
1598                             SALSA20_STREAM_ENC_TEST_VECTORS);
1599                 break;
1600
1601         case 35:
1602                 test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
1603                           AES_GCM_ENC_TEST_VECTORS);
1604                 test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
1605                           AES_GCM_DEC_TEST_VECTORS);
1606                 break;
1607
1608         case 36:
1609                 test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template,
1610                           LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
1611                 break;
1612
1613         case 37:
1614                 test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template,
1615                           AES_CCM_ENC_TEST_VECTORS);
1616                 test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template,
1617                           AES_CCM_DEC_TEST_VECTORS);
1618                 break;
1619
1620         case 38:
1621                 test_cipher("cts(cbc(aes))", ENCRYPT, cts_mode_enc_tv_template,
1622                             CTS_MODE_ENC_TEST_VECTORS);
1623                 test_cipher("cts(cbc(aes))", DECRYPT, cts_mode_dec_tv_template,
1624                             CTS_MODE_DEC_TEST_VECTORS);
1625                 break;
1626
1627         case 39:
1628                 test_hash("rmd128", rmd128_tv_template, RMD128_TEST_VECTORS);
1629                 break;
1630
1631         case 40:
1632                 test_hash("rmd160", rmd160_tv_template, RMD160_TEST_VECTORS);
1633                 break;
1634
1635         case 100:
1636                 test_hash("hmac(md5)", hmac_md5_tv_template,
1637                           HMAC_MD5_TEST_VECTORS);
1638                 break;
1639
1640         case 101:
1641                 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1642                           HMAC_SHA1_TEST_VECTORS);
1643                 break;
1644
1645         case 102:
1646                 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1647                           HMAC_SHA256_TEST_VECTORS);
1648                 break;
1649
1650         case 103:
1651                 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1652                           HMAC_SHA384_TEST_VECTORS);
1653                 break;
1654
1655         case 104:
1656                 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1657                           HMAC_SHA512_TEST_VECTORS);
1658                 break;
1659
1660         case 105:
1661                 test_hash("hmac(sha224)", hmac_sha224_tv_template,
1662                           HMAC_SHA224_TEST_VECTORS);
1663                 break;
1664
1665         case 106:
1666                 test_hash("xcbc(aes)", aes_xcbc128_tv_template,
1667                           XCBC_AES_TEST_VECTORS);
1668                 break;
1669
1670         case 107:
1671                 test_hash("hmac(rmd128)", hmac_rmd128_tv_template,
1672                           HMAC_RMD128_TEST_VECTORS);
1673                 break;
1674
1675         case 108:
1676                 test_hash("hmac(rmd160)", hmac_rmd160_tv_template,
1677                           HMAC_RMD160_TEST_VECTORS);
1678                 break;
1679
1680         case 200:
1681                 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1682                                 speed_template_16_24_32);
1683                 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1684                                 speed_template_16_24_32);
1685                 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1686                                 speed_template_16_24_32);
1687                 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1688                                 speed_template_16_24_32);
1689                 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1690                                 speed_template_32_40_48);
1691                 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1692                                 speed_template_32_40_48);
1693                 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1694                                 speed_template_32_48_64);
1695                 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1696                                 speed_template_32_48_64);
1697                 break;
1698
1699         case 201:
1700                 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1701                                 des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
1702                                 speed_template_24);
1703                 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1704                                 des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
1705                                 speed_template_24);
1706                 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1707                                 des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
1708                                 speed_template_24);
1709                 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1710                                 des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
1711                                 speed_template_24);
1712                 break;
1713
1714         case 202:
1715                 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1716                                 speed_template_16_24_32);
1717                 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1718                                 speed_template_16_24_32);
1719                 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1720                                 speed_template_16_24_32);
1721                 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1722                                 speed_template_16_24_32);
1723                 break;
1724
1725         case 203:
1726                 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1727                                   speed_template_8_32);
1728                 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1729                                   speed_template_8_32);
1730                 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1731                                   speed_template_8_32);
1732                 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1733                                   speed_template_8_32);
1734                 break;
1735
1736         case 204:
1737                 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1738                                   speed_template_8);
1739                 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1740                                   speed_template_8);
1741                 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1742                                   speed_template_8);
1743                 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1744                                   speed_template_8);
1745                 break;
1746
1747         case 205:
1748                 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1749                                 speed_template_16_24_32);
1750                 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1751                                 speed_template_16_24_32);
1752                 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1753                                 speed_template_16_24_32);
1754                 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1755                                 speed_template_16_24_32);
1756                 break;
1757
1758         case 206:
1759                 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
1760                                   speed_template_16_32);
1761                 break;
1762
1763         case 300:
1764                 /* fall through */
1765
1766         case 301:
1767                 test_hash_speed("md4", sec, generic_hash_speed_template);
1768                 if (mode > 300 && mode < 400) break;
1769
1770         case 302:
1771                 test_hash_speed("md5", sec, generic_hash_speed_template);
1772                 if (mode > 300 && mode < 400) break;
1773
1774         case 303:
1775                 test_hash_speed("sha1", sec, generic_hash_speed_template);
1776                 if (mode > 300 && mode < 400) break;
1777
1778         case 304:
1779                 test_hash_speed("sha256", sec, generic_hash_speed_template);
1780                 if (mode > 300 && mode < 400) break;
1781
1782         case 305:
1783                 test_hash_speed("sha384", sec, generic_hash_speed_template);
1784                 if (mode > 300 && mode < 400) break;
1785
1786         case 306:
1787                 test_hash_speed("sha512", sec, generic_hash_speed_template);
1788                 if (mode > 300 && mode < 400) break;
1789
1790         case 307:
1791                 test_hash_speed("wp256", sec, generic_hash_speed_template);
1792                 if (mode > 300 && mode < 400) break;
1793
1794         case 308:
1795                 test_hash_speed("wp384", sec, generic_hash_speed_template);
1796                 if (mode > 300 && mode < 400) break;
1797
1798         case 309:
1799                 test_hash_speed("wp512", sec, generic_hash_speed_template);
1800                 if (mode > 300 && mode < 400) break;
1801
1802         case 310:
1803                 test_hash_speed("tgr128", sec, generic_hash_speed_template);
1804                 if (mode > 300 && mode < 400) break;
1805
1806         case 311:
1807                 test_hash_speed("tgr160", sec, generic_hash_speed_template);
1808                 if (mode > 300 && mode < 400) break;
1809
1810         case 312:
1811                 test_hash_speed("tgr192", sec, generic_hash_speed_template);
1812                 if (mode > 300 && mode < 400) break;
1813
1814         case 313:
1815                 test_hash_speed("sha224", sec, generic_hash_speed_template);
1816                 if (mode > 300 && mode < 400) break;
1817
1818         case 314:
1819                 test_hash_speed("rmd128", sec, generic_hash_speed_template);
1820                 if (mode > 300 && mode < 400) break;
1821
1822         case 315:
1823                 test_hash_speed("rmd160", sec, generic_hash_speed_template);
1824                 if (mode > 300 && mode < 400) break;
1825
1826         case 399:
1827                 break;
1828
1829         case 1000:
1830                 test_available();
1831                 break;
1832
1833         default:
1834                 /* useful for debugging */
1835                 printk("not testing anything\n");
1836                 break;
1837         }
1838 }
1839
1840 static int __init tcrypt_mod_init(void)
1841 {
1842         int err = -ENOMEM;
1843
1844         tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
1845         if (tvmem == NULL)
1846                 return err;
1847
1848         xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1849         if (xbuf == NULL)
1850                 goto err_free_tv;
1851
1852         axbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1853         if (axbuf == NULL)
1854                 goto err_free_xbuf;
1855
1856         do_test();
1857
1858         /* We intentionaly return -EAGAIN to prevent keeping
1859          * the module. It does all its work from init()
1860          * and doesn't offer any runtime functionality 
1861          * => we don't need it in the memory, do we?
1862          *                                        -- mludvig
1863          */
1864         err = -EAGAIN;
1865
1866         kfree(axbuf);
1867  err_free_xbuf:
1868         kfree(xbuf);
1869  err_free_tv:
1870         kfree(tvmem);
1871
1872         return err;
1873 }
1874
1875 /*
1876  * If an init function is provided, an exit function must also be provided
1877  * to allow module unload.
1878  */
1879 static void __exit tcrypt_mod_fini(void) { }
1880
1881 module_init(tcrypt_mod_init);
1882 module_exit(tcrypt_mod_fini);
1883
1884 module_param(mode, int, 0);
1885 module_param(sec, uint, 0);
1886 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
1887                       "(defaults to zero which uses CPU cycles instead)");
1888
1889 MODULE_LICENSE("GPL");
1890 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1891 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");