tcrypt.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. /*
  2. * Quick & dirty crypto testing module.
  3. *
  4. * This will only exist until we have a better testing mechanism
  5. * (e.g. a char device).
  6. *
  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
  10. *
  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)
  14. * any later version.
  15. *
  16. */
  17. #include <crypto/hash.h>
  18. #include <linux/err.h>
  19. #include <linux/init.h>
  20. #include <linux/module.h>
  21. #include <linux/slab.h>
  22. #include <linux/scatterlist.h>
  23. #include <linux/string.h>
  24. #include <linux/moduleparam.h>
  25. #include <linux/jiffies.h>
  26. #include <linux/timex.h>
  27. #include <linux/interrupt.h>
  28. #include "tcrypt.h"
  29. /*
  30. * Need slab memory for testing (size in number of pages).
  31. */
  32. #define TVMEMSIZE 4
  33. /*
  34. * Used by test_cipher_speed()
  35. */
  36. #define ENCRYPT 1
  37. #define DECRYPT 0
  38. /*
  39. * Used by test_cipher_speed()
  40. */
  41. static unsigned int sec;
  42. static int mode;
  43. static char *tvmem[TVMEMSIZE];
  44. static char *check[] = {
  45. "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
  46. "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
  47. "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
  48. "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
  49. "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
  50. "lzo", "cts", "zlib", NULL
  51. };
  52. static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc,
  53. struct scatterlist *sg, int blen, int sec)
  54. {
  55. unsigned long start, end;
  56. int bcount;
  57. int ret;
  58. for (start = jiffies, end = start + sec * HZ, bcount = 0;
  59. time_before(jiffies, end); bcount++) {
  60. if (enc)
  61. ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
  62. else
  63. ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
  64. if (ret)
  65. return ret;
  66. }
  67. printk("%d operations in %d seconds (%ld bytes)\n",
  68. bcount, sec, (long)bcount * blen);
  69. return 0;
  70. }
  71. static int test_cipher_cycles(struct blkcipher_desc *desc, int enc,
  72. struct scatterlist *sg, int blen)
  73. {
  74. unsigned long cycles = 0;
  75. int ret = 0;
  76. int i;
  77. local_bh_disable();
  78. local_irq_disable();
  79. /* Warm-up run. */
  80. for (i = 0; i < 4; i++) {
  81. if (enc)
  82. ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
  83. else
  84. ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
  85. if (ret)
  86. goto out;
  87. }
  88. /* The real thing. */
  89. for (i = 0; i < 8; i++) {
  90. cycles_t start, end;
  91. start = get_cycles();
  92. if (enc)
  93. ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
  94. else
  95. ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
  96. end = get_cycles();
  97. if (ret)
  98. goto out;
  99. cycles += end - start;
  100. }
  101. out:
  102. local_irq_enable();
  103. local_bh_enable();
  104. if (ret == 0)
  105. printk("1 operation in %lu cycles (%d bytes)\n",
  106. (cycles + 4) / 8, blen);
  107. return ret;
  108. }
  109. static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
  110. static void test_cipher_speed(const char *algo, int enc, unsigned int sec,
  111. struct cipher_speed_template *template,
  112. unsigned int tcount, u8 *keysize)
  113. {
  114. unsigned int ret, i, j, iv_len;
  115. const char *key, iv[128];
  116. struct crypto_blkcipher *tfm;
  117. struct blkcipher_desc desc;
  118. const char *e;
  119. u32 *b_size;
  120. if (enc == ENCRYPT)
  121. e = "encryption";
  122. else
  123. e = "decryption";
  124. printk("\ntesting speed of %s %s\n", algo, e);
  125. tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
  126. if (IS_ERR(tfm)) {
  127. printk("failed to load transform for %s: %ld\n", algo,
  128. PTR_ERR(tfm));
  129. return;
  130. }
  131. desc.tfm = tfm;
  132. desc.flags = 0;
  133. i = 0;
  134. do {
  135. b_size = block_sizes;
  136. do {
  137. struct scatterlist sg[TVMEMSIZE];
  138. if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
  139. printk("template (%u) too big for "
  140. "tvmem (%lu)\n", *keysize + *b_size,
  141. TVMEMSIZE * PAGE_SIZE);
  142. goto out;
  143. }
  144. printk("test %u (%d bit key, %d byte blocks): ", i,
  145. *keysize * 8, *b_size);
  146. memset(tvmem[0], 0xff, PAGE_SIZE);
  147. /* set key, plain text and IV */
  148. key = tvmem[0];
  149. for (j = 0; j < tcount; j++) {
  150. if (template[j].klen == *keysize) {
  151. key = template[j].key;
  152. break;
  153. }
  154. }
  155. ret = crypto_blkcipher_setkey(tfm, key, *keysize);
  156. if (ret) {
  157. printk("setkey() failed flags=%x\n",
  158. crypto_blkcipher_get_flags(tfm));
  159. goto out;
  160. }
  161. sg_init_table(sg, TVMEMSIZE);
  162. sg_set_buf(sg, tvmem[0] + *keysize,
  163. PAGE_SIZE - *keysize);
  164. for (j = 1; j < TVMEMSIZE; j++) {
  165. sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
  166. memset (tvmem[j], 0xff, PAGE_SIZE);
  167. }
  168. iv_len = crypto_blkcipher_ivsize(tfm);
  169. if (iv_len) {
  170. memset(&iv, 0xff, iv_len);
  171. crypto_blkcipher_set_iv(tfm, iv, iv_len);
  172. }
  173. if (sec)
  174. ret = test_cipher_jiffies(&desc, enc, sg,
  175. *b_size, sec);
  176. else
  177. ret = test_cipher_cycles(&desc, enc, sg,
  178. *b_size);
  179. if (ret) {
  180. printk("%s() failed flags=%x\n", e, desc.flags);
  181. break;
  182. }
  183. b_size++;
  184. i++;
  185. } while (*b_size);
  186. keysize++;
  187. } while (*keysize);
  188. out:
  189. crypto_free_blkcipher(tfm);
  190. }
  191. static int test_hash_jiffies_digest(struct hash_desc *desc,
  192. struct scatterlist *sg, int blen,
  193. char *out, int sec)
  194. {
  195. unsigned long start, end;
  196. int bcount;
  197. int ret;
  198. for (start = jiffies, end = start + sec * HZ, bcount = 0;
  199. time_before(jiffies, end); bcount++) {
  200. ret = crypto_hash_digest(desc, sg, blen, out);
  201. if (ret)
  202. return ret;
  203. }
  204. printk("%6u opers/sec, %9lu bytes/sec\n",
  205. bcount / sec, ((long)bcount * blen) / sec);
  206. return 0;
  207. }
  208. static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg,
  209. int blen, int plen, char *out, int sec)
  210. {
  211. unsigned long start, end;
  212. int bcount, pcount;
  213. int ret;
  214. if (plen == blen)
  215. return test_hash_jiffies_digest(desc, sg, blen, out, sec);
  216. for (start = jiffies, end = start + sec * HZ, bcount = 0;
  217. time_before(jiffies, end); bcount++) {
  218. ret = crypto_hash_init(desc);
  219. if (ret)
  220. return ret;
  221. for (pcount = 0; pcount < blen; pcount += plen) {
  222. ret = crypto_hash_update(desc, sg, plen);
  223. if (ret)
  224. return ret;
  225. }
  226. /* we assume there is enough space in 'out' for the result */
  227. ret = crypto_hash_final(desc, out);
  228. if (ret)
  229. return ret;
  230. }
  231. printk("%6u opers/sec, %9lu bytes/sec\n",
  232. bcount / sec, ((long)bcount * blen) / sec);
  233. return 0;
  234. }
  235. static int test_hash_cycles_digest(struct hash_desc *desc,
  236. struct scatterlist *sg, int blen, char *out)
  237. {
  238. unsigned long cycles = 0;
  239. int i;
  240. int ret;
  241. local_bh_disable();
  242. local_irq_disable();
  243. /* Warm-up run. */
  244. for (i = 0; i < 4; i++) {
  245. ret = crypto_hash_digest(desc, sg, blen, out);
  246. if (ret)
  247. goto out;
  248. }
  249. /* The real thing. */
  250. for (i = 0; i < 8; i++) {
  251. cycles_t start, end;
  252. start = get_cycles();
  253. ret = crypto_hash_digest(desc, sg, blen, out);
  254. if (ret)
  255. goto out;
  256. end = get_cycles();
  257. cycles += end - start;
  258. }
  259. out:
  260. local_irq_enable();
  261. local_bh_enable();
  262. if (ret)
  263. return ret;
  264. printk("%6lu cycles/operation, %4lu cycles/byte\n",
  265. cycles / 8, cycles / (8 * blen));
  266. return 0;
  267. }
  268. static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg,
  269. int blen, int plen, char *out)
  270. {
  271. unsigned long cycles = 0;
  272. int i, pcount;
  273. int ret;
  274. if (plen == blen)
  275. return test_hash_cycles_digest(desc, sg, blen, out);
  276. local_bh_disable();
  277. local_irq_disable();
  278. /* Warm-up run. */
  279. for (i = 0; i < 4; i++) {
  280. ret = crypto_hash_init(desc);
  281. if (ret)
  282. goto out;
  283. for (pcount = 0; pcount < blen; pcount += plen) {
  284. ret = crypto_hash_update(desc, sg, plen);
  285. if (ret)
  286. goto out;
  287. }
  288. ret = crypto_hash_final(desc, out);
  289. if (ret)
  290. goto out;
  291. }
  292. /* The real thing. */
  293. for (i = 0; i < 8; i++) {
  294. cycles_t start, end;
  295. start = get_cycles();
  296. ret = crypto_hash_init(desc);
  297. if (ret)
  298. goto out;
  299. for (pcount = 0; pcount < blen; pcount += plen) {
  300. ret = crypto_hash_update(desc, sg, plen);
  301. if (ret)
  302. goto out;
  303. }
  304. ret = crypto_hash_final(desc, out);
  305. if (ret)
  306. goto out;
  307. end = get_cycles();
  308. cycles += end - start;
  309. }
  310. out:
  311. local_irq_enable();
  312. local_bh_enable();
  313. if (ret)
  314. return ret;
  315. printk("%6lu cycles/operation, %4lu cycles/byte\n",
  316. cycles / 8, cycles / (8 * blen));
  317. return 0;
  318. }
  319. static void test_hash_speed(const char *algo, unsigned int sec,
  320. struct hash_speed *speed)
  321. {
  322. struct scatterlist sg[TVMEMSIZE];
  323. struct crypto_hash *tfm;
  324. struct hash_desc desc;
  325. static char output[1024];
  326. int i;
  327. int ret;
  328. printk(KERN_INFO "\ntesting speed of %s\n", algo);
  329. tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
  330. if (IS_ERR(tfm)) {
  331. printk(KERN_ERR "failed to load transform for %s: %ld\n", algo,
  332. PTR_ERR(tfm));
  333. return;
  334. }
  335. desc.tfm = tfm;
  336. desc.flags = 0;
  337. if (crypto_hash_digestsize(tfm) > sizeof(output)) {
  338. printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n",
  339. crypto_hash_digestsize(tfm), sizeof(output));
  340. goto out;
  341. }
  342. sg_init_table(sg, TVMEMSIZE);
  343. for (i = 0; i < TVMEMSIZE; i++) {
  344. sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
  345. memset(tvmem[i], 0xff, PAGE_SIZE);
  346. }
  347. for (i = 0; speed[i].blen != 0; i++) {
  348. if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
  349. printk(KERN_ERR
  350. "template (%u) too big for tvmem (%lu)\n",
  351. speed[i].blen, TVMEMSIZE * PAGE_SIZE);
  352. goto out;
  353. }
  354. printk(KERN_INFO "test%3u "
  355. "(%5u byte blocks,%5u bytes per update,%4u updates): ",
  356. i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
  357. if (sec)
  358. ret = test_hash_jiffies(&desc, sg, speed[i].blen,
  359. speed[i].plen, output, sec);
  360. else
  361. ret = test_hash_cycles(&desc, sg, speed[i].blen,
  362. speed[i].plen, output);
  363. if (ret) {
  364. printk(KERN_ERR "hashing failed ret=%d\n", ret);
  365. break;
  366. }
  367. }
  368. out:
  369. crypto_free_hash(tfm);
  370. }
  371. static void test_available(void)
  372. {
  373. char **name = check;
  374. while (*name) {
  375. printk("alg %s ", *name);
  376. printk(crypto_has_alg(*name, 0, 0) ?
  377. "found\n" : "not found\n");
  378. name++;
  379. }
  380. }
  381. static inline int tcrypt_test(const char *alg)
  382. {
  383. return alg_test(alg, alg, 0, 0);
  384. }
  385. static void do_test(int m)
  386. {
  387. int i;
  388. switch (m) {
  389. case 0:
  390. for (i = 1; i < 200; i++)
  391. do_test(i);
  392. break;
  393. case 1:
  394. tcrypt_test("md5");
  395. break;
  396. case 2:
  397. tcrypt_test("sha1");
  398. break;
  399. case 3:
  400. tcrypt_test("ecb(des)");
  401. tcrypt_test("cbc(des)");
  402. break;
  403. case 4:
  404. tcrypt_test("ecb(des3_ede)");
  405. tcrypt_test("cbc(des3_ede)");
  406. break;
  407. case 5:
  408. tcrypt_test("md4");
  409. break;
  410. case 6:
  411. tcrypt_test("sha256");
  412. break;
  413. case 7:
  414. tcrypt_test("ecb(blowfish)");
  415. tcrypt_test("cbc(blowfish)");
  416. break;
  417. case 8:
  418. tcrypt_test("ecb(twofish)");
  419. tcrypt_test("cbc(twofish)");
  420. break;
  421. case 9:
  422. tcrypt_test("ecb(serpent)");
  423. break;
  424. case 10:
  425. tcrypt_test("ecb(aes)");
  426. tcrypt_test("cbc(aes)");
  427. tcrypt_test("lrw(aes)");
  428. tcrypt_test("xts(aes)");
  429. tcrypt_test("rfc3686(ctr(aes))");
  430. break;
  431. case 11:
  432. tcrypt_test("sha384");
  433. break;
  434. case 12:
  435. tcrypt_test("sha512");
  436. break;
  437. case 13:
  438. tcrypt_test("deflate");
  439. break;
  440. case 14:
  441. tcrypt_test("ecb(cast5)");
  442. break;
  443. case 15:
  444. tcrypt_test("ecb(cast6)");
  445. break;
  446. case 16:
  447. tcrypt_test("ecb(arc4)");
  448. break;
  449. case 17:
  450. tcrypt_test("michael_mic");
  451. break;
  452. case 18:
  453. tcrypt_test("crc32c");
  454. break;
  455. case 19:
  456. tcrypt_test("ecb(tea)");
  457. break;
  458. case 20:
  459. tcrypt_test("ecb(xtea)");
  460. break;
  461. case 21:
  462. tcrypt_test("ecb(khazad)");
  463. break;
  464. case 22:
  465. tcrypt_test("wp512");
  466. break;
  467. case 23:
  468. tcrypt_test("wp384");
  469. break;
  470. case 24:
  471. tcrypt_test("wp256");
  472. break;
  473. case 25:
  474. tcrypt_test("ecb(tnepres)");
  475. break;
  476. case 26:
  477. tcrypt_test("ecb(anubis)");
  478. tcrypt_test("cbc(anubis)");
  479. break;
  480. case 27:
  481. tcrypt_test("tgr192");
  482. break;
  483. case 28:
  484. tcrypt_test("tgr160");
  485. break;
  486. case 29:
  487. tcrypt_test("tgr128");
  488. break;
  489. case 30:
  490. tcrypt_test("ecb(xeta)");
  491. break;
  492. case 31:
  493. tcrypt_test("pcbc(fcrypt)");
  494. break;
  495. case 32:
  496. tcrypt_test("ecb(camellia)");
  497. tcrypt_test("cbc(camellia)");
  498. break;
  499. case 33:
  500. tcrypt_test("sha224");
  501. break;
  502. case 34:
  503. tcrypt_test("salsa20");
  504. break;
  505. case 35:
  506. tcrypt_test("gcm(aes)");
  507. break;
  508. case 36:
  509. tcrypt_test("lzo");
  510. break;
  511. case 37:
  512. tcrypt_test("ccm(aes)");
  513. break;
  514. case 38:
  515. tcrypt_test("cts(cbc(aes))");
  516. break;
  517. case 39:
  518. tcrypt_test("rmd128");
  519. break;
  520. case 40:
  521. tcrypt_test("rmd160");
  522. break;
  523. case 41:
  524. tcrypt_test("rmd256");
  525. break;
  526. case 42:
  527. tcrypt_test("rmd320");
  528. break;
  529. case 43:
  530. tcrypt_test("ecb(seed)");
  531. break;
  532. case 44:
  533. tcrypt_test("zlib");
  534. break;
  535. case 100:
  536. tcrypt_test("hmac(md5)");
  537. break;
  538. case 101:
  539. tcrypt_test("hmac(sha1)");
  540. break;
  541. case 102:
  542. tcrypt_test("hmac(sha256)");
  543. break;
  544. case 103:
  545. tcrypt_test("hmac(sha384)");
  546. break;
  547. case 104:
  548. tcrypt_test("hmac(sha512)");
  549. break;
  550. case 105:
  551. tcrypt_test("hmac(sha224)");
  552. break;
  553. case 106:
  554. tcrypt_test("xcbc(aes)");
  555. break;
  556. case 107:
  557. tcrypt_test("hmac(rmd128)");
  558. break;
  559. case 108:
  560. tcrypt_test("hmac(rmd160)");
  561. break;
  562. case 200:
  563. test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
  564. speed_template_16_24_32);
  565. test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
  566. speed_template_16_24_32);
  567. test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
  568. speed_template_16_24_32);
  569. test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
  570. speed_template_16_24_32);
  571. test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
  572. speed_template_32_40_48);
  573. test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
  574. speed_template_32_40_48);
  575. test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
  576. speed_template_32_48_64);
  577. test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
  578. speed_template_32_48_64);
  579. break;
  580. case 201:
  581. test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
  582. des3_speed_template, DES3_SPEED_VECTORS,
  583. speed_template_24);
  584. test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
  585. des3_speed_template, DES3_SPEED_VECTORS,
  586. speed_template_24);
  587. test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
  588. des3_speed_template, DES3_SPEED_VECTORS,
  589. speed_template_24);
  590. test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
  591. des3_speed_template, DES3_SPEED_VECTORS,
  592. speed_template_24);
  593. break;
  594. case 202:
  595. test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
  596. speed_template_16_24_32);
  597. test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
  598. speed_template_16_24_32);
  599. test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
  600. speed_template_16_24_32);
  601. test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
  602. speed_template_16_24_32);
  603. break;
  604. case 203:
  605. test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
  606. speed_template_8_32);
  607. test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
  608. speed_template_8_32);
  609. test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
  610. speed_template_8_32);
  611. test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
  612. speed_template_8_32);
  613. break;
  614. case 204:
  615. test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
  616. speed_template_8);
  617. test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
  618. speed_template_8);
  619. test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
  620. speed_template_8);
  621. test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
  622. speed_template_8);
  623. break;
  624. case 205:
  625. test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
  626. speed_template_16_24_32);
  627. test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
  628. speed_template_16_24_32);
  629. test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
  630. speed_template_16_24_32);
  631. test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
  632. speed_template_16_24_32);
  633. break;
  634. case 206:
  635. test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
  636. speed_template_16_32);
  637. break;
  638. case 300:
  639. /* fall through */
  640. case 301:
  641. test_hash_speed("md4", sec, generic_hash_speed_template);
  642. if (mode > 300 && mode < 400) break;
  643. case 302:
  644. test_hash_speed("md5", sec, generic_hash_speed_template);
  645. if (mode > 300 && mode < 400) break;
  646. case 303:
  647. test_hash_speed("sha1", sec, generic_hash_speed_template);
  648. if (mode > 300 && mode < 400) break;
  649. case 304:
  650. test_hash_speed("sha256", sec, generic_hash_speed_template);
  651. if (mode > 300 && mode < 400) break;
  652. case 305:
  653. test_hash_speed("sha384", sec, generic_hash_speed_template);
  654. if (mode > 300 && mode < 400) break;
  655. case 306:
  656. test_hash_speed("sha512", sec, generic_hash_speed_template);
  657. if (mode > 300 && mode < 400) break;
  658. case 307:
  659. test_hash_speed("wp256", sec, generic_hash_speed_template);
  660. if (mode > 300 && mode < 400) break;
  661. case 308:
  662. test_hash_speed("wp384", sec, generic_hash_speed_template);
  663. if (mode > 300 && mode < 400) break;
  664. case 309:
  665. test_hash_speed("wp512", sec, generic_hash_speed_template);
  666. if (mode > 300 && mode < 400) break;
  667. case 310:
  668. test_hash_speed("tgr128", sec, generic_hash_speed_template);
  669. if (mode > 300 && mode < 400) break;
  670. case 311:
  671. test_hash_speed("tgr160", sec, generic_hash_speed_template);
  672. if (mode > 300 && mode < 400) break;
  673. case 312:
  674. test_hash_speed("tgr192", sec, generic_hash_speed_template);
  675. if (mode > 300 && mode < 400) break;
  676. case 313:
  677. test_hash_speed("sha224", sec, generic_hash_speed_template);
  678. if (mode > 300 && mode < 400) break;
  679. case 314:
  680. test_hash_speed("rmd128", sec, generic_hash_speed_template);
  681. if (mode > 300 && mode < 400) break;
  682. case 315:
  683. test_hash_speed("rmd160", sec, generic_hash_speed_template);
  684. if (mode > 300 && mode < 400) break;
  685. case 316:
  686. test_hash_speed("rmd256", sec, generic_hash_speed_template);
  687. if (mode > 300 && mode < 400) break;
  688. case 317:
  689. test_hash_speed("rmd320", sec, generic_hash_speed_template);
  690. if (mode > 300 && mode < 400) break;
  691. case 399:
  692. break;
  693. case 1000:
  694. test_available();
  695. break;
  696. }
  697. }
  698. static int __init tcrypt_mod_init(void)
  699. {
  700. int err = -ENOMEM;
  701. int i;
  702. for (i = 0; i < TVMEMSIZE; i++) {
  703. tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
  704. if (!tvmem[i])
  705. goto err_free_tv;
  706. }
  707. do_test(mode);
  708. /* We intentionaly return -EAGAIN to prevent keeping
  709. * the module. It does all its work from init()
  710. * and doesn't offer any runtime functionality
  711. * => we don't need it in the memory, do we?
  712. * -- mludvig
  713. */
  714. err = -EAGAIN;
  715. err_free_tv:
  716. for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
  717. free_page((unsigned long)tvmem[i]);
  718. return err;
  719. }
  720. /*
  721. * If an init function is provided, an exit function must also be provided
  722. * to allow module unload.
  723. */
  724. static void __exit tcrypt_mod_fini(void) { }
  725. module_init(tcrypt_mod_init);
  726. module_exit(tcrypt_mod_fini);
  727. module_param(mode, int, 0);
  728. module_param(sec, uint, 0);
  729. MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
  730. "(defaults to zero which uses CPU cycles instead)");
  731. MODULE_LICENSE("GPL");
  732. MODULE_DESCRIPTION("Quick & dirty crypto testing module");
  733. MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");