2 * Quick & dirty crypto testing module.
4 * This will only exist until we have a better testing mechanism
5 * (e.g. a char device).
7 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
8 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
9 * Copyright (c) 2007 Nokia Siemens Networks
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License, or (at your option)
18 #include <crypto/hash.h>
19 #include <linux/err.h>
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/moduleparam.h>
28 #include <linux/jiffies.h>
29 #include <linux/timex.h>
30 #include <linux/interrupt.h>
34 * Need slab memory for testing (size in number of pages).
40 * Indexes into the xbuf to simulate cross-page access.
52 * Used by test_cipher()
57 struct tcrypt_result {
58 struct completion completion;
62 static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
65 * Used by test_cipher_speed()
67 static unsigned int sec;
70 static char *xbuf[XBUFSIZE];
71 static char *axbuf[XBUFSIZE];
72 static char *tvmem[TVMEMSIZE];
74 static char *check[] = {
75 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
76 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
77 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
78 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
79 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
83 static void hexdump(unsigned char *buf, unsigned int len)
85 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
90 static void tcrypt_complete(struct crypto_async_request *req, int err)
92 struct tcrypt_result *res = req->data;
94 if (err == -EINPROGRESS)
98 complete(&res->completion);
101 static int test_hash(char *algo, struct hash_testvec *template,
104 unsigned int i, j, k, temp;
105 struct scatterlist sg[8];
107 struct crypto_ahash *tfm;
108 struct ahash_request *req;
109 struct tcrypt_result tresult;
113 init_completion(&tresult.completion);
115 tfm = crypto_alloc_ahash(algo, 0, 0);
117 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
118 "%ld\n", algo, PTR_ERR(tfm));
122 req = ahash_request_alloc(tfm, GFP_KERNEL);
124 printk(KERN_ERR "alg: hash: Failed to allocate request for "
129 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
130 tcrypt_complete, &tresult);
132 for (i = 0; i < tcount; i++) {
133 memset(result, 0, 64);
137 memcpy(hash_buff, template[i].plaintext, template[i].psize);
138 sg_init_one(&sg[0], hash_buff, template[i].psize);
140 if (template[i].ksize) {
141 crypto_ahash_clear_flags(tfm, ~0);
142 ret = crypto_ahash_setkey(tfm, template[i].key,
145 printk(KERN_ERR "alg: hash: setkey failed on "
146 "test %d for %s: ret=%d\n", i + 1, algo,
152 ahash_request_set_crypt(req, sg, result, template[i].psize);
153 ret = crypto_ahash_digest(req);
159 ret = wait_for_completion_interruptible(
160 &tresult.completion);
161 if (!ret && !(ret = tresult.err)) {
162 INIT_COMPLETION(tresult.completion);
167 printk(KERN_ERR "alg: hash: digest failed on test %d "
168 "for %s: ret=%d\n", i + 1, algo, -ret);
172 if (memcmp(result, template[i].digest,
173 crypto_ahash_digestsize(tfm))) {
174 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
176 hexdump(result, crypto_ahash_digestsize(tfm));
183 for (i = 0; i < tcount; i++) {
184 if (template[i].np) {
186 memset(result, 0, 64);
189 sg_init_table(sg, template[i].np);
190 for (k = 0; k < template[i].np; k++) {
192 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
193 offset_in_page(IDX[k]),
194 template[i].plaintext + temp,
197 temp += template[i].tap[k];
200 if (template[i].ksize) {
201 crypto_ahash_clear_flags(tfm, ~0);
202 ret = crypto_ahash_setkey(tfm, template[i].key,
206 printk(KERN_ERR "alg: hash: setkey "
207 "failed on chunking test %d "
208 "for %s: ret=%d\n", j, algo,
214 ahash_request_set_crypt(req, sg, result,
216 ret = crypto_ahash_digest(req);
222 ret = wait_for_completion_interruptible(
223 &tresult.completion);
224 if (!ret && !(ret = tresult.err)) {
225 INIT_COMPLETION(tresult.completion);
230 printk(KERN_ERR "alg: hash: digest failed "
231 "on chunking test %d for %s: "
232 "ret=%d\n", j, algo, -ret);
236 if (memcmp(result, template[i].digest,
237 crypto_ahash_digestsize(tfm))) {
238 printk(KERN_ERR "alg: hash: Chunking test %d "
239 "failed for %s\n", j, algo);
240 hexdump(result, crypto_ahash_digestsize(tfm));
250 ahash_request_free(req);
252 crypto_free_ahash(tfm);
256 static int test_aead(char *algo, int enc, struct aead_testvec *template,
259 unsigned int i, j, k, n, temp;
262 struct crypto_aead *tfm;
264 struct aead_request *req;
265 struct scatterlist sg[8];
266 struct scatterlist asg[8];
268 struct tcrypt_result result;
269 unsigned int authsize;
279 init_completion(&result.completion);
281 tfm = crypto_alloc_aead(algo, 0, 0);
284 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
285 "%ld\n", algo, PTR_ERR(tfm));
289 req = aead_request_alloc(tfm, GFP_KERNEL);
291 printk(KERN_ERR "alg: aead: Failed to allocate request for "
297 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
298 tcrypt_complete, &result);
300 for (i = 0, j = 0; i < tcount; i++) {
301 if (!template[i].np) {
304 /* some tepmplates have no input data but they will
310 memcpy(input, template[i].input, template[i].ilen);
311 memcpy(assoc, template[i].assoc, template[i].alen);
313 memcpy(iv, template[i].iv, MAX_IVLEN);
315 memset(iv, 0, MAX_IVLEN);
317 crypto_aead_clear_flags(tfm, ~0);
319 crypto_aead_set_flags(
320 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
322 key = template[i].key;
324 ret = crypto_aead_setkey(tfm, key,
326 if (!ret == template[i].fail) {
327 printk(KERN_ERR "alg: aead: setkey failed on "
328 "test %d for %s: flags=%x\n", j, algo,
329 crypto_aead_get_flags(tfm));
334 authsize = abs(template[i].rlen - template[i].ilen);
335 ret = crypto_aead_setauthsize(tfm, authsize);
337 printk(KERN_ERR "alg: aead: Failed to set "
338 "authsize to %u on test %d for %s\n",
343 sg_init_one(&sg[0], input,
344 template[i].ilen + (enc ? authsize : 0));
346 sg_init_one(&asg[0], assoc, template[i].alen);
348 aead_request_set_crypt(req, sg, sg,
349 template[i].ilen, iv);
351 aead_request_set_assoc(req, asg, template[i].alen);
354 crypto_aead_encrypt(req) :
355 crypto_aead_decrypt(req);
362 ret = wait_for_completion_interruptible(
364 if (!ret && !(ret = result.err)) {
365 INIT_COMPLETION(result.completion);
370 printk(KERN_ERR "alg: aead: %s failed on test "
371 "%d for %s: ret=%d\n", e, j, algo, -ret);
376 if (memcmp(q, template[i].result, template[i].rlen)) {
377 printk(KERN_ERR "alg: aead: Test %d failed on "
378 "%s for %s\n", j, e, algo);
379 hexdump(q, template[i].rlen);
386 for (i = 0, j = 0; i < tcount; i++) {
387 if (template[i].np) {
391 memcpy(iv, template[i].iv, MAX_IVLEN);
393 memset(iv, 0, MAX_IVLEN);
395 crypto_aead_clear_flags(tfm, ~0);
397 crypto_aead_set_flags(
398 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
399 key = template[i].key;
401 ret = crypto_aead_setkey(tfm, key, template[i].klen);
402 if (!ret == template[i].fail) {
403 printk(KERN_ERR "alg: aead: setkey failed on "
404 "chunk test %d for %s: flags=%x\n", j,
405 algo, crypto_aead_get_flags(tfm));
410 authsize = abs(template[i].rlen - template[i].ilen);
413 sg_init_table(sg, template[i].np);
414 for (k = 0, temp = 0; k < template[i].np; k++) {
415 if (WARN_ON(offset_in_page(IDX[k]) +
416 template[i].tap[k] > PAGE_SIZE))
419 q = xbuf[IDX[k] >> PAGE_SHIFT] +
420 offset_in_page(IDX[k]);
422 memcpy(q, template[i].input + temp,
425 n = template[i].tap[k];
426 if (k == template[i].np - 1 && enc)
428 if (offset_in_page(q) + n < PAGE_SIZE)
431 sg_set_buf(&sg[k], q, template[i].tap[k]);
432 temp += template[i].tap[k];
435 ret = crypto_aead_setauthsize(tfm, authsize);
437 printk(KERN_ERR "alg: aead: Failed to set "
438 "authsize to %u on chunk test %d for "
439 "%s\n", authsize, j, algo);
444 if (WARN_ON(sg[k - 1].offset +
445 sg[k - 1].length + authsize >
451 sg[k - 1].length += authsize;
454 sg_init_table(asg, template[i].anp);
455 for (k = 0, temp = 0; k < template[i].anp; k++) {
457 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
458 offset_in_page(IDX[k]),
459 template[i].assoc + temp,
460 template[i].atap[k]),
461 template[i].atap[k]);
462 temp += template[i].atap[k];
465 aead_request_set_crypt(req, sg, sg,
469 aead_request_set_assoc(req, asg, template[i].alen);
472 crypto_aead_encrypt(req) :
473 crypto_aead_decrypt(req);
480 ret = wait_for_completion_interruptible(
482 if (!ret && !(ret = result.err)) {
483 INIT_COMPLETION(result.completion);
488 printk(KERN_ERR "alg: aead: %s failed on "
489 "chunk test %d for %s: ret=%d\n", e, j,
495 for (k = 0, temp = 0; k < template[i].np; k++) {
496 q = xbuf[IDX[k] >> PAGE_SHIFT] +
497 offset_in_page(IDX[k]);
499 n = template[i].tap[k];
500 if (k == template[i].np - 1)
501 n += enc ? authsize : -authsize;
503 if (memcmp(q, template[i].result + temp, n)) {
504 printk(KERN_ERR "alg: aead: Chunk "
505 "test %d failed on %s at page "
506 "%u for %s\n", j, e, k, algo);
512 if (k == template[i].np - 1 && !enc) {
513 if (memcmp(q, template[i].input +
519 for (n = 0; offset_in_page(q + n) &&
524 printk(KERN_ERR "alg: aead: Result "
525 "buffer corruption in chunk "
526 "test %d on %s at page %u for "
527 "%s: %u bytes:\n", j, e, k,
533 temp += template[i].tap[k];
541 crypto_free_aead(tfm);
542 aead_request_free(req);
546 static int test_cipher(char *algo, int enc,
547 struct cipher_testvec *template, unsigned int tcount)
549 unsigned int i, j, k, n, temp;
552 struct crypto_ablkcipher *tfm;
553 struct ablkcipher_request *req;
554 struct scatterlist sg[8];
556 struct tcrypt_result result;
565 init_completion(&result.completion);
566 tfm = crypto_alloc_ablkcipher(algo, 0, 0);
569 printk(KERN_ERR "alg: cipher: Failed to load transform for "
570 "%s: %ld\n", algo, PTR_ERR(tfm));
574 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
576 printk(KERN_ERR "alg: cipher: Failed to allocate request for "
582 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
583 tcrypt_complete, &result);
586 for (i = 0; i < tcount; i++) {
588 memcpy(iv, template[i].iv, MAX_IVLEN);
590 memset(iv, 0, MAX_IVLEN);
592 if (!(template[i].np)) {
596 memcpy(data, template[i].input, template[i].ilen);
598 crypto_ablkcipher_clear_flags(tfm, ~0);
600 crypto_ablkcipher_set_flags(
601 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
603 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
605 if (!ret == template[i].fail) {
606 printk(KERN_ERR "alg: cipher: setkey failed "
607 "on test %d for %s: flags=%x\n", j,
608 algo, crypto_ablkcipher_get_flags(tfm));
613 sg_init_one(&sg[0], data, template[i].ilen);
615 ablkcipher_request_set_crypt(req, sg, sg,
616 template[i].ilen, iv);
618 crypto_ablkcipher_encrypt(req) :
619 crypto_ablkcipher_decrypt(req);
626 ret = wait_for_completion_interruptible(
628 if (!ret && !((ret = result.err))) {
629 INIT_COMPLETION(result.completion);
634 printk(KERN_ERR "alg: cipher: %s failed on "
635 "test %d for %s: ret=%d\n", e, j, algo,
641 if (memcmp(q, template[i].result, template[i].rlen)) {
642 printk(KERN_ERR "alg: cipher: Test %d failed "
643 "on %s for %s\n", j, e, algo);
644 hexdump(q, template[i].rlen);
652 for (i = 0; i < tcount; i++) {
655 memcpy(iv, template[i].iv, MAX_IVLEN);
657 memset(iv, 0, MAX_IVLEN);
659 if (template[i].np) {
662 crypto_ablkcipher_clear_flags(tfm, ~0);
664 crypto_ablkcipher_set_flags(
665 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
667 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
669 if (!ret == template[i].fail) {
670 printk(KERN_ERR "alg: cipher: setkey failed "
671 "on chunk test %d for %s: flags=%x\n",
673 crypto_ablkcipher_get_flags(tfm));
680 sg_init_table(sg, template[i].np);
681 for (k = 0; k < template[i].np; k++) {
682 if (WARN_ON(offset_in_page(IDX[k]) +
683 template[i].tap[k] > PAGE_SIZE))
686 q = xbuf[IDX[k] >> PAGE_SHIFT] +
687 offset_in_page(IDX[k]);
689 memcpy(q, template[i].input + temp,
692 if (offset_in_page(q) + template[i].tap[k] <
694 q[template[i].tap[k]] = 0;
696 sg_set_buf(&sg[k], q, template[i].tap[k]);
698 temp += template[i].tap[k];
701 ablkcipher_request_set_crypt(req, sg, sg,
702 template[i].ilen, iv);
705 crypto_ablkcipher_encrypt(req) :
706 crypto_ablkcipher_decrypt(req);
713 ret = wait_for_completion_interruptible(
715 if (!ret && !((ret = result.err))) {
716 INIT_COMPLETION(result.completion);
721 printk(KERN_ERR "alg: cipher: %s failed on "
722 "chunk test %d for %s: ret=%d\n", e, j,
729 for (k = 0; k < template[i].np; k++) {
730 q = xbuf[IDX[k] >> PAGE_SHIFT] +
731 offset_in_page(IDX[k]);
733 if (memcmp(q, template[i].result + temp,
734 template[i].tap[k])) {
735 printk(KERN_ERR "alg: cipher: Chunk "
736 "test %d failed on %s at page "
737 "%u for %s\n", j, e, k, algo);
738 hexdump(q, template[i].tap[k]);
742 q += template[i].tap[k];
743 for (n = 0; offset_in_page(q + n) && q[n]; n++)
746 printk(KERN_ERR "alg: cipher: "
747 "Result buffer corruption in "
748 "chunk test %d on %s at page "
749 "%u for %s: %u bytes:\n", j, e,
754 temp += template[i].tap[k];
762 crypto_free_ablkcipher(tfm);
763 ablkcipher_request_free(req);
767 static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc,
768 struct scatterlist *sg, int blen, int sec)
770 unsigned long start, end;
774 for (start = jiffies, end = start + sec * HZ, bcount = 0;
775 time_before(jiffies, end); bcount++) {
777 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
779 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
785 printk("%d operations in %d seconds (%ld bytes)\n",
786 bcount, sec, (long)bcount * blen);
790 static int test_cipher_cycles(struct blkcipher_desc *desc, int enc,
791 struct scatterlist *sg, int blen)
793 unsigned long cycles = 0;
801 for (i = 0; i < 4; i++) {
803 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
805 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
811 /* The real thing. */
812 for (i = 0; i < 8; i++) {
815 start = get_cycles();
817 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
819 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
825 cycles += end - start;
833 printk("1 operation in %lu cycles (%d bytes)\n",
834 (cycles + 4) / 8, blen);
839 static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
841 static void test_cipher_speed(char *algo, int enc, unsigned int sec,
842 struct cipher_testvec *template,
843 unsigned int tcount, u8 *keysize)
845 unsigned int ret, i, j, iv_len;
846 unsigned char *key, iv[128];
847 struct crypto_blkcipher *tfm;
848 struct blkcipher_desc desc;
857 printk("\ntesting speed of %s %s\n", algo, e);
859 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
862 printk("failed to load transform for %s: %ld\n", algo,
872 b_size = block_sizes;
874 struct scatterlist sg[TVMEMSIZE];
876 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
877 printk("template (%u) too big for "
878 "tvmem (%lu)\n", *keysize + *b_size,
879 TVMEMSIZE * PAGE_SIZE);
883 printk("test %u (%d bit key, %d byte blocks): ", i,
884 *keysize * 8, *b_size);
886 memset(tvmem[0], 0xff, PAGE_SIZE);
888 /* set key, plain text and IV */
889 key = (unsigned char *)tvmem[0];
890 for (j = 0; j < tcount; j++) {
891 if (template[j].klen == *keysize) {
892 key = template[j].key;
897 ret = crypto_blkcipher_setkey(tfm, key, *keysize);
899 printk("setkey() failed flags=%x\n",
900 crypto_blkcipher_get_flags(tfm));
904 sg_init_table(sg, TVMEMSIZE);
905 sg_set_buf(sg, tvmem[0] + *keysize,
906 PAGE_SIZE - *keysize);
907 for (j = 1; j < TVMEMSIZE; j++) {
908 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
909 memset (tvmem[j], 0xff, PAGE_SIZE);
912 iv_len = crypto_blkcipher_ivsize(tfm);
914 memset(&iv, 0xff, iv_len);
915 crypto_blkcipher_set_iv(tfm, iv, iv_len);
919 ret = test_cipher_jiffies(&desc, enc, sg,
922 ret = test_cipher_cycles(&desc, enc, sg,
926 printk("%s() failed flags=%x\n", e, desc.flags);
936 crypto_free_blkcipher(tfm);
939 static int test_hash_jiffies_digest(struct hash_desc *desc,
940 struct scatterlist *sg, int blen,
943 unsigned long start, end;
947 for (start = jiffies, end = start + sec * HZ, bcount = 0;
948 time_before(jiffies, end); bcount++) {
949 ret = crypto_hash_digest(desc, sg, blen, out);
954 printk("%6u opers/sec, %9lu bytes/sec\n",
955 bcount / sec, ((long)bcount * blen) / sec);
960 static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg,
961 int blen, int plen, char *out, int sec)
963 unsigned long start, end;
968 return test_hash_jiffies_digest(desc, sg, blen, out, sec);
970 for (start = jiffies, end = start + sec * HZ, bcount = 0;
971 time_before(jiffies, end); bcount++) {
972 ret = crypto_hash_init(desc);
975 for (pcount = 0; pcount < blen; pcount += plen) {
976 ret = crypto_hash_update(desc, sg, plen);
980 /* we assume there is enough space in 'out' for the result */
981 ret = crypto_hash_final(desc, out);
986 printk("%6u opers/sec, %9lu bytes/sec\n",
987 bcount / sec, ((long)bcount * blen) / sec);
992 static int test_hash_cycles_digest(struct hash_desc *desc,
993 struct scatterlist *sg, int blen, char *out)
995 unsigned long cycles = 0;
1000 local_irq_disable();
1003 for (i = 0; i < 4; i++) {
1004 ret = crypto_hash_digest(desc, sg, blen, out);
1009 /* The real thing. */
1010 for (i = 0; i < 8; i++) {
1011 cycles_t start, end;
1013 start = get_cycles();
1015 ret = crypto_hash_digest(desc, sg, blen, out);
1021 cycles += end - start;
1031 printk("%6lu cycles/operation, %4lu cycles/byte\n",
1032 cycles / 8, cycles / (8 * blen));
1037 static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg,
1038 int blen, int plen, char *out)
1040 unsigned long cycles = 0;
1045 return test_hash_cycles_digest(desc, sg, blen, out);
1048 local_irq_disable();
1051 for (i = 0; i < 4; i++) {
1052 ret = crypto_hash_init(desc);
1055 for (pcount = 0; pcount < blen; pcount += plen) {
1056 ret = crypto_hash_update(desc, sg, plen);
1060 ret = crypto_hash_final(desc, out);
1065 /* The real thing. */
1066 for (i = 0; i < 8; i++) {
1067 cycles_t start, end;
1069 start = get_cycles();
1071 ret = crypto_hash_init(desc);
1074 for (pcount = 0; pcount < blen; pcount += plen) {
1075 ret = crypto_hash_update(desc, sg, plen);
1079 ret = crypto_hash_final(desc, out);
1085 cycles += end - start;
1095 printk("%6lu cycles/operation, %4lu cycles/byte\n",
1096 cycles / 8, cycles / (8 * blen));
1101 static void test_hash_speed(char *algo, unsigned int sec,
1102 struct hash_speed *speed)
1104 struct scatterlist sg[TVMEMSIZE];
1105 struct crypto_hash *tfm;
1106 struct hash_desc desc;
1111 printk("\ntesting speed of %s\n", algo);
1113 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
1116 printk("failed to load transform for %s: %ld\n", algo,
1124 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
1125 printk("digestsize(%u) > outputbuffer(%zu)\n",
1126 crypto_hash_digestsize(tfm), sizeof(output));
1130 sg_init_table(sg, TVMEMSIZE);
1131 for (i = 0; i < TVMEMSIZE; i++) {
1132 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
1133 memset(tvmem[i], 0xff, PAGE_SIZE);
1136 for (i = 0; speed[i].blen != 0; i++) {
1137 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
1138 printk("template (%u) too big for tvmem (%lu)\n",
1139 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
1143 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
1144 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
1147 ret = test_hash_jiffies(&desc, sg, speed[i].blen,
1148 speed[i].plen, output, sec);
1150 ret = test_hash_cycles(&desc, sg, speed[i].blen,
1151 speed[i].plen, output);
1154 printk("hashing failed ret=%d\n", ret);
1160 crypto_free_hash(tfm);
1163 static int test_comp(char *algo, struct comp_testvec *ctemplate,
1164 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1167 char result[COMP_BUF_SIZE];
1168 struct crypto_comp *tfm;
1171 tfm = crypto_alloc_comp(algo, 0, CRYPTO_ALG_ASYNC);
1173 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1174 "%ld\n", algo, PTR_ERR(tfm));
1175 return PTR_ERR(tfm);
1178 for (i = 0; i < ctcount; i++) {
1179 int ilen, dlen = COMP_BUF_SIZE;
1181 memset(result, 0, sizeof (result));
1183 ilen = ctemplate[i].inlen;
1184 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1185 ilen, result, &dlen);
1187 printk(KERN_ERR "alg: comp: compression failed "
1188 "on test %d for %s: ret=%d\n", i + 1, algo,
1193 if (memcmp(result, ctemplate[i].output, dlen)) {
1194 printk(KERN_ERR "alg: comp: Compression test %d "
1195 "failed for %s\n", i + 1, algo);
1196 hexdump(result, dlen);
1202 for (i = 0; i < dtcount; i++) {
1203 int ilen, ret, dlen = COMP_BUF_SIZE;
1205 memset(result, 0, sizeof (result));
1207 ilen = dtemplate[i].inlen;
1208 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1209 ilen, result, &dlen);
1211 printk(KERN_ERR "alg: comp: decompression failed "
1212 "on test %d for %s: ret=%d\n", i + 1, algo,
1217 if (memcmp(result, dtemplate[i].output, dlen)) {
1218 printk(KERN_ERR "alg: comp: Decompression test %d "
1219 "failed for %s\n", i + 1, algo);
1220 hexdump(result, dlen);
1229 crypto_free_comp(tfm);
1233 static void test_available(void)
1235 char **name = check;
1238 printk("alg %s ", *name);
1239 printk(crypto_has_alg(*name, 0, 0) ?
1240 "found\n" : "not found\n");
1245 static void do_test(void)
1250 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
1252 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
1255 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
1256 DES_ENC_TEST_VECTORS);
1257 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
1258 DES_DEC_TEST_VECTORS);
1259 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
1260 DES_CBC_ENC_TEST_VECTORS);
1261 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
1262 DES_CBC_DEC_TEST_VECTORS);
1265 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
1266 DES3_EDE_ENC_TEST_VECTORS);
1267 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1268 DES3_EDE_DEC_TEST_VECTORS);
1270 test_cipher("cbc(des3_ede)", ENCRYPT,
1271 des3_ede_cbc_enc_tv_template,
1272 DES3_EDE_CBC_ENC_TEST_VECTORS);
1274 test_cipher("cbc(des3_ede)", DECRYPT,
1275 des3_ede_cbc_dec_tv_template,
1276 DES3_EDE_CBC_DEC_TEST_VECTORS);
1278 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1280 test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
1282 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1285 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
1286 BF_ENC_TEST_VECTORS);
1287 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
1288 BF_DEC_TEST_VECTORS);
1289 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
1290 BF_CBC_ENC_TEST_VECTORS);
1291 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
1292 BF_CBC_DEC_TEST_VECTORS);
1295 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
1296 TF_ENC_TEST_VECTORS);
1297 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
1298 TF_DEC_TEST_VECTORS);
1299 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
1300 TF_CBC_ENC_TEST_VECTORS);
1301 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
1302 TF_CBC_DEC_TEST_VECTORS);
1305 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
1306 SERPENT_ENC_TEST_VECTORS);
1307 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
1308 SERPENT_DEC_TEST_VECTORS);
1311 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1312 TNEPRES_ENC_TEST_VECTORS);
1313 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1314 TNEPRES_DEC_TEST_VECTORS);
1317 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
1318 AES_ENC_TEST_VECTORS);
1319 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
1320 AES_DEC_TEST_VECTORS);
1321 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
1322 AES_CBC_ENC_TEST_VECTORS);
1323 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
1324 AES_CBC_DEC_TEST_VECTORS);
1325 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
1326 AES_LRW_ENC_TEST_VECTORS);
1327 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
1328 AES_LRW_DEC_TEST_VECTORS);
1329 test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
1330 AES_XTS_ENC_TEST_VECTORS);
1331 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
1332 AES_XTS_DEC_TEST_VECTORS);
1333 test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
1334 AES_CTR_ENC_TEST_VECTORS);
1335 test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
1336 AES_CTR_DEC_TEST_VECTORS);
1337 test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
1338 AES_GCM_ENC_TEST_VECTORS);
1339 test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
1340 AES_GCM_DEC_TEST_VECTORS);
1341 test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template,
1342 AES_CCM_ENC_TEST_VECTORS);
1343 test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template,
1344 AES_CCM_DEC_TEST_VECTORS);
1347 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1348 CAST5_ENC_TEST_VECTORS);
1349 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1350 CAST5_DEC_TEST_VECTORS);
1353 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1354 CAST6_ENC_TEST_VECTORS);
1355 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1356 CAST6_DEC_TEST_VECTORS);
1359 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1360 ARC4_ENC_TEST_VECTORS);
1361 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1362 ARC4_DEC_TEST_VECTORS);
1365 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1366 TEA_ENC_TEST_VECTORS);
1367 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1368 TEA_DEC_TEST_VECTORS);
1372 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1373 XTEA_ENC_TEST_VECTORS);
1374 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1375 XTEA_DEC_TEST_VECTORS);
1378 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1379 KHAZAD_ENC_TEST_VECTORS);
1380 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1381 KHAZAD_DEC_TEST_VECTORS);
1384 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1385 ANUBIS_ENC_TEST_VECTORS);
1386 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1387 ANUBIS_DEC_TEST_VECTORS);
1388 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1389 ANUBIS_CBC_ENC_TEST_VECTORS);
1390 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1391 ANUBIS_CBC_ENC_TEST_VECTORS);
1394 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1395 XETA_ENC_TEST_VECTORS);
1396 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1397 XETA_DEC_TEST_VECTORS);
1400 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1401 FCRYPT_ENC_TEST_VECTORS);
1402 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1403 FCRYPT_DEC_TEST_VECTORS);
1406 test_cipher("ecb(camellia)", ENCRYPT,
1407 camellia_enc_tv_template,
1408 CAMELLIA_ENC_TEST_VECTORS);
1409 test_cipher("ecb(camellia)", DECRYPT,
1410 camellia_dec_tv_template,
1411 CAMELLIA_DEC_TEST_VECTORS);
1412 test_cipher("cbc(camellia)", ENCRYPT,
1413 camellia_cbc_enc_tv_template,
1414 CAMELLIA_CBC_ENC_TEST_VECTORS);
1415 test_cipher("cbc(camellia)", DECRYPT,
1416 camellia_cbc_dec_tv_template,
1417 CAMELLIA_CBC_DEC_TEST_VECTORS);
1420 test_cipher("ecb(seed)", ENCRYPT, seed_enc_tv_template,
1421 SEED_ENC_TEST_VECTORS);
1422 test_cipher("ecb(seed)", DECRYPT, seed_dec_tv_template,
1423 SEED_DEC_TEST_VECTORS);
1426 test_cipher("cts(cbc(aes))", ENCRYPT, cts_mode_enc_tv_template,
1427 CTS_MODE_ENC_TEST_VECTORS);
1428 test_cipher("cts(cbc(aes))", DECRYPT, cts_mode_dec_tv_template,
1429 CTS_MODE_DEC_TEST_VECTORS);
1431 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1432 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1433 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1434 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1435 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1436 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1437 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1438 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1439 test_comp("deflate", deflate_comp_tv_template,
1440 deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
1441 DEFLATE_DECOMP_TEST_VECTORS);
1442 test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template,
1443 LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
1444 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1445 test_hash("hmac(md5)", hmac_md5_tv_template,
1446 HMAC_MD5_TEST_VECTORS);
1447 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1448 HMAC_SHA1_TEST_VECTORS);
1449 test_hash("hmac(sha224)", hmac_sha224_tv_template,
1450 HMAC_SHA224_TEST_VECTORS);
1451 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1452 HMAC_SHA256_TEST_VECTORS);
1453 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1454 HMAC_SHA384_TEST_VECTORS);
1455 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1456 HMAC_SHA512_TEST_VECTORS);
1458 test_hash("xcbc(aes)", aes_xcbc128_tv_template,
1459 XCBC_AES_TEST_VECTORS);
1461 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1465 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
1469 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
1473 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
1474 DES_ENC_TEST_VECTORS);
1475 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
1476 DES_DEC_TEST_VECTORS);
1477 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
1478 DES_CBC_ENC_TEST_VECTORS);
1479 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
1480 DES_CBC_DEC_TEST_VECTORS);
1484 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
1485 DES3_EDE_ENC_TEST_VECTORS);
1486 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1487 DES3_EDE_DEC_TEST_VECTORS);
1489 test_cipher("cbc(des3_ede)", ENCRYPT,
1490 des3_ede_cbc_enc_tv_template,
1491 DES3_EDE_CBC_ENC_TEST_VECTORS);
1493 test_cipher("cbc(des3_ede)", DECRYPT,
1494 des3_ede_cbc_dec_tv_template,
1495 DES3_EDE_CBC_DEC_TEST_VECTORS);
1499 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1503 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1507 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
1508 BF_ENC_TEST_VECTORS);
1509 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
1510 BF_DEC_TEST_VECTORS);
1511 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
1512 BF_CBC_ENC_TEST_VECTORS);
1513 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
1514 BF_CBC_DEC_TEST_VECTORS);
1518 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
1519 TF_ENC_TEST_VECTORS);
1520 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
1521 TF_DEC_TEST_VECTORS);
1522 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
1523 TF_CBC_ENC_TEST_VECTORS);
1524 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
1525 TF_CBC_DEC_TEST_VECTORS);
1529 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
1530 SERPENT_ENC_TEST_VECTORS);
1531 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
1532 SERPENT_DEC_TEST_VECTORS);
1536 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
1537 AES_ENC_TEST_VECTORS);
1538 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
1539 AES_DEC_TEST_VECTORS);
1540 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
1541 AES_CBC_ENC_TEST_VECTORS);
1542 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
1543 AES_CBC_DEC_TEST_VECTORS);
1544 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
1545 AES_LRW_ENC_TEST_VECTORS);
1546 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
1547 AES_LRW_DEC_TEST_VECTORS);
1548 test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
1549 AES_XTS_ENC_TEST_VECTORS);
1550 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
1551 AES_XTS_DEC_TEST_VECTORS);
1552 test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
1553 AES_CTR_ENC_TEST_VECTORS);
1554 test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
1555 AES_CTR_DEC_TEST_VECTORS);
1559 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1563 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1567 test_comp("deflate", deflate_comp_tv_template,
1568 deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
1569 DEFLATE_DECOMP_TEST_VECTORS);
1573 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1574 CAST5_ENC_TEST_VECTORS);
1575 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1576 CAST5_DEC_TEST_VECTORS);
1580 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1581 CAST6_ENC_TEST_VECTORS);
1582 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1583 CAST6_DEC_TEST_VECTORS);
1587 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1588 ARC4_ENC_TEST_VECTORS);
1589 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1590 ARC4_DEC_TEST_VECTORS);
1594 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1598 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1602 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1603 TEA_ENC_TEST_VECTORS);
1604 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1605 TEA_DEC_TEST_VECTORS);
1609 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1610 XTEA_ENC_TEST_VECTORS);
1611 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1612 XTEA_DEC_TEST_VECTORS);
1616 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1617 KHAZAD_ENC_TEST_VECTORS);
1618 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1619 KHAZAD_DEC_TEST_VECTORS);
1623 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1627 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1631 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1635 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1636 TNEPRES_ENC_TEST_VECTORS);
1637 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1638 TNEPRES_DEC_TEST_VECTORS);
1642 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1643 ANUBIS_ENC_TEST_VECTORS);
1644 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1645 ANUBIS_DEC_TEST_VECTORS);
1646 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1647 ANUBIS_CBC_ENC_TEST_VECTORS);
1648 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1649 ANUBIS_CBC_ENC_TEST_VECTORS);
1653 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1658 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1662 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1666 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1667 XETA_ENC_TEST_VECTORS);
1668 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1669 XETA_DEC_TEST_VECTORS);
1673 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1674 FCRYPT_ENC_TEST_VECTORS);
1675 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1676 FCRYPT_DEC_TEST_VECTORS);
1680 test_cipher("ecb(camellia)", ENCRYPT,
1681 camellia_enc_tv_template,
1682 CAMELLIA_ENC_TEST_VECTORS);
1683 test_cipher("ecb(camellia)", DECRYPT,
1684 camellia_dec_tv_template,
1685 CAMELLIA_DEC_TEST_VECTORS);
1686 test_cipher("cbc(camellia)", ENCRYPT,
1687 camellia_cbc_enc_tv_template,
1688 CAMELLIA_CBC_ENC_TEST_VECTORS);
1689 test_cipher("cbc(camellia)", DECRYPT,
1690 camellia_cbc_dec_tv_template,
1691 CAMELLIA_CBC_DEC_TEST_VECTORS);
1694 test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
1698 test_cipher("salsa20", ENCRYPT,
1699 salsa20_stream_enc_tv_template,
1700 SALSA20_STREAM_ENC_TEST_VECTORS);
1704 test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
1705 AES_GCM_ENC_TEST_VECTORS);
1706 test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
1707 AES_GCM_DEC_TEST_VECTORS);
1711 test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template,
1712 LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
1716 test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template,
1717 AES_CCM_ENC_TEST_VECTORS);
1718 test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template,
1719 AES_CCM_DEC_TEST_VECTORS);
1723 test_cipher("cts(cbc(aes))", ENCRYPT, cts_mode_enc_tv_template,
1724 CTS_MODE_ENC_TEST_VECTORS);
1725 test_cipher("cts(cbc(aes))", DECRYPT, cts_mode_dec_tv_template,
1726 CTS_MODE_DEC_TEST_VECTORS);
1730 test_hash("rmd128", rmd128_tv_template, RMD128_TEST_VECTORS);
1734 test_hash("rmd160", rmd160_tv_template, RMD160_TEST_VECTORS);
1738 test_hash("rmd256", rmd256_tv_template, RMD256_TEST_VECTORS);
1742 test_hash("rmd320", rmd320_tv_template, RMD320_TEST_VECTORS);
1746 test_hash("hmac(md5)", hmac_md5_tv_template,
1747 HMAC_MD5_TEST_VECTORS);
1751 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1752 HMAC_SHA1_TEST_VECTORS);
1756 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1757 HMAC_SHA256_TEST_VECTORS);
1761 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1762 HMAC_SHA384_TEST_VECTORS);
1766 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1767 HMAC_SHA512_TEST_VECTORS);
1771 test_hash("hmac(sha224)", hmac_sha224_tv_template,
1772 HMAC_SHA224_TEST_VECTORS);
1776 test_hash("xcbc(aes)", aes_xcbc128_tv_template,
1777 XCBC_AES_TEST_VECTORS);
1781 test_hash("hmac(rmd128)", hmac_rmd128_tv_template,
1782 HMAC_RMD128_TEST_VECTORS);
1786 test_hash("hmac(rmd160)", hmac_rmd160_tv_template,
1787 HMAC_RMD160_TEST_VECTORS);
1791 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1792 speed_template_16_24_32);
1793 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1794 speed_template_16_24_32);
1795 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1796 speed_template_16_24_32);
1797 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1798 speed_template_16_24_32);
1799 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1800 speed_template_32_40_48);
1801 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1802 speed_template_32_40_48);
1803 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1804 speed_template_32_48_64);
1805 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1806 speed_template_32_48_64);
1810 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1811 des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
1813 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1814 des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
1816 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1817 des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
1819 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1820 des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
1825 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1826 speed_template_16_24_32);
1827 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1828 speed_template_16_24_32);
1829 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1830 speed_template_16_24_32);
1831 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1832 speed_template_16_24_32);
1836 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1837 speed_template_8_32);
1838 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1839 speed_template_8_32);
1840 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1841 speed_template_8_32);
1842 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1843 speed_template_8_32);
1847 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1849 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1851 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1853 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1858 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1859 speed_template_16_24_32);
1860 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1861 speed_template_16_24_32);
1862 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1863 speed_template_16_24_32);
1864 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1865 speed_template_16_24_32);
1869 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
1870 speed_template_16_32);
1877 test_hash_speed("md4", sec, generic_hash_speed_template);
1878 if (mode > 300 && mode < 400) break;
1881 test_hash_speed("md5", sec, generic_hash_speed_template);
1882 if (mode > 300 && mode < 400) break;
1885 test_hash_speed("sha1", sec, generic_hash_speed_template);
1886 if (mode > 300 && mode < 400) break;
1889 test_hash_speed("sha256", sec, generic_hash_speed_template);
1890 if (mode > 300 && mode < 400) break;
1893 test_hash_speed("sha384", sec, generic_hash_speed_template);
1894 if (mode > 300 && mode < 400) break;
1897 test_hash_speed("sha512", sec, generic_hash_speed_template);
1898 if (mode > 300 && mode < 400) break;
1901 test_hash_speed("wp256", sec, generic_hash_speed_template);
1902 if (mode > 300 && mode < 400) break;
1905 test_hash_speed("wp384", sec, generic_hash_speed_template);
1906 if (mode > 300 && mode < 400) break;
1909 test_hash_speed("wp512", sec, generic_hash_speed_template);
1910 if (mode > 300 && mode < 400) break;
1913 test_hash_speed("tgr128", sec, generic_hash_speed_template);
1914 if (mode > 300 && mode < 400) break;
1917 test_hash_speed("tgr160", sec, generic_hash_speed_template);
1918 if (mode > 300 && mode < 400) break;
1921 test_hash_speed("tgr192", sec, generic_hash_speed_template);
1922 if (mode > 300 && mode < 400) break;
1925 test_hash_speed("sha224", sec, generic_hash_speed_template);
1926 if (mode > 300 && mode < 400) break;
1929 test_hash_speed("rmd128", sec, generic_hash_speed_template);
1930 if (mode > 300 && mode < 400) break;
1933 test_hash_speed("rmd160", sec, generic_hash_speed_template);
1934 if (mode > 300 && mode < 400) break;
1937 test_hash_speed("rmd256", sec, generic_hash_speed_template);
1938 if (mode > 300 && mode < 400) break;
1941 test_hash_speed("rmd320", sec, generic_hash_speed_template);
1942 if (mode > 300 && mode < 400) break;
1952 /* useful for debugging */
1953 printk("not testing anything\n");
1958 static int __init tcrypt_mod_init(void)
1963 for (i = 0; i < TVMEMSIZE; i++) {
1964 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
1969 for (i = 0; i < XBUFSIZE; i++) {
1970 xbuf[i] = (void *)__get_free_page(GFP_KERNEL);
1975 for (i = 0; i < XBUFSIZE; i++) {
1976 axbuf[i] = (void *)__get_free_page(GFP_KERNEL);
1978 goto err_free_axbuf;
1983 /* We intentionaly return -EAGAIN to prevent keeping
1984 * the module. It does all its work from init()
1985 * and doesn't offer any runtime functionality
1986 * => we don't need it in the memory, do we?
1992 for (i = 0; i < XBUFSIZE && axbuf[i]; i++)
1993 free_page((unsigned long)axbuf[i]);
1995 for (i = 0; i < XBUFSIZE && xbuf[i]; i++)
1996 free_page((unsigned long)xbuf[i]);
1998 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
1999 free_page((unsigned long)tvmem[i]);
2005 * If an init function is provided, an exit function must also be provided
2006 * to allow module unload.
2008 static void __exit tcrypt_mod_fini(void) { }
2010 module_init(tcrypt_mod_init);
2011 module_exit(tcrypt_mod_fini);
2013 module_param(mode, int, 0);
2014 module_param(sec, uint, 0);
2015 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
2016 "(defaults to zero which uses CPU cycles instead)");
2018 MODULE_LICENSE("GPL");
2019 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2020 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");