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)
18 #include <linux/err.h>
19 #include <linux/init.h>
20 #include <linux/module.h>
22 #include <linux/slab.h>
23 #include <linux/scatterlist.h>
24 #include <linux/string.h>
25 #include <linux/crypto.h>
26 #include <linux/highmem.h>
27 #include <linux/moduleparam.h>
28 #include <linux/jiffies.h>
29 #include <linux/timex.h>
30 #include <linux/interrupt.h>
34 * Need to kmalloc() memory for testing kmap().
36 #define TVMEMSIZE 16384
37 #define XBUFSIZE 32768
40 * Indexes into the xbuf to simulate cross-page access.
52 * Used by test_cipher()
57 struct tcrypt_result
{
58 struct completion completion
;
62 static unsigned int IDX
[8] = { IDX1
, IDX2
, IDX3
, IDX4
, IDX5
, IDX6
, IDX7
, IDX8
};
65 * Used by test_cipher_speed()
67 static unsigned int sec
;
74 static char *check
[] = {
75 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
76 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
77 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
78 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
79 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
83 static void hexdump(unsigned char *buf
, unsigned int len
)
85 print_hex_dump(KERN_CONT
, "", DUMP_PREFIX_OFFSET
,
90 static void tcrypt_complete(struct crypto_async_request
*req
, int err
)
92 struct tcrypt_result
*res
= req
->data
;
94 if (err
== -EINPROGRESS
)
98 complete(&res
->completion
);
101 static void test_hash(char *algo
, struct hash_testvec
*template,
104 unsigned int i
, j
, k
, temp
;
105 struct scatterlist sg
[8];
107 struct crypto_ahash
*tfm
;
108 struct ahash_request
*req
;
109 struct tcrypt_result tresult
;
113 printk("\ntesting %s\n", algo
);
115 init_completion(&tresult
.completion
);
117 tfm
= crypto_alloc_ahash(algo
, 0, 0);
119 printk("failed to load transform for %s: %ld\n", algo
,
124 req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
126 printk(KERN_ERR
"failed to allocate request for %s\n", algo
);
129 ahash_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
130 tcrypt_complete
, &tresult
);
132 for (i
= 0; i
< tcount
; i
++) {
133 printk("test %u:\n", i
+ 1);
134 memset(result
, 0, 64);
136 hash_buff
= kzalloc(template[i
].psize
, GFP_KERNEL
);
140 memcpy(hash_buff
, template[i
].plaintext
, template[i
].psize
);
141 sg_init_one(&sg
[0], hash_buff
, template[i
].psize
);
143 if (template[i
].ksize
) {
144 crypto_ahash_clear_flags(tfm
, ~0);
145 ret
= crypto_ahash_setkey(tfm
, template[i
].key
,
148 printk("setkey() failed ret=%d\n", ret
);
154 ahash_request_set_crypt(req
, sg
, result
, template[i
].psize
);
155 ret
= crypto_ahash_digest(req
);
161 ret
= wait_for_completion_interruptible(
162 &tresult
.completion
);
163 if (!ret
&& !(ret
= tresult
.err
)) {
164 INIT_COMPLETION(tresult
.completion
);
169 printk("digest () failed ret=%d\n", ret
);
174 hexdump(result
, crypto_ahash_digestsize(tfm
));
176 memcmp(result
, template[i
].digest
,
177 crypto_ahash_digestsize(tfm
)) ?
182 printk("testing %s across pages\n", algo
);
184 /* setup the dummy buffer first */
185 memset(xbuf
, 0, XBUFSIZE
);
188 for (i
= 0; i
< tcount
; i
++) {
189 if (template[i
].np
) {
191 printk("test %u:\n", j
);
192 memset(result
, 0, 64);
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
,
200 temp
+= template[i
].tap
[k
];
201 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
205 if (template[i
].ksize
) {
206 crypto_ahash_clear_flags(tfm
, ~0);
207 ret
= crypto_ahash_setkey(tfm
, template[i
].key
,
211 printk("setkey() failed ret=%d\n", ret
);
216 ahash_request_set_crypt(req
, sg
, result
,
218 ret
= crypto_ahash_digest(req
);
224 ret
= wait_for_completion_interruptible(
225 &tresult
.completion
);
226 if (!ret
&& !(ret
= tresult
.err
)) {
227 INIT_COMPLETION(tresult
.completion
);
232 printk("digest () failed ret=%d\n", ret
);
236 hexdump(result
, crypto_ahash_digestsize(tfm
));
238 memcmp(result
, template[i
].digest
,
239 crypto_ahash_digestsize(tfm
)) ?
245 ahash_request_free(req
);
247 crypto_free_ahash(tfm
);
250 static void test_aead(char *algo
, int enc
, struct aead_testvec
*template,
253 unsigned int ret
, i
, j
, k
, n
, temp
;
255 struct crypto_aead
*tfm
;
257 struct aead_request
*req
;
258 struct scatterlist sg
[8];
259 struct scatterlist asg
[8];
261 struct tcrypt_result result
;
262 unsigned int authsize
;
272 printk(KERN_INFO
"\ntesting %s %s\n", algo
, e
);
274 init_completion(&result
.completion
);
276 tfm
= crypto_alloc_aead(algo
, 0, 0);
279 printk(KERN_INFO
"failed to load transform for %s: %ld\n",
284 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
286 printk(KERN_INFO
"failed to allocate request for %s\n", algo
);
290 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
291 tcrypt_complete
, &result
);
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);
298 /* some tepmplates have no input data but they will
301 input
= kzalloc(template[i
].ilen
+ template[i
].rlen
, GFP_KERNEL
);
305 assoc
= kzalloc(template[i
].alen
, GFP_KERNEL
);
311 memcpy(input
, template[i
].input
, template[i
].ilen
);
312 memcpy(assoc
, template[i
].assoc
, template[i
].alen
);
314 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
316 memset(iv
, 0, MAX_IVLEN
);
318 crypto_aead_clear_flags(tfm
, ~0);
320 crypto_aead_set_flags(
321 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
324 key
= template[i
].key
;
326 key
= kzalloc(template[i
].klen
, GFP_KERNEL
);
328 ret
= crypto_aead_setkey(tfm
, key
,
331 printk(KERN_INFO
"setkey() failed flags=%x\n",
332 crypto_aead_get_flags(tfm
));
334 if (!template[i
].fail
)
338 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
339 ret
= crypto_aead_setauthsize(tfm
, authsize
);
342 "failed to set authsize = %u\n",
347 sg_init_one(&sg
[0], input
,
348 template[i
].ilen
+ (enc
? authsize
: 0));
350 sg_init_one(&asg
[0], assoc
, template[i
].alen
);
352 aead_request_set_crypt(req
, sg
, sg
,
353 template[i
].ilen
, iv
);
355 aead_request_set_assoc(req
, asg
, template[i
].alen
);
358 crypto_aead_encrypt(req
) :
359 crypto_aead_decrypt(req
);
366 ret
= wait_for_completion_interruptible(
368 if (!ret
&& !(ret
= result
.err
)) {
369 INIT_COMPLETION(result
.completion
);
374 printk(KERN_INFO
"%s () failed err=%d\n",
379 q
= kmap(sg_page(&sg
[0])) + sg
[0].offset
;
380 hexdump(q
, template[i
].rlen
);
382 printk(KERN_INFO
"enc/dec: %s\n",
383 memcmp(q
, template[i
].result
,
384 template[i
].rlen
) ? "fail" : "pass");
385 kunmap(sg_page(&sg
[0]));
387 if (!template[i
].key
)
394 printk(KERN_INFO
"\ntesting %s %s across pages (chunking)\n", algo
, e
);
395 memset(axbuf
, 0, XBUFSIZE
);
397 for (i
= 0, j
= 0; i
< tcount
; i
++) {
398 if (template[i
].np
) {
399 printk(KERN_INFO
"test %u (%d bit key):\n",
400 ++j
, template[i
].klen
* 8);
403 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
405 memset(iv
, 0, MAX_IVLEN
);
407 crypto_aead_clear_flags(tfm
, ~0);
409 crypto_aead_set_flags(
410 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
411 key
= template[i
].key
;
413 ret
= crypto_aead_setkey(tfm
, key
, template[i
].klen
);
415 printk(KERN_INFO
"setkey() failed flags=%x\n",
416 crypto_aead_get_flags(tfm
));
418 if (!template[i
].fail
)
422 memset(xbuf
, 0, XBUFSIZE
);
423 sg_init_table(sg
, template[i
].np
);
424 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
425 memcpy(&xbuf
[IDX
[k
]],
426 template[i
].input
+ temp
,
428 temp
+= template[i
].tap
[k
];
429 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
433 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
434 ret
= crypto_aead_setauthsize(tfm
, authsize
);
437 "failed to set authsize = %u\n",
443 sg
[k
- 1].length
+= authsize
;
445 sg_init_table(asg
, template[i
].anp
);
446 for (k
= 0, temp
= 0; k
< template[i
].anp
; k
++) {
447 memcpy(&axbuf
[IDX
[k
]],
448 template[i
].assoc
+ temp
,
449 template[i
].atap
[k
]);
450 temp
+= template[i
].atap
[k
];
451 sg_set_buf(&asg
[k
], &axbuf
[IDX
[k
]],
452 template[i
].atap
[k
]);
455 aead_request_set_crypt(req
, sg
, sg
,
459 aead_request_set_assoc(req
, asg
, template[i
].alen
);
462 crypto_aead_encrypt(req
) :
463 crypto_aead_decrypt(req
);
470 ret
= wait_for_completion_interruptible(
472 if (!ret
&& !(ret
= result
.err
)) {
473 INIT_COMPLETION(result
.completion
);
478 printk(KERN_INFO
"%s () failed err=%d\n",
483 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
484 printk(KERN_INFO
"page %u\n", k
);
485 q
= kmap(sg_page(&sg
[k
])) + sg
[k
].offset
;
486 hexdump(q
, template[i
].tap
[k
]);
487 printk(KERN_INFO
"%s\n",
488 memcmp(q
, template[i
].result
+ temp
,
490 (k
< template[i
].np
- 1 || enc
?
494 for (n
= 0; q
[template[i
].tap
[k
] + n
]; n
++)
497 printk("Result buffer corruption %u "
499 hexdump(&q
[template[i
].tap
[k
]], n
);
502 temp
+= template[i
].tap
[k
];
503 kunmap(sg_page(&sg
[k
]));
509 crypto_free_aead(tfm
);
510 aead_request_free(req
);
513 static void test_cipher(char *algo
, int enc
,
514 struct cipher_testvec
*template, unsigned int tcount
)
516 unsigned int ret
, i
, j
, k
, n
, temp
;
518 struct crypto_ablkcipher
*tfm
;
519 struct ablkcipher_request
*req
;
520 struct scatterlist sg
[8];
522 struct tcrypt_result result
;
531 printk("\ntesting %s %s\n", algo
, e
);
533 init_completion(&result
.completion
);
534 tfm
= crypto_alloc_ablkcipher(algo
, 0, 0);
537 printk("failed to load transform for %s: %ld\n", algo
,
542 req
= ablkcipher_request_alloc(tfm
, GFP_KERNEL
);
544 printk("failed to allocate request for %s\n", algo
);
548 ablkcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
549 tcrypt_complete
, &result
);
552 for (i
= 0; i
< tcount
; i
++) {
554 data
= kzalloc(template[i
].ilen
, GFP_KERNEL
);
558 memcpy(data
, template[i
].input
, template[i
].ilen
);
560 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
562 memset(iv
, 0, MAX_IVLEN
);
564 if (!(template[i
].np
)) {
566 printk("test %u (%d bit key):\n",
567 j
, template[i
].klen
* 8);
569 crypto_ablkcipher_clear_flags(tfm
, ~0);
571 crypto_ablkcipher_set_flags(
572 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
574 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
577 printk("setkey() failed flags=%x\n",
578 crypto_ablkcipher_get_flags(tfm
));
580 if (!template[i
].fail
) {
586 sg_init_one(&sg
[0], data
, template[i
].ilen
);
588 ablkcipher_request_set_crypt(req
, sg
, sg
,
589 template[i
].ilen
, iv
);
591 crypto_ablkcipher_encrypt(req
) :
592 crypto_ablkcipher_decrypt(req
);
599 ret
= wait_for_completion_interruptible(
601 if (!ret
&& !((ret
= result
.err
))) {
602 INIT_COMPLETION(result
.completion
);
607 printk("%s () failed err=%d\n", e
, -ret
);
612 q
= kmap(sg_page(&sg
[0])) + sg
[0].offset
;
613 hexdump(q
, template[i
].rlen
);
616 memcmp(q
, template[i
].result
,
617 template[i
].rlen
) ? "fail" : "pass");
618 kunmap(sg_page(&sg
[0]));
623 printk("\ntesting %s %s across pages (chunking)\n", algo
, e
);
626 for (i
= 0; i
< tcount
; i
++) {
629 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
631 memset(iv
, 0, MAX_IVLEN
);
633 if (template[i
].np
) {
635 printk("test %u (%d bit key):\n",
636 j
, template[i
].klen
* 8);
638 memset(xbuf
, 0, XBUFSIZE
);
639 crypto_ablkcipher_clear_flags(tfm
, ~0);
641 crypto_ablkcipher_set_flags(
642 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
644 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
647 printk("setkey() failed flags=%x\n",
648 crypto_ablkcipher_get_flags(tfm
));
650 if (!template[i
].fail
)
655 sg_init_table(sg
, template[i
].np
);
656 for (k
= 0; k
< template[i
].np
; k
++) {
657 memcpy(&xbuf
[IDX
[k
]],
658 template[i
].input
+ temp
,
660 temp
+= template[i
].tap
[k
];
661 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
665 ablkcipher_request_set_crypt(req
, sg
, sg
,
666 template[i
].ilen
, iv
);
669 crypto_ablkcipher_encrypt(req
) :
670 crypto_ablkcipher_decrypt(req
);
677 ret
= wait_for_completion_interruptible(
679 if (!ret
&& !((ret
= result
.err
))) {
680 INIT_COMPLETION(result
.completion
);
685 printk("%s () failed err=%d\n", e
, -ret
);
690 for (k
= 0; k
< template[i
].np
; k
++) {
691 printk("page %u\n", k
);
692 q
= kmap(sg_page(&sg
[k
])) + sg
[k
].offset
;
693 hexdump(q
, template[i
].tap
[k
]);
695 memcmp(q
, template[i
].result
+ temp
,
696 template[i
].tap
[k
]) ? "fail" :
699 for (n
= 0; q
[template[i
].tap
[k
] + n
]; n
++)
702 printk("Result buffer corruption %u "
704 hexdump(&q
[template[i
].tap
[k
]], n
);
706 temp
+= template[i
].tap
[k
];
707 kunmap(sg_page(&sg
[k
]));
712 crypto_free_ablkcipher(tfm
);
713 ablkcipher_request_free(req
);
716 static int test_cipher_jiffies(struct blkcipher_desc
*desc
, int enc
, char *p
,
719 struct scatterlist sg
[1];
720 unsigned long start
, end
;
724 sg_init_one(sg
, p
, blen
);
726 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
727 time_before(jiffies
, end
); bcount
++) {
729 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
731 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
737 printk("%d operations in %d seconds (%ld bytes)\n",
738 bcount
, sec
, (long)bcount
* blen
);
742 static int test_cipher_cycles(struct blkcipher_desc
*desc
, int enc
, char *p
,
745 struct scatterlist sg
[1];
746 unsigned long cycles
= 0;
750 sg_init_one(sg
, p
, blen
);
756 for (i
= 0; i
< 4; i
++) {
758 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
760 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
766 /* The real thing. */
767 for (i
= 0; i
< 8; i
++) {
770 start
= get_cycles();
772 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
774 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
780 cycles
+= end
- start
;
788 printk("1 operation in %lu cycles (%d bytes)\n",
789 (cycles
+ 4) / 8, blen
);
794 static u32 block_sizes
[] = { 16, 64, 256, 1024, 8192, 0 };
796 static void test_cipher_speed(char *algo
, int enc
, unsigned int sec
,
797 struct cipher_testvec
*template,
798 unsigned int tcount
, u8
*keysize
)
800 unsigned int ret
, i
, j
, iv_len
;
801 unsigned char *key
, *p
, iv
[128];
802 struct crypto_blkcipher
*tfm
;
803 struct blkcipher_desc desc
;
812 printk("\ntesting speed of %s %s\n", algo
, e
);
814 tfm
= crypto_alloc_blkcipher(algo
, 0, CRYPTO_ALG_ASYNC
);
817 printk("failed to load transform for %s: %ld\n", algo
,
827 b_size
= block_sizes
;
830 if ((*keysize
+ *b_size
) > TVMEMSIZE
) {
831 printk("template (%u) too big for tvmem (%u)\n",
832 *keysize
+ *b_size
, TVMEMSIZE
);
836 printk("test %u (%d bit key, %d byte blocks): ", i
,
837 *keysize
* 8, *b_size
);
839 memset(tvmem
, 0xff, *keysize
+ *b_size
);
841 /* set key, plain text and IV */
842 key
= (unsigned char *)tvmem
;
843 for (j
= 0; j
< tcount
; j
++) {
844 if (template[j
].klen
== *keysize
) {
845 key
= template[j
].key
;
849 p
= (unsigned char *)tvmem
+ *keysize
;
851 ret
= crypto_blkcipher_setkey(tfm
, key
, *keysize
);
853 printk("setkey() failed flags=%x\n",
854 crypto_blkcipher_get_flags(tfm
));
858 iv_len
= crypto_blkcipher_ivsize(tfm
);
860 memset(&iv
, 0xff, iv_len
);
861 crypto_blkcipher_set_iv(tfm
, iv
, iv_len
);
865 ret
= test_cipher_jiffies(&desc
, enc
, p
, *b_size
, sec
);
867 ret
= test_cipher_cycles(&desc
, enc
, p
, *b_size
);
870 printk("%s() failed flags=%x\n", e
, desc
.flags
);
880 crypto_free_blkcipher(tfm
);
883 static int test_hash_jiffies_digest(struct hash_desc
*desc
, char *p
, int blen
,
886 struct scatterlist sg
[1];
887 unsigned long start
, end
;
891 sg_init_table(sg
, 1);
893 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
894 time_before(jiffies
, end
); bcount
++) {
895 sg_set_buf(sg
, p
, blen
);
896 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
901 printk("%6u opers/sec, %9lu bytes/sec\n",
902 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
907 static int test_hash_jiffies(struct hash_desc
*desc
, char *p
, int blen
,
908 int plen
, char *out
, int sec
)
910 struct scatterlist sg
[1];
911 unsigned long start
, end
;
916 return test_hash_jiffies_digest(desc
, p
, blen
, out
, sec
);
918 sg_init_table(sg
, 1);
920 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
921 time_before(jiffies
, end
); bcount
++) {
922 ret
= crypto_hash_init(desc
);
925 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
926 sg_set_buf(sg
, p
+ pcount
, plen
);
927 ret
= crypto_hash_update(desc
, sg
, plen
);
931 /* we assume there is enough space in 'out' for the result */
932 ret
= crypto_hash_final(desc
, out
);
937 printk("%6u opers/sec, %9lu bytes/sec\n",
938 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
943 static int test_hash_cycles_digest(struct hash_desc
*desc
, char *p
, int blen
,
946 struct scatterlist sg
[1];
947 unsigned long cycles
= 0;
951 sg_init_table(sg
, 1);
957 for (i
= 0; i
< 4; i
++) {
958 sg_set_buf(sg
, p
, blen
);
959 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
964 /* The real thing. */
965 for (i
= 0; i
< 8; i
++) {
968 start
= get_cycles();
970 sg_set_buf(sg
, p
, blen
);
971 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
977 cycles
+= end
- start
;
987 printk("%6lu cycles/operation, %4lu cycles/byte\n",
988 cycles
/ 8, cycles
/ (8 * blen
));
993 static int test_hash_cycles(struct hash_desc
*desc
, char *p
, int blen
,
996 struct scatterlist sg
[1];
997 unsigned long cycles
= 0;
1002 return test_hash_cycles_digest(desc
, p
, blen
, out
);
1004 sg_init_table(sg
, 1);
1007 local_irq_disable();
1010 for (i
= 0; i
< 4; i
++) {
1011 ret
= crypto_hash_init(desc
);
1014 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
1015 sg_set_buf(sg
, p
+ pcount
, plen
);
1016 ret
= crypto_hash_update(desc
, sg
, plen
);
1020 ret
= crypto_hash_final(desc
, out
);
1025 /* The real thing. */
1026 for (i
= 0; i
< 8; i
++) {
1027 cycles_t start
, end
;
1029 start
= get_cycles();
1031 ret
= crypto_hash_init(desc
);
1034 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
1035 sg_set_buf(sg
, p
+ pcount
, plen
);
1036 ret
= crypto_hash_update(desc
, sg
, plen
);
1040 ret
= crypto_hash_final(desc
, out
);
1046 cycles
+= end
- start
;
1056 printk("%6lu cycles/operation, %4lu cycles/byte\n",
1057 cycles
/ 8, cycles
/ (8 * blen
));
1062 static void test_hash_speed(char *algo
, unsigned int sec
,
1063 struct hash_speed
*speed
)
1065 struct crypto_hash
*tfm
;
1066 struct hash_desc desc
;
1071 printk("\ntesting speed of %s\n", algo
);
1073 tfm
= crypto_alloc_hash(algo
, 0, CRYPTO_ALG_ASYNC
);
1076 printk("failed to load transform for %s: %ld\n", algo
,
1084 if (crypto_hash_digestsize(tfm
) > sizeof(output
)) {
1085 printk("digestsize(%u) > outputbuffer(%zu)\n",
1086 crypto_hash_digestsize(tfm
), sizeof(output
));
1090 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
1091 if (speed
[i
].blen
> TVMEMSIZE
) {
1092 printk("template (%u) too big for tvmem (%u)\n",
1093 speed
[i
].blen
, TVMEMSIZE
);
1097 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
1098 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
1100 memset(tvmem
, 0xff, speed
[i
].blen
);
1103 ret
= test_hash_jiffies(&desc
, tvmem
, speed
[i
].blen
,
1104 speed
[i
].plen
, output
, sec
);
1106 ret
= test_hash_cycles(&desc
, tvmem
, speed
[i
].blen
,
1107 speed
[i
].plen
, output
);
1110 printk("hashing failed ret=%d\n", ret
);
1116 crypto_free_hash(tfm
);
1119 static void test_comp(char *algo
, struct comp_testvec
*ctemplate
,
1120 struct comp_testvec
*dtemplate
, int ctcount
, int dtcount
)
1123 char result
[COMP_BUF_SIZE
];
1124 struct crypto_comp
*tfm
;
1127 printk("\ntesting %s compression\n", algo
);
1129 tfm
= crypto_alloc_comp(algo
, 0, CRYPTO_ALG_ASYNC
);
1131 printk("failed to load transform for %s\n", algo
);
1135 for (i
= 0; i
< ctcount
; i
++) {
1136 int ilen
, ret
, dlen
= COMP_BUF_SIZE
;
1138 printk("test %u:\n", i
+ 1);
1139 memset(result
, 0, sizeof (result
));
1141 ilen
= ctemplate
[i
].inlen
;
1142 ret
= crypto_comp_compress(tfm
, ctemplate
[i
].input
,
1143 ilen
, result
, &dlen
);
1145 printk("fail: ret=%d\n", ret
);
1148 hexdump(result
, dlen
);
1149 printk("%s (ratio %d:%d)\n",
1150 memcmp(result
, ctemplate
[i
].output
, dlen
) ? "fail" : "pass",
1154 printk("\ntesting %s decompression\n", algo
);
1156 tsize
= sizeof(struct comp_testvec
);
1158 if (tsize
> TVMEMSIZE
) {
1159 printk("template (%u) too big for tvmem (%u)\n", tsize
,
1164 for (i
= 0; i
< dtcount
; i
++) {
1165 int ilen
, ret
, dlen
= COMP_BUF_SIZE
;
1167 printk("test %u:\n", i
+ 1);
1168 memset(result
, 0, sizeof (result
));
1170 ilen
= dtemplate
[i
].inlen
;
1171 ret
= crypto_comp_decompress(tfm
, dtemplate
[i
].input
,
1172 ilen
, result
, &dlen
);
1174 printk("fail: ret=%d\n", ret
);
1177 hexdump(result
, dlen
);
1178 printk("%s (ratio %d:%d)\n",
1179 memcmp(result
, dtemplate
[i
].output
, dlen
) ? "fail" : "pass",
1183 crypto_free_comp(tfm
);
1186 static void test_available(void)
1188 char **name
= check
;
1191 printk("alg %s ", *name
);
1192 printk(crypto_has_alg(*name
, 0, 0) ?
1193 "found\n" : "not found\n");
1198 static void do_test(void)
1203 test_hash("md5", md5_tv_template
, MD5_TEST_VECTORS
);
1205 test_hash("sha1", sha1_tv_template
, SHA1_TEST_VECTORS
);
1208 test_cipher("ecb(des)", ENCRYPT
, des_enc_tv_template
,
1209 DES_ENC_TEST_VECTORS
);
1210 test_cipher("ecb(des)", DECRYPT
, des_dec_tv_template
,
1211 DES_DEC_TEST_VECTORS
);
1212 test_cipher("cbc(des)", ENCRYPT
, des_cbc_enc_tv_template
,
1213 DES_CBC_ENC_TEST_VECTORS
);
1214 test_cipher("cbc(des)", DECRYPT
, des_cbc_dec_tv_template
,
1215 DES_CBC_DEC_TEST_VECTORS
);
1218 test_cipher("ecb(des3_ede)", ENCRYPT
, des3_ede_enc_tv_template
,
1219 DES3_EDE_ENC_TEST_VECTORS
);
1220 test_cipher("ecb(des3_ede)", DECRYPT
, des3_ede_dec_tv_template
,
1221 DES3_EDE_DEC_TEST_VECTORS
);
1223 test_cipher("cbc(des3_ede)", ENCRYPT
,
1224 des3_ede_cbc_enc_tv_template
,
1225 DES3_EDE_CBC_ENC_TEST_VECTORS
);
1227 test_cipher("cbc(des3_ede)", DECRYPT
,
1228 des3_ede_cbc_dec_tv_template
,
1229 DES3_EDE_CBC_DEC_TEST_VECTORS
);
1231 test_hash("md4", md4_tv_template
, MD4_TEST_VECTORS
);
1233 test_hash("sha224", sha224_tv_template
, SHA224_TEST_VECTORS
);
1235 test_hash("sha256", sha256_tv_template
, SHA256_TEST_VECTORS
);
1238 test_cipher("ecb(blowfish)", ENCRYPT
, bf_enc_tv_template
,
1239 BF_ENC_TEST_VECTORS
);
1240 test_cipher("ecb(blowfish)", DECRYPT
, bf_dec_tv_template
,
1241 BF_DEC_TEST_VECTORS
);
1242 test_cipher("cbc(blowfish)", ENCRYPT
, bf_cbc_enc_tv_template
,
1243 BF_CBC_ENC_TEST_VECTORS
);
1244 test_cipher("cbc(blowfish)", DECRYPT
, bf_cbc_dec_tv_template
,
1245 BF_CBC_DEC_TEST_VECTORS
);
1248 test_cipher("ecb(twofish)", ENCRYPT
, tf_enc_tv_template
,
1249 TF_ENC_TEST_VECTORS
);
1250 test_cipher("ecb(twofish)", DECRYPT
, tf_dec_tv_template
,
1251 TF_DEC_TEST_VECTORS
);
1252 test_cipher("cbc(twofish)", ENCRYPT
, tf_cbc_enc_tv_template
,
1253 TF_CBC_ENC_TEST_VECTORS
);
1254 test_cipher("cbc(twofish)", DECRYPT
, tf_cbc_dec_tv_template
,
1255 TF_CBC_DEC_TEST_VECTORS
);
1258 test_cipher("ecb(serpent)", ENCRYPT
, serpent_enc_tv_template
,
1259 SERPENT_ENC_TEST_VECTORS
);
1260 test_cipher("ecb(serpent)", DECRYPT
, serpent_dec_tv_template
,
1261 SERPENT_DEC_TEST_VECTORS
);
1264 test_cipher("ecb(tnepres)", ENCRYPT
, tnepres_enc_tv_template
,
1265 TNEPRES_ENC_TEST_VECTORS
);
1266 test_cipher("ecb(tnepres)", DECRYPT
, tnepres_dec_tv_template
,
1267 TNEPRES_DEC_TEST_VECTORS
);
1270 test_cipher("ecb(aes)", ENCRYPT
, aes_enc_tv_template
,
1271 AES_ENC_TEST_VECTORS
);
1272 test_cipher("ecb(aes)", DECRYPT
, aes_dec_tv_template
,
1273 AES_DEC_TEST_VECTORS
);
1274 test_cipher("cbc(aes)", ENCRYPT
, aes_cbc_enc_tv_template
,
1275 AES_CBC_ENC_TEST_VECTORS
);
1276 test_cipher("cbc(aes)", DECRYPT
, aes_cbc_dec_tv_template
,
1277 AES_CBC_DEC_TEST_VECTORS
);
1278 test_cipher("lrw(aes)", ENCRYPT
, aes_lrw_enc_tv_template
,
1279 AES_LRW_ENC_TEST_VECTORS
);
1280 test_cipher("lrw(aes)", DECRYPT
, aes_lrw_dec_tv_template
,
1281 AES_LRW_DEC_TEST_VECTORS
);
1282 test_cipher("xts(aes)", ENCRYPT
, aes_xts_enc_tv_template
,
1283 AES_XTS_ENC_TEST_VECTORS
);
1284 test_cipher("xts(aes)", DECRYPT
, aes_xts_dec_tv_template
,
1285 AES_XTS_DEC_TEST_VECTORS
);
1286 test_cipher("rfc3686(ctr(aes))", ENCRYPT
, aes_ctr_enc_tv_template
,
1287 AES_CTR_ENC_TEST_VECTORS
);
1288 test_cipher("rfc3686(ctr(aes))", DECRYPT
, aes_ctr_dec_tv_template
,
1289 AES_CTR_DEC_TEST_VECTORS
);
1290 test_aead("gcm(aes)", ENCRYPT
, aes_gcm_enc_tv_template
,
1291 AES_GCM_ENC_TEST_VECTORS
);
1292 test_aead("gcm(aes)", DECRYPT
, aes_gcm_dec_tv_template
,
1293 AES_GCM_DEC_TEST_VECTORS
);
1294 test_aead("ccm(aes)", ENCRYPT
, aes_ccm_enc_tv_template
,
1295 AES_CCM_ENC_TEST_VECTORS
);
1296 test_aead("ccm(aes)", DECRYPT
, aes_ccm_dec_tv_template
,
1297 AES_CCM_DEC_TEST_VECTORS
);
1300 test_cipher("ecb(cast5)", ENCRYPT
, cast5_enc_tv_template
,
1301 CAST5_ENC_TEST_VECTORS
);
1302 test_cipher("ecb(cast5)", DECRYPT
, cast5_dec_tv_template
,
1303 CAST5_DEC_TEST_VECTORS
);
1306 test_cipher("ecb(cast6)", ENCRYPT
, cast6_enc_tv_template
,
1307 CAST6_ENC_TEST_VECTORS
);
1308 test_cipher("ecb(cast6)", DECRYPT
, cast6_dec_tv_template
,
1309 CAST6_DEC_TEST_VECTORS
);
1312 test_cipher("ecb(arc4)", ENCRYPT
, arc4_enc_tv_template
,
1313 ARC4_ENC_TEST_VECTORS
);
1314 test_cipher("ecb(arc4)", DECRYPT
, arc4_dec_tv_template
,
1315 ARC4_DEC_TEST_VECTORS
);
1318 test_cipher("ecb(tea)", ENCRYPT
, tea_enc_tv_template
,
1319 TEA_ENC_TEST_VECTORS
);
1320 test_cipher("ecb(tea)", DECRYPT
, tea_dec_tv_template
,
1321 TEA_DEC_TEST_VECTORS
);
1325 test_cipher("ecb(xtea)", ENCRYPT
, xtea_enc_tv_template
,
1326 XTEA_ENC_TEST_VECTORS
);
1327 test_cipher("ecb(xtea)", DECRYPT
, xtea_dec_tv_template
,
1328 XTEA_DEC_TEST_VECTORS
);
1331 test_cipher("ecb(khazad)", ENCRYPT
, khazad_enc_tv_template
,
1332 KHAZAD_ENC_TEST_VECTORS
);
1333 test_cipher("ecb(khazad)", DECRYPT
, khazad_dec_tv_template
,
1334 KHAZAD_DEC_TEST_VECTORS
);
1337 test_cipher("ecb(anubis)", ENCRYPT
, anubis_enc_tv_template
,
1338 ANUBIS_ENC_TEST_VECTORS
);
1339 test_cipher("ecb(anubis)", DECRYPT
, anubis_dec_tv_template
,
1340 ANUBIS_DEC_TEST_VECTORS
);
1341 test_cipher("cbc(anubis)", ENCRYPT
, anubis_cbc_enc_tv_template
,
1342 ANUBIS_CBC_ENC_TEST_VECTORS
);
1343 test_cipher("cbc(anubis)", DECRYPT
, anubis_cbc_dec_tv_template
,
1344 ANUBIS_CBC_ENC_TEST_VECTORS
);
1347 test_cipher("ecb(xeta)", ENCRYPT
, xeta_enc_tv_template
,
1348 XETA_ENC_TEST_VECTORS
);
1349 test_cipher("ecb(xeta)", DECRYPT
, xeta_dec_tv_template
,
1350 XETA_DEC_TEST_VECTORS
);
1353 test_cipher("pcbc(fcrypt)", ENCRYPT
, fcrypt_pcbc_enc_tv_template
,
1354 FCRYPT_ENC_TEST_VECTORS
);
1355 test_cipher("pcbc(fcrypt)", DECRYPT
, fcrypt_pcbc_dec_tv_template
,
1356 FCRYPT_DEC_TEST_VECTORS
);
1359 test_cipher("ecb(camellia)", ENCRYPT
,
1360 camellia_enc_tv_template
,
1361 CAMELLIA_ENC_TEST_VECTORS
);
1362 test_cipher("ecb(camellia)", DECRYPT
,
1363 camellia_dec_tv_template
,
1364 CAMELLIA_DEC_TEST_VECTORS
);
1365 test_cipher("cbc(camellia)", ENCRYPT
,
1366 camellia_cbc_enc_tv_template
,
1367 CAMELLIA_CBC_ENC_TEST_VECTORS
);
1368 test_cipher("cbc(camellia)", DECRYPT
,
1369 camellia_cbc_dec_tv_template
,
1370 CAMELLIA_CBC_DEC_TEST_VECTORS
);
1373 test_cipher("ecb(seed)", ENCRYPT
, seed_enc_tv_template
,
1374 SEED_ENC_TEST_VECTORS
);
1375 test_cipher("ecb(seed)", DECRYPT
, seed_dec_tv_template
,
1376 SEED_DEC_TEST_VECTORS
);
1379 test_cipher("cts(cbc(aes))", ENCRYPT
, cts_mode_enc_tv_template
,
1380 CTS_MODE_ENC_TEST_VECTORS
);
1381 test_cipher("cts(cbc(aes))", DECRYPT
, cts_mode_dec_tv_template
,
1382 CTS_MODE_DEC_TEST_VECTORS
);
1384 test_hash("sha384", sha384_tv_template
, SHA384_TEST_VECTORS
);
1385 test_hash("sha512", sha512_tv_template
, SHA512_TEST_VECTORS
);
1386 test_hash("wp512", wp512_tv_template
, WP512_TEST_VECTORS
);
1387 test_hash("wp384", wp384_tv_template
, WP384_TEST_VECTORS
);
1388 test_hash("wp256", wp256_tv_template
, WP256_TEST_VECTORS
);
1389 test_hash("tgr192", tgr192_tv_template
, TGR192_TEST_VECTORS
);
1390 test_hash("tgr160", tgr160_tv_template
, TGR160_TEST_VECTORS
);
1391 test_hash("tgr128", tgr128_tv_template
, TGR128_TEST_VECTORS
);
1392 test_comp("deflate", deflate_comp_tv_template
,
1393 deflate_decomp_tv_template
, DEFLATE_COMP_TEST_VECTORS
,
1394 DEFLATE_DECOMP_TEST_VECTORS
);
1395 test_comp("lzo", lzo_comp_tv_template
, lzo_decomp_tv_template
,
1396 LZO_COMP_TEST_VECTORS
, LZO_DECOMP_TEST_VECTORS
);
1397 test_hash("crc32c", crc32c_tv_template
, CRC32C_TEST_VECTORS
);
1398 test_hash("hmac(md5)", hmac_md5_tv_template
,
1399 HMAC_MD5_TEST_VECTORS
);
1400 test_hash("hmac(sha1)", hmac_sha1_tv_template
,
1401 HMAC_SHA1_TEST_VECTORS
);
1402 test_hash("hmac(sha224)", hmac_sha224_tv_template
,
1403 HMAC_SHA224_TEST_VECTORS
);
1404 test_hash("hmac(sha256)", hmac_sha256_tv_template
,
1405 HMAC_SHA256_TEST_VECTORS
);
1406 test_hash("hmac(sha384)", hmac_sha384_tv_template
,
1407 HMAC_SHA384_TEST_VECTORS
);
1408 test_hash("hmac(sha512)", hmac_sha512_tv_template
,
1409 HMAC_SHA512_TEST_VECTORS
);
1411 test_hash("xcbc(aes)", aes_xcbc128_tv_template
,
1412 XCBC_AES_TEST_VECTORS
);
1414 test_hash("michael_mic", michael_mic_tv_template
, MICHAEL_MIC_TEST_VECTORS
);
1418 test_hash("md5", md5_tv_template
, MD5_TEST_VECTORS
);
1422 test_hash("sha1", sha1_tv_template
, SHA1_TEST_VECTORS
);
1426 test_cipher("ecb(des)", ENCRYPT
, des_enc_tv_template
,
1427 DES_ENC_TEST_VECTORS
);
1428 test_cipher("ecb(des)", DECRYPT
, des_dec_tv_template
,
1429 DES_DEC_TEST_VECTORS
);
1430 test_cipher("cbc(des)", ENCRYPT
, des_cbc_enc_tv_template
,
1431 DES_CBC_ENC_TEST_VECTORS
);
1432 test_cipher("cbc(des)", DECRYPT
, des_cbc_dec_tv_template
,
1433 DES_CBC_DEC_TEST_VECTORS
);
1437 test_cipher("ecb(des3_ede)", ENCRYPT
, des3_ede_enc_tv_template
,
1438 DES3_EDE_ENC_TEST_VECTORS
);
1439 test_cipher("ecb(des3_ede)", DECRYPT
, des3_ede_dec_tv_template
,
1440 DES3_EDE_DEC_TEST_VECTORS
);
1442 test_cipher("cbc(des3_ede)", ENCRYPT
,
1443 des3_ede_cbc_enc_tv_template
,
1444 DES3_EDE_CBC_ENC_TEST_VECTORS
);
1446 test_cipher("cbc(des3_ede)", DECRYPT
,
1447 des3_ede_cbc_dec_tv_template
,
1448 DES3_EDE_CBC_DEC_TEST_VECTORS
);
1452 test_hash("md4", md4_tv_template
, MD4_TEST_VECTORS
);
1456 test_hash("sha256", sha256_tv_template
, SHA256_TEST_VECTORS
);
1460 test_cipher("ecb(blowfish)", ENCRYPT
, bf_enc_tv_template
,
1461 BF_ENC_TEST_VECTORS
);
1462 test_cipher("ecb(blowfish)", DECRYPT
, bf_dec_tv_template
,
1463 BF_DEC_TEST_VECTORS
);
1464 test_cipher("cbc(blowfish)", ENCRYPT
, bf_cbc_enc_tv_template
,
1465 BF_CBC_ENC_TEST_VECTORS
);
1466 test_cipher("cbc(blowfish)", DECRYPT
, bf_cbc_dec_tv_template
,
1467 BF_CBC_DEC_TEST_VECTORS
);
1471 test_cipher("ecb(twofish)", ENCRYPT
, tf_enc_tv_template
,
1472 TF_ENC_TEST_VECTORS
);
1473 test_cipher("ecb(twofish)", DECRYPT
, tf_dec_tv_template
,
1474 TF_DEC_TEST_VECTORS
);
1475 test_cipher("cbc(twofish)", ENCRYPT
, tf_cbc_enc_tv_template
,
1476 TF_CBC_ENC_TEST_VECTORS
);
1477 test_cipher("cbc(twofish)", DECRYPT
, tf_cbc_dec_tv_template
,
1478 TF_CBC_DEC_TEST_VECTORS
);
1482 test_cipher("ecb(serpent)", ENCRYPT
, serpent_enc_tv_template
,
1483 SERPENT_ENC_TEST_VECTORS
);
1484 test_cipher("ecb(serpent)", DECRYPT
, serpent_dec_tv_template
,
1485 SERPENT_DEC_TEST_VECTORS
);
1489 test_cipher("ecb(aes)", ENCRYPT
, aes_enc_tv_template
,
1490 AES_ENC_TEST_VECTORS
);
1491 test_cipher("ecb(aes)", DECRYPT
, aes_dec_tv_template
,
1492 AES_DEC_TEST_VECTORS
);
1493 test_cipher("cbc(aes)", ENCRYPT
, aes_cbc_enc_tv_template
,
1494 AES_CBC_ENC_TEST_VECTORS
);
1495 test_cipher("cbc(aes)", DECRYPT
, aes_cbc_dec_tv_template
,
1496 AES_CBC_DEC_TEST_VECTORS
);
1497 test_cipher("lrw(aes)", ENCRYPT
, aes_lrw_enc_tv_template
,
1498 AES_LRW_ENC_TEST_VECTORS
);
1499 test_cipher("lrw(aes)", DECRYPT
, aes_lrw_dec_tv_template
,
1500 AES_LRW_DEC_TEST_VECTORS
);
1501 test_cipher("xts(aes)", ENCRYPT
, aes_xts_enc_tv_template
,
1502 AES_XTS_ENC_TEST_VECTORS
);
1503 test_cipher("xts(aes)", DECRYPT
, aes_xts_dec_tv_template
,
1504 AES_XTS_DEC_TEST_VECTORS
);
1505 test_cipher("rfc3686(ctr(aes))", ENCRYPT
, aes_ctr_enc_tv_template
,
1506 AES_CTR_ENC_TEST_VECTORS
);
1507 test_cipher("rfc3686(ctr(aes))", DECRYPT
, aes_ctr_dec_tv_template
,
1508 AES_CTR_DEC_TEST_VECTORS
);
1512 test_hash("sha384", sha384_tv_template
, SHA384_TEST_VECTORS
);
1516 test_hash("sha512", sha512_tv_template
, SHA512_TEST_VECTORS
);
1520 test_comp("deflate", deflate_comp_tv_template
,
1521 deflate_decomp_tv_template
, DEFLATE_COMP_TEST_VECTORS
,
1522 DEFLATE_DECOMP_TEST_VECTORS
);
1526 test_cipher("ecb(cast5)", ENCRYPT
, cast5_enc_tv_template
,
1527 CAST5_ENC_TEST_VECTORS
);
1528 test_cipher("ecb(cast5)", DECRYPT
, cast5_dec_tv_template
,
1529 CAST5_DEC_TEST_VECTORS
);
1533 test_cipher("ecb(cast6)", ENCRYPT
, cast6_enc_tv_template
,
1534 CAST6_ENC_TEST_VECTORS
);
1535 test_cipher("ecb(cast6)", DECRYPT
, cast6_dec_tv_template
,
1536 CAST6_DEC_TEST_VECTORS
);
1540 test_cipher("ecb(arc4)", ENCRYPT
, arc4_enc_tv_template
,
1541 ARC4_ENC_TEST_VECTORS
);
1542 test_cipher("ecb(arc4)", DECRYPT
, arc4_dec_tv_template
,
1543 ARC4_DEC_TEST_VECTORS
);
1547 test_hash("michael_mic", michael_mic_tv_template
, MICHAEL_MIC_TEST_VECTORS
);
1551 test_hash("crc32c", crc32c_tv_template
, CRC32C_TEST_VECTORS
);
1555 test_cipher("ecb(tea)", ENCRYPT
, tea_enc_tv_template
,
1556 TEA_ENC_TEST_VECTORS
);
1557 test_cipher("ecb(tea)", DECRYPT
, tea_dec_tv_template
,
1558 TEA_DEC_TEST_VECTORS
);
1562 test_cipher("ecb(xtea)", ENCRYPT
, xtea_enc_tv_template
,
1563 XTEA_ENC_TEST_VECTORS
);
1564 test_cipher("ecb(xtea)", DECRYPT
, xtea_dec_tv_template
,
1565 XTEA_DEC_TEST_VECTORS
);
1569 test_cipher("ecb(khazad)", ENCRYPT
, khazad_enc_tv_template
,
1570 KHAZAD_ENC_TEST_VECTORS
);
1571 test_cipher("ecb(khazad)", DECRYPT
, khazad_dec_tv_template
,
1572 KHAZAD_DEC_TEST_VECTORS
);
1576 test_hash("wp512", wp512_tv_template
, WP512_TEST_VECTORS
);
1580 test_hash("wp384", wp384_tv_template
, WP384_TEST_VECTORS
);
1584 test_hash("wp256", wp256_tv_template
, WP256_TEST_VECTORS
);
1588 test_cipher("ecb(tnepres)", ENCRYPT
, tnepres_enc_tv_template
,
1589 TNEPRES_ENC_TEST_VECTORS
);
1590 test_cipher("ecb(tnepres)", DECRYPT
, tnepres_dec_tv_template
,
1591 TNEPRES_DEC_TEST_VECTORS
);
1595 test_cipher("ecb(anubis)", ENCRYPT
, anubis_enc_tv_template
,
1596 ANUBIS_ENC_TEST_VECTORS
);
1597 test_cipher("ecb(anubis)", DECRYPT
, anubis_dec_tv_template
,
1598 ANUBIS_DEC_TEST_VECTORS
);
1599 test_cipher("cbc(anubis)", ENCRYPT
, anubis_cbc_enc_tv_template
,
1600 ANUBIS_CBC_ENC_TEST_VECTORS
);
1601 test_cipher("cbc(anubis)", DECRYPT
, anubis_cbc_dec_tv_template
,
1602 ANUBIS_CBC_ENC_TEST_VECTORS
);
1606 test_hash("tgr192", tgr192_tv_template
, TGR192_TEST_VECTORS
);
1611 test_hash("tgr160", tgr160_tv_template
, TGR160_TEST_VECTORS
);
1615 test_hash("tgr128", tgr128_tv_template
, TGR128_TEST_VECTORS
);
1619 test_cipher("ecb(xeta)", ENCRYPT
, xeta_enc_tv_template
,
1620 XETA_ENC_TEST_VECTORS
);
1621 test_cipher("ecb(xeta)", DECRYPT
, xeta_dec_tv_template
,
1622 XETA_DEC_TEST_VECTORS
);
1626 test_cipher("pcbc(fcrypt)", ENCRYPT
, fcrypt_pcbc_enc_tv_template
,
1627 FCRYPT_ENC_TEST_VECTORS
);
1628 test_cipher("pcbc(fcrypt)", DECRYPT
, fcrypt_pcbc_dec_tv_template
,
1629 FCRYPT_DEC_TEST_VECTORS
);
1633 test_cipher("ecb(camellia)", ENCRYPT
,
1634 camellia_enc_tv_template
,
1635 CAMELLIA_ENC_TEST_VECTORS
);
1636 test_cipher("ecb(camellia)", DECRYPT
,
1637 camellia_dec_tv_template
,
1638 CAMELLIA_DEC_TEST_VECTORS
);
1639 test_cipher("cbc(camellia)", ENCRYPT
,
1640 camellia_cbc_enc_tv_template
,
1641 CAMELLIA_CBC_ENC_TEST_VECTORS
);
1642 test_cipher("cbc(camellia)", DECRYPT
,
1643 camellia_cbc_dec_tv_template
,
1644 CAMELLIA_CBC_DEC_TEST_VECTORS
);
1647 test_hash("sha224", sha224_tv_template
, SHA224_TEST_VECTORS
);
1651 test_cipher("salsa20", ENCRYPT
,
1652 salsa20_stream_enc_tv_template
,
1653 SALSA20_STREAM_ENC_TEST_VECTORS
);
1657 test_aead("gcm(aes)", ENCRYPT
, aes_gcm_enc_tv_template
,
1658 AES_GCM_ENC_TEST_VECTORS
);
1659 test_aead("gcm(aes)", DECRYPT
, aes_gcm_dec_tv_template
,
1660 AES_GCM_DEC_TEST_VECTORS
);
1664 test_comp("lzo", lzo_comp_tv_template
, lzo_decomp_tv_template
,
1665 LZO_COMP_TEST_VECTORS
, LZO_DECOMP_TEST_VECTORS
);
1669 test_aead("ccm(aes)", ENCRYPT
, aes_ccm_enc_tv_template
,
1670 AES_CCM_ENC_TEST_VECTORS
);
1671 test_aead("ccm(aes)", DECRYPT
, aes_ccm_dec_tv_template
,
1672 AES_CCM_DEC_TEST_VECTORS
);
1676 test_cipher("cts(cbc(aes))", ENCRYPT
, cts_mode_enc_tv_template
,
1677 CTS_MODE_ENC_TEST_VECTORS
);
1678 test_cipher("cts(cbc(aes))", DECRYPT
, cts_mode_dec_tv_template
,
1679 CTS_MODE_DEC_TEST_VECTORS
);
1683 test_hash("rmd128", rmd128_tv_template
, RMD128_TEST_VECTORS
);
1687 test_hash("rmd160", rmd160_tv_template
, RMD160_TEST_VECTORS
);
1691 test_hash("rmd256", rmd256_tv_template
, RMD256_TEST_VECTORS
);
1695 test_hash("rmd320", rmd320_tv_template
, RMD320_TEST_VECTORS
);
1699 test_hash("hmac(md5)", hmac_md5_tv_template
,
1700 HMAC_MD5_TEST_VECTORS
);
1704 test_hash("hmac(sha1)", hmac_sha1_tv_template
,
1705 HMAC_SHA1_TEST_VECTORS
);
1709 test_hash("hmac(sha256)", hmac_sha256_tv_template
,
1710 HMAC_SHA256_TEST_VECTORS
);
1714 test_hash("hmac(sha384)", hmac_sha384_tv_template
,
1715 HMAC_SHA384_TEST_VECTORS
);
1719 test_hash("hmac(sha512)", hmac_sha512_tv_template
,
1720 HMAC_SHA512_TEST_VECTORS
);
1724 test_hash("hmac(sha224)", hmac_sha224_tv_template
,
1725 HMAC_SHA224_TEST_VECTORS
);
1729 test_hash("xcbc(aes)", aes_xcbc128_tv_template
,
1730 XCBC_AES_TEST_VECTORS
);
1734 test_hash("hmac(rmd128)", hmac_rmd128_tv_template
,
1735 HMAC_RMD128_TEST_VECTORS
);
1739 test_hash("hmac(rmd160)", hmac_rmd160_tv_template
,
1740 HMAC_RMD160_TEST_VECTORS
);
1744 test_cipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1745 speed_template_16_24_32
);
1746 test_cipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1747 speed_template_16_24_32
);
1748 test_cipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1749 speed_template_16_24_32
);
1750 test_cipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1751 speed_template_16_24_32
);
1752 test_cipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1753 speed_template_32_40_48
);
1754 test_cipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1755 speed_template_32_40_48
);
1756 test_cipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1757 speed_template_32_48_64
);
1758 test_cipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1759 speed_template_32_48_64
);
1763 test_cipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1764 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1766 test_cipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1767 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1769 test_cipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1770 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1772 test_cipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1773 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1778 test_cipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1779 speed_template_16_24_32
);
1780 test_cipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1781 speed_template_16_24_32
);
1782 test_cipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1783 speed_template_16_24_32
);
1784 test_cipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1785 speed_template_16_24_32
);
1789 test_cipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1790 speed_template_8_32
);
1791 test_cipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
1792 speed_template_8_32
);
1793 test_cipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1794 speed_template_8_32
);
1795 test_cipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
1796 speed_template_8_32
);
1800 test_cipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1802 test_cipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1804 test_cipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1806 test_cipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1811 test_cipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
1812 speed_template_16_24_32
);
1813 test_cipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
1814 speed_template_16_24_32
);
1815 test_cipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
1816 speed_template_16_24_32
);
1817 test_cipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
1818 speed_template_16_24_32
);
1822 test_cipher_speed("salsa20", ENCRYPT
, sec
, NULL
, 0,
1823 speed_template_16_32
);
1830 test_hash_speed("md4", sec
, generic_hash_speed_template
);
1831 if (mode
> 300 && mode
< 400) break;
1834 test_hash_speed("md5", sec
, generic_hash_speed_template
);
1835 if (mode
> 300 && mode
< 400) break;
1838 test_hash_speed("sha1", sec
, generic_hash_speed_template
);
1839 if (mode
> 300 && mode
< 400) break;
1842 test_hash_speed("sha256", sec
, generic_hash_speed_template
);
1843 if (mode
> 300 && mode
< 400) break;
1846 test_hash_speed("sha384", sec
, generic_hash_speed_template
);
1847 if (mode
> 300 && mode
< 400) break;
1850 test_hash_speed("sha512", sec
, generic_hash_speed_template
);
1851 if (mode
> 300 && mode
< 400) break;
1854 test_hash_speed("wp256", sec
, generic_hash_speed_template
);
1855 if (mode
> 300 && mode
< 400) break;
1858 test_hash_speed("wp384", sec
, generic_hash_speed_template
);
1859 if (mode
> 300 && mode
< 400) break;
1862 test_hash_speed("wp512", sec
, generic_hash_speed_template
);
1863 if (mode
> 300 && mode
< 400) break;
1866 test_hash_speed("tgr128", sec
, generic_hash_speed_template
);
1867 if (mode
> 300 && mode
< 400) break;
1870 test_hash_speed("tgr160", sec
, generic_hash_speed_template
);
1871 if (mode
> 300 && mode
< 400) break;
1874 test_hash_speed("tgr192", sec
, generic_hash_speed_template
);
1875 if (mode
> 300 && mode
< 400) break;
1878 test_hash_speed("sha224", sec
, generic_hash_speed_template
);
1879 if (mode
> 300 && mode
< 400) break;
1882 test_hash_speed("rmd128", sec
, generic_hash_speed_template
);
1883 if (mode
> 300 && mode
< 400) break;
1886 test_hash_speed("rmd160", sec
, generic_hash_speed_template
);
1887 if (mode
> 300 && mode
< 400) break;
1890 test_hash_speed("rmd256", sec
, generic_hash_speed_template
);
1891 if (mode
> 300 && mode
< 400) break;
1894 test_hash_speed("rmd320", sec
, generic_hash_speed_template
);
1895 if (mode
> 300 && mode
< 400) break;
1905 /* useful for debugging */
1906 printk("not testing anything\n");
1911 static int __init
tcrypt_mod_init(void)
1915 tvmem
= kmalloc(TVMEMSIZE
, GFP_KERNEL
);
1919 xbuf
= kmalloc(XBUFSIZE
, GFP_KERNEL
);
1923 axbuf
= kmalloc(XBUFSIZE
, GFP_KERNEL
);
1929 /* We intentionaly return -EAGAIN to prevent keeping
1930 * the module. It does all its work from init()
1931 * and doesn't offer any runtime functionality
1932 * => we don't need it in the memory, do we?
1947 * If an init function is provided, an exit function must also be provided
1948 * to allow module unload.
1950 static void __exit
tcrypt_mod_fini(void) { }
1952 module_init(tcrypt_mod_init
);
1953 module_exit(tcrypt_mod_fini
);
1955 module_param(mode
, int, 0);
1956 module_param(sec
, uint
, 0);
1957 MODULE_PARM_DESC(sec
, "Length in seconds of speed tests "
1958 "(defaults to zero which uses CPU cycles instead)");
1960 MODULE_LICENSE("GPL");
1961 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1962 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");