2 * Quick & dirty crypto testing module.
4 * This will only exist until we have a better testing mechanism
5 * (e.g. a char device).
7 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
8 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
9 * Copyright (c) 2007 Nokia Siemens Networks
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License, or (at your option)
16 * 2007-11-13 Added GCM tests
17 * 2007-11-13 Added AEAD support
18 * 2007-11-06 Added SHA-224 and SHA-224-HMAC tests
19 * 2006-12-07 Added SHA384 HMAC and SHA512 HMAC tests
20 * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>)
21 * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt
25 #include <linux/err.h>
26 #include <linux/init.h>
27 #include <linux/module.h>
29 #include <linux/slab.h>
30 #include <linux/scatterlist.h>
31 #include <linux/string.h>
32 #include <linux/crypto.h>
33 #include <linux/highmem.h>
34 #include <linux/moduleparam.h>
35 #include <linux/jiffies.h>
36 #include <linux/timex.h>
37 #include <linux/interrupt.h>
41 * Need to kmalloc() memory for testing kmap().
43 #define TVMEMSIZE 16384
44 #define XBUFSIZE 32768
47 * Indexes into the xbuf to simulate cross-page access.
59 * Used by test_cipher()
64 struct tcrypt_result
{
65 struct completion completion
;
69 static unsigned int IDX
[8] = { IDX1
, IDX2
, IDX3
, IDX4
, IDX5
, IDX6
, IDX7
, IDX8
};
72 * Used by test_cipher_speed()
74 static unsigned int sec
;
81 static char *check
[] = {
82 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
83 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
84 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
85 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
86 "camellia", "seed", "salsa20", "lzo", "cts", NULL
89 static void hexdump(unsigned char *buf
, unsigned int len
)
91 print_hex_dump(KERN_CONT
, "", DUMP_PREFIX_OFFSET
,
96 static void tcrypt_complete(struct crypto_async_request
*req
, int err
)
98 struct tcrypt_result
*res
= req
->data
;
100 if (err
== -EINPROGRESS
)
104 complete(&res
->completion
);
107 static void test_hash(char *algo
, struct hash_testvec
*template,
110 unsigned int i
, j
, k
, temp
;
111 struct scatterlist sg
[8];
113 struct crypto_hash
*tfm
;
114 struct hash_desc desc
;
118 printk("\ntesting %s\n", algo
);
120 tfm
= crypto_alloc_hash(algo
, 0, CRYPTO_ALG_ASYNC
);
122 printk("failed to load transform for %s: %ld\n", algo
,
130 for (i
= 0; i
< tcount
; i
++) {
131 printk("test %u:\n", i
+ 1);
132 memset(result
, 0, 64);
134 hash_buff
= kzalloc(template[i
].psize
, GFP_KERNEL
);
138 memcpy(hash_buff
, template[i
].plaintext
, template[i
].psize
);
139 sg_init_one(&sg
[0], hash_buff
, template[i
].psize
);
141 if (template[i
].ksize
) {
142 ret
= crypto_hash_setkey(tfm
, template[i
].key
,
145 printk("setkey() failed ret=%d\n", ret
);
151 ret
= crypto_hash_digest(&desc
, sg
, template[i
].psize
, result
);
153 printk("digest () failed ret=%d\n", ret
);
158 hexdump(result
, crypto_hash_digestsize(tfm
));
160 memcmp(result
, template[i
].digest
,
161 crypto_hash_digestsize(tfm
)) ?
166 printk("testing %s across pages\n", algo
);
168 /* setup the dummy buffer first */
169 memset(xbuf
, 0, XBUFSIZE
);
172 for (i
= 0; i
< tcount
; i
++) {
173 if (template[i
].np
) {
175 printk("test %u:\n", j
);
176 memset(result
, 0, 64);
179 sg_init_table(sg
, template[i
].np
);
180 for (k
= 0; k
< template[i
].np
; k
++) {
181 memcpy(&xbuf
[IDX
[k
]],
182 template[i
].plaintext
+ temp
,
184 temp
+= template[i
].tap
[k
];
185 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
189 if (template[i
].ksize
) {
190 ret
= crypto_hash_setkey(tfm
, template[i
].key
,
194 printk("setkey() failed ret=%d\n", ret
);
199 ret
= crypto_hash_digest(&desc
, sg
, template[i
].psize
,
202 printk("digest () failed ret=%d\n", ret
);
206 hexdump(result
, crypto_hash_digestsize(tfm
));
208 memcmp(result
, template[i
].digest
,
209 crypto_hash_digestsize(tfm
)) ?
215 crypto_free_hash(tfm
);
218 static void test_aead(char *algo
, int enc
, struct aead_testvec
*template,
221 unsigned int ret
, i
, j
, k
, temp
;
223 struct crypto_aead
*tfm
;
225 struct aead_request
*req
;
226 struct scatterlist sg
[8];
227 struct scatterlist asg
[8];
229 struct tcrypt_result result
;
230 unsigned int authsize
;
240 printk(KERN_INFO
"\ntesting %s %s\n", algo
, e
);
242 init_completion(&result
.completion
);
244 tfm
= crypto_alloc_aead(algo
, 0, 0);
247 printk(KERN_INFO
"failed to load transform for %s: %ld\n",
252 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
254 printk(KERN_INFO
"failed to allocate request for %s\n", algo
);
258 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
259 tcrypt_complete
, &result
);
261 for (i
= 0, j
= 0; i
< tcount
; i
++) {
262 if (!template[i
].np
) {
263 printk(KERN_INFO
"test %u (%d bit key):\n",
264 ++j
, template[i
].klen
* 8);
266 /* some tepmplates have no input data but they will
269 input
= kzalloc(template[i
].ilen
+ template[i
].rlen
, GFP_KERNEL
);
273 assoc
= kzalloc(template[i
].alen
, GFP_KERNEL
);
279 memcpy(input
, template[i
].input
, template[i
].ilen
);
280 memcpy(assoc
, template[i
].assoc
, template[i
].alen
);
282 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
284 memset(iv
, 0, MAX_IVLEN
);
286 crypto_aead_clear_flags(tfm
, ~0);
288 crypto_aead_set_flags(
289 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
292 key
= template[i
].key
;
294 key
= kzalloc(template[i
].klen
, GFP_KERNEL
);
296 ret
= crypto_aead_setkey(tfm
, key
,
299 printk(KERN_INFO
"setkey() failed flags=%x\n",
300 crypto_aead_get_flags(tfm
));
302 if (!template[i
].fail
)
306 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
307 ret
= crypto_aead_setauthsize(tfm
, authsize
);
310 "failed to set authsize = %u\n",
315 sg_init_one(&sg
[0], input
,
316 template[i
].ilen
+ (enc
? authsize
: 0));
318 sg_init_one(&asg
[0], assoc
, template[i
].alen
);
320 aead_request_set_crypt(req
, sg
, sg
,
321 template[i
].ilen
, iv
);
323 aead_request_set_assoc(req
, asg
, template[i
].alen
);
326 crypto_aead_encrypt(req
) :
327 crypto_aead_decrypt(req
);
334 ret
= wait_for_completion_interruptible(
336 if (!ret
&& !(ret
= result
.err
)) {
337 INIT_COMPLETION(result
.completion
);
342 printk(KERN_INFO
"%s () failed err=%d\n",
347 q
= kmap(sg_page(&sg
[0])) + sg
[0].offset
;
348 hexdump(q
, template[i
].rlen
);
350 printk(KERN_INFO
"enc/dec: %s\n",
351 memcmp(q
, template[i
].result
,
352 template[i
].rlen
) ? "fail" : "pass");
353 kunmap(sg_page(&sg
[0]));
355 if (!template[i
].key
)
362 printk(KERN_INFO
"\ntesting %s %s across pages (chunking)\n", algo
, e
);
363 memset(xbuf
, 0, XBUFSIZE
);
364 memset(axbuf
, 0, XBUFSIZE
);
366 for (i
= 0, j
= 0; i
< tcount
; i
++) {
367 if (template[i
].np
) {
368 printk(KERN_INFO
"test %u (%d bit key):\n",
369 ++j
, template[i
].klen
* 8);
372 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
374 memset(iv
, 0, MAX_IVLEN
);
376 crypto_aead_clear_flags(tfm
, ~0);
378 crypto_aead_set_flags(
379 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
380 key
= template[i
].key
;
382 ret
= crypto_aead_setkey(tfm
, key
, template[i
].klen
);
384 printk(KERN_INFO
"setkey() failed flags=%x\n",
385 crypto_aead_get_flags(tfm
));
387 if (!template[i
].fail
)
391 sg_init_table(sg
, template[i
].np
);
392 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
393 memcpy(&xbuf
[IDX
[k
]],
394 template[i
].input
+ temp
,
396 temp
+= template[i
].tap
[k
];
397 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
401 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
402 ret
= crypto_aead_setauthsize(tfm
, authsize
);
405 "failed to set authsize = %u\n",
411 sg
[k
- 1].length
+= authsize
;
413 sg_init_table(asg
, template[i
].anp
);
414 for (k
= 0, temp
= 0; k
< template[i
].anp
; k
++) {
415 memcpy(&axbuf
[IDX
[k
]],
416 template[i
].assoc
+ temp
,
417 template[i
].atap
[k
]);
418 temp
+= template[i
].atap
[k
];
419 sg_set_buf(&asg
[k
], &axbuf
[IDX
[k
]],
420 template[i
].atap
[k
]);
423 aead_request_set_crypt(req
, sg
, sg
,
427 aead_request_set_assoc(req
, asg
, template[i
].alen
);
430 crypto_aead_encrypt(req
) :
431 crypto_aead_decrypt(req
);
438 ret
= wait_for_completion_interruptible(
440 if (!ret
&& !(ret
= result
.err
)) {
441 INIT_COMPLETION(result
.completion
);
446 printk(KERN_INFO
"%s () failed err=%d\n",
451 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
452 printk(KERN_INFO
"page %u\n", k
);
453 q
= kmap(sg_page(&sg
[k
])) + sg
[k
].offset
;
454 hexdump(q
, template[i
].tap
[k
]);
455 printk(KERN_INFO
"%s\n",
456 memcmp(q
, template[i
].result
+ temp
,
458 (k
< template[i
].np
- 1 || enc
?
462 temp
+= template[i
].tap
[k
];
463 kunmap(sg_page(&sg
[k
]));
469 crypto_free_aead(tfm
);
470 aead_request_free(req
);
473 static void test_cipher(char *algo
, int enc
,
474 struct cipher_testvec
*template, unsigned int tcount
)
476 unsigned int ret
, i
, j
, k
, temp
;
478 struct crypto_ablkcipher
*tfm
;
479 struct ablkcipher_request
*req
;
480 struct scatterlist sg
[8];
482 struct tcrypt_result result
;
491 printk("\ntesting %s %s\n", algo
, e
);
493 init_completion(&result
.completion
);
494 tfm
= crypto_alloc_ablkcipher(algo
, 0, 0);
497 printk("failed to load transform for %s: %ld\n", algo
,
502 req
= ablkcipher_request_alloc(tfm
, GFP_KERNEL
);
504 printk("failed to allocate request for %s\n", algo
);
508 ablkcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
509 tcrypt_complete
, &result
);
512 for (i
= 0; i
< tcount
; i
++) {
514 data
= kzalloc(template[i
].ilen
, GFP_KERNEL
);
518 memcpy(data
, template[i
].input
, template[i
].ilen
);
520 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
522 memset(iv
, 0, MAX_IVLEN
);
524 if (!(template[i
].np
)) {
526 printk("test %u (%d bit key):\n",
527 j
, template[i
].klen
* 8);
529 crypto_ablkcipher_clear_flags(tfm
, ~0);
531 crypto_ablkcipher_set_flags(
532 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
534 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
537 printk("setkey() failed flags=%x\n",
538 crypto_ablkcipher_get_flags(tfm
));
540 if (!template[i
].fail
) {
546 sg_init_one(&sg
[0], data
, template[i
].ilen
);
548 ablkcipher_request_set_crypt(req
, sg
, sg
,
549 template[i
].ilen
, iv
);
551 crypto_ablkcipher_encrypt(req
) :
552 crypto_ablkcipher_decrypt(req
);
559 ret
= wait_for_completion_interruptible(
561 if (!ret
&& !((ret
= result
.err
))) {
562 INIT_COMPLETION(result
.completion
);
567 printk("%s () failed err=%d\n", e
, -ret
);
572 q
= kmap(sg_page(&sg
[0])) + sg
[0].offset
;
573 hexdump(q
, template[i
].rlen
);
576 memcmp(q
, template[i
].result
,
577 template[i
].rlen
) ? "fail" : "pass");
578 kunmap(sg_page(&sg
[0]));
583 printk("\ntesting %s %s across pages (chunking)\n", algo
, e
);
584 memset(xbuf
, 0, XBUFSIZE
);
587 for (i
= 0; i
< tcount
; i
++) {
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 crypto_ablkcipher_clear_flags(tfm
, ~0);
601 crypto_ablkcipher_set_flags(
602 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
604 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
607 printk("setkey() failed flags=%x\n",
608 crypto_ablkcipher_get_flags(tfm
));
610 if (!template[i
].fail
)
615 sg_init_table(sg
, template[i
].np
);
616 for (k
= 0; k
< template[i
].np
; k
++) {
617 memcpy(&xbuf
[IDX
[k
]],
618 template[i
].input
+ temp
,
620 temp
+= template[i
].tap
[k
];
621 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
625 ablkcipher_request_set_crypt(req
, sg
, sg
,
626 template[i
].ilen
, iv
);
629 crypto_ablkcipher_encrypt(req
) :
630 crypto_ablkcipher_decrypt(req
);
637 ret
= wait_for_completion_interruptible(
639 if (!ret
&& !((ret
= result
.err
))) {
640 INIT_COMPLETION(result
.completion
);
645 printk("%s () failed err=%d\n", e
, -ret
);
650 for (k
= 0; k
< template[i
].np
; k
++) {
651 printk("page %u\n", k
);
652 q
= kmap(sg_page(&sg
[k
])) + sg
[k
].offset
;
653 hexdump(q
, template[i
].tap
[k
]);
655 memcmp(q
, template[i
].result
+ temp
,
656 template[i
].tap
[k
]) ? "fail" :
658 temp
+= template[i
].tap
[k
];
659 kunmap(sg_page(&sg
[k
]));
664 crypto_free_ablkcipher(tfm
);
665 ablkcipher_request_free(req
);
668 static int test_cipher_jiffies(struct blkcipher_desc
*desc
, int enc
, char *p
,
671 struct scatterlist sg
[1];
672 unsigned long start
, end
;
676 sg_init_one(sg
, p
, blen
);
678 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
679 time_before(jiffies
, end
); bcount
++) {
681 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
683 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
689 printk("%d operations in %d seconds (%ld bytes)\n",
690 bcount
, sec
, (long)bcount
* blen
);
694 static int test_cipher_cycles(struct blkcipher_desc
*desc
, int enc
, char *p
,
697 struct scatterlist sg
[1];
698 unsigned long cycles
= 0;
702 sg_init_one(sg
, p
, blen
);
708 for (i
= 0; i
< 4; i
++) {
710 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
712 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
718 /* The real thing. */
719 for (i
= 0; i
< 8; i
++) {
722 start
= get_cycles();
724 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
726 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
732 cycles
+= end
- start
;
740 printk("1 operation in %lu cycles (%d bytes)\n",
741 (cycles
+ 4) / 8, blen
);
746 static u32 block_sizes
[] = { 16, 64, 256, 1024, 8192, 0 };
748 static void test_cipher_speed(char *algo
, int enc
, unsigned int sec
,
749 struct cipher_testvec
*template,
750 unsigned int tcount
, u8
*keysize
)
752 unsigned int ret
, i
, j
, iv_len
;
753 unsigned char *key
, *p
, iv
[128];
754 struct crypto_blkcipher
*tfm
;
755 struct blkcipher_desc desc
;
764 printk("\ntesting speed of %s %s\n", algo
, e
);
766 tfm
= crypto_alloc_blkcipher(algo
, 0, CRYPTO_ALG_ASYNC
);
769 printk("failed to load transform for %s: %ld\n", algo
,
779 b_size
= block_sizes
;
782 if ((*keysize
+ *b_size
) > TVMEMSIZE
) {
783 printk("template (%u) too big for tvmem (%u)\n",
784 *keysize
+ *b_size
, TVMEMSIZE
);
788 printk("test %u (%d bit key, %d byte blocks): ", i
,
789 *keysize
* 8, *b_size
);
791 memset(tvmem
, 0xff, *keysize
+ *b_size
);
793 /* set key, plain text and IV */
794 key
= (unsigned char *)tvmem
;
795 for (j
= 0; j
< tcount
; j
++) {
796 if (template[j
].klen
== *keysize
) {
797 key
= template[j
].key
;
801 p
= (unsigned char *)tvmem
+ *keysize
;
803 ret
= crypto_blkcipher_setkey(tfm
, key
, *keysize
);
805 printk("setkey() failed flags=%x\n",
806 crypto_blkcipher_get_flags(tfm
));
810 iv_len
= crypto_blkcipher_ivsize(tfm
);
812 memset(&iv
, 0xff, iv_len
);
813 crypto_blkcipher_set_iv(tfm
, iv
, iv_len
);
817 ret
= test_cipher_jiffies(&desc
, enc
, p
, *b_size
, sec
);
819 ret
= test_cipher_cycles(&desc
, enc
, p
, *b_size
);
822 printk("%s() failed flags=%x\n", e
, desc
.flags
);
832 crypto_free_blkcipher(tfm
);
835 static int test_hash_jiffies_digest(struct hash_desc
*desc
, char *p
, int blen
,
838 struct scatterlist sg
[1];
839 unsigned long start
, end
;
843 sg_init_table(sg
, 1);
845 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
846 time_before(jiffies
, end
); bcount
++) {
847 sg_set_buf(sg
, p
, blen
);
848 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
853 printk("%6u opers/sec, %9lu bytes/sec\n",
854 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
859 static int test_hash_jiffies(struct hash_desc
*desc
, char *p
, int blen
,
860 int plen
, char *out
, int sec
)
862 struct scatterlist sg
[1];
863 unsigned long start
, end
;
868 return test_hash_jiffies_digest(desc
, p
, blen
, out
, sec
);
870 sg_init_table(sg
, 1);
872 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
873 time_before(jiffies
, end
); bcount
++) {
874 ret
= crypto_hash_init(desc
);
877 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
878 sg_set_buf(sg
, p
+ pcount
, plen
);
879 ret
= crypto_hash_update(desc
, sg
, plen
);
883 /* we assume there is enough space in 'out' for the result */
884 ret
= crypto_hash_final(desc
, out
);
889 printk("%6u opers/sec, %9lu bytes/sec\n",
890 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
895 static int test_hash_cycles_digest(struct hash_desc
*desc
, char *p
, int blen
,
898 struct scatterlist sg
[1];
899 unsigned long cycles
= 0;
903 sg_init_table(sg
, 1);
909 for (i
= 0; i
< 4; i
++) {
910 sg_set_buf(sg
, p
, blen
);
911 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
916 /* The real thing. */
917 for (i
= 0; i
< 8; i
++) {
920 start
= get_cycles();
922 sg_set_buf(sg
, p
, blen
);
923 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
929 cycles
+= end
- start
;
939 printk("%6lu cycles/operation, %4lu cycles/byte\n",
940 cycles
/ 8, cycles
/ (8 * blen
));
945 static int test_hash_cycles(struct hash_desc
*desc
, char *p
, int blen
,
948 struct scatterlist sg
[1];
949 unsigned long cycles
= 0;
954 return test_hash_cycles_digest(desc
, p
, blen
, out
);
956 sg_init_table(sg
, 1);
962 for (i
= 0; i
< 4; i
++) {
963 ret
= crypto_hash_init(desc
);
966 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
967 sg_set_buf(sg
, p
+ pcount
, plen
);
968 ret
= crypto_hash_update(desc
, sg
, plen
);
972 ret
= crypto_hash_final(desc
, out
);
977 /* The real thing. */
978 for (i
= 0; i
< 8; i
++) {
981 start
= get_cycles();
983 ret
= crypto_hash_init(desc
);
986 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
987 sg_set_buf(sg
, p
+ pcount
, plen
);
988 ret
= crypto_hash_update(desc
, sg
, plen
);
992 ret
= crypto_hash_final(desc
, out
);
998 cycles
+= end
- start
;
1008 printk("%6lu cycles/operation, %4lu cycles/byte\n",
1009 cycles
/ 8, cycles
/ (8 * blen
));
1014 static void test_hash_speed(char *algo
, unsigned int sec
,
1015 struct hash_speed
*speed
)
1017 struct crypto_hash
*tfm
;
1018 struct hash_desc desc
;
1023 printk("\ntesting speed of %s\n", algo
);
1025 tfm
= crypto_alloc_hash(algo
, 0, CRYPTO_ALG_ASYNC
);
1028 printk("failed to load transform for %s: %ld\n", algo
,
1036 if (crypto_hash_digestsize(tfm
) > sizeof(output
)) {
1037 printk("digestsize(%u) > outputbuffer(%zu)\n",
1038 crypto_hash_digestsize(tfm
), sizeof(output
));
1042 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
1043 if (speed
[i
].blen
> TVMEMSIZE
) {
1044 printk("template (%u) too big for tvmem (%u)\n",
1045 speed
[i
].blen
, TVMEMSIZE
);
1049 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
1050 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
1052 memset(tvmem
, 0xff, speed
[i
].blen
);
1055 ret
= test_hash_jiffies(&desc
, tvmem
, speed
[i
].blen
,
1056 speed
[i
].plen
, output
, sec
);
1058 ret
= test_hash_cycles(&desc
, tvmem
, speed
[i
].blen
,
1059 speed
[i
].plen
, output
);
1062 printk("hashing failed ret=%d\n", ret
);
1068 crypto_free_hash(tfm
);
1071 static void test_comp(char *algo
, struct comp_testvec
*ctemplate
,
1072 struct comp_testvec
*dtemplate
, int ctcount
, int dtcount
)
1075 char result
[COMP_BUF_SIZE
];
1076 struct crypto_comp
*tfm
;
1079 printk("\ntesting %s compression\n", algo
);
1081 tfm
= crypto_alloc_comp(algo
, 0, CRYPTO_ALG_ASYNC
);
1083 printk("failed to load transform for %s\n", algo
);
1087 for (i
= 0; i
< ctcount
; i
++) {
1088 int ilen
, ret
, dlen
= COMP_BUF_SIZE
;
1090 printk("test %u:\n", i
+ 1);
1091 memset(result
, 0, sizeof (result
));
1093 ilen
= ctemplate
[i
].inlen
;
1094 ret
= crypto_comp_compress(tfm
, ctemplate
[i
].input
,
1095 ilen
, result
, &dlen
);
1097 printk("fail: ret=%d\n", ret
);
1100 hexdump(result
, dlen
);
1101 printk("%s (ratio %d:%d)\n",
1102 memcmp(result
, ctemplate
[i
].output
, dlen
) ? "fail" : "pass",
1106 printk("\ntesting %s decompression\n", algo
);
1108 tsize
= sizeof(struct comp_testvec
);
1110 if (tsize
> TVMEMSIZE
) {
1111 printk("template (%u) too big for tvmem (%u)\n", tsize
,
1116 for (i
= 0; i
< dtcount
; i
++) {
1117 int ilen
, ret
, dlen
= COMP_BUF_SIZE
;
1119 printk("test %u:\n", i
+ 1);
1120 memset(result
, 0, sizeof (result
));
1122 ilen
= dtemplate
[i
].inlen
;
1123 ret
= crypto_comp_decompress(tfm
, dtemplate
[i
].input
,
1124 ilen
, result
, &dlen
);
1126 printk("fail: ret=%d\n", ret
);
1129 hexdump(result
, dlen
);
1130 printk("%s (ratio %d:%d)\n",
1131 memcmp(result
, dtemplate
[i
].output
, dlen
) ? "fail" : "pass",
1135 crypto_free_comp(tfm
);
1138 static void test_available(void)
1140 char **name
= check
;
1143 printk("alg %s ", *name
);
1144 printk(crypto_has_alg(*name
, 0, 0) ?
1145 "found\n" : "not found\n");
1150 static void do_test(void)
1155 test_hash("md5", md5_tv_template
, MD5_TEST_VECTORS
);
1157 test_hash("sha1", sha1_tv_template
, SHA1_TEST_VECTORS
);
1160 test_cipher("ecb(des)", ENCRYPT
, des_enc_tv_template
,
1161 DES_ENC_TEST_VECTORS
);
1162 test_cipher("ecb(des)", DECRYPT
, des_dec_tv_template
,
1163 DES_DEC_TEST_VECTORS
);
1164 test_cipher("cbc(des)", ENCRYPT
, des_cbc_enc_tv_template
,
1165 DES_CBC_ENC_TEST_VECTORS
);
1166 test_cipher("cbc(des)", DECRYPT
, des_cbc_dec_tv_template
,
1167 DES_CBC_DEC_TEST_VECTORS
);
1170 test_cipher("ecb(des3_ede)", ENCRYPT
, des3_ede_enc_tv_template
,
1171 DES3_EDE_ENC_TEST_VECTORS
);
1172 test_cipher("ecb(des3_ede)", DECRYPT
, des3_ede_dec_tv_template
,
1173 DES3_EDE_DEC_TEST_VECTORS
);
1175 test_hash("md4", md4_tv_template
, MD4_TEST_VECTORS
);
1177 test_hash("sha224", sha224_tv_template
, SHA224_TEST_VECTORS
);
1179 test_hash("sha256", sha256_tv_template
, SHA256_TEST_VECTORS
);
1182 test_cipher("ecb(blowfish)", ENCRYPT
, bf_enc_tv_template
,
1183 BF_ENC_TEST_VECTORS
);
1184 test_cipher("ecb(blowfish)", DECRYPT
, bf_dec_tv_template
,
1185 BF_DEC_TEST_VECTORS
);
1186 test_cipher("cbc(blowfish)", ENCRYPT
, bf_cbc_enc_tv_template
,
1187 BF_CBC_ENC_TEST_VECTORS
);
1188 test_cipher("cbc(blowfish)", DECRYPT
, bf_cbc_dec_tv_template
,
1189 BF_CBC_DEC_TEST_VECTORS
);
1192 test_cipher("ecb(twofish)", ENCRYPT
, tf_enc_tv_template
,
1193 TF_ENC_TEST_VECTORS
);
1194 test_cipher("ecb(twofish)", DECRYPT
, tf_dec_tv_template
,
1195 TF_DEC_TEST_VECTORS
);
1196 test_cipher("cbc(twofish)", ENCRYPT
, tf_cbc_enc_tv_template
,
1197 TF_CBC_ENC_TEST_VECTORS
);
1198 test_cipher("cbc(twofish)", DECRYPT
, tf_cbc_dec_tv_template
,
1199 TF_CBC_DEC_TEST_VECTORS
);
1202 test_cipher("ecb(serpent)", ENCRYPT
, serpent_enc_tv_template
,
1203 SERPENT_ENC_TEST_VECTORS
);
1204 test_cipher("ecb(serpent)", DECRYPT
, serpent_dec_tv_template
,
1205 SERPENT_DEC_TEST_VECTORS
);
1208 test_cipher("ecb(tnepres)", ENCRYPT
, tnepres_enc_tv_template
,
1209 TNEPRES_ENC_TEST_VECTORS
);
1210 test_cipher("ecb(tnepres)", DECRYPT
, tnepres_dec_tv_template
,
1211 TNEPRES_DEC_TEST_VECTORS
);
1214 test_cipher("ecb(aes)", ENCRYPT
, aes_enc_tv_template
,
1215 AES_ENC_TEST_VECTORS
);
1216 test_cipher("ecb(aes)", DECRYPT
, aes_dec_tv_template
,
1217 AES_DEC_TEST_VECTORS
);
1218 test_cipher("cbc(aes)", ENCRYPT
, aes_cbc_enc_tv_template
,
1219 AES_CBC_ENC_TEST_VECTORS
);
1220 test_cipher("cbc(aes)", DECRYPT
, aes_cbc_dec_tv_template
,
1221 AES_CBC_DEC_TEST_VECTORS
);
1222 test_cipher("lrw(aes)", ENCRYPT
, aes_lrw_enc_tv_template
,
1223 AES_LRW_ENC_TEST_VECTORS
);
1224 test_cipher("lrw(aes)", DECRYPT
, aes_lrw_dec_tv_template
,
1225 AES_LRW_DEC_TEST_VECTORS
);
1226 test_cipher("xts(aes)", ENCRYPT
, aes_xts_enc_tv_template
,
1227 AES_XTS_ENC_TEST_VECTORS
);
1228 test_cipher("xts(aes)", DECRYPT
, aes_xts_dec_tv_template
,
1229 AES_XTS_DEC_TEST_VECTORS
);
1230 test_cipher("rfc3686(ctr(aes))", ENCRYPT
, aes_ctr_enc_tv_template
,
1231 AES_CTR_ENC_TEST_VECTORS
);
1232 test_cipher("rfc3686(ctr(aes))", DECRYPT
, aes_ctr_dec_tv_template
,
1233 AES_CTR_DEC_TEST_VECTORS
);
1234 test_aead("gcm(aes)", ENCRYPT
, aes_gcm_enc_tv_template
,
1235 AES_GCM_ENC_TEST_VECTORS
);
1236 test_aead("gcm(aes)", DECRYPT
, aes_gcm_dec_tv_template
,
1237 AES_GCM_DEC_TEST_VECTORS
);
1238 test_aead("ccm(aes)", ENCRYPT
, aes_ccm_enc_tv_template
,
1239 AES_CCM_ENC_TEST_VECTORS
);
1240 test_aead("ccm(aes)", DECRYPT
, aes_ccm_dec_tv_template
,
1241 AES_CCM_DEC_TEST_VECTORS
);
1244 test_cipher("ecb(cast5)", ENCRYPT
, cast5_enc_tv_template
,
1245 CAST5_ENC_TEST_VECTORS
);
1246 test_cipher("ecb(cast5)", DECRYPT
, cast5_dec_tv_template
,
1247 CAST5_DEC_TEST_VECTORS
);
1250 test_cipher("ecb(cast6)", ENCRYPT
, cast6_enc_tv_template
,
1251 CAST6_ENC_TEST_VECTORS
);
1252 test_cipher("ecb(cast6)", DECRYPT
, cast6_dec_tv_template
,
1253 CAST6_DEC_TEST_VECTORS
);
1256 test_cipher("ecb(arc4)", ENCRYPT
, arc4_enc_tv_template
,
1257 ARC4_ENC_TEST_VECTORS
);
1258 test_cipher("ecb(arc4)", DECRYPT
, arc4_dec_tv_template
,
1259 ARC4_DEC_TEST_VECTORS
);
1262 test_cipher("ecb(tea)", ENCRYPT
, tea_enc_tv_template
,
1263 TEA_ENC_TEST_VECTORS
);
1264 test_cipher("ecb(tea)", DECRYPT
, tea_dec_tv_template
,
1265 TEA_DEC_TEST_VECTORS
);
1269 test_cipher("ecb(xtea)", ENCRYPT
, xtea_enc_tv_template
,
1270 XTEA_ENC_TEST_VECTORS
);
1271 test_cipher("ecb(xtea)", DECRYPT
, xtea_dec_tv_template
,
1272 XTEA_DEC_TEST_VECTORS
);
1275 test_cipher("ecb(khazad)", ENCRYPT
, khazad_enc_tv_template
,
1276 KHAZAD_ENC_TEST_VECTORS
);
1277 test_cipher("ecb(khazad)", DECRYPT
, khazad_dec_tv_template
,
1278 KHAZAD_DEC_TEST_VECTORS
);
1281 test_cipher("ecb(anubis)", ENCRYPT
, anubis_enc_tv_template
,
1282 ANUBIS_ENC_TEST_VECTORS
);
1283 test_cipher("ecb(anubis)", DECRYPT
, anubis_dec_tv_template
,
1284 ANUBIS_DEC_TEST_VECTORS
);
1285 test_cipher("cbc(anubis)", ENCRYPT
, anubis_cbc_enc_tv_template
,
1286 ANUBIS_CBC_ENC_TEST_VECTORS
);
1287 test_cipher("cbc(anubis)", DECRYPT
, anubis_cbc_dec_tv_template
,
1288 ANUBIS_CBC_ENC_TEST_VECTORS
);
1291 test_cipher("ecb(xeta)", ENCRYPT
, xeta_enc_tv_template
,
1292 XETA_ENC_TEST_VECTORS
);
1293 test_cipher("ecb(xeta)", DECRYPT
, xeta_dec_tv_template
,
1294 XETA_DEC_TEST_VECTORS
);
1297 test_cipher("pcbc(fcrypt)", ENCRYPT
, fcrypt_pcbc_enc_tv_template
,
1298 FCRYPT_ENC_TEST_VECTORS
);
1299 test_cipher("pcbc(fcrypt)", DECRYPT
, fcrypt_pcbc_dec_tv_template
,
1300 FCRYPT_DEC_TEST_VECTORS
);
1303 test_cipher("ecb(camellia)", ENCRYPT
,
1304 camellia_enc_tv_template
,
1305 CAMELLIA_ENC_TEST_VECTORS
);
1306 test_cipher("ecb(camellia)", DECRYPT
,
1307 camellia_dec_tv_template
,
1308 CAMELLIA_DEC_TEST_VECTORS
);
1309 test_cipher("cbc(camellia)", ENCRYPT
,
1310 camellia_cbc_enc_tv_template
,
1311 CAMELLIA_CBC_ENC_TEST_VECTORS
);
1312 test_cipher("cbc(camellia)", DECRYPT
,
1313 camellia_cbc_dec_tv_template
,
1314 CAMELLIA_CBC_DEC_TEST_VECTORS
);
1317 test_cipher("ecb(seed)", ENCRYPT
, seed_enc_tv_template
,
1318 SEED_ENC_TEST_VECTORS
);
1319 test_cipher("ecb(seed)", DECRYPT
, seed_dec_tv_template
,
1320 SEED_DEC_TEST_VECTORS
);
1323 test_cipher("cts(cbc(aes))", ENCRYPT
, cts_mode_enc_tv_template
,
1324 CTS_MODE_ENC_TEST_VECTORS
);
1325 test_cipher("cts(cbc(aes))", DECRYPT
, cts_mode_dec_tv_template
,
1326 CTS_MODE_DEC_TEST_VECTORS
);
1328 test_hash("sha384", sha384_tv_template
, SHA384_TEST_VECTORS
);
1329 test_hash("sha512", sha512_tv_template
, SHA512_TEST_VECTORS
);
1330 test_hash("wp512", wp512_tv_template
, WP512_TEST_VECTORS
);
1331 test_hash("wp384", wp384_tv_template
, WP384_TEST_VECTORS
);
1332 test_hash("wp256", wp256_tv_template
, WP256_TEST_VECTORS
);
1333 test_hash("tgr192", tgr192_tv_template
, TGR192_TEST_VECTORS
);
1334 test_hash("tgr160", tgr160_tv_template
, TGR160_TEST_VECTORS
);
1335 test_hash("tgr128", tgr128_tv_template
, TGR128_TEST_VECTORS
);
1336 test_comp("deflate", deflate_comp_tv_template
,
1337 deflate_decomp_tv_template
, DEFLATE_COMP_TEST_VECTORS
,
1338 DEFLATE_DECOMP_TEST_VECTORS
);
1339 test_comp("lzo", lzo_comp_tv_template
, lzo_decomp_tv_template
,
1340 LZO_COMP_TEST_VECTORS
, LZO_DECOMP_TEST_VECTORS
);
1341 test_hash("crc32c", crc32c_tv_template
, CRC32C_TEST_VECTORS
);
1342 test_hash("hmac(md5)", hmac_md5_tv_template
,
1343 HMAC_MD5_TEST_VECTORS
);
1344 test_hash("hmac(sha1)", hmac_sha1_tv_template
,
1345 HMAC_SHA1_TEST_VECTORS
);
1346 test_hash("hmac(sha224)", hmac_sha224_tv_template
,
1347 HMAC_SHA224_TEST_VECTORS
);
1348 test_hash("hmac(sha256)", hmac_sha256_tv_template
,
1349 HMAC_SHA256_TEST_VECTORS
);
1350 test_hash("hmac(sha384)", hmac_sha384_tv_template
,
1351 HMAC_SHA384_TEST_VECTORS
);
1352 test_hash("hmac(sha512)", hmac_sha512_tv_template
,
1353 HMAC_SHA512_TEST_VECTORS
);
1355 test_hash("xcbc(aes)", aes_xcbc128_tv_template
,
1356 XCBC_AES_TEST_VECTORS
);
1358 test_hash("michael_mic", michael_mic_tv_template
, MICHAEL_MIC_TEST_VECTORS
);
1362 test_hash("md5", md5_tv_template
, MD5_TEST_VECTORS
);
1366 test_hash("sha1", sha1_tv_template
, SHA1_TEST_VECTORS
);
1370 test_cipher("ecb(des)", ENCRYPT
, des_enc_tv_template
,
1371 DES_ENC_TEST_VECTORS
);
1372 test_cipher("ecb(des)", DECRYPT
, des_dec_tv_template
,
1373 DES_DEC_TEST_VECTORS
);
1374 test_cipher("cbc(des)", ENCRYPT
, des_cbc_enc_tv_template
,
1375 DES_CBC_ENC_TEST_VECTORS
);
1376 test_cipher("cbc(des)", DECRYPT
, des_cbc_dec_tv_template
,
1377 DES_CBC_DEC_TEST_VECTORS
);
1381 test_cipher("ecb(des3_ede)", ENCRYPT
, des3_ede_enc_tv_template
,
1382 DES3_EDE_ENC_TEST_VECTORS
);
1383 test_cipher("ecb(des3_ede)", DECRYPT
, des3_ede_dec_tv_template
,
1384 DES3_EDE_DEC_TEST_VECTORS
);
1388 test_hash("md4", md4_tv_template
, MD4_TEST_VECTORS
);
1392 test_hash("sha256", sha256_tv_template
, SHA256_TEST_VECTORS
);
1396 test_cipher("ecb(blowfish)", ENCRYPT
, bf_enc_tv_template
,
1397 BF_ENC_TEST_VECTORS
);
1398 test_cipher("ecb(blowfish)", DECRYPT
, bf_dec_tv_template
,
1399 BF_DEC_TEST_VECTORS
);
1400 test_cipher("cbc(blowfish)", ENCRYPT
, bf_cbc_enc_tv_template
,
1401 BF_CBC_ENC_TEST_VECTORS
);
1402 test_cipher("cbc(blowfish)", DECRYPT
, bf_cbc_dec_tv_template
,
1403 BF_CBC_DEC_TEST_VECTORS
);
1407 test_cipher("ecb(twofish)", ENCRYPT
, tf_enc_tv_template
,
1408 TF_ENC_TEST_VECTORS
);
1409 test_cipher("ecb(twofish)", DECRYPT
, tf_dec_tv_template
,
1410 TF_DEC_TEST_VECTORS
);
1411 test_cipher("cbc(twofish)", ENCRYPT
, tf_cbc_enc_tv_template
,
1412 TF_CBC_ENC_TEST_VECTORS
);
1413 test_cipher("cbc(twofish)", DECRYPT
, tf_cbc_dec_tv_template
,
1414 TF_CBC_DEC_TEST_VECTORS
);
1418 test_cipher("ecb(serpent)", ENCRYPT
, serpent_enc_tv_template
,
1419 SERPENT_ENC_TEST_VECTORS
);
1420 test_cipher("ecb(serpent)", DECRYPT
, serpent_dec_tv_template
,
1421 SERPENT_DEC_TEST_VECTORS
);
1425 test_cipher("ecb(aes)", ENCRYPT
, aes_enc_tv_template
,
1426 AES_ENC_TEST_VECTORS
);
1427 test_cipher("ecb(aes)", DECRYPT
, aes_dec_tv_template
,
1428 AES_DEC_TEST_VECTORS
);
1429 test_cipher("cbc(aes)", ENCRYPT
, aes_cbc_enc_tv_template
,
1430 AES_CBC_ENC_TEST_VECTORS
);
1431 test_cipher("cbc(aes)", DECRYPT
, aes_cbc_dec_tv_template
,
1432 AES_CBC_DEC_TEST_VECTORS
);
1433 test_cipher("lrw(aes)", ENCRYPT
, aes_lrw_enc_tv_template
,
1434 AES_LRW_ENC_TEST_VECTORS
);
1435 test_cipher("lrw(aes)", DECRYPT
, aes_lrw_dec_tv_template
,
1436 AES_LRW_DEC_TEST_VECTORS
);
1437 test_cipher("xts(aes)", ENCRYPT
, aes_xts_enc_tv_template
,
1438 AES_XTS_ENC_TEST_VECTORS
);
1439 test_cipher("xts(aes)", DECRYPT
, aes_xts_dec_tv_template
,
1440 AES_XTS_DEC_TEST_VECTORS
);
1441 test_cipher("rfc3686(ctr(aes))", ENCRYPT
, aes_ctr_enc_tv_template
,
1442 AES_CTR_ENC_TEST_VECTORS
);
1443 test_cipher("rfc3686(ctr(aes))", DECRYPT
, aes_ctr_dec_tv_template
,
1444 AES_CTR_DEC_TEST_VECTORS
);
1448 test_hash("sha384", sha384_tv_template
, SHA384_TEST_VECTORS
);
1452 test_hash("sha512", sha512_tv_template
, SHA512_TEST_VECTORS
);
1456 test_comp("deflate", deflate_comp_tv_template
,
1457 deflate_decomp_tv_template
, DEFLATE_COMP_TEST_VECTORS
,
1458 DEFLATE_DECOMP_TEST_VECTORS
);
1462 test_cipher("ecb(cast5)", ENCRYPT
, cast5_enc_tv_template
,
1463 CAST5_ENC_TEST_VECTORS
);
1464 test_cipher("ecb(cast5)", DECRYPT
, cast5_dec_tv_template
,
1465 CAST5_DEC_TEST_VECTORS
);
1469 test_cipher("ecb(cast6)", ENCRYPT
, cast6_enc_tv_template
,
1470 CAST6_ENC_TEST_VECTORS
);
1471 test_cipher("ecb(cast6)", DECRYPT
, cast6_dec_tv_template
,
1472 CAST6_DEC_TEST_VECTORS
);
1476 test_cipher("ecb(arc4)", ENCRYPT
, arc4_enc_tv_template
,
1477 ARC4_ENC_TEST_VECTORS
);
1478 test_cipher("ecb(arc4)", DECRYPT
, arc4_dec_tv_template
,
1479 ARC4_DEC_TEST_VECTORS
);
1483 test_hash("michael_mic", michael_mic_tv_template
, MICHAEL_MIC_TEST_VECTORS
);
1487 test_hash("crc32c", crc32c_tv_template
, CRC32C_TEST_VECTORS
);
1491 test_cipher("ecb(tea)", ENCRYPT
, tea_enc_tv_template
,
1492 TEA_ENC_TEST_VECTORS
);
1493 test_cipher("ecb(tea)", DECRYPT
, tea_dec_tv_template
,
1494 TEA_DEC_TEST_VECTORS
);
1498 test_cipher("ecb(xtea)", ENCRYPT
, xtea_enc_tv_template
,
1499 XTEA_ENC_TEST_VECTORS
);
1500 test_cipher("ecb(xtea)", DECRYPT
, xtea_dec_tv_template
,
1501 XTEA_DEC_TEST_VECTORS
);
1505 test_cipher("ecb(khazad)", ENCRYPT
, khazad_enc_tv_template
,
1506 KHAZAD_ENC_TEST_VECTORS
);
1507 test_cipher("ecb(khazad)", DECRYPT
, khazad_dec_tv_template
,
1508 KHAZAD_DEC_TEST_VECTORS
);
1512 test_hash("wp512", wp512_tv_template
, WP512_TEST_VECTORS
);
1516 test_hash("wp384", wp384_tv_template
, WP384_TEST_VECTORS
);
1520 test_hash("wp256", wp256_tv_template
, WP256_TEST_VECTORS
);
1524 test_cipher("ecb(tnepres)", ENCRYPT
, tnepres_enc_tv_template
,
1525 TNEPRES_ENC_TEST_VECTORS
);
1526 test_cipher("ecb(tnepres)", DECRYPT
, tnepres_dec_tv_template
,
1527 TNEPRES_DEC_TEST_VECTORS
);
1531 test_cipher("ecb(anubis)", ENCRYPT
, anubis_enc_tv_template
,
1532 ANUBIS_ENC_TEST_VECTORS
);
1533 test_cipher("ecb(anubis)", DECRYPT
, anubis_dec_tv_template
,
1534 ANUBIS_DEC_TEST_VECTORS
);
1535 test_cipher("cbc(anubis)", ENCRYPT
, anubis_cbc_enc_tv_template
,
1536 ANUBIS_CBC_ENC_TEST_VECTORS
);
1537 test_cipher("cbc(anubis)", DECRYPT
, anubis_cbc_dec_tv_template
,
1538 ANUBIS_CBC_ENC_TEST_VECTORS
);
1542 test_hash("tgr192", tgr192_tv_template
, TGR192_TEST_VECTORS
);
1547 test_hash("tgr160", tgr160_tv_template
, TGR160_TEST_VECTORS
);
1551 test_hash("tgr128", tgr128_tv_template
, TGR128_TEST_VECTORS
);
1555 test_cipher("ecb(xeta)", ENCRYPT
, xeta_enc_tv_template
,
1556 XETA_ENC_TEST_VECTORS
);
1557 test_cipher("ecb(xeta)", DECRYPT
, xeta_dec_tv_template
,
1558 XETA_DEC_TEST_VECTORS
);
1562 test_cipher("pcbc(fcrypt)", ENCRYPT
, fcrypt_pcbc_enc_tv_template
,
1563 FCRYPT_ENC_TEST_VECTORS
);
1564 test_cipher("pcbc(fcrypt)", DECRYPT
, fcrypt_pcbc_dec_tv_template
,
1565 FCRYPT_DEC_TEST_VECTORS
);
1569 test_cipher("ecb(camellia)", ENCRYPT
,
1570 camellia_enc_tv_template
,
1571 CAMELLIA_ENC_TEST_VECTORS
);
1572 test_cipher("ecb(camellia)", DECRYPT
,
1573 camellia_dec_tv_template
,
1574 CAMELLIA_DEC_TEST_VECTORS
);
1575 test_cipher("cbc(camellia)", ENCRYPT
,
1576 camellia_cbc_enc_tv_template
,
1577 CAMELLIA_CBC_ENC_TEST_VECTORS
);
1578 test_cipher("cbc(camellia)", DECRYPT
,
1579 camellia_cbc_dec_tv_template
,
1580 CAMELLIA_CBC_DEC_TEST_VECTORS
);
1583 test_hash("sha224", sha224_tv_template
, SHA224_TEST_VECTORS
);
1587 test_cipher("salsa20", ENCRYPT
,
1588 salsa20_stream_enc_tv_template
,
1589 SALSA20_STREAM_ENC_TEST_VECTORS
);
1593 test_aead("gcm(aes)", ENCRYPT
, aes_gcm_enc_tv_template
,
1594 AES_GCM_ENC_TEST_VECTORS
);
1595 test_aead("gcm(aes)", DECRYPT
, aes_gcm_dec_tv_template
,
1596 AES_GCM_DEC_TEST_VECTORS
);
1600 test_comp("lzo", lzo_comp_tv_template
, lzo_decomp_tv_template
,
1601 LZO_COMP_TEST_VECTORS
, LZO_DECOMP_TEST_VECTORS
);
1605 test_aead("ccm(aes)", ENCRYPT
, aes_ccm_enc_tv_template
,
1606 AES_CCM_ENC_TEST_VECTORS
);
1607 test_aead("ccm(aes)", DECRYPT
, aes_ccm_dec_tv_template
,
1608 AES_CCM_DEC_TEST_VECTORS
);
1612 test_cipher("cts(cbc(aes))", ENCRYPT
, cts_mode_enc_tv_template
,
1613 CTS_MODE_ENC_TEST_VECTORS
);
1614 test_cipher("cts(cbc(aes))", DECRYPT
, cts_mode_dec_tv_template
,
1615 CTS_MODE_DEC_TEST_VECTORS
);
1619 test_hash("hmac(md5)", hmac_md5_tv_template
,
1620 HMAC_MD5_TEST_VECTORS
);
1624 test_hash("hmac(sha1)", hmac_sha1_tv_template
,
1625 HMAC_SHA1_TEST_VECTORS
);
1629 test_hash("hmac(sha256)", hmac_sha256_tv_template
,
1630 HMAC_SHA256_TEST_VECTORS
);
1634 test_hash("hmac(sha384)", hmac_sha384_tv_template
,
1635 HMAC_SHA384_TEST_VECTORS
);
1639 test_hash("hmac(sha512)", hmac_sha512_tv_template
,
1640 HMAC_SHA512_TEST_VECTORS
);
1644 test_hash("hmac(sha224)", hmac_sha224_tv_template
,
1645 HMAC_SHA224_TEST_VECTORS
);
1649 test_hash("xcbc(aes)", aes_xcbc128_tv_template
,
1650 XCBC_AES_TEST_VECTORS
);
1654 test_cipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1655 speed_template_16_24_32
);
1656 test_cipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1657 speed_template_16_24_32
);
1658 test_cipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1659 speed_template_16_24_32
);
1660 test_cipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1661 speed_template_16_24_32
);
1662 test_cipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1663 speed_template_32_40_48
);
1664 test_cipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1665 speed_template_32_40_48
);
1666 test_cipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1667 speed_template_32_48_64
);
1668 test_cipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1669 speed_template_32_48_64
);
1673 test_cipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1674 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1676 test_cipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1677 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1679 test_cipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1680 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1682 test_cipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1683 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1688 test_cipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1689 speed_template_16_24_32
);
1690 test_cipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1691 speed_template_16_24_32
);
1692 test_cipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1693 speed_template_16_24_32
);
1694 test_cipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1695 speed_template_16_24_32
);
1699 test_cipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1700 speed_template_8_32
);
1701 test_cipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
1702 speed_template_8_32
);
1703 test_cipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1704 speed_template_8_32
);
1705 test_cipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
1706 speed_template_8_32
);
1710 test_cipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1712 test_cipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1714 test_cipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1716 test_cipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1721 test_cipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
1722 speed_template_16_24_32
);
1723 test_cipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
1724 speed_template_16_24_32
);
1725 test_cipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
1726 speed_template_16_24_32
);
1727 test_cipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
1728 speed_template_16_24_32
);
1732 test_cipher_speed("salsa20", ENCRYPT
, sec
, NULL
, 0,
1733 speed_template_16_32
);
1740 test_hash_speed("md4", sec
, generic_hash_speed_template
);
1741 if (mode
> 300 && mode
< 400) break;
1744 test_hash_speed("md5", sec
, generic_hash_speed_template
);
1745 if (mode
> 300 && mode
< 400) break;
1748 test_hash_speed("sha1", sec
, generic_hash_speed_template
);
1749 if (mode
> 300 && mode
< 400) break;
1752 test_hash_speed("sha256", sec
, generic_hash_speed_template
);
1753 if (mode
> 300 && mode
< 400) break;
1756 test_hash_speed("sha384", sec
, generic_hash_speed_template
);
1757 if (mode
> 300 && mode
< 400) break;
1760 test_hash_speed("sha512", sec
, generic_hash_speed_template
);
1761 if (mode
> 300 && mode
< 400) break;
1764 test_hash_speed("wp256", sec
, generic_hash_speed_template
);
1765 if (mode
> 300 && mode
< 400) break;
1768 test_hash_speed("wp384", sec
, generic_hash_speed_template
);
1769 if (mode
> 300 && mode
< 400) break;
1772 test_hash_speed("wp512", sec
, generic_hash_speed_template
);
1773 if (mode
> 300 && mode
< 400) break;
1776 test_hash_speed("tgr128", sec
, generic_hash_speed_template
);
1777 if (mode
> 300 && mode
< 400) break;
1780 test_hash_speed("tgr160", sec
, generic_hash_speed_template
);
1781 if (mode
> 300 && mode
< 400) break;
1784 test_hash_speed("tgr192", sec
, generic_hash_speed_template
);
1785 if (mode
> 300 && mode
< 400) break;
1788 test_hash_speed("sha224", sec
, generic_hash_speed_template
);
1789 if (mode
> 300 && mode
< 400) break;
1799 /* useful for debugging */
1800 printk("not testing anything\n");
1805 static int __init
tcrypt_mod_init(void)
1809 tvmem
= kmalloc(TVMEMSIZE
, GFP_KERNEL
);
1813 xbuf
= kmalloc(XBUFSIZE
, GFP_KERNEL
);
1817 axbuf
= kmalloc(XBUFSIZE
, GFP_KERNEL
);
1823 /* We intentionaly return -EAGAIN to prevent keeping
1824 * the module. It does all its work from init()
1825 * and doesn't offer any runtime functionality
1826 * => we don't need it in the memory, do we?
1841 * If an init function is provided, an exit function must also be provided
1842 * to allow module unload.
1844 static void __exit
tcrypt_mod_fini(void) { }
1846 module_init(tcrypt_mod_init
);
1847 module_exit(tcrypt_mod_fini
);
1849 module_param(mode
, int, 0);
1850 module_param(sec
, uint
, 0);
1851 MODULE_PARM_DESC(sec
, "Length in seconds of speed tests "
1852 "(defaults to zero which uses CPU cycles instead)");
1854 MODULE_LICENSE("GPL");
1855 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1856 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");