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 "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
86 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
87 "camellia", "seed", "salsa20", "lzo", NULL
90 static void hexdump(unsigned char *buf
, unsigned int len
)
92 print_hex_dump(KERN_CONT
, "", DUMP_PREFIX_OFFSET
,
97 static void tcrypt_complete(struct crypto_async_request
*req
, int err
)
99 struct tcrypt_result
*res
= req
->data
;
101 if (err
== -EINPROGRESS
)
105 complete(&res
->completion
);
108 static void test_hash(char *algo
, struct hash_testvec
*template,
111 unsigned int i
, j
, k
, temp
;
112 struct scatterlist sg
[8];
114 struct crypto_hash
*tfm
;
115 struct hash_desc desc
;
116 struct hash_testvec
*hash_tv
;
120 printk("\ntesting %s\n", algo
);
122 tsize
= sizeof(struct hash_testvec
);
125 if (tsize
> TVMEMSIZE
) {
126 printk("template (%u) too big for tvmem (%u)\n", tsize
, TVMEMSIZE
);
130 memcpy(tvmem
, template, tsize
);
131 hash_tv
= (void *)tvmem
;
133 tfm
= crypto_alloc_hash(algo
, 0, CRYPTO_ALG_ASYNC
);
135 printk("failed to load transform for %s: %ld\n", algo
,
143 for (i
= 0; i
< tcount
; i
++) {
144 printk("test %u:\n", i
+ 1);
145 memset(result
, 0, 64);
147 sg_init_one(&sg
[0], hash_tv
[i
].plaintext
, hash_tv
[i
].psize
);
149 if (hash_tv
[i
].ksize
) {
150 ret
= crypto_hash_setkey(tfm
, hash_tv
[i
].key
,
153 printk("setkey() failed ret=%d\n", ret
);
158 ret
= crypto_hash_digest(&desc
, sg
, hash_tv
[i
].psize
, result
);
160 printk("digest () failed ret=%d\n", ret
);
164 hexdump(result
, crypto_hash_digestsize(tfm
));
166 memcmp(result
, hash_tv
[i
].digest
,
167 crypto_hash_digestsize(tfm
)) ?
171 printk("testing %s across pages\n", algo
);
173 /* setup the dummy buffer first */
174 memset(xbuf
, 0, XBUFSIZE
);
175 memset(axbuf
, 0, XBUFSIZE
);
178 for (i
= 0; i
< tcount
; i
++) {
181 printk("test %u:\n", j
);
182 memset(result
, 0, 64);
185 sg_init_table(sg
, hash_tv
[i
].np
);
186 for (k
= 0; k
< hash_tv
[i
].np
; k
++) {
187 memcpy(&xbuf
[IDX
[k
]],
188 hash_tv
[i
].plaintext
+ temp
,
190 temp
+= hash_tv
[i
].tap
[k
];
191 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
195 if (hash_tv
[i
].ksize
) {
196 ret
= crypto_hash_setkey(tfm
, hash_tv
[i
].key
,
200 printk("setkey() failed ret=%d\n", ret
);
205 ret
= crypto_hash_digest(&desc
, sg
, hash_tv
[i
].psize
,
208 printk("digest () failed ret=%d\n", ret
);
212 hexdump(result
, crypto_hash_digestsize(tfm
));
214 memcmp(result
, hash_tv
[i
].digest
,
215 crypto_hash_digestsize(tfm
)) ?
221 crypto_free_hash(tfm
);
224 static void test_aead(char *algo
, int enc
, struct aead_testvec
*template,
227 unsigned int ret
, i
, j
, k
, temp
;
230 struct crypto_aead
*tfm
;
232 struct aead_testvec
*aead_tv
;
233 struct aead_request
*req
;
234 struct scatterlist sg
[8];
235 struct scatterlist asg
[8];
237 struct tcrypt_result result
;
238 unsigned int authsize
;
245 printk(KERN_INFO
"\ntesting %s %s\n", algo
, e
);
247 tsize
= sizeof(struct aead_testvec
);
250 if (tsize
> TVMEMSIZE
) {
251 printk(KERN_INFO
"template (%u) too big for tvmem (%u)\n",
256 memcpy(tvmem
, template, tsize
);
257 aead_tv
= (void *)tvmem
;
259 init_completion(&result
.completion
);
261 tfm
= crypto_alloc_aead(algo
, 0, 0);
264 printk(KERN_INFO
"failed to load transform for %s: %ld\n",
269 authsize
= crypto_aead_authsize(tfm
);
271 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
273 printk(KERN_INFO
"failed to allocate request for %s\n", algo
);
277 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
278 tcrypt_complete
, &result
);
280 for (i
= 0, j
= 0; i
< tcount
; i
++) {
281 if (!aead_tv
[i
].np
) {
282 printk(KERN_INFO
"test %u (%d bit key):\n",
283 ++j
, aead_tv
[i
].klen
* 8);
285 crypto_aead_clear_flags(tfm
, ~0);
287 crypto_aead_set_flags(
288 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
289 key
= aead_tv
[i
].key
;
291 ret
= crypto_aead_setkey(tfm
, key
,
294 printk(KERN_INFO
"setkey() failed flags=%x\n",
295 crypto_aead_get_flags(tfm
));
297 if (!aead_tv
[i
].fail
)
301 sg_init_one(&sg
[0], aead_tv
[i
].input
,
302 aead_tv
[i
].ilen
+ (enc
? authsize
: 0));
304 sg_init_one(&asg
[0], aead_tv
[i
].assoc
,
307 aead_request_set_crypt(req
, sg
, sg
,
311 aead_request_set_assoc(req
, asg
, aead_tv
[i
].alen
);
314 crypto_aead_encrypt(req
) :
315 crypto_aead_decrypt(req
);
322 ret
= wait_for_completion_interruptible(
324 if (!ret
&& !(ret
= result
.err
)) {
325 INIT_COMPLETION(result
.completion
);
330 printk(KERN_INFO
"%s () failed err=%d\n",
335 q
= kmap(sg_page(&sg
[0])) + sg
[0].offset
;
336 hexdump(q
, aead_tv
[i
].rlen
);
338 printk(KERN_INFO
"enc/dec: %s\n",
339 memcmp(q
, aead_tv
[i
].result
,
340 aead_tv
[i
].rlen
) ? "fail" : "pass");
344 printk(KERN_INFO
"\ntesting %s %s across pages (chunking)\n", algo
, e
);
345 memset(xbuf
, 0, XBUFSIZE
);
347 for (i
= 0, j
= 0; i
< tcount
; i
++) {
349 printk(KERN_INFO
"test %u (%d bit key):\n",
350 ++j
, aead_tv
[i
].klen
* 8);
352 crypto_aead_clear_flags(tfm
, ~0);
354 crypto_aead_set_flags(
355 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
356 key
= aead_tv
[i
].key
;
358 ret
= crypto_aead_setkey(tfm
, key
, aead_tv
[i
].klen
);
360 printk(KERN_INFO
"setkey() failed flags=%x\n",
361 crypto_aead_get_flags(tfm
));
363 if (!aead_tv
[i
].fail
)
367 sg_init_table(sg
, aead_tv
[i
].np
);
368 for (k
= 0, temp
= 0; k
< aead_tv
[i
].np
; k
++) {
369 memcpy(&xbuf
[IDX
[k
]],
370 aead_tv
[i
].input
+ temp
,
372 temp
+= aead_tv
[i
].tap
[k
];
373 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
378 sg
[k
- 1].length
+= authsize
;
380 sg_init_table(asg
, aead_tv
[i
].anp
);
381 for (k
= 0, temp
= 0; k
< aead_tv
[i
].anp
; k
++) {
382 memcpy(&axbuf
[IDX
[k
]],
383 aead_tv
[i
].assoc
+ temp
,
385 temp
+= aead_tv
[i
].atap
[k
];
386 sg_set_buf(&asg
[k
], &axbuf
[IDX
[k
]],
390 aead_request_set_crypt(req
, sg
, sg
,
394 aead_request_set_assoc(req
, asg
, aead_tv
[i
].alen
);
397 crypto_aead_encrypt(req
) :
398 crypto_aead_decrypt(req
);
405 ret
= wait_for_completion_interruptible(
407 if (!ret
&& !(ret
= result
.err
)) {
408 INIT_COMPLETION(result
.completion
);
413 printk(KERN_INFO
"%s () failed err=%d\n",
418 for (k
= 0, temp
= 0; k
< aead_tv
[i
].np
; k
++) {
419 printk(KERN_INFO
"page %u\n", k
);
420 q
= kmap(sg_page(&sg
[k
])) + sg
[k
].offset
;
421 hexdump(q
, aead_tv
[i
].tap
[k
]);
422 printk(KERN_INFO
"%s\n",
423 memcmp(q
, aead_tv
[i
].result
+ temp
,
425 (k
< aead_tv
[i
].np
- 1 || enc
?
429 temp
+= aead_tv
[i
].tap
[k
];
435 crypto_free_aead(tfm
);
436 aead_request_free(req
);
439 static void test_cipher(char *algo
, int enc
,
440 struct cipher_testvec
*template, unsigned int tcount
)
442 unsigned int ret
, i
, j
, k
, temp
;
445 struct crypto_ablkcipher
*tfm
;
447 struct cipher_testvec
*cipher_tv
;
448 struct ablkcipher_request
*req
;
449 struct scatterlist sg
[8];
451 struct tcrypt_result result
;
458 printk("\ntesting %s %s\n", algo
, e
);
460 tsize
= sizeof (struct cipher_testvec
);
461 if (tsize
> TVMEMSIZE
) {
462 printk("template (%u) too big for tvmem (%u)\n", tsize
,
466 cipher_tv
= (void *)tvmem
;
468 init_completion(&result
.completion
);
470 tfm
= crypto_alloc_ablkcipher(algo
, 0, 0);
473 printk("failed to load transform for %s: %ld\n", algo
,
478 req
= ablkcipher_request_alloc(tfm
, GFP_KERNEL
);
480 printk("failed to allocate request for %s\n", algo
);
484 ablkcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
485 tcrypt_complete
, &result
);
488 for (i
= 0; i
< tcount
; i
++) {
489 memcpy(cipher_tv
, &template[i
], tsize
);
490 if (!(cipher_tv
->np
)) {
492 printk("test %u (%d bit key):\n",
493 j
, cipher_tv
->klen
* 8);
495 crypto_ablkcipher_clear_flags(tfm
, ~0);
497 crypto_ablkcipher_set_flags(
498 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
499 key
= cipher_tv
->key
;
501 ret
= crypto_ablkcipher_setkey(tfm
, key
,
504 printk("setkey() failed flags=%x\n",
505 crypto_ablkcipher_get_flags(tfm
));
507 if (!cipher_tv
->fail
)
511 sg_init_one(&sg
[0], cipher_tv
->input
,
514 ablkcipher_request_set_crypt(req
, sg
, sg
,
519 crypto_ablkcipher_encrypt(req
) :
520 crypto_ablkcipher_decrypt(req
);
527 ret
= wait_for_completion_interruptible(
529 if (!ret
&& !((ret
= result
.err
))) {
530 INIT_COMPLETION(result
.completion
);
535 printk("%s () failed err=%d\n", e
, -ret
);
539 q
= kmap(sg_page(&sg
[0])) + sg
[0].offset
;
540 hexdump(q
, cipher_tv
->rlen
);
543 memcmp(q
, cipher_tv
->result
,
544 cipher_tv
->rlen
) ? "fail" : "pass");
548 printk("\ntesting %s %s across pages (chunking)\n", algo
, e
);
549 memset(xbuf
, 0, XBUFSIZE
);
552 for (i
= 0; i
< tcount
; i
++) {
553 memcpy(cipher_tv
, &template[i
], tsize
);
556 printk("test %u (%d bit key):\n",
557 j
, cipher_tv
->klen
* 8);
559 crypto_ablkcipher_clear_flags(tfm
, ~0);
561 crypto_ablkcipher_set_flags(
562 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
563 key
= cipher_tv
->key
;
565 ret
= crypto_ablkcipher_setkey(tfm
, key
,
568 printk("setkey() failed flags=%x\n",
569 crypto_ablkcipher_get_flags(tfm
));
571 if (!cipher_tv
->fail
)
576 sg_init_table(sg
, cipher_tv
->np
);
577 for (k
= 0; k
< cipher_tv
->np
; k
++) {
578 memcpy(&xbuf
[IDX
[k
]],
579 cipher_tv
->input
+ temp
,
581 temp
+= cipher_tv
->tap
[k
];
582 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
586 ablkcipher_request_set_crypt(req
, sg
, sg
,
591 crypto_ablkcipher_encrypt(req
) :
592 crypto_ablkcipher_decrypt(req
);
599 ret
= wait_for_completion_interruptible(
601 if (!ret
&& !((ret
= result
.err
))) {
602 INIT_COMPLETION(result
.completion
);
607 printk("%s () failed err=%d\n", e
, -ret
);
612 for (k
= 0; k
< cipher_tv
->np
; k
++) {
613 printk("page %u\n", k
);
614 q
= kmap(sg_page(&sg
[k
])) + sg
[k
].offset
;
615 hexdump(q
, cipher_tv
->tap
[k
]);
617 memcmp(q
, cipher_tv
->result
+ temp
,
618 cipher_tv
->tap
[k
]) ? "fail" :
620 temp
+= cipher_tv
->tap
[k
];
626 crypto_free_ablkcipher(tfm
);
627 ablkcipher_request_free(req
);
630 static int test_cipher_jiffies(struct blkcipher_desc
*desc
, int enc
, char *p
,
633 struct scatterlist sg
[1];
634 unsigned long start
, end
;
638 sg_init_one(sg
, p
, blen
);
640 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
641 time_before(jiffies
, end
); bcount
++) {
643 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
645 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
651 printk("%d operations in %d seconds (%ld bytes)\n",
652 bcount
, sec
, (long)bcount
* blen
);
656 static int test_cipher_cycles(struct blkcipher_desc
*desc
, int enc
, char *p
,
659 struct scatterlist sg
[1];
660 unsigned long cycles
= 0;
664 sg_init_one(sg
, p
, blen
);
670 for (i
= 0; i
< 4; i
++) {
672 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
674 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
680 /* The real thing. */
681 for (i
= 0; i
< 8; i
++) {
684 start
= get_cycles();
686 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
688 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
694 cycles
+= end
- start
;
702 printk("1 operation in %lu cycles (%d bytes)\n",
703 (cycles
+ 4) / 8, blen
);
708 static void test_cipher_speed(char *algo
, int enc
, unsigned int sec
,
709 struct cipher_testvec
*template,
710 unsigned int tcount
, struct cipher_speed
*speed
)
712 unsigned int ret
, i
, j
, iv_len
;
713 unsigned char *key
, *p
, iv
[128];
714 struct crypto_blkcipher
*tfm
;
715 struct blkcipher_desc desc
;
723 printk("\ntesting speed of %s %s\n", algo
, e
);
725 tfm
= crypto_alloc_blkcipher(algo
, 0, CRYPTO_ALG_ASYNC
);
728 printk("failed to load transform for %s: %ld\n", algo
,
735 for (i
= 0; speed
[i
].klen
!= 0; i
++) {
736 if ((speed
[i
].blen
+ speed
[i
].klen
) > TVMEMSIZE
) {
737 printk("template (%u) too big for tvmem (%u)\n",
738 speed
[i
].blen
+ speed
[i
].klen
, TVMEMSIZE
);
742 printk("test %u (%d bit key, %d byte blocks): ", i
,
743 speed
[i
].klen
* 8, speed
[i
].blen
);
745 memset(tvmem
, 0xff, speed
[i
].klen
+ speed
[i
].blen
);
747 /* set key, plain text and IV */
748 key
= (unsigned char *)tvmem
;
749 for (j
= 0; j
< tcount
; j
++) {
750 if (template[j
].klen
== speed
[i
].klen
) {
751 key
= template[j
].key
;
755 p
= (unsigned char *)tvmem
+ speed
[i
].klen
;
757 ret
= crypto_blkcipher_setkey(tfm
, key
, speed
[i
].klen
);
759 printk("setkey() failed flags=%x\n",
760 crypto_blkcipher_get_flags(tfm
));
764 iv_len
= crypto_blkcipher_ivsize(tfm
);
766 memset(&iv
, 0xff, iv_len
);
767 crypto_blkcipher_set_iv(tfm
, iv
, iv_len
);
771 ret
= test_cipher_jiffies(&desc
, enc
, p
, speed
[i
].blen
,
774 ret
= test_cipher_cycles(&desc
, enc
, p
, speed
[i
].blen
);
777 printk("%s() failed flags=%x\n", e
, desc
.flags
);
783 crypto_free_blkcipher(tfm
);
786 static int test_hash_jiffies_digest(struct hash_desc
*desc
, char *p
, int blen
,
789 struct scatterlist sg
[1];
790 unsigned long start
, end
;
794 sg_init_table(sg
, 1);
796 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
797 time_before(jiffies
, end
); bcount
++) {
798 sg_set_buf(sg
, p
, blen
);
799 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
804 printk("%6u opers/sec, %9lu bytes/sec\n",
805 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
810 static int test_hash_jiffies(struct hash_desc
*desc
, char *p
, int blen
,
811 int plen
, char *out
, int sec
)
813 struct scatterlist sg
[1];
814 unsigned long start
, end
;
819 return test_hash_jiffies_digest(desc
, p
, blen
, out
, sec
);
821 sg_init_table(sg
, 1);
823 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
824 time_before(jiffies
, end
); bcount
++) {
825 ret
= crypto_hash_init(desc
);
828 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
829 sg_set_buf(sg
, p
+ pcount
, plen
);
830 ret
= crypto_hash_update(desc
, sg
, plen
);
834 /* we assume there is enough space in 'out' for the result */
835 ret
= crypto_hash_final(desc
, out
);
840 printk("%6u opers/sec, %9lu bytes/sec\n",
841 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
846 static int test_hash_cycles_digest(struct hash_desc
*desc
, char *p
, int blen
,
849 struct scatterlist sg
[1];
850 unsigned long cycles
= 0;
854 sg_init_table(sg
, 1);
860 for (i
= 0; i
< 4; i
++) {
861 sg_set_buf(sg
, p
, blen
);
862 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
867 /* The real thing. */
868 for (i
= 0; i
< 8; i
++) {
871 start
= get_cycles();
873 sg_set_buf(sg
, p
, blen
);
874 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
880 cycles
+= end
- start
;
890 printk("%6lu cycles/operation, %4lu cycles/byte\n",
891 cycles
/ 8, cycles
/ (8 * blen
));
896 static int test_hash_cycles(struct hash_desc
*desc
, char *p
, int blen
,
899 struct scatterlist sg
[1];
900 unsigned long cycles
= 0;
905 return test_hash_cycles_digest(desc
, p
, blen
, out
);
907 sg_init_table(sg
, 1);
913 for (i
= 0; i
< 4; i
++) {
914 ret
= crypto_hash_init(desc
);
917 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
918 sg_set_buf(sg
, p
+ pcount
, plen
);
919 ret
= crypto_hash_update(desc
, sg
, plen
);
923 ret
= crypto_hash_final(desc
, out
);
928 /* The real thing. */
929 for (i
= 0; i
< 8; i
++) {
932 start
= get_cycles();
934 ret
= crypto_hash_init(desc
);
937 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
938 sg_set_buf(sg
, p
+ pcount
, plen
);
939 ret
= crypto_hash_update(desc
, sg
, plen
);
943 ret
= crypto_hash_final(desc
, out
);
949 cycles
+= end
- start
;
959 printk("%6lu cycles/operation, %4lu cycles/byte\n",
960 cycles
/ 8, cycles
/ (8 * blen
));
965 static void test_hash_speed(char *algo
, unsigned int sec
,
966 struct hash_speed
*speed
)
968 struct crypto_hash
*tfm
;
969 struct hash_desc desc
;
974 printk("\ntesting speed of %s\n", algo
);
976 tfm
= crypto_alloc_hash(algo
, 0, CRYPTO_ALG_ASYNC
);
979 printk("failed to load transform for %s: %ld\n", algo
,
987 if (crypto_hash_digestsize(tfm
) > sizeof(output
)) {
988 printk("digestsize(%u) > outputbuffer(%zu)\n",
989 crypto_hash_digestsize(tfm
), sizeof(output
));
993 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
994 if (speed
[i
].blen
> TVMEMSIZE
) {
995 printk("template (%u) too big for tvmem (%u)\n",
996 speed
[i
].blen
, TVMEMSIZE
);
1000 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
1001 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
1003 memset(tvmem
, 0xff, speed
[i
].blen
);
1006 ret
= test_hash_jiffies(&desc
, tvmem
, speed
[i
].blen
,
1007 speed
[i
].plen
, output
, sec
);
1009 ret
= test_hash_cycles(&desc
, tvmem
, speed
[i
].blen
,
1010 speed
[i
].plen
, output
);
1013 printk("hashing failed ret=%d\n", ret
);
1019 crypto_free_hash(tfm
);
1022 static void test_comp(char *algo
, struct comp_testvec
*ctemplate
,
1023 struct comp_testvec
*dtemplate
, int ctcount
, int dtcount
)
1026 char result
[COMP_BUF_SIZE
];
1027 struct crypto_comp
*tfm
;
1028 struct comp_testvec
*tv
;
1031 printk("\ntesting %s compression\n", algo
);
1033 tsize
= sizeof(struct comp_testvec
);
1035 if (tsize
> TVMEMSIZE
) {
1036 printk("template (%u) too big for tvmem (%u)\n", tsize
,
1041 memcpy(tvmem
, ctemplate
, tsize
);
1044 tfm
= crypto_alloc_comp(algo
, 0, CRYPTO_ALG_ASYNC
);
1046 printk("failed to load transform for %s\n", algo
);
1050 for (i
= 0; i
< ctcount
; i
++) {
1051 int ilen
, ret
, dlen
= COMP_BUF_SIZE
;
1053 printk("test %u:\n", i
+ 1);
1054 memset(result
, 0, sizeof (result
));
1057 ret
= crypto_comp_compress(tfm
, tv
[i
].input
,
1058 ilen
, result
, &dlen
);
1060 printk("fail: ret=%d\n", ret
);
1063 hexdump(result
, dlen
);
1064 printk("%s (ratio %d:%d)\n",
1065 memcmp(result
, tv
[i
].output
, dlen
) ? "fail" : "pass",
1069 printk("\ntesting %s decompression\n", algo
);
1071 tsize
= sizeof(struct comp_testvec
);
1073 if (tsize
> TVMEMSIZE
) {
1074 printk("template (%u) too big for tvmem (%u)\n", tsize
,
1079 memcpy(tvmem
, dtemplate
, tsize
);
1082 for (i
= 0; i
< dtcount
; i
++) {
1083 int ilen
, ret
, dlen
= COMP_BUF_SIZE
;
1085 printk("test %u:\n", i
+ 1);
1086 memset(result
, 0, sizeof (result
));
1089 ret
= crypto_comp_decompress(tfm
, tv
[i
].input
,
1090 ilen
, result
, &dlen
);
1092 printk("fail: ret=%d\n", ret
);
1095 hexdump(result
, dlen
);
1096 printk("%s (ratio %d:%d)\n",
1097 memcmp(result
, tv
[i
].output
, dlen
) ? "fail" : "pass",
1101 crypto_free_comp(tfm
);
1104 static void test_available(void)
1106 char **name
= check
;
1109 printk("alg %s ", *name
);
1110 printk(crypto_has_alg(*name
, 0, 0) ?
1111 "found\n" : "not found\n");
1116 static void do_test(void)
1121 test_hash("md5", md5_tv_template
, MD5_TEST_VECTORS
);
1123 test_hash("sha1", sha1_tv_template
, SHA1_TEST_VECTORS
);
1126 test_cipher("ecb(des)", ENCRYPT
, des_enc_tv_template
,
1127 DES_ENC_TEST_VECTORS
);
1128 test_cipher("ecb(des)", DECRYPT
, des_dec_tv_template
,
1129 DES_DEC_TEST_VECTORS
);
1130 test_cipher("cbc(des)", ENCRYPT
, des_cbc_enc_tv_template
,
1131 DES_CBC_ENC_TEST_VECTORS
);
1132 test_cipher("cbc(des)", DECRYPT
, des_cbc_dec_tv_template
,
1133 DES_CBC_DEC_TEST_VECTORS
);
1136 test_cipher("ecb(des3_ede)", ENCRYPT
, des3_ede_enc_tv_template
,
1137 DES3_EDE_ENC_TEST_VECTORS
);
1138 test_cipher("ecb(des3_ede)", DECRYPT
, des3_ede_dec_tv_template
,
1139 DES3_EDE_DEC_TEST_VECTORS
);
1141 test_hash("md4", md4_tv_template
, MD4_TEST_VECTORS
);
1143 test_hash("sha224", sha224_tv_template
, SHA224_TEST_VECTORS
);
1145 test_hash("sha256", sha256_tv_template
, SHA256_TEST_VECTORS
);
1148 test_cipher("ecb(blowfish)", ENCRYPT
, bf_enc_tv_template
,
1149 BF_ENC_TEST_VECTORS
);
1150 test_cipher("ecb(blowfish)", DECRYPT
, bf_dec_tv_template
,
1151 BF_DEC_TEST_VECTORS
);
1152 test_cipher("cbc(blowfish)", ENCRYPT
, bf_cbc_enc_tv_template
,
1153 BF_CBC_ENC_TEST_VECTORS
);
1154 test_cipher("cbc(blowfish)", DECRYPT
, bf_cbc_dec_tv_template
,
1155 BF_CBC_DEC_TEST_VECTORS
);
1158 test_cipher("ecb(twofish)", ENCRYPT
, tf_enc_tv_template
,
1159 TF_ENC_TEST_VECTORS
);
1160 test_cipher("ecb(twofish)", DECRYPT
, tf_dec_tv_template
,
1161 TF_DEC_TEST_VECTORS
);
1162 test_cipher("cbc(twofish)", ENCRYPT
, tf_cbc_enc_tv_template
,
1163 TF_CBC_ENC_TEST_VECTORS
);
1164 test_cipher("cbc(twofish)", DECRYPT
, tf_cbc_dec_tv_template
,
1165 TF_CBC_DEC_TEST_VECTORS
);
1168 test_cipher("ecb(serpent)", ENCRYPT
, serpent_enc_tv_template
,
1169 SERPENT_ENC_TEST_VECTORS
);
1170 test_cipher("ecb(serpent)", DECRYPT
, serpent_dec_tv_template
,
1171 SERPENT_DEC_TEST_VECTORS
);
1174 test_cipher("ecb(tnepres)", ENCRYPT
, tnepres_enc_tv_template
,
1175 TNEPRES_ENC_TEST_VECTORS
);
1176 test_cipher("ecb(tnepres)", DECRYPT
, tnepres_dec_tv_template
,
1177 TNEPRES_DEC_TEST_VECTORS
);
1180 test_cipher("ecb(aes)", ENCRYPT
, aes_enc_tv_template
,
1181 AES_ENC_TEST_VECTORS
);
1182 test_cipher("ecb(aes)", DECRYPT
, aes_dec_tv_template
,
1183 AES_DEC_TEST_VECTORS
);
1184 test_cipher("cbc(aes)", ENCRYPT
, aes_cbc_enc_tv_template
,
1185 AES_CBC_ENC_TEST_VECTORS
);
1186 test_cipher("cbc(aes)", DECRYPT
, aes_cbc_dec_tv_template
,
1187 AES_CBC_DEC_TEST_VECTORS
);
1188 test_cipher("lrw(aes)", ENCRYPT
, aes_lrw_enc_tv_template
,
1189 AES_LRW_ENC_TEST_VECTORS
);
1190 test_cipher("lrw(aes)", DECRYPT
, aes_lrw_dec_tv_template
,
1191 AES_LRW_DEC_TEST_VECTORS
);
1192 test_cipher("xts(aes)", ENCRYPT
, aes_xts_enc_tv_template
,
1193 AES_XTS_ENC_TEST_VECTORS
);
1194 test_cipher("xts(aes)", DECRYPT
, aes_xts_dec_tv_template
,
1195 AES_XTS_DEC_TEST_VECTORS
);
1196 test_cipher("ctr(aes,4,8,4)", ENCRYPT
, aes_ctr_enc_tv_template
,
1197 AES_CTR_ENC_TEST_VECTORS
);
1198 test_cipher("ctr(aes,4,8,4)", DECRYPT
, aes_ctr_dec_tv_template
,
1199 AES_CTR_DEC_TEST_VECTORS
);
1200 test_aead("gcm(aes)", ENCRYPT
, aes_gcm_enc_tv_template
,
1201 AES_GCM_ENC_TEST_VECTORS
);
1202 test_aead("gcm(aes)", DECRYPT
, aes_gcm_dec_tv_template
,
1203 AES_GCM_DEC_TEST_VECTORS
);
1206 test_cipher("ecb(cast5)", ENCRYPT
, cast5_enc_tv_template
,
1207 CAST5_ENC_TEST_VECTORS
);
1208 test_cipher("ecb(cast5)", DECRYPT
, cast5_dec_tv_template
,
1209 CAST5_DEC_TEST_VECTORS
);
1212 test_cipher("ecb(cast6)", ENCRYPT
, cast6_enc_tv_template
,
1213 CAST6_ENC_TEST_VECTORS
);
1214 test_cipher("ecb(cast6)", DECRYPT
, cast6_dec_tv_template
,
1215 CAST6_DEC_TEST_VECTORS
);
1218 test_cipher("ecb(arc4)", ENCRYPT
, arc4_enc_tv_template
,
1219 ARC4_ENC_TEST_VECTORS
);
1220 test_cipher("ecb(arc4)", DECRYPT
, arc4_dec_tv_template
,
1221 ARC4_DEC_TEST_VECTORS
);
1224 test_cipher("ecb(tea)", ENCRYPT
, tea_enc_tv_template
,
1225 TEA_ENC_TEST_VECTORS
);
1226 test_cipher("ecb(tea)", DECRYPT
, tea_dec_tv_template
,
1227 TEA_DEC_TEST_VECTORS
);
1231 test_cipher("ecb(xtea)", ENCRYPT
, xtea_enc_tv_template
,
1232 XTEA_ENC_TEST_VECTORS
);
1233 test_cipher("ecb(xtea)", DECRYPT
, xtea_dec_tv_template
,
1234 XTEA_DEC_TEST_VECTORS
);
1237 test_cipher("ecb(khazad)", ENCRYPT
, khazad_enc_tv_template
,
1238 KHAZAD_ENC_TEST_VECTORS
);
1239 test_cipher("ecb(khazad)", DECRYPT
, khazad_dec_tv_template
,
1240 KHAZAD_DEC_TEST_VECTORS
);
1243 test_cipher("ecb(anubis)", ENCRYPT
, anubis_enc_tv_template
,
1244 ANUBIS_ENC_TEST_VECTORS
);
1245 test_cipher("ecb(anubis)", DECRYPT
, anubis_dec_tv_template
,
1246 ANUBIS_DEC_TEST_VECTORS
);
1247 test_cipher("cbc(anubis)", ENCRYPT
, anubis_cbc_enc_tv_template
,
1248 ANUBIS_CBC_ENC_TEST_VECTORS
);
1249 test_cipher("cbc(anubis)", DECRYPT
, anubis_cbc_dec_tv_template
,
1250 ANUBIS_CBC_ENC_TEST_VECTORS
);
1253 test_cipher("ecb(xeta)", ENCRYPT
, xeta_enc_tv_template
,
1254 XETA_ENC_TEST_VECTORS
);
1255 test_cipher("ecb(xeta)", DECRYPT
, xeta_dec_tv_template
,
1256 XETA_DEC_TEST_VECTORS
);
1259 test_cipher("pcbc(fcrypt)", ENCRYPT
, fcrypt_pcbc_enc_tv_template
,
1260 FCRYPT_ENC_TEST_VECTORS
);
1261 test_cipher("pcbc(fcrypt)", DECRYPT
, fcrypt_pcbc_dec_tv_template
,
1262 FCRYPT_DEC_TEST_VECTORS
);
1265 test_cipher("ecb(camellia)", ENCRYPT
,
1266 camellia_enc_tv_template
,
1267 CAMELLIA_ENC_TEST_VECTORS
);
1268 test_cipher("ecb(camellia)", DECRYPT
,
1269 camellia_dec_tv_template
,
1270 CAMELLIA_DEC_TEST_VECTORS
);
1271 test_cipher("cbc(camellia)", ENCRYPT
,
1272 camellia_cbc_enc_tv_template
,
1273 CAMELLIA_CBC_ENC_TEST_VECTORS
);
1274 test_cipher("cbc(camellia)", DECRYPT
,
1275 camellia_cbc_dec_tv_template
,
1276 CAMELLIA_CBC_DEC_TEST_VECTORS
);
1279 test_cipher("ecb(seed)", ENCRYPT
, seed_enc_tv_template
,
1280 SEED_ENC_TEST_VECTORS
);
1281 test_cipher("ecb(seed)", DECRYPT
, seed_dec_tv_template
,
1282 SEED_DEC_TEST_VECTORS
);
1284 test_hash("sha384", sha384_tv_template
, SHA384_TEST_VECTORS
);
1285 test_hash("sha512", sha512_tv_template
, SHA512_TEST_VECTORS
);
1286 test_hash("wp512", wp512_tv_template
, WP512_TEST_VECTORS
);
1287 test_hash("wp384", wp384_tv_template
, WP384_TEST_VECTORS
);
1288 test_hash("wp256", wp256_tv_template
, WP256_TEST_VECTORS
);
1289 test_hash("tgr192", tgr192_tv_template
, TGR192_TEST_VECTORS
);
1290 test_hash("tgr160", tgr160_tv_template
, TGR160_TEST_VECTORS
);
1291 test_hash("tgr128", tgr128_tv_template
, TGR128_TEST_VECTORS
);
1292 test_comp("deflate", deflate_comp_tv_template
,
1293 deflate_decomp_tv_template
, DEFLATE_COMP_TEST_VECTORS
,
1294 DEFLATE_DECOMP_TEST_VECTORS
);
1295 test_comp("lzo", lzo_comp_tv_template
, lzo_decomp_tv_template
,
1296 LZO_COMP_TEST_VECTORS
, LZO_DECOMP_TEST_VECTORS
);
1297 test_hash("crc32c", crc32c_tv_template
, CRC32C_TEST_VECTORS
);
1298 test_hash("hmac(md5)", hmac_md5_tv_template
,
1299 HMAC_MD5_TEST_VECTORS
);
1300 test_hash("hmac(sha1)", hmac_sha1_tv_template
,
1301 HMAC_SHA1_TEST_VECTORS
);
1302 test_hash("hmac(sha224)", hmac_sha224_tv_template
,
1303 HMAC_SHA224_TEST_VECTORS
);
1304 test_hash("hmac(sha256)", hmac_sha256_tv_template
,
1305 HMAC_SHA256_TEST_VECTORS
);
1306 test_hash("hmac(sha384)", hmac_sha384_tv_template
,
1307 HMAC_SHA384_TEST_VECTORS
);
1308 test_hash("hmac(sha512)", hmac_sha512_tv_template
,
1309 HMAC_SHA512_TEST_VECTORS
);
1311 test_hash("xcbc(aes)", aes_xcbc128_tv_template
,
1312 XCBC_AES_TEST_VECTORS
);
1314 test_hash("michael_mic", michael_mic_tv_template
, MICHAEL_MIC_TEST_VECTORS
);
1318 test_hash("md5", md5_tv_template
, MD5_TEST_VECTORS
);
1322 test_hash("sha1", sha1_tv_template
, SHA1_TEST_VECTORS
);
1326 test_cipher("ecb(des)", ENCRYPT
, des_enc_tv_template
,
1327 DES_ENC_TEST_VECTORS
);
1328 test_cipher("ecb(des)", DECRYPT
, des_dec_tv_template
,
1329 DES_DEC_TEST_VECTORS
);
1330 test_cipher("cbc(des)", ENCRYPT
, des_cbc_enc_tv_template
,
1331 DES_CBC_ENC_TEST_VECTORS
);
1332 test_cipher("cbc(des)", DECRYPT
, des_cbc_dec_tv_template
,
1333 DES_CBC_DEC_TEST_VECTORS
);
1337 test_cipher("ecb(des3_ede)", ENCRYPT
, des3_ede_enc_tv_template
,
1338 DES3_EDE_ENC_TEST_VECTORS
);
1339 test_cipher("ecb(des3_ede)", DECRYPT
, des3_ede_dec_tv_template
,
1340 DES3_EDE_DEC_TEST_VECTORS
);
1344 test_hash("md4", md4_tv_template
, MD4_TEST_VECTORS
);
1348 test_hash("sha256", sha256_tv_template
, SHA256_TEST_VECTORS
);
1352 test_cipher("ecb(blowfish)", ENCRYPT
, bf_enc_tv_template
,
1353 BF_ENC_TEST_VECTORS
);
1354 test_cipher("ecb(blowfish)", DECRYPT
, bf_dec_tv_template
,
1355 BF_DEC_TEST_VECTORS
);
1356 test_cipher("cbc(blowfish)", ENCRYPT
, bf_cbc_enc_tv_template
,
1357 BF_CBC_ENC_TEST_VECTORS
);
1358 test_cipher("cbc(blowfish)", DECRYPT
, bf_cbc_dec_tv_template
,
1359 BF_CBC_DEC_TEST_VECTORS
);
1363 test_cipher("ecb(twofish)", ENCRYPT
, tf_enc_tv_template
,
1364 TF_ENC_TEST_VECTORS
);
1365 test_cipher("ecb(twofish)", DECRYPT
, tf_dec_tv_template
,
1366 TF_DEC_TEST_VECTORS
);
1367 test_cipher("cbc(twofish)", ENCRYPT
, tf_cbc_enc_tv_template
,
1368 TF_CBC_ENC_TEST_VECTORS
);
1369 test_cipher("cbc(twofish)", DECRYPT
, tf_cbc_dec_tv_template
,
1370 TF_CBC_DEC_TEST_VECTORS
);
1374 test_cipher("ecb(serpent)", ENCRYPT
, serpent_enc_tv_template
,
1375 SERPENT_ENC_TEST_VECTORS
);
1376 test_cipher("ecb(serpent)", DECRYPT
, serpent_dec_tv_template
,
1377 SERPENT_DEC_TEST_VECTORS
);
1381 test_cipher("ecb(aes)", ENCRYPT
, aes_enc_tv_template
,
1382 AES_ENC_TEST_VECTORS
);
1383 test_cipher("ecb(aes)", DECRYPT
, aes_dec_tv_template
,
1384 AES_DEC_TEST_VECTORS
);
1385 test_cipher("cbc(aes)", ENCRYPT
, aes_cbc_enc_tv_template
,
1386 AES_CBC_ENC_TEST_VECTORS
);
1387 test_cipher("cbc(aes)", DECRYPT
, aes_cbc_dec_tv_template
,
1388 AES_CBC_DEC_TEST_VECTORS
);
1389 test_cipher("lrw(aes)", ENCRYPT
, aes_lrw_enc_tv_template
,
1390 AES_LRW_ENC_TEST_VECTORS
);
1391 test_cipher("lrw(aes)", DECRYPT
, aes_lrw_dec_tv_template
,
1392 AES_LRW_DEC_TEST_VECTORS
);
1393 test_cipher("xts(aes)", ENCRYPT
, aes_xts_enc_tv_template
,
1394 AES_XTS_ENC_TEST_VECTORS
);
1395 test_cipher("xts(aes)", DECRYPT
, aes_xts_dec_tv_template
,
1396 AES_XTS_DEC_TEST_VECTORS
);
1397 test_cipher("ctr(aes,4,8,4)", ENCRYPT
, aes_ctr_enc_tv_template
,
1398 AES_CTR_ENC_TEST_VECTORS
);
1399 test_cipher("ctr(aes,4,8,4)", DECRYPT
, aes_ctr_dec_tv_template
,
1400 AES_CTR_DEC_TEST_VECTORS
);
1404 test_hash("sha384", sha384_tv_template
, SHA384_TEST_VECTORS
);
1408 test_hash("sha512", sha512_tv_template
, SHA512_TEST_VECTORS
);
1412 test_comp("deflate", deflate_comp_tv_template
,
1413 deflate_decomp_tv_template
, DEFLATE_COMP_TEST_VECTORS
,
1414 DEFLATE_DECOMP_TEST_VECTORS
);
1418 test_cipher("ecb(cast5)", ENCRYPT
, cast5_enc_tv_template
,
1419 CAST5_ENC_TEST_VECTORS
);
1420 test_cipher("ecb(cast5)", DECRYPT
, cast5_dec_tv_template
,
1421 CAST5_DEC_TEST_VECTORS
);
1425 test_cipher("ecb(cast6)", ENCRYPT
, cast6_enc_tv_template
,
1426 CAST6_ENC_TEST_VECTORS
);
1427 test_cipher("ecb(cast6)", DECRYPT
, cast6_dec_tv_template
,
1428 CAST6_DEC_TEST_VECTORS
);
1432 test_cipher("ecb(arc4)", ENCRYPT
, arc4_enc_tv_template
,
1433 ARC4_ENC_TEST_VECTORS
);
1434 test_cipher("ecb(arc4)", DECRYPT
, arc4_dec_tv_template
,
1435 ARC4_DEC_TEST_VECTORS
);
1439 test_hash("michael_mic", michael_mic_tv_template
, MICHAEL_MIC_TEST_VECTORS
);
1443 test_hash("crc32c", crc32c_tv_template
, CRC32C_TEST_VECTORS
);
1447 test_cipher("ecb(tea)", ENCRYPT
, tea_enc_tv_template
,
1448 TEA_ENC_TEST_VECTORS
);
1449 test_cipher("ecb(tea)", DECRYPT
, tea_dec_tv_template
,
1450 TEA_DEC_TEST_VECTORS
);
1454 test_cipher("ecb(xtea)", ENCRYPT
, xtea_enc_tv_template
,
1455 XTEA_ENC_TEST_VECTORS
);
1456 test_cipher("ecb(xtea)", DECRYPT
, xtea_dec_tv_template
,
1457 XTEA_DEC_TEST_VECTORS
);
1461 test_cipher("ecb(khazad)", ENCRYPT
, khazad_enc_tv_template
,
1462 KHAZAD_ENC_TEST_VECTORS
);
1463 test_cipher("ecb(khazad)", DECRYPT
, khazad_dec_tv_template
,
1464 KHAZAD_DEC_TEST_VECTORS
);
1468 test_hash("wp512", wp512_tv_template
, WP512_TEST_VECTORS
);
1472 test_hash("wp384", wp384_tv_template
, WP384_TEST_VECTORS
);
1476 test_hash("wp256", wp256_tv_template
, WP256_TEST_VECTORS
);
1480 test_cipher("ecb(tnepres)", ENCRYPT
, tnepres_enc_tv_template
,
1481 TNEPRES_ENC_TEST_VECTORS
);
1482 test_cipher("ecb(tnepres)", DECRYPT
, tnepres_dec_tv_template
,
1483 TNEPRES_DEC_TEST_VECTORS
);
1487 test_cipher("ecb(anubis)", ENCRYPT
, anubis_enc_tv_template
,
1488 ANUBIS_ENC_TEST_VECTORS
);
1489 test_cipher("ecb(anubis)", DECRYPT
, anubis_dec_tv_template
,
1490 ANUBIS_DEC_TEST_VECTORS
);
1491 test_cipher("cbc(anubis)", ENCRYPT
, anubis_cbc_enc_tv_template
,
1492 ANUBIS_CBC_ENC_TEST_VECTORS
);
1493 test_cipher("cbc(anubis)", DECRYPT
, anubis_cbc_dec_tv_template
,
1494 ANUBIS_CBC_ENC_TEST_VECTORS
);
1498 test_hash("tgr192", tgr192_tv_template
, TGR192_TEST_VECTORS
);
1503 test_hash("tgr160", tgr160_tv_template
, TGR160_TEST_VECTORS
);
1507 test_hash("tgr128", tgr128_tv_template
, TGR128_TEST_VECTORS
);
1511 test_cipher("ecb(xeta)", ENCRYPT
, xeta_enc_tv_template
,
1512 XETA_ENC_TEST_VECTORS
);
1513 test_cipher("ecb(xeta)", DECRYPT
, xeta_dec_tv_template
,
1514 XETA_DEC_TEST_VECTORS
);
1518 test_cipher("pcbc(fcrypt)", ENCRYPT
, fcrypt_pcbc_enc_tv_template
,
1519 FCRYPT_ENC_TEST_VECTORS
);
1520 test_cipher("pcbc(fcrypt)", DECRYPT
, fcrypt_pcbc_dec_tv_template
,
1521 FCRYPT_DEC_TEST_VECTORS
);
1525 test_cipher("ecb(camellia)", ENCRYPT
,
1526 camellia_enc_tv_template
,
1527 CAMELLIA_ENC_TEST_VECTORS
);
1528 test_cipher("ecb(camellia)", DECRYPT
,
1529 camellia_dec_tv_template
,
1530 CAMELLIA_DEC_TEST_VECTORS
);
1531 test_cipher("cbc(camellia)", ENCRYPT
,
1532 camellia_cbc_enc_tv_template
,
1533 CAMELLIA_CBC_ENC_TEST_VECTORS
);
1534 test_cipher("cbc(camellia)", DECRYPT
,
1535 camellia_cbc_dec_tv_template
,
1536 CAMELLIA_CBC_DEC_TEST_VECTORS
);
1539 test_hash("sha224", sha224_tv_template
, SHA224_TEST_VECTORS
);
1543 test_cipher("salsa20", ENCRYPT
,
1544 salsa20_stream_enc_tv_template
,
1545 SALSA20_STREAM_ENC_TEST_VECTORS
);
1549 test_aead("gcm(aes)", ENCRYPT
, aes_gcm_enc_tv_template
,
1550 AES_GCM_ENC_TEST_VECTORS
);
1551 test_aead("gcm(aes)", DECRYPT
, aes_gcm_dec_tv_template
,
1552 AES_GCM_DEC_TEST_VECTORS
);
1556 test_comp("lzo", lzo_comp_tv_template
, lzo_decomp_tv_template
,
1557 LZO_COMP_TEST_VECTORS
, LZO_DECOMP_TEST_VECTORS
);
1561 test_hash("hmac(md5)", hmac_md5_tv_template
,
1562 HMAC_MD5_TEST_VECTORS
);
1566 test_hash("hmac(sha1)", hmac_sha1_tv_template
,
1567 HMAC_SHA1_TEST_VECTORS
);
1571 test_hash("hmac(sha256)", hmac_sha256_tv_template
,
1572 HMAC_SHA256_TEST_VECTORS
);
1576 test_hash("hmac(sha384)", hmac_sha384_tv_template
,
1577 HMAC_SHA384_TEST_VECTORS
);
1581 test_hash("hmac(sha512)", hmac_sha512_tv_template
,
1582 HMAC_SHA512_TEST_VECTORS
);
1585 test_hash("hmac(sha224)", hmac_sha224_tv_template
,
1586 HMAC_SHA224_TEST_VECTORS
);
1590 test_cipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1591 aes_speed_template
);
1592 test_cipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1593 aes_speed_template
);
1594 test_cipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1595 aes_speed_template
);
1596 test_cipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1597 aes_speed_template
);
1598 test_cipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1599 aes_lrw_speed_template
);
1600 test_cipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1601 aes_lrw_speed_template
);
1602 test_cipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1603 aes_xts_speed_template
);
1604 test_cipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1605 aes_xts_speed_template
);
1609 test_cipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1610 des3_ede_enc_tv_template
,
1611 DES3_EDE_ENC_TEST_VECTORS
,
1612 des3_ede_speed_template
);
1613 test_cipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1614 des3_ede_dec_tv_template
,
1615 DES3_EDE_DEC_TEST_VECTORS
,
1616 des3_ede_speed_template
);
1617 test_cipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1618 des3_ede_enc_tv_template
,
1619 DES3_EDE_ENC_TEST_VECTORS
,
1620 des3_ede_speed_template
);
1621 test_cipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1622 des3_ede_dec_tv_template
,
1623 DES3_EDE_DEC_TEST_VECTORS
,
1624 des3_ede_speed_template
);
1628 test_cipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1629 twofish_speed_template
);
1630 test_cipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1631 twofish_speed_template
);
1632 test_cipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1633 twofish_speed_template
);
1634 test_cipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1635 twofish_speed_template
);
1639 test_cipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1640 blowfish_speed_template
);
1641 test_cipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
1642 blowfish_speed_template
);
1643 test_cipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1644 blowfish_speed_template
);
1645 test_cipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
1646 blowfish_speed_template
);
1650 test_cipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1651 des_speed_template
);
1652 test_cipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1653 des_speed_template
);
1654 test_cipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1655 des_speed_template
);
1656 test_cipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1657 des_speed_template
);
1661 test_cipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
1662 camellia_speed_template
);
1663 test_cipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
1664 camellia_speed_template
);
1665 test_cipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
1666 camellia_speed_template
);
1667 test_cipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
1668 camellia_speed_template
);
1672 test_cipher_speed("salsa20", ENCRYPT
, sec
, NULL
, 0,
1673 salsa20_speed_template
);
1680 test_hash_speed("md4", sec
, generic_hash_speed_template
);
1681 if (mode
> 300 && mode
< 400) break;
1684 test_hash_speed("md5", sec
, generic_hash_speed_template
);
1685 if (mode
> 300 && mode
< 400) break;
1688 test_hash_speed("sha1", sec
, generic_hash_speed_template
);
1689 if (mode
> 300 && mode
< 400) break;
1692 test_hash_speed("sha256", sec
, generic_hash_speed_template
);
1693 if (mode
> 300 && mode
< 400) break;
1696 test_hash_speed("sha384", sec
, generic_hash_speed_template
);
1697 if (mode
> 300 && mode
< 400) break;
1700 test_hash_speed("sha512", sec
, generic_hash_speed_template
);
1701 if (mode
> 300 && mode
< 400) break;
1704 test_hash_speed("wp256", sec
, generic_hash_speed_template
);
1705 if (mode
> 300 && mode
< 400) break;
1708 test_hash_speed("wp384", sec
, generic_hash_speed_template
);
1709 if (mode
> 300 && mode
< 400) break;
1712 test_hash_speed("wp512", sec
, generic_hash_speed_template
);
1713 if (mode
> 300 && mode
< 400) break;
1716 test_hash_speed("tgr128", sec
, generic_hash_speed_template
);
1717 if (mode
> 300 && mode
< 400) break;
1720 test_hash_speed("tgr160", sec
, generic_hash_speed_template
);
1721 if (mode
> 300 && mode
< 400) break;
1724 test_hash_speed("tgr192", sec
, generic_hash_speed_template
);
1725 if (mode
> 300 && mode
< 400) break;
1728 test_hash_speed("sha224", sec
, generic_hash_speed_template
);
1729 if (mode
> 300 && mode
< 400) break;
1739 /* useful for debugging */
1740 printk("not testing anything\n");
1745 static int __init
init(void)
1749 tvmem
= kmalloc(TVMEMSIZE
, GFP_KERNEL
);
1753 xbuf
= kmalloc(XBUFSIZE
, GFP_KERNEL
);
1757 axbuf
= kmalloc(XBUFSIZE
, GFP_KERNEL
);
1763 /* We intentionaly return -EAGAIN to prevent keeping
1764 * the module. It does all its work from init()
1765 * and doesn't offer any runtime functionality
1766 * => we don't need it in the memory, do we?
1781 * If an init function is provided, an exit function must also be provided
1782 * to allow module unload.
1784 static void __exit
fini(void) { }
1789 module_param(mode
, int, 0);
1790 module_param(sec
, uint
, 0);
1791 MODULE_PARM_DESC(sec
, "Length in seconds of speed tests "
1792 "(defaults to zero which uses CPU cycles instead)");
1794 MODULE_LICENSE("GPL");
1795 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1796 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");