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)
16 * Rewritten by Kartikey Mahendra Bhatt
19 #include <linux/init.h>
20 #include <linux/module.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 <linux/moduleparam.h>
31 * Need to kmalloc() memory for testing kmap().
33 #define TVMEMSIZE 4096
34 #define XBUFSIZE 32768
37 * Indexes into the xbuf to simulate cross-page access.
49 * Used by test_cipher()
56 static unsigned int IDX
[8] = { IDX1
, IDX2
, IDX3
, IDX4
, IDX5
, IDX6
, IDX7
, IDX8
};
62 static char *check
[] = {
63 "des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish",
64 "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6",
65 "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
66 "khazad", "wp512", "wp384", "wp256", "tnepres", NULL
70 hexdump(unsigned char *buf
, unsigned int len
)
73 printk("%02x", *buf
++);
79 test_hash (char * algo
, struct hash_testvec
* template, unsigned int tcount
)
82 unsigned int i
, j
, k
, temp
;
83 struct scatterlist sg
[8];
85 struct crypto_tfm
*tfm
;
86 struct hash_testvec
*hash_tv
;
89 printk("\ntesting %s\n", algo
);
91 tsize
= sizeof (struct hash_testvec
);
94 if (tsize
> TVMEMSIZE
) {
95 printk("template (%u) too big for tvmem (%u)\n", tsize
, TVMEMSIZE
);
99 memcpy(tvmem
, template, tsize
);
100 hash_tv
= (void *) tvmem
;
101 tfm
= crypto_alloc_tfm(algo
, 0);
103 printk("failed to load transform for %s\n", algo
);
107 for (i
= 0; i
< tcount
; i
++) {
108 printk ("test %u:\n", i
+ 1);
109 memset (result
, 0, 64);
111 p
= hash_tv
[i
].plaintext
;
112 sg
[0].page
= virt_to_page (p
);
113 sg
[0].offset
= offset_in_page (p
);
114 sg
[0].length
= hash_tv
[i
].psize
;
116 crypto_digest_init (tfm
);
117 if (tfm
->crt_u
.digest
.dit_setkey
) {
118 crypto_digest_setkey (tfm
, hash_tv
[i
].key
,
121 crypto_digest_update (tfm
, sg
, 1);
122 crypto_digest_final (tfm
, result
);
124 hexdump (result
, crypto_tfm_alg_digestsize (tfm
));
126 memcmp(result
, hash_tv
[i
].digest
,
127 crypto_tfm_alg_digestsize(tfm
)) ? "fail" :
131 printk ("testing %s across pages\n", algo
);
133 /* setup the dummy buffer first */
134 memset(xbuf
, 0, XBUFSIZE
);
137 for (i
= 0; i
< tcount
; i
++) {
140 printk ("test %u:\n", j
);
141 memset (result
, 0, 64);
144 for (k
= 0; k
< hash_tv
[i
].np
; k
++) {
145 memcpy (&xbuf
[IDX
[k
]], hash_tv
[i
].plaintext
+ temp
,
147 temp
+= hash_tv
[i
].tap
[k
];
149 sg
[k
].page
= virt_to_page (p
);
150 sg
[k
].offset
= offset_in_page (p
);
151 sg
[k
].length
= hash_tv
[i
].tap
[k
];
154 crypto_digest_digest (tfm
, sg
, hash_tv
[i
].np
, result
);
156 hexdump (result
, crypto_tfm_alg_digestsize (tfm
));
158 memcmp(result
, hash_tv
[i
].digest
,
159 crypto_tfm_alg_digestsize(tfm
)) ? "fail" :
164 crypto_free_tfm (tfm
);
168 #ifdef CONFIG_CRYPTO_HMAC
171 test_hmac(char *algo
, struct hmac_testvec
* template, unsigned int tcount
)
174 unsigned int i
, j
, k
, temp
;
175 struct scatterlist sg
[8];
177 struct crypto_tfm
*tfm
;
178 struct hmac_testvec
*hmac_tv
;
179 unsigned int tsize
, klen
;
181 tfm
= crypto_alloc_tfm(algo
, 0);
183 printk("failed to load transform for %s\n", algo
);
187 printk("\ntesting hmac_%s\n", algo
);
189 tsize
= sizeof (struct hmac_testvec
);
191 if (tsize
> TVMEMSIZE
) {
192 printk("template (%u) too big for tvmem (%u)\n", tsize
,
197 memcpy(tvmem
, template, tsize
);
198 hmac_tv
= (void *) tvmem
;
200 for (i
= 0; i
< tcount
; i
++) {
201 printk("test %u:\n", i
+ 1);
202 memset(result
, 0, sizeof (result
));
204 p
= hmac_tv
[i
].plaintext
;
205 klen
= hmac_tv
[i
].ksize
;
206 sg
[0].page
= virt_to_page(p
);
207 sg
[0].offset
= offset_in_page(p
);
208 sg
[0].length
= hmac_tv
[i
].psize
;
210 crypto_hmac(tfm
, hmac_tv
[i
].key
, &klen
, sg
, 1, result
);
212 hexdump(result
, crypto_tfm_alg_digestsize(tfm
));
214 memcmp(result
, hmac_tv
[i
].digest
,
215 crypto_tfm_alg_digestsize(tfm
)) ? "fail" :
219 printk("\ntesting hmac_%s across pages\n", algo
);
221 memset(xbuf
, 0, XBUFSIZE
);
224 for (i
= 0; i
< tcount
; i
++) {
227 printk ("test %u:\n",j
);
228 memset (result
, 0, 64);
231 klen
= hmac_tv
[i
].ksize
;
232 for (k
= 0; k
< hmac_tv
[i
].np
; k
++) {
233 memcpy (&xbuf
[IDX
[k
]], hmac_tv
[i
].plaintext
+ temp
,
235 temp
+= hmac_tv
[i
].tap
[k
];
237 sg
[k
].page
= virt_to_page (p
);
238 sg
[k
].offset
= offset_in_page (p
);
239 sg
[k
].length
= hmac_tv
[i
].tap
[k
];
242 crypto_hmac(tfm
, hmac_tv
[i
].key
, &klen
, sg
, hmac_tv
[i
].np
,
244 hexdump(result
, crypto_tfm_alg_digestsize(tfm
));
247 memcmp(result
, hmac_tv
[i
].digest
,
248 crypto_tfm_alg_digestsize(tfm
)) ? "fail" :
253 crypto_free_tfm(tfm
);
256 #endif /* CONFIG_CRYPTO_HMAC */
259 test_cipher(char * algo
, int mode
, int enc
, struct cipher_testvec
* template, unsigned int tcount
)
261 unsigned int ret
, i
, j
, k
, temp
;
264 struct crypto_tfm
*tfm
;
266 struct cipher_testvec
*cipher_tv
;
267 struct scatterlist sg
[8];
271 strncpy(e
, "encryption", 11);
273 strncpy(e
, "decryption", 11);
274 if (mode
== MODE_ECB
)
275 strncpy(m
, "ECB", 4);
277 strncpy(m
, "CBC", 4);
279 printk("\ntesting %s %s %s \n", algo
, m
, e
);
281 tsize
= sizeof (struct cipher_testvec
);
284 if (tsize
> TVMEMSIZE
) {
285 printk("template (%u) too big for tvmem (%u)\n", tsize
,
290 memcpy(tvmem
, template, tsize
);
291 cipher_tv
= (void *) tvmem
;
294 tfm
= crypto_alloc_tfm (algo
, 0);
296 tfm
= crypto_alloc_tfm (algo
, CRYPTO_TFM_MODE_CBC
);
299 printk("failed to load transform for %s %s\n", algo
, m
);
304 for (i
= 0; i
< tcount
; i
++) {
305 if (!(cipher_tv
[i
].np
)) {
307 printk("test %u (%d bit key):\n",
308 j
, cipher_tv
[i
].klen
* 8);
312 tfm
->crt_flags
|= CRYPTO_TFM_REQ_WEAK_KEY
;
313 key
= cipher_tv
[i
].key
;
315 ret
= crypto_cipher_setkey(tfm
, key
, cipher_tv
[i
].klen
);
317 printk("setkey() failed flags=%x\n", tfm
->crt_flags
);
319 if (!cipher_tv
[i
].fail
)
323 p
= cipher_tv
[i
].input
;
324 sg
[0].page
= virt_to_page(p
);
325 sg
[0].offset
= offset_in_page(p
);
326 sg
[0].length
= cipher_tv
[i
].ilen
;
329 crypto_cipher_set_iv(tfm
, cipher_tv
[i
].iv
,
330 crypto_tfm_alg_ivsize (tfm
));
334 ret
= crypto_cipher_encrypt(tfm
, sg
, sg
, cipher_tv
[i
].ilen
);
336 ret
= crypto_cipher_decrypt(tfm
, sg
, sg
, cipher_tv
[i
].ilen
);
340 printk("%s () failed flags=%x\n", e
, tfm
->crt_flags
);
344 q
= kmap(sg
[0].page
) + sg
[0].offset
;
345 hexdump(q
, cipher_tv
[i
].rlen
);
348 memcmp(q
, cipher_tv
[i
].result
, cipher_tv
[i
].rlen
) ? "fail" :
353 printk("\ntesting %s %s %s across pages (chunking) \n", algo
, m
, e
);
354 memset(xbuf
, 0, XBUFSIZE
);
357 for (i
= 0; i
< tcount
; i
++) {
358 if (cipher_tv
[i
].np
) {
360 printk("test %u (%d bit key):\n",
361 j
, cipher_tv
[i
].klen
* 8);
365 tfm
->crt_flags
|= CRYPTO_TFM_REQ_WEAK_KEY
;
366 key
= cipher_tv
[i
].key
;
368 ret
= crypto_cipher_setkey(tfm
, key
, cipher_tv
[i
].klen
);
370 printk("setkey() failed flags=%x\n", tfm
->crt_flags
);
372 if (!cipher_tv
[i
].fail
)
377 for (k
= 0; k
< cipher_tv
[i
].np
; k
++) {
378 memcpy (&xbuf
[IDX
[k
]], cipher_tv
[i
].input
+ temp
,
379 cipher_tv
[i
].tap
[k
]);
380 temp
+= cipher_tv
[i
].tap
[k
];
382 sg
[k
].page
= virt_to_page (p
);
383 sg
[k
].offset
= offset_in_page (p
);
384 sg
[k
].length
= cipher_tv
[i
].tap
[k
];
388 crypto_cipher_set_iv(tfm
, cipher_tv
[i
].iv
,
389 crypto_tfm_alg_ivsize (tfm
));
393 ret
= crypto_cipher_encrypt(tfm
, sg
, sg
, cipher_tv
[i
].ilen
);
395 ret
= crypto_cipher_decrypt(tfm
, sg
, sg
, cipher_tv
[i
].ilen
);
398 printk("%s () failed flags=%x\n", e
, tfm
->crt_flags
);
403 for (k
= 0; k
< cipher_tv
[i
].np
; k
++) {
404 printk("page %u\n", k
);
405 q
= kmap(sg
[k
].page
) + sg
[k
].offset
;
406 hexdump(q
, cipher_tv
[i
].tap
[k
]);
408 memcmp(q
, cipher_tv
[i
].result
+ temp
,
409 cipher_tv
[i
].tap
[k
]) ? "fail" :
411 temp
+= cipher_tv
[i
].tap
[k
];
417 crypto_free_tfm(tfm
);
424 char result
[COMP_BUF_SIZE
];
425 struct crypto_tfm
*tfm
;
426 struct comp_testvec
*tv
;
429 printk("\ntesting deflate compression\n");
431 tsize
= sizeof (deflate_comp_tv_template
);
432 if (tsize
> TVMEMSIZE
) {
433 printk("template (%u) too big for tvmem (%u)\n", tsize
,
438 memcpy(tvmem
, deflate_comp_tv_template
, tsize
);
441 tfm
= crypto_alloc_tfm("deflate", 0);
443 printk("failed to load transform for deflate\n");
447 for (i
= 0; i
< DEFLATE_COMP_TEST_VECTORS
; i
++) {
448 int ilen
, ret
, dlen
= COMP_BUF_SIZE
;
450 printk("test %u:\n", i
+ 1);
451 memset(result
, 0, sizeof (result
));
454 ret
= crypto_comp_compress(tfm
, tv
[i
].input
,
455 ilen
, result
, &dlen
);
457 printk("fail: ret=%d\n", ret
);
460 hexdump(result
, dlen
);
461 printk("%s (ratio %d:%d)\n",
462 memcmp(result
, tv
[i
].output
, dlen
) ? "fail" : "pass",
466 printk("\ntesting deflate decompression\n");
468 tsize
= sizeof (deflate_decomp_tv_template
);
469 if (tsize
> TVMEMSIZE
) {
470 printk("template (%u) too big for tvmem (%u)\n", tsize
,
475 memcpy(tvmem
, deflate_decomp_tv_template
, tsize
);
478 for (i
= 0; i
< DEFLATE_DECOMP_TEST_VECTORS
; i
++) {
479 int ilen
, ret
, dlen
= COMP_BUF_SIZE
;
481 printk("test %u:\n", i
+ 1);
482 memset(result
, 0, sizeof (result
));
485 ret
= crypto_comp_decompress(tfm
, tv
[i
].input
,
486 ilen
, result
, &dlen
);
488 printk("fail: ret=%d\n", ret
);
491 hexdump(result
, dlen
);
492 printk("%s (ratio %d:%d)\n",
493 memcmp(result
, tv
[i
].output
, dlen
) ? "fail" : "pass",
497 crypto_free_tfm(tfm
);
508 u8 b
, test_vec
[NUMVEC
][VECSIZE
];
509 static u32 vec_results
[NUMVEC
] = {
510 0x0e2c157f, 0xe980ebf6, 0xde74bded,
511 0xd579c862, 0xba979ad0, 0x2b29d913
513 static u32 tot_vec_results
= 0x24c5d375;
515 struct scatterlist sg
[NUMVEC
];
516 struct crypto_tfm
*tfm
;
517 char *fmtdata
= "testing crc32c initialized to %08x: %s\n";
518 #define SEEDTESTVAL 0xedcba987
521 printk("\ntesting crc32c\n");
523 tfm
= crypto_alloc_tfm("crc32c", 0);
525 printk("failed to load transform for crc32c\n");
529 crypto_digest_init(tfm
);
530 crypto_digest_final(tfm
, (u8
*)&crc
);
531 printk(fmtdata
, crc
, (crc
== 0) ? "pass" : "ERROR");
534 * stuff test_vec with known values, simple incrementing
538 for (i
= 0; i
< NUMVEC
; i
++) {
539 for (j
= 0; j
< VECSIZE
; j
++)
540 test_vec
[i
][j
] = ++b
;
541 sg
[i
].page
= virt_to_page(test_vec
[i
]);
542 sg
[i
].offset
= offset_in_page(test_vec
[i
]);
543 sg
[i
].length
= VECSIZE
;
547 (void)crypto_digest_setkey(tfm
, (const u8
*)&seed
, sizeof(u32
));
548 crypto_digest_final(tfm
, (u8
*)&crc
);
549 printk("testing crc32c setkey returns %08x : %s\n", crc
, (crc
== (SEEDTESTVAL
^ ~(u32
)0)) ?
552 printk("testing crc32c using update/final:\n");
554 pass
= 1; /* assume all is well */
556 for (i
= 0; i
< NUMVEC
; i
++) {
558 (void)crypto_digest_setkey(tfm
, (const u8
*)&seed
, sizeof(u32
));
559 crypto_digest_update(tfm
, &sg
[i
], 1);
560 crypto_digest_final(tfm
, (u8
*)&crc
);
561 if (crc
== vec_results
[i
]) {
562 printk(" %08x:OK", crc
);
564 printk(" %08x:BAD, wanted %08x\n", crc
, vec_results
[i
]);
569 printk("\ntesting crc32c using incremental accumulator:\n");
571 for (i
= 0; i
< NUMVEC
; i
++) {
572 seed
= (crc
^ ~(u32
)0);
573 (void)crypto_digest_setkey(tfm
, (const u8
*)&seed
, sizeof(u32
));
574 crypto_digest_update(tfm
, &sg
[i
], 1);
575 crypto_digest_final(tfm
, (u8
*)&crc
);
577 if (crc
== tot_vec_results
) {
578 printk(" %08x:OK", crc
);
580 printk(" %08x:BAD, wanted %08x\n", crc
, tot_vec_results
);
584 printk("\ntesting crc32c using digest:\n");
586 (void)crypto_digest_setkey(tfm
, (const u8
*)&seed
, sizeof(u32
));
587 crypto_digest_digest(tfm
, sg
, NUMVEC
, (u8
*)&crc
);
588 if (crc
== tot_vec_results
) {
589 printk(" %08x:OK", crc
);
591 printk(" %08x:BAD, wanted %08x\n", crc
, tot_vec_results
);
595 printk("\n%s\n", pass
? "pass" : "ERROR");
597 crypto_free_tfm(tfm
);
598 printk("crc32c test complete\n");
607 printk("alg %s ", *name
);
608 printk((crypto_alg_available(*name
, 0)) ?
609 "found\n" : "not found\n");
620 test_hash("md5", md5_tv_template
, MD5_TEST_VECTORS
);
622 test_hash("sha1", sha1_tv_template
, SHA1_TEST_VECTORS
);
625 test_cipher ("des", MODE_ECB
, ENCRYPT
, des_enc_tv_template
, DES_ENC_TEST_VECTORS
);
626 test_cipher ("des", MODE_ECB
, DECRYPT
, des_dec_tv_template
, DES_DEC_TEST_VECTORS
);
627 test_cipher ("des", MODE_CBC
, ENCRYPT
, des_cbc_enc_tv_template
, DES_CBC_ENC_TEST_VECTORS
);
628 test_cipher ("des", MODE_CBC
, DECRYPT
, des_cbc_dec_tv_template
, DES_CBC_DEC_TEST_VECTORS
);
631 test_cipher ("des3_ede", MODE_ECB
, ENCRYPT
, des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
);
632 test_cipher ("des3_ede", MODE_ECB
, DECRYPT
, des3_ede_dec_tv_template
, DES3_EDE_DEC_TEST_VECTORS
);
634 test_hash("md4", md4_tv_template
, MD4_TEST_VECTORS
);
636 test_hash("sha256", sha256_tv_template
, SHA256_TEST_VECTORS
);
639 test_cipher ("blowfish", MODE_ECB
, ENCRYPT
, bf_enc_tv_template
, BF_ENC_TEST_VECTORS
);
640 test_cipher ("blowfish", MODE_ECB
, DECRYPT
, bf_dec_tv_template
, BF_DEC_TEST_VECTORS
);
641 test_cipher ("blowfish", MODE_CBC
, ENCRYPT
, bf_cbc_enc_tv_template
, BF_CBC_ENC_TEST_VECTORS
);
642 test_cipher ("blowfish", MODE_CBC
, DECRYPT
, bf_cbc_dec_tv_template
, BF_CBC_DEC_TEST_VECTORS
);
645 test_cipher ("twofish", MODE_ECB
, ENCRYPT
, tf_enc_tv_template
, TF_ENC_TEST_VECTORS
);
646 test_cipher ("twofish", MODE_ECB
, DECRYPT
, tf_dec_tv_template
, TF_DEC_TEST_VECTORS
);
647 test_cipher ("twofish", MODE_CBC
, ENCRYPT
, tf_cbc_enc_tv_template
, TF_CBC_ENC_TEST_VECTORS
);
648 test_cipher ("twofish", MODE_CBC
, DECRYPT
, tf_cbc_dec_tv_template
, TF_CBC_DEC_TEST_VECTORS
);
651 test_cipher ("serpent", MODE_ECB
, ENCRYPT
, serpent_enc_tv_template
, SERPENT_ENC_TEST_VECTORS
);
652 test_cipher ("serpent", MODE_ECB
, DECRYPT
, serpent_dec_tv_template
, SERPENT_DEC_TEST_VECTORS
);
655 test_cipher ("tnepres", MODE_ECB
, ENCRYPT
, tnepres_enc_tv_template
, TNEPRES_ENC_TEST_VECTORS
);
656 test_cipher ("tnepres", MODE_ECB
, DECRYPT
, tnepres_dec_tv_template
, TNEPRES_DEC_TEST_VECTORS
);
659 test_cipher ("aes", MODE_ECB
, ENCRYPT
, aes_enc_tv_template
, AES_ENC_TEST_VECTORS
);
660 test_cipher ("aes", MODE_ECB
, DECRYPT
, aes_dec_tv_template
, AES_DEC_TEST_VECTORS
);
663 test_cipher ("cast5", MODE_ECB
, ENCRYPT
, cast5_enc_tv_template
, CAST5_ENC_TEST_VECTORS
);
664 test_cipher ("cast5", MODE_ECB
, DECRYPT
, cast5_dec_tv_template
, CAST5_DEC_TEST_VECTORS
);
667 test_cipher ("cast6", MODE_ECB
, ENCRYPT
, cast6_enc_tv_template
, CAST6_ENC_TEST_VECTORS
);
668 test_cipher ("cast6", MODE_ECB
, DECRYPT
, cast6_dec_tv_template
, CAST6_DEC_TEST_VECTORS
);
671 test_cipher ("arc4", MODE_ECB
, ENCRYPT
, arc4_enc_tv_template
, ARC4_ENC_TEST_VECTORS
);
672 test_cipher ("arc4", MODE_ECB
, DECRYPT
, arc4_dec_tv_template
, ARC4_DEC_TEST_VECTORS
);
675 test_cipher ("tea", MODE_ECB
, ENCRYPT
, tea_enc_tv_template
, TEA_ENC_TEST_VECTORS
);
676 test_cipher ("tea", MODE_ECB
, DECRYPT
, tea_dec_tv_template
, TEA_DEC_TEST_VECTORS
);
680 test_cipher ("xtea", MODE_ECB
, ENCRYPT
, xtea_enc_tv_template
, XTEA_ENC_TEST_VECTORS
);
681 test_cipher ("xtea", MODE_ECB
, DECRYPT
, xtea_dec_tv_template
, XTEA_DEC_TEST_VECTORS
);
684 test_cipher ("khazad", MODE_ECB
, ENCRYPT
, khazad_enc_tv_template
, KHAZAD_ENC_TEST_VECTORS
);
685 test_cipher ("khazad", MODE_ECB
, DECRYPT
, khazad_dec_tv_template
, KHAZAD_DEC_TEST_VECTORS
);
688 test_cipher ("anubis", MODE_ECB
, ENCRYPT
, anubis_enc_tv_template
, ANUBIS_ENC_TEST_VECTORS
);
689 test_cipher ("anubis", MODE_ECB
, DECRYPT
, anubis_dec_tv_template
, ANUBIS_DEC_TEST_VECTORS
);
690 test_cipher ("anubis", MODE_CBC
, ENCRYPT
, anubis_cbc_enc_tv_template
, ANUBIS_CBC_ENC_TEST_VECTORS
);
691 test_cipher ("anubis", MODE_CBC
, DECRYPT
, anubis_cbc_dec_tv_template
, ANUBIS_CBC_ENC_TEST_VECTORS
);
693 test_hash("sha384", sha384_tv_template
, SHA384_TEST_VECTORS
);
694 test_hash("sha512", sha512_tv_template
, SHA512_TEST_VECTORS
);
695 test_hash("wp512", wp512_tv_template
, WP512_TEST_VECTORS
);
696 test_hash("wp384", wp384_tv_template
, WP384_TEST_VECTORS
);
697 test_hash("wp256", wp256_tv_template
, WP256_TEST_VECTORS
);
698 test_hash("tgr192", tgr192_tv_template
, TGR192_TEST_VECTORS
);
699 test_hash("tgr160", tgr160_tv_template
, TGR160_TEST_VECTORS
);
700 test_hash("tgr128", tgr128_tv_template
, TGR128_TEST_VECTORS
);
703 #ifdef CONFIG_CRYPTO_HMAC
704 test_hmac("md5", hmac_md5_tv_template
, HMAC_MD5_TEST_VECTORS
);
705 test_hmac("sha1", hmac_sha1_tv_template
, HMAC_SHA1_TEST_VECTORS
);
706 test_hmac("sha256", hmac_sha256_tv_template
, HMAC_SHA256_TEST_VECTORS
);
709 test_hash("michael_mic", michael_mic_tv_template
, MICHAEL_MIC_TEST_VECTORS
);
713 test_hash("md5", md5_tv_template
, MD5_TEST_VECTORS
);
717 test_hash("sha1", sha1_tv_template
, SHA1_TEST_VECTORS
);
721 test_cipher ("des", MODE_ECB
, ENCRYPT
, des_enc_tv_template
, DES_ENC_TEST_VECTORS
);
722 test_cipher ("des", MODE_ECB
, DECRYPT
, des_dec_tv_template
, DES_DEC_TEST_VECTORS
);
723 test_cipher ("des", MODE_CBC
, ENCRYPT
, des_cbc_enc_tv_template
, DES_CBC_ENC_TEST_VECTORS
);
724 test_cipher ("des", MODE_CBC
, DECRYPT
, des_cbc_dec_tv_template
, DES_CBC_DEC_TEST_VECTORS
);
728 test_cipher ("des3_ede", MODE_ECB
, ENCRYPT
, des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
);
729 test_cipher ("des3_ede", MODE_ECB
, DECRYPT
, des3_ede_dec_tv_template
, DES3_EDE_DEC_TEST_VECTORS
);
733 test_hash("md4", md4_tv_template
, MD4_TEST_VECTORS
);
737 test_hash("sha256", sha256_tv_template
, SHA256_TEST_VECTORS
);
741 test_cipher ("blowfish", MODE_ECB
, ENCRYPT
, bf_enc_tv_template
, BF_ENC_TEST_VECTORS
);
742 test_cipher ("blowfish", MODE_ECB
, DECRYPT
, bf_dec_tv_template
, BF_DEC_TEST_VECTORS
);
743 test_cipher ("blowfish", MODE_CBC
, ENCRYPT
, bf_cbc_enc_tv_template
, BF_CBC_ENC_TEST_VECTORS
);
744 test_cipher ("blowfish", MODE_CBC
, DECRYPT
, bf_cbc_dec_tv_template
, BF_CBC_DEC_TEST_VECTORS
);
748 test_cipher ("twofish", MODE_ECB
, ENCRYPT
, tf_enc_tv_template
, TF_ENC_TEST_VECTORS
);
749 test_cipher ("twofish", MODE_ECB
, DECRYPT
, tf_dec_tv_template
, TF_DEC_TEST_VECTORS
);
750 test_cipher ("twofish", MODE_CBC
, ENCRYPT
, tf_cbc_enc_tv_template
, TF_CBC_ENC_TEST_VECTORS
);
751 test_cipher ("twofish", MODE_CBC
, DECRYPT
, tf_cbc_dec_tv_template
, TF_CBC_DEC_TEST_VECTORS
);
755 test_cipher ("serpent", MODE_ECB
, ENCRYPT
, serpent_enc_tv_template
, SERPENT_ENC_TEST_VECTORS
);
756 test_cipher ("serpent", MODE_ECB
, DECRYPT
, serpent_dec_tv_template
, SERPENT_DEC_TEST_VECTORS
);
760 test_cipher ("aes", MODE_ECB
, ENCRYPT
, aes_enc_tv_template
, AES_ENC_TEST_VECTORS
);
761 test_cipher ("aes", MODE_ECB
, DECRYPT
, aes_dec_tv_template
, AES_DEC_TEST_VECTORS
);
765 test_hash("sha384", sha384_tv_template
, SHA384_TEST_VECTORS
);
769 test_hash("sha512", sha512_tv_template
, SHA512_TEST_VECTORS
);
777 test_cipher ("cast5", MODE_ECB
, ENCRYPT
, cast5_enc_tv_template
, CAST5_ENC_TEST_VECTORS
);
778 test_cipher ("cast5", MODE_ECB
, DECRYPT
, cast5_dec_tv_template
, CAST5_DEC_TEST_VECTORS
);
782 test_cipher ("cast6", MODE_ECB
, ENCRYPT
, cast6_enc_tv_template
, CAST6_ENC_TEST_VECTORS
);
783 test_cipher ("cast6", MODE_ECB
, DECRYPT
, cast6_dec_tv_template
, CAST6_DEC_TEST_VECTORS
);
787 test_cipher ("arc4", MODE_ECB
, ENCRYPT
, arc4_enc_tv_template
, ARC4_ENC_TEST_VECTORS
);
788 test_cipher ("arc4", MODE_ECB
, DECRYPT
, arc4_dec_tv_template
, ARC4_DEC_TEST_VECTORS
);
792 test_hash("michael_mic", michael_mic_tv_template
, MICHAEL_MIC_TEST_VECTORS
);
800 test_cipher ("tea", MODE_ECB
, ENCRYPT
, tea_enc_tv_template
, TEA_ENC_TEST_VECTORS
);
801 test_cipher ("tea", MODE_ECB
, DECRYPT
, tea_dec_tv_template
, TEA_DEC_TEST_VECTORS
);
805 test_cipher ("xtea", MODE_ECB
, ENCRYPT
, xtea_enc_tv_template
, XTEA_ENC_TEST_VECTORS
);
806 test_cipher ("xtea", MODE_ECB
, DECRYPT
, xtea_dec_tv_template
, XTEA_DEC_TEST_VECTORS
);
810 test_cipher ("khazad", MODE_ECB
, ENCRYPT
, khazad_enc_tv_template
, KHAZAD_ENC_TEST_VECTORS
);
811 test_cipher ("khazad", MODE_ECB
, DECRYPT
, khazad_dec_tv_template
, KHAZAD_DEC_TEST_VECTORS
);
815 test_hash("wp512", wp512_tv_template
, WP512_TEST_VECTORS
);
819 test_hash("wp384", wp384_tv_template
, WP384_TEST_VECTORS
);
823 test_hash("wp256", wp256_tv_template
, WP256_TEST_VECTORS
);
827 test_cipher ("tnepres", MODE_ECB
, ENCRYPT
, tnepres_enc_tv_template
, TNEPRES_ENC_TEST_VECTORS
);
828 test_cipher ("tnepres", MODE_ECB
, DECRYPT
, tnepres_dec_tv_template
, TNEPRES_DEC_TEST_VECTORS
);
832 test_cipher ("anubis", MODE_ECB
, ENCRYPT
, anubis_enc_tv_template
, ANUBIS_ENC_TEST_VECTORS
);
833 test_cipher ("anubis", MODE_ECB
, DECRYPT
, anubis_dec_tv_template
, ANUBIS_DEC_TEST_VECTORS
);
834 test_cipher ("anubis", MODE_CBC
, ENCRYPT
, anubis_cbc_enc_tv_template
, ANUBIS_CBC_ENC_TEST_VECTORS
);
835 test_cipher ("anubis", MODE_CBC
, DECRYPT
, anubis_cbc_dec_tv_template
, ANUBIS_CBC_ENC_TEST_VECTORS
);
839 test_hash("tgr192", tgr192_tv_template
, TGR192_TEST_VECTORS
);
844 test_hash("tgr160", tgr160_tv_template
, TGR160_TEST_VECTORS
);
848 test_hash("tgr128", tgr128_tv_template
, TGR128_TEST_VECTORS
);
851 #ifdef CONFIG_CRYPTO_HMAC
853 test_hmac("md5", hmac_md5_tv_template
, HMAC_MD5_TEST_VECTORS
);
857 test_hmac("sha1", hmac_sha1_tv_template
, HMAC_SHA1_TEST_VECTORS
);
861 test_hmac("sha256", hmac_sha256_tv_template
, HMAC_SHA256_TEST_VECTORS
);
871 /* useful for debugging */
872 printk("not testing anything\n");
880 tvmem
= kmalloc(TVMEMSIZE
, GFP_KERNEL
);
884 xbuf
= kmalloc(XBUFSIZE
, GFP_KERNEL
);
898 * If an init function is provided, an exit function must also be provided
899 * to allow module unload.
901 static void __exit
fini(void) { }
906 module_param(mode
, int, 0);
908 MODULE_LICENSE("GPL");
909 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
910 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");