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
);
177 for (i
= 0; i
< tcount
; i
++) {
180 printk("test %u:\n", j
);
181 memset(result
, 0, 64);
184 sg_init_table(sg
, hash_tv
[i
].np
);
185 for (k
= 0; k
< hash_tv
[i
].np
; k
++) {
186 memcpy(&xbuf
[IDX
[k
]],
187 hash_tv
[i
].plaintext
+ temp
,
189 temp
+= hash_tv
[i
].tap
[k
];
190 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
194 if (hash_tv
[i
].ksize
) {
195 ret
= crypto_hash_setkey(tfm
, hash_tv
[i
].key
,
199 printk("setkey() failed ret=%d\n", ret
);
204 ret
= crypto_hash_digest(&desc
, sg
, hash_tv
[i
].psize
,
207 printk("digest () failed ret=%d\n", ret
);
211 hexdump(result
, crypto_hash_digestsize(tfm
));
213 memcmp(result
, hash_tv
[i
].digest
,
214 crypto_hash_digestsize(tfm
)) ?
220 crypto_free_hash(tfm
);
223 static void test_aead(char *algo
, int enc
, struct aead_testvec
*template,
226 unsigned int ret
, i
, j
, k
, temp
;
229 struct crypto_aead
*tfm
;
231 struct aead_testvec
*aead_tv
;
232 struct aead_request
*req
;
233 struct scatterlist sg
[8];
234 struct scatterlist asg
[8];
236 struct tcrypt_result result
;
237 unsigned int authsize
;
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 authsize
= abs(aead_tv
[i
].rlen
- aead_tv
[i
].ilen
);
299 ret
= crypto_aead_setauthsize(tfm
, authsize
);
302 "failed to set authsize = %u\n",
307 sg_init_one(&sg
[0], aead_tv
[i
].input
,
308 aead_tv
[i
].ilen
+ (enc
? authsize
: 0));
310 sg_init_one(&asg
[0], aead_tv
[i
].assoc
,
313 aead_request_set_crypt(req
, sg
, sg
,
317 aead_request_set_assoc(req
, asg
, aead_tv
[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
, aead_tv
[i
].rlen
);
344 printk(KERN_INFO
"enc/dec: %s\n",
345 memcmp(q
, aead_tv
[i
].result
,
346 aead_tv
[i
].rlen
) ? "fail" : "pass");
350 printk(KERN_INFO
"\ntesting %s %s across pages (chunking)\n", algo
, e
);
351 memset(xbuf
, 0, XBUFSIZE
);
352 memset(axbuf
, 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 authsize
= abs(aead_tv
[i
].rlen
- aead_tv
[i
].ilen
);
385 ret
= crypto_aead_setauthsize(tfm
, authsize
);
388 "failed to set authsize = %u\n",
394 sg
[k
- 1].length
+= authsize
;
396 sg_init_table(asg
, aead_tv
[i
].anp
);
397 for (k
= 0, temp
= 0; k
< aead_tv
[i
].anp
; k
++) {
398 memcpy(&axbuf
[IDX
[k
]],
399 aead_tv
[i
].assoc
+ temp
,
401 temp
+= aead_tv
[i
].atap
[k
];
402 sg_set_buf(&asg
[k
], &axbuf
[IDX
[k
]],
406 aead_request_set_crypt(req
, sg
, sg
,
410 aead_request_set_assoc(req
, asg
, aead_tv
[i
].alen
);
413 crypto_aead_encrypt(req
) :
414 crypto_aead_decrypt(req
);
421 ret
= wait_for_completion_interruptible(
423 if (!ret
&& !(ret
= result
.err
)) {
424 INIT_COMPLETION(result
.completion
);
429 printk(KERN_INFO
"%s () failed err=%d\n",
434 for (k
= 0, temp
= 0; k
< aead_tv
[i
].np
; k
++) {
435 printk(KERN_INFO
"page %u\n", k
);
436 q
= kmap(sg_page(&sg
[k
])) + sg
[k
].offset
;
437 hexdump(q
, aead_tv
[i
].tap
[k
]);
438 printk(KERN_INFO
"%s\n",
439 memcmp(q
, aead_tv
[i
].result
+ temp
,
441 (k
< aead_tv
[i
].np
- 1 || enc
?
445 temp
+= aead_tv
[i
].tap
[k
];
451 crypto_free_aead(tfm
);
452 aead_request_free(req
);
455 static void test_cipher(char *algo
, int enc
,
456 struct cipher_testvec
*template, unsigned int tcount
)
458 unsigned int ret
, i
, j
, k
, temp
;
461 struct crypto_ablkcipher
*tfm
;
463 struct cipher_testvec
*cipher_tv
;
464 struct ablkcipher_request
*req
;
465 struct scatterlist sg
[8];
467 struct tcrypt_result result
;
474 printk("\ntesting %s %s\n", algo
, e
);
476 tsize
= sizeof (struct cipher_testvec
);
477 if (tsize
> TVMEMSIZE
) {
478 printk("template (%u) too big for tvmem (%u)\n", tsize
,
482 cipher_tv
= (void *)tvmem
;
484 init_completion(&result
.completion
);
486 tfm
= crypto_alloc_ablkcipher(algo
, 0, 0);
489 printk("failed to load transform for %s: %ld\n", algo
,
494 req
= ablkcipher_request_alloc(tfm
, GFP_KERNEL
);
496 printk("failed to allocate request for %s\n", algo
);
500 ablkcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
501 tcrypt_complete
, &result
);
504 for (i
= 0; i
< tcount
; i
++) {
505 memcpy(cipher_tv
, &template[i
], tsize
);
506 if (!(cipher_tv
->np
)) {
508 printk("test %u (%d bit key):\n",
509 j
, cipher_tv
->klen
* 8);
511 crypto_ablkcipher_clear_flags(tfm
, ~0);
513 crypto_ablkcipher_set_flags(
514 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
515 key
= cipher_tv
->key
;
517 ret
= crypto_ablkcipher_setkey(tfm
, key
,
520 printk("setkey() failed flags=%x\n",
521 crypto_ablkcipher_get_flags(tfm
));
523 if (!cipher_tv
->fail
)
527 sg_init_one(&sg
[0], cipher_tv
->input
,
530 ablkcipher_request_set_crypt(req
, sg
, sg
,
535 crypto_ablkcipher_encrypt(req
) :
536 crypto_ablkcipher_decrypt(req
);
543 ret
= wait_for_completion_interruptible(
545 if (!ret
&& !((ret
= result
.err
))) {
546 INIT_COMPLETION(result
.completion
);
551 printk("%s () failed err=%d\n", e
, -ret
);
555 q
= kmap(sg_page(&sg
[0])) + sg
[0].offset
;
556 hexdump(q
, cipher_tv
->rlen
);
559 memcmp(q
, cipher_tv
->result
,
560 cipher_tv
->rlen
) ? "fail" : "pass");
564 printk("\ntesting %s %s across pages (chunking)\n", algo
, e
);
565 memset(xbuf
, 0, XBUFSIZE
);
568 for (i
= 0; i
< tcount
; i
++) {
569 memcpy(cipher_tv
, &template[i
], tsize
);
572 printk("test %u (%d bit key):\n",
573 j
, cipher_tv
->klen
* 8);
575 crypto_ablkcipher_clear_flags(tfm
, ~0);
577 crypto_ablkcipher_set_flags(
578 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
579 key
= cipher_tv
->key
;
581 ret
= crypto_ablkcipher_setkey(tfm
, key
,
584 printk("setkey() failed flags=%x\n",
585 crypto_ablkcipher_get_flags(tfm
));
587 if (!cipher_tv
->fail
)
592 sg_init_table(sg
, cipher_tv
->np
);
593 for (k
= 0; k
< cipher_tv
->np
; k
++) {
594 memcpy(&xbuf
[IDX
[k
]],
595 cipher_tv
->input
+ temp
,
597 temp
+= cipher_tv
->tap
[k
];
598 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
602 ablkcipher_request_set_crypt(req
, sg
, sg
,
607 crypto_ablkcipher_encrypt(req
) :
608 crypto_ablkcipher_decrypt(req
);
615 ret
= wait_for_completion_interruptible(
617 if (!ret
&& !((ret
= result
.err
))) {
618 INIT_COMPLETION(result
.completion
);
623 printk("%s () failed err=%d\n", e
, -ret
);
628 for (k
= 0; k
< cipher_tv
->np
; k
++) {
629 printk("page %u\n", k
);
630 q
= kmap(sg_page(&sg
[k
])) + sg
[k
].offset
;
631 hexdump(q
, cipher_tv
->tap
[k
]);
633 memcmp(q
, cipher_tv
->result
+ temp
,
634 cipher_tv
->tap
[k
]) ? "fail" :
636 temp
+= cipher_tv
->tap
[k
];
642 crypto_free_ablkcipher(tfm
);
643 ablkcipher_request_free(req
);
646 static int test_cipher_jiffies(struct blkcipher_desc
*desc
, int enc
, char *p
,
649 struct scatterlist sg
[1];
650 unsigned long start
, end
;
654 sg_init_one(sg
, p
, blen
);
656 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
657 time_before(jiffies
, end
); bcount
++) {
659 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
661 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
667 printk("%d operations in %d seconds (%ld bytes)\n",
668 bcount
, sec
, (long)bcount
* blen
);
672 static int test_cipher_cycles(struct blkcipher_desc
*desc
, int enc
, char *p
,
675 struct scatterlist sg
[1];
676 unsigned long cycles
= 0;
680 sg_init_one(sg
, p
, blen
);
686 for (i
= 0; i
< 4; i
++) {
688 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
690 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
696 /* The real thing. */
697 for (i
= 0; i
< 8; i
++) {
700 start
= get_cycles();
702 ret
= crypto_blkcipher_encrypt(desc
, sg
, sg
, blen
);
704 ret
= crypto_blkcipher_decrypt(desc
, sg
, sg
, blen
);
710 cycles
+= end
- start
;
718 printk("1 operation in %lu cycles (%d bytes)\n",
719 (cycles
+ 4) / 8, blen
);
724 static void test_cipher_speed(char *algo
, int enc
, unsigned int sec
,
725 struct cipher_testvec
*template,
726 unsigned int tcount
, struct cipher_speed
*speed
)
728 unsigned int ret
, i
, j
, iv_len
;
729 unsigned char *key
, *p
, iv
[128];
730 struct crypto_blkcipher
*tfm
;
731 struct blkcipher_desc desc
;
739 printk("\ntesting speed of %s %s\n", algo
, e
);
741 tfm
= crypto_alloc_blkcipher(algo
, 0, CRYPTO_ALG_ASYNC
);
744 printk("failed to load transform for %s: %ld\n", algo
,
751 for (i
= 0; speed
[i
].klen
!= 0; i
++) {
752 if ((speed
[i
].blen
+ speed
[i
].klen
) > TVMEMSIZE
) {
753 printk("template (%u) too big for tvmem (%u)\n",
754 speed
[i
].blen
+ speed
[i
].klen
, TVMEMSIZE
);
758 printk("test %u (%d bit key, %d byte blocks): ", i
,
759 speed
[i
].klen
* 8, speed
[i
].blen
);
761 memset(tvmem
, 0xff, speed
[i
].klen
+ speed
[i
].blen
);
763 /* set key, plain text and IV */
764 key
= (unsigned char *)tvmem
;
765 for (j
= 0; j
< tcount
; j
++) {
766 if (template[j
].klen
== speed
[i
].klen
) {
767 key
= template[j
].key
;
771 p
= (unsigned char *)tvmem
+ speed
[i
].klen
;
773 ret
= crypto_blkcipher_setkey(tfm
, key
, speed
[i
].klen
);
775 printk("setkey() failed flags=%x\n",
776 crypto_blkcipher_get_flags(tfm
));
780 iv_len
= crypto_blkcipher_ivsize(tfm
);
782 memset(&iv
, 0xff, iv_len
);
783 crypto_blkcipher_set_iv(tfm
, iv
, iv_len
);
787 ret
= test_cipher_jiffies(&desc
, enc
, p
, speed
[i
].blen
,
790 ret
= test_cipher_cycles(&desc
, enc
, p
, speed
[i
].blen
);
793 printk("%s() failed flags=%x\n", e
, desc
.flags
);
799 crypto_free_blkcipher(tfm
);
802 static int test_hash_jiffies_digest(struct hash_desc
*desc
, char *p
, int blen
,
805 struct scatterlist sg
[1];
806 unsigned long start
, end
;
810 sg_init_table(sg
, 1);
812 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
813 time_before(jiffies
, end
); bcount
++) {
814 sg_set_buf(sg
, p
, blen
);
815 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
820 printk("%6u opers/sec, %9lu bytes/sec\n",
821 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
826 static int test_hash_jiffies(struct hash_desc
*desc
, char *p
, int blen
,
827 int plen
, char *out
, int sec
)
829 struct scatterlist sg
[1];
830 unsigned long start
, end
;
835 return test_hash_jiffies_digest(desc
, p
, blen
, out
, sec
);
837 sg_init_table(sg
, 1);
839 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
840 time_before(jiffies
, end
); bcount
++) {
841 ret
= crypto_hash_init(desc
);
844 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
845 sg_set_buf(sg
, p
+ pcount
, plen
);
846 ret
= crypto_hash_update(desc
, sg
, plen
);
850 /* we assume there is enough space in 'out' for the result */
851 ret
= crypto_hash_final(desc
, out
);
856 printk("%6u opers/sec, %9lu bytes/sec\n",
857 bcount
/ sec
, ((long)bcount
* blen
) / sec
);
862 static int test_hash_cycles_digest(struct hash_desc
*desc
, char *p
, int blen
,
865 struct scatterlist sg
[1];
866 unsigned long cycles
= 0;
870 sg_init_table(sg
, 1);
876 for (i
= 0; i
< 4; i
++) {
877 sg_set_buf(sg
, p
, blen
);
878 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
883 /* The real thing. */
884 for (i
= 0; i
< 8; i
++) {
887 start
= get_cycles();
889 sg_set_buf(sg
, p
, blen
);
890 ret
= crypto_hash_digest(desc
, sg
, blen
, out
);
896 cycles
+= end
- start
;
906 printk("%6lu cycles/operation, %4lu cycles/byte\n",
907 cycles
/ 8, cycles
/ (8 * blen
));
912 static int test_hash_cycles(struct hash_desc
*desc
, char *p
, int blen
,
915 struct scatterlist sg
[1];
916 unsigned long cycles
= 0;
921 return test_hash_cycles_digest(desc
, p
, blen
, out
);
923 sg_init_table(sg
, 1);
929 for (i
= 0; i
< 4; i
++) {
930 ret
= crypto_hash_init(desc
);
933 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
934 sg_set_buf(sg
, p
+ pcount
, plen
);
935 ret
= crypto_hash_update(desc
, sg
, plen
);
939 ret
= crypto_hash_final(desc
, out
);
944 /* The real thing. */
945 for (i
= 0; i
< 8; i
++) {
948 start
= get_cycles();
950 ret
= crypto_hash_init(desc
);
953 for (pcount
= 0; pcount
< blen
; pcount
+= plen
) {
954 sg_set_buf(sg
, p
+ pcount
, plen
);
955 ret
= crypto_hash_update(desc
, sg
, plen
);
959 ret
= crypto_hash_final(desc
, out
);
965 cycles
+= end
- start
;
975 printk("%6lu cycles/operation, %4lu cycles/byte\n",
976 cycles
/ 8, cycles
/ (8 * blen
));
981 static void test_hash_speed(char *algo
, unsigned int sec
,
982 struct hash_speed
*speed
)
984 struct crypto_hash
*tfm
;
985 struct hash_desc desc
;
990 printk("\ntesting speed of %s\n", algo
);
992 tfm
= crypto_alloc_hash(algo
, 0, CRYPTO_ALG_ASYNC
);
995 printk("failed to load transform for %s: %ld\n", algo
,
1003 if (crypto_hash_digestsize(tfm
) > sizeof(output
)) {
1004 printk("digestsize(%u) > outputbuffer(%zu)\n",
1005 crypto_hash_digestsize(tfm
), sizeof(output
));
1009 for (i
= 0; speed
[i
].blen
!= 0; i
++) {
1010 if (speed
[i
].blen
> TVMEMSIZE
) {
1011 printk("template (%u) too big for tvmem (%u)\n",
1012 speed
[i
].blen
, TVMEMSIZE
);
1016 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
1017 i
, speed
[i
].blen
, speed
[i
].plen
, speed
[i
].blen
/ speed
[i
].plen
);
1019 memset(tvmem
, 0xff, speed
[i
].blen
);
1022 ret
= test_hash_jiffies(&desc
, tvmem
, speed
[i
].blen
,
1023 speed
[i
].plen
, output
, sec
);
1025 ret
= test_hash_cycles(&desc
, tvmem
, speed
[i
].blen
,
1026 speed
[i
].plen
, output
);
1029 printk("hashing failed ret=%d\n", ret
);
1035 crypto_free_hash(tfm
);
1038 static void test_comp(char *algo
, struct comp_testvec
*ctemplate
,
1039 struct comp_testvec
*dtemplate
, int ctcount
, int dtcount
)
1042 char result
[COMP_BUF_SIZE
];
1043 struct crypto_comp
*tfm
;
1044 struct comp_testvec
*tv
;
1047 printk("\ntesting %s compression\n", algo
);
1049 tsize
= sizeof(struct comp_testvec
);
1051 if (tsize
> TVMEMSIZE
) {
1052 printk("template (%u) too big for tvmem (%u)\n", tsize
,
1057 memcpy(tvmem
, ctemplate
, tsize
);
1060 tfm
= crypto_alloc_comp(algo
, 0, CRYPTO_ALG_ASYNC
);
1062 printk("failed to load transform for %s\n", algo
);
1066 for (i
= 0; i
< ctcount
; i
++) {
1067 int ilen
, ret
, dlen
= COMP_BUF_SIZE
;
1069 printk("test %u:\n", i
+ 1);
1070 memset(result
, 0, sizeof (result
));
1073 ret
= crypto_comp_compress(tfm
, tv
[i
].input
,
1074 ilen
, result
, &dlen
);
1076 printk("fail: ret=%d\n", ret
);
1079 hexdump(result
, dlen
);
1080 printk("%s (ratio %d:%d)\n",
1081 memcmp(result
, tv
[i
].output
, dlen
) ? "fail" : "pass",
1085 printk("\ntesting %s decompression\n", algo
);
1087 tsize
= sizeof(struct comp_testvec
);
1089 if (tsize
> TVMEMSIZE
) {
1090 printk("template (%u) too big for tvmem (%u)\n", tsize
,
1095 memcpy(tvmem
, dtemplate
, tsize
);
1098 for (i
= 0; i
< dtcount
; i
++) {
1099 int ilen
, ret
, dlen
= COMP_BUF_SIZE
;
1101 printk("test %u:\n", i
+ 1);
1102 memset(result
, 0, sizeof (result
));
1105 ret
= crypto_comp_decompress(tfm
, tv
[i
].input
,
1106 ilen
, result
, &dlen
);
1108 printk("fail: ret=%d\n", ret
);
1111 hexdump(result
, dlen
);
1112 printk("%s (ratio %d:%d)\n",
1113 memcmp(result
, tv
[i
].output
, dlen
) ? "fail" : "pass",
1117 crypto_free_comp(tfm
);
1120 static void test_available(void)
1122 char **name
= check
;
1125 printk("alg %s ", *name
);
1126 printk(crypto_has_alg(*name
, 0, 0) ?
1127 "found\n" : "not found\n");
1132 static void do_test(void)
1137 test_hash("md5", md5_tv_template
, MD5_TEST_VECTORS
);
1139 test_hash("sha1", sha1_tv_template
, SHA1_TEST_VECTORS
);
1142 test_cipher("ecb(des)", ENCRYPT
, des_enc_tv_template
,
1143 DES_ENC_TEST_VECTORS
);
1144 test_cipher("ecb(des)", DECRYPT
, des_dec_tv_template
,
1145 DES_DEC_TEST_VECTORS
);
1146 test_cipher("cbc(des)", ENCRYPT
, des_cbc_enc_tv_template
,
1147 DES_CBC_ENC_TEST_VECTORS
);
1148 test_cipher("cbc(des)", DECRYPT
, des_cbc_dec_tv_template
,
1149 DES_CBC_DEC_TEST_VECTORS
);
1152 test_cipher("ecb(des3_ede)", ENCRYPT
, des3_ede_enc_tv_template
,
1153 DES3_EDE_ENC_TEST_VECTORS
);
1154 test_cipher("ecb(des3_ede)", DECRYPT
, des3_ede_dec_tv_template
,
1155 DES3_EDE_DEC_TEST_VECTORS
);
1157 test_hash("md4", md4_tv_template
, MD4_TEST_VECTORS
);
1159 test_hash("sha224", sha224_tv_template
, SHA224_TEST_VECTORS
);
1161 test_hash("sha256", sha256_tv_template
, SHA256_TEST_VECTORS
);
1164 test_cipher("ecb(blowfish)", ENCRYPT
, bf_enc_tv_template
,
1165 BF_ENC_TEST_VECTORS
);
1166 test_cipher("ecb(blowfish)", DECRYPT
, bf_dec_tv_template
,
1167 BF_DEC_TEST_VECTORS
);
1168 test_cipher("cbc(blowfish)", ENCRYPT
, bf_cbc_enc_tv_template
,
1169 BF_CBC_ENC_TEST_VECTORS
);
1170 test_cipher("cbc(blowfish)", DECRYPT
, bf_cbc_dec_tv_template
,
1171 BF_CBC_DEC_TEST_VECTORS
);
1174 test_cipher("ecb(twofish)", ENCRYPT
, tf_enc_tv_template
,
1175 TF_ENC_TEST_VECTORS
);
1176 test_cipher("ecb(twofish)", DECRYPT
, tf_dec_tv_template
,
1177 TF_DEC_TEST_VECTORS
);
1178 test_cipher("cbc(twofish)", ENCRYPT
, tf_cbc_enc_tv_template
,
1179 TF_CBC_ENC_TEST_VECTORS
);
1180 test_cipher("cbc(twofish)", DECRYPT
, tf_cbc_dec_tv_template
,
1181 TF_CBC_DEC_TEST_VECTORS
);
1184 test_cipher("ecb(serpent)", ENCRYPT
, serpent_enc_tv_template
,
1185 SERPENT_ENC_TEST_VECTORS
);
1186 test_cipher("ecb(serpent)", DECRYPT
, serpent_dec_tv_template
,
1187 SERPENT_DEC_TEST_VECTORS
);
1190 test_cipher("ecb(tnepres)", ENCRYPT
, tnepres_enc_tv_template
,
1191 TNEPRES_ENC_TEST_VECTORS
);
1192 test_cipher("ecb(tnepres)", DECRYPT
, tnepres_dec_tv_template
,
1193 TNEPRES_DEC_TEST_VECTORS
);
1196 test_cipher("ecb(aes)", ENCRYPT
, aes_enc_tv_template
,
1197 AES_ENC_TEST_VECTORS
);
1198 test_cipher("ecb(aes)", DECRYPT
, aes_dec_tv_template
,
1199 AES_DEC_TEST_VECTORS
);
1200 test_cipher("cbc(aes)", ENCRYPT
, aes_cbc_enc_tv_template
,
1201 AES_CBC_ENC_TEST_VECTORS
);
1202 test_cipher("cbc(aes)", DECRYPT
, aes_cbc_dec_tv_template
,
1203 AES_CBC_DEC_TEST_VECTORS
);
1204 test_cipher("lrw(aes)", ENCRYPT
, aes_lrw_enc_tv_template
,
1205 AES_LRW_ENC_TEST_VECTORS
);
1206 test_cipher("lrw(aes)", DECRYPT
, aes_lrw_dec_tv_template
,
1207 AES_LRW_DEC_TEST_VECTORS
);
1208 test_cipher("xts(aes)", ENCRYPT
, aes_xts_enc_tv_template
,
1209 AES_XTS_ENC_TEST_VECTORS
);
1210 test_cipher("xts(aes)", DECRYPT
, aes_xts_dec_tv_template
,
1211 AES_XTS_DEC_TEST_VECTORS
);
1212 test_cipher("rfc3686(ctr(aes))", ENCRYPT
, aes_ctr_enc_tv_template
,
1213 AES_CTR_ENC_TEST_VECTORS
);
1214 test_cipher("rfc3686(ctr(aes))", DECRYPT
, aes_ctr_dec_tv_template
,
1215 AES_CTR_DEC_TEST_VECTORS
);
1216 test_aead("gcm(aes)", ENCRYPT
, aes_gcm_enc_tv_template
,
1217 AES_GCM_ENC_TEST_VECTORS
);
1218 test_aead("gcm(aes)", DECRYPT
, aes_gcm_dec_tv_template
,
1219 AES_GCM_DEC_TEST_VECTORS
);
1220 test_aead("ccm(aes)", ENCRYPT
, aes_ccm_enc_tv_template
,
1221 AES_CCM_ENC_TEST_VECTORS
);
1222 test_aead("ccm(aes)", DECRYPT
, aes_ccm_dec_tv_template
,
1223 AES_CCM_DEC_TEST_VECTORS
);
1226 test_cipher("ecb(cast5)", ENCRYPT
, cast5_enc_tv_template
,
1227 CAST5_ENC_TEST_VECTORS
);
1228 test_cipher("ecb(cast5)", DECRYPT
, cast5_dec_tv_template
,
1229 CAST5_DEC_TEST_VECTORS
);
1232 test_cipher("ecb(cast6)", ENCRYPT
, cast6_enc_tv_template
,
1233 CAST6_ENC_TEST_VECTORS
);
1234 test_cipher("ecb(cast6)", DECRYPT
, cast6_dec_tv_template
,
1235 CAST6_DEC_TEST_VECTORS
);
1238 test_cipher("ecb(arc4)", ENCRYPT
, arc4_enc_tv_template
,
1239 ARC4_ENC_TEST_VECTORS
);
1240 test_cipher("ecb(arc4)", DECRYPT
, arc4_dec_tv_template
,
1241 ARC4_DEC_TEST_VECTORS
);
1244 test_cipher("ecb(tea)", ENCRYPT
, tea_enc_tv_template
,
1245 TEA_ENC_TEST_VECTORS
);
1246 test_cipher("ecb(tea)", DECRYPT
, tea_dec_tv_template
,
1247 TEA_DEC_TEST_VECTORS
);
1251 test_cipher("ecb(xtea)", ENCRYPT
, xtea_enc_tv_template
,
1252 XTEA_ENC_TEST_VECTORS
);
1253 test_cipher("ecb(xtea)", DECRYPT
, xtea_dec_tv_template
,
1254 XTEA_DEC_TEST_VECTORS
);
1257 test_cipher("ecb(khazad)", ENCRYPT
, khazad_enc_tv_template
,
1258 KHAZAD_ENC_TEST_VECTORS
);
1259 test_cipher("ecb(khazad)", DECRYPT
, khazad_dec_tv_template
,
1260 KHAZAD_DEC_TEST_VECTORS
);
1263 test_cipher("ecb(anubis)", ENCRYPT
, anubis_enc_tv_template
,
1264 ANUBIS_ENC_TEST_VECTORS
);
1265 test_cipher("ecb(anubis)", DECRYPT
, anubis_dec_tv_template
,
1266 ANUBIS_DEC_TEST_VECTORS
);
1267 test_cipher("cbc(anubis)", ENCRYPT
, anubis_cbc_enc_tv_template
,
1268 ANUBIS_CBC_ENC_TEST_VECTORS
);
1269 test_cipher("cbc(anubis)", DECRYPT
, anubis_cbc_dec_tv_template
,
1270 ANUBIS_CBC_ENC_TEST_VECTORS
);
1273 test_cipher("ecb(xeta)", ENCRYPT
, xeta_enc_tv_template
,
1274 XETA_ENC_TEST_VECTORS
);
1275 test_cipher("ecb(xeta)", DECRYPT
, xeta_dec_tv_template
,
1276 XETA_DEC_TEST_VECTORS
);
1279 test_cipher("pcbc(fcrypt)", ENCRYPT
, fcrypt_pcbc_enc_tv_template
,
1280 FCRYPT_ENC_TEST_VECTORS
);
1281 test_cipher("pcbc(fcrypt)", DECRYPT
, fcrypt_pcbc_dec_tv_template
,
1282 FCRYPT_DEC_TEST_VECTORS
);
1285 test_cipher("ecb(camellia)", ENCRYPT
,
1286 camellia_enc_tv_template
,
1287 CAMELLIA_ENC_TEST_VECTORS
);
1288 test_cipher("ecb(camellia)", DECRYPT
,
1289 camellia_dec_tv_template
,
1290 CAMELLIA_DEC_TEST_VECTORS
);
1291 test_cipher("cbc(camellia)", ENCRYPT
,
1292 camellia_cbc_enc_tv_template
,
1293 CAMELLIA_CBC_ENC_TEST_VECTORS
);
1294 test_cipher("cbc(camellia)", DECRYPT
,
1295 camellia_cbc_dec_tv_template
,
1296 CAMELLIA_CBC_DEC_TEST_VECTORS
);
1299 test_cipher("ecb(seed)", ENCRYPT
, seed_enc_tv_template
,
1300 SEED_ENC_TEST_VECTORS
);
1301 test_cipher("ecb(seed)", DECRYPT
, seed_dec_tv_template
,
1302 SEED_DEC_TEST_VECTORS
);
1304 test_hash("sha384", sha384_tv_template
, SHA384_TEST_VECTORS
);
1305 test_hash("sha512", sha512_tv_template
, SHA512_TEST_VECTORS
);
1306 test_hash("wp512", wp512_tv_template
, WP512_TEST_VECTORS
);
1307 test_hash("wp384", wp384_tv_template
, WP384_TEST_VECTORS
);
1308 test_hash("wp256", wp256_tv_template
, WP256_TEST_VECTORS
);
1309 test_hash("tgr192", tgr192_tv_template
, TGR192_TEST_VECTORS
);
1310 test_hash("tgr160", tgr160_tv_template
, TGR160_TEST_VECTORS
);
1311 test_hash("tgr128", tgr128_tv_template
, TGR128_TEST_VECTORS
);
1312 test_comp("deflate", deflate_comp_tv_template
,
1313 deflate_decomp_tv_template
, DEFLATE_COMP_TEST_VECTORS
,
1314 DEFLATE_DECOMP_TEST_VECTORS
);
1315 test_comp("lzo", lzo_comp_tv_template
, lzo_decomp_tv_template
,
1316 LZO_COMP_TEST_VECTORS
, LZO_DECOMP_TEST_VECTORS
);
1317 test_hash("crc32c", crc32c_tv_template
, CRC32C_TEST_VECTORS
);
1318 test_hash("hmac(md5)", hmac_md5_tv_template
,
1319 HMAC_MD5_TEST_VECTORS
);
1320 test_hash("hmac(sha1)", hmac_sha1_tv_template
,
1321 HMAC_SHA1_TEST_VECTORS
);
1322 test_hash("hmac(sha224)", hmac_sha224_tv_template
,
1323 HMAC_SHA224_TEST_VECTORS
);
1324 test_hash("hmac(sha256)", hmac_sha256_tv_template
,
1325 HMAC_SHA256_TEST_VECTORS
);
1326 test_hash("hmac(sha384)", hmac_sha384_tv_template
,
1327 HMAC_SHA384_TEST_VECTORS
);
1328 test_hash("hmac(sha512)", hmac_sha512_tv_template
,
1329 HMAC_SHA512_TEST_VECTORS
);
1331 test_hash("xcbc(aes)", aes_xcbc128_tv_template
,
1332 XCBC_AES_TEST_VECTORS
);
1334 test_hash("michael_mic", michael_mic_tv_template
, MICHAEL_MIC_TEST_VECTORS
);
1338 test_hash("md5", md5_tv_template
, MD5_TEST_VECTORS
);
1342 test_hash("sha1", sha1_tv_template
, SHA1_TEST_VECTORS
);
1346 test_cipher("ecb(des)", ENCRYPT
, des_enc_tv_template
,
1347 DES_ENC_TEST_VECTORS
);
1348 test_cipher("ecb(des)", DECRYPT
, des_dec_tv_template
,
1349 DES_DEC_TEST_VECTORS
);
1350 test_cipher("cbc(des)", ENCRYPT
, des_cbc_enc_tv_template
,
1351 DES_CBC_ENC_TEST_VECTORS
);
1352 test_cipher("cbc(des)", DECRYPT
, des_cbc_dec_tv_template
,
1353 DES_CBC_DEC_TEST_VECTORS
);
1357 test_cipher("ecb(des3_ede)", ENCRYPT
, des3_ede_enc_tv_template
,
1358 DES3_EDE_ENC_TEST_VECTORS
);
1359 test_cipher("ecb(des3_ede)", DECRYPT
, des3_ede_dec_tv_template
,
1360 DES3_EDE_DEC_TEST_VECTORS
);
1364 test_hash("md4", md4_tv_template
, MD4_TEST_VECTORS
);
1368 test_hash("sha256", sha256_tv_template
, SHA256_TEST_VECTORS
);
1372 test_cipher("ecb(blowfish)", ENCRYPT
, bf_enc_tv_template
,
1373 BF_ENC_TEST_VECTORS
);
1374 test_cipher("ecb(blowfish)", DECRYPT
, bf_dec_tv_template
,
1375 BF_DEC_TEST_VECTORS
);
1376 test_cipher("cbc(blowfish)", ENCRYPT
, bf_cbc_enc_tv_template
,
1377 BF_CBC_ENC_TEST_VECTORS
);
1378 test_cipher("cbc(blowfish)", DECRYPT
, bf_cbc_dec_tv_template
,
1379 BF_CBC_DEC_TEST_VECTORS
);
1383 test_cipher("ecb(twofish)", ENCRYPT
, tf_enc_tv_template
,
1384 TF_ENC_TEST_VECTORS
);
1385 test_cipher("ecb(twofish)", DECRYPT
, tf_dec_tv_template
,
1386 TF_DEC_TEST_VECTORS
);
1387 test_cipher("cbc(twofish)", ENCRYPT
, tf_cbc_enc_tv_template
,
1388 TF_CBC_ENC_TEST_VECTORS
);
1389 test_cipher("cbc(twofish)", DECRYPT
, tf_cbc_dec_tv_template
,
1390 TF_CBC_DEC_TEST_VECTORS
);
1394 test_cipher("ecb(serpent)", ENCRYPT
, serpent_enc_tv_template
,
1395 SERPENT_ENC_TEST_VECTORS
);
1396 test_cipher("ecb(serpent)", DECRYPT
, serpent_dec_tv_template
,
1397 SERPENT_DEC_TEST_VECTORS
);
1401 test_cipher("ecb(aes)", ENCRYPT
, aes_enc_tv_template
,
1402 AES_ENC_TEST_VECTORS
);
1403 test_cipher("ecb(aes)", DECRYPT
, aes_dec_tv_template
,
1404 AES_DEC_TEST_VECTORS
);
1405 test_cipher("cbc(aes)", ENCRYPT
, aes_cbc_enc_tv_template
,
1406 AES_CBC_ENC_TEST_VECTORS
);
1407 test_cipher("cbc(aes)", DECRYPT
, aes_cbc_dec_tv_template
,
1408 AES_CBC_DEC_TEST_VECTORS
);
1409 test_cipher("lrw(aes)", ENCRYPT
, aes_lrw_enc_tv_template
,
1410 AES_LRW_ENC_TEST_VECTORS
);
1411 test_cipher("lrw(aes)", DECRYPT
, aes_lrw_dec_tv_template
,
1412 AES_LRW_DEC_TEST_VECTORS
);
1413 test_cipher("xts(aes)", ENCRYPT
, aes_xts_enc_tv_template
,
1414 AES_XTS_ENC_TEST_VECTORS
);
1415 test_cipher("xts(aes)", DECRYPT
, aes_xts_dec_tv_template
,
1416 AES_XTS_DEC_TEST_VECTORS
);
1417 test_cipher("rfc3686(ctr(aes))", ENCRYPT
, aes_ctr_enc_tv_template
,
1418 AES_CTR_ENC_TEST_VECTORS
);
1419 test_cipher("rfc3686(ctr(aes))", DECRYPT
, aes_ctr_dec_tv_template
,
1420 AES_CTR_DEC_TEST_VECTORS
);
1424 test_hash("sha384", sha384_tv_template
, SHA384_TEST_VECTORS
);
1428 test_hash("sha512", sha512_tv_template
, SHA512_TEST_VECTORS
);
1432 test_comp("deflate", deflate_comp_tv_template
,
1433 deflate_decomp_tv_template
, DEFLATE_COMP_TEST_VECTORS
,
1434 DEFLATE_DECOMP_TEST_VECTORS
);
1438 test_cipher("ecb(cast5)", ENCRYPT
, cast5_enc_tv_template
,
1439 CAST5_ENC_TEST_VECTORS
);
1440 test_cipher("ecb(cast5)", DECRYPT
, cast5_dec_tv_template
,
1441 CAST5_DEC_TEST_VECTORS
);
1445 test_cipher("ecb(cast6)", ENCRYPT
, cast6_enc_tv_template
,
1446 CAST6_ENC_TEST_VECTORS
);
1447 test_cipher("ecb(cast6)", DECRYPT
, cast6_dec_tv_template
,
1448 CAST6_DEC_TEST_VECTORS
);
1452 test_cipher("ecb(arc4)", ENCRYPT
, arc4_enc_tv_template
,
1453 ARC4_ENC_TEST_VECTORS
);
1454 test_cipher("ecb(arc4)", DECRYPT
, arc4_dec_tv_template
,
1455 ARC4_DEC_TEST_VECTORS
);
1459 test_hash("michael_mic", michael_mic_tv_template
, MICHAEL_MIC_TEST_VECTORS
);
1463 test_hash("crc32c", crc32c_tv_template
, CRC32C_TEST_VECTORS
);
1467 test_cipher("ecb(tea)", ENCRYPT
, tea_enc_tv_template
,
1468 TEA_ENC_TEST_VECTORS
);
1469 test_cipher("ecb(tea)", DECRYPT
, tea_dec_tv_template
,
1470 TEA_DEC_TEST_VECTORS
);
1474 test_cipher("ecb(xtea)", ENCRYPT
, xtea_enc_tv_template
,
1475 XTEA_ENC_TEST_VECTORS
);
1476 test_cipher("ecb(xtea)", DECRYPT
, xtea_dec_tv_template
,
1477 XTEA_DEC_TEST_VECTORS
);
1481 test_cipher("ecb(khazad)", ENCRYPT
, khazad_enc_tv_template
,
1482 KHAZAD_ENC_TEST_VECTORS
);
1483 test_cipher("ecb(khazad)", DECRYPT
, khazad_dec_tv_template
,
1484 KHAZAD_DEC_TEST_VECTORS
);
1488 test_hash("wp512", wp512_tv_template
, WP512_TEST_VECTORS
);
1492 test_hash("wp384", wp384_tv_template
, WP384_TEST_VECTORS
);
1496 test_hash("wp256", wp256_tv_template
, WP256_TEST_VECTORS
);
1500 test_cipher("ecb(tnepres)", ENCRYPT
, tnepres_enc_tv_template
,
1501 TNEPRES_ENC_TEST_VECTORS
);
1502 test_cipher("ecb(tnepres)", DECRYPT
, tnepres_dec_tv_template
,
1503 TNEPRES_DEC_TEST_VECTORS
);
1507 test_cipher("ecb(anubis)", ENCRYPT
, anubis_enc_tv_template
,
1508 ANUBIS_ENC_TEST_VECTORS
);
1509 test_cipher("ecb(anubis)", DECRYPT
, anubis_dec_tv_template
,
1510 ANUBIS_DEC_TEST_VECTORS
);
1511 test_cipher("cbc(anubis)", ENCRYPT
, anubis_cbc_enc_tv_template
,
1512 ANUBIS_CBC_ENC_TEST_VECTORS
);
1513 test_cipher("cbc(anubis)", DECRYPT
, anubis_cbc_dec_tv_template
,
1514 ANUBIS_CBC_ENC_TEST_VECTORS
);
1518 test_hash("tgr192", tgr192_tv_template
, TGR192_TEST_VECTORS
);
1523 test_hash("tgr160", tgr160_tv_template
, TGR160_TEST_VECTORS
);
1527 test_hash("tgr128", tgr128_tv_template
, TGR128_TEST_VECTORS
);
1531 test_cipher("ecb(xeta)", ENCRYPT
, xeta_enc_tv_template
,
1532 XETA_ENC_TEST_VECTORS
);
1533 test_cipher("ecb(xeta)", DECRYPT
, xeta_dec_tv_template
,
1534 XETA_DEC_TEST_VECTORS
);
1538 test_cipher("pcbc(fcrypt)", ENCRYPT
, fcrypt_pcbc_enc_tv_template
,
1539 FCRYPT_ENC_TEST_VECTORS
);
1540 test_cipher("pcbc(fcrypt)", DECRYPT
, fcrypt_pcbc_dec_tv_template
,
1541 FCRYPT_DEC_TEST_VECTORS
);
1545 test_cipher("ecb(camellia)", ENCRYPT
,
1546 camellia_enc_tv_template
,
1547 CAMELLIA_ENC_TEST_VECTORS
);
1548 test_cipher("ecb(camellia)", DECRYPT
,
1549 camellia_dec_tv_template
,
1550 CAMELLIA_DEC_TEST_VECTORS
);
1551 test_cipher("cbc(camellia)", ENCRYPT
,
1552 camellia_cbc_enc_tv_template
,
1553 CAMELLIA_CBC_ENC_TEST_VECTORS
);
1554 test_cipher("cbc(camellia)", DECRYPT
,
1555 camellia_cbc_dec_tv_template
,
1556 CAMELLIA_CBC_DEC_TEST_VECTORS
);
1559 test_hash("sha224", sha224_tv_template
, SHA224_TEST_VECTORS
);
1563 test_cipher("salsa20", ENCRYPT
,
1564 salsa20_stream_enc_tv_template
,
1565 SALSA20_STREAM_ENC_TEST_VECTORS
);
1569 test_aead("gcm(aes)", ENCRYPT
, aes_gcm_enc_tv_template
,
1570 AES_GCM_ENC_TEST_VECTORS
);
1571 test_aead("gcm(aes)", DECRYPT
, aes_gcm_dec_tv_template
,
1572 AES_GCM_DEC_TEST_VECTORS
);
1576 test_comp("lzo", lzo_comp_tv_template
, lzo_decomp_tv_template
,
1577 LZO_COMP_TEST_VECTORS
, LZO_DECOMP_TEST_VECTORS
);
1581 test_aead("ccm(aes)", ENCRYPT
, aes_ccm_enc_tv_template
,
1582 AES_CCM_ENC_TEST_VECTORS
);
1583 test_aead("ccm(aes)", DECRYPT
, aes_ccm_dec_tv_template
,
1584 AES_CCM_DEC_TEST_VECTORS
);
1588 test_hash("hmac(md5)", hmac_md5_tv_template
,
1589 HMAC_MD5_TEST_VECTORS
);
1593 test_hash("hmac(sha1)", hmac_sha1_tv_template
,
1594 HMAC_SHA1_TEST_VECTORS
);
1598 test_hash("hmac(sha256)", hmac_sha256_tv_template
,
1599 HMAC_SHA256_TEST_VECTORS
);
1603 test_hash("hmac(sha384)", hmac_sha384_tv_template
,
1604 HMAC_SHA384_TEST_VECTORS
);
1608 test_hash("hmac(sha512)", hmac_sha512_tv_template
,
1609 HMAC_SHA512_TEST_VECTORS
);
1613 test_hash("hmac(sha224)", hmac_sha224_tv_template
,
1614 HMAC_SHA224_TEST_VECTORS
);
1618 test_hash("xcbc(aes)", aes_xcbc128_tv_template
,
1619 XCBC_AES_TEST_VECTORS
);
1623 test_cipher_speed("ecb(aes)", ENCRYPT
, sec
, NULL
, 0,
1624 aes_speed_template
);
1625 test_cipher_speed("ecb(aes)", DECRYPT
, sec
, NULL
, 0,
1626 aes_speed_template
);
1627 test_cipher_speed("cbc(aes)", ENCRYPT
, sec
, NULL
, 0,
1628 aes_speed_template
);
1629 test_cipher_speed("cbc(aes)", DECRYPT
, sec
, NULL
, 0,
1630 aes_speed_template
);
1631 test_cipher_speed("lrw(aes)", ENCRYPT
, sec
, NULL
, 0,
1632 aes_lrw_speed_template
);
1633 test_cipher_speed("lrw(aes)", DECRYPT
, sec
, NULL
, 0,
1634 aes_lrw_speed_template
);
1635 test_cipher_speed("xts(aes)", ENCRYPT
, sec
, NULL
, 0,
1636 aes_xts_speed_template
);
1637 test_cipher_speed("xts(aes)", DECRYPT
, sec
, NULL
, 0,
1638 aes_xts_speed_template
);
1642 test_cipher_speed("ecb(des3_ede)", ENCRYPT
, sec
,
1643 des3_ede_enc_tv_template
,
1644 DES3_EDE_ENC_TEST_VECTORS
,
1645 des3_ede_speed_template
);
1646 test_cipher_speed("ecb(des3_ede)", DECRYPT
, sec
,
1647 des3_ede_dec_tv_template
,
1648 DES3_EDE_DEC_TEST_VECTORS
,
1649 des3_ede_speed_template
);
1650 test_cipher_speed("cbc(des3_ede)", ENCRYPT
, sec
,
1651 des3_ede_enc_tv_template
,
1652 DES3_EDE_ENC_TEST_VECTORS
,
1653 des3_ede_speed_template
);
1654 test_cipher_speed("cbc(des3_ede)", DECRYPT
, sec
,
1655 des3_ede_dec_tv_template
,
1656 DES3_EDE_DEC_TEST_VECTORS
,
1657 des3_ede_speed_template
);
1661 test_cipher_speed("ecb(twofish)", ENCRYPT
, sec
, NULL
, 0,
1662 twofish_speed_template
);
1663 test_cipher_speed("ecb(twofish)", DECRYPT
, sec
, NULL
, 0,
1664 twofish_speed_template
);
1665 test_cipher_speed("cbc(twofish)", ENCRYPT
, sec
, NULL
, 0,
1666 twofish_speed_template
);
1667 test_cipher_speed("cbc(twofish)", DECRYPT
, sec
, NULL
, 0,
1668 twofish_speed_template
);
1672 test_cipher_speed("ecb(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1673 blowfish_speed_template
);
1674 test_cipher_speed("ecb(blowfish)", DECRYPT
, sec
, NULL
, 0,
1675 blowfish_speed_template
);
1676 test_cipher_speed("cbc(blowfish)", ENCRYPT
, sec
, NULL
, 0,
1677 blowfish_speed_template
);
1678 test_cipher_speed("cbc(blowfish)", DECRYPT
, sec
, NULL
, 0,
1679 blowfish_speed_template
);
1683 test_cipher_speed("ecb(des)", ENCRYPT
, sec
, NULL
, 0,
1684 des_speed_template
);
1685 test_cipher_speed("ecb(des)", DECRYPT
, sec
, NULL
, 0,
1686 des_speed_template
);
1687 test_cipher_speed("cbc(des)", ENCRYPT
, sec
, NULL
, 0,
1688 des_speed_template
);
1689 test_cipher_speed("cbc(des)", DECRYPT
, sec
, NULL
, 0,
1690 des_speed_template
);
1694 test_cipher_speed("ecb(camellia)", ENCRYPT
, sec
, NULL
, 0,
1695 camellia_speed_template
);
1696 test_cipher_speed("ecb(camellia)", DECRYPT
, sec
, NULL
, 0,
1697 camellia_speed_template
);
1698 test_cipher_speed("cbc(camellia)", ENCRYPT
, sec
, NULL
, 0,
1699 camellia_speed_template
);
1700 test_cipher_speed("cbc(camellia)", DECRYPT
, sec
, NULL
, 0,
1701 camellia_speed_template
);
1705 test_cipher_speed("salsa20", ENCRYPT
, sec
, NULL
, 0,
1706 salsa20_speed_template
);
1713 test_hash_speed("md4", sec
, generic_hash_speed_template
);
1714 if (mode
> 300 && mode
< 400) break;
1717 test_hash_speed("md5", sec
, generic_hash_speed_template
);
1718 if (mode
> 300 && mode
< 400) break;
1721 test_hash_speed("sha1", sec
, generic_hash_speed_template
);
1722 if (mode
> 300 && mode
< 400) break;
1725 test_hash_speed("sha256", sec
, generic_hash_speed_template
);
1726 if (mode
> 300 && mode
< 400) break;
1729 test_hash_speed("sha384", sec
, generic_hash_speed_template
);
1730 if (mode
> 300 && mode
< 400) break;
1733 test_hash_speed("sha512", sec
, generic_hash_speed_template
);
1734 if (mode
> 300 && mode
< 400) break;
1737 test_hash_speed("wp256", sec
, generic_hash_speed_template
);
1738 if (mode
> 300 && mode
< 400) break;
1741 test_hash_speed("wp384", sec
, generic_hash_speed_template
);
1742 if (mode
> 300 && mode
< 400) break;
1745 test_hash_speed("wp512", sec
, generic_hash_speed_template
);
1746 if (mode
> 300 && mode
< 400) break;
1749 test_hash_speed("tgr128", sec
, generic_hash_speed_template
);
1750 if (mode
> 300 && mode
< 400) break;
1753 test_hash_speed("tgr160", sec
, generic_hash_speed_template
);
1754 if (mode
> 300 && mode
< 400) break;
1757 test_hash_speed("tgr192", sec
, generic_hash_speed_template
);
1758 if (mode
> 300 && mode
< 400) break;
1761 test_hash_speed("sha224", sec
, generic_hash_speed_template
);
1762 if (mode
> 300 && mode
< 400) break;
1772 /* useful for debugging */
1773 printk("not testing anything\n");
1778 static int __init
init(void)
1782 tvmem
= kmalloc(TVMEMSIZE
, GFP_KERNEL
);
1786 xbuf
= kmalloc(XBUFSIZE
, GFP_KERNEL
);
1790 axbuf
= kmalloc(XBUFSIZE
, GFP_KERNEL
);
1796 /* We intentionaly return -EAGAIN to prevent keeping
1797 * the module. It does all its work from init()
1798 * and doesn't offer any runtime functionality
1799 * => we don't need it in the memory, do we?
1814 * If an init function is provided, an exit function must also be provided
1815 * to allow module unload.
1817 static void __exit
fini(void) { }
1822 module_param(mode
, int, 0);
1823 module_param(sec
, uint
, 0);
1824 MODULE_PARM_DESC(sec
, "Length in seconds of speed tests "
1825 "(defaults to zero which uses CPU cycles instead)");
1827 MODULE_LICENSE("GPL");
1828 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1829 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");