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", 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
;
244 printk(KERN_INFO
"\ntesting %s %s\n", algo
, e
);
246 tsize
= sizeof(struct aead_testvec
);
249 if (tsize
> TVMEMSIZE
) {
250 printk(KERN_INFO
"template (%u) too big for tvmem (%u)\n",
255 memcpy(tvmem
, template, tsize
);
256 aead_tv
= (void *)tvmem
;
258 init_completion(&result
.completion
);
260 tfm
= crypto_alloc_aead(algo
, 0, 0);
263 printk(KERN_INFO
"failed to load transform for %s: %ld\n",
268 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
270 printk(KERN_INFO
"failed to allocate request for %s\n", algo
);
274 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
275 tcrypt_complete
, &result
);
277 for (i
= 0, j
= 0; i
< tcount
; i
++) {
278 if (!aead_tv
[i
].np
) {
279 printk(KERN_INFO
"test %u (%d bit key):\n",
280 ++j
, aead_tv
[i
].klen
* 8);
282 crypto_aead_clear_flags(tfm
, ~0);
284 crypto_aead_set_flags(
285 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
286 key
= aead_tv
[i
].key
;
288 ret
= crypto_aead_setkey(tfm
, key
,
291 printk(KERN_INFO
"setkey() failed flags=%x\n",
292 crypto_aead_get_flags(tfm
));
294 if (!aead_tv
[i
].fail
)
298 sg_init_one(&sg
[0], aead_tv
[i
].input
,
301 sg_init_one(&asg
[0], aead_tv
[i
].assoc
,
304 aead_request_set_crypt(req
, sg
, sg
,
308 aead_request_set_assoc(req
, asg
, aead_tv
[i
].alen
);
311 ret
= crypto_aead_encrypt(req
);
313 memcpy(req
->__ctx
, aead_tv
[i
].tag
,
315 ret
= crypto_aead_decrypt(req
);
323 ret
= wait_for_completion_interruptible(
325 if (!ret
&& !(ret
= result
.err
)) {
326 INIT_COMPLETION(result
.completion
);
331 printk(KERN_INFO
"%s () failed err=%d\n",
336 q
= kmap(sg_page(&sg
[0])) + sg
[0].offset
;
337 hexdump(q
, aead_tv
[i
].rlen
);
338 printk(KERN_INFO
"auth tag: ");
339 hexdump((unsigned char *)req
->__ctx
, aead_tv
[i
].tlen
);
341 printk(KERN_INFO
"enc/dec: %s\n",
342 memcmp(q
, aead_tv
[i
].result
,
343 aead_tv
[i
].rlen
) ? "fail" : "pass");
345 printk(KERN_INFO
"auth tag: %s\n",
346 memcmp(req
->__ctx
, aead_tv
[i
].tag
,
347 aead_tv
[i
].tlen
) ? "fail" : "pass");
351 printk(KERN_INFO
"\ntesting %s %s across pages (chunking)\n", algo
, e
);
352 memset(xbuf
, 0, XBUFSIZE
);
354 for (i
= 0, j
= 0; i
< tcount
; i
++) {
356 printk(KERN_INFO
"test %u (%d bit key):\n",
357 ++j
, aead_tv
[i
].klen
* 8);
359 crypto_aead_clear_flags(tfm
, ~0);
361 crypto_aead_set_flags(
362 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
363 key
= aead_tv
[i
].key
;
365 ret
= crypto_aead_setkey(tfm
, key
, aead_tv
[i
].klen
);
367 printk(KERN_INFO
"setkey() failed flags=%x\n",
368 crypto_aead_get_flags(tfm
));
370 if (!aead_tv
[i
].fail
)
374 sg_init_table(sg
, aead_tv
[i
].np
);
375 for (k
= 0, temp
= 0; k
< aead_tv
[i
].np
; k
++) {
376 memcpy(&xbuf
[IDX
[k
]],
377 aead_tv
[i
].input
+ temp
,
379 temp
+= aead_tv
[i
].tap
[k
];
380 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
384 sg_init_table(asg
, aead_tv
[i
].anp
);
385 for (k
= 0, temp
= 0; k
< aead_tv
[i
].anp
; k
++) {
386 memcpy(&axbuf
[IDX
[k
]],
387 aead_tv
[i
].assoc
+ temp
,
389 temp
+= aead_tv
[i
].atap
[k
];
390 sg_set_buf(&asg
[k
], &axbuf
[IDX
[k
]],
394 aead_request_set_crypt(req
, sg
, sg
,
398 aead_request_set_assoc(req
, asg
, aead_tv
[i
].alen
);
401 ret
= crypto_aead_encrypt(req
);
403 memcpy(req
->__ctx
, aead_tv
[i
].tag
,
405 ret
= crypto_aead_decrypt(req
);
413 ret
= wait_for_completion_interruptible(
415 if (!ret
&& !(ret
= result
.err
)) {
416 INIT_COMPLETION(result
.completion
);
421 printk(KERN_INFO
"%s () failed err=%d\n",
426 for (k
= 0, temp
= 0; k
< aead_tv
[i
].np
; k
++) {
427 printk(KERN_INFO
"page %u\n", k
);
428 q
= kmap(sg_page(&sg
[k
])) + sg
[k
].offset
;
429 hexdump(q
, aead_tv
[i
].tap
[k
]);
430 printk(KERN_INFO
"%s\n",
431 memcmp(q
, aead_tv
[i
].result
+ temp
,
435 temp
+= aead_tv
[i
].tap
[k
];
437 printk(KERN_INFO
"auth tag: ");
438 hexdump((unsigned char *)req
->__ctx
, aead_tv
[i
].tlen
);
440 printk(KERN_INFO
"auth tag: %s\n",
441 memcmp(req
->__ctx
, aead_tv
[i
].tag
,
442 aead_tv
[i
].tlen
) ? "fail" : "pass");
447 crypto_free_aead(tfm
);
448 aead_request_free(req
);
451 static void test_cipher(char *algo
, int enc
,
452 struct cipher_testvec
*template, unsigned int tcount
)
454 unsigned int ret
, i
, j
, k
, temp
;
457 struct crypto_ablkcipher
*tfm
;
459 struct cipher_testvec
*cipher_tv
;
460 struct ablkcipher_request
*req
;
461 struct scatterlist sg
[8];
463 struct tcrypt_result result
;
470 printk("\ntesting %s %s\n", algo
, e
);
472 tsize
= sizeof (struct cipher_testvec
);
473 if (tsize
> TVMEMSIZE
) {
474 printk("template (%u) too big for tvmem (%u)\n", tsize
,
478 cipher_tv
= (void *)tvmem
;
480 init_completion(&result
.completion
);
482 tfm
= crypto_alloc_ablkcipher(algo
, 0, 0);
485 printk("failed to load transform for %s: %ld\n", algo
,
490 req
= ablkcipher_request_alloc(tfm
, GFP_KERNEL
);
492 printk("failed to allocate request for %s\n", algo
);
496 ablkcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
497 tcrypt_complete
, &result
);
500 for (i
= 0; i
< tcount
; i
++) {
501 memcpy(cipher_tv
, &template[i
], tsize
);
502 if (!(cipher_tv
->np
)) {
504 printk("test %u (%d bit key):\n",
505 j
, cipher_tv
->klen
* 8);
507 crypto_ablkcipher_clear_flags(tfm
, ~0);
509 crypto_ablkcipher_set_flags(
510 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
511 key
= cipher_tv
->key
;
513 ret
= crypto_ablkcipher_setkey(tfm
, key
,
516 printk("setkey() failed flags=%x\n",
517 crypto_ablkcipher_get_flags(tfm
));
519 if (!cipher_tv
->fail
)
523 sg_init_one(&sg
[0], cipher_tv
->input
,
526 ablkcipher_request_set_crypt(req
, sg
, sg
,
531 crypto_ablkcipher_encrypt(req
) :
532 crypto_ablkcipher_decrypt(req
);
539 ret
= wait_for_completion_interruptible(
541 if (!ret
&& !((ret
= result
.err
))) {
542 INIT_COMPLETION(result
.completion
);
547 printk("%s () failed err=%d\n", e
, -ret
);
551 q
= kmap(sg_page(&sg
[0])) + sg
[0].offset
;
552 hexdump(q
, cipher_tv
->rlen
);
555 memcmp(q
, cipher_tv
->result
,
556 cipher_tv
->rlen
) ? "fail" : "pass");
560 printk("\ntesting %s %s across pages (chunking)\n", algo
, e
);
561 memset(xbuf
, 0, XBUFSIZE
);
564 for (i
= 0; i
< tcount
; i
++) {
565 memcpy(cipher_tv
, &template[i
], tsize
);
568 printk("test %u (%d bit key):\n",
569 j
, cipher_tv
->klen
* 8);
571 crypto_ablkcipher_clear_flags(tfm
, ~0);
573 crypto_ablkcipher_set_flags(
574 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
575 key
= cipher_tv
->key
;
577 ret
= crypto_ablkcipher_setkey(tfm
, key
,
580 printk("setkey() failed flags=%x\n",
581 crypto_ablkcipher_get_flags(tfm
));
583 if (!cipher_tv
->fail
)
588 sg_init_table(sg
, cipher_tv
->np
);
589 for (k
= 0; k
< cipher_tv
->np
; k
++) {
590 memcpy(&xbuf
[IDX
[k
]],
591 cipher_tv
->input
+ temp
,
593 temp
+= cipher_tv
->tap
[k
];
594 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
598 ablkcipher_request_set_crypt(req
, sg
, sg
,
603 crypto_ablkcipher_encrypt(req
) :
604 crypto_ablkcipher_decrypt(req
);
611 ret
= wait_for_completion_interruptible(
613 if (!ret
&& !((ret
= result
.err
))) {
614 INIT_COMPLETION(result
.completion
);
619 printk("%s () failed err=%d\n", e
, -ret
);
624 for (k
= 0; k
< cipher_tv
->np
; k
++) {
625 printk("page %u\n", k
);
626 q
= kmap(sg_page(&sg
[k
])) + sg
[k
].offset
;
627 hexdump(q
, cipher_tv
->tap
[k
]);
629 memcmp(q
, cipher_tv
->result
+ temp
,
630 cipher_tv
->tap
[k
]) ? "fail" :
632 temp
+= cipher_tv
->tap
[k
];
638 crypto_free_ablkcipher(tfm
);
639 ablkcipher_request_free(req
);
642 static int test_cipher_jiffies(struct blkcipher_desc
*desc
, int enc
, char *p
,
645 struct scatterlist sg
[1];
646 unsigned long start
, end
;
650 sg_init_one(sg
, p
, blen
);
652 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
653 time_before(jiffies
, end
); bcount
++) {
655 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
657 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
663 printk("%d operations in %d seconds (%ld bytes)\n",
664 bcount
, sec
, (long)bcount
* blen
);
668 static int test_cipher_cycles(struct blkcipher_desc
*desc
, int enc
, char *p
,
671 struct scatterlist sg
[1];
672 unsigned long cycles
= 0;
676 sg_init_one(sg
, p
, blen
);
682 for (i
= 0; i
< 4; i
++) {
684 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
686 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
692 /* The real thing. */
693 for (i
= 0; i
< 8; i
++) {
696 start
= get_cycles();
698 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
700 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
706 cycles
+= end
- start
;
714 printk("1 operation in %lu cycles (%d bytes)\n",
715 (cycles
+ 4) / 8, blen
);
720 static void test_cipher_speed(char *algo
, int enc
, unsigned int sec
,
721 struct cipher_testvec
*template,
722 unsigned int tcount
, struct cipher_speed
*speed
)
724 unsigned int ret
, i
, j
, iv_len
;
725 unsigned char *key
, *p
, iv
[128];
726 struct crypto_blkcipher
*tfm
;
727 struct blkcipher_desc desc
;
735 printk("\ntesting speed of %s %s\n", algo
, e
);
737 tfm
= crypto_alloc_blkcipher(algo
, 0, CRYPTO_ALG_ASYNC
);
740 printk("failed to load transform for %s: %ld\n", algo
,
747 for (i
= 0; speed
[i
].klen
!= 0; i
++) {
748 if ((speed
[i
].blen
+ speed
[i
].klen
) > TVMEMSIZE
) {
749 printk("template (%u) too big for tvmem (%u)\n",
750 speed
[i
].blen
+ speed
[i
].klen
, TVMEMSIZE
);
754 printk("test %u (%d bit key, %d byte blocks): ", i
,
755 speed
[i
].klen
* 8, speed
[i
].blen
);
757 memset(tvmem
, 0xff, speed
[i
].klen
+ speed
[i
].blen
);
759 /* set key, plain text and IV */
760 key
= (unsigned char *)tvmem
;
761 for (j
= 0; j
< tcount
; j
++) {
762 if (template[j
].klen
== speed
[i
].klen
) {
763 key
= template[j
].key
;
767 p
= (unsigned char *)tvmem
+ speed
[i
].klen
;
769 ret
= crypto_blkcipher_setkey(tfm
, key
, speed
[i
].klen
);
771 printk("setkey() failed flags=%x\n",
772 crypto_blkcipher_get_flags(tfm
));
776 iv_len
= crypto_blkcipher_ivsize(tfm
);
778 memset(&iv
, 0xff, iv_len
);
779 crypto_blkcipher_set_iv(tfm
, iv
, iv_len
);
783 ret
= test_cipher_jiffies(&desc
, enc
, p
, speed
[i
].blen
,
786 ret
= test_cipher_cycles(&desc
, enc
, p
, speed
[i
].blen
);
789 printk("%s() failed flags=%x\n", e
, desc
.flags
);
795 crypto_free_blkcipher(tfm
);
798 static int test_hash_jiffies_digest(struct hash_desc
*desc
, char *p
, int blen
,
801 struct scatterlist sg
[1];
802 unsigned long start
, end
;
806 sg_init_table(sg
, 1);
808 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
809 time_before(jiffies
, end
); bcount
++) {
810 sg_set_buf(sg
, p
, blen
);
811 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
816 printk("%6u opers/sec, %9lu bytes/sec\n",
817 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
822 static int test_hash_jiffies(struct hash_desc
*desc
, char *p
, int blen
,
823 int plen
, char *out
, int sec
)
825 struct scatterlist sg
[1];
826 unsigned long start
, end
;
831 return test_hash_jiffies_digest(desc
, p
, blen
, out
, sec
);
833 sg_init_table(sg
, 1);
835 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
836 time_before(jiffies
, end
); bcount
++) {
837 ret
= crypto_hash_init(desc
);
840 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
841 sg_set_buf(sg
, p
+ pcount
, plen
);
842 ret
= crypto_hash_update(desc
, sg
, plen
);
846 /* we assume there is enough space in 'out' for the result */
847 ret
= crypto_hash_final(desc
, out
);
852 printk("%6u opers/sec, %9lu bytes/sec\n",
853 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
858 static int test_hash_cycles_digest(struct hash_desc
*desc
, char *p
, int blen
,
861 struct scatterlist sg
[1];
862 unsigned long cycles
= 0;
866 sg_init_table(sg
, 1);
872 for (i
= 0; i
< 4; i
++) {
873 sg_set_buf(sg
, p
, blen
);
874 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
879 /* The real thing. */
880 for (i
= 0; i
< 8; i
++) {
883 start
= get_cycles();
885 sg_set_buf(sg
, p
, blen
);
886 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
892 cycles
+= end
- start
;
902 printk("%6lu cycles/operation, %4lu cycles/byte\n",
903 cycles
/ 8, cycles
/ (8 * blen
));
908 static int test_hash_cycles(struct hash_desc
*desc
, char *p
, int blen
,
911 struct scatterlist sg
[1];
912 unsigned long cycles
= 0;
917 return test_hash_cycles_digest(desc
, p
, blen
, out
);
919 sg_init_table(sg
, 1);
925 for (i
= 0; i
< 4; i
++) {
926 ret
= crypto_hash_init(desc
);
929 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
930 sg_set_buf(sg
, p
+ pcount
, plen
);
931 ret
= crypto_hash_update(desc
, sg
, plen
);
935 ret
= crypto_hash_final(desc
, out
);
940 /* The real thing. */
941 for (i
= 0; i
< 8; i
++) {
944 start
= get_cycles();
946 ret
= crypto_hash_init(desc
);
949 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
950 sg_set_buf(sg
, p
+ pcount
, plen
);
951 ret
= crypto_hash_update(desc
, sg
, plen
);
955 ret
= crypto_hash_final(desc
, out
);
961 cycles
+= end
- start
;
971 printk("%6lu cycles/operation, %4lu cycles/byte\n",
972 cycles
/ 8, cycles
/ (8 * blen
));
977 static void test_hash_speed(char *algo
, unsigned int sec
,
978 struct hash_speed
*speed
)
980 struct crypto_hash
*tfm
;
981 struct hash_desc desc
;
986 printk("\ntesting speed of %s\n", algo
);
988 tfm
= crypto_alloc_hash(algo
, 0, CRYPTO_ALG_ASYNC
);
991 printk("failed to load transform for %s: %ld\n", algo
,
999 if (crypto_hash_digestsize(tfm
) > sizeof(output
)) {
1000 printk("digestsize(%u) > outputbuffer(%zu)\n",
1001 crypto_hash_digestsize(tfm
), sizeof(output
));
1005 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
1006 if (speed
[i
].blen
> TVMEMSIZE
) {
1007 printk("template (%u) too big for tvmem (%u)\n",
1008 speed
[i
].blen
, TVMEMSIZE
);
1012 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
1013 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
1015 memset(tvmem
, 0xff, speed
[i
].blen
);
1018 ret
= test_hash_jiffies(&desc
, tvmem
, speed
[i
].blen
,
1019 speed
[i
].plen
, output
, sec
);
1021 ret
= test_hash_cycles(&desc
, tvmem
, speed
[i
].blen
,
1022 speed
[i
].plen
, output
);
1025 printk("hashing failed ret=%d\n", ret
);
1031 crypto_free_hash(tfm
);
1034 static void test_deflate(void)
1037 char result
[COMP_BUF_SIZE
];
1038 struct crypto_comp
*tfm
;
1039 struct comp_testvec
*tv
;
1042 printk("\ntesting deflate compression\n");
1044 tsize
= sizeof (deflate_comp_tv_template
);
1045 if (tsize
> TVMEMSIZE
) {
1046 printk("template (%u) too big for tvmem (%u)\n", tsize
,
1051 memcpy(tvmem
, deflate_comp_tv_template
, tsize
);
1054 tfm
= crypto_alloc_comp("deflate", 0, CRYPTO_ALG_ASYNC
);
1056 printk("failed to load transform for deflate\n");
1060 for (i
= 0; i
< DEFLATE_COMP_TEST_VECTORS
; i
++) {
1061 int ilen
, ret
, dlen
= COMP_BUF_SIZE
;
1063 printk("test %u:\n", i
+ 1);
1064 memset(result
, 0, sizeof (result
));
1067 ret
= crypto_comp_compress(tfm
, tv
[i
].input
,
1068 ilen
, result
, &dlen
);
1070 printk("fail: ret=%d\n", ret
);
1073 hexdump(result
, dlen
);
1074 printk("%s (ratio %d:%d)\n",
1075 memcmp(result
, tv
[i
].output
, dlen
) ? "fail" : "pass",
1079 printk("\ntesting deflate decompression\n");
1081 tsize
= sizeof (deflate_decomp_tv_template
);
1082 if (tsize
> TVMEMSIZE
) {
1083 printk("template (%u) too big for tvmem (%u)\n", tsize
,
1088 memcpy(tvmem
, deflate_decomp_tv_template
, tsize
);
1091 for (i
= 0; i
< DEFLATE_DECOMP_TEST_VECTORS
; i
++) {
1092 int ilen
, ret
, dlen
= COMP_BUF_SIZE
;
1094 printk("test %u:\n", i
+ 1);
1095 memset(result
, 0, sizeof (result
));
1098 ret
= crypto_comp_decompress(tfm
, tv
[i
].input
,
1099 ilen
, result
, &dlen
);
1101 printk("fail: ret=%d\n", ret
);
1104 hexdump(result
, dlen
);
1105 printk("%s (ratio %d:%d)\n",
1106 memcmp(result
, tv
[i
].output
, dlen
) ? "fail" : "pass",
1110 crypto_free_comp(tfm
);
1113 static void test_available(void)
1115 char **name
= check
;
1118 printk("alg %s ", *name
);
1119 printk(crypto_has_alg(*name
, 0, 0) ?
1120 "found\n" : "not found\n");
1125 static void do_test(void)
1130 test_hash("md5", md5_tv_template
, MD5_TEST_VECTORS
);
1132 test_hash("sha1", sha1_tv_template
, SHA1_TEST_VECTORS
);
1135 test_cipher("ecb(des)", ENCRYPT
, des_enc_tv_template
,
1136 DES_ENC_TEST_VECTORS
);
1137 test_cipher("ecb(des)", DECRYPT
, des_dec_tv_template
,
1138 DES_DEC_TEST_VECTORS
);
1139 test_cipher("cbc(des)", ENCRYPT
, des_cbc_enc_tv_template
,
1140 DES_CBC_ENC_TEST_VECTORS
);
1141 test_cipher("cbc(des)", DECRYPT
, des_cbc_dec_tv_template
,
1142 DES_CBC_DEC_TEST_VECTORS
);
1145 test_cipher("ecb(des3_ede)", ENCRYPT
, des3_ede_enc_tv_template
,
1146 DES3_EDE_ENC_TEST_VECTORS
);
1147 test_cipher("ecb(des3_ede)", DECRYPT
, des3_ede_dec_tv_template
,
1148 DES3_EDE_DEC_TEST_VECTORS
);
1150 test_hash("md4", md4_tv_template
, MD4_TEST_VECTORS
);
1152 test_hash("sha224", sha224_tv_template
, SHA224_TEST_VECTORS
);
1154 test_hash("sha256", sha256_tv_template
, SHA256_TEST_VECTORS
);
1157 test_cipher("ecb(blowfish)", ENCRYPT
, bf_enc_tv_template
,
1158 BF_ENC_TEST_VECTORS
);
1159 test_cipher("ecb(blowfish)", DECRYPT
, bf_dec_tv_template
,
1160 BF_DEC_TEST_VECTORS
);
1161 test_cipher("cbc(blowfish)", ENCRYPT
, bf_cbc_enc_tv_template
,
1162 BF_CBC_ENC_TEST_VECTORS
);
1163 test_cipher("cbc(blowfish)", DECRYPT
, bf_cbc_dec_tv_template
,
1164 BF_CBC_DEC_TEST_VECTORS
);
1167 test_cipher("ecb(twofish)", ENCRYPT
, tf_enc_tv_template
,
1168 TF_ENC_TEST_VECTORS
);
1169 test_cipher("ecb(twofish)", DECRYPT
, tf_dec_tv_template
,
1170 TF_DEC_TEST_VECTORS
);
1171 test_cipher("cbc(twofish)", ENCRYPT
, tf_cbc_enc_tv_template
,
1172 TF_CBC_ENC_TEST_VECTORS
);
1173 test_cipher("cbc(twofish)", DECRYPT
, tf_cbc_dec_tv_template
,
1174 TF_CBC_DEC_TEST_VECTORS
);
1177 test_cipher("ecb(serpent)", ENCRYPT
, serpent_enc_tv_template
,
1178 SERPENT_ENC_TEST_VECTORS
);
1179 test_cipher("ecb(serpent)", DECRYPT
, serpent_dec_tv_template
,
1180 SERPENT_DEC_TEST_VECTORS
);
1183 test_cipher("ecb(tnepres)", ENCRYPT
, tnepres_enc_tv_template
,
1184 TNEPRES_ENC_TEST_VECTORS
);
1185 test_cipher("ecb(tnepres)", DECRYPT
, tnepres_dec_tv_template
,
1186 TNEPRES_DEC_TEST_VECTORS
);
1189 test_cipher("ecb(aes)", ENCRYPT
, aes_enc_tv_template
,
1190 AES_ENC_TEST_VECTORS
);
1191 test_cipher("ecb(aes)", DECRYPT
, aes_dec_tv_template
,
1192 AES_DEC_TEST_VECTORS
);
1193 test_cipher("cbc(aes)", ENCRYPT
, aes_cbc_enc_tv_template
,
1194 AES_CBC_ENC_TEST_VECTORS
);
1195 test_cipher("cbc(aes)", DECRYPT
, aes_cbc_dec_tv_template
,
1196 AES_CBC_DEC_TEST_VECTORS
);
1197 test_cipher("lrw(aes)", ENCRYPT
, aes_lrw_enc_tv_template
,
1198 AES_LRW_ENC_TEST_VECTORS
);
1199 test_cipher("lrw(aes)", DECRYPT
, aes_lrw_dec_tv_template
,
1200 AES_LRW_DEC_TEST_VECTORS
);
1201 test_cipher("xts(aes)", ENCRYPT
, aes_xts_enc_tv_template
,
1202 AES_XTS_ENC_TEST_VECTORS
);
1203 test_cipher("xts(aes)", DECRYPT
, aes_xts_dec_tv_template
,
1204 AES_XTS_DEC_TEST_VECTORS
);
1205 test_cipher("ctr(aes,4,8,4)", ENCRYPT
, aes_ctr_enc_tv_template
,
1206 AES_CTR_ENC_TEST_VECTORS
);
1207 test_cipher("ctr(aes,4,8,4)", DECRYPT
, aes_ctr_dec_tv_template
,
1208 AES_CTR_DEC_TEST_VECTORS
);
1209 test_aead("gcm(aes)", ENCRYPT
, aes_gcm_enc_tv_template
,
1210 AES_GCM_ENC_TEST_VECTORS
);
1211 test_aead("gcm(aes)", DECRYPT
, aes_gcm_dec_tv_template
,
1212 AES_GCM_DEC_TEST_VECTORS
);
1215 test_cipher("ecb(cast5)", ENCRYPT
, cast5_enc_tv_template
,
1216 CAST5_ENC_TEST_VECTORS
);
1217 test_cipher("ecb(cast5)", DECRYPT
, cast5_dec_tv_template
,
1218 CAST5_DEC_TEST_VECTORS
);
1221 test_cipher("ecb(cast6)", ENCRYPT
, cast6_enc_tv_template
,
1222 CAST6_ENC_TEST_VECTORS
);
1223 test_cipher("ecb(cast6)", DECRYPT
, cast6_dec_tv_template
,
1224 CAST6_DEC_TEST_VECTORS
);
1227 test_cipher("ecb(arc4)", ENCRYPT
, arc4_enc_tv_template
,
1228 ARC4_ENC_TEST_VECTORS
);
1229 test_cipher("ecb(arc4)", DECRYPT
, arc4_dec_tv_template
,
1230 ARC4_DEC_TEST_VECTORS
);
1233 test_cipher("ecb(tea)", ENCRYPT
, tea_enc_tv_template
,
1234 TEA_ENC_TEST_VECTORS
);
1235 test_cipher("ecb(tea)", DECRYPT
, tea_dec_tv_template
,
1236 TEA_DEC_TEST_VECTORS
);
1240 test_cipher("ecb(xtea)", ENCRYPT
, xtea_enc_tv_template
,
1241 XTEA_ENC_TEST_VECTORS
);
1242 test_cipher("ecb(xtea)", DECRYPT
, xtea_dec_tv_template
,
1243 XTEA_DEC_TEST_VECTORS
);
1246 test_cipher("ecb(khazad)", ENCRYPT
, khazad_enc_tv_template
,
1247 KHAZAD_ENC_TEST_VECTORS
);
1248 test_cipher("ecb(khazad)", DECRYPT
, khazad_dec_tv_template
,
1249 KHAZAD_DEC_TEST_VECTORS
);
1252 test_cipher("ecb(anubis)", ENCRYPT
, anubis_enc_tv_template
,
1253 ANUBIS_ENC_TEST_VECTORS
);
1254 test_cipher("ecb(anubis)", DECRYPT
, anubis_dec_tv_template
,
1255 ANUBIS_DEC_TEST_VECTORS
);
1256 test_cipher("cbc(anubis)", ENCRYPT
, anubis_cbc_enc_tv_template
,
1257 ANUBIS_CBC_ENC_TEST_VECTORS
);
1258 test_cipher("cbc(anubis)", DECRYPT
, anubis_cbc_dec_tv_template
,
1259 ANUBIS_CBC_ENC_TEST_VECTORS
);
1262 test_cipher("ecb(xeta)", ENCRYPT
, xeta_enc_tv_template
,
1263 XETA_ENC_TEST_VECTORS
);
1264 test_cipher("ecb(xeta)", DECRYPT
, xeta_dec_tv_template
,
1265 XETA_DEC_TEST_VECTORS
);
1268 test_cipher("pcbc(fcrypt)", ENCRYPT
, fcrypt_pcbc_enc_tv_template
,
1269 FCRYPT_ENC_TEST_VECTORS
);
1270 test_cipher("pcbc(fcrypt)", DECRYPT
, fcrypt_pcbc_dec_tv_template
,
1271 FCRYPT_DEC_TEST_VECTORS
);
1274 test_cipher("ecb(camellia)", ENCRYPT
,
1275 camellia_enc_tv_template
,
1276 CAMELLIA_ENC_TEST_VECTORS
);
1277 test_cipher("ecb(camellia)", DECRYPT
,
1278 camellia_dec_tv_template
,
1279 CAMELLIA_DEC_TEST_VECTORS
);
1280 test_cipher("cbc(camellia)", ENCRYPT
,
1281 camellia_cbc_enc_tv_template
,
1282 CAMELLIA_CBC_ENC_TEST_VECTORS
);
1283 test_cipher("cbc(camellia)", DECRYPT
,
1284 camellia_cbc_dec_tv_template
,
1285 CAMELLIA_CBC_DEC_TEST_VECTORS
);
1288 test_cipher("ecb(seed)", ENCRYPT
, seed_enc_tv_template
,
1289 SEED_ENC_TEST_VECTORS
);
1290 test_cipher("ecb(seed)", DECRYPT
, seed_dec_tv_template
,
1291 SEED_DEC_TEST_VECTORS
);
1293 test_hash("sha384", sha384_tv_template
, SHA384_TEST_VECTORS
);
1294 test_hash("sha512", sha512_tv_template
, SHA512_TEST_VECTORS
);
1295 test_hash("wp512", wp512_tv_template
, WP512_TEST_VECTORS
);
1296 test_hash("wp384", wp384_tv_template
, WP384_TEST_VECTORS
);
1297 test_hash("wp256", wp256_tv_template
, WP256_TEST_VECTORS
);
1298 test_hash("tgr192", tgr192_tv_template
, TGR192_TEST_VECTORS
);
1299 test_hash("tgr160", tgr160_tv_template
, TGR160_TEST_VECTORS
);
1300 test_hash("tgr128", tgr128_tv_template
, TGR128_TEST_VECTORS
);
1302 test_hash("crc32c", crc32c_tv_template
, CRC32C_TEST_VECTORS
);
1303 test_hash("hmac(md5)", hmac_md5_tv_template
,
1304 HMAC_MD5_TEST_VECTORS
);
1305 test_hash("hmac(sha1)", hmac_sha1_tv_template
,
1306 HMAC_SHA1_TEST_VECTORS
);
1307 test_hash("hmac(sha224)", hmac_sha224_tv_template
,
1308 HMAC_SHA224_TEST_VECTORS
);
1309 test_hash("hmac(sha256)", hmac_sha256_tv_template
,
1310 HMAC_SHA256_TEST_VECTORS
);
1311 test_hash("hmac(sha384)", hmac_sha384_tv_template
,
1312 HMAC_SHA384_TEST_VECTORS
);
1313 test_hash("hmac(sha512)", hmac_sha512_tv_template
,
1314 HMAC_SHA512_TEST_VECTORS
);
1316 test_hash("xcbc(aes)", aes_xcbc128_tv_template
,
1317 XCBC_AES_TEST_VECTORS
);
1319 test_hash("michael_mic", michael_mic_tv_template
, MICHAEL_MIC_TEST_VECTORS
);
1323 test_hash("md5", md5_tv_template
, MD5_TEST_VECTORS
);
1327 test_hash("sha1", sha1_tv_template
, SHA1_TEST_VECTORS
);
1331 test_cipher("ecb(des)", ENCRYPT
, des_enc_tv_template
,
1332 DES_ENC_TEST_VECTORS
);
1333 test_cipher("ecb(des)", DECRYPT
, des_dec_tv_template
,
1334 DES_DEC_TEST_VECTORS
);
1335 test_cipher("cbc(des)", ENCRYPT
, des_cbc_enc_tv_template
,
1336 DES_CBC_ENC_TEST_VECTORS
);
1337 test_cipher("cbc(des)", DECRYPT
, des_cbc_dec_tv_template
,
1338 DES_CBC_DEC_TEST_VECTORS
);
1342 test_cipher("ecb(des3_ede)", ENCRYPT
, des3_ede_enc_tv_template
,
1343 DES3_EDE_ENC_TEST_VECTORS
);
1344 test_cipher("ecb(des3_ede)", DECRYPT
, des3_ede_dec_tv_template
,
1345 DES3_EDE_DEC_TEST_VECTORS
);
1349 test_hash("md4", md4_tv_template
, MD4_TEST_VECTORS
);
1353 test_hash("sha256", sha256_tv_template
, SHA256_TEST_VECTORS
);
1357 test_cipher("ecb(blowfish)", ENCRYPT
, bf_enc_tv_template
,
1358 BF_ENC_TEST_VECTORS
);
1359 test_cipher("ecb(blowfish)", DECRYPT
, bf_dec_tv_template
,
1360 BF_DEC_TEST_VECTORS
);
1361 test_cipher("cbc(blowfish)", ENCRYPT
, bf_cbc_enc_tv_template
,
1362 BF_CBC_ENC_TEST_VECTORS
);
1363 test_cipher("cbc(blowfish)", DECRYPT
, bf_cbc_dec_tv_template
,
1364 BF_CBC_DEC_TEST_VECTORS
);
1368 test_cipher("ecb(twofish)", ENCRYPT
, tf_enc_tv_template
,
1369 TF_ENC_TEST_VECTORS
);
1370 test_cipher("ecb(twofish)", DECRYPT
, tf_dec_tv_template
,
1371 TF_DEC_TEST_VECTORS
);
1372 test_cipher("cbc(twofish)", ENCRYPT
, tf_cbc_enc_tv_template
,
1373 TF_CBC_ENC_TEST_VECTORS
);
1374 test_cipher("cbc(twofish)", DECRYPT
, tf_cbc_dec_tv_template
,
1375 TF_CBC_DEC_TEST_VECTORS
);
1379 test_cipher("ecb(serpent)", ENCRYPT
, serpent_enc_tv_template
,
1380 SERPENT_ENC_TEST_VECTORS
);
1381 test_cipher("ecb(serpent)", DECRYPT
, serpent_dec_tv_template
,
1382 SERPENT_DEC_TEST_VECTORS
);
1386 test_cipher("ecb(aes)", ENCRYPT
, aes_enc_tv_template
,
1387 AES_ENC_TEST_VECTORS
);
1388 test_cipher("ecb(aes)", DECRYPT
, aes_dec_tv_template
,
1389 AES_DEC_TEST_VECTORS
);
1390 test_cipher("cbc(aes)", ENCRYPT
, aes_cbc_enc_tv_template
,
1391 AES_CBC_ENC_TEST_VECTORS
);
1392 test_cipher("cbc(aes)", DECRYPT
, aes_cbc_dec_tv_template
,
1393 AES_CBC_DEC_TEST_VECTORS
);
1394 test_cipher("lrw(aes)", ENCRYPT
, aes_lrw_enc_tv_template
,
1395 AES_LRW_ENC_TEST_VECTORS
);
1396 test_cipher("lrw(aes)", DECRYPT
, aes_lrw_dec_tv_template
,
1397 AES_LRW_DEC_TEST_VECTORS
);
1398 test_cipher("xts(aes)", ENCRYPT
, aes_xts_enc_tv_template
,
1399 AES_XTS_ENC_TEST_VECTORS
);
1400 test_cipher("xts(aes)", DECRYPT
, aes_xts_dec_tv_template
,
1401 AES_XTS_DEC_TEST_VECTORS
);
1402 test_cipher("ctr(aes,4,8,4)", ENCRYPT
, aes_ctr_enc_tv_template
,
1403 AES_CTR_ENC_TEST_VECTORS
);
1404 test_cipher("ctr(aes,4,8,4)", DECRYPT
, aes_ctr_dec_tv_template
,
1405 AES_CTR_DEC_TEST_VECTORS
);
1409 test_hash("sha384", sha384_tv_template
, SHA384_TEST_VECTORS
);
1413 test_hash("sha512", sha512_tv_template
, SHA512_TEST_VECTORS
);
1421 test_cipher("ecb(cast5)", ENCRYPT
, cast5_enc_tv_template
,
1422 CAST5_ENC_TEST_VECTORS
);
1423 test_cipher("ecb(cast5)", DECRYPT
, cast5_dec_tv_template
,
1424 CAST5_DEC_TEST_VECTORS
);
1428 test_cipher("ecb(cast6)", ENCRYPT
, cast6_enc_tv_template
,
1429 CAST6_ENC_TEST_VECTORS
);
1430 test_cipher("ecb(cast6)", DECRYPT
, cast6_dec_tv_template
,
1431 CAST6_DEC_TEST_VECTORS
);
1435 test_cipher("ecb(arc4)", ENCRYPT
, arc4_enc_tv_template
,
1436 ARC4_ENC_TEST_VECTORS
);
1437 test_cipher("ecb(arc4)", DECRYPT
, arc4_dec_tv_template
,
1438 ARC4_DEC_TEST_VECTORS
);
1442 test_hash("michael_mic", michael_mic_tv_template
, MICHAEL_MIC_TEST_VECTORS
);
1446 test_hash("crc32c", crc32c_tv_template
, CRC32C_TEST_VECTORS
);
1450 test_cipher("ecb(tea)", ENCRYPT
, tea_enc_tv_template
,
1451 TEA_ENC_TEST_VECTORS
);
1452 test_cipher("ecb(tea)", DECRYPT
, tea_dec_tv_template
,
1453 TEA_DEC_TEST_VECTORS
);
1457 test_cipher("ecb(xtea)", ENCRYPT
, xtea_enc_tv_template
,
1458 XTEA_ENC_TEST_VECTORS
);
1459 test_cipher("ecb(xtea)", DECRYPT
, xtea_dec_tv_template
,
1460 XTEA_DEC_TEST_VECTORS
);
1464 test_cipher("ecb(khazad)", ENCRYPT
, khazad_enc_tv_template
,
1465 KHAZAD_ENC_TEST_VECTORS
);
1466 test_cipher("ecb(khazad)", DECRYPT
, khazad_dec_tv_template
,
1467 KHAZAD_DEC_TEST_VECTORS
);
1471 test_hash("wp512", wp512_tv_template
, WP512_TEST_VECTORS
);
1475 test_hash("wp384", wp384_tv_template
, WP384_TEST_VECTORS
);
1479 test_hash("wp256", wp256_tv_template
, WP256_TEST_VECTORS
);
1483 test_cipher("ecb(tnepres)", ENCRYPT
, tnepres_enc_tv_template
,
1484 TNEPRES_ENC_TEST_VECTORS
);
1485 test_cipher("ecb(tnepres)", DECRYPT
, tnepres_dec_tv_template
,
1486 TNEPRES_DEC_TEST_VECTORS
);
1490 test_cipher("ecb(anubis)", ENCRYPT
, anubis_enc_tv_template
,
1491 ANUBIS_ENC_TEST_VECTORS
);
1492 test_cipher("ecb(anubis)", DECRYPT
, anubis_dec_tv_template
,
1493 ANUBIS_DEC_TEST_VECTORS
);
1494 test_cipher("cbc(anubis)", ENCRYPT
, anubis_cbc_enc_tv_template
,
1495 ANUBIS_CBC_ENC_TEST_VECTORS
);
1496 test_cipher("cbc(anubis)", DECRYPT
, anubis_cbc_dec_tv_template
,
1497 ANUBIS_CBC_ENC_TEST_VECTORS
);
1501 test_hash("tgr192", tgr192_tv_template
, TGR192_TEST_VECTORS
);
1506 test_hash("tgr160", tgr160_tv_template
, TGR160_TEST_VECTORS
);
1510 test_hash("tgr128", tgr128_tv_template
, TGR128_TEST_VECTORS
);
1514 test_cipher("ecb(xeta)", ENCRYPT
, xeta_enc_tv_template
,
1515 XETA_ENC_TEST_VECTORS
);
1516 test_cipher("ecb(xeta)", DECRYPT
, xeta_dec_tv_template
,
1517 XETA_DEC_TEST_VECTORS
);
1521 test_cipher("pcbc(fcrypt)", ENCRYPT
, fcrypt_pcbc_enc_tv_template
,
1522 FCRYPT_ENC_TEST_VECTORS
);
1523 test_cipher("pcbc(fcrypt)", DECRYPT
, fcrypt_pcbc_dec_tv_template
,
1524 FCRYPT_DEC_TEST_VECTORS
);
1528 test_cipher("ecb(camellia)", ENCRYPT
,
1529 camellia_enc_tv_template
,
1530 CAMELLIA_ENC_TEST_VECTORS
);
1531 test_cipher("ecb(camellia)", DECRYPT
,
1532 camellia_dec_tv_template
,
1533 CAMELLIA_DEC_TEST_VECTORS
);
1534 test_cipher("cbc(camellia)", ENCRYPT
,
1535 camellia_cbc_enc_tv_template
,
1536 CAMELLIA_CBC_ENC_TEST_VECTORS
);
1537 test_cipher("cbc(camellia)", DECRYPT
,
1538 camellia_cbc_dec_tv_template
,
1539 CAMELLIA_CBC_DEC_TEST_VECTORS
);
1542 test_hash("sha224", sha224_tv_template
, SHA224_TEST_VECTORS
);
1546 test_cipher("salsa20", ENCRYPT
,
1547 salsa20_stream_enc_tv_template
,
1548 SALSA20_STREAM_ENC_TEST_VECTORS
);
1552 test_hash("hmac(md5)", hmac_md5_tv_template
,
1553 HMAC_MD5_TEST_VECTORS
);
1557 test_hash("hmac(sha1)", hmac_sha1_tv_template
,
1558 HMAC_SHA1_TEST_VECTORS
);
1562 test_hash("hmac(sha256)", hmac_sha256_tv_template
,
1563 HMAC_SHA256_TEST_VECTORS
);
1567 test_hash("hmac(sha384)", hmac_sha384_tv_template
,
1568 HMAC_SHA384_TEST_VECTORS
);
1572 test_hash("hmac(sha512)", hmac_sha512_tv_template
,
1573 HMAC_SHA512_TEST_VECTORS
);
1576 test_hash("hmac(sha224)", hmac_sha224_tv_template
,
1577 HMAC_SHA224_TEST_VECTORS
);
1581 test_cipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1582 aes_speed_template
);
1583 test_cipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1584 aes_speed_template
);
1585 test_cipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1586 aes_speed_template
);
1587 test_cipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1588 aes_speed_template
);
1589 test_cipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1590 aes_lrw_speed_template
);
1591 test_cipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1592 aes_lrw_speed_template
);
1593 test_cipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1594 aes_xts_speed_template
);
1595 test_cipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1596 aes_xts_speed_template
);
1600 test_cipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1601 des3_ede_enc_tv_template
,
1602 DES3_EDE_ENC_TEST_VECTORS
,
1603 des3_ede_speed_template
);
1604 test_cipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1605 des3_ede_dec_tv_template
,
1606 DES3_EDE_DEC_TEST_VECTORS
,
1607 des3_ede_speed_template
);
1608 test_cipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1609 des3_ede_enc_tv_template
,
1610 DES3_EDE_ENC_TEST_VECTORS
,
1611 des3_ede_speed_template
);
1612 test_cipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1613 des3_ede_dec_tv_template
,
1614 DES3_EDE_DEC_TEST_VECTORS
,
1615 des3_ede_speed_template
);
1619 test_cipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1620 twofish_speed_template
);
1621 test_cipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1622 twofish_speed_template
);
1623 test_cipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1624 twofish_speed_template
);
1625 test_cipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1626 twofish_speed_template
);
1630 test_cipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1631 blowfish_speed_template
);
1632 test_cipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
1633 blowfish_speed_template
);
1634 test_cipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1635 blowfish_speed_template
);
1636 test_cipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
1637 blowfish_speed_template
);
1641 test_cipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1642 des_speed_template
);
1643 test_cipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1644 des_speed_template
);
1645 test_cipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1646 des_speed_template
);
1647 test_cipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1648 des_speed_template
);
1652 test_cipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
1653 camellia_speed_template
);
1654 test_cipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
1655 camellia_speed_template
);
1656 test_cipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
1657 camellia_speed_template
);
1658 test_cipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
1659 camellia_speed_template
);
1666 test_hash_speed("md4", sec
, generic_hash_speed_template
);
1667 if (mode
> 300 && mode
< 400) break;
1670 test_hash_speed("md5", sec
, generic_hash_speed_template
);
1671 if (mode
> 300 && mode
< 400) break;
1674 test_hash_speed("sha1", sec
, generic_hash_speed_template
);
1675 if (mode
> 300 && mode
< 400) break;
1678 test_hash_speed("sha256", sec
, generic_hash_speed_template
);
1679 if (mode
> 300 && mode
< 400) break;
1682 test_hash_speed("sha384", sec
, generic_hash_speed_template
);
1683 if (mode
> 300 && mode
< 400) break;
1686 test_hash_speed("sha512", sec
, generic_hash_speed_template
);
1687 if (mode
> 300 && mode
< 400) break;
1690 test_hash_speed("wp256", sec
, generic_hash_speed_template
);
1691 if (mode
> 300 && mode
< 400) break;
1694 test_hash_speed("wp384", sec
, generic_hash_speed_template
);
1695 if (mode
> 300 && mode
< 400) break;
1698 test_hash_speed("wp512", sec
, generic_hash_speed_template
);
1699 if (mode
> 300 && mode
< 400) break;
1702 test_hash_speed("tgr128", sec
, generic_hash_speed_template
);
1703 if (mode
> 300 && mode
< 400) break;
1706 test_hash_speed("tgr160", sec
, generic_hash_speed_template
);
1707 if (mode
> 300 && mode
< 400) break;
1710 test_hash_speed("tgr192", sec
, generic_hash_speed_template
);
1711 if (mode
> 300 && mode
< 400) break;
1714 test_hash_speed("sha224", sec
, generic_hash_speed_template
);
1715 if (mode
> 300 && mode
< 400) break;
1725 /* useful for debugging */
1726 printk("not testing anything\n");
1731 static int __init
init(void)
1735 tvmem
= kmalloc(TVMEMSIZE
, GFP_KERNEL
);
1739 xbuf
= kmalloc(XBUFSIZE
, GFP_KERNEL
);
1743 axbuf
= kmalloc(XBUFSIZE
, GFP_KERNEL
);
1749 /* We intentionaly return -EAGAIN to prevent keeping
1750 * the module. It does all its work from init()
1751 * and doesn't offer any runtime functionality
1752 * => we don't need it in the memory, do we?
1767 * If an init function is provided, an exit function must also be provided
1768 * to allow module unload.
1770 static void __exit
fini(void) { }
1775 module_param(mode
, int, 0);
1776 module_param(sec
, uint
, 0);
1777 MODULE_PARM_DESC(sec
, "Length in seconds of speed tests "
1778 "(defaults to zero which uses CPU cycles instead)");
1780 MODULE_LICENSE("GPL");
1781 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1782 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");