2 * Quick & dirty crypto testing module.
4 * This will only exist until we have a better testing mechanism
5 * (e.g. a char device).
7 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
8 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
9 * Copyright (c) 2007 Nokia Siemens Networks
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License, or (at your option)
18 #include <linux/err.h>
19 #include <linux/init.h>
20 #include <linux/module.h>
22 #include <linux/slab.h>
23 #include <linux/scatterlist.h>
24 #include <linux/string.h>
25 #include <linux/crypto.h>
26 #include <linux/highmem.h>
27 #include <linux/moduleparam.h>
28 #include <linux/jiffies.h>
29 #include <linux/timex.h>
30 #include <linux/interrupt.h>
34 * Need to kmalloc() memory for testing kmap().
36 #define TVMEMSIZE 16384
37 #define XBUFSIZE 32768
40 * Indexes into the xbuf to simulate cross-page access.
52 * Used by test_cipher()
57 struct tcrypt_result
{
58 struct completion completion
;
62 static unsigned int IDX
[8] = { IDX1
, IDX2
, IDX3
, IDX4
, IDX5
, IDX6
, IDX7
, IDX8
};
65 * Used by test_cipher_speed()
67 static unsigned int sec
;
74 static char *check
[] = {
75 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
76 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
77 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
78 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
79 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
83 static void hexdump(unsigned char *buf
, unsigned int len
)
85 print_hex_dump(KERN_CONT
, "", DUMP_PREFIX_OFFSET
,
90 static void tcrypt_complete(struct crypto_async_request
*req
, int err
)
92 struct tcrypt_result
*res
= req
->data
;
94 if (err
== -EINPROGRESS
)
98 complete(&res
->completion
);
101 static void test_hash(char *algo
, struct hash_testvec
*template,
104 unsigned int i
, j
, k
, temp
;
105 struct scatterlist sg
[8];
107 struct crypto_hash
*tfm
;
108 struct hash_desc desc
;
112 printk("\ntesting %s\n", algo
);
114 tfm
= crypto_alloc_hash(algo
, 0, CRYPTO_ALG_ASYNC
);
116 printk("failed to load transform for %s: %ld\n", algo
,
124 for (i
= 0; i
< tcount
; i
++) {
125 printk("test %u:\n", i
+ 1);
126 memset(result
, 0, 64);
128 hash_buff
= kzalloc(template[i
].psize
, GFP_KERNEL
);
132 memcpy(hash_buff
, template[i
].plaintext
, template[i
].psize
);
133 sg_init_one(&sg
[0], hash_buff
, template[i
].psize
);
135 if (template[i
].ksize
) {
136 ret
= crypto_hash_setkey(tfm
, template[i
].key
,
139 printk("setkey() failed ret=%d\n", ret
);
145 ret
= crypto_hash_digest(&desc
, sg
, template[i
].psize
, result
);
147 printk("digest () failed ret=%d\n", ret
);
152 hexdump(result
, crypto_hash_digestsize(tfm
));
154 memcmp(result
, template[i
].digest
,
155 crypto_hash_digestsize(tfm
)) ?
160 printk("testing %s across pages\n", algo
);
162 /* setup the dummy buffer first */
163 memset(xbuf
, 0, XBUFSIZE
);
166 for (i
= 0; i
< tcount
; i
++) {
167 if (template[i
].np
) {
169 printk("test %u:\n", j
);
170 memset(result
, 0, 64);
173 sg_init_table(sg
, template[i
].np
);
174 for (k
= 0; k
< template[i
].np
; k
++) {
175 memcpy(&xbuf
[IDX
[k
]],
176 template[i
].plaintext
+ temp
,
178 temp
+= template[i
].tap
[k
];
179 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
183 if (template[i
].ksize
) {
184 ret
= crypto_hash_setkey(tfm
, template[i
].key
,
188 printk("setkey() failed ret=%d\n", ret
);
193 ret
= crypto_hash_digest(&desc
, sg
, template[i
].psize
,
196 printk("digest () failed ret=%d\n", ret
);
200 hexdump(result
, crypto_hash_digestsize(tfm
));
202 memcmp(result
, template[i
].digest
,
203 crypto_hash_digestsize(tfm
)) ?
209 crypto_free_hash(tfm
);
212 static void test_aead(char *algo
, int enc
, struct aead_testvec
*template,
215 unsigned int ret
, i
, j
, k
, n
, temp
;
217 struct crypto_aead
*tfm
;
219 struct aead_request
*req
;
220 struct scatterlist sg
[8];
221 struct scatterlist asg
[8];
223 struct tcrypt_result result
;
224 unsigned int authsize
;
234 printk(KERN_INFO
"\ntesting %s %s\n", algo
, e
);
236 init_completion(&result
.completion
);
238 tfm
= crypto_alloc_aead(algo
, 0, 0);
241 printk(KERN_INFO
"failed to load transform for %s: %ld\n",
246 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
248 printk(KERN_INFO
"failed to allocate request for %s\n", algo
);
252 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
253 tcrypt_complete
, &result
);
255 for (i
= 0, j
= 0; i
< tcount
; i
++) {
256 if (!template[i
].np
) {
257 printk(KERN_INFO
"test %u (%d bit key):\n",
258 ++j
, template[i
].klen
* 8);
260 /* some tepmplates have no input data but they will
263 input
= kzalloc(template[i
].ilen
+ template[i
].rlen
, GFP_KERNEL
);
267 assoc
= kzalloc(template[i
].alen
, GFP_KERNEL
);
273 memcpy(input
, template[i
].input
, template[i
].ilen
);
274 memcpy(assoc
, template[i
].assoc
, template[i
].alen
);
276 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
278 memset(iv
, 0, MAX_IVLEN
);
280 crypto_aead_clear_flags(tfm
, ~0);
282 crypto_aead_set_flags(
283 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
286 key
= template[i
].key
;
288 key
= kzalloc(template[i
].klen
, GFP_KERNEL
);
290 ret
= crypto_aead_setkey(tfm
, key
,
293 printk(KERN_INFO
"setkey() failed flags=%x\n",
294 crypto_aead_get_flags(tfm
));
296 if (!template[i
].fail
)
300 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
301 ret
= crypto_aead_setauthsize(tfm
, authsize
);
304 "failed to set authsize = %u\n",
309 sg_init_one(&sg
[0], input
,
310 template[i
].ilen
+ (enc
? authsize
: 0));
312 sg_init_one(&asg
[0], assoc
, template[i
].alen
);
314 aead_request_set_crypt(req
, sg
, sg
,
315 template[i
].ilen
, iv
);
317 aead_request_set_assoc(req
, asg
, template[i
].alen
);
320 crypto_aead_encrypt(req
) :
321 crypto_aead_decrypt(req
);
328 ret
= wait_for_completion_interruptible(
330 if (!ret
&& !(ret
= result
.err
)) {
331 INIT_COMPLETION(result
.completion
);
336 printk(KERN_INFO
"%s () failed err=%d\n",
341 q
= kmap(sg_page(&sg
[0])) + sg
[0].offset
;
342 hexdump(q
, template[i
].rlen
);
344 printk(KERN_INFO
"enc/dec: %s\n",
345 memcmp(q
, template[i
].result
,
346 template[i
].rlen
) ? "fail" : "pass");
347 kunmap(sg_page(&sg
[0]));
349 if (!template[i
].key
)
356 printk(KERN_INFO
"\ntesting %s %s across pages (chunking)\n", algo
, e
);
357 memset(axbuf
, 0, XBUFSIZE
);
359 for (i
= 0, j
= 0; i
< tcount
; i
++) {
360 if (template[i
].np
) {
361 printk(KERN_INFO
"test %u (%d bit key):\n",
362 ++j
, template[i
].klen
* 8);
365 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
367 memset(iv
, 0, MAX_IVLEN
);
369 crypto_aead_clear_flags(tfm
, ~0);
371 crypto_aead_set_flags(
372 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
373 key
= template[i
].key
;
375 ret
= crypto_aead_setkey(tfm
, key
, template[i
].klen
);
377 printk(KERN_INFO
"setkey() failed flags=%x\n",
378 crypto_aead_get_flags(tfm
));
380 if (!template[i
].fail
)
384 memset(xbuf
, 0, XBUFSIZE
);
385 sg_init_table(sg
, template[i
].np
);
386 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
387 memcpy(&xbuf
[IDX
[k
]],
388 template[i
].input
+ temp
,
390 temp
+= template[i
].tap
[k
];
391 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
395 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
396 ret
= crypto_aead_setauthsize(tfm
, authsize
);
399 "failed to set authsize = %u\n",
405 sg
[k
- 1].length
+= authsize
;
407 sg_init_table(asg
, template[i
].anp
);
408 for (k
= 0, temp
= 0; k
< template[i
].anp
; k
++) {
409 memcpy(&axbuf
[IDX
[k
]],
410 template[i
].assoc
+ temp
,
411 template[i
].atap
[k
]);
412 temp
+= template[i
].atap
[k
];
413 sg_set_buf(&asg
[k
], &axbuf
[IDX
[k
]],
414 template[i
].atap
[k
]);
417 aead_request_set_crypt(req
, sg
, sg
,
421 aead_request_set_assoc(req
, asg
, template[i
].alen
);
424 crypto_aead_encrypt(req
) :
425 crypto_aead_decrypt(req
);
432 ret
= wait_for_completion_interruptible(
434 if (!ret
&& !(ret
= result
.err
)) {
435 INIT_COMPLETION(result
.completion
);
440 printk(KERN_INFO
"%s () failed err=%d\n",
445 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
446 printk(KERN_INFO
"page %u\n", k
);
447 q
= kmap(sg_page(&sg
[k
])) + sg
[k
].offset
;
448 hexdump(q
, template[i
].tap
[k
]);
449 printk(KERN_INFO
"%s\n",
450 memcmp(q
, template[i
].result
+ temp
,
452 (k
< template[i
].np
- 1 || enc
?
456 for (n
= 0; q
[template[i
].tap
[k
] + n
]; n
++)
459 printk("Result buffer corruption %u "
461 hexdump(&q
[template[i
].tap
[k
]], n
);
464 temp
+= template[i
].tap
[k
];
465 kunmap(sg_page(&sg
[k
]));
471 crypto_free_aead(tfm
);
472 aead_request_free(req
);
475 static void test_cipher(char *algo
, int enc
,
476 struct cipher_testvec
*template, unsigned int tcount
)
478 unsigned int ret
, i
, j
, k
, n
, temp
;
480 struct crypto_ablkcipher
*tfm
;
481 struct ablkcipher_request
*req
;
482 struct scatterlist sg
[8];
484 struct tcrypt_result result
;
493 printk("\ntesting %s %s\n", algo
, e
);
495 init_completion(&result
.completion
);
496 tfm
= crypto_alloc_ablkcipher(algo
, 0, 0);
499 printk("failed to load transform for %s: %ld\n", algo
,
504 req
= ablkcipher_request_alloc(tfm
, GFP_KERNEL
);
506 printk("failed to allocate request for %s\n", algo
);
510 ablkcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
511 tcrypt_complete
, &result
);
514 for (i
= 0; i
< tcount
; i
++) {
516 data
= kzalloc(template[i
].ilen
, GFP_KERNEL
);
520 memcpy(data
, template[i
].input
, template[i
].ilen
);
522 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
524 memset(iv
, 0, MAX_IVLEN
);
526 if (!(template[i
].np
)) {
528 printk("test %u (%d bit key):\n",
529 j
, template[i
].klen
* 8);
531 crypto_ablkcipher_clear_flags(tfm
, ~0);
533 crypto_ablkcipher_set_flags(
534 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
536 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
539 printk("setkey() failed flags=%x\n",
540 crypto_ablkcipher_get_flags(tfm
));
542 if (!template[i
].fail
) {
548 sg_init_one(&sg
[0], data
, template[i
].ilen
);
550 ablkcipher_request_set_crypt(req
, sg
, sg
,
551 template[i
].ilen
, iv
);
553 crypto_ablkcipher_encrypt(req
) :
554 crypto_ablkcipher_decrypt(req
);
561 ret
= wait_for_completion_interruptible(
563 if (!ret
&& !((ret
= result
.err
))) {
564 INIT_COMPLETION(result
.completion
);
569 printk("%s () failed err=%d\n", e
, -ret
);
574 q
= kmap(sg_page(&sg
[0])) + sg
[0].offset
;
575 hexdump(q
, template[i
].rlen
);
578 memcmp(q
, template[i
].result
,
579 template[i
].rlen
) ? "fail" : "pass");
580 kunmap(sg_page(&sg
[0]));
585 printk("\ntesting %s %s across pages (chunking)\n", algo
, e
);
588 for (i
= 0; i
< tcount
; i
++) {
591 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
593 memset(iv
, 0, MAX_IVLEN
);
595 if (template[i
].np
) {
597 printk("test %u (%d bit key):\n",
598 j
, template[i
].klen
* 8);
600 memset(xbuf
, 0, XBUFSIZE
);
601 crypto_ablkcipher_clear_flags(tfm
, ~0);
603 crypto_ablkcipher_set_flags(
604 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
606 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
609 printk("setkey() failed flags=%x\n",
610 crypto_ablkcipher_get_flags(tfm
));
612 if (!template[i
].fail
)
617 sg_init_table(sg
, template[i
].np
);
618 for (k
= 0; k
< template[i
].np
; k
++) {
619 memcpy(&xbuf
[IDX
[k
]],
620 template[i
].input
+ temp
,
622 temp
+= template[i
].tap
[k
];
623 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
627 ablkcipher_request_set_crypt(req
, sg
, sg
,
628 template[i
].ilen
, iv
);
631 crypto_ablkcipher_encrypt(req
) :
632 crypto_ablkcipher_decrypt(req
);
639 ret
= wait_for_completion_interruptible(
641 if (!ret
&& !((ret
= result
.err
))) {
642 INIT_COMPLETION(result
.completion
);
647 printk("%s () failed err=%d\n", e
, -ret
);
652 for (k
= 0; k
< template[i
].np
; k
++) {
653 printk("page %u\n", k
);
654 q
= kmap(sg_page(&sg
[k
])) + sg
[k
].offset
;
655 hexdump(q
, template[i
].tap
[k
]);
657 memcmp(q
, template[i
].result
+ temp
,
658 template[i
].tap
[k
]) ? "fail" :
661 for (n
= 0; q
[template[i
].tap
[k
] + n
]; n
++)
664 printk("Result buffer corruption %u "
666 hexdump(&q
[template[i
].tap
[k
]], n
);
668 temp
+= template[i
].tap
[k
];
669 kunmap(sg_page(&sg
[k
]));
674 crypto_free_ablkcipher(tfm
);
675 ablkcipher_request_free(req
);
678 static int test_cipher_jiffies(struct blkcipher_desc
*desc
, int enc
, char *p
,
681 struct scatterlist sg
[1];
682 unsigned long start
, end
;
686 sg_init_one(sg
, p
, blen
);
688 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
689 time_before(jiffies
, end
); bcount
++) {
691 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
693 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
699 printk("%d operations in %d seconds (%ld bytes)\n",
700 bcount
, sec
, (long)bcount
* blen
);
704 static int test_cipher_cycles(struct blkcipher_desc
*desc
, int enc
, char *p
,
707 struct scatterlist sg
[1];
708 unsigned long cycles
= 0;
712 sg_init_one(sg
, p
, blen
);
718 for (i
= 0; i
< 4; i
++) {
720 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
722 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
728 /* The real thing. */
729 for (i
= 0; i
< 8; i
++) {
732 start
= get_cycles();
734 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
736 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
742 cycles
+= end
- start
;
750 printk("1 operation in %lu cycles (%d bytes)\n",
751 (cycles
+ 4) / 8, blen
);
756 static u32 block_sizes
[] = { 16, 64, 256, 1024, 8192, 0 };
758 static void test_cipher_speed(char *algo
, int enc
, unsigned int sec
,
759 struct cipher_testvec
*template,
760 unsigned int tcount
, u8
*keysize
)
762 unsigned int ret
, i
, j
, iv_len
;
763 unsigned char *key
, *p
, iv
[128];
764 struct crypto_blkcipher
*tfm
;
765 struct blkcipher_desc desc
;
774 printk("\ntesting speed of %s %s\n", algo
, e
);
776 tfm
= crypto_alloc_blkcipher(algo
, 0, CRYPTO_ALG_ASYNC
);
779 printk("failed to load transform for %s: %ld\n", algo
,
789 b_size
= block_sizes
;
792 if ((*keysize
+ *b_size
) > TVMEMSIZE
) {
793 printk("template (%u) too big for tvmem (%u)\n",
794 *keysize
+ *b_size
, TVMEMSIZE
);
798 printk("test %u (%d bit key, %d byte blocks): ", i
,
799 *keysize
* 8, *b_size
);
801 memset(tvmem
, 0xff, *keysize
+ *b_size
);
803 /* set key, plain text and IV */
804 key
= (unsigned char *)tvmem
;
805 for (j
= 0; j
< tcount
; j
++) {
806 if (template[j
].klen
== *keysize
) {
807 key
= template[j
].key
;
811 p
= (unsigned char *)tvmem
+ *keysize
;
813 ret
= crypto_blkcipher_setkey(tfm
, key
, *keysize
);
815 printk("setkey() failed flags=%x\n",
816 crypto_blkcipher_get_flags(tfm
));
820 iv_len
= crypto_blkcipher_ivsize(tfm
);
822 memset(&iv
, 0xff, iv_len
);
823 crypto_blkcipher_set_iv(tfm
, iv
, iv_len
);
827 ret
= test_cipher_jiffies(&desc
, enc
, p
, *b_size
, sec
);
829 ret
= test_cipher_cycles(&desc
, enc
, p
, *b_size
);
832 printk("%s() failed flags=%x\n", e
, desc
.flags
);
842 crypto_free_blkcipher(tfm
);
845 static int test_hash_jiffies_digest(struct hash_desc
*desc
, char *p
, int blen
,
848 struct scatterlist sg
[1];
849 unsigned long start
, end
;
853 sg_init_table(sg
, 1);
855 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
856 time_before(jiffies
, end
); bcount
++) {
857 sg_set_buf(sg
, p
, blen
);
858 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
863 printk("%6u opers/sec, %9lu bytes/sec\n",
864 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
869 static int test_hash_jiffies(struct hash_desc
*desc
, char *p
, int blen
,
870 int plen
, char *out
, int sec
)
872 struct scatterlist sg
[1];
873 unsigned long start
, end
;
878 return test_hash_jiffies_digest(desc
, p
, blen
, out
, sec
);
880 sg_init_table(sg
, 1);
882 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
883 time_before(jiffies
, end
); bcount
++) {
884 ret
= crypto_hash_init(desc
);
887 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
888 sg_set_buf(sg
, p
+ pcount
, plen
);
889 ret
= crypto_hash_update(desc
, sg
, plen
);
893 /* we assume there is enough space in 'out' for the result */
894 ret
= crypto_hash_final(desc
, out
);
899 printk("%6u opers/sec, %9lu bytes/sec\n",
900 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
905 static int test_hash_cycles_digest(struct hash_desc
*desc
, char *p
, int blen
,
908 struct scatterlist sg
[1];
909 unsigned long cycles
= 0;
913 sg_init_table(sg
, 1);
919 for (i
= 0; i
< 4; i
++) {
920 sg_set_buf(sg
, p
, blen
);
921 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
926 /* The real thing. */
927 for (i
= 0; i
< 8; i
++) {
930 start
= get_cycles();
932 sg_set_buf(sg
, p
, blen
);
933 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
939 cycles
+= end
- start
;
949 printk("%6lu cycles/operation, %4lu cycles/byte\n",
950 cycles
/ 8, cycles
/ (8 * blen
));
955 static int test_hash_cycles(struct hash_desc
*desc
, char *p
, int blen
,
958 struct scatterlist sg
[1];
959 unsigned long cycles
= 0;
964 return test_hash_cycles_digest(desc
, p
, blen
, out
);
966 sg_init_table(sg
, 1);
972 for (i
= 0; i
< 4; i
++) {
973 ret
= crypto_hash_init(desc
);
976 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
977 sg_set_buf(sg
, p
+ pcount
, plen
);
978 ret
= crypto_hash_update(desc
, sg
, plen
);
982 ret
= crypto_hash_final(desc
, out
);
987 /* The real thing. */
988 for (i
= 0; i
< 8; i
++) {
991 start
= get_cycles();
993 ret
= crypto_hash_init(desc
);
996 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
997 sg_set_buf(sg
, p
+ pcount
, plen
);
998 ret
= crypto_hash_update(desc
, sg
, plen
);
1002 ret
= crypto_hash_final(desc
, out
);
1008 cycles
+= end
- start
;
1018 printk("%6lu cycles/operation, %4lu cycles/byte\n",
1019 cycles
/ 8, cycles
/ (8 * blen
));
1024 static void test_hash_speed(char *algo
, unsigned int sec
,
1025 struct hash_speed
*speed
)
1027 struct crypto_hash
*tfm
;
1028 struct hash_desc desc
;
1033 printk("\ntesting speed of %s\n", algo
);
1035 tfm
= crypto_alloc_hash(algo
, 0, CRYPTO_ALG_ASYNC
);
1038 printk("failed to load transform for %s: %ld\n", algo
,
1046 if (crypto_hash_digestsize(tfm
) > sizeof(output
)) {
1047 printk("digestsize(%u) > outputbuffer(%zu)\n",
1048 crypto_hash_digestsize(tfm
), sizeof(output
));
1052 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
1053 if (speed
[i
].blen
> TVMEMSIZE
) {
1054 printk("template (%u) too big for tvmem (%u)\n",
1055 speed
[i
].blen
, TVMEMSIZE
);
1059 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
1060 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
1062 memset(tvmem
, 0xff, speed
[i
].blen
);
1065 ret
= test_hash_jiffies(&desc
, tvmem
, speed
[i
].blen
,
1066 speed
[i
].plen
, output
, sec
);
1068 ret
= test_hash_cycles(&desc
, tvmem
, speed
[i
].blen
,
1069 speed
[i
].plen
, output
);
1072 printk("hashing failed ret=%d\n", ret
);
1078 crypto_free_hash(tfm
);
1081 static void test_comp(char *algo
, struct comp_testvec
*ctemplate
,
1082 struct comp_testvec
*dtemplate
, int ctcount
, int dtcount
)
1085 char result
[COMP_BUF_SIZE
];
1086 struct crypto_comp
*tfm
;
1089 printk("\ntesting %s compression\n", algo
);
1091 tfm
= crypto_alloc_comp(algo
, 0, CRYPTO_ALG_ASYNC
);
1093 printk("failed to load transform for %s\n", algo
);
1097 for (i
= 0; i
< ctcount
; i
++) {
1098 int ilen
, ret
, dlen
= COMP_BUF_SIZE
;
1100 printk("test %u:\n", i
+ 1);
1101 memset(result
, 0, sizeof (result
));
1103 ilen
= ctemplate
[i
].inlen
;
1104 ret
= crypto_comp_compress(tfm
, ctemplate
[i
].input
,
1105 ilen
, result
, &dlen
);
1107 printk("fail: ret=%d\n", ret
);
1110 hexdump(result
, dlen
);
1111 printk("%s (ratio %d:%d)\n",
1112 memcmp(result
, ctemplate
[i
].output
, dlen
) ? "fail" : "pass",
1116 printk("\ntesting %s decompression\n", algo
);
1118 tsize
= sizeof(struct comp_testvec
);
1120 if (tsize
> TVMEMSIZE
) {
1121 printk("template (%u) too big for tvmem (%u)\n", tsize
,
1126 for (i
= 0; i
< dtcount
; i
++) {
1127 int ilen
, ret
, dlen
= COMP_BUF_SIZE
;
1129 printk("test %u:\n", i
+ 1);
1130 memset(result
, 0, sizeof (result
));
1132 ilen
= dtemplate
[i
].inlen
;
1133 ret
= crypto_comp_decompress(tfm
, dtemplate
[i
].input
,
1134 ilen
, result
, &dlen
);
1136 printk("fail: ret=%d\n", ret
);
1139 hexdump(result
, dlen
);
1140 printk("%s (ratio %d:%d)\n",
1141 memcmp(result
, dtemplate
[i
].output
, dlen
) ? "fail" : "pass",
1145 crypto_free_comp(tfm
);
1148 static void test_available(void)
1150 char **name
= check
;
1153 printk("alg %s ", *name
);
1154 printk(crypto_has_alg(*name
, 0, 0) ?
1155 "found\n" : "not found\n");
1160 static void do_test(void)
1165 test_hash("md5", md5_tv_template
, MD5_TEST_VECTORS
);
1167 test_hash("sha1", sha1_tv_template
, SHA1_TEST_VECTORS
);
1170 test_cipher("ecb(des)", ENCRYPT
, des_enc_tv_template
,
1171 DES_ENC_TEST_VECTORS
);
1172 test_cipher("ecb(des)", DECRYPT
, des_dec_tv_template
,
1173 DES_DEC_TEST_VECTORS
);
1174 test_cipher("cbc(des)", ENCRYPT
, des_cbc_enc_tv_template
,
1175 DES_CBC_ENC_TEST_VECTORS
);
1176 test_cipher("cbc(des)", DECRYPT
, des_cbc_dec_tv_template
,
1177 DES_CBC_DEC_TEST_VECTORS
);
1180 test_cipher("ecb(des3_ede)", ENCRYPT
, des3_ede_enc_tv_template
,
1181 DES3_EDE_ENC_TEST_VECTORS
);
1182 test_cipher("ecb(des3_ede)", DECRYPT
, des3_ede_dec_tv_template
,
1183 DES3_EDE_DEC_TEST_VECTORS
);
1185 test_hash("md4", md4_tv_template
, MD4_TEST_VECTORS
);
1187 test_hash("sha224", sha224_tv_template
, SHA224_TEST_VECTORS
);
1189 test_hash("sha256", sha256_tv_template
, SHA256_TEST_VECTORS
);
1192 test_cipher("ecb(blowfish)", ENCRYPT
, bf_enc_tv_template
,
1193 BF_ENC_TEST_VECTORS
);
1194 test_cipher("ecb(blowfish)", DECRYPT
, bf_dec_tv_template
,
1195 BF_DEC_TEST_VECTORS
);
1196 test_cipher("cbc(blowfish)", ENCRYPT
, bf_cbc_enc_tv_template
,
1197 BF_CBC_ENC_TEST_VECTORS
);
1198 test_cipher("cbc(blowfish)", DECRYPT
, bf_cbc_dec_tv_template
,
1199 BF_CBC_DEC_TEST_VECTORS
);
1202 test_cipher("ecb(twofish)", ENCRYPT
, tf_enc_tv_template
,
1203 TF_ENC_TEST_VECTORS
);
1204 test_cipher("ecb(twofish)", DECRYPT
, tf_dec_tv_template
,
1205 TF_DEC_TEST_VECTORS
);
1206 test_cipher("cbc(twofish)", ENCRYPT
, tf_cbc_enc_tv_template
,
1207 TF_CBC_ENC_TEST_VECTORS
);
1208 test_cipher("cbc(twofish)", DECRYPT
, tf_cbc_dec_tv_template
,
1209 TF_CBC_DEC_TEST_VECTORS
);
1212 test_cipher("ecb(serpent)", ENCRYPT
, serpent_enc_tv_template
,
1213 SERPENT_ENC_TEST_VECTORS
);
1214 test_cipher("ecb(serpent)", DECRYPT
, serpent_dec_tv_template
,
1215 SERPENT_DEC_TEST_VECTORS
);
1218 test_cipher("ecb(tnepres)", ENCRYPT
, tnepres_enc_tv_template
,
1219 TNEPRES_ENC_TEST_VECTORS
);
1220 test_cipher("ecb(tnepres)", DECRYPT
, tnepres_dec_tv_template
,
1221 TNEPRES_DEC_TEST_VECTORS
);
1224 test_cipher("ecb(aes)", ENCRYPT
, aes_enc_tv_template
,
1225 AES_ENC_TEST_VECTORS
);
1226 test_cipher("ecb(aes)", DECRYPT
, aes_dec_tv_template
,
1227 AES_DEC_TEST_VECTORS
);
1228 test_cipher("cbc(aes)", ENCRYPT
, aes_cbc_enc_tv_template
,
1229 AES_CBC_ENC_TEST_VECTORS
);
1230 test_cipher("cbc(aes)", DECRYPT
, aes_cbc_dec_tv_template
,
1231 AES_CBC_DEC_TEST_VECTORS
);
1232 test_cipher("lrw(aes)", ENCRYPT
, aes_lrw_enc_tv_template
,
1233 AES_LRW_ENC_TEST_VECTORS
);
1234 test_cipher("lrw(aes)", DECRYPT
, aes_lrw_dec_tv_template
,
1235 AES_LRW_DEC_TEST_VECTORS
);
1236 test_cipher("xts(aes)", ENCRYPT
, aes_xts_enc_tv_template
,
1237 AES_XTS_ENC_TEST_VECTORS
);
1238 test_cipher("xts(aes)", DECRYPT
, aes_xts_dec_tv_template
,
1239 AES_XTS_DEC_TEST_VECTORS
);
1240 test_cipher("rfc3686(ctr(aes))", ENCRYPT
, aes_ctr_enc_tv_template
,
1241 AES_CTR_ENC_TEST_VECTORS
);
1242 test_cipher("rfc3686(ctr(aes))", DECRYPT
, aes_ctr_dec_tv_template
,
1243 AES_CTR_DEC_TEST_VECTORS
);
1244 test_aead("gcm(aes)", ENCRYPT
, aes_gcm_enc_tv_template
,
1245 AES_GCM_ENC_TEST_VECTORS
);
1246 test_aead("gcm(aes)", DECRYPT
, aes_gcm_dec_tv_template
,
1247 AES_GCM_DEC_TEST_VECTORS
);
1248 test_aead("ccm(aes)", ENCRYPT
, aes_ccm_enc_tv_template
,
1249 AES_CCM_ENC_TEST_VECTORS
);
1250 test_aead("ccm(aes)", DECRYPT
, aes_ccm_dec_tv_template
,
1251 AES_CCM_DEC_TEST_VECTORS
);
1254 test_cipher("ecb(cast5)", ENCRYPT
, cast5_enc_tv_template
,
1255 CAST5_ENC_TEST_VECTORS
);
1256 test_cipher("ecb(cast5)", DECRYPT
, cast5_dec_tv_template
,
1257 CAST5_DEC_TEST_VECTORS
);
1260 test_cipher("ecb(cast6)", ENCRYPT
, cast6_enc_tv_template
,
1261 CAST6_ENC_TEST_VECTORS
);
1262 test_cipher("ecb(cast6)", DECRYPT
, cast6_dec_tv_template
,
1263 CAST6_DEC_TEST_VECTORS
);
1266 test_cipher("ecb(arc4)", ENCRYPT
, arc4_enc_tv_template
,
1267 ARC4_ENC_TEST_VECTORS
);
1268 test_cipher("ecb(arc4)", DECRYPT
, arc4_dec_tv_template
,
1269 ARC4_DEC_TEST_VECTORS
);
1272 test_cipher("ecb(tea)", ENCRYPT
, tea_enc_tv_template
,
1273 TEA_ENC_TEST_VECTORS
);
1274 test_cipher("ecb(tea)", DECRYPT
, tea_dec_tv_template
,
1275 TEA_DEC_TEST_VECTORS
);
1279 test_cipher("ecb(xtea)", ENCRYPT
, xtea_enc_tv_template
,
1280 XTEA_ENC_TEST_VECTORS
);
1281 test_cipher("ecb(xtea)", DECRYPT
, xtea_dec_tv_template
,
1282 XTEA_DEC_TEST_VECTORS
);
1285 test_cipher("ecb(khazad)", ENCRYPT
, khazad_enc_tv_template
,
1286 KHAZAD_ENC_TEST_VECTORS
);
1287 test_cipher("ecb(khazad)", DECRYPT
, khazad_dec_tv_template
,
1288 KHAZAD_DEC_TEST_VECTORS
);
1291 test_cipher("ecb(anubis)", ENCRYPT
, anubis_enc_tv_template
,
1292 ANUBIS_ENC_TEST_VECTORS
);
1293 test_cipher("ecb(anubis)", DECRYPT
, anubis_dec_tv_template
,
1294 ANUBIS_DEC_TEST_VECTORS
);
1295 test_cipher("cbc(anubis)", ENCRYPT
, anubis_cbc_enc_tv_template
,
1296 ANUBIS_CBC_ENC_TEST_VECTORS
);
1297 test_cipher("cbc(anubis)", DECRYPT
, anubis_cbc_dec_tv_template
,
1298 ANUBIS_CBC_ENC_TEST_VECTORS
);
1301 test_cipher("ecb(xeta)", ENCRYPT
, xeta_enc_tv_template
,
1302 XETA_ENC_TEST_VECTORS
);
1303 test_cipher("ecb(xeta)", DECRYPT
, xeta_dec_tv_template
,
1304 XETA_DEC_TEST_VECTORS
);
1307 test_cipher("pcbc(fcrypt)", ENCRYPT
, fcrypt_pcbc_enc_tv_template
,
1308 FCRYPT_ENC_TEST_VECTORS
);
1309 test_cipher("pcbc(fcrypt)", DECRYPT
, fcrypt_pcbc_dec_tv_template
,
1310 FCRYPT_DEC_TEST_VECTORS
);
1313 test_cipher("ecb(camellia)", ENCRYPT
,
1314 camellia_enc_tv_template
,
1315 CAMELLIA_ENC_TEST_VECTORS
);
1316 test_cipher("ecb(camellia)", DECRYPT
,
1317 camellia_dec_tv_template
,
1318 CAMELLIA_DEC_TEST_VECTORS
);
1319 test_cipher("cbc(camellia)", ENCRYPT
,
1320 camellia_cbc_enc_tv_template
,
1321 CAMELLIA_CBC_ENC_TEST_VECTORS
);
1322 test_cipher("cbc(camellia)", DECRYPT
,
1323 camellia_cbc_dec_tv_template
,
1324 CAMELLIA_CBC_DEC_TEST_VECTORS
);
1327 test_cipher("ecb(seed)", ENCRYPT
, seed_enc_tv_template
,
1328 SEED_ENC_TEST_VECTORS
);
1329 test_cipher("ecb(seed)", DECRYPT
, seed_dec_tv_template
,
1330 SEED_DEC_TEST_VECTORS
);
1333 test_cipher("cts(cbc(aes))", ENCRYPT
, cts_mode_enc_tv_template
,
1334 CTS_MODE_ENC_TEST_VECTORS
);
1335 test_cipher("cts(cbc(aes))", DECRYPT
, cts_mode_dec_tv_template
,
1336 CTS_MODE_DEC_TEST_VECTORS
);
1338 test_hash("sha384", sha384_tv_template
, SHA384_TEST_VECTORS
);
1339 test_hash("sha512", sha512_tv_template
, SHA512_TEST_VECTORS
);
1340 test_hash("wp512", wp512_tv_template
, WP512_TEST_VECTORS
);
1341 test_hash("wp384", wp384_tv_template
, WP384_TEST_VECTORS
);
1342 test_hash("wp256", wp256_tv_template
, WP256_TEST_VECTORS
);
1343 test_hash("tgr192", tgr192_tv_template
, TGR192_TEST_VECTORS
);
1344 test_hash("tgr160", tgr160_tv_template
, TGR160_TEST_VECTORS
);
1345 test_hash("tgr128", tgr128_tv_template
, TGR128_TEST_VECTORS
);
1346 test_comp("deflate", deflate_comp_tv_template
,
1347 deflate_decomp_tv_template
, DEFLATE_COMP_TEST_VECTORS
,
1348 DEFLATE_DECOMP_TEST_VECTORS
);
1349 test_comp("lzo", lzo_comp_tv_template
, lzo_decomp_tv_template
,
1350 LZO_COMP_TEST_VECTORS
, LZO_DECOMP_TEST_VECTORS
);
1351 test_hash("crc32c", crc32c_tv_template
, CRC32C_TEST_VECTORS
);
1352 test_hash("hmac(md5)", hmac_md5_tv_template
,
1353 HMAC_MD5_TEST_VECTORS
);
1354 test_hash("hmac(sha1)", hmac_sha1_tv_template
,
1355 HMAC_SHA1_TEST_VECTORS
);
1356 test_hash("hmac(sha224)", hmac_sha224_tv_template
,
1357 HMAC_SHA224_TEST_VECTORS
);
1358 test_hash("hmac(sha256)", hmac_sha256_tv_template
,
1359 HMAC_SHA256_TEST_VECTORS
);
1360 test_hash("hmac(sha384)", hmac_sha384_tv_template
,
1361 HMAC_SHA384_TEST_VECTORS
);
1362 test_hash("hmac(sha512)", hmac_sha512_tv_template
,
1363 HMAC_SHA512_TEST_VECTORS
);
1365 test_hash("xcbc(aes)", aes_xcbc128_tv_template
,
1366 XCBC_AES_TEST_VECTORS
);
1368 test_hash("michael_mic", michael_mic_tv_template
, MICHAEL_MIC_TEST_VECTORS
);
1372 test_hash("md5", md5_tv_template
, MD5_TEST_VECTORS
);
1376 test_hash("sha1", sha1_tv_template
, SHA1_TEST_VECTORS
);
1380 test_cipher("ecb(des)", ENCRYPT
, des_enc_tv_template
,
1381 DES_ENC_TEST_VECTORS
);
1382 test_cipher("ecb(des)", DECRYPT
, des_dec_tv_template
,
1383 DES_DEC_TEST_VECTORS
);
1384 test_cipher("cbc(des)", ENCRYPT
, des_cbc_enc_tv_template
,
1385 DES_CBC_ENC_TEST_VECTORS
);
1386 test_cipher("cbc(des)", DECRYPT
, des_cbc_dec_tv_template
,
1387 DES_CBC_DEC_TEST_VECTORS
);
1391 test_cipher("ecb(des3_ede)", ENCRYPT
, des3_ede_enc_tv_template
,
1392 DES3_EDE_ENC_TEST_VECTORS
);
1393 test_cipher("ecb(des3_ede)", DECRYPT
, des3_ede_dec_tv_template
,
1394 DES3_EDE_DEC_TEST_VECTORS
);
1398 test_hash("md4", md4_tv_template
, MD4_TEST_VECTORS
);
1402 test_hash("sha256", sha256_tv_template
, SHA256_TEST_VECTORS
);
1406 test_cipher("ecb(blowfish)", ENCRYPT
, bf_enc_tv_template
,
1407 BF_ENC_TEST_VECTORS
);
1408 test_cipher("ecb(blowfish)", DECRYPT
, bf_dec_tv_template
,
1409 BF_DEC_TEST_VECTORS
);
1410 test_cipher("cbc(blowfish)", ENCRYPT
, bf_cbc_enc_tv_template
,
1411 BF_CBC_ENC_TEST_VECTORS
);
1412 test_cipher("cbc(blowfish)", DECRYPT
, bf_cbc_dec_tv_template
,
1413 BF_CBC_DEC_TEST_VECTORS
);
1417 test_cipher("ecb(twofish)", ENCRYPT
, tf_enc_tv_template
,
1418 TF_ENC_TEST_VECTORS
);
1419 test_cipher("ecb(twofish)", DECRYPT
, tf_dec_tv_template
,
1420 TF_DEC_TEST_VECTORS
);
1421 test_cipher("cbc(twofish)", ENCRYPT
, tf_cbc_enc_tv_template
,
1422 TF_CBC_ENC_TEST_VECTORS
);
1423 test_cipher("cbc(twofish)", DECRYPT
, tf_cbc_dec_tv_template
,
1424 TF_CBC_DEC_TEST_VECTORS
);
1428 test_cipher("ecb(serpent)", ENCRYPT
, serpent_enc_tv_template
,
1429 SERPENT_ENC_TEST_VECTORS
);
1430 test_cipher("ecb(serpent)", DECRYPT
, serpent_dec_tv_template
,
1431 SERPENT_DEC_TEST_VECTORS
);
1435 test_cipher("ecb(aes)", ENCRYPT
, aes_enc_tv_template
,
1436 AES_ENC_TEST_VECTORS
);
1437 test_cipher("ecb(aes)", DECRYPT
, aes_dec_tv_template
,
1438 AES_DEC_TEST_VECTORS
);
1439 test_cipher("cbc(aes)", ENCRYPT
, aes_cbc_enc_tv_template
,
1440 AES_CBC_ENC_TEST_VECTORS
);
1441 test_cipher("cbc(aes)", DECRYPT
, aes_cbc_dec_tv_template
,
1442 AES_CBC_DEC_TEST_VECTORS
);
1443 test_cipher("lrw(aes)", ENCRYPT
, aes_lrw_enc_tv_template
,
1444 AES_LRW_ENC_TEST_VECTORS
);
1445 test_cipher("lrw(aes)", DECRYPT
, aes_lrw_dec_tv_template
,
1446 AES_LRW_DEC_TEST_VECTORS
);
1447 test_cipher("xts(aes)", ENCRYPT
, aes_xts_enc_tv_template
,
1448 AES_XTS_ENC_TEST_VECTORS
);
1449 test_cipher("xts(aes)", DECRYPT
, aes_xts_dec_tv_template
,
1450 AES_XTS_DEC_TEST_VECTORS
);
1451 test_cipher("rfc3686(ctr(aes))", ENCRYPT
, aes_ctr_enc_tv_template
,
1452 AES_CTR_ENC_TEST_VECTORS
);
1453 test_cipher("rfc3686(ctr(aes))", DECRYPT
, aes_ctr_dec_tv_template
,
1454 AES_CTR_DEC_TEST_VECTORS
);
1458 test_hash("sha384", sha384_tv_template
, SHA384_TEST_VECTORS
);
1462 test_hash("sha512", sha512_tv_template
, SHA512_TEST_VECTORS
);
1466 test_comp("deflate", deflate_comp_tv_template
,
1467 deflate_decomp_tv_template
, DEFLATE_COMP_TEST_VECTORS
,
1468 DEFLATE_DECOMP_TEST_VECTORS
);
1472 test_cipher("ecb(cast5)", ENCRYPT
, cast5_enc_tv_template
,
1473 CAST5_ENC_TEST_VECTORS
);
1474 test_cipher("ecb(cast5)", DECRYPT
, cast5_dec_tv_template
,
1475 CAST5_DEC_TEST_VECTORS
);
1479 test_cipher("ecb(cast6)", ENCRYPT
, cast6_enc_tv_template
,
1480 CAST6_ENC_TEST_VECTORS
);
1481 test_cipher("ecb(cast6)", DECRYPT
, cast6_dec_tv_template
,
1482 CAST6_DEC_TEST_VECTORS
);
1486 test_cipher("ecb(arc4)", ENCRYPT
, arc4_enc_tv_template
,
1487 ARC4_ENC_TEST_VECTORS
);
1488 test_cipher("ecb(arc4)", DECRYPT
, arc4_dec_tv_template
,
1489 ARC4_DEC_TEST_VECTORS
);
1493 test_hash("michael_mic", michael_mic_tv_template
, MICHAEL_MIC_TEST_VECTORS
);
1497 test_hash("crc32c", crc32c_tv_template
, CRC32C_TEST_VECTORS
);
1501 test_cipher("ecb(tea)", ENCRYPT
, tea_enc_tv_template
,
1502 TEA_ENC_TEST_VECTORS
);
1503 test_cipher("ecb(tea)", DECRYPT
, tea_dec_tv_template
,
1504 TEA_DEC_TEST_VECTORS
);
1508 test_cipher("ecb(xtea)", ENCRYPT
, xtea_enc_tv_template
,
1509 XTEA_ENC_TEST_VECTORS
);
1510 test_cipher("ecb(xtea)", DECRYPT
, xtea_dec_tv_template
,
1511 XTEA_DEC_TEST_VECTORS
);
1515 test_cipher("ecb(khazad)", ENCRYPT
, khazad_enc_tv_template
,
1516 KHAZAD_ENC_TEST_VECTORS
);
1517 test_cipher("ecb(khazad)", DECRYPT
, khazad_dec_tv_template
,
1518 KHAZAD_DEC_TEST_VECTORS
);
1522 test_hash("wp512", wp512_tv_template
, WP512_TEST_VECTORS
);
1526 test_hash("wp384", wp384_tv_template
, WP384_TEST_VECTORS
);
1530 test_hash("wp256", wp256_tv_template
, WP256_TEST_VECTORS
);
1534 test_cipher("ecb(tnepres)", ENCRYPT
, tnepres_enc_tv_template
,
1535 TNEPRES_ENC_TEST_VECTORS
);
1536 test_cipher("ecb(tnepres)", DECRYPT
, tnepres_dec_tv_template
,
1537 TNEPRES_DEC_TEST_VECTORS
);
1541 test_cipher("ecb(anubis)", ENCRYPT
, anubis_enc_tv_template
,
1542 ANUBIS_ENC_TEST_VECTORS
);
1543 test_cipher("ecb(anubis)", DECRYPT
, anubis_dec_tv_template
,
1544 ANUBIS_DEC_TEST_VECTORS
);
1545 test_cipher("cbc(anubis)", ENCRYPT
, anubis_cbc_enc_tv_template
,
1546 ANUBIS_CBC_ENC_TEST_VECTORS
);
1547 test_cipher("cbc(anubis)", DECRYPT
, anubis_cbc_dec_tv_template
,
1548 ANUBIS_CBC_ENC_TEST_VECTORS
);
1552 test_hash("tgr192", tgr192_tv_template
, TGR192_TEST_VECTORS
);
1557 test_hash("tgr160", tgr160_tv_template
, TGR160_TEST_VECTORS
);
1561 test_hash("tgr128", tgr128_tv_template
, TGR128_TEST_VECTORS
);
1565 test_cipher("ecb(xeta)", ENCRYPT
, xeta_enc_tv_template
,
1566 XETA_ENC_TEST_VECTORS
);
1567 test_cipher("ecb(xeta)", DECRYPT
, xeta_dec_tv_template
,
1568 XETA_DEC_TEST_VECTORS
);
1572 test_cipher("pcbc(fcrypt)", ENCRYPT
, fcrypt_pcbc_enc_tv_template
,
1573 FCRYPT_ENC_TEST_VECTORS
);
1574 test_cipher("pcbc(fcrypt)", DECRYPT
, fcrypt_pcbc_dec_tv_template
,
1575 FCRYPT_DEC_TEST_VECTORS
);
1579 test_cipher("ecb(camellia)", ENCRYPT
,
1580 camellia_enc_tv_template
,
1581 CAMELLIA_ENC_TEST_VECTORS
);
1582 test_cipher("ecb(camellia)", DECRYPT
,
1583 camellia_dec_tv_template
,
1584 CAMELLIA_DEC_TEST_VECTORS
);
1585 test_cipher("cbc(camellia)", ENCRYPT
,
1586 camellia_cbc_enc_tv_template
,
1587 CAMELLIA_CBC_ENC_TEST_VECTORS
);
1588 test_cipher("cbc(camellia)", DECRYPT
,
1589 camellia_cbc_dec_tv_template
,
1590 CAMELLIA_CBC_DEC_TEST_VECTORS
);
1593 test_hash("sha224", sha224_tv_template
, SHA224_TEST_VECTORS
);
1597 test_cipher("salsa20", ENCRYPT
,
1598 salsa20_stream_enc_tv_template
,
1599 SALSA20_STREAM_ENC_TEST_VECTORS
);
1603 test_aead("gcm(aes)", ENCRYPT
, aes_gcm_enc_tv_template
,
1604 AES_GCM_ENC_TEST_VECTORS
);
1605 test_aead("gcm(aes)", DECRYPT
, aes_gcm_dec_tv_template
,
1606 AES_GCM_DEC_TEST_VECTORS
);
1610 test_comp("lzo", lzo_comp_tv_template
, lzo_decomp_tv_template
,
1611 LZO_COMP_TEST_VECTORS
, LZO_DECOMP_TEST_VECTORS
);
1615 test_aead("ccm(aes)", ENCRYPT
, aes_ccm_enc_tv_template
,
1616 AES_CCM_ENC_TEST_VECTORS
);
1617 test_aead("ccm(aes)", DECRYPT
, aes_ccm_dec_tv_template
,
1618 AES_CCM_DEC_TEST_VECTORS
);
1622 test_cipher("cts(cbc(aes))", ENCRYPT
, cts_mode_enc_tv_template
,
1623 CTS_MODE_ENC_TEST_VECTORS
);
1624 test_cipher("cts(cbc(aes))", DECRYPT
, cts_mode_dec_tv_template
,
1625 CTS_MODE_DEC_TEST_VECTORS
);
1629 test_hash("rmd128", rmd128_tv_template
, RMD128_TEST_VECTORS
);
1633 test_hash("rmd160", rmd160_tv_template
, RMD160_TEST_VECTORS
);
1637 test_hash("rmd256", rmd256_tv_template
, RMD256_TEST_VECTORS
);
1641 test_hash("rmd320", rmd320_tv_template
, RMD320_TEST_VECTORS
);
1645 test_hash("hmac(md5)", hmac_md5_tv_template
,
1646 HMAC_MD5_TEST_VECTORS
);
1650 test_hash("hmac(sha1)", hmac_sha1_tv_template
,
1651 HMAC_SHA1_TEST_VECTORS
);
1655 test_hash("hmac(sha256)", hmac_sha256_tv_template
,
1656 HMAC_SHA256_TEST_VECTORS
);
1660 test_hash("hmac(sha384)", hmac_sha384_tv_template
,
1661 HMAC_SHA384_TEST_VECTORS
);
1665 test_hash("hmac(sha512)", hmac_sha512_tv_template
,
1666 HMAC_SHA512_TEST_VECTORS
);
1670 test_hash("hmac(sha224)", hmac_sha224_tv_template
,
1671 HMAC_SHA224_TEST_VECTORS
);
1675 test_hash("xcbc(aes)", aes_xcbc128_tv_template
,
1676 XCBC_AES_TEST_VECTORS
);
1680 test_hash("hmac(rmd128)", hmac_rmd128_tv_template
,
1681 HMAC_RMD128_TEST_VECTORS
);
1685 test_hash("hmac(rmd160)", hmac_rmd160_tv_template
,
1686 HMAC_RMD160_TEST_VECTORS
);
1690 test_cipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1691 speed_template_16_24_32
);
1692 test_cipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1693 speed_template_16_24_32
);
1694 test_cipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1695 speed_template_16_24_32
);
1696 test_cipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1697 speed_template_16_24_32
);
1698 test_cipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1699 speed_template_32_40_48
);
1700 test_cipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1701 speed_template_32_40_48
);
1702 test_cipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1703 speed_template_32_48_64
);
1704 test_cipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1705 speed_template_32_48_64
);
1709 test_cipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1710 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1712 test_cipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1713 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1715 test_cipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1716 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1718 test_cipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1719 des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
,
1724 test_cipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1725 speed_template_16_24_32
);
1726 test_cipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1727 speed_template_16_24_32
);
1728 test_cipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1729 speed_template_16_24_32
);
1730 test_cipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1731 speed_template_16_24_32
);
1735 test_cipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1736 speed_template_8_32
);
1737 test_cipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
1738 speed_template_8_32
);
1739 test_cipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1740 speed_template_8_32
);
1741 test_cipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
1742 speed_template_8_32
);
1746 test_cipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1748 test_cipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1750 test_cipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1752 test_cipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1757 test_cipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
1758 speed_template_16_24_32
);
1759 test_cipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
1760 speed_template_16_24_32
);
1761 test_cipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
1762 speed_template_16_24_32
);
1763 test_cipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
1764 speed_template_16_24_32
);
1768 test_cipher_speed("salsa20", ENCRYPT
, sec
, NULL
, 0,
1769 speed_template_16_32
);
1776 test_hash_speed("md4", sec
, generic_hash_speed_template
);
1777 if (mode
> 300 && mode
< 400) break;
1780 test_hash_speed("md5", sec
, generic_hash_speed_template
);
1781 if (mode
> 300 && mode
< 400) break;
1784 test_hash_speed("sha1", sec
, generic_hash_speed_template
);
1785 if (mode
> 300 && mode
< 400) break;
1788 test_hash_speed("sha256", sec
, generic_hash_speed_template
);
1789 if (mode
> 300 && mode
< 400) break;
1792 test_hash_speed("sha384", sec
, generic_hash_speed_template
);
1793 if (mode
> 300 && mode
< 400) break;
1796 test_hash_speed("sha512", sec
, generic_hash_speed_template
);
1797 if (mode
> 300 && mode
< 400) break;
1800 test_hash_speed("wp256", sec
, generic_hash_speed_template
);
1801 if (mode
> 300 && mode
< 400) break;
1804 test_hash_speed("wp384", sec
, generic_hash_speed_template
);
1805 if (mode
> 300 && mode
< 400) break;
1808 test_hash_speed("wp512", sec
, generic_hash_speed_template
);
1809 if (mode
> 300 && mode
< 400) break;
1812 test_hash_speed("tgr128", sec
, generic_hash_speed_template
);
1813 if (mode
> 300 && mode
< 400) break;
1816 test_hash_speed("tgr160", sec
, generic_hash_speed_template
);
1817 if (mode
> 300 && mode
< 400) break;
1820 test_hash_speed("tgr192", sec
, generic_hash_speed_template
);
1821 if (mode
> 300 && mode
< 400) break;
1824 test_hash_speed("sha224", sec
, generic_hash_speed_template
);
1825 if (mode
> 300 && mode
< 400) break;
1828 test_hash_speed("rmd128", sec
, generic_hash_speed_template
);
1829 if (mode
> 300 && mode
< 400) break;
1832 test_hash_speed("rmd160", sec
, generic_hash_speed_template
);
1833 if (mode
> 300 && mode
< 400) break;
1836 test_hash_speed("rmd256", sec
, generic_hash_speed_template
);
1837 if (mode
> 300 && mode
< 400) break;
1840 test_hash_speed("rmd320", sec
, generic_hash_speed_template
);
1841 if (mode
> 300 && mode
< 400) break;
1851 /* useful for debugging */
1852 printk("not testing anything\n");
1857 static int __init
tcrypt_mod_init(void)
1861 tvmem
= kmalloc(TVMEMSIZE
, GFP_KERNEL
);
1865 xbuf
= kmalloc(XBUFSIZE
, GFP_KERNEL
);
1869 axbuf
= kmalloc(XBUFSIZE
, GFP_KERNEL
);
1875 /* We intentionaly return -EAGAIN to prevent keeping
1876 * the module. It does all its work from init()
1877 * and doesn't offer any runtime functionality
1878 * => we don't need it in the memory, do we?
1893 * If an init function is provided, an exit function must also be provided
1894 * to allow module unload.
1896 static void __exit
tcrypt_mod_fini(void) { }
1898 module_init(tcrypt_mod_init
);
1899 module_exit(tcrypt_mod_fini
);
1901 module_param(mode
, int, 0);
1902 module_param(sec
, uint
, 0);
1903 MODULE_PARM_DESC(sec
, "Length in seconds of speed tests "
1904 "(defaults to zero which uses CPU cycles instead)");
1906 MODULE_LICENSE("GPL");
1907 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1908 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");