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>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
15 * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>)
16 * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt
20 #include <linux/init.h>
21 #include <linux/module.h>
23 #include <linux/slab.h>
24 #include <linux/scatterlist.h>
25 #include <linux/string.h>
26 #include <linux/crypto.h>
27 #include <linux/highmem.h>
28 #include <linux/moduleparam.h>
29 #include <linux/jiffies.h>
30 #include <linux/timex.h>
31 #include <linux/interrupt.h>
35 * Need to kmalloc() memory for testing kmap().
37 #define TVMEMSIZE 16384
38 #define XBUFSIZE 32768
41 * Indexes into the xbuf to simulate cross-page access.
53 * Used by test_cipher()
60 static unsigned int IDX
[8] = { IDX1
, IDX2
, IDX3
, IDX4
, IDX5
, IDX6
, IDX7
, IDX8
};
63 * Used by test_cipher_speed()
65 static unsigned int sec
;
71 static char *check
[] = {
72 "des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish",
73 "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6",
74 "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
75 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", NULL
78 static void hexdump(unsigned char *buf
, unsigned int len
)
81 printk("%02x", *buf
++);
86 static void test_hash(char *algo
, struct hash_testvec
*template,
89 unsigned int i
, j
, k
, temp
;
90 struct scatterlist sg
[8];
92 struct crypto_tfm
*tfm
;
93 struct hash_testvec
*hash_tv
;
96 printk("\ntesting %s\n", algo
);
98 tsize
= sizeof(struct hash_testvec
);
101 if (tsize
> TVMEMSIZE
) {
102 printk("template (%u) too big for tvmem (%u)\n", tsize
, TVMEMSIZE
);
106 memcpy(tvmem
, template, tsize
);
107 hash_tv
= (void *)tvmem
;
108 tfm
= crypto_alloc_tfm(algo
, 0);
110 printk("failed to load transform for %s\n", algo
);
114 for (i
= 0; i
< tcount
; i
++) {
115 printk("test %u:\n", i
+ 1);
116 memset(result
, 0, 64);
118 sg_set_buf(&sg
[0], hash_tv
[i
].plaintext
, hash_tv
[i
].psize
);
120 crypto_digest_init(tfm
);
121 if (tfm
->crt_u
.digest
.dit_setkey
) {
122 crypto_digest_setkey(tfm
, hash_tv
[i
].key
,
125 crypto_digest_update(tfm
, sg
, 1);
126 crypto_digest_final(tfm
, result
);
128 hexdump(result
, crypto_tfm_alg_digestsize(tfm
));
130 memcmp(result
, hash_tv
[i
].digest
,
131 crypto_tfm_alg_digestsize(tfm
)) ?
135 printk("testing %s across pages\n", algo
);
137 /* setup the dummy buffer first */
138 memset(xbuf
, 0, XBUFSIZE
);
141 for (i
= 0; i
< tcount
; i
++) {
144 printk("test %u:\n", j
);
145 memset(result
, 0, 64);
148 for (k
= 0; k
< hash_tv
[i
].np
; k
++) {
149 memcpy(&xbuf
[IDX
[k
]],
150 hash_tv
[i
].plaintext
+ temp
,
152 temp
+= hash_tv
[i
].tap
[k
];
153 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
157 crypto_digest_digest(tfm
, sg
, hash_tv
[i
].np
, result
);
159 hexdump(result
, crypto_tfm_alg_digestsize(tfm
));
161 memcmp(result
, hash_tv
[i
].digest
,
162 crypto_tfm_alg_digestsize(tfm
)) ?
167 crypto_free_tfm(tfm
);
171 #ifdef CONFIG_CRYPTO_HMAC
173 static void test_hmac(char *algo
, struct hmac_testvec
*template,
176 unsigned int i
, j
, k
, temp
;
177 struct scatterlist sg
[8];
179 struct crypto_tfm
*tfm
;
180 struct hmac_testvec
*hmac_tv
;
181 unsigned int tsize
, klen
;
183 tfm
= crypto_alloc_tfm(algo
, 0);
185 printk("failed to load transform for %s\n", algo
);
189 printk("\ntesting hmac_%s\n", algo
);
191 tsize
= sizeof(struct hmac_testvec
);
193 if (tsize
> TVMEMSIZE
) {
194 printk("template (%u) too big for tvmem (%u)\n", tsize
,
199 memcpy(tvmem
, template, tsize
);
200 hmac_tv
= (void *)tvmem
;
202 for (i
= 0; i
< tcount
; i
++) {
203 printk("test %u:\n", i
+ 1);
204 memset(result
, 0, sizeof (result
));
206 klen
= hmac_tv
[i
].ksize
;
207 sg_set_buf(&sg
[0], hmac_tv
[i
].plaintext
, hmac_tv
[i
].psize
);
209 crypto_hmac(tfm
, hmac_tv
[i
].key
, &klen
, sg
, 1, result
);
211 hexdump(result
, crypto_tfm_alg_digestsize(tfm
));
213 memcmp(result
, hmac_tv
[i
].digest
,
214 crypto_tfm_alg_digestsize(tfm
)) ? "fail" :
218 printk("\ntesting hmac_%s across pages\n", algo
);
220 memset(xbuf
, 0, XBUFSIZE
);
223 for (i
= 0; i
< tcount
; i
++) {
226 printk("test %u:\n",j
);
227 memset(result
, 0, 64);
230 klen
= hmac_tv
[i
].ksize
;
231 for (k
= 0; k
< hmac_tv
[i
].np
; k
++) {
232 memcpy(&xbuf
[IDX
[k
]],
233 hmac_tv
[i
].plaintext
+ temp
,
235 temp
+= hmac_tv
[i
].tap
[k
];
236 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
240 crypto_hmac(tfm
, hmac_tv
[i
].key
, &klen
, sg
,
241 hmac_tv
[i
].np
, result
);
242 hexdump(result
, crypto_tfm_alg_digestsize(tfm
));
245 memcmp(result
, hmac_tv
[i
].digest
,
246 crypto_tfm_alg_digestsize(tfm
)) ?
251 crypto_free_tfm(tfm
);
254 #endif /* CONFIG_CRYPTO_HMAC */
256 static void test_cipher(char *algo
, int mode
, int enc
,
257 struct cipher_testvec
*template, unsigned int tcount
)
259 unsigned int ret
, i
, j
, k
, temp
;
262 struct crypto_tfm
*tfm
;
264 struct cipher_testvec
*cipher_tv
;
265 struct scatterlist sg
[8];
272 if (mode
== MODE_ECB
)
277 printk("\ntesting %s %s %s\n", algo
, m
, e
);
279 tsize
= sizeof (struct cipher_testvec
);
282 if (tsize
> TVMEMSIZE
) {
283 printk("template (%u) too big for tvmem (%u)\n", tsize
,
288 memcpy(tvmem
, template, tsize
);
289 cipher_tv
= (void *)tvmem
;
292 tfm
= crypto_alloc_tfm(algo
, 0);
294 tfm
= crypto_alloc_tfm(algo
, CRYPTO_TFM_MODE_CBC
);
297 printk("failed to load transform for %s %s\n", algo
, m
);
302 for (i
= 0; i
< tcount
; i
++) {
303 if (!(cipher_tv
[i
].np
)) {
305 printk("test %u (%d bit key):\n",
306 j
, cipher_tv
[i
].klen
* 8);
310 tfm
->crt_flags
|= CRYPTO_TFM_REQ_WEAK_KEY
;
311 key
= cipher_tv
[i
].key
;
313 ret
= crypto_cipher_setkey(tfm
, key
, cipher_tv
[i
].klen
);
315 printk("setkey() failed flags=%x\n", tfm
->crt_flags
);
317 if (!cipher_tv
[i
].fail
)
321 sg_set_buf(&sg
[0], cipher_tv
[i
].input
,
325 crypto_cipher_set_iv(tfm
, cipher_tv
[i
].iv
,
326 crypto_tfm_alg_ivsize(tfm
));
330 ret
= crypto_cipher_encrypt(tfm
, sg
, sg
, cipher_tv
[i
].ilen
);
332 ret
= crypto_cipher_decrypt(tfm
, sg
, sg
, cipher_tv
[i
].ilen
);
336 printk("%s () failed flags=%x\n", e
, tfm
->crt_flags
);
340 q
= kmap(sg
[0].page
) + sg
[0].offset
;
341 hexdump(q
, cipher_tv
[i
].rlen
);
344 memcmp(q
, cipher_tv
[i
].result
,
345 cipher_tv
[i
].rlen
) ? "fail" : "pass");
349 printk("\ntesting %s %s %s across pages (chunking)\n", algo
, m
, e
);
350 memset(xbuf
, 0, XBUFSIZE
);
353 for (i
= 0; i
< tcount
; i
++) {
354 if (cipher_tv
[i
].np
) {
356 printk("test %u (%d bit key):\n",
357 j
, cipher_tv
[i
].klen
* 8);
361 tfm
->crt_flags
|= CRYPTO_TFM_REQ_WEAK_KEY
;
362 key
= cipher_tv
[i
].key
;
364 ret
= crypto_cipher_setkey(tfm
, key
, cipher_tv
[i
].klen
);
366 printk("setkey() failed flags=%x\n", tfm
->crt_flags
);
368 if (!cipher_tv
[i
].fail
)
373 for (k
= 0; k
< cipher_tv
[i
].np
; k
++) {
374 memcpy(&xbuf
[IDX
[k
]],
375 cipher_tv
[i
].input
+ temp
,
376 cipher_tv
[i
].tap
[k
]);
377 temp
+= cipher_tv
[i
].tap
[k
];
378 sg_set_buf(&sg
[k
], &xbuf
[IDX
[k
]],
379 cipher_tv
[i
].tap
[k
]);
383 crypto_cipher_set_iv(tfm
, cipher_tv
[i
].iv
,
384 crypto_tfm_alg_ivsize(tfm
));
388 ret
= crypto_cipher_encrypt(tfm
, sg
, sg
, cipher_tv
[i
].ilen
);
390 ret
= crypto_cipher_decrypt(tfm
, sg
, sg
, cipher_tv
[i
].ilen
);
393 printk("%s () failed flags=%x\n", e
, tfm
->crt_flags
);
398 for (k
= 0; k
< cipher_tv
[i
].np
; k
++) {
399 printk("page %u\n", k
);
400 q
= kmap(sg
[k
].page
) + sg
[k
].offset
;
401 hexdump(q
, cipher_tv
[i
].tap
[k
]);
403 memcmp(q
, cipher_tv
[i
].result
+ temp
,
404 cipher_tv
[i
].tap
[k
]) ? "fail" :
406 temp
+= cipher_tv
[i
].tap
[k
];
412 crypto_free_tfm(tfm
);
415 static int test_cipher_jiffies(struct crypto_tfm
*tfm
, int enc
, char *p
,
418 struct scatterlist sg
[1];
419 unsigned long start
, end
;
423 sg_set_buf(sg
, p
, blen
);
425 for (start
= jiffies
, end
= start
+ sec
* HZ
, bcount
= 0;
426 time_before(jiffies
, end
); bcount
++) {
428 ret
= crypto_cipher_encrypt(tfm
, sg
, sg
, blen
);
430 ret
= crypto_cipher_decrypt(tfm
, sg
, sg
, blen
);
436 printk("%d operations in %d seconds (%ld bytes)\n",
437 bcount
, sec
, (long)bcount
* blen
);
441 static int test_cipher_cycles(struct crypto_tfm
*tfm
, int enc
, char *p
,
444 struct scatterlist sg
[1];
445 unsigned long cycles
= 0;
449 sg_set_buf(sg
, p
, blen
);
455 for (i
= 0; i
< 4; i
++) {
457 ret
= crypto_cipher_encrypt(tfm
, sg
, sg
, blen
);
459 ret
= crypto_cipher_decrypt(tfm
, sg
, sg
, blen
);
465 /* The real thing. */
466 for (i
= 0; i
< 8; i
++) {
469 start
= get_cycles();
471 ret
= crypto_cipher_encrypt(tfm
, sg
, sg
, blen
);
473 ret
= crypto_cipher_decrypt(tfm
, sg
, sg
, blen
);
479 cycles
+= end
- start
;
487 printk("1 operation in %lu cycles (%d bytes)\n",
488 (cycles
+ 4) / 8, blen
);
493 static void test_cipher_speed(char *algo
, int mode
, int enc
, unsigned int sec
,
494 struct cipher_testvec
*template,
495 unsigned int tcount
, struct cipher_speed
*speed
)
497 unsigned int ret
, i
, j
, iv_len
;
498 unsigned char *key
, *p
, iv
[128];
499 struct crypto_tfm
*tfm
;
506 if (mode
== MODE_ECB
)
511 printk("\ntesting speed of %s %s %s\n", algo
, m
, e
);
514 tfm
= crypto_alloc_tfm(algo
, 0);
516 tfm
= crypto_alloc_tfm(algo
, CRYPTO_TFM_MODE_CBC
);
519 printk("failed to load transform for %s %s\n", algo
, m
);
523 for (i
= 0; speed
[i
].klen
!= 0; i
++) {
524 if ((speed
[i
].blen
+ speed
[i
].klen
) > TVMEMSIZE
) {
525 printk("template (%u) too big for tvmem (%u)\n",
526 speed
[i
].blen
+ speed
[i
].klen
, TVMEMSIZE
);
530 printk("test %u (%d bit key, %d byte blocks): ", i
,
531 speed
[i
].klen
* 8, speed
[i
].blen
);
533 memset(tvmem
, 0xff, speed
[i
].klen
+ speed
[i
].blen
);
535 /* set key, plain text and IV */
536 key
= (unsigned char *)tvmem
;
537 for (j
= 0; j
< tcount
; j
++) {
538 if (template[j
].klen
== speed
[i
].klen
) {
539 key
= template[j
].key
;
543 p
= (unsigned char *)tvmem
+ speed
[i
].klen
;
545 ret
= crypto_cipher_setkey(tfm
, key
, speed
[i
].klen
);
547 printk("setkey() failed flags=%x\n", tfm
->crt_flags
);
552 iv_len
= crypto_tfm_alg_ivsize(tfm
);
553 memset(&iv
, 0xff, iv_len
);
554 crypto_cipher_set_iv(tfm
, iv
, iv_len
);
558 ret
= test_cipher_jiffies(tfm
, enc
, p
, speed
[i
].blen
,
561 ret
= test_cipher_cycles(tfm
, enc
, p
, speed
[i
].blen
);
564 printk("%s() failed flags=%x\n", e
, tfm
->crt_flags
);
570 crypto_free_tfm(tfm
);
573 static void test_deflate(void)
576 char result
[COMP_BUF_SIZE
];
577 struct crypto_tfm
*tfm
;
578 struct comp_testvec
*tv
;
581 printk("\ntesting deflate compression\n");
583 tsize
= sizeof (deflate_comp_tv_template
);
584 if (tsize
> TVMEMSIZE
) {
585 printk("template (%u) too big for tvmem (%u)\n", tsize
,
590 memcpy(tvmem
, deflate_comp_tv_template
, tsize
);
593 tfm
= crypto_alloc_tfm("deflate", 0);
595 printk("failed to load transform for deflate\n");
599 for (i
= 0; i
< DEFLATE_COMP_TEST_VECTORS
; i
++) {
600 int ilen
, ret
, dlen
= COMP_BUF_SIZE
;
602 printk("test %u:\n", i
+ 1);
603 memset(result
, 0, sizeof (result
));
606 ret
= crypto_comp_compress(tfm
, tv
[i
].input
,
607 ilen
, result
, &dlen
);
609 printk("fail: ret=%d\n", ret
);
612 hexdump(result
, dlen
);
613 printk("%s (ratio %d:%d)\n",
614 memcmp(result
, tv
[i
].output
, dlen
) ? "fail" : "pass",
618 printk("\ntesting deflate decompression\n");
620 tsize
= sizeof (deflate_decomp_tv_template
);
621 if (tsize
> TVMEMSIZE
) {
622 printk("template (%u) too big for tvmem (%u)\n", tsize
,
627 memcpy(tvmem
, deflate_decomp_tv_template
, tsize
);
630 for (i
= 0; i
< DEFLATE_DECOMP_TEST_VECTORS
; i
++) {
631 int ilen
, ret
, dlen
= COMP_BUF_SIZE
;
633 printk("test %u:\n", i
+ 1);
634 memset(result
, 0, sizeof (result
));
637 ret
= crypto_comp_decompress(tfm
, tv
[i
].input
,
638 ilen
, result
, &dlen
);
640 printk("fail: ret=%d\n", ret
);
643 hexdump(result
, dlen
);
644 printk("%s (ratio %d:%d)\n",
645 memcmp(result
, tv
[i
].output
, dlen
) ? "fail" : "pass",
649 crypto_free_tfm(tfm
);
652 static void test_crc32c(void)
659 u8 b
, test_vec
[NUMVEC
][VECSIZE
];
660 static u32 vec_results
[NUMVEC
] = {
661 0x0e2c157f, 0xe980ebf6, 0xde74bded,
662 0xd579c862, 0xba979ad0, 0x2b29d913
664 static u32 tot_vec_results
= 0x24c5d375;
666 struct scatterlist sg
[NUMVEC
];
667 struct crypto_tfm
*tfm
;
668 char *fmtdata
= "testing crc32c initialized to %08x: %s\n";
669 #define SEEDTESTVAL 0xedcba987
672 printk("\ntesting crc32c\n");
674 tfm
= crypto_alloc_tfm("crc32c", 0);
676 printk("failed to load transform for crc32c\n");
680 crypto_digest_init(tfm
);
681 crypto_digest_final(tfm
, (u8
*)&crc
);
682 printk(fmtdata
, crc
, (crc
== 0) ? "pass" : "ERROR");
685 * stuff test_vec with known values, simple incrementing
689 for (i
= 0; i
< NUMVEC
; i
++) {
690 for (j
= 0; j
< VECSIZE
; j
++)
691 test_vec
[i
][j
] = ++b
;
692 sg_set_buf(&sg
[i
], test_vec
[i
], VECSIZE
);
696 (void)crypto_digest_setkey(tfm
, (const u8
*)&seed
, sizeof(u32
));
697 crypto_digest_final(tfm
, (u8
*)&crc
);
698 printk("testing crc32c setkey returns %08x : %s\n", crc
, (crc
== (SEEDTESTVAL
^ ~(u32
)0)) ?
701 printk("testing crc32c using update/final:\n");
703 pass
= 1; /* assume all is well */
705 for (i
= 0; i
< NUMVEC
; i
++) {
707 (void)crypto_digest_setkey(tfm
, (const u8
*)&seed
, sizeof(u32
));
708 crypto_digest_update(tfm
, &sg
[i
], 1);
709 crypto_digest_final(tfm
, (u8
*)&crc
);
710 if (crc
== vec_results
[i
]) {
711 printk(" %08x:OK", crc
);
713 printk(" %08x:BAD, wanted %08x\n", crc
, vec_results
[i
]);
718 printk("\ntesting crc32c using incremental accumulator:\n");
720 for (i
= 0; i
< NUMVEC
; i
++) {
721 seed
= (crc
^ ~(u32
)0);
722 (void)crypto_digest_setkey(tfm
, (const u8
*)&seed
, sizeof(u32
));
723 crypto_digest_update(tfm
, &sg
[i
], 1);
724 crypto_digest_final(tfm
, (u8
*)&crc
);
726 if (crc
== tot_vec_results
) {
727 printk(" %08x:OK", crc
);
729 printk(" %08x:BAD, wanted %08x\n", crc
, tot_vec_results
);
733 printk("\ntesting crc32c using digest:\n");
735 (void)crypto_digest_setkey(tfm
, (const u8
*)&seed
, sizeof(u32
));
736 crypto_digest_digest(tfm
, sg
, NUMVEC
, (u8
*)&crc
);
737 if (crc
== tot_vec_results
) {
738 printk(" %08x:OK", crc
);
740 printk(" %08x:BAD, wanted %08x\n", crc
, tot_vec_results
);
744 printk("\n%s\n", pass
? "pass" : "ERROR");
746 crypto_free_tfm(tfm
);
747 printk("crc32c test complete\n");
750 static void test_available(void)
755 printk("alg %s ", *name
);
756 printk((crypto_alg_available(*name
, 0)) ?
757 "found\n" : "not found\n");
762 static void do_test(void)
767 test_hash("md5", md5_tv_template
, MD5_TEST_VECTORS
);
769 test_hash("sha1", sha1_tv_template
, SHA1_TEST_VECTORS
);
772 test_cipher ("des", MODE_ECB
, ENCRYPT
, des_enc_tv_template
, DES_ENC_TEST_VECTORS
);
773 test_cipher ("des", MODE_ECB
, DECRYPT
, des_dec_tv_template
, DES_DEC_TEST_VECTORS
);
774 test_cipher ("des", MODE_CBC
, ENCRYPT
, des_cbc_enc_tv_template
, DES_CBC_ENC_TEST_VECTORS
);
775 test_cipher ("des", MODE_CBC
, DECRYPT
, des_cbc_dec_tv_template
, DES_CBC_DEC_TEST_VECTORS
);
778 test_cipher ("des3_ede", MODE_ECB
, ENCRYPT
, des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
);
779 test_cipher ("des3_ede", MODE_ECB
, DECRYPT
, des3_ede_dec_tv_template
, DES3_EDE_DEC_TEST_VECTORS
);
781 test_hash("md4", md4_tv_template
, MD4_TEST_VECTORS
);
783 test_hash("sha256", sha256_tv_template
, SHA256_TEST_VECTORS
);
786 test_cipher ("blowfish", MODE_ECB
, ENCRYPT
, bf_enc_tv_template
, BF_ENC_TEST_VECTORS
);
787 test_cipher ("blowfish", MODE_ECB
, DECRYPT
, bf_dec_tv_template
, BF_DEC_TEST_VECTORS
);
788 test_cipher ("blowfish", MODE_CBC
, ENCRYPT
, bf_cbc_enc_tv_template
, BF_CBC_ENC_TEST_VECTORS
);
789 test_cipher ("blowfish", MODE_CBC
, DECRYPT
, bf_cbc_dec_tv_template
, BF_CBC_DEC_TEST_VECTORS
);
792 test_cipher ("twofish", MODE_ECB
, ENCRYPT
, tf_enc_tv_template
, TF_ENC_TEST_VECTORS
);
793 test_cipher ("twofish", MODE_ECB
, DECRYPT
, tf_dec_tv_template
, TF_DEC_TEST_VECTORS
);
794 test_cipher ("twofish", MODE_CBC
, ENCRYPT
, tf_cbc_enc_tv_template
, TF_CBC_ENC_TEST_VECTORS
);
795 test_cipher ("twofish", MODE_CBC
, DECRYPT
, tf_cbc_dec_tv_template
, TF_CBC_DEC_TEST_VECTORS
);
798 test_cipher ("serpent", MODE_ECB
, ENCRYPT
, serpent_enc_tv_template
, SERPENT_ENC_TEST_VECTORS
);
799 test_cipher ("serpent", MODE_ECB
, DECRYPT
, serpent_dec_tv_template
, SERPENT_DEC_TEST_VECTORS
);
802 test_cipher ("tnepres", MODE_ECB
, ENCRYPT
, tnepres_enc_tv_template
, TNEPRES_ENC_TEST_VECTORS
);
803 test_cipher ("tnepres", MODE_ECB
, DECRYPT
, tnepres_dec_tv_template
, TNEPRES_DEC_TEST_VECTORS
);
806 test_cipher ("aes", MODE_ECB
, ENCRYPT
, aes_enc_tv_template
, AES_ENC_TEST_VECTORS
);
807 test_cipher ("aes", MODE_ECB
, DECRYPT
, aes_dec_tv_template
, AES_DEC_TEST_VECTORS
);
808 test_cipher ("aes", MODE_CBC
, ENCRYPT
, aes_cbc_enc_tv_template
, AES_CBC_ENC_TEST_VECTORS
);
809 test_cipher ("aes", MODE_CBC
, DECRYPT
, aes_cbc_dec_tv_template
, AES_CBC_DEC_TEST_VECTORS
);
812 test_cipher ("cast5", MODE_ECB
, ENCRYPT
, cast5_enc_tv_template
, CAST5_ENC_TEST_VECTORS
);
813 test_cipher ("cast5", MODE_ECB
, DECRYPT
, cast5_dec_tv_template
, CAST5_DEC_TEST_VECTORS
);
816 test_cipher ("cast6", MODE_ECB
, ENCRYPT
, cast6_enc_tv_template
, CAST6_ENC_TEST_VECTORS
);
817 test_cipher ("cast6", MODE_ECB
, DECRYPT
, cast6_dec_tv_template
, CAST6_DEC_TEST_VECTORS
);
820 test_cipher ("arc4", MODE_ECB
, ENCRYPT
, arc4_enc_tv_template
, ARC4_ENC_TEST_VECTORS
);
821 test_cipher ("arc4", MODE_ECB
, DECRYPT
, arc4_dec_tv_template
, ARC4_DEC_TEST_VECTORS
);
824 test_cipher ("tea", MODE_ECB
, ENCRYPT
, tea_enc_tv_template
, TEA_ENC_TEST_VECTORS
);
825 test_cipher ("tea", MODE_ECB
, DECRYPT
, tea_dec_tv_template
, TEA_DEC_TEST_VECTORS
);
829 test_cipher ("xtea", MODE_ECB
, ENCRYPT
, xtea_enc_tv_template
, XTEA_ENC_TEST_VECTORS
);
830 test_cipher ("xtea", MODE_ECB
, DECRYPT
, xtea_dec_tv_template
, XTEA_DEC_TEST_VECTORS
);
833 test_cipher ("khazad", MODE_ECB
, ENCRYPT
, khazad_enc_tv_template
, KHAZAD_ENC_TEST_VECTORS
);
834 test_cipher ("khazad", MODE_ECB
, DECRYPT
, khazad_dec_tv_template
, KHAZAD_DEC_TEST_VECTORS
);
837 test_cipher ("anubis", MODE_ECB
, ENCRYPT
, anubis_enc_tv_template
, ANUBIS_ENC_TEST_VECTORS
);
838 test_cipher ("anubis", MODE_ECB
, DECRYPT
, anubis_dec_tv_template
, ANUBIS_DEC_TEST_VECTORS
);
839 test_cipher ("anubis", MODE_CBC
, ENCRYPT
, anubis_cbc_enc_tv_template
, ANUBIS_CBC_ENC_TEST_VECTORS
);
840 test_cipher ("anubis", MODE_CBC
, DECRYPT
, anubis_cbc_dec_tv_template
, ANUBIS_CBC_ENC_TEST_VECTORS
);
843 test_cipher ("xeta", MODE_ECB
, ENCRYPT
, xeta_enc_tv_template
, XETA_ENC_TEST_VECTORS
);
844 test_cipher ("xeta", MODE_ECB
, DECRYPT
, xeta_dec_tv_template
, XETA_DEC_TEST_VECTORS
);
846 test_hash("sha384", sha384_tv_template
, SHA384_TEST_VECTORS
);
847 test_hash("sha512", sha512_tv_template
, SHA512_TEST_VECTORS
);
848 test_hash("wp512", wp512_tv_template
, WP512_TEST_VECTORS
);
849 test_hash("wp384", wp384_tv_template
, WP384_TEST_VECTORS
);
850 test_hash("wp256", wp256_tv_template
, WP256_TEST_VECTORS
);
851 test_hash("tgr192", tgr192_tv_template
, TGR192_TEST_VECTORS
);
852 test_hash("tgr160", tgr160_tv_template
, TGR160_TEST_VECTORS
);
853 test_hash("tgr128", tgr128_tv_template
, TGR128_TEST_VECTORS
);
856 #ifdef CONFIG_CRYPTO_HMAC
857 test_hmac("md5", hmac_md5_tv_template
, HMAC_MD5_TEST_VECTORS
);
858 test_hmac("sha1", hmac_sha1_tv_template
, HMAC_SHA1_TEST_VECTORS
);
859 test_hmac("sha256", hmac_sha256_tv_template
, HMAC_SHA256_TEST_VECTORS
);
862 test_hash("michael_mic", michael_mic_tv_template
, MICHAEL_MIC_TEST_VECTORS
);
866 test_hash("md5", md5_tv_template
, MD5_TEST_VECTORS
);
870 test_hash("sha1", sha1_tv_template
, SHA1_TEST_VECTORS
);
874 test_cipher ("des", MODE_ECB
, ENCRYPT
, des_enc_tv_template
, DES_ENC_TEST_VECTORS
);
875 test_cipher ("des", MODE_ECB
, DECRYPT
, des_dec_tv_template
, DES_DEC_TEST_VECTORS
);
876 test_cipher ("des", MODE_CBC
, ENCRYPT
, des_cbc_enc_tv_template
, DES_CBC_ENC_TEST_VECTORS
);
877 test_cipher ("des", MODE_CBC
, DECRYPT
, des_cbc_dec_tv_template
, DES_CBC_DEC_TEST_VECTORS
);
881 test_cipher ("des3_ede", MODE_ECB
, ENCRYPT
, des3_ede_enc_tv_template
, DES3_EDE_ENC_TEST_VECTORS
);
882 test_cipher ("des3_ede", MODE_ECB
, DECRYPT
, des3_ede_dec_tv_template
, DES3_EDE_DEC_TEST_VECTORS
);
886 test_hash("md4", md4_tv_template
, MD4_TEST_VECTORS
);
890 test_hash("sha256", sha256_tv_template
, SHA256_TEST_VECTORS
);
894 test_cipher ("blowfish", MODE_ECB
, ENCRYPT
, bf_enc_tv_template
, BF_ENC_TEST_VECTORS
);
895 test_cipher ("blowfish", MODE_ECB
, DECRYPT
, bf_dec_tv_template
, BF_DEC_TEST_VECTORS
);
896 test_cipher ("blowfish", MODE_CBC
, ENCRYPT
, bf_cbc_enc_tv_template
, BF_CBC_ENC_TEST_VECTORS
);
897 test_cipher ("blowfish", MODE_CBC
, DECRYPT
, bf_cbc_dec_tv_template
, BF_CBC_DEC_TEST_VECTORS
);
901 test_cipher ("twofish", MODE_ECB
, ENCRYPT
, tf_enc_tv_template
, TF_ENC_TEST_VECTORS
);
902 test_cipher ("twofish", MODE_ECB
, DECRYPT
, tf_dec_tv_template
, TF_DEC_TEST_VECTORS
);
903 test_cipher ("twofish", MODE_CBC
, ENCRYPT
, tf_cbc_enc_tv_template
, TF_CBC_ENC_TEST_VECTORS
);
904 test_cipher ("twofish", MODE_CBC
, DECRYPT
, tf_cbc_dec_tv_template
, TF_CBC_DEC_TEST_VECTORS
);
908 test_cipher ("serpent", MODE_ECB
, ENCRYPT
, serpent_enc_tv_template
, SERPENT_ENC_TEST_VECTORS
);
909 test_cipher ("serpent", MODE_ECB
, DECRYPT
, serpent_dec_tv_template
, SERPENT_DEC_TEST_VECTORS
);
913 test_cipher ("aes", MODE_ECB
, ENCRYPT
, aes_enc_tv_template
, AES_ENC_TEST_VECTORS
);
914 test_cipher ("aes", MODE_ECB
, DECRYPT
, aes_dec_tv_template
, AES_DEC_TEST_VECTORS
);
915 test_cipher ("aes", MODE_CBC
, ENCRYPT
, aes_cbc_enc_tv_template
, AES_CBC_ENC_TEST_VECTORS
);
916 test_cipher ("aes", MODE_CBC
, DECRYPT
, aes_cbc_dec_tv_template
, AES_CBC_DEC_TEST_VECTORS
);
920 test_hash("sha384", sha384_tv_template
, SHA384_TEST_VECTORS
);
924 test_hash("sha512", sha512_tv_template
, SHA512_TEST_VECTORS
);
932 test_cipher ("cast5", MODE_ECB
, ENCRYPT
, cast5_enc_tv_template
, CAST5_ENC_TEST_VECTORS
);
933 test_cipher ("cast5", MODE_ECB
, DECRYPT
, cast5_dec_tv_template
, CAST5_DEC_TEST_VECTORS
);
937 test_cipher ("cast6", MODE_ECB
, ENCRYPT
, cast6_enc_tv_template
, CAST6_ENC_TEST_VECTORS
);
938 test_cipher ("cast6", MODE_ECB
, DECRYPT
, cast6_dec_tv_template
, CAST6_DEC_TEST_VECTORS
);
942 test_cipher ("arc4", MODE_ECB
, ENCRYPT
, arc4_enc_tv_template
, ARC4_ENC_TEST_VECTORS
);
943 test_cipher ("arc4", MODE_ECB
, DECRYPT
, arc4_dec_tv_template
, ARC4_DEC_TEST_VECTORS
);
947 test_hash("michael_mic", michael_mic_tv_template
, MICHAEL_MIC_TEST_VECTORS
);
955 test_cipher ("tea", MODE_ECB
, ENCRYPT
, tea_enc_tv_template
, TEA_ENC_TEST_VECTORS
);
956 test_cipher ("tea", MODE_ECB
, DECRYPT
, tea_dec_tv_template
, TEA_DEC_TEST_VECTORS
);
960 test_cipher ("xtea", MODE_ECB
, ENCRYPT
, xtea_enc_tv_template
, XTEA_ENC_TEST_VECTORS
);
961 test_cipher ("xtea", MODE_ECB
, DECRYPT
, xtea_dec_tv_template
, XTEA_DEC_TEST_VECTORS
);
965 test_cipher ("khazad", MODE_ECB
, ENCRYPT
, khazad_enc_tv_template
, KHAZAD_ENC_TEST_VECTORS
);
966 test_cipher ("khazad", MODE_ECB
, DECRYPT
, khazad_dec_tv_template
, KHAZAD_DEC_TEST_VECTORS
);
970 test_hash("wp512", wp512_tv_template
, WP512_TEST_VECTORS
);
974 test_hash("wp384", wp384_tv_template
, WP384_TEST_VECTORS
);
978 test_hash("wp256", wp256_tv_template
, WP256_TEST_VECTORS
);
982 test_cipher ("tnepres", MODE_ECB
, ENCRYPT
, tnepres_enc_tv_template
, TNEPRES_ENC_TEST_VECTORS
);
983 test_cipher ("tnepres", MODE_ECB
, DECRYPT
, tnepres_dec_tv_template
, TNEPRES_DEC_TEST_VECTORS
);
987 test_cipher ("anubis", MODE_ECB
, ENCRYPT
, anubis_enc_tv_template
, ANUBIS_ENC_TEST_VECTORS
);
988 test_cipher ("anubis", MODE_ECB
, DECRYPT
, anubis_dec_tv_template
, ANUBIS_DEC_TEST_VECTORS
);
989 test_cipher ("anubis", MODE_CBC
, ENCRYPT
, anubis_cbc_enc_tv_template
, ANUBIS_CBC_ENC_TEST_VECTORS
);
990 test_cipher ("anubis", MODE_CBC
, DECRYPT
, anubis_cbc_dec_tv_template
, ANUBIS_CBC_ENC_TEST_VECTORS
);
994 test_hash("tgr192", tgr192_tv_template
, TGR192_TEST_VECTORS
);
999 test_hash("tgr160", tgr160_tv_template
, TGR160_TEST_VECTORS
);
1003 test_hash("tgr128", tgr128_tv_template
, TGR128_TEST_VECTORS
);
1007 test_cipher ("xeta", MODE_ECB
, ENCRYPT
, xeta_enc_tv_template
, XETA_ENC_TEST_VECTORS
);
1008 test_cipher ("xeta", MODE_ECB
, DECRYPT
, xeta_dec_tv_template
, XETA_DEC_TEST_VECTORS
);
1011 #ifdef CONFIG_CRYPTO_HMAC
1013 test_hmac("md5", hmac_md5_tv_template
, HMAC_MD5_TEST_VECTORS
);
1017 test_hmac("sha1", hmac_sha1_tv_template
, HMAC_SHA1_TEST_VECTORS
);
1021 test_hmac("sha256", hmac_sha256_tv_template
, HMAC_SHA256_TEST_VECTORS
);
1027 test_cipher_speed("aes", MODE_ECB
, ENCRYPT
, sec
, NULL
, 0,
1028 aes_speed_template
);
1029 test_cipher_speed("aes", MODE_ECB
, DECRYPT
, sec
, NULL
, 0,
1030 aes_speed_template
);
1031 test_cipher_speed("aes", MODE_CBC
, ENCRYPT
, sec
, NULL
, 0,
1032 aes_speed_template
);
1033 test_cipher_speed("aes", MODE_CBC
, DECRYPT
, sec
, NULL
, 0,
1034 aes_speed_template
);
1038 test_cipher_speed("des3_ede", MODE_ECB
, ENCRYPT
, sec
,
1039 des3_ede_enc_tv_template
,
1040 DES3_EDE_ENC_TEST_VECTORS
,
1041 des3_ede_speed_template
);
1042 test_cipher_speed("des3_ede", MODE_ECB
, DECRYPT
, sec
,
1043 des3_ede_dec_tv_template
,
1044 DES3_EDE_DEC_TEST_VECTORS
,
1045 des3_ede_speed_template
);
1046 test_cipher_speed("des3_ede", MODE_CBC
, ENCRYPT
, sec
,
1047 des3_ede_enc_tv_template
,
1048 DES3_EDE_ENC_TEST_VECTORS
,
1049 des3_ede_speed_template
);
1050 test_cipher_speed("des3_ede", MODE_CBC
, DECRYPT
, sec
,
1051 des3_ede_dec_tv_template
,
1052 DES3_EDE_DEC_TEST_VECTORS
,
1053 des3_ede_speed_template
);
1057 test_cipher_speed("twofish", MODE_ECB
, ENCRYPT
, sec
, NULL
, 0,
1058 twofish_speed_template
);
1059 test_cipher_speed("twofish", MODE_ECB
, DECRYPT
, sec
, NULL
, 0,
1060 twofish_speed_template
);
1061 test_cipher_speed("twofish", MODE_CBC
, ENCRYPT
, sec
, NULL
, 0,
1062 twofish_speed_template
);
1063 test_cipher_speed("twofish", MODE_CBC
, DECRYPT
, sec
, NULL
, 0,
1064 twofish_speed_template
);
1068 test_cipher_speed("blowfish", MODE_ECB
, ENCRYPT
, sec
, NULL
, 0,
1069 blowfish_speed_template
);
1070 test_cipher_speed("blowfish", MODE_ECB
, DECRYPT
, sec
, NULL
, 0,
1071 blowfish_speed_template
);
1072 test_cipher_speed("blowfish", MODE_CBC
, ENCRYPT
, sec
, NULL
, 0,
1073 blowfish_speed_template
);
1074 test_cipher_speed("blowfish", MODE_CBC
, DECRYPT
, sec
, NULL
, 0,
1075 blowfish_speed_template
);
1079 test_cipher_speed("des", MODE_ECB
, ENCRYPT
, sec
, NULL
, 0,
1080 des_speed_template
);
1081 test_cipher_speed("des", MODE_ECB
, DECRYPT
, sec
, NULL
, 0,
1082 des_speed_template
);
1083 test_cipher_speed("des", MODE_CBC
, ENCRYPT
, sec
, NULL
, 0,
1084 des_speed_template
);
1085 test_cipher_speed("des", MODE_CBC
, DECRYPT
, sec
, NULL
, 0,
1086 des_speed_template
);
1094 /* useful for debugging */
1095 printk("not testing anything\n");
1100 static int __init
init(void)
1102 tvmem
= kmalloc(TVMEMSIZE
, GFP_KERNEL
);
1106 xbuf
= kmalloc(XBUFSIZE
, GFP_KERNEL
);
1120 * If an init function is provided, an exit function must also be provided
1121 * to allow module unload.
1123 static void __exit
fini(void) { }
1128 module_param(mode
, int, 0);
1129 module_param(sec
, uint
, 0);
1130 MODULE_PARM_DESC(sec
, "Length in seconds of speed tests "
1131 "(defaults to zero which uses CPU cycles instead)");
1133 MODULE_LICENSE("GPL");
1134 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1135 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");