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", "lzo", "cts", NULL
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_hash
*tfm
;
107 struct hash_desc desc
;
111 printk("\ntesting %s\n", algo
);
113 tfm
= crypto_alloc_hash(algo
, 0, CRYPTO_ALG_ASYNC
);
115 printk("failed to load transform for %s: %ld\n", algo
,
123 for (i
= 0; i
< tcount
; i
++) {
124 printk("test %u:\n", i
+ 1);
125 memset(result
, 0, 64);
127 hash_buff
= kzalloc(template[i
].psize
, GFP_KERNEL
);
131 memcpy(hash_buff
, template[i
].plaintext
, template[i
].psize
);
132 sg_init_one(&sg
[0], hash_buff
, template[i
].psize
);
134 if (template[i
].ksize
) {
135 ret
= crypto_hash_setkey(tfm
, template[i
].key
,
138 printk("setkey() failed ret=%d\n", ret
);
144 ret
= crypto_hash_digest(&desc
, sg
, template[i
].psize
, result
);
146 printk("digest () failed ret=%d\n", ret
);
151 hexdump(result
, crypto_hash_digestsize(tfm
));
153 memcmp(result
, template[i
].digest
,
154 crypto_hash_digestsize(tfm
)) ?
159 printk("testing %s across pages\n", algo
);
161 /* setup the dummy buffer first */
162 memset(xbuf
, 0, XBUFSIZE
);
165 for (i
= 0; i
< tcount
; i
++) {
166 if (template[i
].np
) {
168 printk("test %u:\n", j
);
169 memset(result
, 0, 64);
172 sg_init_table(sg
, template[i
].np
);
173 for (k
= 0; k
< template[i
].np
; k
++) {
174 memcpy(&xbuf
[IDX
[k
]],
175 template[i
].plaintext
+ temp
,
177 temp
+= template[i
].tap
[k
];
178 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
182 if (template[i
].ksize
) {
183 ret
= crypto_hash_setkey(tfm
, template[i
].key
,
187 printk("setkey() failed ret=%d\n", ret
);
192 ret
= crypto_hash_digest(&desc
, sg
, template[i
].psize
,
195 printk("digest () failed ret=%d\n", ret
);
199 hexdump(result
, crypto_hash_digestsize(tfm
));
201 memcmp(result
, template[i
].digest
,
202 crypto_hash_digestsize(tfm
)) ?
208 crypto_free_hash(tfm
);
211 static void test_aead(char *algo
, int enc
, struct aead_testvec
*template,
214 unsigned int ret
, i
, j
, k
, n
, temp
;
216 struct crypto_aead
*tfm
;
218 struct aead_request
*req
;
219 struct scatterlist sg
[8];
220 struct scatterlist asg
[8];
222 struct tcrypt_result result
;
223 unsigned int authsize
;
233 printk(KERN_INFO
"\ntesting %s %s\n", algo
, e
);
235 init_completion(&result
.completion
);
237 tfm
= crypto_alloc_aead(algo
, 0, 0);
240 printk(KERN_INFO
"failed to load transform for %s: %ld\n",
245 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
247 printk(KERN_INFO
"failed to allocate request for %s\n", algo
);
251 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
252 tcrypt_complete
, &result
);
254 for (i
= 0, j
= 0; i
< tcount
; i
++) {
255 if (!template[i
].np
) {
256 printk(KERN_INFO
"test %u (%d bit key):\n",
257 ++j
, template[i
].klen
* 8);
259 /* some tepmplates have no input data but they will
262 input
= kzalloc(template[i
].ilen
+ template[i
].rlen
, GFP_KERNEL
);
266 assoc
= kzalloc(template[i
].alen
, GFP_KERNEL
);
272 memcpy(input
, template[i
].input
, template[i
].ilen
);
273 memcpy(assoc
, template[i
].assoc
, template[i
].alen
);
275 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
277 memset(iv
, 0, MAX_IVLEN
);
279 crypto_aead_clear_flags(tfm
, ~0);
281 crypto_aead_set_flags(
282 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
285 key
= template[i
].key
;
287 key
= kzalloc(template[i
].klen
, GFP_KERNEL
);
289 ret
= crypto_aead_setkey(tfm
, key
,
292 printk(KERN_INFO
"setkey() failed flags=%x\n",
293 crypto_aead_get_flags(tfm
));
295 if (!template[i
].fail
)
299 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
300 ret
= crypto_aead_setauthsize(tfm
, authsize
);
303 "failed to set authsize = %u\n",
308 sg_init_one(&sg
[0], input
,
309 template[i
].ilen
+ (enc
? authsize
: 0));
311 sg_init_one(&asg
[0], assoc
, template[i
].alen
);
313 aead_request_set_crypt(req
, sg
, sg
,
314 template[i
].ilen
, iv
);
316 aead_request_set_assoc(req
, asg
, template[i
].alen
);
319 crypto_aead_encrypt(req
) :
320 crypto_aead_decrypt(req
);
327 ret
= wait_for_completion_interruptible(
329 if (!ret
&& !(ret
= result
.err
)) {
330 INIT_COMPLETION(result
.completion
);
335 printk(KERN_INFO
"%s () failed err=%d\n",
340 q
= kmap(sg_page(&sg
[0])) + sg
[0].offset
;
341 hexdump(q
, template[i
].rlen
);
343 printk(KERN_INFO
"enc/dec: %s\n",
344 memcmp(q
, template[i
].result
,
345 template[i
].rlen
) ? "fail" : "pass");
346 kunmap(sg_page(&sg
[0]));
348 if (!template[i
].key
)
355 printk(KERN_INFO
"\ntesting %s %s across pages (chunking)\n", algo
, e
);
356 memset(axbuf
, 0, XBUFSIZE
);
358 for (i
= 0, j
= 0; i
< tcount
; i
++) {
359 if (template[i
].np
) {
360 printk(KERN_INFO
"test %u (%d bit key):\n",
361 ++j
, template[i
].klen
* 8);
364 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
366 memset(iv
, 0, MAX_IVLEN
);
368 crypto_aead_clear_flags(tfm
, ~0);
370 crypto_aead_set_flags(
371 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
372 key
= template[i
].key
;
374 ret
= crypto_aead_setkey(tfm
, key
, template[i
].klen
);
376 printk(KERN_INFO
"setkey() failed flags=%x\n",
377 crypto_aead_get_flags(tfm
));
379 if (!template[i
].fail
)
383 memset(xbuf
, 0, XBUFSIZE
);
384 sg_init_table(sg
, template[i
].np
);
385 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
386 memcpy(&xbuf
[IDX
[k
]],
387 template[i
].input
+ temp
,
389 temp
+= template[i
].tap
[k
];
390 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
394 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
395 ret
= crypto_aead_setauthsize(tfm
, authsize
);
398 "failed to set authsize = %u\n",
404 sg
[k
- 1].length
+= authsize
;
406 sg_init_table(asg
, template[i
].anp
);
407 for (k
= 0, temp
= 0; k
< template[i
].anp
; k
++) {
408 memcpy(&axbuf
[IDX
[k
]],
409 template[i
].assoc
+ temp
,
410 template[i
].atap
[k
]);
411 temp
+= template[i
].atap
[k
];
412 sg_set_buf(&asg
[k
], &axbuf
[IDX
[k
]],
413 template[i
].atap
[k
]);
416 aead_request_set_crypt(req
, sg
, sg
,
420 aead_request_set_assoc(req
, asg
, template[i
].alen
);
423 crypto_aead_encrypt(req
) :
424 crypto_aead_decrypt(req
);
431 ret
= wait_for_completion_interruptible(
433 if (!ret
&& !(ret
= result
.err
)) {
434 INIT_COMPLETION(result
.completion
);
439 printk(KERN_INFO
"%s () failed err=%d\n",
444 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
445 printk(KERN_INFO
"page %u\n", k
);
446 q
= kmap(sg_page(&sg
[k
])) + sg
[k
].offset
;
447 hexdump(q
, template[i
].tap
[k
]);
448 printk(KERN_INFO
"%s\n",
449 memcmp(q
, template[i
].result
+ temp
,
451 (k
< template[i
].np
- 1 || enc
?
455 for (n
= 0; q
[template[i
].tap
[k
] + n
]; n
++)
458 printk("Result buffer corruption %u "
460 hexdump(&q
[template[i
].tap
[k
]], n
);
463 temp
+= template[i
].tap
[k
];
464 kunmap(sg_page(&sg
[k
]));
470 crypto_free_aead(tfm
);
471 aead_request_free(req
);
474 static void test_cipher(char *algo
, int enc
,
475 struct cipher_testvec
*template, unsigned int tcount
)
477 unsigned int ret
, i
, j
, k
, n
, temp
;
479 struct crypto_ablkcipher
*tfm
;
480 struct ablkcipher_request
*req
;
481 struct scatterlist sg
[8];
483 struct tcrypt_result result
;
492 printk("\ntesting %s %s\n", algo
, e
);
494 init_completion(&result
.completion
);
495 tfm
= crypto_alloc_ablkcipher(algo
, 0, 0);
498 printk("failed to load transform for %s: %ld\n", algo
,
503 req
= ablkcipher_request_alloc(tfm
, GFP_KERNEL
);
505 printk("failed to allocate request for %s\n", algo
);
509 ablkcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
510 tcrypt_complete
, &result
);
513 for (i
= 0; i
< tcount
; i
++) {
515 data
= kzalloc(template[i
].ilen
, GFP_KERNEL
);
519 memcpy(data
, template[i
].input
, template[i
].ilen
);
521 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
523 memset(iv
, 0, MAX_IVLEN
);
525 if (!(template[i
].np
)) {
527 printk("test %u (%d bit key):\n",
528 j
, template[i
].klen
* 8);
530 crypto_ablkcipher_clear_flags(tfm
, ~0);
532 crypto_ablkcipher_set_flags(
533 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
535 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
538 printk("setkey() failed flags=%x\n",
539 crypto_ablkcipher_get_flags(tfm
));
541 if (!template[i
].fail
) {
547 sg_init_one(&sg
[0], data
, template[i
].ilen
);
549 ablkcipher_request_set_crypt(req
, sg
, sg
,
550 template[i
].ilen
, iv
);
552 crypto_ablkcipher_encrypt(req
) :
553 crypto_ablkcipher_decrypt(req
);
560 ret
= wait_for_completion_interruptible(
562 if (!ret
&& !((ret
= result
.err
))) {
563 INIT_COMPLETION(result
.completion
);
568 printk("%s () failed err=%d\n", e
, -ret
);
573 q
= kmap(sg_page(&sg
[0])) + sg
[0].offset
;
574 hexdump(q
, template[i
].rlen
);
577 memcmp(q
, template[i
].result
,
578 template[i
].rlen
) ? "fail" : "pass");
579 kunmap(sg_page(&sg
[0]));
584 printk("\ntesting %s %s across pages (chunking)\n", algo
, e
);
587 for (i
= 0; i
< tcount
; i
++) {
590 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
592 memset(iv
, 0, MAX_IVLEN
);
594 if (template[i
].np
) {
596 printk("test %u (%d bit key):\n",
597 j
, template[i
].klen
* 8);
599 memset(xbuf
, 0, XBUFSIZE
);
600 crypto_ablkcipher_clear_flags(tfm
, ~0);
602 crypto_ablkcipher_set_flags(
603 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
605 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
608 printk("setkey() failed flags=%x\n",
609 crypto_ablkcipher_get_flags(tfm
));
611 if (!template[i
].fail
)
616 sg_init_table(sg
, template[i
].np
);
617 for (k
= 0; k
< template[i
].np
; k
++) {
618 memcpy(&xbuf
[IDX
[k
]],
619 template[i
].input
+ temp
,
621 temp
+= template[i
].tap
[k
];
622 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
626 ablkcipher_request_set_crypt(req
, sg
, sg
,
627 template[i
].ilen
, iv
);
630 crypto_ablkcipher_encrypt(req
) :
631 crypto_ablkcipher_decrypt(req
);
638 ret
= wait_for_completion_interruptible(
640 if (!ret
&& !((ret
= result
.err
))) {
641 INIT_COMPLETION(result
.completion
);
646 printk("%s () failed err=%d\n", e
, -ret
);
651 for (k
= 0; k
< template[i
].np
; k
++) {
652 printk("page %u\n", k
);
653 q
= kmap(sg_page(&sg
[k
])) + sg
[k
].offset
;
654 hexdump(q
, template[i
].tap
[k
]);
656 memcmp(q
, template[i
].result
+ temp
,
657 template[i
].tap
[k
]) ? "fail" :
660 for (n
= 0; q
[template[i
].tap
[k
] + n
]; n
++)
663 printk("Result buffer corruption %u "
665 hexdump(&q
[template[i
].tap
[k
]], n
);
667 temp
+= template[i
].tap
[k
];
668 kunmap(sg_page(&sg
[k
]));
673 crypto_free_ablkcipher(tfm
);
674 ablkcipher_request_free(req
);
677 static int test_cipher_jiffies(struct blkcipher_desc
*desc
, int enc
, char *p
,
680 struct scatterlist sg
[1];
681 unsigned long start
, end
;
685 sg_init_one(sg
, p
, blen
);
687 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
688 time_before(jiffies
, end
); bcount
++) {
690 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
692 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
698 printk("%d operations in %d seconds (%ld bytes)\n",
699 bcount
, sec
, (long)bcount
* blen
);
703 static int test_cipher_cycles(struct blkcipher_desc
*desc
, int enc
, char *p
,
706 struct scatterlist sg
[1];
707 unsigned long cycles
= 0;
711 sg_init_one(sg
, p
, blen
);
717 for (i
= 0; i
< 4; i
++) {
719 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
721 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
727 /* The real thing. */
728 for (i
= 0; i
< 8; i
++) {
731 start
= get_cycles();
733 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
735 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
741 cycles
+= end
- start
;
749 printk("1 operation in %lu cycles (%d bytes)\n",
750 (cycles
+ 4) / 8, blen
);
755 static u32 block_sizes
[] = { 16, 64, 256, 1024, 8192, 0 };
757 static void test_cipher_speed(char *algo
, int enc
, unsigned int sec
,
758 struct cipher_testvec
*template,
759 unsigned int tcount
, u8
*keysize
)
761 unsigned int ret
, i
, j
, iv_len
;
762 unsigned char *key
, *p
, iv
[128];
763 struct crypto_blkcipher
*tfm
;
764 struct blkcipher_desc desc
;
773 printk("\ntesting speed of %s %s\n", algo
, e
);
775 tfm
= crypto_alloc_blkcipher(algo
, 0, CRYPTO_ALG_ASYNC
);
778 printk("failed to load transform for %s: %ld\n", algo
,
788 b_size
= block_sizes
;
791 if ((*keysize
+ *b_size
) > TVMEMSIZE
) {
792 printk("template (%u) too big for tvmem (%u)\n",
793 *keysize
+ *b_size
, TVMEMSIZE
);
797 printk("test %u (%d bit key, %d byte blocks): ", i
,
798 *keysize
* 8, *b_size
);
800 memset(tvmem
, 0xff, *keysize
+ *b_size
);
802 /* set key, plain text and IV */
803 key
= (unsigned char *)tvmem
;
804 for (j
= 0; j
< tcount
; j
++) {
805 if (template[j
].klen
== *keysize
) {
806 key
= template[j
].key
;
810 p
= (unsigned char *)tvmem
+ *keysize
;
812 ret
= crypto_blkcipher_setkey(tfm
, key
, *keysize
);
814 printk("setkey() failed flags=%x\n",
815 crypto_blkcipher_get_flags(tfm
));
819 iv_len
= crypto_blkcipher_ivsize(tfm
);
821 memset(&iv
, 0xff, iv_len
);
822 crypto_blkcipher_set_iv(tfm
, iv
, iv_len
);
826 ret
= test_cipher_jiffies(&desc
, enc
, p
, *b_size
, sec
);
828 ret
= test_cipher_cycles(&desc
, enc
, p
, *b_size
);
831 printk("%s() failed flags=%x\n", e
, desc
.flags
);
841 crypto_free_blkcipher(tfm
);
844 static int test_hash_jiffies_digest(struct hash_desc
*desc
, char *p
, int blen
,
847 struct scatterlist sg
[1];
848 unsigned long start
, end
;
852 sg_init_table(sg
, 1);
854 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
855 time_before(jiffies
, end
); bcount
++) {
856 sg_set_buf(sg
, p
, blen
);
857 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
862 printk("%6u opers/sec, %9lu bytes/sec\n",
863 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
868 static int test_hash_jiffies(struct hash_desc
*desc
, char *p
, int blen
,
869 int plen
, char *out
, int sec
)
871 struct scatterlist sg
[1];
872 unsigned long start
, end
;
877 return test_hash_jiffies_digest(desc
, p
, blen
, out
, sec
);
879 sg_init_table(sg
, 1);
881 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
882 time_before(jiffies
, end
); bcount
++) {
883 ret
= crypto_hash_init(desc
);
886 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
887 sg_set_buf(sg
, p
+ pcount
, plen
);
888 ret
= crypto_hash_update(desc
, sg
, plen
);
892 /* we assume there is enough space in 'out' for the result */
893 ret
= crypto_hash_final(desc
, out
);
898 printk("%6u opers/sec, %9lu bytes/sec\n",
899 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
904 static int test_hash_cycles_digest(struct hash_desc
*desc
, char *p
, int blen
,
907 struct scatterlist sg
[1];
908 unsigned long cycles
= 0;
912 sg_init_table(sg
, 1);
918 for (i
= 0; i
< 4; i
++) {
919 sg_set_buf(sg
, p
, blen
);
920 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
925 /* The real thing. */
926 for (i
= 0; i
< 8; i
++) {
929 start
= get_cycles();
931 sg_set_buf(sg
, p
, blen
);
932 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
938 cycles
+= end
- start
;
948 printk("%6lu cycles/operation, %4lu cycles/byte\n",
949 cycles
/ 8, cycles
/ (8 * blen
));
954 static int test_hash_cycles(struct hash_desc
*desc
, char *p
, int blen
,
957 struct scatterlist sg
[1];
958 unsigned long cycles
= 0;
963 return test_hash_cycles_digest(desc
, p
, blen
, out
);
965 sg_init_table(sg
, 1);
971 for (i
= 0; i
< 4; i
++) {
972 ret
= crypto_hash_init(desc
);
975 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
976 sg_set_buf(sg
, p
+ pcount
, plen
);
977 ret
= crypto_hash_update(desc
, sg
, plen
);
981 ret
= crypto_hash_final(desc
, out
);
986 /* The real thing. */
987 for (i
= 0; i
< 8; i
++) {
990 start
= get_cycles();
992 ret
= crypto_hash_init(desc
);
995 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
996 sg_set_buf(sg
, p
+ pcount
, plen
);
997 ret
= crypto_hash_update(desc
, sg
, plen
);
1001 ret
= crypto_hash_final(desc
, out
);
1007 cycles
+= end
- start
;
1017 printk("%6lu cycles/operation, %4lu cycles/byte\n",
1018 cycles
/ 8, cycles
/ (8 * blen
));
1023 static void test_hash_speed(char *algo
, unsigned int sec
,
1024 struct hash_speed
*speed
)
1026 struct crypto_hash
*tfm
;
1027 struct hash_desc desc
;
1032 printk("\ntesting speed of %s\n", algo
);
1034 tfm
= crypto_alloc_hash(algo
, 0, CRYPTO_ALG_ASYNC
);
1037 printk("failed to load transform for %s: %ld\n", algo
,
1045 if (crypto_hash_digestsize(tfm
) > sizeof(output
)) {
1046 printk("digestsize(%u) > outputbuffer(%zu)\n",
1047 crypto_hash_digestsize(tfm
), sizeof(output
));
1051 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
1052 if (speed
[i
].blen
> TVMEMSIZE
) {
1053 printk("template (%u) too big for tvmem (%u)\n",
1054 speed
[i
].blen
, TVMEMSIZE
);
1058 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
1059 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
1061 memset(tvmem
, 0xff, speed
[i
].blen
);
1064 ret
= test_hash_jiffies(&desc
, tvmem
, speed
[i
].blen
,
1065 speed
[i
].plen
, output
, sec
);
1067 ret
= test_hash_cycles(&desc
, tvmem
, speed
[i
].blen
,
1068 speed
[i
].plen
, output
);
1071 printk("hashing failed ret=%d\n", ret
);
1077 crypto_free_hash(tfm
);
1080 static void test_comp(char *algo
, struct comp_testvec
*ctemplate
,
1081 struct comp_testvec
*dtemplate
, int ctcount
, int dtcount
)
1084 char result
[COMP_BUF_SIZE
];
1085 struct crypto_comp
*tfm
;
1088 printk("\ntesting %s compression\n", algo
);
1090 tfm
= crypto_alloc_comp(algo
, 0, CRYPTO_ALG_ASYNC
);
1092 printk("failed to load transform for %s\n", algo
);
1096 for (i
= 0; i
< ctcount
; i
++) {
1097 int ilen
, ret
, dlen
= COMP_BUF_SIZE
;
1099 printk("test %u:\n", i
+ 1);
1100 memset(result
, 0, sizeof (result
));
1102 ilen
= ctemplate
[i
].inlen
;
1103 ret
= crypto_comp_compress(tfm
, ctemplate
[i
].input
,
1104 ilen
, result
, &dlen
);
1106 printk("fail: ret=%d\n", ret
);
1109 hexdump(result
, dlen
);
1110 printk("%s (ratio %d:%d)\n",
1111 memcmp(result
, ctemplate
[i
].output
, dlen
) ? "fail" : "pass",
1115 printk("\ntesting %s decompression\n", algo
);
1117 tsize
= sizeof(struct comp_testvec
);
1119 if (tsize
> TVMEMSIZE
) {
1120 printk("template (%u) too big for tvmem (%u)\n", tsize
,
1125 for (i
= 0; i
< dtcount
; i
++) {
1126 int ilen
, ret
, dlen
= COMP_BUF_SIZE
;
1128 printk("test %u:\n", i
+ 1);
1129 memset(result
, 0, sizeof (result
));
1131 ilen
= dtemplate
[i
].inlen
;
1132 ret
= crypto_comp_decompress(tfm
, dtemplate
[i
].input
,
1133 ilen
, result
, &dlen
);
1135 printk("fail: ret=%d\n", ret
);
1138 hexdump(result
, dlen
);
1139 printk("%s (ratio %d:%d)\n",
1140 memcmp(result
, dtemplate
[i
].output
, dlen
) ? "fail" : "pass",
1144 crypto_free_comp(tfm
);
1147 static void test_available(void)
1149 char **name
= check
;
1152 printk("alg %s ", *name
);
1153 printk(crypto_has_alg(*name
, 0, 0) ?
1154 "found\n" : "not found\n");
1159 static void do_test(void)
1164 test_hash("md5", md5_tv_template
, MD5_TEST_VECTORS
);
1166 test_hash("sha1", sha1_tv_template
, SHA1_TEST_VECTORS
);
1169 test_cipher("ecb(des)", ENCRYPT
, des_enc_tv_template
,
1170 DES_ENC_TEST_VECTORS
);
1171 test_cipher("ecb(des)", DECRYPT
, des_dec_tv_template
,
1172 DES_DEC_TEST_VECTORS
);
1173 test_cipher("cbc(des)", ENCRYPT
, des_cbc_enc_tv_template
,
1174 DES_CBC_ENC_TEST_VECTORS
);
1175 test_cipher("cbc(des)", DECRYPT
, des_cbc_dec_tv_template
,
1176 DES_CBC_DEC_TEST_VECTORS
);
1179 test_cipher("ecb(des3_ede)", ENCRYPT
, des3_ede_enc_tv_template
,
1180 DES3_EDE_ENC_TEST_VECTORS
);
1181 test_cipher("ecb(des3_ede)", DECRYPT
, des3_ede_dec_tv_template
,
1182 DES3_EDE_DEC_TEST_VECTORS
);
1184 test_hash("md4", md4_tv_template
, MD4_TEST_VECTORS
);
1186 test_hash("sha224", sha224_tv_template
, SHA224_TEST_VECTORS
);
1188 test_hash("sha256", sha256_tv_template
, SHA256_TEST_VECTORS
);
1191 test_cipher("ecb(blowfish)", ENCRYPT
, bf_enc_tv_template
,
1192 BF_ENC_TEST_VECTORS
);
1193 test_cipher("ecb(blowfish)", DECRYPT
, bf_dec_tv_template
,
1194 BF_DEC_TEST_VECTORS
);
1195 test_cipher("cbc(blowfish)", ENCRYPT
, bf_cbc_enc_tv_template
,
1196 BF_CBC_ENC_TEST_VECTORS
);
1197 test_cipher("cbc(blowfish)", DECRYPT
, bf_cbc_dec_tv_template
,
1198 BF_CBC_DEC_TEST_VECTORS
);
1201 test_cipher("ecb(twofish)", ENCRYPT
, tf_enc_tv_template
,
1202 TF_ENC_TEST_VECTORS
);
1203 test_cipher("ecb(twofish)", DECRYPT
, tf_dec_tv_template
,
1204 TF_DEC_TEST_VECTORS
);
1205 test_cipher("cbc(twofish)", ENCRYPT
, tf_cbc_enc_tv_template
,
1206 TF_CBC_ENC_TEST_VECTORS
);
1207 test_cipher("cbc(twofish)", DECRYPT
, tf_cbc_dec_tv_template
,
1208 TF_CBC_DEC_TEST_VECTORS
);
1211 test_cipher("ecb(serpent)", ENCRYPT
, serpent_enc_tv_template
,
1212 SERPENT_ENC_TEST_VECTORS
);
1213 test_cipher("ecb(serpent)", DECRYPT
, serpent_dec_tv_template
,
1214 SERPENT_DEC_TEST_VECTORS
);
1217 test_cipher("ecb(tnepres)", ENCRYPT
, tnepres_enc_tv_template
,
1218 TNEPRES_ENC_TEST_VECTORS
);
1219 test_cipher("ecb(tnepres)", DECRYPT
, tnepres_dec_tv_template
,
1220 TNEPRES_DEC_TEST_VECTORS
);
1223 test_cipher("ecb(aes)", ENCRYPT
, aes_enc_tv_template
,
1224 AES_ENC_TEST_VECTORS
);
1225 test_cipher("ecb(aes)", DECRYPT
, aes_dec_tv_template
,
1226 AES_DEC_TEST_VECTORS
);
1227 test_cipher("cbc(aes)", ENCRYPT
, aes_cbc_enc_tv_template
,
1228 AES_CBC_ENC_TEST_VECTORS
);
1229 test_cipher("cbc(aes)", DECRYPT
, aes_cbc_dec_tv_template
,
1230 AES_CBC_DEC_TEST_VECTORS
);
1231 test_cipher("lrw(aes)", ENCRYPT
, aes_lrw_enc_tv_template
,
1232 AES_LRW_ENC_TEST_VECTORS
);
1233 test_cipher("lrw(aes)", DECRYPT
, aes_lrw_dec_tv_template
,
1234 AES_LRW_DEC_TEST_VECTORS
);
1235 test_cipher("xts(aes)", ENCRYPT
, aes_xts_enc_tv_template
,
1236 AES_XTS_ENC_TEST_VECTORS
);
1237 test_cipher("xts(aes)", DECRYPT
, aes_xts_dec_tv_template
,
1238 AES_XTS_DEC_TEST_VECTORS
);
1239 test_cipher("rfc3686(ctr(aes))", ENCRYPT
, aes_ctr_enc_tv_template
,
1240 AES_CTR_ENC_TEST_VECTORS
);
1241 test_cipher("rfc3686(ctr(aes))", DECRYPT
, aes_ctr_dec_tv_template
,
1242 AES_CTR_DEC_TEST_VECTORS
);
1243 test_aead("gcm(aes)", ENCRYPT
, aes_gcm_enc_tv_template
,
1244 AES_GCM_ENC_TEST_VECTORS
);
1245 test_aead("gcm(aes)", DECRYPT
, aes_gcm_dec_tv_template
,
1246 AES_GCM_DEC_TEST_VECTORS
);
1247 test_aead("ccm(aes)", ENCRYPT
, aes_ccm_enc_tv_template
,
1248 AES_CCM_ENC_TEST_VECTORS
);
1249 test_aead("ccm(aes)", DECRYPT
, aes_ccm_dec_tv_template
,
1250 AES_CCM_DEC_TEST_VECTORS
);
1253 test_cipher("ecb(cast5)", ENCRYPT
, cast5_enc_tv_template
,
1254 CAST5_ENC_TEST_VECTORS
);
1255 test_cipher("ecb(cast5)", DECRYPT
, cast5_dec_tv_template
,
1256 CAST5_DEC_TEST_VECTORS
);
1259 test_cipher("ecb(cast6)", ENCRYPT
, cast6_enc_tv_template
,
1260 CAST6_ENC_TEST_VECTORS
);
1261 test_cipher("ecb(cast6)", DECRYPT
, cast6_dec_tv_template
,
1262 CAST6_DEC_TEST_VECTORS
);
1265 test_cipher("ecb(arc4)", ENCRYPT
, arc4_enc_tv_template
,
1266 ARC4_ENC_TEST_VECTORS
);
1267 test_cipher("ecb(arc4)", DECRYPT
, arc4_dec_tv_template
,
1268 ARC4_DEC_TEST_VECTORS
);
1271 test_cipher("ecb(tea)", ENCRYPT
, tea_enc_tv_template
,
1272 TEA_ENC_TEST_VECTORS
);
1273 test_cipher("ecb(tea)", DECRYPT
, tea_dec_tv_template
,
1274 TEA_DEC_TEST_VECTORS
);
1278 test_cipher("ecb(xtea)", ENCRYPT
, xtea_enc_tv_template
,
1279 XTEA_ENC_TEST_VECTORS
);
1280 test_cipher("ecb(xtea)", DECRYPT
, xtea_dec_tv_template
,
1281 XTEA_DEC_TEST_VECTORS
);
1284 test_cipher("ecb(khazad)", ENCRYPT
, khazad_enc_tv_template
,
1285 KHAZAD_ENC_TEST_VECTORS
);
1286 test_cipher("ecb(khazad)", DECRYPT
, khazad_dec_tv_template
,
1287 KHAZAD_DEC_TEST_VECTORS
);
1290 test_cipher("ecb(anubis)", ENCRYPT
, anubis_enc_tv_template
,
1291 ANUBIS_ENC_TEST_VECTORS
);
1292 test_cipher("ecb(anubis)", DECRYPT
, anubis_dec_tv_template
,
1293 ANUBIS_DEC_TEST_VECTORS
);
1294 test_cipher("cbc(anubis)", ENCRYPT
, anubis_cbc_enc_tv_template
,
1295 ANUBIS_CBC_ENC_TEST_VECTORS
);
1296 test_cipher("cbc(anubis)", DECRYPT
, anubis_cbc_dec_tv_template
,
1297 ANUBIS_CBC_ENC_TEST_VECTORS
);
1300 test_cipher("ecb(xeta)", ENCRYPT
, xeta_enc_tv_template
,
1301 XETA_ENC_TEST_VECTORS
);
1302 test_cipher("ecb(xeta)", DECRYPT
, xeta_dec_tv_template
,
1303 XETA_DEC_TEST_VECTORS
);
1306 test_cipher("pcbc(fcrypt)", ENCRYPT
, fcrypt_pcbc_enc_tv_template
,
1307 FCRYPT_ENC_TEST_VECTORS
);
1308 test_cipher("pcbc(fcrypt)", DECRYPT
, fcrypt_pcbc_dec_tv_template
,
1309 FCRYPT_DEC_TEST_VECTORS
);
1312 test_cipher("ecb(camellia)", ENCRYPT
,
1313 camellia_enc_tv_template
,
1314 CAMELLIA_ENC_TEST_VECTORS
);
1315 test_cipher("ecb(camellia)", DECRYPT
,
1316 camellia_dec_tv_template
,
1317 CAMELLIA_DEC_TEST_VECTORS
);
1318 test_cipher("cbc(camellia)", ENCRYPT
,
1319 camellia_cbc_enc_tv_template
,
1320 CAMELLIA_CBC_ENC_TEST_VECTORS
);
1321 test_cipher("cbc(camellia)", DECRYPT
,
1322 camellia_cbc_dec_tv_template
,
1323 CAMELLIA_CBC_DEC_TEST_VECTORS
);
1326 test_cipher("ecb(seed)", ENCRYPT
, seed_enc_tv_template
,
1327 SEED_ENC_TEST_VECTORS
);
1328 test_cipher("ecb(seed)", DECRYPT
, seed_dec_tv_template
,
1329 SEED_DEC_TEST_VECTORS
);
1332 test_cipher("cts(cbc(aes))", ENCRYPT
, cts_mode_enc_tv_template
,
1333 CTS_MODE_ENC_TEST_VECTORS
);
1334 test_cipher("cts(cbc(aes))", DECRYPT
, cts_mode_dec_tv_template
,
1335 CTS_MODE_DEC_TEST_VECTORS
);
1337 test_hash("sha384", sha384_tv_template
, SHA384_TEST_VECTORS
);
1338 test_hash("sha512", sha512_tv_template
, SHA512_TEST_VECTORS
);
1339 test_hash("wp512", wp512_tv_template
, WP512_TEST_VECTORS
);
1340 test_hash("wp384", wp384_tv_template
, WP384_TEST_VECTORS
);
1341 test_hash("wp256", wp256_tv_template
, WP256_TEST_VECTORS
);
1342 test_hash("tgr192", tgr192_tv_template
, TGR192_TEST_VECTORS
);
1343 test_hash("tgr160", tgr160_tv_template
, TGR160_TEST_VECTORS
);
1344 test_hash("tgr128", tgr128_tv_template
, TGR128_TEST_VECTORS
);
1345 test_comp("deflate", deflate_comp_tv_template
,
1346 deflate_decomp_tv_template
, DEFLATE_COMP_TEST_VECTORS
,
1347 DEFLATE_DECOMP_TEST_VECTORS
);
1348 test_comp("lzo", lzo_comp_tv_template
, lzo_decomp_tv_template
,
1349 LZO_COMP_TEST_VECTORS
, LZO_DECOMP_TEST_VECTORS
);
1350 test_hash("crc32c", crc32c_tv_template
, CRC32C_TEST_VECTORS
);
1351 test_hash("hmac(md5)", hmac_md5_tv_template
,
1352 HMAC_MD5_TEST_VECTORS
);
1353 test_hash("hmac(sha1)", hmac_sha1_tv_template
,
1354 HMAC_SHA1_TEST_VECTORS
);
1355 test_hash("hmac(sha224)", hmac_sha224_tv_template
,
1356 HMAC_SHA224_TEST_VECTORS
);
1357 test_hash("hmac(sha256)", hmac_sha256_tv_template
,
1358 HMAC_SHA256_TEST_VECTORS
);
1359 test_hash("hmac(sha384)", hmac_sha384_tv_template
,
1360 HMAC_SHA384_TEST_VECTORS
);
1361 test_hash("hmac(sha512)", hmac_sha512_tv_template
,
1362 HMAC_SHA512_TEST_VECTORS
);
1364 test_hash("xcbc(aes)", aes_xcbc128_tv_template
,
1365 XCBC_AES_TEST_VECTORS
);
1367 test_hash("michael_mic", michael_mic_tv_template
, MICHAEL_MIC_TEST_VECTORS
);
1371 test_hash("md5", md5_tv_template
, MD5_TEST_VECTORS
);
1375 test_hash("sha1", sha1_tv_template
, SHA1_TEST_VECTORS
);
1379 test_cipher("ecb(des)", ENCRYPT
, des_enc_tv_template
,
1380 DES_ENC_TEST_VECTORS
);
1381 test_cipher("ecb(des)", DECRYPT
, des_dec_tv_template
,
1382 DES_DEC_TEST_VECTORS
);
1383 test_cipher("cbc(des)", ENCRYPT
, des_cbc_enc_tv_template
,
1384 DES_CBC_ENC_TEST_VECTORS
);
1385 test_cipher("cbc(des)", DECRYPT
, des_cbc_dec_tv_template
,
1386 DES_CBC_DEC_TEST_VECTORS
);
1390 test_cipher("ecb(des3_ede)", ENCRYPT
, des3_ede_enc_tv_template
,
1391 DES3_EDE_ENC_TEST_VECTORS
);
1392 test_cipher("ecb(des3_ede)", DECRYPT
, des3_ede_dec_tv_template
,
1393 DES3_EDE_DEC_TEST_VECTORS
);
1397 test_hash("md4", md4_tv_template
, MD4_TEST_VECTORS
);
1401 test_hash("sha256", sha256_tv_template
, SHA256_TEST_VECTORS
);
1405 test_cipher("ecb(blowfish)", ENCRYPT
, bf_enc_tv_template
,
1406 BF_ENC_TEST_VECTORS
);
1407 test_cipher("ecb(blowfish)", DECRYPT
, bf_dec_tv_template
,
1408 BF_DEC_TEST_VECTORS
);
1409 test_cipher("cbc(blowfish)", ENCRYPT
, bf_cbc_enc_tv_template
,
1410 BF_CBC_ENC_TEST_VECTORS
);
1411 test_cipher("cbc(blowfish)", DECRYPT
, bf_cbc_dec_tv_template
,
1412 BF_CBC_DEC_TEST_VECTORS
);
1416 test_cipher("ecb(twofish)", ENCRYPT
, tf_enc_tv_template
,
1417 TF_ENC_TEST_VECTORS
);
1418 test_cipher("ecb(twofish)", DECRYPT
, tf_dec_tv_template
,
1419 TF_DEC_TEST_VECTORS
);
1420 test_cipher("cbc(twofish)", ENCRYPT
, tf_cbc_enc_tv_template
,
1421 TF_CBC_ENC_TEST_VECTORS
);
1422 test_cipher("cbc(twofish)", DECRYPT
, tf_cbc_dec_tv_template
,
1423 TF_CBC_DEC_TEST_VECTORS
);
1427 test_cipher("ecb(serpent)", ENCRYPT
, serpent_enc_tv_template
,
1428 SERPENT_ENC_TEST_VECTORS
);
1429 test_cipher("ecb(serpent)", DECRYPT
, serpent_dec_tv_template
,
1430 SERPENT_DEC_TEST_VECTORS
);
1434 test_cipher("ecb(aes)", ENCRYPT
, aes_enc_tv_template
,
1435 AES_ENC_TEST_VECTORS
);
1436 test_cipher("ecb(aes)", DECRYPT
, aes_dec_tv_template
,
1437 AES_DEC_TEST_VECTORS
);
1438 test_cipher("cbc(aes)", ENCRYPT
, aes_cbc_enc_tv_template
,
1439 AES_CBC_ENC_TEST_VECTORS
);
1440 test_cipher("cbc(aes)", DECRYPT
, aes_cbc_dec_tv_template
,
1441 AES_CBC_DEC_TEST_VECTORS
);
1442 test_cipher("lrw(aes)", ENCRYPT
, aes_lrw_enc_tv_template
,
1443 AES_LRW_ENC_TEST_VECTORS
);
1444 test_cipher("lrw(aes)", DECRYPT
, aes_lrw_dec_tv_template
,
1445 AES_LRW_DEC_TEST_VECTORS
);
1446 test_cipher("xts(aes)", ENCRYPT
, aes_xts_enc_tv_template
,
1447 AES_XTS_ENC_TEST_VECTORS
);
1448 test_cipher("xts(aes)", DECRYPT
, aes_xts_dec_tv_template
,
1449 AES_XTS_DEC_TEST_VECTORS
);
1450 test_cipher("rfc3686(ctr(aes))", ENCRYPT
, aes_ctr_enc_tv_template
,
1451 AES_CTR_ENC_TEST_VECTORS
);
1452 test_cipher("rfc3686(ctr(aes))", DECRYPT
, aes_ctr_dec_tv_template
,
1453 AES_CTR_DEC_TEST_VECTORS
);
1457 test_hash("sha384", sha384_tv_template
, SHA384_TEST_VECTORS
);
1461 test_hash("sha512", sha512_tv_template
, SHA512_TEST_VECTORS
);
1465 test_comp("deflate", deflate_comp_tv_template
,
1466 deflate_decomp_tv_template
, DEFLATE_COMP_TEST_VECTORS
,
1467 DEFLATE_DECOMP_TEST_VECTORS
);
1471 test_cipher("ecb(cast5)", ENCRYPT
, cast5_enc_tv_template
,
1472 CAST5_ENC_TEST_VECTORS
);
1473 test_cipher("ecb(cast5)", DECRYPT
, cast5_dec_tv_template
,
1474 CAST5_DEC_TEST_VECTORS
);
1478 test_cipher("ecb(cast6)", ENCRYPT
, cast6_enc_tv_template
,
1479 CAST6_ENC_TEST_VECTORS
);
1480 test_cipher("ecb(cast6)", DECRYPT
, cast6_dec_tv_template
,
1481 CAST6_DEC_TEST_VECTORS
);
1485 test_cipher("ecb(arc4)", ENCRYPT
, arc4_enc_tv_template
,
1486 ARC4_ENC_TEST_VECTORS
);
1487 test_cipher("ecb(arc4)", DECRYPT
, arc4_dec_tv_template
,
1488 ARC4_DEC_TEST_VECTORS
);
1492 test_hash("michael_mic", michael_mic_tv_template
, MICHAEL_MIC_TEST_VECTORS
);
1496 test_hash("crc32c", crc32c_tv_template
, CRC32C_TEST_VECTORS
);
1500 test_cipher("ecb(tea)", ENCRYPT
, tea_enc_tv_template
,
1501 TEA_ENC_TEST_VECTORS
);
1502 test_cipher("ecb(tea)", DECRYPT
, tea_dec_tv_template
,
1503 TEA_DEC_TEST_VECTORS
);
1507 test_cipher("ecb(xtea)", ENCRYPT
, xtea_enc_tv_template
,
1508 XTEA_ENC_TEST_VECTORS
);
1509 test_cipher("ecb(xtea)", DECRYPT
, xtea_dec_tv_template
,
1510 XTEA_DEC_TEST_VECTORS
);
1514 test_cipher("ecb(khazad)", ENCRYPT
, khazad_enc_tv_template
,
1515 KHAZAD_ENC_TEST_VECTORS
);
1516 test_cipher("ecb(khazad)", DECRYPT
, khazad_dec_tv_template
,
1517 KHAZAD_DEC_TEST_VECTORS
);
1521 test_hash("wp512", wp512_tv_template
, WP512_TEST_VECTORS
);
1525 test_hash("wp384", wp384_tv_template
, WP384_TEST_VECTORS
);
1529 test_hash("wp256", wp256_tv_template
, WP256_TEST_VECTORS
);
1533 test_cipher("ecb(tnepres)", ENCRYPT
, tnepres_enc_tv_template
,
1534 TNEPRES_ENC_TEST_VECTORS
);
1535 test_cipher("ecb(tnepres)", DECRYPT
, tnepres_dec_tv_template
,
1536 TNEPRES_DEC_TEST_VECTORS
);
1540 test_cipher("ecb(anubis)", ENCRYPT
, anubis_enc_tv_template
,
1541 ANUBIS_ENC_TEST_VECTORS
);
1542 test_cipher("ecb(anubis)", DECRYPT
, anubis_dec_tv_template
,
1543 ANUBIS_DEC_TEST_VECTORS
);
1544 test_cipher("cbc(anubis)", ENCRYPT
, anubis_cbc_enc_tv_template
,
1545 ANUBIS_CBC_ENC_TEST_VECTORS
);
1546 test_cipher("cbc(anubis)", DECRYPT
, anubis_cbc_dec_tv_template
,
1547 ANUBIS_CBC_ENC_TEST_VECTORS
);
1551 test_hash("tgr192", tgr192_tv_template
, TGR192_TEST_VECTORS
);
1556 test_hash("tgr160", tgr160_tv_template
, TGR160_TEST_VECTORS
);
1560 test_hash("tgr128", tgr128_tv_template
, TGR128_TEST_VECTORS
);
1564 test_cipher("ecb(xeta)", ENCRYPT
, xeta_enc_tv_template
,
1565 XETA_ENC_TEST_VECTORS
);
1566 test_cipher("ecb(xeta)", DECRYPT
, xeta_dec_tv_template
,
1567 XETA_DEC_TEST_VECTORS
);
1571 test_cipher("pcbc(fcrypt)", ENCRYPT
, fcrypt_pcbc_enc_tv_template
,
1572 FCRYPT_ENC_TEST_VECTORS
);
1573 test_cipher("pcbc(fcrypt)", DECRYPT
, fcrypt_pcbc_dec_tv_template
,
1574 FCRYPT_DEC_TEST_VECTORS
);
1578 test_cipher("ecb(camellia)", ENCRYPT
,
1579 camellia_enc_tv_template
,
1580 CAMELLIA_ENC_TEST_VECTORS
);
1581 test_cipher("ecb(camellia)", DECRYPT
,
1582 camellia_dec_tv_template
,
1583 CAMELLIA_DEC_TEST_VECTORS
);
1584 test_cipher("cbc(camellia)", ENCRYPT
,
1585 camellia_cbc_enc_tv_template
,
1586 CAMELLIA_CBC_ENC_TEST_VECTORS
);
1587 test_cipher("cbc(camellia)", DECRYPT
,
1588 camellia_cbc_dec_tv_template
,
1589 CAMELLIA_CBC_DEC_TEST_VECTORS
);
1592 test_hash("sha224", sha224_tv_template
, SHA224_TEST_VECTORS
);
1596 test_cipher("salsa20", ENCRYPT
,
1597 salsa20_stream_enc_tv_template
,
1598 SALSA20_STREAM_ENC_TEST_VECTORS
);
1602 test_aead("gcm(aes)", ENCRYPT
, aes_gcm_enc_tv_template
,
1603 AES_GCM_ENC_TEST_VECTORS
);
1604 test_aead("gcm(aes)", DECRYPT
, aes_gcm_dec_tv_template
,
1605 AES_GCM_DEC_TEST_VECTORS
);
1609 test_comp("lzo", lzo_comp_tv_template
, lzo_decomp_tv_template
,
1610 LZO_COMP_TEST_VECTORS
, LZO_DECOMP_TEST_VECTORS
);
1614 test_aead("ccm(aes)", ENCRYPT
, aes_ccm_enc_tv_template
,
1615 AES_CCM_ENC_TEST_VECTORS
);
1616 test_aead("ccm(aes)", DECRYPT
, aes_ccm_dec_tv_template
,
1617 AES_CCM_DEC_TEST_VECTORS
);
1621 test_cipher("cts(cbc(aes))", ENCRYPT
, cts_mode_enc_tv_template
,
1622 CTS_MODE_ENC_TEST_VECTORS
);
1623 test_cipher("cts(cbc(aes))", DECRYPT
, cts_mode_dec_tv_template
,
1624 CTS_MODE_DEC_TEST_VECTORS
);
1628 test_hash("rmd128", rmd128_tv_template
, RMD128_TEST_VECTORS
);
1632 test_hash("rmd160", rmd160_tv_template
, RMD160_TEST_VECTORS
);
1636 test_hash("hmac(md5)", hmac_md5_tv_template
,
1637 HMAC_MD5_TEST_VECTORS
);
1641 test_hash("hmac(sha1)", hmac_sha1_tv_template
,
1642 HMAC_SHA1_TEST_VECTORS
);
1646 test_hash("hmac(sha256)", hmac_sha256_tv_template
,
1647 HMAC_SHA256_TEST_VECTORS
);
1651 test_hash("hmac(sha384)", hmac_sha384_tv_template
,
1652 HMAC_SHA384_TEST_VECTORS
);
1656 test_hash("hmac(sha512)", hmac_sha512_tv_template
,
1657 HMAC_SHA512_TEST_VECTORS
);
1661 test_hash("hmac(sha224)", hmac_sha224_tv_template
,
1662 HMAC_SHA224_TEST_VECTORS
);
1666 test_hash("xcbc(aes)", aes_xcbc128_tv_template
,
1667 XCBC_AES_TEST_VECTORS
);
1671 test_hash("hmac(rmd128)", hmac_rmd128_tv_template
,
1672 HMAC_RMD128_TEST_VECTORS
);
1676 test_hash("hmac(rmd160)", hmac_rmd160_tv_template
,
1677 HMAC_RMD160_TEST_VECTORS
);
1681 test_cipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1682 speed_template_16_24_32
);
1683 test_cipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1684 speed_template_16_24_32
);
1685 test_cipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1686 speed_template_16_24_32
);
1687 test_cipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1688 speed_template_16_24_32
);
1689 test_cipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1690 speed_template_32_40_48
);
1691 test_cipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1692 speed_template_32_40_48
);
1693 test_cipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1694 speed_template_32_48_64
);
1695 test_cipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1696 speed_template_32_48_64
);
1700 test_cipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1701 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1703 test_cipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1704 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1706 test_cipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1707 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1709 test_cipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1710 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1715 test_cipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1716 speed_template_16_24_32
);
1717 test_cipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1718 speed_template_16_24_32
);
1719 test_cipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1720 speed_template_16_24_32
);
1721 test_cipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1722 speed_template_16_24_32
);
1726 test_cipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1727 speed_template_8_32
);
1728 test_cipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
1729 speed_template_8_32
);
1730 test_cipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1731 speed_template_8_32
);
1732 test_cipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
1733 speed_template_8_32
);
1737 test_cipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1739 test_cipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1741 test_cipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1743 test_cipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1748 test_cipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
1749 speed_template_16_24_32
);
1750 test_cipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
1751 speed_template_16_24_32
);
1752 test_cipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
1753 speed_template_16_24_32
);
1754 test_cipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
1755 speed_template_16_24_32
);
1759 test_cipher_speed("salsa20", ENCRYPT
, sec
, NULL
, 0,
1760 speed_template_16_32
);
1767 test_hash_speed("md4", sec
, generic_hash_speed_template
);
1768 if (mode
> 300 && mode
< 400) break;
1771 test_hash_speed("md5", sec
, generic_hash_speed_template
);
1772 if (mode
> 300 && mode
< 400) break;
1775 test_hash_speed("sha1", sec
, generic_hash_speed_template
);
1776 if (mode
> 300 && mode
< 400) break;
1779 test_hash_speed("sha256", sec
, generic_hash_speed_template
);
1780 if (mode
> 300 && mode
< 400) break;
1783 test_hash_speed("sha384", sec
, generic_hash_speed_template
);
1784 if (mode
> 300 && mode
< 400) break;
1787 test_hash_speed("sha512", sec
, generic_hash_speed_template
);
1788 if (mode
> 300 && mode
< 400) break;
1791 test_hash_speed("wp256", sec
, generic_hash_speed_template
);
1792 if (mode
> 300 && mode
< 400) break;
1795 test_hash_speed("wp384", sec
, generic_hash_speed_template
);
1796 if (mode
> 300 && mode
< 400) break;
1799 test_hash_speed("wp512", sec
, generic_hash_speed_template
);
1800 if (mode
> 300 && mode
< 400) break;
1803 test_hash_speed("tgr128", sec
, generic_hash_speed_template
);
1804 if (mode
> 300 && mode
< 400) break;
1807 test_hash_speed("tgr160", sec
, generic_hash_speed_template
);
1808 if (mode
> 300 && mode
< 400) break;
1811 test_hash_speed("tgr192", sec
, generic_hash_speed_template
);
1812 if (mode
> 300 && mode
< 400) break;
1815 test_hash_speed("sha224", sec
, generic_hash_speed_template
);
1816 if (mode
> 300 && mode
< 400) break;
1819 test_hash_speed("rmd128", sec
, generic_hash_speed_template
);
1820 if (mode
> 300 && mode
< 400) break;
1823 test_hash_speed("rmd160", sec
, generic_hash_speed_template
);
1824 if (mode
> 300 && mode
< 400) break;
1834 /* useful for debugging */
1835 printk("not testing anything\n");
1840 static int __init
tcrypt_mod_init(void)
1844 tvmem
= kmalloc(TVMEMSIZE
, GFP_KERNEL
);
1848 xbuf
= kmalloc(XBUFSIZE
, GFP_KERNEL
);
1852 axbuf
= kmalloc(XBUFSIZE
, GFP_KERNEL
);
1858 /* We intentionaly return -EAGAIN to prevent keeping
1859 * the module. It does all its work from init()
1860 * and doesn't offer any runtime functionality
1861 * => we don't need it in the memory, do we?
1876 * If an init function is provided, an exit function must also be provided
1877 * to allow module unload.
1879 static void __exit
tcrypt_mod_fini(void) { }
1881 module_init(tcrypt_mod_init
);
1882 module_exit(tcrypt_mod_fini
);
1884 module_param(mode
, int, 0);
1885 module_param(sec
, uint
, 0);
1886 MODULE_PARM_DESC(sec
, "Length in seconds of speed tests "
1887 "(defaults to zero which uses CPU cycles instead)");
1889 MODULE_LICENSE("GPL");
1890 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1891 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");