[PATCH] DVB: Documentation and Kconfig updazes
[linux-2.6/history.git] / crypto / tcrypt.c
blob6e1faab2a1643a079f4543279ab8cb18b79aa860
1 /*
2 * Quick & dirty crypto testing module.
4 * This will only exist until we have a better testing mechanism
5 * (e.g. a char device).
7 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
8 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
13 * any later version.
15 * 14 - 09 - 2003
16 * Rewritten by Kartikey Mahendra Bhatt
19 #include <linux/init.h>
20 #include <linux/module.h>
21 #include <linux/mm.h>
22 #include <linux/slab.h>
23 #include <asm/scatterlist.h>
24 #include <linux/string.h>
25 #include <linux/crypto.h>
26 #include <linux/highmem.h>
27 #include "tcrypt.h"
30 * Need to kmalloc() memory for testing kmap().
32 #define TVMEMSIZE 4096
33 #define XBUFSIZE 32768
36 * Indexes into the xbuf to simulate cross-page access.
38 #define IDX1 37
39 #define IDX2 32400
40 #define IDX3 1
41 #define IDX4 8193
42 #define IDX5 22222
43 #define IDX6 17101
44 #define IDX7 27333
45 #define IDX8 3000
48 * Used by test_cipher()
50 #define ENCRYPT 1
51 #define DECRYPT 0
52 #define MODE_ECB 1
53 #define MODE_CBC 0
55 static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
57 static int mode;
58 static char *xbuf;
59 static char *tvmem;
61 static char *check[] = {
62 "des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish",
63 "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6",
64 "arc4", "michael_mic", "deflate", NULL
67 static void
68 hexdump(unsigned char *buf, unsigned int len)
70 while (len--)
71 printk("%02x", *buf++);
73 printk("\n");
76 static void
77 test_hash (char * algo, struct hash_testvec * template, unsigned int tcount)
79 char *p;
80 unsigned int i, j, k, temp;
81 struct scatterlist sg[8];
82 char result[64];
83 struct crypto_tfm *tfm;
84 struct hash_testvec *hash_tv;
85 unsigned int tsize;
87 printk("\ntesting %s\n", algo);
89 tsize = sizeof (struct hash_testvec);
90 tsize *= tcount;
92 if (tsize > TVMEMSIZE) {
93 printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE);
94 return;
97 memcpy(tvmem, template, tsize);
98 hash_tv = (void *) tvmem;
99 tfm = crypto_alloc_tfm(algo, 0);
100 if (tfm == NULL) {
101 printk("failed to load transform for %s\n", algo);
102 return;
105 for (i = 0; i < tcount; i++) {
106 printk ("test %u:\n", i + 1);
107 memset (result, 0, 64);
109 p = hash_tv[i].plaintext;
110 sg[0].page = virt_to_page (p);
111 sg[0].offset = offset_in_page (p);
112 sg[0].length = hash_tv[i].psize;
114 crypto_digest_init (tfm);
115 if (tfm->crt_u.digest.dit_setkey) {
116 crypto_digest_setkey (tfm, hash_tv[i].key,
117 hash_tv[i].ksize);
119 crypto_digest_update (tfm, sg, 1);
120 crypto_digest_final (tfm, result);
122 hexdump (result, crypto_tfm_alg_digestsize (tfm));
123 printk("%s\n",
124 memcmp(result, hash_tv[i].digest,
125 crypto_tfm_alg_digestsize(tfm)) ? "fail" :
126 "pass");
129 printk ("testing %s across pages\n", algo);
131 /* setup the dummy buffer first */
132 memset(xbuf, 0, XBUFSIZE);
134 j = 0;
135 for (i = 0; i < tcount; i++) {
136 if (hash_tv[i].np) {
137 j++;
138 printk ("test %u:\n", j);
139 memset (result, 0, 64);
141 temp = 0;
142 for (k = 0; k < hash_tv[i].np; k++) {
143 memcpy (&xbuf[IDX[k]], hash_tv[i].plaintext + temp,
144 hash_tv[i].tap[k]);
145 temp += hash_tv[i].tap[k];
146 p = &xbuf[IDX[k]];
147 sg[k].page = virt_to_page (p);
148 sg[k].offset = offset_in_page (p);
149 sg[k].length = hash_tv[i].tap[k];
152 crypto_digest_digest (tfm, sg, hash_tv[i].np, result);
154 hexdump (result, crypto_tfm_alg_digestsize (tfm));
155 printk("%s\n",
156 memcmp(result, hash_tv[i].digest,
157 crypto_tfm_alg_digestsize(tfm)) ? "fail" :
158 "pass");
162 crypto_free_tfm (tfm);
166 #ifdef CONFIG_CRYPTO_HMAC
168 static void
169 test_hmac(char *algo, struct hmac_testvec * template, unsigned int tcount)
171 char *p;
172 unsigned int i, j, k, temp;
173 struct scatterlist sg[8];
174 char result[64];
175 struct crypto_tfm *tfm;
176 struct hmac_testvec *hmac_tv;
177 unsigned int tsize, klen;
179 tfm = crypto_alloc_tfm(algo, 0);
180 if (tfm == NULL) {
181 printk("failed to load transform for %s\n", algo);
182 return;
185 printk("\ntesting hmac_%s\n", algo);
187 tsize = sizeof (struct hmac_testvec);
188 tsize *= tcount;
189 if (tsize > TVMEMSIZE) {
190 printk("template (%u) too big for tvmem (%u)\n", tsize,
191 TVMEMSIZE);
192 goto out;
195 memcpy(tvmem, template, tsize);
196 hmac_tv = (void *) tvmem;
198 for (i = 0; i < tcount; i++) {
199 printk("test %u:\n", i + 1);
200 memset(result, 0, sizeof (result));
202 p = hmac_tv[i].plaintext;
203 klen = hmac_tv[i].ksize;
204 sg[0].page = virt_to_page(p);
205 sg[0].offset = offset_in_page(p);
206 sg[0].length = hmac_tv[i].psize;
208 crypto_hmac(tfm, hmac_tv[i].key, &klen, sg, 1, result);
210 hexdump(result, crypto_tfm_alg_digestsize(tfm));
211 printk("%s\n",
212 memcmp(result, hmac_tv[i].digest,
213 crypto_tfm_alg_digestsize(tfm)) ? "fail" :
214 "pass");
217 printk("\ntesting hmac_%s across pages\n", algo);
219 memset(xbuf, 0, XBUFSIZE);
221 j = 0;
222 for (i = 0; i < tcount; i++) {
223 if (hmac_tv[i].np) {
224 j++;
225 printk ("test %u:\n",j);
226 memset (result, 0, 64);
228 temp = 0;
229 klen = hmac_tv[i].ksize;
230 for (k = 0; k < hmac_tv[i].np; k++) {
231 memcpy (&xbuf[IDX[k]], hmac_tv[i].plaintext + temp,
232 hmac_tv[i].tap[k]);
233 temp += hmac_tv[i].tap[k];
234 p = &xbuf[IDX[k]];
235 sg[k].page = virt_to_page (p);
236 sg[k].offset = offset_in_page (p);
237 sg[k].length = hmac_tv[i].tap[k];
240 crypto_hmac(tfm, hmac_tv[i].key, &klen, sg, hmac_tv[i].np,
241 result);
242 hexdump(result, crypto_tfm_alg_digestsize(tfm));
244 printk("%s\n",
245 memcmp(result, hmac_tv[i].digest,
246 crypto_tfm_alg_digestsize(tfm)) ? "fail" :
247 "pass");
250 out:
251 crypto_free_tfm(tfm);
254 #endif /* CONFIG_CRYPTO_HMAC */
256 void
257 test_cipher(char * algo, int mode, int enc, struct cipher_testvec * template, unsigned int tcount)
259 unsigned int ret, i, j, k, temp;
260 unsigned int tsize;
261 char *p, *q;
262 struct crypto_tfm *tfm;
263 char *key;
264 struct cipher_testvec *cipher_tv;
265 struct scatterlist sg[8];
266 char e[11], m[4];
268 if (enc == ENCRYPT)
269 strncpy(e, "encryption", 11);
270 else
271 strncpy(e, "decryption", 11);
272 if (mode == MODE_ECB)
273 strncpy(m, "ECB", 4);
274 else
275 strncpy(m, "CBC", 4);
277 printk("\ntesting %s %s %s \n", algo, m, e);
279 tsize = sizeof (struct cipher_testvec);
280 tsize *= tcount;
282 if (tsize > TVMEMSIZE) {
283 printk("template (%u) too big for tvmem (%u)\n", tsize,
284 TVMEMSIZE);
285 return;
288 memcpy(tvmem, template, tsize);
289 cipher_tv = (void *) tvmem;
291 if (mode)
292 tfm = crypto_alloc_tfm (algo, 0);
293 else
294 tfm = crypto_alloc_tfm (algo, CRYPTO_TFM_MODE_CBC);
296 if (tfm == NULL) {
297 printk("failed to load transform for %s %s\n", algo, m);
298 return;
301 j = 0;
302 for (i = 0; i < tcount; i++) {
303 if (!(cipher_tv[i].np)) {
304 j++;
305 printk("test %u (%d bit key):\n",
306 j, cipher_tv[i].klen * 8);
308 tfm->crt_flags = 0;
309 if (cipher_tv[i].wk)
310 tfm->crt_flags |= CRYPTO_TFM_REQ_WEAK_KEY;
311 key = cipher_tv[i].key;
313 ret = crypto_cipher_setkey(tfm, key, cipher_tv[i].klen);
314 if (ret) {
315 printk("setkey() failed flags=%x\n", tfm->crt_flags);
317 if (!cipher_tv[i].fail)
318 goto out;
321 p = cipher_tv[i].input;
322 sg[0].page = virt_to_page(p);
323 sg[0].offset = offset_in_page(p);
324 sg[0].length = cipher_tv[i].ilen;
326 if (!mode) {
327 crypto_cipher_set_iv(tfm, cipher_tv[i].iv,
328 crypto_tfm_alg_ivsize (tfm));
331 if (enc)
332 ret = crypto_cipher_encrypt(tfm, sg, sg, cipher_tv[i].ilen);
333 else
334 ret = crypto_cipher_decrypt(tfm, sg, sg, cipher_tv[i].ilen);
337 if (ret) {
338 printk("%s () failed flags=%x\n", e, tfm->crt_flags);
339 goto out;
342 q = kmap(sg[0].page) + sg[0].offset;
343 hexdump(q, cipher_tv[i].rlen);
345 printk("%s\n",
346 memcmp(q, cipher_tv[i].result, cipher_tv[i].rlen) ? "fail" :
347 "pass");
351 printk("\ntesting %s %s %s across pages (chunking) \n", algo, m, e);
352 memset(xbuf, 0, XBUFSIZE);
354 j = 0;
355 for (i = 0; i < tcount; i++) {
356 if (cipher_tv[i].np) {
357 j++;
358 printk("test %u (%d bit key):\n",
359 j, cipher_tv[i].klen * 8);
361 tfm->crt_flags = 0;
362 if (cipher_tv[i].wk)
363 tfm->crt_flags |= CRYPTO_TFM_REQ_WEAK_KEY;
364 key = cipher_tv[i].key;
366 ret = crypto_cipher_setkey(tfm, key, cipher_tv[i].klen);
367 if (ret) {
368 printk("setkey() failed flags=%x\n", tfm->crt_flags);
370 if (!cipher_tv[i].fail)
371 goto out;
374 temp = 0;
375 for (k = 0; k < cipher_tv[i].np; k++) {
376 memcpy (&xbuf[IDX[k]], cipher_tv[i].input + temp,
377 cipher_tv[i].tap[k]);
378 temp += cipher_tv[i].tap[k];
379 p = &xbuf[IDX[k]];
380 sg[k].page = virt_to_page (p);
381 sg[k].offset = offset_in_page (p);
382 sg[k].length = cipher_tv[i].tap[k];
385 if (!mode) {
386 crypto_cipher_set_iv(tfm, cipher_tv[i].iv,
387 crypto_tfm_alg_ivsize (tfm));
390 if (enc)
391 ret = crypto_cipher_encrypt(tfm, sg, sg, cipher_tv[i].ilen);
392 else
393 ret = crypto_cipher_decrypt(tfm, sg, sg, cipher_tv[i].ilen);
395 if (ret) {
396 printk("%s () failed flags=%x\n", e, tfm->crt_flags);
397 goto out;
400 temp = 0;
401 for (k = 0; k < cipher_tv[i].np; k++) {
402 printk("page %u\n", k);
403 q = kmap(sg[k].page) + sg[k].offset;
404 hexdump(q, cipher_tv[i].tap[k]);
405 printk("%s\n",
406 memcmp(q, cipher_tv[i].result + temp,
407 cipher_tv[i].tap[k]) ? "fail" :
408 "pass");
409 temp += cipher_tv[i].tap[k];
414 out:
415 crypto_free_tfm(tfm);
418 static void
419 test_deflate(void)
421 unsigned int i;
422 char result[COMP_BUF_SIZE];
423 struct crypto_tfm *tfm;
424 struct comp_testvec *tv;
425 unsigned int tsize;
427 printk("\ntesting deflate compression\n");
429 tsize = sizeof (deflate_comp_tv_template);
430 if (tsize > TVMEMSIZE) {
431 printk("template (%u) too big for tvmem (%u)\n", tsize,
432 TVMEMSIZE);
433 return;
436 memcpy(tvmem, deflate_comp_tv_template, tsize);
437 tv = (void *) tvmem;
439 tfm = crypto_alloc_tfm("deflate", 0);
440 if (tfm == NULL) {
441 printk("failed to load transform for deflate\n");
442 return;
445 for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) {
446 int ilen, ret, dlen = COMP_BUF_SIZE;
448 printk("test %u:\n", i + 1);
449 memset(result, 0, sizeof (result));
451 ilen = tv[i].inlen;
452 ret = crypto_comp_compress(tfm, tv[i].input,
453 ilen, result, &dlen);
454 if (ret) {
455 printk("fail: ret=%d\n", ret);
456 continue;
458 hexdump(result, dlen);
459 printk("%s (ratio %d:%d)\n",
460 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
461 ilen, dlen);
464 printk("\ntesting deflate decompression\n");
466 tsize = sizeof (deflate_decomp_tv_template);
467 if (tsize > TVMEMSIZE) {
468 printk("template (%u) too big for tvmem (%u)\n", tsize,
469 TVMEMSIZE);
470 goto out;
473 memcpy(tvmem, deflate_decomp_tv_template, tsize);
474 tv = (void *) tvmem;
476 for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) {
477 int ilen, ret, dlen = COMP_BUF_SIZE;
479 printk("test %u:\n", i + 1);
480 memset(result, 0, sizeof (result));
482 ilen = tv[i].inlen;
483 ret = crypto_comp_decompress(tfm, tv[i].input,
484 ilen, result, &dlen);
485 if (ret) {
486 printk("fail: ret=%d\n", ret);
487 continue;
489 hexdump(result, dlen);
490 printk("%s (ratio %d:%d)\n",
491 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
492 ilen, dlen);
494 out:
495 crypto_free_tfm(tfm);
498 static void
499 test_available(void)
501 char **name = check;
503 while (*name) {
504 printk("alg %s ", *name);
505 printk((crypto_alg_available(*name, 0)) ?
506 "found\n" : "not found\n");
507 name++;
511 static void
512 do_test(void)
514 switch (mode) {
516 case 0:
517 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
519 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
521 //DES
522 test_cipher ("des", MODE_ECB, ENCRYPT, des_enc_tv_template, DES_ENC_TEST_VECTORS);
523 test_cipher ("des", MODE_ECB, DECRYPT, des_dec_tv_template, DES_DEC_TEST_VECTORS);
524 test_cipher ("des", MODE_CBC, ENCRYPT, des_cbc_enc_tv_template, DES_CBC_ENC_TEST_VECTORS);
525 test_cipher ("des", MODE_CBC, DECRYPT, des_cbc_dec_tv_template, DES_CBC_DEC_TEST_VECTORS);
527 //DES3_EDE
528 test_cipher ("des3_ede", MODE_ECB, ENCRYPT, des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS);
529 test_cipher ("des3_ede", MODE_ECB, DECRYPT, des3_ede_dec_tv_template, DES3_EDE_DEC_TEST_VECTORS);
531 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
533 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
535 //BLOWFISH
536 test_cipher ("blowfish", MODE_ECB, ENCRYPT, bf_enc_tv_template, BF_ENC_TEST_VECTORS);
537 test_cipher ("blowfish", MODE_ECB, DECRYPT, bf_dec_tv_template, BF_DEC_TEST_VECTORS);
538 test_cipher ("blowfish", MODE_CBC, ENCRYPT, bf_cbc_enc_tv_template, BF_CBC_ENC_TEST_VECTORS);
539 test_cipher ("blowfish", MODE_CBC, DECRYPT, bf_cbc_dec_tv_template, BF_CBC_DEC_TEST_VECTORS);
541 //TWOFISH
542 test_cipher ("twofish", MODE_ECB, ENCRYPT, tf_enc_tv_template, TF_ENC_TEST_VECTORS);
543 test_cipher ("twofish", MODE_ECB, DECRYPT, tf_dec_tv_template, TF_DEC_TEST_VECTORS);
544 test_cipher ("twofish", MODE_CBC, ENCRYPT, tf_cbc_enc_tv_template, TF_CBC_ENC_TEST_VECTORS);
545 test_cipher ("twofish", MODE_CBC, DECRYPT, tf_cbc_dec_tv_template, TF_CBC_DEC_TEST_VECTORS);
547 //SERPENT
548 test_cipher ("serpent", MODE_ECB, ENCRYPT, serpent_enc_tv_template, SERPENT_ENC_TEST_VECTORS);
549 test_cipher ("serpent", MODE_ECB, DECRYPT, serpent_dec_tv_template, SERPENT_DEC_TEST_VECTORS);
551 //AES
552 test_cipher ("aes", MODE_ECB, ENCRYPT, aes_enc_tv_template, AES_ENC_TEST_VECTORS);
553 test_cipher ("aes", MODE_ECB, DECRYPT, aes_dec_tv_template, AES_DEC_TEST_VECTORS);
555 //CAST5
556 test_cipher ("cast5", MODE_ECB, ENCRYPT, cast5_enc_tv_template, CAST5_ENC_TEST_VECTORS);
557 test_cipher ("cast5", MODE_ECB, DECRYPT, cast5_dec_tv_template, CAST5_DEC_TEST_VECTORS);
559 //CAST6
560 test_cipher ("cast6", MODE_ECB, ENCRYPT, cast6_enc_tv_template, CAST6_ENC_TEST_VECTORS);
561 test_cipher ("cast6", MODE_ECB, DECRYPT, cast6_dec_tv_template, CAST6_DEC_TEST_VECTORS);
563 //ARC4
564 test_cipher ("arc4", MODE_ECB, ENCRYPT, arc4_enc_tv_template, ARC4_ENC_TEST_VECTORS);
565 test_cipher ("arc4", MODE_ECB, DECRYPT, arc4_dec_tv_template, ARC4_DEC_TEST_VECTORS);
567 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
568 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
569 test_deflate();
570 #ifdef CONFIG_CRYPTO_HMAC
571 test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS);
572 test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS);
573 test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS);
574 #endif
576 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
577 break;
579 case 1:
580 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
581 break;
583 case 2:
584 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
585 break;
587 case 3:
588 test_cipher ("des", MODE_ECB, ENCRYPT, des_enc_tv_template, DES_ENC_TEST_VECTORS);
589 test_cipher ("des", MODE_ECB, DECRYPT, des_dec_tv_template, DES_DEC_TEST_VECTORS);
590 test_cipher ("des", MODE_CBC, ENCRYPT, des_cbc_enc_tv_template, DES_CBC_ENC_TEST_VECTORS);
591 test_cipher ("des", MODE_CBC, DECRYPT, des_cbc_dec_tv_template, DES_CBC_DEC_TEST_VECTORS);
592 break;
594 case 4:
595 test_cipher ("des3_ede", MODE_ECB, ENCRYPT, des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS);
596 test_cipher ("des3_ede", MODE_ECB, DECRYPT, des3_ede_dec_tv_template, DES3_EDE_DEC_TEST_VECTORS);
597 break;
599 case 5:
600 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
601 break;
603 case 6:
604 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
605 break;
607 case 7:
608 test_cipher ("blowfish", MODE_ECB, ENCRYPT, bf_enc_tv_template, BF_ENC_TEST_VECTORS);
609 test_cipher ("blowfish", MODE_ECB, DECRYPT, bf_dec_tv_template, BF_DEC_TEST_VECTORS);
610 test_cipher ("blowfish", MODE_CBC, ENCRYPT, bf_cbc_enc_tv_template, BF_CBC_ENC_TEST_VECTORS);
611 test_cipher ("blowfish", MODE_CBC, DECRYPT, bf_cbc_dec_tv_template, BF_CBC_DEC_TEST_VECTORS);
612 break;
614 case 8:
615 test_cipher ("twofish", MODE_ECB, ENCRYPT, tf_enc_tv_template, TF_ENC_TEST_VECTORS);
616 test_cipher ("twofish", MODE_ECB, DECRYPT, tf_dec_tv_template, TF_DEC_TEST_VECTORS);
617 test_cipher ("twofish", MODE_CBC, ENCRYPT, tf_cbc_enc_tv_template, TF_CBC_ENC_TEST_VECTORS);
618 test_cipher ("twofish", MODE_CBC, DECRYPT, tf_cbc_dec_tv_template, TF_CBC_DEC_TEST_VECTORS);
619 break;
621 case 9:
622 break;
624 case 10:
625 test_cipher ("aes", MODE_ECB, ENCRYPT, aes_enc_tv_template, AES_ENC_TEST_VECTORS);
626 test_cipher ("aes", MODE_ECB, DECRYPT, aes_dec_tv_template, AES_DEC_TEST_VECTORS);
627 break;
629 case 11:
630 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
631 break;
633 case 12:
634 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
635 break;
637 case 13:
638 test_deflate();
639 break;
641 case 14:
642 test_cipher ("cast5", MODE_ECB, ENCRYPT, cast5_enc_tv_template, CAST5_ENC_TEST_VECTORS);
643 test_cipher ("cast5", MODE_ECB, DECRYPT, cast5_dec_tv_template, CAST5_DEC_TEST_VECTORS);
644 break;
646 case 15:
647 test_cipher ("cast6", MODE_ECB, ENCRYPT, cast6_enc_tv_template, CAST6_ENC_TEST_VECTORS);
648 test_cipher ("cast6", MODE_ECB, DECRYPT, cast6_dec_tv_template, CAST6_DEC_TEST_VECTORS);
649 break;
651 case 16:
652 test_cipher ("arc4", MODE_ECB, ENCRYPT, arc4_enc_tv_template, ARC4_ENC_TEST_VECTORS);
653 test_cipher ("arc4", MODE_ECB, DECRYPT, arc4_dec_tv_template, ARC4_DEC_TEST_VECTORS);
654 break;
656 case 17:
657 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
658 break;
660 #ifdef CONFIG_CRYPTO_HMAC
661 case 100:
662 test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS);
663 break;
665 case 101:
666 test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS);
667 break;
669 case 102:
670 test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS);
671 break;
673 #endif
675 case 1000:
676 test_available();
677 break;
679 default:
680 /* useful for debugging */
681 printk("not testing anything\n");
682 break;
686 static int __init
687 init(void)
689 tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
690 if (tvmem == NULL)
691 return -ENOMEM;
693 xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
694 if (xbuf == NULL) {
695 kfree(tvmem);
696 return -ENOMEM;
699 do_test();
701 kfree(xbuf);
702 kfree(tvmem);
703 return 0;
707 * If an init function is provided, an exit function must also be provided
708 * to allow module unload.
710 static void __exit fini(void) { }
712 module_init(init);
713 module_exit(fini);
715 MODULE_PARM(mode, "i");
717 MODULE_LICENSE("GPL");
718 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
719 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");