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