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/gfp.h>
22 #include <linux/module.h>
23 #include <linux/scatterlist.h>
24 #include <linux/string.h>
25 #include <linux/moduleparam.h>
26 #include <linux/jiffies.h>
27 #include <linux/timex.h>
28 #include <linux/interrupt.h>
33 * Need slab memory for testing (size in number of pages).
38 * Used by test_cipher_speed()
44 * Used by test_cipher_speed()
46 static unsigned int sec;
48 static char *alg = NULL;
52 static char *tvmem[TVMEMSIZE];
54 static char *check[] = {
55 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
56 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
57 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
58 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
59 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
60 "lzo", "cts", "zlib", NULL
63 static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc,
64 struct scatterlist *sg, int blen, int sec)
66 unsigned long start, end;
70 for (start = jiffies, end = start + sec * HZ, bcount = 0;
71 time_before(jiffies, end); bcount++) {
73 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
75 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
81 printk("%d operations in %d seconds (%ld bytes)\n",
82 bcount, sec, (long)bcount * blen);
86 static int test_cipher_cycles(struct blkcipher_desc *desc, int enc,
87 struct scatterlist *sg, int blen)
89 unsigned long cycles = 0;
97 for (i = 0; i < 4; i++) {
99 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
101 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
107 /* The real thing. */
108 for (i = 0; i < 8; i++) {
111 start = get_cycles();
113 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
115 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
121 cycles += end - start;
129 printk("1 operation in %lu cycles (%d bytes)\n",
130 (cycles + 4) / 8, blen);
135 static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
137 static void test_cipher_speed(const char *algo, int enc, unsigned int sec,
138 struct cipher_speed_template *template,
139 unsigned int tcount, u8 *keysize)
141 unsigned int ret, i, j, iv_len;
142 const char *key, iv[128];
143 struct crypto_blkcipher *tfm;
144 struct blkcipher_desc desc;
153 printk("\ntesting speed of %s %s\n", algo, e);
155 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
158 printk("failed to load transform for %s: %ld\n", algo,
168 b_size = block_sizes;
170 struct scatterlist sg[TVMEMSIZE];
172 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
173 printk("template (%u) too big for "
174 "tvmem (%lu)\n", *keysize + *b_size,
175 TVMEMSIZE * PAGE_SIZE);
179 printk("test %u (%d bit key, %d byte blocks): ", i,
180 *keysize * 8, *b_size);
182 memset(tvmem[0], 0xff, PAGE_SIZE);
184 /* set key, plain text and IV */
186 for (j = 0; j < tcount; j++) {
187 if (template[j].klen == *keysize) {
188 key = template[j].key;
193 ret = crypto_blkcipher_setkey(tfm, key, *keysize);
195 printk("setkey() failed flags=%x\n",
196 crypto_blkcipher_get_flags(tfm));
200 sg_init_table(sg, TVMEMSIZE);
201 sg_set_buf(sg, tvmem[0] + *keysize,
202 PAGE_SIZE - *keysize);
203 for (j = 1; j < TVMEMSIZE; j++) {
204 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
205 memset (tvmem[j], 0xff, PAGE_SIZE);
208 iv_len = crypto_blkcipher_ivsize(tfm);
210 memset(&iv, 0xff, iv_len);
211 crypto_blkcipher_set_iv(tfm, iv, iv_len);
215 ret = test_cipher_jiffies(&desc, enc, sg,
218 ret = test_cipher_cycles(&desc, enc, sg,
222 printk("%s() failed flags=%x\n", e, desc.flags);
232 crypto_free_blkcipher(tfm);
235 static int test_hash_jiffies_digest(struct hash_desc *desc,
236 struct scatterlist *sg, int blen,
239 unsigned long start, end;
243 for (start = jiffies, end = start + sec * HZ, bcount = 0;
244 time_before(jiffies, end); bcount++) {
245 ret = crypto_hash_digest(desc, sg, blen, out);
250 printk("%6u opers/sec, %9lu bytes/sec\n",
251 bcount / sec, ((long)bcount * blen) / sec);
256 static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg,
257 int blen, int plen, char *out, int sec)
259 unsigned long start, end;
264 return test_hash_jiffies_digest(desc, sg, blen, out, sec);
266 for (start = jiffies, end = start + sec * HZ, bcount = 0;
267 time_before(jiffies, end); bcount++) {
268 ret = crypto_hash_init(desc);
271 for (pcount = 0; pcount < blen; pcount += plen) {
272 ret = crypto_hash_update(desc, sg, plen);
276 /* we assume there is enough space in 'out' for the result */
277 ret = crypto_hash_final(desc, out);
282 printk("%6u opers/sec, %9lu bytes/sec\n",
283 bcount / sec, ((long)bcount * blen) / sec);
288 static int test_hash_cycles_digest(struct hash_desc *desc,
289 struct scatterlist *sg, int blen, char *out)
291 unsigned long cycles = 0;
299 for (i = 0; i < 4; i++) {
300 ret = crypto_hash_digest(desc, sg, blen, out);
305 /* The real thing. */
306 for (i = 0; i < 8; i++) {
309 start = get_cycles();
311 ret = crypto_hash_digest(desc, sg, blen, out);
317 cycles += end - start;
327 printk("%6lu cycles/operation, %4lu cycles/byte\n",
328 cycles / 8, cycles / (8 * blen));
333 static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg,
334 int blen, int plen, char *out)
336 unsigned long cycles = 0;
341 return test_hash_cycles_digest(desc, sg, blen, out);
347 for (i = 0; i < 4; i++) {
348 ret = crypto_hash_init(desc);
351 for (pcount = 0; pcount < blen; pcount += plen) {
352 ret = crypto_hash_update(desc, sg, plen);
356 ret = crypto_hash_final(desc, out);
361 /* The real thing. */
362 for (i = 0; i < 8; i++) {
365 start = get_cycles();
367 ret = crypto_hash_init(desc);
370 for (pcount = 0; pcount < blen; pcount += plen) {
371 ret = crypto_hash_update(desc, sg, plen);
375 ret = crypto_hash_final(desc, out);
381 cycles += end - start;
391 printk("%6lu cycles/operation, %4lu cycles/byte\n",
392 cycles / 8, cycles / (8 * blen));
397 static void test_hash_sg_init(struct scatterlist *sg)
401 sg_init_table(sg, TVMEMSIZE);
402 for (i = 0; i < TVMEMSIZE; i++) {
403 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
404 memset(tvmem[i], 0xff, PAGE_SIZE);
408 static void test_hash_speed(const char *algo, unsigned int sec,
409 struct hash_speed *speed)
411 struct scatterlist sg[TVMEMSIZE];
412 struct crypto_hash *tfm;
413 struct hash_desc desc;
414 static char output[1024];
418 printk(KERN_INFO "\ntesting speed of %s\n", algo);
420 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
423 printk(KERN_ERR "failed to load transform for %s: %ld\n", algo,
431 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
432 printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n",
433 crypto_hash_digestsize(tfm), sizeof(output));
437 test_hash_sg_init(sg);
438 for (i = 0; speed[i].blen != 0; i++) {
439 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
441 "template (%u) too big for tvmem (%lu)\n",
442 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
447 crypto_hash_setkey(tfm, tvmem[0], speed[i].klen);
449 printk(KERN_INFO "test%3u "
450 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
451 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
454 ret = test_hash_jiffies(&desc, sg, speed[i].blen,
455 speed[i].plen, output, sec);
457 ret = test_hash_cycles(&desc, sg, speed[i].blen,
458 speed[i].plen, output);
461 printk(KERN_ERR "hashing failed ret=%d\n", ret);
467 crypto_free_hash(tfm);
470 struct tcrypt_result {
471 struct completion completion;
475 static void tcrypt_complete(struct crypto_async_request *req, int err)
477 struct tcrypt_result *res = req->data;
479 if (err == -EINPROGRESS)
483 complete(&res->completion);
486 static inline int do_one_ahash_op(struct ahash_request *req, int ret)
488 if (ret == -EINPROGRESS || ret == -EBUSY) {
489 struct tcrypt_result *tr = req->base.data;
491 ret = wait_for_completion_interruptible(&tr->completion);
494 INIT_COMPLETION(tr->completion);
499 static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
502 unsigned long start, end;
506 for (start = jiffies, end = start + sec * HZ, bcount = 0;
507 time_before(jiffies, end); bcount++) {
508 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
513 printk("%6u opers/sec, %9lu bytes/sec\n",
514 bcount / sec, ((long)bcount * blen) / sec);
519 static int test_ahash_jiffies(struct ahash_request *req, int blen,
520 int plen, char *out, int sec)
522 unsigned long start, end;
527 return test_ahash_jiffies_digest(req, blen, out, sec);
529 for (start = jiffies, end = start + sec * HZ, bcount = 0;
530 time_before(jiffies, end); bcount++) {
531 ret = crypto_ahash_init(req);
534 for (pcount = 0; pcount < blen; pcount += plen) {
535 ret = do_one_ahash_op(req, crypto_ahash_update(req));
539 /* we assume there is enough space in 'out' for the result */
540 ret = do_one_ahash_op(req, crypto_ahash_final(req));
545 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
546 bcount / sec, ((long)bcount * blen) / sec);
551 static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
554 unsigned long cycles = 0;
558 for (i = 0; i < 4; i++) {
559 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
564 /* The real thing. */
565 for (i = 0; i < 8; i++) {
568 start = get_cycles();
570 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
576 cycles += end - start;
583 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
584 cycles / 8, cycles / (8 * blen));
589 static int test_ahash_cycles(struct ahash_request *req, int blen,
592 unsigned long cycles = 0;
596 return test_ahash_cycles_digest(req, blen, out);
599 for (i = 0; i < 4; i++) {
600 ret = crypto_ahash_init(req);
603 for (pcount = 0; pcount < blen; pcount += plen) {
604 ret = do_one_ahash_op(req, crypto_ahash_update(req));
608 ret = do_one_ahash_op(req, crypto_ahash_final(req));
613 /* The real thing. */
614 for (i = 0; i < 8; i++) {
617 start = get_cycles();
619 ret = crypto_ahash_init(req);
622 for (pcount = 0; pcount < blen; pcount += plen) {
623 ret = do_one_ahash_op(req, crypto_ahash_update(req));
627 ret = do_one_ahash_op(req, crypto_ahash_final(req));
633 cycles += end - start;
640 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
641 cycles / 8, cycles / (8 * blen));
646 static void test_ahash_speed(const char *algo, unsigned int sec,
647 struct hash_speed *speed)
649 struct scatterlist sg[TVMEMSIZE];
650 struct tcrypt_result tresult;
651 struct ahash_request *req;
652 struct crypto_ahash *tfm;
653 static char output[1024];
656 printk(KERN_INFO "\ntesting speed of async %s\n", algo);
658 tfm = crypto_alloc_ahash(algo, 0, 0);
660 pr_err("failed to load transform for %s: %ld\n",
665 if (crypto_ahash_digestsize(tfm) > sizeof(output)) {
666 pr_err("digestsize(%u) > outputbuffer(%zu)\n",
667 crypto_ahash_digestsize(tfm), sizeof(output));
671 test_hash_sg_init(sg);
672 req = ahash_request_alloc(tfm, GFP_KERNEL);
674 pr_err("ahash request allocation failure\n");
678 init_completion(&tresult.completion);
679 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
680 tcrypt_complete, &tresult);
682 for (i = 0; speed[i].blen != 0; i++) {
683 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
684 pr_err("template (%u) too big for tvmem (%lu)\n",
685 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
690 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
691 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
693 ahash_request_set_crypt(req, sg, output, speed[i].plen);
696 ret = test_ahash_jiffies(req, speed[i].blen,
697 speed[i].plen, output, sec);
699 ret = test_ahash_cycles(req, speed[i].blen,
700 speed[i].plen, output);
703 pr_err("hashing failed ret=%d\n", ret);
708 ahash_request_free(req);
711 crypto_free_ahash(tfm);
714 static void test_available(void)
719 printk("alg %s ", *name);
720 printk(crypto_has_alg(*name, 0, 0) ?
721 "found\n" : "not found\n");
726 static inline int tcrypt_test(const char *alg)
730 ret = alg_test(alg, alg, 0, 0);
731 /* non-fips algs return -EINVAL in fips mode */
732 if (fips_enabled && ret == -EINVAL)
737 static int do_test(int m)
744 for (i = 1; i < 200; i++)
749 ret += tcrypt_test("md5");
753 ret += tcrypt_test("sha1");
757 ret += tcrypt_test("ecb(des)");
758 ret += tcrypt_test("cbc(des)");
762 ret += tcrypt_test("ecb(des3_ede)");
763 ret += tcrypt_test("cbc(des3_ede)");
767 ret += tcrypt_test("md4");
771 ret += tcrypt_test("sha256");
775 ret += tcrypt_test("ecb(blowfish)");
776 ret += tcrypt_test("cbc(blowfish)");
780 ret += tcrypt_test("ecb(twofish)");
781 ret += tcrypt_test("cbc(twofish)");
785 ret += tcrypt_test("ecb(serpent)");
789 ret += tcrypt_test("ecb(aes)");
790 ret += tcrypt_test("cbc(aes)");
791 ret += tcrypt_test("lrw(aes)");
792 ret += tcrypt_test("xts(aes)");
793 ret += tcrypt_test("ctr(aes)");
794 ret += tcrypt_test("rfc3686(ctr(aes))");
798 ret += tcrypt_test("sha384");
802 ret += tcrypt_test("sha512");
806 ret += tcrypt_test("deflate");
810 ret += tcrypt_test("ecb(cast5)");
814 ret += tcrypt_test("ecb(cast6)");
818 ret += tcrypt_test("ecb(arc4)");
822 ret += tcrypt_test("michael_mic");
826 ret += tcrypt_test("crc32c");
830 ret += tcrypt_test("ecb(tea)");
834 ret += tcrypt_test("ecb(xtea)");
838 ret += tcrypt_test("ecb(khazad)");
842 ret += tcrypt_test("wp512");
846 ret += tcrypt_test("wp384");
850 ret += tcrypt_test("wp256");
854 ret += tcrypt_test("ecb(tnepres)");
858 ret += tcrypt_test("ecb(anubis)");
859 ret += tcrypt_test("cbc(anubis)");
863 ret += tcrypt_test("tgr192");
868 ret += tcrypt_test("tgr160");
872 ret += tcrypt_test("tgr128");
876 ret += tcrypt_test("ecb(xeta)");
880 ret += tcrypt_test("pcbc(fcrypt)");
884 ret += tcrypt_test("ecb(camellia)");
885 ret += tcrypt_test("cbc(camellia)");
888 ret += tcrypt_test("sha224");
892 ret += tcrypt_test("salsa20");
896 ret += tcrypt_test("gcm(aes)");
900 ret += tcrypt_test("lzo");
904 ret += tcrypt_test("ccm(aes)");
908 ret += tcrypt_test("cts(cbc(aes))");
912 ret += tcrypt_test("rmd128");
916 ret += tcrypt_test("rmd160");
920 ret += tcrypt_test("rmd256");
924 ret += tcrypt_test("rmd320");
928 ret += tcrypt_test("ecb(seed)");
932 ret += tcrypt_test("zlib");
936 ret += tcrypt_test("rfc4309(ccm(aes))");
940 ret += tcrypt_test("hmac(md5)");
944 ret += tcrypt_test("hmac(sha1)");
948 ret += tcrypt_test("hmac(sha256)");
952 ret += tcrypt_test("hmac(sha384)");
956 ret += tcrypt_test("hmac(sha512)");
960 ret += tcrypt_test("hmac(sha224)");
964 ret += tcrypt_test("xcbc(aes)");
968 ret += tcrypt_test("hmac(rmd128)");
972 ret += tcrypt_test("hmac(rmd160)");
976 ret += tcrypt_test("vmac(aes)");
980 ret += tcrypt_test("ansi_cprng");
984 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
985 speed_template_16_24_32);
986 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
987 speed_template_16_24_32);
988 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
989 speed_template_16_24_32);
990 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
991 speed_template_16_24_32);
992 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
993 speed_template_32_40_48);
994 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
995 speed_template_32_40_48);
996 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
997 speed_template_32_48_64);
998 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
999 speed_template_32_48_64);
1003 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1004 des3_speed_template, DES3_SPEED_VECTORS,
1006 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1007 des3_speed_template, DES3_SPEED_VECTORS,
1009 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1010 des3_speed_template, DES3_SPEED_VECTORS,
1012 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1013 des3_speed_template, DES3_SPEED_VECTORS,
1018 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1019 speed_template_16_24_32);
1020 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1021 speed_template_16_24_32);
1022 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1023 speed_template_16_24_32);
1024 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1025 speed_template_16_24_32);
1029 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1030 speed_template_8_32);
1031 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1032 speed_template_8_32);
1033 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1034 speed_template_8_32);
1035 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1036 speed_template_8_32);
1040 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1042 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1044 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1046 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1051 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1052 speed_template_16_24_32);
1053 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1054 speed_template_16_24_32);
1055 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1056 speed_template_16_24_32);
1057 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1058 speed_template_16_24_32);
1062 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
1063 speed_template_16_32);
1070 test_hash_speed("md4", sec, generic_hash_speed_template);
1071 if (mode > 300 && mode < 400) break;
1074 test_hash_speed("md5", sec, generic_hash_speed_template);
1075 if (mode > 300 && mode < 400) break;
1078 test_hash_speed("sha1", sec, generic_hash_speed_template);
1079 if (mode > 300 && mode < 400) break;
1082 test_hash_speed("sha256", sec, generic_hash_speed_template);
1083 if (mode > 300 && mode < 400) break;
1086 test_hash_speed("sha384", sec, generic_hash_speed_template);
1087 if (mode > 300 && mode < 400) break;
1090 test_hash_speed("sha512", sec, generic_hash_speed_template);
1091 if (mode > 300 && mode < 400) break;
1094 test_hash_speed("wp256", sec, generic_hash_speed_template);
1095 if (mode > 300 && mode < 400) break;
1098 test_hash_speed("wp384", sec, generic_hash_speed_template);
1099 if (mode > 300 && mode < 400) break;
1102 test_hash_speed("wp512", sec, generic_hash_speed_template);
1103 if (mode > 300 && mode < 400) break;
1106 test_hash_speed("tgr128", sec, generic_hash_speed_template);
1107 if (mode > 300 && mode < 400) break;
1110 test_hash_speed("tgr160", sec, generic_hash_speed_template);
1111 if (mode > 300 && mode < 400) break;
1114 test_hash_speed("tgr192", sec, generic_hash_speed_template);
1115 if (mode > 300 && mode < 400) break;
1118 test_hash_speed("sha224", sec, generic_hash_speed_template);
1119 if (mode > 300 && mode < 400) break;
1122 test_hash_speed("rmd128", sec, generic_hash_speed_template);
1123 if (mode > 300 && mode < 400) break;
1126 test_hash_speed("rmd160", sec, generic_hash_speed_template);
1127 if (mode > 300 && mode < 400) break;
1130 test_hash_speed("rmd256", sec, generic_hash_speed_template);
1131 if (mode > 300 && mode < 400) break;
1134 test_hash_speed("rmd320", sec, generic_hash_speed_template);
1135 if (mode > 300 && mode < 400) break;
1138 test_hash_speed("ghash-generic", sec, hash_speed_template_16);
1139 if (mode > 300 && mode < 400) break;
1148 test_ahash_speed("md4", sec, generic_hash_speed_template);
1149 if (mode > 400 && mode < 500) break;
1152 test_ahash_speed("md5", sec, generic_hash_speed_template);
1153 if (mode > 400 && mode < 500) break;
1156 test_ahash_speed("sha1", sec, generic_hash_speed_template);
1157 if (mode > 400 && mode < 500) break;
1160 test_ahash_speed("sha256", sec, generic_hash_speed_template);
1161 if (mode > 400 && mode < 500) break;
1164 test_ahash_speed("sha384", sec, generic_hash_speed_template);
1165 if (mode > 400 && mode < 500) break;
1168 test_ahash_speed("sha512", sec, generic_hash_speed_template);
1169 if (mode > 400 && mode < 500) break;
1172 test_ahash_speed("wp256", sec, generic_hash_speed_template);
1173 if (mode > 400 && mode < 500) break;
1176 test_ahash_speed("wp384", sec, generic_hash_speed_template);
1177 if (mode > 400 && mode < 500) break;
1180 test_ahash_speed("wp512", sec, generic_hash_speed_template);
1181 if (mode > 400 && mode < 500) break;
1184 test_ahash_speed("tgr128", sec, generic_hash_speed_template);
1185 if (mode > 400 && mode < 500) break;
1188 test_ahash_speed("tgr160", sec, generic_hash_speed_template);
1189 if (mode > 400 && mode < 500) break;
1192 test_ahash_speed("tgr192", sec, generic_hash_speed_template);
1193 if (mode > 400 && mode < 500) break;
1196 test_ahash_speed("sha224", sec, generic_hash_speed_template);
1197 if (mode > 400 && mode < 500) break;
1200 test_ahash_speed("rmd128", sec, generic_hash_speed_template);
1201 if (mode > 400 && mode < 500) break;
1204 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
1205 if (mode > 400 && mode < 500) break;
1208 test_ahash_speed("rmd256", sec, generic_hash_speed_template);
1209 if (mode > 400 && mode < 500) break;
1212 test_ahash_speed("rmd320", sec, generic_hash_speed_template);
1213 if (mode > 400 && mode < 500) break;
1226 static int do_alg_test(const char *alg, u32 type, u32 mask)
1228 return crypto_has_alg(alg, type, mask ?: CRYPTO_ALG_TYPE_MASK) ?
1232 static int __init tcrypt_mod_init(void)
1237 for (i = 0; i < TVMEMSIZE; i++) {
1238 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
1244 err = do_alg_test(alg, type, mask);
1246 err = do_test(mode);
1249 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
1253 /* We intentionaly return -EAGAIN to prevent keeping the module,
1254 * unless we're running in fips mode. It does all its work from
1255 * init() and doesn't offer any runtime functionality, but in
1256 * the fips case, checking for a successful load is helpful.
1257 * => we don't need it in the memory, do we?
1264 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
1265 free_page((unsigned long)tvmem[i]);
1271 * If an init function is provided, an exit function must also be provided
1272 * to allow module unload.
1274 static void __exit tcrypt_mod_fini(void) { }
1276 module_init(tcrypt_mod_init);
1277 module_exit(tcrypt_mod_fini);
1279 module_param(alg, charp, 0);
1280 module_param(type, uint, 0);
1281 module_param(mask, uint, 0);
1282 module_param(mode, int, 0);
1283 module_param(sec, uint, 0);
1284 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
1285 "(defaults to zero which uses CPU cycles instead)");
1287 MODULE_LICENSE("GPL");
1288 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1289 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");