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/moduleparam.h>
27 #include <linux/jiffies.h>
28 #include <linux/timex.h>
29 #include <linux/interrupt.h>
33 * Need to kmalloc() memory for testing.
35 #define TVMEMSIZE 16384
36 #define XBUFSIZE 32768
39 * Indexes into the xbuf to simulate cross-page access.
51 * Used by test_cipher()
56 struct tcrypt_result
{
57 struct completion completion
;
61 static unsigned int IDX
[8] = { IDX1
, IDX2
, IDX3
, IDX4
, IDX5
, IDX6
, IDX7
, IDX8
};
64 * Used by test_cipher_speed()
66 static unsigned int sec
;
73 static char *check
[] = {
74 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
75 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
76 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
77 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
78 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
82 static void hexdump(unsigned char *buf
, unsigned int len
)
84 print_hex_dump(KERN_CONT
, "", DUMP_PREFIX_OFFSET
,
89 static void tcrypt_complete(struct crypto_async_request
*req
, int err
)
91 struct tcrypt_result
*res
= req
->data
;
93 if (err
== -EINPROGRESS
)
97 complete(&res
->completion
);
100 static void test_hash(char *algo
, struct hash_testvec
*template,
103 unsigned int i
, j
, k
, temp
;
104 struct scatterlist sg
[8];
106 struct crypto_ahash
*tfm
;
107 struct ahash_request
*req
;
108 struct tcrypt_result tresult
;
112 printk("\ntesting %s\n", algo
);
114 init_completion(&tresult
.completion
);
116 tfm
= crypto_alloc_ahash(algo
, 0, 0);
118 printk("failed to load transform for %s: %ld\n", algo
,
123 req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
125 printk(KERN_ERR
"failed to allocate request for %s\n", algo
);
128 ahash_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
129 tcrypt_complete
, &tresult
);
131 for (i
= 0; i
< tcount
; i
++) {
132 printk("test %u:\n", i
+ 1);
133 memset(result
, 0, 64);
135 hash_buff
= kzalloc(template[i
].psize
, GFP_KERNEL
);
139 memcpy(hash_buff
, template[i
].plaintext
, template[i
].psize
);
140 sg_init_one(&sg
[0], hash_buff
, template[i
].psize
);
142 if (template[i
].ksize
) {
143 crypto_ahash_clear_flags(tfm
, ~0);
144 ret
= crypto_ahash_setkey(tfm
, template[i
].key
,
147 printk("setkey() failed ret=%d\n", ret
);
153 ahash_request_set_crypt(req
, sg
, result
, template[i
].psize
);
154 ret
= crypto_ahash_digest(req
);
160 ret
= wait_for_completion_interruptible(
161 &tresult
.completion
);
162 if (!ret
&& !(ret
= tresult
.err
)) {
163 INIT_COMPLETION(tresult
.completion
);
168 printk("digest () failed ret=%d\n", ret
);
173 hexdump(result
, crypto_ahash_digestsize(tfm
));
175 memcmp(result
, template[i
].digest
,
176 crypto_ahash_digestsize(tfm
)) ?
181 printk("testing %s across pages\n", algo
);
183 /* setup the dummy buffer first */
184 memset(xbuf
, 0, XBUFSIZE
);
187 for (i
= 0; i
< tcount
; i
++) {
188 if (template[i
].np
) {
190 printk("test %u:\n", j
);
191 memset(result
, 0, 64);
194 sg_init_table(sg
, template[i
].np
);
195 for (k
= 0; k
< template[i
].np
; k
++) {
196 memcpy(&xbuf
[IDX
[k
]],
197 template[i
].plaintext
+ temp
,
199 temp
+= template[i
].tap
[k
];
200 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
204 if (template[i
].ksize
) {
205 crypto_ahash_clear_flags(tfm
, ~0);
206 ret
= crypto_ahash_setkey(tfm
, template[i
].key
,
210 printk("setkey() failed ret=%d\n", ret
);
215 ahash_request_set_crypt(req
, sg
, result
,
217 ret
= crypto_ahash_digest(req
);
223 ret
= wait_for_completion_interruptible(
224 &tresult
.completion
);
225 if (!ret
&& !(ret
= tresult
.err
)) {
226 INIT_COMPLETION(tresult
.completion
);
231 printk("digest () failed ret=%d\n", ret
);
235 hexdump(result
, crypto_ahash_digestsize(tfm
));
237 memcmp(result
, template[i
].digest
,
238 crypto_ahash_digestsize(tfm
)) ?
244 ahash_request_free(req
);
246 crypto_free_ahash(tfm
);
249 static void test_aead(char *algo
, int enc
, struct aead_testvec
*template,
252 unsigned int ret
, i
, j
, k
, n
, temp
;
254 struct crypto_aead
*tfm
;
256 struct aead_request
*req
;
257 struct scatterlist sg
[8];
258 struct scatterlist asg
[8];
260 struct tcrypt_result result
;
261 unsigned int authsize
;
271 printk(KERN_INFO
"\ntesting %s %s\n", algo
, e
);
273 init_completion(&result
.completion
);
275 tfm
= crypto_alloc_aead(algo
, 0, 0);
278 printk(KERN_INFO
"failed to load transform for %s: %ld\n",
283 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
285 printk(KERN_INFO
"failed to allocate request for %s\n", algo
);
289 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
290 tcrypt_complete
, &result
);
292 for (i
= 0, j
= 0; i
< tcount
; i
++) {
293 if (!template[i
].np
) {
294 printk(KERN_INFO
"test %u (%d bit key):\n",
295 ++j
, template[i
].klen
* 8);
297 /* some tepmplates have no input data but they will
300 input
= kzalloc(template[i
].ilen
+ template[i
].rlen
, GFP_KERNEL
);
304 assoc
= kzalloc(template[i
].alen
, GFP_KERNEL
);
310 memcpy(input
, template[i
].input
, template[i
].ilen
);
311 memcpy(assoc
, template[i
].assoc
, template[i
].alen
);
313 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
315 memset(iv
, 0, MAX_IVLEN
);
317 crypto_aead_clear_flags(tfm
, ~0);
319 crypto_aead_set_flags(
320 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
323 key
= template[i
].key
;
325 key
= kzalloc(template[i
].klen
, GFP_KERNEL
);
327 ret
= crypto_aead_setkey(tfm
, key
,
330 printk(KERN_INFO
"setkey() failed flags=%x\n",
331 crypto_aead_get_flags(tfm
));
333 if (!template[i
].fail
)
337 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
338 ret
= crypto_aead_setauthsize(tfm
, authsize
);
341 "failed to set authsize = %u\n",
346 sg_init_one(&sg
[0], input
,
347 template[i
].ilen
+ (enc
? authsize
: 0));
349 sg_init_one(&asg
[0], assoc
, template[i
].alen
);
351 aead_request_set_crypt(req
, sg
, sg
,
352 template[i
].ilen
, iv
);
354 aead_request_set_assoc(req
, asg
, template[i
].alen
);
357 crypto_aead_encrypt(req
) :
358 crypto_aead_decrypt(req
);
365 ret
= wait_for_completion_interruptible(
367 if (!ret
&& !(ret
= result
.err
)) {
368 INIT_COMPLETION(result
.completion
);
373 printk(KERN_INFO
"%s () failed err=%d\n",
379 hexdump(q
, template[i
].rlen
);
381 printk(KERN_INFO
"enc/dec: %s\n",
382 memcmp(q
, template[i
].result
,
383 template[i
].rlen
) ? "fail" : "pass");
385 if (!template[i
].key
)
392 printk(KERN_INFO
"\ntesting %s %s across pages (chunking)\n", algo
, e
);
393 memset(axbuf
, 0, XBUFSIZE
);
395 for (i
= 0, j
= 0; i
< tcount
; i
++) {
396 if (template[i
].np
) {
397 printk(KERN_INFO
"test %u (%d bit key):\n",
398 ++j
, template[i
].klen
* 8);
401 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
403 memset(iv
, 0, MAX_IVLEN
);
405 crypto_aead_clear_flags(tfm
, ~0);
407 crypto_aead_set_flags(
408 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
409 key
= template[i
].key
;
411 ret
= crypto_aead_setkey(tfm
, key
, template[i
].klen
);
413 printk(KERN_INFO
"setkey() failed flags=%x\n",
414 crypto_aead_get_flags(tfm
));
416 if (!template[i
].fail
)
420 memset(xbuf
, 0, XBUFSIZE
);
421 sg_init_table(sg
, template[i
].np
);
422 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
423 memcpy(&xbuf
[IDX
[k
]],
424 template[i
].input
+ temp
,
426 temp
+= template[i
].tap
[k
];
427 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
431 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
432 ret
= crypto_aead_setauthsize(tfm
, authsize
);
435 "failed to set authsize = %u\n",
441 sg
[k
- 1].length
+= authsize
;
443 sg_init_table(asg
, template[i
].anp
);
444 for (k
= 0, temp
= 0; k
< template[i
].anp
; k
++) {
445 memcpy(&axbuf
[IDX
[k
]],
446 template[i
].assoc
+ temp
,
447 template[i
].atap
[k
]);
448 temp
+= template[i
].atap
[k
];
449 sg_set_buf(&asg
[k
], &axbuf
[IDX
[k
]],
450 template[i
].atap
[k
]);
453 aead_request_set_crypt(req
, sg
, sg
,
457 aead_request_set_assoc(req
, asg
, template[i
].alen
);
460 crypto_aead_encrypt(req
) :
461 crypto_aead_decrypt(req
);
468 ret
= wait_for_completion_interruptible(
470 if (!ret
&& !(ret
= result
.err
)) {
471 INIT_COMPLETION(result
.completion
);
476 printk(KERN_INFO
"%s () failed err=%d\n",
481 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
482 printk(KERN_INFO
"page %u\n", k
);
484 hexdump(q
, template[i
].tap
[k
]);
485 printk(KERN_INFO
"%s\n",
486 memcmp(q
, template[i
].result
+ temp
,
488 (k
< template[i
].np
- 1 || enc
?
492 for (n
= 0; q
[template[i
].tap
[k
] + n
]; n
++)
495 printk("Result buffer corruption %u "
497 hexdump(&q
[template[i
].tap
[k
]], n
);
500 temp
+= template[i
].tap
[k
];
506 crypto_free_aead(tfm
);
507 aead_request_free(req
);
510 static void test_cipher(char *algo
, int enc
,
511 struct cipher_testvec
*template, unsigned int tcount
)
513 unsigned int ret
, i
, j
, k
, n
, temp
;
515 struct crypto_ablkcipher
*tfm
;
516 struct ablkcipher_request
*req
;
517 struct scatterlist sg
[8];
519 struct tcrypt_result result
;
528 printk("\ntesting %s %s\n", algo
, e
);
530 init_completion(&result
.completion
);
531 tfm
= crypto_alloc_ablkcipher(algo
, 0, 0);
534 printk("failed to load transform for %s: %ld\n", algo
,
539 req
= ablkcipher_request_alloc(tfm
, GFP_KERNEL
);
541 printk("failed to allocate request for %s\n", algo
);
545 ablkcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
546 tcrypt_complete
, &result
);
549 for (i
= 0; i
< tcount
; i
++) {
551 data
= kzalloc(template[i
].ilen
, GFP_KERNEL
);
555 memcpy(data
, template[i
].input
, template[i
].ilen
);
557 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
559 memset(iv
, 0, MAX_IVLEN
);
561 if (!(template[i
].np
)) {
563 printk("test %u (%d bit key):\n",
564 j
, template[i
].klen
* 8);
566 crypto_ablkcipher_clear_flags(tfm
, ~0);
568 crypto_ablkcipher_set_flags(
569 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
571 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
574 printk("setkey() failed flags=%x\n",
575 crypto_ablkcipher_get_flags(tfm
));
577 if (!template[i
].fail
) {
583 sg_init_one(&sg
[0], data
, template[i
].ilen
);
585 ablkcipher_request_set_crypt(req
, sg
, sg
,
586 template[i
].ilen
, iv
);
588 crypto_ablkcipher_encrypt(req
) :
589 crypto_ablkcipher_decrypt(req
);
596 ret
= wait_for_completion_interruptible(
598 if (!ret
&& !((ret
= result
.err
))) {
599 INIT_COMPLETION(result
.completion
);
604 printk("%s () failed err=%d\n", e
, -ret
);
610 hexdump(q
, template[i
].rlen
);
613 memcmp(q
, template[i
].result
,
614 template[i
].rlen
) ? "fail" : "pass");
619 printk("\ntesting %s %s across pages (chunking)\n", algo
, e
);
622 for (i
= 0; i
< tcount
; i
++) {
625 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
627 memset(iv
, 0, MAX_IVLEN
);
629 if (template[i
].np
) {
631 printk("test %u (%d bit key):\n",
632 j
, template[i
].klen
* 8);
634 memset(xbuf
, 0, XBUFSIZE
);
635 crypto_ablkcipher_clear_flags(tfm
, ~0);
637 crypto_ablkcipher_set_flags(
638 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
640 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
643 printk("setkey() failed flags=%x\n",
644 crypto_ablkcipher_get_flags(tfm
));
646 if (!template[i
].fail
)
651 sg_init_table(sg
, template[i
].np
);
652 for (k
= 0; k
< template[i
].np
; k
++) {
653 memcpy(&xbuf
[IDX
[k
]],
654 template[i
].input
+ temp
,
656 temp
+= template[i
].tap
[k
];
657 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
661 ablkcipher_request_set_crypt(req
, sg
, sg
,
662 template[i
].ilen
, iv
);
665 crypto_ablkcipher_encrypt(req
) :
666 crypto_ablkcipher_decrypt(req
);
673 ret
= wait_for_completion_interruptible(
675 if (!ret
&& !((ret
= result
.err
))) {
676 INIT_COMPLETION(result
.completion
);
681 printk("%s () failed err=%d\n", e
, -ret
);
686 for (k
= 0; k
< template[i
].np
; k
++) {
687 printk("page %u\n", k
);
689 hexdump(q
, template[i
].tap
[k
]);
691 memcmp(q
, template[i
].result
+ temp
,
692 template[i
].tap
[k
]) ? "fail" :
695 for (n
= 0; q
[template[i
].tap
[k
] + n
]; n
++)
698 printk("Result buffer corruption %u "
700 hexdump(&q
[template[i
].tap
[k
]], n
);
702 temp
+= template[i
].tap
[k
];
707 crypto_free_ablkcipher(tfm
);
708 ablkcipher_request_free(req
);
711 static int test_cipher_jiffies(struct blkcipher_desc
*desc
, int enc
, char *p
,
714 struct scatterlist sg
[1];
715 unsigned long start
, end
;
719 sg_init_one(sg
, p
, blen
);
721 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
722 time_before(jiffies
, end
); bcount
++) {
724 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
726 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
732 printk("%d operations in %d seconds (%ld bytes)\n",
733 bcount
, sec
, (long)bcount
* blen
);
737 static int test_cipher_cycles(struct blkcipher_desc
*desc
, int enc
, char *p
,
740 struct scatterlist sg
[1];
741 unsigned long cycles
= 0;
745 sg_init_one(sg
, p
, blen
);
751 for (i
= 0; i
< 4; i
++) {
753 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
755 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
761 /* The real thing. */
762 for (i
= 0; i
< 8; i
++) {
765 start
= get_cycles();
767 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
769 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
775 cycles
+= end
- start
;
783 printk("1 operation in %lu cycles (%d bytes)\n",
784 (cycles
+ 4) / 8, blen
);
789 static u32 block_sizes
[] = { 16, 64, 256, 1024, 8192, 0 };
791 static void test_cipher_speed(char *algo
, int enc
, unsigned int sec
,
792 struct cipher_testvec
*template,
793 unsigned int tcount
, u8
*keysize
)
795 unsigned int ret
, i
, j
, iv_len
;
796 unsigned char *key
, *p
, iv
[128];
797 struct crypto_blkcipher
*tfm
;
798 struct blkcipher_desc desc
;
807 printk("\ntesting speed of %s %s\n", algo
, e
);
809 tfm
= crypto_alloc_blkcipher(algo
, 0, CRYPTO_ALG_ASYNC
);
812 printk("failed to load transform for %s: %ld\n", algo
,
822 b_size
= block_sizes
;
825 if ((*keysize
+ *b_size
) > TVMEMSIZE
) {
826 printk("template (%u) too big for tvmem (%u)\n",
827 *keysize
+ *b_size
, TVMEMSIZE
);
831 printk("test %u (%d bit key, %d byte blocks): ", i
,
832 *keysize
* 8, *b_size
);
834 memset(tvmem
, 0xff, *keysize
+ *b_size
);
836 /* set key, plain text and IV */
837 key
= (unsigned char *)tvmem
;
838 for (j
= 0; j
< tcount
; j
++) {
839 if (template[j
].klen
== *keysize
) {
840 key
= template[j
].key
;
844 p
= (unsigned char *)tvmem
+ *keysize
;
846 ret
= crypto_blkcipher_setkey(tfm
, key
, *keysize
);
848 printk("setkey() failed flags=%x\n",
849 crypto_blkcipher_get_flags(tfm
));
853 iv_len
= crypto_blkcipher_ivsize(tfm
);
855 memset(&iv
, 0xff, iv_len
);
856 crypto_blkcipher_set_iv(tfm
, iv
, iv_len
);
860 ret
= test_cipher_jiffies(&desc
, enc
, p
, *b_size
, sec
);
862 ret
= test_cipher_cycles(&desc
, enc
, p
, *b_size
);
865 printk("%s() failed flags=%x\n", e
, desc
.flags
);
875 crypto_free_blkcipher(tfm
);
878 static int test_hash_jiffies_digest(struct hash_desc
*desc
, char *p
, int blen
,
881 struct scatterlist sg
[1];
882 unsigned long start
, end
;
886 sg_init_table(sg
, 1);
888 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
889 time_before(jiffies
, end
); bcount
++) {
890 sg_set_buf(sg
, p
, blen
);
891 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
896 printk("%6u opers/sec, %9lu bytes/sec\n",
897 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
902 static int test_hash_jiffies(struct hash_desc
*desc
, char *p
, int blen
,
903 int plen
, char *out
, int sec
)
905 struct scatterlist sg
[1];
906 unsigned long start
, end
;
911 return test_hash_jiffies_digest(desc
, p
, blen
, out
, sec
);
913 sg_init_table(sg
, 1);
915 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
916 time_before(jiffies
, end
); bcount
++) {
917 ret
= crypto_hash_init(desc
);
920 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
921 sg_set_buf(sg
, p
+ pcount
, plen
);
922 ret
= crypto_hash_update(desc
, sg
, plen
);
926 /* we assume there is enough space in 'out' for the result */
927 ret
= crypto_hash_final(desc
, out
);
932 printk("%6u opers/sec, %9lu bytes/sec\n",
933 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
938 static int test_hash_cycles_digest(struct hash_desc
*desc
, char *p
, int blen
,
941 struct scatterlist sg
[1];
942 unsigned long cycles
= 0;
946 sg_init_table(sg
, 1);
952 for (i
= 0; i
< 4; i
++) {
953 sg_set_buf(sg
, p
, blen
);
954 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
959 /* The real thing. */
960 for (i
= 0; i
< 8; i
++) {
963 start
= get_cycles();
965 sg_set_buf(sg
, p
, blen
);
966 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
972 cycles
+= end
- start
;
982 printk("%6lu cycles/operation, %4lu cycles/byte\n",
983 cycles
/ 8, cycles
/ (8 * blen
));
988 static int test_hash_cycles(struct hash_desc
*desc
, char *p
, int blen
,
991 struct scatterlist sg
[1];
992 unsigned long cycles
= 0;
997 return test_hash_cycles_digest(desc
, p
, blen
, out
);
999 sg_init_table(sg
, 1);
1002 local_irq_disable();
1005 for (i
= 0; i
< 4; i
++) {
1006 ret
= crypto_hash_init(desc
);
1009 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
1010 sg_set_buf(sg
, p
+ pcount
, plen
);
1011 ret
= crypto_hash_update(desc
, sg
, plen
);
1015 ret
= crypto_hash_final(desc
, out
);
1020 /* The real thing. */
1021 for (i
= 0; i
< 8; i
++) {
1022 cycles_t start
, end
;
1024 start
= get_cycles();
1026 ret
= crypto_hash_init(desc
);
1029 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
1030 sg_set_buf(sg
, p
+ pcount
, plen
);
1031 ret
= crypto_hash_update(desc
, sg
, plen
);
1035 ret
= crypto_hash_final(desc
, out
);
1041 cycles
+= end
- start
;
1051 printk("%6lu cycles/operation, %4lu cycles/byte\n",
1052 cycles
/ 8, cycles
/ (8 * blen
));
1057 static void test_hash_speed(char *algo
, unsigned int sec
,
1058 struct hash_speed
*speed
)
1060 struct crypto_hash
*tfm
;
1061 struct hash_desc desc
;
1066 printk("\ntesting speed of %s\n", algo
);
1068 tfm
= crypto_alloc_hash(algo
, 0, CRYPTO_ALG_ASYNC
);
1071 printk("failed to load transform for %s: %ld\n", algo
,
1079 if (crypto_hash_digestsize(tfm
) > sizeof(output
)) {
1080 printk("digestsize(%u) > outputbuffer(%zu)\n",
1081 crypto_hash_digestsize(tfm
), sizeof(output
));
1085 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
1086 if (speed
[i
].blen
> TVMEMSIZE
) {
1087 printk("template (%u) too big for tvmem (%u)\n",
1088 speed
[i
].blen
, TVMEMSIZE
);
1092 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
1093 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
1095 memset(tvmem
, 0xff, speed
[i
].blen
);
1098 ret
= test_hash_jiffies(&desc
, tvmem
, speed
[i
].blen
,
1099 speed
[i
].plen
, output
, sec
);
1101 ret
= test_hash_cycles(&desc
, tvmem
, speed
[i
].blen
,
1102 speed
[i
].plen
, output
);
1105 printk("hashing failed ret=%d\n", ret
);
1111 crypto_free_hash(tfm
);
1114 static void test_comp(char *algo
, struct comp_testvec
*ctemplate
,
1115 struct comp_testvec
*dtemplate
, int ctcount
, int dtcount
)
1118 char result
[COMP_BUF_SIZE
];
1119 struct crypto_comp
*tfm
;
1122 printk("\ntesting %s compression\n", algo
);
1124 tfm
= crypto_alloc_comp(algo
, 0, CRYPTO_ALG_ASYNC
);
1126 printk("failed to load transform for %s\n", algo
);
1130 for (i
= 0; i
< ctcount
; i
++) {
1131 int ilen
, ret
, dlen
= COMP_BUF_SIZE
;
1133 printk("test %u:\n", i
+ 1);
1134 memset(result
, 0, sizeof (result
));
1136 ilen
= ctemplate
[i
].inlen
;
1137 ret
= crypto_comp_compress(tfm
, ctemplate
[i
].input
,
1138 ilen
, result
, &dlen
);
1140 printk("fail: ret=%d\n", ret
);
1143 hexdump(result
, dlen
);
1144 printk("%s (ratio %d:%d)\n",
1145 memcmp(result
, ctemplate
[i
].output
, dlen
) ? "fail" : "pass",
1149 printk("\ntesting %s decompression\n", algo
);
1151 tsize
= sizeof(struct comp_testvec
);
1153 if (tsize
> TVMEMSIZE
) {
1154 printk("template (%u) too big for tvmem (%u)\n", tsize
,
1159 for (i
= 0; i
< dtcount
; i
++) {
1160 int ilen
, ret
, dlen
= COMP_BUF_SIZE
;
1162 printk("test %u:\n", i
+ 1);
1163 memset(result
, 0, sizeof (result
));
1165 ilen
= dtemplate
[i
].inlen
;
1166 ret
= crypto_comp_decompress(tfm
, dtemplate
[i
].input
,
1167 ilen
, result
, &dlen
);
1169 printk("fail: ret=%d\n", ret
);
1172 hexdump(result
, dlen
);
1173 printk("%s (ratio %d:%d)\n",
1174 memcmp(result
, dtemplate
[i
].output
, dlen
) ? "fail" : "pass",
1178 crypto_free_comp(tfm
);
1181 static void test_available(void)
1183 char **name
= check
;
1186 printk("alg %s ", *name
);
1187 printk(crypto_has_alg(*name
, 0, 0) ?
1188 "found\n" : "not found\n");
1193 static void do_test(void)
1198 test_hash("md5", md5_tv_template
, MD5_TEST_VECTORS
);
1200 test_hash("sha1", sha1_tv_template
, SHA1_TEST_VECTORS
);
1203 test_cipher("ecb(des)", ENCRYPT
, des_enc_tv_template
,
1204 DES_ENC_TEST_VECTORS
);
1205 test_cipher("ecb(des)", DECRYPT
, des_dec_tv_template
,
1206 DES_DEC_TEST_VECTORS
);
1207 test_cipher("cbc(des)", ENCRYPT
, des_cbc_enc_tv_template
,
1208 DES_CBC_ENC_TEST_VECTORS
);
1209 test_cipher("cbc(des)", DECRYPT
, des_cbc_dec_tv_template
,
1210 DES_CBC_DEC_TEST_VECTORS
);
1213 test_cipher("ecb(des3_ede)", ENCRYPT
, des3_ede_enc_tv_template
,
1214 DES3_EDE_ENC_TEST_VECTORS
);
1215 test_cipher("ecb(des3_ede)", DECRYPT
, des3_ede_dec_tv_template
,
1216 DES3_EDE_DEC_TEST_VECTORS
);
1218 test_cipher("cbc(des3_ede)", ENCRYPT
,
1219 des3_ede_cbc_enc_tv_template
,
1220 DES3_EDE_CBC_ENC_TEST_VECTORS
);
1222 test_cipher("cbc(des3_ede)", DECRYPT
,
1223 des3_ede_cbc_dec_tv_template
,
1224 DES3_EDE_CBC_DEC_TEST_VECTORS
);
1226 test_hash("md4", md4_tv_template
, MD4_TEST_VECTORS
);
1228 test_hash("sha224", sha224_tv_template
, SHA224_TEST_VECTORS
);
1230 test_hash("sha256", sha256_tv_template
, SHA256_TEST_VECTORS
);
1233 test_cipher("ecb(blowfish)", ENCRYPT
, bf_enc_tv_template
,
1234 BF_ENC_TEST_VECTORS
);
1235 test_cipher("ecb(blowfish)", DECRYPT
, bf_dec_tv_template
,
1236 BF_DEC_TEST_VECTORS
);
1237 test_cipher("cbc(blowfish)", ENCRYPT
, bf_cbc_enc_tv_template
,
1238 BF_CBC_ENC_TEST_VECTORS
);
1239 test_cipher("cbc(blowfish)", DECRYPT
, bf_cbc_dec_tv_template
,
1240 BF_CBC_DEC_TEST_VECTORS
);
1243 test_cipher("ecb(twofish)", ENCRYPT
, tf_enc_tv_template
,
1244 TF_ENC_TEST_VECTORS
);
1245 test_cipher("ecb(twofish)", DECRYPT
, tf_dec_tv_template
,
1246 TF_DEC_TEST_VECTORS
);
1247 test_cipher("cbc(twofish)", ENCRYPT
, tf_cbc_enc_tv_template
,
1248 TF_CBC_ENC_TEST_VECTORS
);
1249 test_cipher("cbc(twofish)", DECRYPT
, tf_cbc_dec_tv_template
,
1250 TF_CBC_DEC_TEST_VECTORS
);
1253 test_cipher("ecb(serpent)", ENCRYPT
, serpent_enc_tv_template
,
1254 SERPENT_ENC_TEST_VECTORS
);
1255 test_cipher("ecb(serpent)", DECRYPT
, serpent_dec_tv_template
,
1256 SERPENT_DEC_TEST_VECTORS
);
1259 test_cipher("ecb(tnepres)", ENCRYPT
, tnepres_enc_tv_template
,
1260 TNEPRES_ENC_TEST_VECTORS
);
1261 test_cipher("ecb(tnepres)", DECRYPT
, tnepres_dec_tv_template
,
1262 TNEPRES_DEC_TEST_VECTORS
);
1265 test_cipher("ecb(aes)", ENCRYPT
, aes_enc_tv_template
,
1266 AES_ENC_TEST_VECTORS
);
1267 test_cipher("ecb(aes)", DECRYPT
, aes_dec_tv_template
,
1268 AES_DEC_TEST_VECTORS
);
1269 test_cipher("cbc(aes)", ENCRYPT
, aes_cbc_enc_tv_template
,
1270 AES_CBC_ENC_TEST_VECTORS
);
1271 test_cipher("cbc(aes)", DECRYPT
, aes_cbc_dec_tv_template
,
1272 AES_CBC_DEC_TEST_VECTORS
);
1273 test_cipher("lrw(aes)", ENCRYPT
, aes_lrw_enc_tv_template
,
1274 AES_LRW_ENC_TEST_VECTORS
);
1275 test_cipher("lrw(aes)", DECRYPT
, aes_lrw_dec_tv_template
,
1276 AES_LRW_DEC_TEST_VECTORS
);
1277 test_cipher("xts(aes)", ENCRYPT
, aes_xts_enc_tv_template
,
1278 AES_XTS_ENC_TEST_VECTORS
);
1279 test_cipher("xts(aes)", DECRYPT
, aes_xts_dec_tv_template
,
1280 AES_XTS_DEC_TEST_VECTORS
);
1281 test_cipher("rfc3686(ctr(aes))", ENCRYPT
, aes_ctr_enc_tv_template
,
1282 AES_CTR_ENC_TEST_VECTORS
);
1283 test_cipher("rfc3686(ctr(aes))", DECRYPT
, aes_ctr_dec_tv_template
,
1284 AES_CTR_DEC_TEST_VECTORS
);
1285 test_aead("gcm(aes)", ENCRYPT
, aes_gcm_enc_tv_template
,
1286 AES_GCM_ENC_TEST_VECTORS
);
1287 test_aead("gcm(aes)", DECRYPT
, aes_gcm_dec_tv_template
,
1288 AES_GCM_DEC_TEST_VECTORS
);
1289 test_aead("ccm(aes)", ENCRYPT
, aes_ccm_enc_tv_template
,
1290 AES_CCM_ENC_TEST_VECTORS
);
1291 test_aead("ccm(aes)", DECRYPT
, aes_ccm_dec_tv_template
,
1292 AES_CCM_DEC_TEST_VECTORS
);
1295 test_cipher("ecb(cast5)", ENCRYPT
, cast5_enc_tv_template
,
1296 CAST5_ENC_TEST_VECTORS
);
1297 test_cipher("ecb(cast5)", DECRYPT
, cast5_dec_tv_template
,
1298 CAST5_DEC_TEST_VECTORS
);
1301 test_cipher("ecb(cast6)", ENCRYPT
, cast6_enc_tv_template
,
1302 CAST6_ENC_TEST_VECTORS
);
1303 test_cipher("ecb(cast6)", DECRYPT
, cast6_dec_tv_template
,
1304 CAST6_DEC_TEST_VECTORS
);
1307 test_cipher("ecb(arc4)", ENCRYPT
, arc4_enc_tv_template
,
1308 ARC4_ENC_TEST_VECTORS
);
1309 test_cipher("ecb(arc4)", DECRYPT
, arc4_dec_tv_template
,
1310 ARC4_DEC_TEST_VECTORS
);
1313 test_cipher("ecb(tea)", ENCRYPT
, tea_enc_tv_template
,
1314 TEA_ENC_TEST_VECTORS
);
1315 test_cipher("ecb(tea)", DECRYPT
, tea_dec_tv_template
,
1316 TEA_DEC_TEST_VECTORS
);
1320 test_cipher("ecb(xtea)", ENCRYPT
, xtea_enc_tv_template
,
1321 XTEA_ENC_TEST_VECTORS
);
1322 test_cipher("ecb(xtea)", DECRYPT
, xtea_dec_tv_template
,
1323 XTEA_DEC_TEST_VECTORS
);
1326 test_cipher("ecb(khazad)", ENCRYPT
, khazad_enc_tv_template
,
1327 KHAZAD_ENC_TEST_VECTORS
);
1328 test_cipher("ecb(khazad)", DECRYPT
, khazad_dec_tv_template
,
1329 KHAZAD_DEC_TEST_VECTORS
);
1332 test_cipher("ecb(anubis)", ENCRYPT
, anubis_enc_tv_template
,
1333 ANUBIS_ENC_TEST_VECTORS
);
1334 test_cipher("ecb(anubis)", DECRYPT
, anubis_dec_tv_template
,
1335 ANUBIS_DEC_TEST_VECTORS
);
1336 test_cipher("cbc(anubis)", ENCRYPT
, anubis_cbc_enc_tv_template
,
1337 ANUBIS_CBC_ENC_TEST_VECTORS
);
1338 test_cipher("cbc(anubis)", DECRYPT
, anubis_cbc_dec_tv_template
,
1339 ANUBIS_CBC_ENC_TEST_VECTORS
);
1342 test_cipher("ecb(xeta)", ENCRYPT
, xeta_enc_tv_template
,
1343 XETA_ENC_TEST_VECTORS
);
1344 test_cipher("ecb(xeta)", DECRYPT
, xeta_dec_tv_template
,
1345 XETA_DEC_TEST_VECTORS
);
1348 test_cipher("pcbc(fcrypt)", ENCRYPT
, fcrypt_pcbc_enc_tv_template
,
1349 FCRYPT_ENC_TEST_VECTORS
);
1350 test_cipher("pcbc(fcrypt)", DECRYPT
, fcrypt_pcbc_dec_tv_template
,
1351 FCRYPT_DEC_TEST_VECTORS
);
1354 test_cipher("ecb(camellia)", ENCRYPT
,
1355 camellia_enc_tv_template
,
1356 CAMELLIA_ENC_TEST_VECTORS
);
1357 test_cipher("ecb(camellia)", DECRYPT
,
1358 camellia_dec_tv_template
,
1359 CAMELLIA_DEC_TEST_VECTORS
);
1360 test_cipher("cbc(camellia)", ENCRYPT
,
1361 camellia_cbc_enc_tv_template
,
1362 CAMELLIA_CBC_ENC_TEST_VECTORS
);
1363 test_cipher("cbc(camellia)", DECRYPT
,
1364 camellia_cbc_dec_tv_template
,
1365 CAMELLIA_CBC_DEC_TEST_VECTORS
);
1368 test_cipher("ecb(seed)", ENCRYPT
, seed_enc_tv_template
,
1369 SEED_ENC_TEST_VECTORS
);
1370 test_cipher("ecb(seed)", DECRYPT
, seed_dec_tv_template
,
1371 SEED_DEC_TEST_VECTORS
);
1374 test_cipher("cts(cbc(aes))", ENCRYPT
, cts_mode_enc_tv_template
,
1375 CTS_MODE_ENC_TEST_VECTORS
);
1376 test_cipher("cts(cbc(aes))", DECRYPT
, cts_mode_dec_tv_template
,
1377 CTS_MODE_DEC_TEST_VECTORS
);
1379 test_hash("sha384", sha384_tv_template
, SHA384_TEST_VECTORS
);
1380 test_hash("sha512", sha512_tv_template
, SHA512_TEST_VECTORS
);
1381 test_hash("wp512", wp512_tv_template
, WP512_TEST_VECTORS
);
1382 test_hash("wp384", wp384_tv_template
, WP384_TEST_VECTORS
);
1383 test_hash("wp256", wp256_tv_template
, WP256_TEST_VECTORS
);
1384 test_hash("tgr192", tgr192_tv_template
, TGR192_TEST_VECTORS
);
1385 test_hash("tgr160", tgr160_tv_template
, TGR160_TEST_VECTORS
);
1386 test_hash("tgr128", tgr128_tv_template
, TGR128_TEST_VECTORS
);
1387 test_comp("deflate", deflate_comp_tv_template
,
1388 deflate_decomp_tv_template
, DEFLATE_COMP_TEST_VECTORS
,
1389 DEFLATE_DECOMP_TEST_VECTORS
);
1390 test_comp("lzo", lzo_comp_tv_template
, lzo_decomp_tv_template
,
1391 LZO_COMP_TEST_VECTORS
, LZO_DECOMP_TEST_VECTORS
);
1392 test_hash("crc32c", crc32c_tv_template
, CRC32C_TEST_VECTORS
);
1393 test_hash("hmac(md5)", hmac_md5_tv_template
,
1394 HMAC_MD5_TEST_VECTORS
);
1395 test_hash("hmac(sha1)", hmac_sha1_tv_template
,
1396 HMAC_SHA1_TEST_VECTORS
);
1397 test_hash("hmac(sha224)", hmac_sha224_tv_template
,
1398 HMAC_SHA224_TEST_VECTORS
);
1399 test_hash("hmac(sha256)", hmac_sha256_tv_template
,
1400 HMAC_SHA256_TEST_VECTORS
);
1401 test_hash("hmac(sha384)", hmac_sha384_tv_template
,
1402 HMAC_SHA384_TEST_VECTORS
);
1403 test_hash("hmac(sha512)", hmac_sha512_tv_template
,
1404 HMAC_SHA512_TEST_VECTORS
);
1406 test_hash("xcbc(aes)", aes_xcbc128_tv_template
,
1407 XCBC_AES_TEST_VECTORS
);
1409 test_hash("michael_mic", michael_mic_tv_template
, MICHAEL_MIC_TEST_VECTORS
);
1413 test_hash("md5", md5_tv_template
, MD5_TEST_VECTORS
);
1417 test_hash("sha1", sha1_tv_template
, SHA1_TEST_VECTORS
);
1421 test_cipher("ecb(des)", ENCRYPT
, des_enc_tv_template
,
1422 DES_ENC_TEST_VECTORS
);
1423 test_cipher("ecb(des)", DECRYPT
, des_dec_tv_template
,
1424 DES_DEC_TEST_VECTORS
);
1425 test_cipher("cbc(des)", ENCRYPT
, des_cbc_enc_tv_template
,
1426 DES_CBC_ENC_TEST_VECTORS
);
1427 test_cipher("cbc(des)", DECRYPT
, des_cbc_dec_tv_template
,
1428 DES_CBC_DEC_TEST_VECTORS
);
1432 test_cipher("ecb(des3_ede)", ENCRYPT
, des3_ede_enc_tv_template
,
1433 DES3_EDE_ENC_TEST_VECTORS
);
1434 test_cipher("ecb(des3_ede)", DECRYPT
, des3_ede_dec_tv_template
,
1435 DES3_EDE_DEC_TEST_VECTORS
);
1437 test_cipher("cbc(des3_ede)", ENCRYPT
,
1438 des3_ede_cbc_enc_tv_template
,
1439 DES3_EDE_CBC_ENC_TEST_VECTORS
);
1441 test_cipher("cbc(des3_ede)", DECRYPT
,
1442 des3_ede_cbc_dec_tv_template
,
1443 DES3_EDE_CBC_DEC_TEST_VECTORS
);
1447 test_hash("md4", md4_tv_template
, MD4_TEST_VECTORS
);
1451 test_hash("sha256", sha256_tv_template
, SHA256_TEST_VECTORS
);
1455 test_cipher("ecb(blowfish)", ENCRYPT
, bf_enc_tv_template
,
1456 BF_ENC_TEST_VECTORS
);
1457 test_cipher("ecb(blowfish)", DECRYPT
, bf_dec_tv_template
,
1458 BF_DEC_TEST_VECTORS
);
1459 test_cipher("cbc(blowfish)", ENCRYPT
, bf_cbc_enc_tv_template
,
1460 BF_CBC_ENC_TEST_VECTORS
);
1461 test_cipher("cbc(blowfish)", DECRYPT
, bf_cbc_dec_tv_template
,
1462 BF_CBC_DEC_TEST_VECTORS
);
1466 test_cipher("ecb(twofish)", ENCRYPT
, tf_enc_tv_template
,
1467 TF_ENC_TEST_VECTORS
);
1468 test_cipher("ecb(twofish)", DECRYPT
, tf_dec_tv_template
,
1469 TF_DEC_TEST_VECTORS
);
1470 test_cipher("cbc(twofish)", ENCRYPT
, tf_cbc_enc_tv_template
,
1471 TF_CBC_ENC_TEST_VECTORS
);
1472 test_cipher("cbc(twofish)", DECRYPT
, tf_cbc_dec_tv_template
,
1473 TF_CBC_DEC_TEST_VECTORS
);
1477 test_cipher("ecb(serpent)", ENCRYPT
, serpent_enc_tv_template
,
1478 SERPENT_ENC_TEST_VECTORS
);
1479 test_cipher("ecb(serpent)", DECRYPT
, serpent_dec_tv_template
,
1480 SERPENT_DEC_TEST_VECTORS
);
1484 test_cipher("ecb(aes)", ENCRYPT
, aes_enc_tv_template
,
1485 AES_ENC_TEST_VECTORS
);
1486 test_cipher("ecb(aes)", DECRYPT
, aes_dec_tv_template
,
1487 AES_DEC_TEST_VECTORS
);
1488 test_cipher("cbc(aes)", ENCRYPT
, aes_cbc_enc_tv_template
,
1489 AES_CBC_ENC_TEST_VECTORS
);
1490 test_cipher("cbc(aes)", DECRYPT
, aes_cbc_dec_tv_template
,
1491 AES_CBC_DEC_TEST_VECTORS
);
1492 test_cipher("lrw(aes)", ENCRYPT
, aes_lrw_enc_tv_template
,
1493 AES_LRW_ENC_TEST_VECTORS
);
1494 test_cipher("lrw(aes)", DECRYPT
, aes_lrw_dec_tv_template
,
1495 AES_LRW_DEC_TEST_VECTORS
);
1496 test_cipher("xts(aes)", ENCRYPT
, aes_xts_enc_tv_template
,
1497 AES_XTS_ENC_TEST_VECTORS
);
1498 test_cipher("xts(aes)", DECRYPT
, aes_xts_dec_tv_template
,
1499 AES_XTS_DEC_TEST_VECTORS
);
1500 test_cipher("rfc3686(ctr(aes))", ENCRYPT
, aes_ctr_enc_tv_template
,
1501 AES_CTR_ENC_TEST_VECTORS
);
1502 test_cipher("rfc3686(ctr(aes))", DECRYPT
, aes_ctr_dec_tv_template
,
1503 AES_CTR_DEC_TEST_VECTORS
);
1507 test_hash("sha384", sha384_tv_template
, SHA384_TEST_VECTORS
);
1511 test_hash("sha512", sha512_tv_template
, SHA512_TEST_VECTORS
);
1515 test_comp("deflate", deflate_comp_tv_template
,
1516 deflate_decomp_tv_template
, DEFLATE_COMP_TEST_VECTORS
,
1517 DEFLATE_DECOMP_TEST_VECTORS
);
1521 test_cipher("ecb(cast5)", ENCRYPT
, cast5_enc_tv_template
,
1522 CAST5_ENC_TEST_VECTORS
);
1523 test_cipher("ecb(cast5)", DECRYPT
, cast5_dec_tv_template
,
1524 CAST5_DEC_TEST_VECTORS
);
1528 test_cipher("ecb(cast6)", ENCRYPT
, cast6_enc_tv_template
,
1529 CAST6_ENC_TEST_VECTORS
);
1530 test_cipher("ecb(cast6)", DECRYPT
, cast6_dec_tv_template
,
1531 CAST6_DEC_TEST_VECTORS
);
1535 test_cipher("ecb(arc4)", ENCRYPT
, arc4_enc_tv_template
,
1536 ARC4_ENC_TEST_VECTORS
);
1537 test_cipher("ecb(arc4)", DECRYPT
, arc4_dec_tv_template
,
1538 ARC4_DEC_TEST_VECTORS
);
1542 test_hash("michael_mic", michael_mic_tv_template
, MICHAEL_MIC_TEST_VECTORS
);
1546 test_hash("crc32c", crc32c_tv_template
, CRC32C_TEST_VECTORS
);
1550 test_cipher("ecb(tea)", ENCRYPT
, tea_enc_tv_template
,
1551 TEA_ENC_TEST_VECTORS
);
1552 test_cipher("ecb(tea)", DECRYPT
, tea_dec_tv_template
,
1553 TEA_DEC_TEST_VECTORS
);
1557 test_cipher("ecb(xtea)", ENCRYPT
, xtea_enc_tv_template
,
1558 XTEA_ENC_TEST_VECTORS
);
1559 test_cipher("ecb(xtea)", DECRYPT
, xtea_dec_tv_template
,
1560 XTEA_DEC_TEST_VECTORS
);
1564 test_cipher("ecb(khazad)", ENCRYPT
, khazad_enc_tv_template
,
1565 KHAZAD_ENC_TEST_VECTORS
);
1566 test_cipher("ecb(khazad)", DECRYPT
, khazad_dec_tv_template
,
1567 KHAZAD_DEC_TEST_VECTORS
);
1571 test_hash("wp512", wp512_tv_template
, WP512_TEST_VECTORS
);
1575 test_hash("wp384", wp384_tv_template
, WP384_TEST_VECTORS
);
1579 test_hash("wp256", wp256_tv_template
, WP256_TEST_VECTORS
);
1583 test_cipher("ecb(tnepres)", ENCRYPT
, tnepres_enc_tv_template
,
1584 TNEPRES_ENC_TEST_VECTORS
);
1585 test_cipher("ecb(tnepres)", DECRYPT
, tnepres_dec_tv_template
,
1586 TNEPRES_DEC_TEST_VECTORS
);
1590 test_cipher("ecb(anubis)", ENCRYPT
, anubis_enc_tv_template
,
1591 ANUBIS_ENC_TEST_VECTORS
);
1592 test_cipher("ecb(anubis)", DECRYPT
, anubis_dec_tv_template
,
1593 ANUBIS_DEC_TEST_VECTORS
);
1594 test_cipher("cbc(anubis)", ENCRYPT
, anubis_cbc_enc_tv_template
,
1595 ANUBIS_CBC_ENC_TEST_VECTORS
);
1596 test_cipher("cbc(anubis)", DECRYPT
, anubis_cbc_dec_tv_template
,
1597 ANUBIS_CBC_ENC_TEST_VECTORS
);
1601 test_hash("tgr192", tgr192_tv_template
, TGR192_TEST_VECTORS
);
1606 test_hash("tgr160", tgr160_tv_template
, TGR160_TEST_VECTORS
);
1610 test_hash("tgr128", tgr128_tv_template
, TGR128_TEST_VECTORS
);
1614 test_cipher("ecb(xeta)", ENCRYPT
, xeta_enc_tv_template
,
1615 XETA_ENC_TEST_VECTORS
);
1616 test_cipher("ecb(xeta)", DECRYPT
, xeta_dec_tv_template
,
1617 XETA_DEC_TEST_VECTORS
);
1621 test_cipher("pcbc(fcrypt)", ENCRYPT
, fcrypt_pcbc_enc_tv_template
,
1622 FCRYPT_ENC_TEST_VECTORS
);
1623 test_cipher("pcbc(fcrypt)", DECRYPT
, fcrypt_pcbc_dec_tv_template
,
1624 FCRYPT_DEC_TEST_VECTORS
);
1628 test_cipher("ecb(camellia)", ENCRYPT
,
1629 camellia_enc_tv_template
,
1630 CAMELLIA_ENC_TEST_VECTORS
);
1631 test_cipher("ecb(camellia)", DECRYPT
,
1632 camellia_dec_tv_template
,
1633 CAMELLIA_DEC_TEST_VECTORS
);
1634 test_cipher("cbc(camellia)", ENCRYPT
,
1635 camellia_cbc_enc_tv_template
,
1636 CAMELLIA_CBC_ENC_TEST_VECTORS
);
1637 test_cipher("cbc(camellia)", DECRYPT
,
1638 camellia_cbc_dec_tv_template
,
1639 CAMELLIA_CBC_DEC_TEST_VECTORS
);
1642 test_hash("sha224", sha224_tv_template
, SHA224_TEST_VECTORS
);
1646 test_cipher("salsa20", ENCRYPT
,
1647 salsa20_stream_enc_tv_template
,
1648 SALSA20_STREAM_ENC_TEST_VECTORS
);
1652 test_aead("gcm(aes)", ENCRYPT
, aes_gcm_enc_tv_template
,
1653 AES_GCM_ENC_TEST_VECTORS
);
1654 test_aead("gcm(aes)", DECRYPT
, aes_gcm_dec_tv_template
,
1655 AES_GCM_DEC_TEST_VECTORS
);
1659 test_comp("lzo", lzo_comp_tv_template
, lzo_decomp_tv_template
,
1660 LZO_COMP_TEST_VECTORS
, LZO_DECOMP_TEST_VECTORS
);
1664 test_aead("ccm(aes)", ENCRYPT
, aes_ccm_enc_tv_template
,
1665 AES_CCM_ENC_TEST_VECTORS
);
1666 test_aead("ccm(aes)", DECRYPT
, aes_ccm_dec_tv_template
,
1667 AES_CCM_DEC_TEST_VECTORS
);
1671 test_cipher("cts(cbc(aes))", ENCRYPT
, cts_mode_enc_tv_template
,
1672 CTS_MODE_ENC_TEST_VECTORS
);
1673 test_cipher("cts(cbc(aes))", DECRYPT
, cts_mode_dec_tv_template
,
1674 CTS_MODE_DEC_TEST_VECTORS
);
1678 test_hash("rmd128", rmd128_tv_template
, RMD128_TEST_VECTORS
);
1682 test_hash("rmd160", rmd160_tv_template
, RMD160_TEST_VECTORS
);
1686 test_hash("rmd256", rmd256_tv_template
, RMD256_TEST_VECTORS
);
1690 test_hash("rmd320", rmd320_tv_template
, RMD320_TEST_VECTORS
);
1694 test_hash("hmac(md5)", hmac_md5_tv_template
,
1695 HMAC_MD5_TEST_VECTORS
);
1699 test_hash("hmac(sha1)", hmac_sha1_tv_template
,
1700 HMAC_SHA1_TEST_VECTORS
);
1704 test_hash("hmac(sha256)", hmac_sha256_tv_template
,
1705 HMAC_SHA256_TEST_VECTORS
);
1709 test_hash("hmac(sha384)", hmac_sha384_tv_template
,
1710 HMAC_SHA384_TEST_VECTORS
);
1714 test_hash("hmac(sha512)", hmac_sha512_tv_template
,
1715 HMAC_SHA512_TEST_VECTORS
);
1719 test_hash("hmac(sha224)", hmac_sha224_tv_template
,
1720 HMAC_SHA224_TEST_VECTORS
);
1724 test_hash("xcbc(aes)", aes_xcbc128_tv_template
,
1725 XCBC_AES_TEST_VECTORS
);
1729 test_hash("hmac(rmd128)", hmac_rmd128_tv_template
,
1730 HMAC_RMD128_TEST_VECTORS
);
1734 test_hash("hmac(rmd160)", hmac_rmd160_tv_template
,
1735 HMAC_RMD160_TEST_VECTORS
);
1739 test_cipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1740 speed_template_16_24_32
);
1741 test_cipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1742 speed_template_16_24_32
);
1743 test_cipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1744 speed_template_16_24_32
);
1745 test_cipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1746 speed_template_16_24_32
);
1747 test_cipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1748 speed_template_32_40_48
);
1749 test_cipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1750 speed_template_32_40_48
);
1751 test_cipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1752 speed_template_32_48_64
);
1753 test_cipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1754 speed_template_32_48_64
);
1758 test_cipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1759 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1761 test_cipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1762 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1764 test_cipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1765 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1767 test_cipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1768 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1773 test_cipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1774 speed_template_16_24_32
);
1775 test_cipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1776 speed_template_16_24_32
);
1777 test_cipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1778 speed_template_16_24_32
);
1779 test_cipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1780 speed_template_16_24_32
);
1784 test_cipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1785 speed_template_8_32
);
1786 test_cipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
1787 speed_template_8_32
);
1788 test_cipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1789 speed_template_8_32
);
1790 test_cipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
1791 speed_template_8_32
);
1795 test_cipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1797 test_cipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1799 test_cipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1801 test_cipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1806 test_cipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
1807 speed_template_16_24_32
);
1808 test_cipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
1809 speed_template_16_24_32
);
1810 test_cipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
1811 speed_template_16_24_32
);
1812 test_cipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
1813 speed_template_16_24_32
);
1817 test_cipher_speed("salsa20", ENCRYPT
, sec
, NULL
, 0,
1818 speed_template_16_32
);
1825 test_hash_speed("md4", sec
, generic_hash_speed_template
);
1826 if (mode
> 300 && mode
< 400) break;
1829 test_hash_speed("md5", sec
, generic_hash_speed_template
);
1830 if (mode
> 300 && mode
< 400) break;
1833 test_hash_speed("sha1", sec
, generic_hash_speed_template
);
1834 if (mode
> 300 && mode
< 400) break;
1837 test_hash_speed("sha256", sec
, generic_hash_speed_template
);
1838 if (mode
> 300 && mode
< 400) break;
1841 test_hash_speed("sha384", sec
, generic_hash_speed_template
);
1842 if (mode
> 300 && mode
< 400) break;
1845 test_hash_speed("sha512", sec
, generic_hash_speed_template
);
1846 if (mode
> 300 && mode
< 400) break;
1849 test_hash_speed("wp256", sec
, generic_hash_speed_template
);
1850 if (mode
> 300 && mode
< 400) break;
1853 test_hash_speed("wp384", sec
, generic_hash_speed_template
);
1854 if (mode
> 300 && mode
< 400) break;
1857 test_hash_speed("wp512", sec
, generic_hash_speed_template
);
1858 if (mode
> 300 && mode
< 400) break;
1861 test_hash_speed("tgr128", sec
, generic_hash_speed_template
);
1862 if (mode
> 300 && mode
< 400) break;
1865 test_hash_speed("tgr160", sec
, generic_hash_speed_template
);
1866 if (mode
> 300 && mode
< 400) break;
1869 test_hash_speed("tgr192", sec
, generic_hash_speed_template
);
1870 if (mode
> 300 && mode
< 400) break;
1873 test_hash_speed("sha224", sec
, generic_hash_speed_template
);
1874 if (mode
> 300 && mode
< 400) break;
1877 test_hash_speed("rmd128", sec
, generic_hash_speed_template
);
1878 if (mode
> 300 && mode
< 400) break;
1881 test_hash_speed("rmd160", sec
, generic_hash_speed_template
);
1882 if (mode
> 300 && mode
< 400) break;
1885 test_hash_speed("rmd256", sec
, generic_hash_speed_template
);
1886 if (mode
> 300 && mode
< 400) break;
1889 test_hash_speed("rmd320", sec
, generic_hash_speed_template
);
1890 if (mode
> 300 && mode
< 400) break;
1900 /* useful for debugging */
1901 printk("not testing anything\n");
1906 static int __init
tcrypt_mod_init(void)
1910 tvmem
= kmalloc(TVMEMSIZE
, GFP_KERNEL
);
1914 xbuf
= kmalloc(XBUFSIZE
, GFP_KERNEL
);
1918 axbuf
= kmalloc(XBUFSIZE
, GFP_KERNEL
);
1924 /* We intentionaly return -EAGAIN to prevent keeping
1925 * the module. It does all its work from init()
1926 * and doesn't offer any runtime functionality
1927 * => we don't need it in the memory, do we?
1942 * If an init function is provided, an exit function must also be provided
1943 * to allow module unload.
1945 static void __exit
tcrypt_mod_fini(void) { }
1947 module_init(tcrypt_mod_init
);
1948 module_exit(tcrypt_mod_fini
);
1950 module_param(mode
, int, 0);
1951 module_param(sec
, uint
, 0);
1952 MODULE_PARM_DESC(sec
, "Length in seconds of speed tests "
1953 "(defaults to zero which uses CPU cycles instead)");
1955 MODULE_LICENSE("GPL");
1956 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1957 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");