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 <crypto/hash.h>
19 #include <linux/err.h>
20 #include <linux/init.h>
21 #include <linux/module.h>
23 #include <linux/slab.h>
24 #include <linux/scatterlist.h>
25 #include <linux/string.h>
26 #include <linux/crypto.h>
27 #include <linux/moduleparam.h>
28 #include <linux/jiffies.h>
29 #include <linux/timex.h>
30 #include <linux/interrupt.h>
34 * Need slab memory for testing (size in number of pages).
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
;
70 static char *xbuf
[XBUFSIZE
];
71 static char *axbuf
[XBUFSIZE
];
72 static char *tvmem
[TVMEMSIZE
];
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);
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 crypto_ahash_clear_flags(tfm
, ~0);
143 ret
= crypto_ahash_setkey(tfm
, template[i
].key
,
146 printk("setkey() failed ret=%d\n", ret
);
151 ahash_request_set_crypt(req
, sg
, result
, template[i
].psize
);
152 ret
= crypto_ahash_digest(req
);
158 ret
= wait_for_completion_interruptible(
159 &tresult
.completion
);
160 if (!ret
&& !(ret
= tresult
.err
)) {
161 INIT_COMPLETION(tresult
.completion
);
166 printk("digest () failed ret=%d\n", ret
);
170 hexdump(result
, crypto_ahash_digestsize(tfm
));
172 memcmp(result
, template[i
].digest
,
173 crypto_ahash_digestsize(tfm
)) ?
177 printk("testing %s across pages\n", algo
);
180 for (i
= 0; i
< tcount
; i
++) {
181 if (template[i
].np
) {
183 printk("test %u:\n", j
);
184 memset(result
, 0, 64);
187 sg_init_table(sg
, template[i
].np
);
188 for (k
= 0; k
< template[i
].np
; k
++) {
190 memcpy(xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
191 offset_in_page(IDX
[k
]),
192 template[i
].plaintext
+ temp
,
195 temp
+= template[i
].tap
[k
];
198 if (template[i
].ksize
) {
199 crypto_ahash_clear_flags(tfm
, ~0);
200 ret
= crypto_ahash_setkey(tfm
, template[i
].key
,
204 printk("setkey() failed ret=%d\n", ret
);
209 ahash_request_set_crypt(req
, sg
, result
,
211 ret
= crypto_ahash_digest(req
);
217 ret
= wait_for_completion_interruptible(
218 &tresult
.completion
);
219 if (!ret
&& !(ret
= tresult
.err
)) {
220 INIT_COMPLETION(tresult
.completion
);
225 printk("digest () failed ret=%d\n", ret
);
229 hexdump(result
, crypto_ahash_digestsize(tfm
));
231 memcmp(result
, template[i
].digest
,
232 crypto_ahash_digestsize(tfm
)) ?
238 ahash_request_free(req
);
240 crypto_free_ahash(tfm
);
243 static void test_aead(char *algo
, int enc
, struct aead_testvec
*template,
246 unsigned int ret
, i
, j
, k
, n
, temp
;
248 struct crypto_aead
*tfm
;
250 struct aead_request
*req
;
251 struct scatterlist sg
[8];
252 struct scatterlist asg
[8];
254 struct tcrypt_result result
;
255 unsigned int authsize
;
265 printk(KERN_INFO
"\ntesting %s %s\n", algo
, e
);
267 init_completion(&result
.completion
);
269 tfm
= crypto_alloc_aead(algo
, 0, 0);
272 printk(KERN_INFO
"failed to load transform for %s: %ld\n",
277 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
279 printk(KERN_INFO
"failed to allocate request for %s\n", algo
);
283 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
284 tcrypt_complete
, &result
);
286 for (i
= 0, j
= 0; i
< tcount
; i
++) {
287 if (!template[i
].np
) {
288 printk(KERN_INFO
"test %u (%d bit key):\n",
289 ++j
, template[i
].klen
* 8);
291 /* some tepmplates have no input data but they will
297 memcpy(input
, template[i
].input
, template[i
].ilen
);
298 memcpy(assoc
, template[i
].assoc
, template[i
].alen
);
300 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
302 memset(iv
, 0, MAX_IVLEN
);
304 crypto_aead_clear_flags(tfm
, ~0);
306 crypto_aead_set_flags(
307 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
309 key
= template[i
].key
;
311 ret
= crypto_aead_setkey(tfm
, key
,
314 printk(KERN_INFO
"setkey() failed flags=%x\n",
315 crypto_aead_get_flags(tfm
));
317 if (!template[i
].fail
)
321 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
322 ret
= crypto_aead_setauthsize(tfm
, authsize
);
325 "failed to set authsize = %u\n",
330 sg_init_one(&sg
[0], input
,
331 template[i
].ilen
+ (enc
? authsize
: 0));
333 sg_init_one(&asg
[0], assoc
, template[i
].alen
);
335 aead_request_set_crypt(req
, sg
, sg
,
336 template[i
].ilen
, iv
);
338 aead_request_set_assoc(req
, asg
, template[i
].alen
);
341 crypto_aead_encrypt(req
) :
342 crypto_aead_decrypt(req
);
349 ret
= wait_for_completion_interruptible(
351 if (!ret
&& !(ret
= result
.err
)) {
352 INIT_COMPLETION(result
.completion
);
357 printk(KERN_INFO
"%s () failed err=%d\n",
363 hexdump(q
, template[i
].rlen
);
365 printk(KERN_INFO
"enc/dec: %s\n",
366 memcmp(q
, template[i
].result
,
367 template[i
].rlen
) ? "fail" : "pass");
371 printk(KERN_INFO
"\ntesting %s %s across pages (chunking)\n", algo
, e
);
373 for (i
= 0, j
= 0; i
< tcount
; i
++) {
374 if (template[i
].np
) {
375 printk(KERN_INFO
"test %u (%d bit key):\n",
376 ++j
, template[i
].klen
* 8);
379 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
381 memset(iv
, 0, MAX_IVLEN
);
383 crypto_aead_clear_flags(tfm
, ~0);
385 crypto_aead_set_flags(
386 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
387 key
= template[i
].key
;
389 ret
= crypto_aead_setkey(tfm
, key
, template[i
].klen
);
391 printk(KERN_INFO
"setkey() failed flags=%x\n",
392 crypto_aead_get_flags(tfm
));
394 if (!template[i
].fail
)
398 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
400 sg_init_table(sg
, template[i
].np
);
401 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
402 if (WARN_ON(offset_in_page(IDX
[k
]) +
403 template[i
].tap
[k
] > PAGE_SIZE
))
406 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
407 offset_in_page(IDX
[k
]);
409 memcpy(q
, template[i
].input
+ temp
,
412 n
= template[i
].tap
[k
];
413 if (k
== template[i
].np
- 1 && enc
)
415 if (offset_in_page(q
) + n
< PAGE_SIZE
)
418 sg_set_buf(&sg
[k
], q
, template[i
].tap
[k
]);
419 temp
+= template[i
].tap
[k
];
422 ret
= crypto_aead_setauthsize(tfm
, authsize
);
425 "failed to set authsize = %u\n",
431 if (WARN_ON(sg
[k
- 1].offset
+
432 sg
[k
- 1].length
+ authsize
>
436 sg
[k
- 1].length
+= authsize
;
439 sg_init_table(asg
, template[i
].anp
);
440 for (k
= 0, temp
= 0; k
< template[i
].anp
; k
++) {
442 memcpy(axbuf
[IDX
[k
] >> PAGE_SHIFT
] +
443 offset_in_page(IDX
[k
]),
444 template[i
].assoc
+ temp
,
445 template[i
].atap
[k
]),
446 template[i
].atap
[k
]);
447 temp
+= template[i
].atap
[k
];
450 aead_request_set_crypt(req
, sg
, sg
,
454 aead_request_set_assoc(req
, asg
, template[i
].alen
);
457 crypto_aead_encrypt(req
) :
458 crypto_aead_decrypt(req
);
465 ret
= wait_for_completion_interruptible(
467 if (!ret
&& !(ret
= result
.err
)) {
468 INIT_COMPLETION(result
.completion
);
473 printk(KERN_INFO
"%s () failed err=%d\n",
478 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
479 printk(KERN_INFO
"page %u\n", k
);
480 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
481 offset_in_page(IDX
[k
]);
483 n
= template[i
].tap
[k
];
484 if (k
== template[i
].np
- 1)
485 n
+= enc
? authsize
: -authsize
;
487 printk(KERN_INFO
"%s\n",
488 memcmp(q
, template[i
].result
+ temp
, n
) ?
492 if (k
== template[i
].np
- 1 && !enc
) {
493 if (memcmp(q
, template[i
].input
+
499 for (n
= 0; offset_in_page(q
+ n
) &&
504 printk("Result buffer corruption %u "
509 temp
+= template[i
].tap
[k
];
515 crypto_free_aead(tfm
);
516 aead_request_free(req
);
519 static void test_cipher(char *algo
, int enc
,
520 struct cipher_testvec
*template, unsigned int tcount
)
522 unsigned int ret
, i
, j
, k
, n
, temp
;
524 struct crypto_ablkcipher
*tfm
;
525 struct ablkcipher_request
*req
;
526 struct scatterlist sg
[8];
528 struct tcrypt_result result
;
537 printk("\ntesting %s %s\n", algo
, e
);
539 init_completion(&result
.completion
);
540 tfm
= crypto_alloc_ablkcipher(algo
, 0, 0);
543 printk("failed to load transform for %s: %ld\n", algo
,
548 req
= ablkcipher_request_alloc(tfm
, GFP_KERNEL
);
550 printk("failed to allocate request for %s\n", algo
);
554 ablkcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
555 tcrypt_complete
, &result
);
558 for (i
= 0; i
< tcount
; i
++) {
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);
570 memcpy(data
, template[i
].input
, template[i
].ilen
);
572 crypto_ablkcipher_clear_flags(tfm
, ~0);
574 crypto_ablkcipher_set_flags(
575 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
577 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
580 printk("setkey() failed flags=%x\n",
581 crypto_ablkcipher_get_flags(tfm
));
583 if (!template[i
].fail
)
587 sg_init_one(&sg
[0], data
, template[i
].ilen
);
589 ablkcipher_request_set_crypt(req
, sg
, sg
,
590 template[i
].ilen
, iv
);
592 crypto_ablkcipher_encrypt(req
) :
593 crypto_ablkcipher_decrypt(req
);
600 ret
= wait_for_completion_interruptible(
602 if (!ret
&& !((ret
= result
.err
))) {
603 INIT_COMPLETION(result
.completion
);
608 printk("%s () failed err=%d\n", e
, -ret
);
613 hexdump(q
, template[i
].rlen
);
616 memcmp(q
, template[i
].result
,
617 template[i
].rlen
) ? "fail" : "pass");
621 printk("\ntesting %s %s across pages (chunking)\n", algo
, e
);
624 for (i
= 0; i
< tcount
; i
++) {
627 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
629 memset(iv
, 0, MAX_IVLEN
);
631 if (template[i
].np
) {
633 printk("test %u (%d bit key):\n",
634 j
, template[i
].klen
* 8);
636 crypto_ablkcipher_clear_flags(tfm
, ~0);
638 crypto_ablkcipher_set_flags(
639 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
641 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
644 printk("setkey() failed flags=%x\n",
645 crypto_ablkcipher_get_flags(tfm
));
647 if (!template[i
].fail
)
652 sg_init_table(sg
, template[i
].np
);
653 for (k
= 0; k
< template[i
].np
; k
++) {
654 if (WARN_ON(offset_in_page(IDX
[k
]) +
655 template[i
].tap
[k
] > PAGE_SIZE
))
658 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
659 offset_in_page(IDX
[k
]);
661 memcpy(q
, template[i
].input
+ temp
,
664 if (offset_in_page(q
) + template[i
].tap
[k
] <
666 q
[template[i
].tap
[k
]] = 0;
668 sg_set_buf(&sg
[k
], q
, template[i
].tap
[k
]);
670 temp
+= template[i
].tap
[k
];
673 ablkcipher_request_set_crypt(req
, sg
, sg
,
674 template[i
].ilen
, iv
);
677 crypto_ablkcipher_encrypt(req
) :
678 crypto_ablkcipher_decrypt(req
);
685 ret
= wait_for_completion_interruptible(
687 if (!ret
&& !((ret
= result
.err
))) {
688 INIT_COMPLETION(result
.completion
);
693 printk("%s () failed err=%d\n", e
, -ret
);
698 for (k
= 0; k
< template[i
].np
; k
++) {
699 printk("page %u\n", k
);
700 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
701 offset_in_page(IDX
[k
]);
702 hexdump(q
, template[i
].tap
[k
]);
704 memcmp(q
, template[i
].result
+ temp
,
705 template[i
].tap
[k
]) ? "fail" :
708 q
+= template[i
].tap
[k
];
709 for (n
= 0; offset_in_page(q
+ n
) && q
[n
]; n
++)
712 printk("Result buffer corruption %u "
716 temp
+= template[i
].tap
[k
];
721 crypto_free_ablkcipher(tfm
);
722 ablkcipher_request_free(req
);
725 static int test_cipher_jiffies(struct blkcipher_desc
*desc
, int enc
,
726 struct scatterlist
*sg
, int blen
, int sec
)
728 unsigned long start
, end
;
732 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
733 time_before(jiffies
, end
); bcount
++) {
735 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
737 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
743 printk("%d operations in %d seconds (%ld bytes)\n",
744 bcount
, sec
, (long)bcount
* blen
);
748 static int test_cipher_cycles(struct blkcipher_desc
*desc
, int enc
,
749 struct scatterlist
*sg
, int blen
)
751 unsigned long cycles
= 0;
759 for (i
= 0; i
< 4; i
++) {
761 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
763 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
769 /* The real thing. */
770 for (i
= 0; i
< 8; i
++) {
773 start
= get_cycles();
775 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
777 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
783 cycles
+= end
- start
;
791 printk("1 operation in %lu cycles (%d bytes)\n",
792 (cycles
+ 4) / 8, blen
);
797 static u32 block_sizes
[] = { 16, 64, 256, 1024, 8192, 0 };
799 static void test_cipher_speed(char *algo
, int enc
, unsigned int sec
,
800 struct cipher_testvec
*template,
801 unsigned int tcount
, u8
*keysize
)
803 unsigned int ret
, i
, j
, iv_len
;
804 unsigned char *key
, iv
[128];
805 struct crypto_blkcipher
*tfm
;
806 struct blkcipher_desc desc
;
815 printk("\ntesting speed of %s %s\n", algo
, e
);
817 tfm
= crypto_alloc_blkcipher(algo
, 0, CRYPTO_ALG_ASYNC
);
820 printk("failed to load transform for %s: %ld\n", algo
,
830 b_size
= block_sizes
;
832 struct scatterlist sg
[TVMEMSIZE
];
834 if ((*keysize
+ *b_size
) > TVMEMSIZE
* PAGE_SIZE
) {
835 printk("template (%u) too big for "
836 "tvmem (%lu)\n", *keysize
+ *b_size
,
837 TVMEMSIZE
* PAGE_SIZE
);
841 printk("test %u (%d bit key, %d byte blocks): ", i
,
842 *keysize
* 8, *b_size
);
844 memset(tvmem
[0], 0xff, PAGE_SIZE
);
846 /* set key, plain text and IV */
847 key
= (unsigned char *)tvmem
[0];
848 for (j
= 0; j
< tcount
; j
++) {
849 if (template[j
].klen
== *keysize
) {
850 key
= template[j
].key
;
855 ret
= crypto_blkcipher_setkey(tfm
, key
, *keysize
);
857 printk("setkey() failed flags=%x\n",
858 crypto_blkcipher_get_flags(tfm
));
862 sg_init_table(sg
, TVMEMSIZE
);
863 sg_set_buf(sg
, tvmem
[0] + *keysize
,
864 PAGE_SIZE
- *keysize
);
865 for (j
= 1; j
< TVMEMSIZE
; j
++) {
866 sg_set_buf(sg
+ j
, tvmem
[j
], PAGE_SIZE
);
867 memset (tvmem
[j
], 0xff, PAGE_SIZE
);
870 iv_len
= crypto_blkcipher_ivsize(tfm
);
872 memset(&iv
, 0xff, iv_len
);
873 crypto_blkcipher_set_iv(tfm
, iv
, iv_len
);
877 ret
= test_cipher_jiffies(&desc
, enc
, sg
,
880 ret
= test_cipher_cycles(&desc
, enc
, sg
,
884 printk("%s() failed flags=%x\n", e
, desc
.flags
);
894 crypto_free_blkcipher(tfm
);
897 static int test_hash_jiffies_digest(struct hash_desc
*desc
,
898 struct scatterlist
*sg
, int blen
,
901 unsigned long start
, end
;
905 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
906 time_before(jiffies
, end
); bcount
++) {
907 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
912 printk("%6u opers/sec, %9lu bytes/sec\n",
913 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
918 static int test_hash_jiffies(struct hash_desc
*desc
, struct scatterlist
*sg
,
919 int blen
, int plen
, char *out
, int sec
)
921 unsigned long start
, end
;
926 return test_hash_jiffies_digest(desc
, sg
, blen
, out
, sec
);
928 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
929 time_before(jiffies
, end
); bcount
++) {
930 ret
= crypto_hash_init(desc
);
933 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
934 ret
= crypto_hash_update(desc
, sg
, plen
);
938 /* we assume there is enough space in 'out' for the result */
939 ret
= crypto_hash_final(desc
, out
);
944 printk("%6u opers/sec, %9lu bytes/sec\n",
945 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
950 static int test_hash_cycles_digest(struct hash_desc
*desc
,
951 struct scatterlist
*sg
, int blen
, char *out
)
953 unsigned long cycles
= 0;
961 for (i
= 0; i
< 4; i
++) {
962 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
967 /* The real thing. */
968 for (i
= 0; i
< 8; i
++) {
971 start
= get_cycles();
973 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
979 cycles
+= end
- start
;
989 printk("%6lu cycles/operation, %4lu cycles/byte\n",
990 cycles
/ 8, cycles
/ (8 * blen
));
995 static int test_hash_cycles(struct hash_desc
*desc
, struct scatterlist
*sg
,
996 int blen
, int plen
, char *out
)
998 unsigned long cycles
= 0;
1003 return test_hash_cycles_digest(desc
, sg
, blen
, out
);
1006 local_irq_disable();
1009 for (i
= 0; i
< 4; i
++) {
1010 ret
= crypto_hash_init(desc
);
1013 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
1014 ret
= crypto_hash_update(desc
, sg
, plen
);
1018 ret
= crypto_hash_final(desc
, out
);
1023 /* The real thing. */
1024 for (i
= 0; i
< 8; i
++) {
1025 cycles_t start
, end
;
1027 start
= get_cycles();
1029 ret
= crypto_hash_init(desc
);
1032 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
1033 ret
= crypto_hash_update(desc
, sg
, plen
);
1037 ret
= crypto_hash_final(desc
, out
);
1043 cycles
+= end
- start
;
1053 printk("%6lu cycles/operation, %4lu cycles/byte\n",
1054 cycles
/ 8, cycles
/ (8 * blen
));
1059 static void test_hash_speed(char *algo
, unsigned int sec
,
1060 struct hash_speed
*speed
)
1062 struct scatterlist sg
[TVMEMSIZE
];
1063 struct crypto_hash
*tfm
;
1064 struct hash_desc desc
;
1069 printk("\ntesting speed of %s\n", algo
);
1071 tfm
= crypto_alloc_hash(algo
, 0, CRYPTO_ALG_ASYNC
);
1074 printk("failed to load transform for %s: %ld\n", algo
,
1082 if (crypto_hash_digestsize(tfm
) > sizeof(output
)) {
1083 printk("digestsize(%u) > outputbuffer(%zu)\n",
1084 crypto_hash_digestsize(tfm
), sizeof(output
));
1088 sg_init_table(sg
, TVMEMSIZE
);
1089 for (i
= 0; i
< TVMEMSIZE
; i
++) {
1090 sg_set_buf(sg
+ i
, tvmem
[i
], PAGE_SIZE
);
1091 memset(tvmem
[i
], 0xff, PAGE_SIZE
);
1094 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
1095 if (speed
[i
].blen
> TVMEMSIZE
* PAGE_SIZE
) {
1096 printk("template (%u) too big for tvmem (%lu)\n",
1097 speed
[i
].blen
, TVMEMSIZE
* PAGE_SIZE
);
1101 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
1102 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
1105 ret
= test_hash_jiffies(&desc
, sg
, speed
[i
].blen
,
1106 speed
[i
].plen
, output
, sec
);
1108 ret
= test_hash_cycles(&desc
, sg
, speed
[i
].blen
,
1109 speed
[i
].plen
, output
);
1112 printk("hashing failed ret=%d\n", ret
);
1118 crypto_free_hash(tfm
);
1121 static void test_comp(char *algo
, struct comp_testvec
*ctemplate
,
1122 struct comp_testvec
*dtemplate
, int ctcount
, int dtcount
)
1125 char result
[COMP_BUF_SIZE
];
1126 struct crypto_comp
*tfm
;
1128 printk("\ntesting %s compression\n", algo
);
1130 tfm
= crypto_alloc_comp(algo
, 0, CRYPTO_ALG_ASYNC
);
1132 printk("failed to load transform for %s\n", algo
);
1136 for (i
= 0; i
< ctcount
; i
++) {
1137 int ilen
, ret
, dlen
= COMP_BUF_SIZE
;
1139 printk("test %u:\n", i
+ 1);
1140 memset(result
, 0, sizeof (result
));
1142 ilen
= ctemplate
[i
].inlen
;
1143 ret
= crypto_comp_compress(tfm
, ctemplate
[i
].input
,
1144 ilen
, result
, &dlen
);
1146 printk("fail: ret=%d\n", ret
);
1149 hexdump(result
, dlen
);
1150 printk("%s (ratio %d:%d)\n",
1151 memcmp(result
, ctemplate
[i
].output
, dlen
) ? "fail" : "pass",
1155 printk("\ntesting %s decompression\n", algo
);
1157 for (i
= 0; i
< dtcount
; i
++) {
1158 int ilen
, ret
, dlen
= COMP_BUF_SIZE
;
1160 printk("test %u:\n", i
+ 1);
1161 memset(result
, 0, sizeof (result
));
1163 ilen
= dtemplate
[i
].inlen
;
1164 ret
= crypto_comp_decompress(tfm
, dtemplate
[i
].input
,
1165 ilen
, result
, &dlen
);
1167 printk("fail: ret=%d\n", ret
);
1170 hexdump(result
, dlen
);
1171 printk("%s (ratio %d:%d)\n",
1172 memcmp(result
, dtemplate
[i
].output
, dlen
) ? "fail" : "pass",
1176 crypto_free_comp(tfm
);
1179 static void test_available(void)
1181 char **name
= check
;
1184 printk("alg %s ", *name
);
1185 printk(crypto_has_alg(*name
, 0, 0) ?
1186 "found\n" : "not found\n");
1191 static void do_test(void)
1196 test_hash("md5", md5_tv_template
, MD5_TEST_VECTORS
);
1198 test_hash("sha1", sha1_tv_template
, SHA1_TEST_VECTORS
);
1201 test_cipher("ecb(des)", ENCRYPT
, des_enc_tv_template
,
1202 DES_ENC_TEST_VECTORS
);
1203 test_cipher("ecb(des)", DECRYPT
, des_dec_tv_template
,
1204 DES_DEC_TEST_VECTORS
);
1205 test_cipher("cbc(des)", ENCRYPT
, des_cbc_enc_tv_template
,
1206 DES_CBC_ENC_TEST_VECTORS
);
1207 test_cipher("cbc(des)", DECRYPT
, des_cbc_dec_tv_template
,
1208 DES_CBC_DEC_TEST_VECTORS
);
1211 test_cipher("ecb(des3_ede)", ENCRYPT
, des3_ede_enc_tv_template
,
1212 DES3_EDE_ENC_TEST_VECTORS
);
1213 test_cipher("ecb(des3_ede)", DECRYPT
, des3_ede_dec_tv_template
,
1214 DES3_EDE_DEC_TEST_VECTORS
);
1216 test_cipher("cbc(des3_ede)", ENCRYPT
,
1217 des3_ede_cbc_enc_tv_template
,
1218 DES3_EDE_CBC_ENC_TEST_VECTORS
);
1220 test_cipher("cbc(des3_ede)", DECRYPT
,
1221 des3_ede_cbc_dec_tv_template
,
1222 DES3_EDE_CBC_DEC_TEST_VECTORS
);
1224 test_hash("md4", md4_tv_template
, MD4_TEST_VECTORS
);
1226 test_hash("sha224", sha224_tv_template
, SHA224_TEST_VECTORS
);
1228 test_hash("sha256", sha256_tv_template
, SHA256_TEST_VECTORS
);
1231 test_cipher("ecb(blowfish)", ENCRYPT
, bf_enc_tv_template
,
1232 BF_ENC_TEST_VECTORS
);
1233 test_cipher("ecb(blowfish)", DECRYPT
, bf_dec_tv_template
,
1234 BF_DEC_TEST_VECTORS
);
1235 test_cipher("cbc(blowfish)", ENCRYPT
, bf_cbc_enc_tv_template
,
1236 BF_CBC_ENC_TEST_VECTORS
);
1237 test_cipher("cbc(blowfish)", DECRYPT
, bf_cbc_dec_tv_template
,
1238 BF_CBC_DEC_TEST_VECTORS
);
1241 test_cipher("ecb(twofish)", ENCRYPT
, tf_enc_tv_template
,
1242 TF_ENC_TEST_VECTORS
);
1243 test_cipher("ecb(twofish)", DECRYPT
, tf_dec_tv_template
,
1244 TF_DEC_TEST_VECTORS
);
1245 test_cipher("cbc(twofish)", ENCRYPT
, tf_cbc_enc_tv_template
,
1246 TF_CBC_ENC_TEST_VECTORS
);
1247 test_cipher("cbc(twofish)", DECRYPT
, tf_cbc_dec_tv_template
,
1248 TF_CBC_DEC_TEST_VECTORS
);
1251 test_cipher("ecb(serpent)", ENCRYPT
, serpent_enc_tv_template
,
1252 SERPENT_ENC_TEST_VECTORS
);
1253 test_cipher("ecb(serpent)", DECRYPT
, serpent_dec_tv_template
,
1254 SERPENT_DEC_TEST_VECTORS
);
1257 test_cipher("ecb(tnepres)", ENCRYPT
, tnepres_enc_tv_template
,
1258 TNEPRES_ENC_TEST_VECTORS
);
1259 test_cipher("ecb(tnepres)", DECRYPT
, tnepres_dec_tv_template
,
1260 TNEPRES_DEC_TEST_VECTORS
);
1263 test_cipher("ecb(aes)", ENCRYPT
, aes_enc_tv_template
,
1264 AES_ENC_TEST_VECTORS
);
1265 test_cipher("ecb(aes)", DECRYPT
, aes_dec_tv_template
,
1266 AES_DEC_TEST_VECTORS
);
1267 test_cipher("cbc(aes)", ENCRYPT
, aes_cbc_enc_tv_template
,
1268 AES_CBC_ENC_TEST_VECTORS
);
1269 test_cipher("cbc(aes)", DECRYPT
, aes_cbc_dec_tv_template
,
1270 AES_CBC_DEC_TEST_VECTORS
);
1271 test_cipher("lrw(aes)", ENCRYPT
, aes_lrw_enc_tv_template
,
1272 AES_LRW_ENC_TEST_VECTORS
);
1273 test_cipher("lrw(aes)", DECRYPT
, aes_lrw_dec_tv_template
,
1274 AES_LRW_DEC_TEST_VECTORS
);
1275 test_cipher("xts(aes)", ENCRYPT
, aes_xts_enc_tv_template
,
1276 AES_XTS_ENC_TEST_VECTORS
);
1277 test_cipher("xts(aes)", DECRYPT
, aes_xts_dec_tv_template
,
1278 AES_XTS_DEC_TEST_VECTORS
);
1279 test_cipher("rfc3686(ctr(aes))", ENCRYPT
, aes_ctr_enc_tv_template
,
1280 AES_CTR_ENC_TEST_VECTORS
);
1281 test_cipher("rfc3686(ctr(aes))", DECRYPT
, aes_ctr_dec_tv_template
,
1282 AES_CTR_DEC_TEST_VECTORS
);
1283 test_aead("gcm(aes)", ENCRYPT
, aes_gcm_enc_tv_template
,
1284 AES_GCM_ENC_TEST_VECTORS
);
1285 test_aead("gcm(aes)", DECRYPT
, aes_gcm_dec_tv_template
,
1286 AES_GCM_DEC_TEST_VECTORS
);
1287 test_aead("ccm(aes)", ENCRYPT
, aes_ccm_enc_tv_template
,
1288 AES_CCM_ENC_TEST_VECTORS
);
1289 test_aead("ccm(aes)", DECRYPT
, aes_ccm_dec_tv_template
,
1290 AES_CCM_DEC_TEST_VECTORS
);
1293 test_cipher("ecb(cast5)", ENCRYPT
, cast5_enc_tv_template
,
1294 CAST5_ENC_TEST_VECTORS
);
1295 test_cipher("ecb(cast5)", DECRYPT
, cast5_dec_tv_template
,
1296 CAST5_DEC_TEST_VECTORS
);
1299 test_cipher("ecb(cast6)", ENCRYPT
, cast6_enc_tv_template
,
1300 CAST6_ENC_TEST_VECTORS
);
1301 test_cipher("ecb(cast6)", DECRYPT
, cast6_dec_tv_template
,
1302 CAST6_DEC_TEST_VECTORS
);
1305 test_cipher("ecb(arc4)", ENCRYPT
, arc4_enc_tv_template
,
1306 ARC4_ENC_TEST_VECTORS
);
1307 test_cipher("ecb(arc4)", DECRYPT
, arc4_dec_tv_template
,
1308 ARC4_DEC_TEST_VECTORS
);
1311 test_cipher("ecb(tea)", ENCRYPT
, tea_enc_tv_template
,
1312 TEA_ENC_TEST_VECTORS
);
1313 test_cipher("ecb(tea)", DECRYPT
, tea_dec_tv_template
,
1314 TEA_DEC_TEST_VECTORS
);
1318 test_cipher("ecb(xtea)", ENCRYPT
, xtea_enc_tv_template
,
1319 XTEA_ENC_TEST_VECTORS
);
1320 test_cipher("ecb(xtea)", DECRYPT
, xtea_dec_tv_template
,
1321 XTEA_DEC_TEST_VECTORS
);
1324 test_cipher("ecb(khazad)", ENCRYPT
, khazad_enc_tv_template
,
1325 KHAZAD_ENC_TEST_VECTORS
);
1326 test_cipher("ecb(khazad)", DECRYPT
, khazad_dec_tv_template
,
1327 KHAZAD_DEC_TEST_VECTORS
);
1330 test_cipher("ecb(anubis)", ENCRYPT
, anubis_enc_tv_template
,
1331 ANUBIS_ENC_TEST_VECTORS
);
1332 test_cipher("ecb(anubis)", DECRYPT
, anubis_dec_tv_template
,
1333 ANUBIS_DEC_TEST_VECTORS
);
1334 test_cipher("cbc(anubis)", ENCRYPT
, anubis_cbc_enc_tv_template
,
1335 ANUBIS_CBC_ENC_TEST_VECTORS
);
1336 test_cipher("cbc(anubis)", DECRYPT
, anubis_cbc_dec_tv_template
,
1337 ANUBIS_CBC_ENC_TEST_VECTORS
);
1340 test_cipher("ecb(xeta)", ENCRYPT
, xeta_enc_tv_template
,
1341 XETA_ENC_TEST_VECTORS
);
1342 test_cipher("ecb(xeta)", DECRYPT
, xeta_dec_tv_template
,
1343 XETA_DEC_TEST_VECTORS
);
1346 test_cipher("pcbc(fcrypt)", ENCRYPT
, fcrypt_pcbc_enc_tv_template
,
1347 FCRYPT_ENC_TEST_VECTORS
);
1348 test_cipher("pcbc(fcrypt)", DECRYPT
, fcrypt_pcbc_dec_tv_template
,
1349 FCRYPT_DEC_TEST_VECTORS
);
1352 test_cipher("ecb(camellia)", ENCRYPT
,
1353 camellia_enc_tv_template
,
1354 CAMELLIA_ENC_TEST_VECTORS
);
1355 test_cipher("ecb(camellia)", DECRYPT
,
1356 camellia_dec_tv_template
,
1357 CAMELLIA_DEC_TEST_VECTORS
);
1358 test_cipher("cbc(camellia)", ENCRYPT
,
1359 camellia_cbc_enc_tv_template
,
1360 CAMELLIA_CBC_ENC_TEST_VECTORS
);
1361 test_cipher("cbc(camellia)", DECRYPT
,
1362 camellia_cbc_dec_tv_template
,
1363 CAMELLIA_CBC_DEC_TEST_VECTORS
);
1366 test_cipher("ecb(seed)", ENCRYPT
, seed_enc_tv_template
,
1367 SEED_ENC_TEST_VECTORS
);
1368 test_cipher("ecb(seed)", DECRYPT
, seed_dec_tv_template
,
1369 SEED_DEC_TEST_VECTORS
);
1372 test_cipher("cts(cbc(aes))", ENCRYPT
, cts_mode_enc_tv_template
,
1373 CTS_MODE_ENC_TEST_VECTORS
);
1374 test_cipher("cts(cbc(aes))", DECRYPT
, cts_mode_dec_tv_template
,
1375 CTS_MODE_DEC_TEST_VECTORS
);
1377 test_hash("sha384", sha384_tv_template
, SHA384_TEST_VECTORS
);
1378 test_hash("sha512", sha512_tv_template
, SHA512_TEST_VECTORS
);
1379 test_hash("wp512", wp512_tv_template
, WP512_TEST_VECTORS
);
1380 test_hash("wp384", wp384_tv_template
, WP384_TEST_VECTORS
);
1381 test_hash("wp256", wp256_tv_template
, WP256_TEST_VECTORS
);
1382 test_hash("tgr192", tgr192_tv_template
, TGR192_TEST_VECTORS
);
1383 test_hash("tgr160", tgr160_tv_template
, TGR160_TEST_VECTORS
);
1384 test_hash("tgr128", tgr128_tv_template
, TGR128_TEST_VECTORS
);
1385 test_comp("deflate", deflate_comp_tv_template
,
1386 deflate_decomp_tv_template
, DEFLATE_COMP_TEST_VECTORS
,
1387 DEFLATE_DECOMP_TEST_VECTORS
);
1388 test_comp("lzo", lzo_comp_tv_template
, lzo_decomp_tv_template
,
1389 LZO_COMP_TEST_VECTORS
, LZO_DECOMP_TEST_VECTORS
);
1390 test_hash("crc32c", crc32c_tv_template
, CRC32C_TEST_VECTORS
);
1391 test_hash("hmac(md5)", hmac_md5_tv_template
,
1392 HMAC_MD5_TEST_VECTORS
);
1393 test_hash("hmac(sha1)", hmac_sha1_tv_template
,
1394 HMAC_SHA1_TEST_VECTORS
);
1395 test_hash("hmac(sha224)", hmac_sha224_tv_template
,
1396 HMAC_SHA224_TEST_VECTORS
);
1397 test_hash("hmac(sha256)", hmac_sha256_tv_template
,
1398 HMAC_SHA256_TEST_VECTORS
);
1399 test_hash("hmac(sha384)", hmac_sha384_tv_template
,
1400 HMAC_SHA384_TEST_VECTORS
);
1401 test_hash("hmac(sha512)", hmac_sha512_tv_template
,
1402 HMAC_SHA512_TEST_VECTORS
);
1404 test_hash("xcbc(aes)", aes_xcbc128_tv_template
,
1405 XCBC_AES_TEST_VECTORS
);
1407 test_hash("michael_mic", michael_mic_tv_template
, MICHAEL_MIC_TEST_VECTORS
);
1411 test_hash("md5", md5_tv_template
, MD5_TEST_VECTORS
);
1415 test_hash("sha1", sha1_tv_template
, SHA1_TEST_VECTORS
);
1419 test_cipher("ecb(des)", ENCRYPT
, des_enc_tv_template
,
1420 DES_ENC_TEST_VECTORS
);
1421 test_cipher("ecb(des)", DECRYPT
, des_dec_tv_template
,
1422 DES_DEC_TEST_VECTORS
);
1423 test_cipher("cbc(des)", ENCRYPT
, des_cbc_enc_tv_template
,
1424 DES_CBC_ENC_TEST_VECTORS
);
1425 test_cipher("cbc(des)", DECRYPT
, des_cbc_dec_tv_template
,
1426 DES_CBC_DEC_TEST_VECTORS
);
1430 test_cipher("ecb(des3_ede)", ENCRYPT
, des3_ede_enc_tv_template
,
1431 DES3_EDE_ENC_TEST_VECTORS
);
1432 test_cipher("ecb(des3_ede)", DECRYPT
, des3_ede_dec_tv_template
,
1433 DES3_EDE_DEC_TEST_VECTORS
);
1435 test_cipher("cbc(des3_ede)", ENCRYPT
,
1436 des3_ede_cbc_enc_tv_template
,
1437 DES3_EDE_CBC_ENC_TEST_VECTORS
);
1439 test_cipher("cbc(des3_ede)", DECRYPT
,
1440 des3_ede_cbc_dec_tv_template
,
1441 DES3_EDE_CBC_DEC_TEST_VECTORS
);
1445 test_hash("md4", md4_tv_template
, MD4_TEST_VECTORS
);
1449 test_hash("sha256", sha256_tv_template
, SHA256_TEST_VECTORS
);
1453 test_cipher("ecb(blowfish)", ENCRYPT
, bf_enc_tv_template
,
1454 BF_ENC_TEST_VECTORS
);
1455 test_cipher("ecb(blowfish)", DECRYPT
, bf_dec_tv_template
,
1456 BF_DEC_TEST_VECTORS
);
1457 test_cipher("cbc(blowfish)", ENCRYPT
, bf_cbc_enc_tv_template
,
1458 BF_CBC_ENC_TEST_VECTORS
);
1459 test_cipher("cbc(blowfish)", DECRYPT
, bf_cbc_dec_tv_template
,
1460 BF_CBC_DEC_TEST_VECTORS
);
1464 test_cipher("ecb(twofish)", ENCRYPT
, tf_enc_tv_template
,
1465 TF_ENC_TEST_VECTORS
);
1466 test_cipher("ecb(twofish)", DECRYPT
, tf_dec_tv_template
,
1467 TF_DEC_TEST_VECTORS
);
1468 test_cipher("cbc(twofish)", ENCRYPT
, tf_cbc_enc_tv_template
,
1469 TF_CBC_ENC_TEST_VECTORS
);
1470 test_cipher("cbc(twofish)", DECRYPT
, tf_cbc_dec_tv_template
,
1471 TF_CBC_DEC_TEST_VECTORS
);
1475 test_cipher("ecb(serpent)", ENCRYPT
, serpent_enc_tv_template
,
1476 SERPENT_ENC_TEST_VECTORS
);
1477 test_cipher("ecb(serpent)", DECRYPT
, serpent_dec_tv_template
,
1478 SERPENT_DEC_TEST_VECTORS
);
1482 test_cipher("ecb(aes)", ENCRYPT
, aes_enc_tv_template
,
1483 AES_ENC_TEST_VECTORS
);
1484 test_cipher("ecb(aes)", DECRYPT
, aes_dec_tv_template
,
1485 AES_DEC_TEST_VECTORS
);
1486 test_cipher("cbc(aes)", ENCRYPT
, aes_cbc_enc_tv_template
,
1487 AES_CBC_ENC_TEST_VECTORS
);
1488 test_cipher("cbc(aes)", DECRYPT
, aes_cbc_dec_tv_template
,
1489 AES_CBC_DEC_TEST_VECTORS
);
1490 test_cipher("lrw(aes)", ENCRYPT
, aes_lrw_enc_tv_template
,
1491 AES_LRW_ENC_TEST_VECTORS
);
1492 test_cipher("lrw(aes)", DECRYPT
, aes_lrw_dec_tv_template
,
1493 AES_LRW_DEC_TEST_VECTORS
);
1494 test_cipher("xts(aes)", ENCRYPT
, aes_xts_enc_tv_template
,
1495 AES_XTS_ENC_TEST_VECTORS
);
1496 test_cipher("xts(aes)", DECRYPT
, aes_xts_dec_tv_template
,
1497 AES_XTS_DEC_TEST_VECTORS
);
1498 test_cipher("rfc3686(ctr(aes))", ENCRYPT
, aes_ctr_enc_tv_template
,
1499 AES_CTR_ENC_TEST_VECTORS
);
1500 test_cipher("rfc3686(ctr(aes))", DECRYPT
, aes_ctr_dec_tv_template
,
1501 AES_CTR_DEC_TEST_VECTORS
);
1505 test_hash("sha384", sha384_tv_template
, SHA384_TEST_VECTORS
);
1509 test_hash("sha512", sha512_tv_template
, SHA512_TEST_VECTORS
);
1513 test_comp("deflate", deflate_comp_tv_template
,
1514 deflate_decomp_tv_template
, DEFLATE_COMP_TEST_VECTORS
,
1515 DEFLATE_DECOMP_TEST_VECTORS
);
1519 test_cipher("ecb(cast5)", ENCRYPT
, cast5_enc_tv_template
,
1520 CAST5_ENC_TEST_VECTORS
);
1521 test_cipher("ecb(cast5)", DECRYPT
, cast5_dec_tv_template
,
1522 CAST5_DEC_TEST_VECTORS
);
1526 test_cipher("ecb(cast6)", ENCRYPT
, cast6_enc_tv_template
,
1527 CAST6_ENC_TEST_VECTORS
);
1528 test_cipher("ecb(cast6)", DECRYPT
, cast6_dec_tv_template
,
1529 CAST6_DEC_TEST_VECTORS
);
1533 test_cipher("ecb(arc4)", ENCRYPT
, arc4_enc_tv_template
,
1534 ARC4_ENC_TEST_VECTORS
);
1535 test_cipher("ecb(arc4)", DECRYPT
, arc4_dec_tv_template
,
1536 ARC4_DEC_TEST_VECTORS
);
1540 test_hash("michael_mic", michael_mic_tv_template
, MICHAEL_MIC_TEST_VECTORS
);
1544 test_hash("crc32c", crc32c_tv_template
, CRC32C_TEST_VECTORS
);
1548 test_cipher("ecb(tea)", ENCRYPT
, tea_enc_tv_template
,
1549 TEA_ENC_TEST_VECTORS
);
1550 test_cipher("ecb(tea)", DECRYPT
, tea_dec_tv_template
,
1551 TEA_DEC_TEST_VECTORS
);
1555 test_cipher("ecb(xtea)", ENCRYPT
, xtea_enc_tv_template
,
1556 XTEA_ENC_TEST_VECTORS
);
1557 test_cipher("ecb(xtea)", DECRYPT
, xtea_dec_tv_template
,
1558 XTEA_DEC_TEST_VECTORS
);
1562 test_cipher("ecb(khazad)", ENCRYPT
, khazad_enc_tv_template
,
1563 KHAZAD_ENC_TEST_VECTORS
);
1564 test_cipher("ecb(khazad)", DECRYPT
, khazad_dec_tv_template
,
1565 KHAZAD_DEC_TEST_VECTORS
);
1569 test_hash("wp512", wp512_tv_template
, WP512_TEST_VECTORS
);
1573 test_hash("wp384", wp384_tv_template
, WP384_TEST_VECTORS
);
1577 test_hash("wp256", wp256_tv_template
, WP256_TEST_VECTORS
);
1581 test_cipher("ecb(tnepres)", ENCRYPT
, tnepres_enc_tv_template
,
1582 TNEPRES_ENC_TEST_VECTORS
);
1583 test_cipher("ecb(tnepres)", DECRYPT
, tnepres_dec_tv_template
,
1584 TNEPRES_DEC_TEST_VECTORS
);
1588 test_cipher("ecb(anubis)", ENCRYPT
, anubis_enc_tv_template
,
1589 ANUBIS_ENC_TEST_VECTORS
);
1590 test_cipher("ecb(anubis)", DECRYPT
, anubis_dec_tv_template
,
1591 ANUBIS_DEC_TEST_VECTORS
);
1592 test_cipher("cbc(anubis)", ENCRYPT
, anubis_cbc_enc_tv_template
,
1593 ANUBIS_CBC_ENC_TEST_VECTORS
);
1594 test_cipher("cbc(anubis)", DECRYPT
, anubis_cbc_dec_tv_template
,
1595 ANUBIS_CBC_ENC_TEST_VECTORS
);
1599 test_hash("tgr192", tgr192_tv_template
, TGR192_TEST_VECTORS
);
1604 test_hash("tgr160", tgr160_tv_template
, TGR160_TEST_VECTORS
);
1608 test_hash("tgr128", tgr128_tv_template
, TGR128_TEST_VECTORS
);
1612 test_cipher("ecb(xeta)", ENCRYPT
, xeta_enc_tv_template
,
1613 XETA_ENC_TEST_VECTORS
);
1614 test_cipher("ecb(xeta)", DECRYPT
, xeta_dec_tv_template
,
1615 XETA_DEC_TEST_VECTORS
);
1619 test_cipher("pcbc(fcrypt)", ENCRYPT
, fcrypt_pcbc_enc_tv_template
,
1620 FCRYPT_ENC_TEST_VECTORS
);
1621 test_cipher("pcbc(fcrypt)", DECRYPT
, fcrypt_pcbc_dec_tv_template
,
1622 FCRYPT_DEC_TEST_VECTORS
);
1626 test_cipher("ecb(camellia)", ENCRYPT
,
1627 camellia_enc_tv_template
,
1628 CAMELLIA_ENC_TEST_VECTORS
);
1629 test_cipher("ecb(camellia)", DECRYPT
,
1630 camellia_dec_tv_template
,
1631 CAMELLIA_DEC_TEST_VECTORS
);
1632 test_cipher("cbc(camellia)", ENCRYPT
,
1633 camellia_cbc_enc_tv_template
,
1634 CAMELLIA_CBC_ENC_TEST_VECTORS
);
1635 test_cipher("cbc(camellia)", DECRYPT
,
1636 camellia_cbc_dec_tv_template
,
1637 CAMELLIA_CBC_DEC_TEST_VECTORS
);
1640 test_hash("sha224", sha224_tv_template
, SHA224_TEST_VECTORS
);
1644 test_cipher("salsa20", ENCRYPT
,
1645 salsa20_stream_enc_tv_template
,
1646 SALSA20_STREAM_ENC_TEST_VECTORS
);
1650 test_aead("gcm(aes)", ENCRYPT
, aes_gcm_enc_tv_template
,
1651 AES_GCM_ENC_TEST_VECTORS
);
1652 test_aead("gcm(aes)", DECRYPT
, aes_gcm_dec_tv_template
,
1653 AES_GCM_DEC_TEST_VECTORS
);
1657 test_comp("lzo", lzo_comp_tv_template
, lzo_decomp_tv_template
,
1658 LZO_COMP_TEST_VECTORS
, LZO_DECOMP_TEST_VECTORS
);
1662 test_aead("ccm(aes)", ENCRYPT
, aes_ccm_enc_tv_template
,
1663 AES_CCM_ENC_TEST_VECTORS
);
1664 test_aead("ccm(aes)", DECRYPT
, aes_ccm_dec_tv_template
,
1665 AES_CCM_DEC_TEST_VECTORS
);
1669 test_cipher("cts(cbc(aes))", ENCRYPT
, cts_mode_enc_tv_template
,
1670 CTS_MODE_ENC_TEST_VECTORS
);
1671 test_cipher("cts(cbc(aes))", DECRYPT
, cts_mode_dec_tv_template
,
1672 CTS_MODE_DEC_TEST_VECTORS
);
1676 test_hash("rmd128", rmd128_tv_template
, RMD128_TEST_VECTORS
);
1680 test_hash("rmd160", rmd160_tv_template
, RMD160_TEST_VECTORS
);
1684 test_hash("rmd256", rmd256_tv_template
, RMD256_TEST_VECTORS
);
1688 test_hash("rmd320", rmd320_tv_template
, RMD320_TEST_VECTORS
);
1692 test_hash("hmac(md5)", hmac_md5_tv_template
,
1693 HMAC_MD5_TEST_VECTORS
);
1697 test_hash("hmac(sha1)", hmac_sha1_tv_template
,
1698 HMAC_SHA1_TEST_VECTORS
);
1702 test_hash("hmac(sha256)", hmac_sha256_tv_template
,
1703 HMAC_SHA256_TEST_VECTORS
);
1707 test_hash("hmac(sha384)", hmac_sha384_tv_template
,
1708 HMAC_SHA384_TEST_VECTORS
);
1712 test_hash("hmac(sha512)", hmac_sha512_tv_template
,
1713 HMAC_SHA512_TEST_VECTORS
);
1717 test_hash("hmac(sha224)", hmac_sha224_tv_template
,
1718 HMAC_SHA224_TEST_VECTORS
);
1722 test_hash("xcbc(aes)", aes_xcbc128_tv_template
,
1723 XCBC_AES_TEST_VECTORS
);
1727 test_hash("hmac(rmd128)", hmac_rmd128_tv_template
,
1728 HMAC_RMD128_TEST_VECTORS
);
1732 test_hash("hmac(rmd160)", hmac_rmd160_tv_template
,
1733 HMAC_RMD160_TEST_VECTORS
);
1737 test_cipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1738 speed_template_16_24_32
);
1739 test_cipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1740 speed_template_16_24_32
);
1741 test_cipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1742 speed_template_16_24_32
);
1743 test_cipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1744 speed_template_16_24_32
);
1745 test_cipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1746 speed_template_32_40_48
);
1747 test_cipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1748 speed_template_32_40_48
);
1749 test_cipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1750 speed_template_32_48_64
);
1751 test_cipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1752 speed_template_32_48_64
);
1756 test_cipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1757 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1759 test_cipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1760 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1762 test_cipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1763 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1765 test_cipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1766 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1771 test_cipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1772 speed_template_16_24_32
);
1773 test_cipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1774 speed_template_16_24_32
);
1775 test_cipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1776 speed_template_16_24_32
);
1777 test_cipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1778 speed_template_16_24_32
);
1782 test_cipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1783 speed_template_8_32
);
1784 test_cipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
1785 speed_template_8_32
);
1786 test_cipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1787 speed_template_8_32
);
1788 test_cipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
1789 speed_template_8_32
);
1793 test_cipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1795 test_cipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1797 test_cipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1799 test_cipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1804 test_cipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
1805 speed_template_16_24_32
);
1806 test_cipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
1807 speed_template_16_24_32
);
1808 test_cipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
1809 speed_template_16_24_32
);
1810 test_cipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
1811 speed_template_16_24_32
);
1815 test_cipher_speed("salsa20", ENCRYPT
, sec
, NULL
, 0,
1816 speed_template_16_32
);
1823 test_hash_speed("md4", sec
, generic_hash_speed_template
);
1824 if (mode
> 300 && mode
< 400) break;
1827 test_hash_speed("md5", sec
, generic_hash_speed_template
);
1828 if (mode
> 300 && mode
< 400) break;
1831 test_hash_speed("sha1", sec
, generic_hash_speed_template
);
1832 if (mode
> 300 && mode
< 400) break;
1835 test_hash_speed("sha256", sec
, generic_hash_speed_template
);
1836 if (mode
> 300 && mode
< 400) break;
1839 test_hash_speed("sha384", sec
, generic_hash_speed_template
);
1840 if (mode
> 300 && mode
< 400) break;
1843 test_hash_speed("sha512", sec
, generic_hash_speed_template
);
1844 if (mode
> 300 && mode
< 400) break;
1847 test_hash_speed("wp256", sec
, generic_hash_speed_template
);
1848 if (mode
> 300 && mode
< 400) break;
1851 test_hash_speed("wp384", sec
, generic_hash_speed_template
);
1852 if (mode
> 300 && mode
< 400) break;
1855 test_hash_speed("wp512", sec
, generic_hash_speed_template
);
1856 if (mode
> 300 && mode
< 400) break;
1859 test_hash_speed("tgr128", sec
, generic_hash_speed_template
);
1860 if (mode
> 300 && mode
< 400) break;
1863 test_hash_speed("tgr160", sec
, generic_hash_speed_template
);
1864 if (mode
> 300 && mode
< 400) break;
1867 test_hash_speed("tgr192", sec
, generic_hash_speed_template
);
1868 if (mode
> 300 && mode
< 400) break;
1871 test_hash_speed("sha224", sec
, generic_hash_speed_template
);
1872 if (mode
> 300 && mode
< 400) break;
1875 test_hash_speed("rmd128", sec
, generic_hash_speed_template
);
1876 if (mode
> 300 && mode
< 400) break;
1879 test_hash_speed("rmd160", sec
, generic_hash_speed_template
);
1880 if (mode
> 300 && mode
< 400) break;
1883 test_hash_speed("rmd256", sec
, generic_hash_speed_template
);
1884 if (mode
> 300 && mode
< 400) break;
1887 test_hash_speed("rmd320", sec
, generic_hash_speed_template
);
1888 if (mode
> 300 && mode
< 400) break;
1898 /* useful for debugging */
1899 printk("not testing anything\n");
1904 static int __init
tcrypt_mod_init(void)
1909 for (i
= 0; i
< TVMEMSIZE
; i
++) {
1910 tvmem
[i
] = (void *)__get_free_page(GFP_KERNEL
);
1915 for (i
= 0; i
< XBUFSIZE
; i
++) {
1916 xbuf
[i
] = (void *)__get_free_page(GFP_KERNEL
);
1921 for (i
= 0; i
< XBUFSIZE
; i
++) {
1922 axbuf
[i
] = (void *)__get_free_page(GFP_KERNEL
);
1924 goto err_free_axbuf
;
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?
1938 for (i
= 0; i
< XBUFSIZE
&& axbuf
[i
]; i
++)
1939 free_page((unsigned long)axbuf
[i
]);
1941 for (i
= 0; i
< XBUFSIZE
&& xbuf
[i
]; i
++)
1942 free_page((unsigned long)xbuf
[i
]);
1944 for (i
= 0; i
< TVMEMSIZE
&& tvmem
[i
]; i
++)
1945 free_page((unsigned long)tvmem
[i
]);
1951 * If an init function is provided, an exit function must also be provided
1952 * to allow module unload.
1954 static void __exit
tcrypt_mod_fini(void) { }
1956 module_init(tcrypt_mod_init
);
1957 module_exit(tcrypt_mod_fini
);
1959 module_param(mode
, int, 0);
1960 module_param(sec
, uint
, 0);
1961 MODULE_PARM_DESC(sec
, "Length in seconds of speed tests "
1962 "(defaults to zero which uses CPU cycles instead)");
1964 MODULE_LICENSE("GPL");
1965 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1966 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");