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