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>
9 * Copyright (c) 2007 Nokia Siemens Networks
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License, or (at your option)
16 * 2007-11-13 Added GCM tests
17 * 2007-11-13 Added AEAD support
18 * 2007-11-06 Added SHA-224 and SHA-224-HMAC tests
19 * 2006-12-07 Added SHA384 HMAC and SHA512 HMAC tests
20 * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>)
21 * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt
25 #include <linux/err.h>
26 #include <linux/init.h>
27 #include <linux/module.h>
29 #include <linux/slab.h>
30 #include <linux/scatterlist.h>
31 #include <linux/string.h>
32 #include <linux/crypto.h>
33 #include <linux/highmem.h>
34 #include <linux/moduleparam.h>
35 #include <linux/jiffies.h>
36 #include <linux/timex.h>
37 #include <linux/interrupt.h>
41 * Need to kmalloc() memory for testing kmap().
43 #define TVMEMSIZE 16384
44 #define XBUFSIZE 32768
47 * Indexes into the xbuf to simulate cross-page access.
59 * Used by test_cipher()
64 struct tcrypt_result
{
65 struct completion completion
;
69 static unsigned int IDX
[8] = { IDX1
, IDX2
, IDX3
, IDX4
, IDX5
, IDX6
, IDX7
, IDX8
};
72 * Used by test_cipher_speed()
74 static unsigned int sec
;
81 static char *check
[] = {
82 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
83 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
84 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
85 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
86 "camellia", "seed", "salsa20", "lzo", "cts", NULL
89 static void hexdump(unsigned char *buf
, unsigned int len
)
91 print_hex_dump(KERN_CONT
, "", DUMP_PREFIX_OFFSET
,
96 static void tcrypt_complete(struct crypto_async_request
*req
, int err
)
98 struct tcrypt_result
*res
= req
->data
;
100 if (err
== -EINPROGRESS
)
104 complete(&res
->completion
);
107 static void test_hash(char *algo
, struct hash_testvec
*template,
110 unsigned int i
, j
, k
, temp
;
111 struct scatterlist sg
[8];
113 struct crypto_hash
*tfm
;
114 struct hash_desc desc
;
118 printk("\ntesting %s\n", algo
);
120 tfm
= crypto_alloc_hash(algo
, 0, CRYPTO_ALG_ASYNC
);
122 printk("failed to load transform for %s: %ld\n", algo
,
130 for (i
= 0; i
< tcount
; i
++) {
131 printk("test %u:\n", i
+ 1);
132 memset(result
, 0, 64);
134 hash_buff
= kzalloc(template[i
].psize
, GFP_KERNEL
);
138 memcpy(hash_buff
, template[i
].plaintext
, template[i
].psize
);
139 sg_init_one(&sg
[0], hash_buff
, template[i
].psize
);
141 if (template[i
].ksize
) {
142 ret
= crypto_hash_setkey(tfm
, template[i
].key
,
145 printk("setkey() failed ret=%d\n", ret
);
151 ret
= crypto_hash_digest(&desc
, sg
, template[i
].psize
, result
);
153 printk("digest () failed ret=%d\n", ret
);
158 hexdump(result
, crypto_hash_digestsize(tfm
));
160 memcmp(result
, template[i
].digest
,
161 crypto_hash_digestsize(tfm
)) ?
166 printk("testing %s across pages\n", algo
);
168 /* setup the dummy buffer first */
169 memset(xbuf
, 0, XBUFSIZE
);
172 for (i
= 0; i
< tcount
; i
++) {
173 if (template[i
].np
) {
175 printk("test %u:\n", j
);
176 memset(result
, 0, 64);
179 sg_init_table(sg
, template[i
].np
);
180 for (k
= 0; k
< template[i
].np
; k
++) {
181 memcpy(&xbuf
[IDX
[k
]],
182 template[i
].plaintext
+ temp
,
184 temp
+= template[i
].tap
[k
];
185 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
189 if (template[i
].ksize
) {
190 ret
= crypto_hash_setkey(tfm
, template[i
].key
,
194 printk("setkey() failed ret=%d\n", ret
);
199 ret
= crypto_hash_digest(&desc
, sg
, template[i
].psize
,
202 printk("digest () failed ret=%d\n", ret
);
206 hexdump(result
, crypto_hash_digestsize(tfm
));
208 memcmp(result
, template[i
].digest
,
209 crypto_hash_digestsize(tfm
)) ?
215 crypto_free_hash(tfm
);
218 static void test_aead(char *algo
, int enc
, struct aead_testvec
*template,
221 unsigned int ret
, i
, j
, k
, temp
;
223 struct crypto_aead
*tfm
;
225 struct aead_request
*req
;
226 struct scatterlist sg
[8];
227 struct scatterlist asg
[8];
229 struct tcrypt_result result
;
230 unsigned int authsize
;
240 printk(KERN_INFO
"\ntesting %s %s\n", algo
, e
);
242 init_completion(&result
.completion
);
244 tfm
= crypto_alloc_aead(algo
, 0, 0);
247 printk(KERN_INFO
"failed to load transform for %s: %ld\n",
252 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
254 printk(KERN_INFO
"failed to allocate request for %s\n", algo
);
258 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
259 tcrypt_complete
, &result
);
261 for (i
= 0, j
= 0; i
< tcount
; i
++) {
262 if (!template[i
].np
) {
263 printk(KERN_INFO
"test %u (%d bit key):\n",
264 ++j
, template[i
].klen
* 8);
266 /* some tepmplates have no input data but they will
269 input
= kzalloc(template[i
].ilen
+ template[i
].rlen
, GFP_KERNEL
);
273 assoc
= kzalloc(template[i
].alen
, GFP_KERNEL
);
279 memcpy(input
, template[i
].input
, template[i
].ilen
);
280 memcpy(assoc
, template[i
].assoc
, template[i
].alen
);
282 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
284 memset(iv
, 0, MAX_IVLEN
);
286 crypto_aead_clear_flags(tfm
, ~0);
288 crypto_aead_set_flags(
289 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
292 key
= template[i
].key
;
294 key
= kzalloc(template[i
].klen
, GFP_KERNEL
);
296 ret
= crypto_aead_setkey(tfm
, key
,
299 printk(KERN_INFO
"setkey() failed flags=%x\n",
300 crypto_aead_get_flags(tfm
));
302 if (!template[i
].fail
)
306 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
307 ret
= crypto_aead_setauthsize(tfm
, authsize
);
310 "failed to set authsize = %u\n",
315 sg_init_one(&sg
[0], input
,
316 template[i
].ilen
+ (enc
? authsize
: 0));
318 sg_init_one(&asg
[0], assoc
, template[i
].alen
);
320 aead_request_set_crypt(req
, sg
, sg
,
321 template[i
].ilen
, iv
);
323 aead_request_set_assoc(req
, asg
, template[i
].alen
);
326 crypto_aead_encrypt(req
) :
327 crypto_aead_decrypt(req
);
334 ret
= wait_for_completion_interruptible(
336 if (!ret
&& !(ret
= result
.err
)) {
337 INIT_COMPLETION(result
.completion
);
342 printk(KERN_INFO
"%s () failed err=%d\n",
347 q
= kmap(sg_page(&sg
[0])) + sg
[0].offset
;
348 hexdump(q
, template[i
].rlen
);
350 printk(KERN_INFO
"enc/dec: %s\n",
351 memcmp(q
, template[i
].result
,
352 template[i
].rlen
) ? "fail" : "pass");
353 kunmap(sg_page(&sg
[0]));
355 if (!template[i
].key
)
362 printk(KERN_INFO
"\ntesting %s %s across pages (chunking)\n", algo
, e
);
363 memset(xbuf
, 0, XBUFSIZE
);
364 memset(axbuf
, 0, XBUFSIZE
);
366 for (i
= 0, j
= 0; i
< tcount
; i
++) {
367 if (template[i
].np
) {
368 printk(KERN_INFO
"test %u (%d bit key):\n",
369 ++j
, template[i
].klen
* 8);
372 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
374 memset(iv
, 0, MAX_IVLEN
);
376 crypto_aead_clear_flags(tfm
, ~0);
378 crypto_aead_set_flags(
379 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
380 key
= template[i
].key
;
382 ret
= crypto_aead_setkey(tfm
, key
, template[i
].klen
);
384 printk(KERN_INFO
"setkey() failed flags=%x\n",
385 crypto_aead_get_flags(tfm
));
387 if (!template[i
].fail
)
391 sg_init_table(sg
, template[i
].np
);
392 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
393 memcpy(&xbuf
[IDX
[k
]],
394 template[i
].input
+ temp
,
396 temp
+= template[i
].tap
[k
];
397 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
401 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
402 ret
= crypto_aead_setauthsize(tfm
, authsize
);
405 "failed to set authsize = %u\n",
411 sg
[k
- 1].length
+= authsize
;
413 sg_init_table(asg
, template[i
].anp
);
414 for (k
= 0, temp
= 0; k
< template[i
].anp
; k
++) {
415 memcpy(&axbuf
[IDX
[k
]],
416 template[i
].assoc
+ temp
,
417 template[i
].atap
[k
]);
418 temp
+= template[i
].atap
[k
];
419 sg_set_buf(&asg
[k
], &axbuf
[IDX
[k
]],
420 template[i
].atap
[k
]);
423 aead_request_set_crypt(req
, sg
, sg
,
427 aead_request_set_assoc(req
, asg
, template[i
].alen
);
430 crypto_aead_encrypt(req
) :
431 crypto_aead_decrypt(req
);
438 ret
= wait_for_completion_interruptible(
440 if (!ret
&& !(ret
= result
.err
)) {
441 INIT_COMPLETION(result
.completion
);
446 printk(KERN_INFO
"%s () failed err=%d\n",
451 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
452 printk(KERN_INFO
"page %u\n", k
);
453 q
= kmap(sg_page(&sg
[k
])) + sg
[k
].offset
;
454 hexdump(q
, template[i
].tap
[k
]);
455 printk(KERN_INFO
"%s\n",
456 memcmp(q
, template[i
].result
+ temp
,
458 (k
< template[i
].np
- 1 || enc
?
462 temp
+= template[i
].tap
[k
];
463 kunmap(sg_page(&sg
[k
]));
469 crypto_free_aead(tfm
);
470 aead_request_free(req
);
473 static void test_cipher(char *algo
, int enc
,
474 struct cipher_testvec
*template, unsigned int tcount
)
476 unsigned int ret
, i
, j
, k
, temp
;
478 struct crypto_ablkcipher
*tfm
;
479 struct ablkcipher_request
*req
;
480 struct scatterlist sg
[8];
482 struct tcrypt_result result
;
491 printk("\ntesting %s %s\n", algo
, e
);
493 init_completion(&result
.completion
);
494 tfm
= crypto_alloc_ablkcipher(algo
, 0, 0);
497 printk("failed to load transform for %s: %ld\n", algo
,
502 req
= ablkcipher_request_alloc(tfm
, GFP_KERNEL
);
504 printk("failed to allocate request for %s\n", algo
);
508 ablkcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
509 tcrypt_complete
, &result
);
512 for (i
= 0; i
< tcount
; i
++) {
514 data
= kzalloc(template[i
].ilen
, GFP_KERNEL
);
518 memcpy(data
, template[i
].input
, template[i
].ilen
);
520 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
522 memset(iv
, 0, MAX_IVLEN
);
524 if (!(template[i
].np
)) {
526 printk("test %u (%d bit key):\n",
527 j
, template[i
].klen
* 8);
529 crypto_ablkcipher_clear_flags(tfm
, ~0);
531 crypto_ablkcipher_set_flags(
532 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
534 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
537 printk("setkey() failed flags=%x\n",
538 crypto_ablkcipher_get_flags(tfm
));
540 if (!template[i
].fail
) {
546 sg_init_one(&sg
[0], data
, template[i
].ilen
);
548 ablkcipher_request_set_crypt(req
, sg
, sg
,
549 template[i
].ilen
, iv
);
551 crypto_ablkcipher_encrypt(req
) :
552 crypto_ablkcipher_decrypt(req
);
559 ret
= wait_for_completion_interruptible(
561 if (!ret
&& !((ret
= result
.err
))) {
562 INIT_COMPLETION(result
.completion
);
567 printk("%s () failed err=%d\n", e
, -ret
);
572 q
= kmap(sg_page(&sg
[0])) + sg
[0].offset
;
573 hexdump(q
, template[i
].rlen
);
576 memcmp(q
, template[i
].result
,
577 template[i
].rlen
) ? "fail" : "pass");
578 kunmap(sg_page(&sg
[0]));
583 printk("\ntesting %s %s across pages (chunking)\n", algo
, e
);
584 memset(xbuf
, 0, XBUFSIZE
);
587 for (i
= 0; i
< tcount
; i
++) {
589 data
= kzalloc(template[i
].ilen
, GFP_KERNEL
);
593 memcpy(data
, template[i
].input
, template[i
].ilen
);
596 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
598 memset(iv
, 0, MAX_IVLEN
);
600 if (template[i
].np
) {
602 printk("test %u (%d bit key):\n",
603 j
, template[i
].klen
* 8);
605 crypto_ablkcipher_clear_flags(tfm
, ~0);
607 crypto_ablkcipher_set_flags(
608 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
610 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
613 printk("setkey() failed flags=%x\n",
614 crypto_ablkcipher_get_flags(tfm
));
616 if (!template[i
].fail
) {
623 sg_init_table(sg
, template[i
].np
);
624 for (k
= 0; k
< template[i
].np
; k
++) {
625 memcpy(&xbuf
[IDX
[k
]],
626 template[i
].input
+ temp
,
628 temp
+= template[i
].tap
[k
];
629 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
633 ablkcipher_request_set_crypt(req
, sg
, sg
,
634 template[i
].ilen
, iv
);
637 crypto_ablkcipher_encrypt(req
) :
638 crypto_ablkcipher_decrypt(req
);
645 ret
= wait_for_completion_interruptible(
647 if (!ret
&& !((ret
= result
.err
))) {
648 INIT_COMPLETION(result
.completion
);
653 printk("%s () failed err=%d\n", e
, -ret
);
658 for (k
= 0; k
< template[i
].np
; k
++) {
659 printk("page %u\n", k
);
660 q
= kmap(sg_page(&sg
[k
])) + sg
[k
].offset
;
661 hexdump(q
, template[i
].tap
[k
]);
663 memcmp(q
, template[i
].result
+ temp
,
664 template[i
].tap
[k
]) ? "fail" :
666 temp
+= template[i
].tap
[k
];
667 kunmap(sg_page(&sg
[k
]));
672 crypto_free_ablkcipher(tfm
);
673 ablkcipher_request_free(req
);
676 static int test_cipher_jiffies(struct blkcipher_desc
*desc
, int enc
, char *p
,
679 struct scatterlist sg
[1];
680 unsigned long start
, end
;
684 sg_init_one(sg
, p
, blen
);
686 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
687 time_before(jiffies
, end
); bcount
++) {
689 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
691 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
697 printk("%d operations in %d seconds (%ld bytes)\n",
698 bcount
, sec
, (long)bcount
* blen
);
702 static int test_cipher_cycles(struct blkcipher_desc
*desc
, int enc
, char *p
,
705 struct scatterlist sg
[1];
706 unsigned long cycles
= 0;
710 sg_init_one(sg
, p
, blen
);
716 for (i
= 0; i
< 4; i
++) {
718 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
720 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
726 /* The real thing. */
727 for (i
= 0; i
< 8; i
++) {
730 start
= get_cycles();
732 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
734 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
740 cycles
+= end
- start
;
748 printk("1 operation in %lu cycles (%d bytes)\n",
749 (cycles
+ 4) / 8, blen
);
754 static u32 block_sizes
[] = { 16, 64, 256, 1024, 8192, 0 };
756 static void test_cipher_speed(char *algo
, int enc
, unsigned int sec
,
757 struct cipher_testvec
*template,
758 unsigned int tcount
, u8
*keysize
)
760 unsigned int ret
, i
, j
, iv_len
;
761 unsigned char *key
, *p
, iv
[128];
762 struct crypto_blkcipher
*tfm
;
763 struct blkcipher_desc desc
;
772 printk("\ntesting speed of %s %s\n", algo
, e
);
774 tfm
= crypto_alloc_blkcipher(algo
, 0, CRYPTO_ALG_ASYNC
);
777 printk("failed to load transform for %s: %ld\n", algo
,
787 b_size
= block_sizes
;
790 if ((*keysize
+ *b_size
) > TVMEMSIZE
) {
791 printk("template (%u) too big for tvmem (%u)\n",
792 *keysize
+ *b_size
, TVMEMSIZE
);
796 printk("test %u (%d bit key, %d byte blocks): ", i
,
797 *keysize
* 8, *b_size
);
799 memset(tvmem
, 0xff, *keysize
+ *b_size
);
801 /* set key, plain text and IV */
802 key
= (unsigned char *)tvmem
;
803 for (j
= 0; j
< tcount
; j
++) {
804 if (template[j
].klen
== *keysize
) {
805 key
= template[j
].key
;
809 p
= (unsigned char *)tvmem
+ *keysize
;
811 ret
= crypto_blkcipher_setkey(tfm
, key
, *keysize
);
813 printk("setkey() failed flags=%x\n",
814 crypto_blkcipher_get_flags(tfm
));
818 iv_len
= crypto_blkcipher_ivsize(tfm
);
820 memset(&iv
, 0xff, iv_len
);
821 crypto_blkcipher_set_iv(tfm
, iv
, iv_len
);
825 ret
= test_cipher_jiffies(&desc
, enc
, p
, *b_size
, sec
);
827 ret
= test_cipher_cycles(&desc
, enc
, p
, *b_size
);
830 printk("%s() failed flags=%x\n", e
, desc
.flags
);
840 crypto_free_blkcipher(tfm
);
843 static int test_hash_jiffies_digest(struct hash_desc
*desc
, char *p
, int blen
,
846 struct scatterlist sg
[1];
847 unsigned long start
, end
;
851 sg_init_table(sg
, 1);
853 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
854 time_before(jiffies
, end
); bcount
++) {
855 sg_set_buf(sg
, p
, blen
);
856 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
861 printk("%6u opers/sec, %9lu bytes/sec\n",
862 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
867 static int test_hash_jiffies(struct hash_desc
*desc
, char *p
, int blen
,
868 int plen
, char *out
, int sec
)
870 struct scatterlist sg
[1];
871 unsigned long start
, end
;
876 return test_hash_jiffies_digest(desc
, p
, blen
, out
, sec
);
878 sg_init_table(sg
, 1);
880 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
881 time_before(jiffies
, end
); bcount
++) {
882 ret
= crypto_hash_init(desc
);
885 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
886 sg_set_buf(sg
, p
+ pcount
, plen
);
887 ret
= crypto_hash_update(desc
, sg
, plen
);
891 /* we assume there is enough space in 'out' for the result */
892 ret
= crypto_hash_final(desc
, out
);
897 printk("%6u opers/sec, %9lu bytes/sec\n",
898 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
903 static int test_hash_cycles_digest(struct hash_desc
*desc
, char *p
, int blen
,
906 struct scatterlist sg
[1];
907 unsigned long cycles
= 0;
911 sg_init_table(sg
, 1);
917 for (i
= 0; i
< 4; i
++) {
918 sg_set_buf(sg
, p
, blen
);
919 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
924 /* The real thing. */
925 for (i
= 0; i
< 8; i
++) {
928 start
= get_cycles();
930 sg_set_buf(sg
, p
, blen
);
931 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
937 cycles
+= end
- start
;
947 printk("%6lu cycles/operation, %4lu cycles/byte\n",
948 cycles
/ 8, cycles
/ (8 * blen
));
953 static int test_hash_cycles(struct hash_desc
*desc
, char *p
, int blen
,
956 struct scatterlist sg
[1];
957 unsigned long cycles
= 0;
962 return test_hash_cycles_digest(desc
, p
, blen
, out
);
964 sg_init_table(sg
, 1);
970 for (i
= 0; i
< 4; i
++) {
971 ret
= crypto_hash_init(desc
);
974 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
975 sg_set_buf(sg
, p
+ pcount
, plen
);
976 ret
= crypto_hash_update(desc
, sg
, plen
);
980 ret
= crypto_hash_final(desc
, out
);
985 /* The real thing. */
986 for (i
= 0; i
< 8; i
++) {
989 start
= get_cycles();
991 ret
= crypto_hash_init(desc
);
994 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
995 sg_set_buf(sg
, p
+ pcount
, plen
);
996 ret
= crypto_hash_update(desc
, sg
, plen
);
1000 ret
= crypto_hash_final(desc
, out
);
1006 cycles
+= end
- start
;
1016 printk("%6lu cycles/operation, %4lu cycles/byte\n",
1017 cycles
/ 8, cycles
/ (8 * blen
));
1022 static void test_hash_speed(char *algo
, unsigned int sec
,
1023 struct hash_speed
*speed
)
1025 struct crypto_hash
*tfm
;
1026 struct hash_desc desc
;
1031 printk("\ntesting speed of %s\n", algo
);
1033 tfm
= crypto_alloc_hash(algo
, 0, CRYPTO_ALG_ASYNC
);
1036 printk("failed to load transform for %s: %ld\n", algo
,
1044 if (crypto_hash_digestsize(tfm
) > sizeof(output
)) {
1045 printk("digestsize(%u) > outputbuffer(%zu)\n",
1046 crypto_hash_digestsize(tfm
), sizeof(output
));
1050 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
1051 if (speed
[i
].blen
> TVMEMSIZE
) {
1052 printk("template (%u) too big for tvmem (%u)\n",
1053 speed
[i
].blen
, TVMEMSIZE
);
1057 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
1058 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
1060 memset(tvmem
, 0xff, speed
[i
].blen
);
1063 ret
= test_hash_jiffies(&desc
, tvmem
, speed
[i
].blen
,
1064 speed
[i
].plen
, output
, sec
);
1066 ret
= test_hash_cycles(&desc
, tvmem
, speed
[i
].blen
,
1067 speed
[i
].plen
, output
);
1070 printk("hashing failed ret=%d\n", ret
);
1076 crypto_free_hash(tfm
);
1079 static void test_comp(char *algo
, struct comp_testvec
*ctemplate
,
1080 struct comp_testvec
*dtemplate
, int ctcount
, int dtcount
)
1083 char result
[COMP_BUF_SIZE
];
1084 struct crypto_comp
*tfm
;
1087 printk("\ntesting %s compression\n", algo
);
1089 tfm
= crypto_alloc_comp(algo
, 0, CRYPTO_ALG_ASYNC
);
1091 printk("failed to load transform for %s\n", algo
);
1095 for (i
= 0; i
< ctcount
; i
++) {
1096 int ilen
, ret
, dlen
= COMP_BUF_SIZE
;
1098 printk("test %u:\n", i
+ 1);
1099 memset(result
, 0, sizeof (result
));
1101 ilen
= ctemplate
[i
].inlen
;
1102 ret
= crypto_comp_compress(tfm
, ctemplate
[i
].input
,
1103 ilen
, result
, &dlen
);
1105 printk("fail: ret=%d\n", ret
);
1108 hexdump(result
, dlen
);
1109 printk("%s (ratio %d:%d)\n",
1110 memcmp(result
, ctemplate
[i
].output
, dlen
) ? "fail" : "pass",
1114 printk("\ntesting %s decompression\n", algo
);
1116 tsize
= sizeof(struct comp_testvec
);
1118 if (tsize
> TVMEMSIZE
) {
1119 printk("template (%u) too big for tvmem (%u)\n", tsize
,
1124 for (i
= 0; i
< dtcount
; i
++) {
1125 int ilen
, ret
, dlen
= COMP_BUF_SIZE
;
1127 printk("test %u:\n", i
+ 1);
1128 memset(result
, 0, sizeof (result
));
1130 ilen
= dtemplate
[i
].inlen
;
1131 ret
= crypto_comp_decompress(tfm
, dtemplate
[i
].input
,
1132 ilen
, result
, &dlen
);
1134 printk("fail: ret=%d\n", ret
);
1137 hexdump(result
, dlen
);
1138 printk("%s (ratio %d:%d)\n",
1139 memcmp(result
, dtemplate
[i
].output
, dlen
) ? "fail" : "pass",
1143 crypto_free_comp(tfm
);
1146 static void test_available(void)
1148 char **name
= check
;
1151 printk("alg %s ", *name
);
1152 printk(crypto_has_alg(*name
, 0, 0) ?
1153 "found\n" : "not found\n");
1158 static void do_test(void)
1163 test_hash("md5", md5_tv_template
, MD5_TEST_VECTORS
);
1165 test_hash("sha1", sha1_tv_template
, SHA1_TEST_VECTORS
);
1168 test_cipher("ecb(des)", ENCRYPT
, des_enc_tv_template
,
1169 DES_ENC_TEST_VECTORS
);
1170 test_cipher("ecb(des)", DECRYPT
, des_dec_tv_template
,
1171 DES_DEC_TEST_VECTORS
);
1172 test_cipher("cbc(des)", ENCRYPT
, des_cbc_enc_tv_template
,
1173 DES_CBC_ENC_TEST_VECTORS
);
1174 test_cipher("cbc(des)", DECRYPT
, des_cbc_dec_tv_template
,
1175 DES_CBC_DEC_TEST_VECTORS
);
1178 test_cipher("ecb(des3_ede)", ENCRYPT
, des3_ede_enc_tv_template
,
1179 DES3_EDE_ENC_TEST_VECTORS
);
1180 test_cipher("ecb(des3_ede)", DECRYPT
, des3_ede_dec_tv_template
,
1181 DES3_EDE_DEC_TEST_VECTORS
);
1183 test_hash("md4", md4_tv_template
, MD4_TEST_VECTORS
);
1185 test_hash("sha224", sha224_tv_template
, SHA224_TEST_VECTORS
);
1187 test_hash("sha256", sha256_tv_template
, SHA256_TEST_VECTORS
);
1190 test_cipher("ecb(blowfish)", ENCRYPT
, bf_enc_tv_template
,
1191 BF_ENC_TEST_VECTORS
);
1192 test_cipher("ecb(blowfish)", DECRYPT
, bf_dec_tv_template
,
1193 BF_DEC_TEST_VECTORS
);
1194 test_cipher("cbc(blowfish)", ENCRYPT
, bf_cbc_enc_tv_template
,
1195 BF_CBC_ENC_TEST_VECTORS
);
1196 test_cipher("cbc(blowfish)", DECRYPT
, bf_cbc_dec_tv_template
,
1197 BF_CBC_DEC_TEST_VECTORS
);
1200 test_cipher("ecb(twofish)", ENCRYPT
, tf_enc_tv_template
,
1201 TF_ENC_TEST_VECTORS
);
1202 test_cipher("ecb(twofish)", DECRYPT
, tf_dec_tv_template
,
1203 TF_DEC_TEST_VECTORS
);
1204 test_cipher("cbc(twofish)", ENCRYPT
, tf_cbc_enc_tv_template
,
1205 TF_CBC_ENC_TEST_VECTORS
);
1206 test_cipher("cbc(twofish)", DECRYPT
, tf_cbc_dec_tv_template
,
1207 TF_CBC_DEC_TEST_VECTORS
);
1210 test_cipher("ecb(serpent)", ENCRYPT
, serpent_enc_tv_template
,
1211 SERPENT_ENC_TEST_VECTORS
);
1212 test_cipher("ecb(serpent)", DECRYPT
, serpent_dec_tv_template
,
1213 SERPENT_DEC_TEST_VECTORS
);
1216 test_cipher("ecb(tnepres)", ENCRYPT
, tnepres_enc_tv_template
,
1217 TNEPRES_ENC_TEST_VECTORS
);
1218 test_cipher("ecb(tnepres)", DECRYPT
, tnepres_dec_tv_template
,
1219 TNEPRES_DEC_TEST_VECTORS
);
1222 test_cipher("ecb(aes)", ENCRYPT
, aes_enc_tv_template
,
1223 AES_ENC_TEST_VECTORS
);
1224 test_cipher("ecb(aes)", DECRYPT
, aes_dec_tv_template
,
1225 AES_DEC_TEST_VECTORS
);
1226 test_cipher("cbc(aes)", ENCRYPT
, aes_cbc_enc_tv_template
,
1227 AES_CBC_ENC_TEST_VECTORS
);
1228 test_cipher("cbc(aes)", DECRYPT
, aes_cbc_dec_tv_template
,
1229 AES_CBC_DEC_TEST_VECTORS
);
1230 test_cipher("lrw(aes)", ENCRYPT
, aes_lrw_enc_tv_template
,
1231 AES_LRW_ENC_TEST_VECTORS
);
1232 test_cipher("lrw(aes)", DECRYPT
, aes_lrw_dec_tv_template
,
1233 AES_LRW_DEC_TEST_VECTORS
);
1234 test_cipher("xts(aes)", ENCRYPT
, aes_xts_enc_tv_template
,
1235 AES_XTS_ENC_TEST_VECTORS
);
1236 test_cipher("xts(aes)", DECRYPT
, aes_xts_dec_tv_template
,
1237 AES_XTS_DEC_TEST_VECTORS
);
1238 test_cipher("rfc3686(ctr(aes))", ENCRYPT
, aes_ctr_enc_tv_template
,
1239 AES_CTR_ENC_TEST_VECTORS
);
1240 test_cipher("rfc3686(ctr(aes))", DECRYPT
, aes_ctr_dec_tv_template
,
1241 AES_CTR_DEC_TEST_VECTORS
);
1242 test_aead("gcm(aes)", ENCRYPT
, aes_gcm_enc_tv_template
,
1243 AES_GCM_ENC_TEST_VECTORS
);
1244 test_aead("gcm(aes)", DECRYPT
, aes_gcm_dec_tv_template
,
1245 AES_GCM_DEC_TEST_VECTORS
);
1246 test_aead("ccm(aes)", ENCRYPT
, aes_ccm_enc_tv_template
,
1247 AES_CCM_ENC_TEST_VECTORS
);
1248 test_aead("ccm(aes)", DECRYPT
, aes_ccm_dec_tv_template
,
1249 AES_CCM_DEC_TEST_VECTORS
);
1252 test_cipher("ecb(cast5)", ENCRYPT
, cast5_enc_tv_template
,
1253 CAST5_ENC_TEST_VECTORS
);
1254 test_cipher("ecb(cast5)", DECRYPT
, cast5_dec_tv_template
,
1255 CAST5_DEC_TEST_VECTORS
);
1258 test_cipher("ecb(cast6)", ENCRYPT
, cast6_enc_tv_template
,
1259 CAST6_ENC_TEST_VECTORS
);
1260 test_cipher("ecb(cast6)", DECRYPT
, cast6_dec_tv_template
,
1261 CAST6_DEC_TEST_VECTORS
);
1264 test_cipher("ecb(arc4)", ENCRYPT
, arc4_enc_tv_template
,
1265 ARC4_ENC_TEST_VECTORS
);
1266 test_cipher("ecb(arc4)", DECRYPT
, arc4_dec_tv_template
,
1267 ARC4_DEC_TEST_VECTORS
);
1270 test_cipher("ecb(tea)", ENCRYPT
, tea_enc_tv_template
,
1271 TEA_ENC_TEST_VECTORS
);
1272 test_cipher("ecb(tea)", DECRYPT
, tea_dec_tv_template
,
1273 TEA_DEC_TEST_VECTORS
);
1277 test_cipher("ecb(xtea)", ENCRYPT
, xtea_enc_tv_template
,
1278 XTEA_ENC_TEST_VECTORS
);
1279 test_cipher("ecb(xtea)", DECRYPT
, xtea_dec_tv_template
,
1280 XTEA_DEC_TEST_VECTORS
);
1283 test_cipher("ecb(khazad)", ENCRYPT
, khazad_enc_tv_template
,
1284 KHAZAD_ENC_TEST_VECTORS
);
1285 test_cipher("ecb(khazad)", DECRYPT
, khazad_dec_tv_template
,
1286 KHAZAD_DEC_TEST_VECTORS
);
1289 test_cipher("ecb(anubis)", ENCRYPT
, anubis_enc_tv_template
,
1290 ANUBIS_ENC_TEST_VECTORS
);
1291 test_cipher("ecb(anubis)", DECRYPT
, anubis_dec_tv_template
,
1292 ANUBIS_DEC_TEST_VECTORS
);
1293 test_cipher("cbc(anubis)", ENCRYPT
, anubis_cbc_enc_tv_template
,
1294 ANUBIS_CBC_ENC_TEST_VECTORS
);
1295 test_cipher("cbc(anubis)", DECRYPT
, anubis_cbc_dec_tv_template
,
1296 ANUBIS_CBC_ENC_TEST_VECTORS
);
1299 test_cipher("ecb(xeta)", ENCRYPT
, xeta_enc_tv_template
,
1300 XETA_ENC_TEST_VECTORS
);
1301 test_cipher("ecb(xeta)", DECRYPT
, xeta_dec_tv_template
,
1302 XETA_DEC_TEST_VECTORS
);
1305 test_cipher("pcbc(fcrypt)", ENCRYPT
, fcrypt_pcbc_enc_tv_template
,
1306 FCRYPT_ENC_TEST_VECTORS
);
1307 test_cipher("pcbc(fcrypt)", DECRYPT
, fcrypt_pcbc_dec_tv_template
,
1308 FCRYPT_DEC_TEST_VECTORS
);
1311 test_cipher("ecb(camellia)", ENCRYPT
,
1312 camellia_enc_tv_template
,
1313 CAMELLIA_ENC_TEST_VECTORS
);
1314 test_cipher("ecb(camellia)", DECRYPT
,
1315 camellia_dec_tv_template
,
1316 CAMELLIA_DEC_TEST_VECTORS
);
1317 test_cipher("cbc(camellia)", ENCRYPT
,
1318 camellia_cbc_enc_tv_template
,
1319 CAMELLIA_CBC_ENC_TEST_VECTORS
);
1320 test_cipher("cbc(camellia)", DECRYPT
,
1321 camellia_cbc_dec_tv_template
,
1322 CAMELLIA_CBC_DEC_TEST_VECTORS
);
1325 test_cipher("ecb(seed)", ENCRYPT
, seed_enc_tv_template
,
1326 SEED_ENC_TEST_VECTORS
);
1327 test_cipher("ecb(seed)", DECRYPT
, seed_dec_tv_template
,
1328 SEED_DEC_TEST_VECTORS
);
1331 test_cipher("cts(cbc(aes))", ENCRYPT
, cts_mode_enc_tv_template
,
1332 CTS_MODE_ENC_TEST_VECTORS
);
1333 test_cipher("cts(cbc(aes))", DECRYPT
, cts_mode_dec_tv_template
,
1334 CTS_MODE_DEC_TEST_VECTORS
);
1336 test_hash("sha384", sha384_tv_template
, SHA384_TEST_VECTORS
);
1337 test_hash("sha512", sha512_tv_template
, SHA512_TEST_VECTORS
);
1338 test_hash("wp512", wp512_tv_template
, WP512_TEST_VECTORS
);
1339 test_hash("wp384", wp384_tv_template
, WP384_TEST_VECTORS
);
1340 test_hash("wp256", wp256_tv_template
, WP256_TEST_VECTORS
);
1341 test_hash("tgr192", tgr192_tv_template
, TGR192_TEST_VECTORS
);
1342 test_hash("tgr160", tgr160_tv_template
, TGR160_TEST_VECTORS
);
1343 test_hash("tgr128", tgr128_tv_template
, TGR128_TEST_VECTORS
);
1344 test_comp("deflate", deflate_comp_tv_template
,
1345 deflate_decomp_tv_template
, DEFLATE_COMP_TEST_VECTORS
,
1346 DEFLATE_DECOMP_TEST_VECTORS
);
1347 test_comp("lzo", lzo_comp_tv_template
, lzo_decomp_tv_template
,
1348 LZO_COMP_TEST_VECTORS
, LZO_DECOMP_TEST_VECTORS
);
1349 test_hash("crc32c", crc32c_tv_template
, CRC32C_TEST_VECTORS
);
1350 test_hash("hmac(md5)", hmac_md5_tv_template
,
1351 HMAC_MD5_TEST_VECTORS
);
1352 test_hash("hmac(sha1)", hmac_sha1_tv_template
,
1353 HMAC_SHA1_TEST_VECTORS
);
1354 test_hash("hmac(sha224)", hmac_sha224_tv_template
,
1355 HMAC_SHA224_TEST_VECTORS
);
1356 test_hash("hmac(sha256)", hmac_sha256_tv_template
,
1357 HMAC_SHA256_TEST_VECTORS
);
1358 test_hash("hmac(sha384)", hmac_sha384_tv_template
,
1359 HMAC_SHA384_TEST_VECTORS
);
1360 test_hash("hmac(sha512)", hmac_sha512_tv_template
,
1361 HMAC_SHA512_TEST_VECTORS
);
1363 test_hash("xcbc(aes)", aes_xcbc128_tv_template
,
1364 XCBC_AES_TEST_VECTORS
);
1366 test_hash("michael_mic", michael_mic_tv_template
, MICHAEL_MIC_TEST_VECTORS
);
1370 test_hash("md5", md5_tv_template
, MD5_TEST_VECTORS
);
1374 test_hash("sha1", sha1_tv_template
, SHA1_TEST_VECTORS
);
1378 test_cipher("ecb(des)", ENCRYPT
, des_enc_tv_template
,
1379 DES_ENC_TEST_VECTORS
);
1380 test_cipher("ecb(des)", DECRYPT
, des_dec_tv_template
,
1381 DES_DEC_TEST_VECTORS
);
1382 test_cipher("cbc(des)", ENCRYPT
, des_cbc_enc_tv_template
,
1383 DES_CBC_ENC_TEST_VECTORS
);
1384 test_cipher("cbc(des)", DECRYPT
, des_cbc_dec_tv_template
,
1385 DES_CBC_DEC_TEST_VECTORS
);
1389 test_cipher("ecb(des3_ede)", ENCRYPT
, des3_ede_enc_tv_template
,
1390 DES3_EDE_ENC_TEST_VECTORS
);
1391 test_cipher("ecb(des3_ede)", DECRYPT
, des3_ede_dec_tv_template
,
1392 DES3_EDE_DEC_TEST_VECTORS
);
1396 test_hash("md4", md4_tv_template
, MD4_TEST_VECTORS
);
1400 test_hash("sha256", sha256_tv_template
, SHA256_TEST_VECTORS
);
1404 test_cipher("ecb(blowfish)", ENCRYPT
, bf_enc_tv_template
,
1405 BF_ENC_TEST_VECTORS
);
1406 test_cipher("ecb(blowfish)", DECRYPT
, bf_dec_tv_template
,
1407 BF_DEC_TEST_VECTORS
);
1408 test_cipher("cbc(blowfish)", ENCRYPT
, bf_cbc_enc_tv_template
,
1409 BF_CBC_ENC_TEST_VECTORS
);
1410 test_cipher("cbc(blowfish)", DECRYPT
, bf_cbc_dec_tv_template
,
1411 BF_CBC_DEC_TEST_VECTORS
);
1415 test_cipher("ecb(twofish)", ENCRYPT
, tf_enc_tv_template
,
1416 TF_ENC_TEST_VECTORS
);
1417 test_cipher("ecb(twofish)", DECRYPT
, tf_dec_tv_template
,
1418 TF_DEC_TEST_VECTORS
);
1419 test_cipher("cbc(twofish)", ENCRYPT
, tf_cbc_enc_tv_template
,
1420 TF_CBC_ENC_TEST_VECTORS
);
1421 test_cipher("cbc(twofish)", DECRYPT
, tf_cbc_dec_tv_template
,
1422 TF_CBC_DEC_TEST_VECTORS
);
1426 test_cipher("ecb(serpent)", ENCRYPT
, serpent_enc_tv_template
,
1427 SERPENT_ENC_TEST_VECTORS
);
1428 test_cipher("ecb(serpent)", DECRYPT
, serpent_dec_tv_template
,
1429 SERPENT_DEC_TEST_VECTORS
);
1433 test_cipher("ecb(aes)", ENCRYPT
, aes_enc_tv_template
,
1434 AES_ENC_TEST_VECTORS
);
1435 test_cipher("ecb(aes)", DECRYPT
, aes_dec_tv_template
,
1436 AES_DEC_TEST_VECTORS
);
1437 test_cipher("cbc(aes)", ENCRYPT
, aes_cbc_enc_tv_template
,
1438 AES_CBC_ENC_TEST_VECTORS
);
1439 test_cipher("cbc(aes)", DECRYPT
, aes_cbc_dec_tv_template
,
1440 AES_CBC_DEC_TEST_VECTORS
);
1441 test_cipher("lrw(aes)", ENCRYPT
, aes_lrw_enc_tv_template
,
1442 AES_LRW_ENC_TEST_VECTORS
);
1443 test_cipher("lrw(aes)", DECRYPT
, aes_lrw_dec_tv_template
,
1444 AES_LRW_DEC_TEST_VECTORS
);
1445 test_cipher("xts(aes)", ENCRYPT
, aes_xts_enc_tv_template
,
1446 AES_XTS_ENC_TEST_VECTORS
);
1447 test_cipher("xts(aes)", DECRYPT
, aes_xts_dec_tv_template
,
1448 AES_XTS_DEC_TEST_VECTORS
);
1449 test_cipher("rfc3686(ctr(aes))", ENCRYPT
, aes_ctr_enc_tv_template
,
1450 AES_CTR_ENC_TEST_VECTORS
);
1451 test_cipher("rfc3686(ctr(aes))", DECRYPT
, aes_ctr_dec_tv_template
,
1452 AES_CTR_DEC_TEST_VECTORS
);
1456 test_hash("sha384", sha384_tv_template
, SHA384_TEST_VECTORS
);
1460 test_hash("sha512", sha512_tv_template
, SHA512_TEST_VECTORS
);
1464 test_comp("deflate", deflate_comp_tv_template
,
1465 deflate_decomp_tv_template
, DEFLATE_COMP_TEST_VECTORS
,
1466 DEFLATE_DECOMP_TEST_VECTORS
);
1470 test_cipher("ecb(cast5)", ENCRYPT
, cast5_enc_tv_template
,
1471 CAST5_ENC_TEST_VECTORS
);
1472 test_cipher("ecb(cast5)", DECRYPT
, cast5_dec_tv_template
,
1473 CAST5_DEC_TEST_VECTORS
);
1477 test_cipher("ecb(cast6)", ENCRYPT
, cast6_enc_tv_template
,
1478 CAST6_ENC_TEST_VECTORS
);
1479 test_cipher("ecb(cast6)", DECRYPT
, cast6_dec_tv_template
,
1480 CAST6_DEC_TEST_VECTORS
);
1484 test_cipher("ecb(arc4)", ENCRYPT
, arc4_enc_tv_template
,
1485 ARC4_ENC_TEST_VECTORS
);
1486 test_cipher("ecb(arc4)", DECRYPT
, arc4_dec_tv_template
,
1487 ARC4_DEC_TEST_VECTORS
);
1491 test_hash("michael_mic", michael_mic_tv_template
, MICHAEL_MIC_TEST_VECTORS
);
1495 test_hash("crc32c", crc32c_tv_template
, CRC32C_TEST_VECTORS
);
1499 test_cipher("ecb(tea)", ENCRYPT
, tea_enc_tv_template
,
1500 TEA_ENC_TEST_VECTORS
);
1501 test_cipher("ecb(tea)", DECRYPT
, tea_dec_tv_template
,
1502 TEA_DEC_TEST_VECTORS
);
1506 test_cipher("ecb(xtea)", ENCRYPT
, xtea_enc_tv_template
,
1507 XTEA_ENC_TEST_VECTORS
);
1508 test_cipher("ecb(xtea)", DECRYPT
, xtea_dec_tv_template
,
1509 XTEA_DEC_TEST_VECTORS
);
1513 test_cipher("ecb(khazad)", ENCRYPT
, khazad_enc_tv_template
,
1514 KHAZAD_ENC_TEST_VECTORS
);
1515 test_cipher("ecb(khazad)", DECRYPT
, khazad_dec_tv_template
,
1516 KHAZAD_DEC_TEST_VECTORS
);
1520 test_hash("wp512", wp512_tv_template
, WP512_TEST_VECTORS
);
1524 test_hash("wp384", wp384_tv_template
, WP384_TEST_VECTORS
);
1528 test_hash("wp256", wp256_tv_template
, WP256_TEST_VECTORS
);
1532 test_cipher("ecb(tnepres)", ENCRYPT
, tnepres_enc_tv_template
,
1533 TNEPRES_ENC_TEST_VECTORS
);
1534 test_cipher("ecb(tnepres)", DECRYPT
, tnepres_dec_tv_template
,
1535 TNEPRES_DEC_TEST_VECTORS
);
1539 test_cipher("ecb(anubis)", ENCRYPT
, anubis_enc_tv_template
,
1540 ANUBIS_ENC_TEST_VECTORS
);
1541 test_cipher("ecb(anubis)", DECRYPT
, anubis_dec_tv_template
,
1542 ANUBIS_DEC_TEST_VECTORS
);
1543 test_cipher("cbc(anubis)", ENCRYPT
, anubis_cbc_enc_tv_template
,
1544 ANUBIS_CBC_ENC_TEST_VECTORS
);
1545 test_cipher("cbc(anubis)", DECRYPT
, anubis_cbc_dec_tv_template
,
1546 ANUBIS_CBC_ENC_TEST_VECTORS
);
1550 test_hash("tgr192", tgr192_tv_template
, TGR192_TEST_VECTORS
);
1555 test_hash("tgr160", tgr160_tv_template
, TGR160_TEST_VECTORS
);
1559 test_hash("tgr128", tgr128_tv_template
, TGR128_TEST_VECTORS
);
1563 test_cipher("ecb(xeta)", ENCRYPT
, xeta_enc_tv_template
,
1564 XETA_ENC_TEST_VECTORS
);
1565 test_cipher("ecb(xeta)", DECRYPT
, xeta_dec_tv_template
,
1566 XETA_DEC_TEST_VECTORS
);
1570 test_cipher("pcbc(fcrypt)", ENCRYPT
, fcrypt_pcbc_enc_tv_template
,
1571 FCRYPT_ENC_TEST_VECTORS
);
1572 test_cipher("pcbc(fcrypt)", DECRYPT
, fcrypt_pcbc_dec_tv_template
,
1573 FCRYPT_DEC_TEST_VECTORS
);
1577 test_cipher("ecb(camellia)", ENCRYPT
,
1578 camellia_enc_tv_template
,
1579 CAMELLIA_ENC_TEST_VECTORS
);
1580 test_cipher("ecb(camellia)", DECRYPT
,
1581 camellia_dec_tv_template
,
1582 CAMELLIA_DEC_TEST_VECTORS
);
1583 test_cipher("cbc(camellia)", ENCRYPT
,
1584 camellia_cbc_enc_tv_template
,
1585 CAMELLIA_CBC_ENC_TEST_VECTORS
);
1586 test_cipher("cbc(camellia)", DECRYPT
,
1587 camellia_cbc_dec_tv_template
,
1588 CAMELLIA_CBC_DEC_TEST_VECTORS
);
1591 test_hash("sha224", sha224_tv_template
, SHA224_TEST_VECTORS
);
1595 test_cipher("salsa20", ENCRYPT
,
1596 salsa20_stream_enc_tv_template
,
1597 SALSA20_STREAM_ENC_TEST_VECTORS
);
1601 test_aead("gcm(aes)", ENCRYPT
, aes_gcm_enc_tv_template
,
1602 AES_GCM_ENC_TEST_VECTORS
);
1603 test_aead("gcm(aes)", DECRYPT
, aes_gcm_dec_tv_template
,
1604 AES_GCM_DEC_TEST_VECTORS
);
1608 test_comp("lzo", lzo_comp_tv_template
, lzo_decomp_tv_template
,
1609 LZO_COMP_TEST_VECTORS
, LZO_DECOMP_TEST_VECTORS
);
1613 test_aead("ccm(aes)", ENCRYPT
, aes_ccm_enc_tv_template
,
1614 AES_CCM_ENC_TEST_VECTORS
);
1615 test_aead("ccm(aes)", DECRYPT
, aes_ccm_dec_tv_template
,
1616 AES_CCM_DEC_TEST_VECTORS
);
1620 test_cipher("cts(cbc(aes))", ENCRYPT
, cts_mode_enc_tv_template
,
1621 CTS_MODE_ENC_TEST_VECTORS
);
1622 test_cipher("cts(cbc(aes))", DECRYPT
, cts_mode_dec_tv_template
,
1623 CTS_MODE_DEC_TEST_VECTORS
);
1627 test_hash("hmac(md5)", hmac_md5_tv_template
,
1628 HMAC_MD5_TEST_VECTORS
);
1632 test_hash("hmac(sha1)", hmac_sha1_tv_template
,
1633 HMAC_SHA1_TEST_VECTORS
);
1637 test_hash("hmac(sha256)", hmac_sha256_tv_template
,
1638 HMAC_SHA256_TEST_VECTORS
);
1642 test_hash("hmac(sha384)", hmac_sha384_tv_template
,
1643 HMAC_SHA384_TEST_VECTORS
);
1647 test_hash("hmac(sha512)", hmac_sha512_tv_template
,
1648 HMAC_SHA512_TEST_VECTORS
);
1652 test_hash("hmac(sha224)", hmac_sha224_tv_template
,
1653 HMAC_SHA224_TEST_VECTORS
);
1657 test_hash("xcbc(aes)", aes_xcbc128_tv_template
,
1658 XCBC_AES_TEST_VECTORS
);
1662 test_cipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1663 speed_template_16_24_32
);
1664 test_cipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1665 speed_template_16_24_32
);
1666 test_cipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1667 speed_template_16_24_32
);
1668 test_cipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1669 speed_template_16_24_32
);
1670 test_cipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1671 speed_template_32_40_48
);
1672 test_cipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1673 speed_template_32_40_48
);
1674 test_cipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1675 speed_template_32_48_64
);
1676 test_cipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1677 speed_template_32_48_64
);
1681 test_cipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1682 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1684 test_cipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1685 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1687 test_cipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1688 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1690 test_cipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1691 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1696 test_cipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1697 speed_template_16_24_32
);
1698 test_cipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1699 speed_template_16_24_32
);
1700 test_cipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1701 speed_template_16_24_32
);
1702 test_cipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1703 speed_template_16_24_32
);
1707 test_cipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1708 speed_template_8_32
);
1709 test_cipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
1710 speed_template_8_32
);
1711 test_cipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1712 speed_template_8_32
);
1713 test_cipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
1714 speed_template_8_32
);
1718 test_cipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1720 test_cipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1722 test_cipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1724 test_cipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1729 test_cipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
1730 speed_template_16_24_32
);
1731 test_cipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
1732 speed_template_16_24_32
);
1733 test_cipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
1734 speed_template_16_24_32
);
1735 test_cipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
1736 speed_template_16_24_32
);
1740 test_cipher_speed("salsa20", ENCRYPT
, sec
, NULL
, 0,
1741 speed_template_16_32
);
1748 test_hash_speed("md4", sec
, generic_hash_speed_template
);
1749 if (mode
> 300 && mode
< 400) break;
1752 test_hash_speed("md5", sec
, generic_hash_speed_template
);
1753 if (mode
> 300 && mode
< 400) break;
1756 test_hash_speed("sha1", sec
, generic_hash_speed_template
);
1757 if (mode
> 300 && mode
< 400) break;
1760 test_hash_speed("sha256", sec
, generic_hash_speed_template
);
1761 if (mode
> 300 && mode
< 400) break;
1764 test_hash_speed("sha384", sec
, generic_hash_speed_template
);
1765 if (mode
> 300 && mode
< 400) break;
1768 test_hash_speed("sha512", sec
, generic_hash_speed_template
);
1769 if (mode
> 300 && mode
< 400) break;
1772 test_hash_speed("wp256", sec
, generic_hash_speed_template
);
1773 if (mode
> 300 && mode
< 400) break;
1776 test_hash_speed("wp384", sec
, generic_hash_speed_template
);
1777 if (mode
> 300 && mode
< 400) break;
1780 test_hash_speed("wp512", sec
, generic_hash_speed_template
);
1781 if (mode
> 300 && mode
< 400) break;
1784 test_hash_speed("tgr128", sec
, generic_hash_speed_template
);
1785 if (mode
> 300 && mode
< 400) break;
1788 test_hash_speed("tgr160", sec
, generic_hash_speed_template
);
1789 if (mode
> 300 && mode
< 400) break;
1792 test_hash_speed("tgr192", sec
, generic_hash_speed_template
);
1793 if (mode
> 300 && mode
< 400) break;
1796 test_hash_speed("sha224", sec
, generic_hash_speed_template
);
1797 if (mode
> 300 && mode
< 400) break;
1807 /* useful for debugging */
1808 printk("not testing anything\n");
1813 static int __init
tcrypt_mod_init(void)
1817 tvmem
= kmalloc(TVMEMSIZE
, GFP_KERNEL
);
1821 xbuf
= kmalloc(XBUFSIZE
, GFP_KERNEL
);
1825 axbuf
= kmalloc(XBUFSIZE
, GFP_KERNEL
);
1831 /* We intentionaly return -EAGAIN to prevent keeping
1832 * the module. It does all its work from init()
1833 * and doesn't offer any runtime functionality
1834 * => we don't need it in the memory, do we?
1849 * If an init function is provided, an exit function must also be provided
1850 * to allow module unload.
1852 static void __exit
tcrypt_mod_fini(void) { }
1854 module_init(tcrypt_mod_init
);
1855 module_exit(tcrypt_mod_fini
);
1857 module_param(mode
, int, 0);
1858 module_param(sec
, uint
, 0);
1859 MODULE_PARM_DESC(sec
, "Length in seconds of speed tests "
1860 "(defaults to zero which uses CPU cycles instead)");
1862 MODULE_LICENSE("GPL");
1863 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1864 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");