tcrypt.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911
  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. char output[1024];
  326. int i;
  327. int ret;
  328. printk("\ntesting speed of %s\n", algo);
  329. tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
  330. if (IS_ERR(tfm)) {
  331. printk("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("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("template (%u) too big for tvmem (%lu)\n",
  350. speed[i].blen, TVMEMSIZE * PAGE_SIZE);
  351. goto out;
  352. }
  353. printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
  354. i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
  355. if (sec)
  356. ret = test_hash_jiffies(&desc, sg, speed[i].blen,
  357. speed[i].plen, output, sec);
  358. else
  359. ret = test_hash_cycles(&desc, sg, speed[i].blen,
  360. speed[i].plen, output);
  361. if (ret) {
  362. printk("hashing failed ret=%d\n", ret);
  363. break;
  364. }
  365. }
  366. out:
  367. crypto_free_hash(tfm);
  368. }
  369. static void test_available(void)
  370. {
  371. char **name = check;
  372. while (*name) {
  373. printk("alg %s ", *name);
  374. printk(crypto_has_alg(*name, 0, 0) ?
  375. "found\n" : "not found\n");
  376. name++;
  377. }
  378. }
  379. static inline int tcrypt_test(const char *alg)
  380. {
  381. return alg_test(alg, alg, 0, 0);
  382. }
  383. static void do_test(int m)
  384. {
  385. int i;
  386. switch (m) {
  387. case 0:
  388. for (i = 1; i < 200; i++)
  389. do_test(i);
  390. break;
  391. case 1:
  392. tcrypt_test("md5");
  393. break;
  394. case 2:
  395. tcrypt_test("sha1");
  396. break;
  397. case 3:
  398. tcrypt_test("ecb(des)");
  399. tcrypt_test("cbc(des)");
  400. break;
  401. case 4:
  402. tcrypt_test("ecb(des3_ede)");
  403. tcrypt_test("cbc(des3_ede)");
  404. break;
  405. case 5:
  406. tcrypt_test("md4");
  407. break;
  408. case 6:
  409. tcrypt_test("sha256");
  410. break;
  411. case 7:
  412. tcrypt_test("ecb(blowfish)");
  413. tcrypt_test("cbc(blowfish)");
  414. break;
  415. case 8:
  416. tcrypt_test("ecb(twofish)");
  417. tcrypt_test("cbc(twofish)");
  418. break;
  419. case 9:
  420. tcrypt_test("ecb(serpent)");
  421. break;
  422. case 10:
  423. tcrypt_test("ecb(aes)");
  424. tcrypt_test("cbc(aes)");
  425. tcrypt_test("lrw(aes)");
  426. tcrypt_test("xts(aes)");
  427. tcrypt_test("rfc3686(ctr(aes))");
  428. break;
  429. case 11:
  430. tcrypt_test("sha384");
  431. break;
  432. case 12:
  433. tcrypt_test("sha512");
  434. break;
  435. case 13:
  436. tcrypt_test("deflate");
  437. break;
  438. case 14:
  439. tcrypt_test("ecb(cast5)");
  440. break;
  441. case 15:
  442. tcrypt_test("ecb(cast6)");
  443. break;
  444. case 16:
  445. tcrypt_test("ecb(arc4)");
  446. break;
  447. case 17:
  448. tcrypt_test("michael_mic");
  449. break;
  450. case 18:
  451. tcrypt_test("crc32c");
  452. break;
  453. case 19:
  454. tcrypt_test("ecb(tea)");
  455. break;
  456. case 20:
  457. tcrypt_test("ecb(xtea)");
  458. break;
  459. case 21:
  460. tcrypt_test("ecb(khazad)");
  461. break;
  462. case 22:
  463. tcrypt_test("wp512");
  464. break;
  465. case 23:
  466. tcrypt_test("wp384");
  467. break;
  468. case 24:
  469. tcrypt_test("wp256");
  470. break;
  471. case 25:
  472. tcrypt_test("ecb(tnepres)");
  473. break;
  474. case 26:
  475. tcrypt_test("ecb(anubis)");
  476. tcrypt_test("cbc(anubis)");
  477. break;
  478. case 27:
  479. tcrypt_test("tgr192");
  480. break;
  481. case 28:
  482. tcrypt_test("tgr160");
  483. break;
  484. case 29:
  485. tcrypt_test("tgr128");
  486. break;
  487. case 30:
  488. tcrypt_test("ecb(xeta)");
  489. break;
  490. case 31:
  491. tcrypt_test("pcbc(fcrypt)");
  492. break;
  493. case 32:
  494. tcrypt_test("ecb(camellia)");
  495. tcrypt_test("cbc(camellia)");
  496. break;
  497. case 33:
  498. tcrypt_test("sha224");
  499. break;
  500. case 34:
  501. tcrypt_test("salsa20");
  502. break;
  503. case 35:
  504. tcrypt_test("gcm(aes)");
  505. break;
  506. case 36:
  507. tcrypt_test("lzo");
  508. break;
  509. case 37:
  510. tcrypt_test("ccm(aes)");
  511. break;
  512. case 38:
  513. tcrypt_test("cts(cbc(aes))");
  514. break;
  515. case 39:
  516. tcrypt_test("rmd128");
  517. break;
  518. case 40:
  519. tcrypt_test("rmd160");
  520. break;
  521. case 41:
  522. tcrypt_test("rmd256");
  523. break;
  524. case 42:
  525. tcrypt_test("rmd320");
  526. break;
  527. case 43:
  528. tcrypt_test("ecb(seed)");
  529. break;
  530. case 44:
  531. tcrypt_test("zlib");
  532. break;
  533. case 100:
  534. tcrypt_test("hmac(md5)");
  535. break;
  536. case 101:
  537. tcrypt_test("hmac(sha1)");
  538. break;
  539. case 102:
  540. tcrypt_test("hmac(sha256)");
  541. break;
  542. case 103:
  543. tcrypt_test("hmac(sha384)");
  544. break;
  545. case 104:
  546. tcrypt_test("hmac(sha512)");
  547. break;
  548. case 105:
  549. tcrypt_test("hmac(sha224)");
  550. break;
  551. case 106:
  552. tcrypt_test("xcbc(aes)");
  553. break;
  554. case 107:
  555. tcrypt_test("hmac(rmd128)");
  556. break;
  557. case 108:
  558. tcrypt_test("hmac(rmd160)");
  559. break;
  560. case 200:
  561. test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
  562. speed_template_16_24_32);
  563. test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
  564. speed_template_16_24_32);
  565. test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
  566. speed_template_16_24_32);
  567. test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
  568. speed_template_16_24_32);
  569. test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
  570. speed_template_32_40_48);
  571. test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
  572. speed_template_32_40_48);
  573. test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
  574. speed_template_32_48_64);
  575. test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
  576. speed_template_32_48_64);
  577. break;
  578. case 201:
  579. test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
  580. des3_speed_template, DES3_SPEED_VECTORS,
  581. speed_template_24);
  582. test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
  583. des3_speed_template, DES3_SPEED_VECTORS,
  584. speed_template_24);
  585. test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
  586. des3_speed_template, DES3_SPEED_VECTORS,
  587. speed_template_24);
  588. test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
  589. des3_speed_template, DES3_SPEED_VECTORS,
  590. speed_template_24);
  591. break;
  592. case 202:
  593. test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
  594. speed_template_16_24_32);
  595. test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
  596. speed_template_16_24_32);
  597. test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
  598. speed_template_16_24_32);
  599. test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
  600. speed_template_16_24_32);
  601. break;
  602. case 203:
  603. test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
  604. speed_template_8_32);
  605. test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
  606. speed_template_8_32);
  607. test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
  608. speed_template_8_32);
  609. test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
  610. speed_template_8_32);
  611. break;
  612. case 204:
  613. test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
  614. speed_template_8);
  615. test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
  616. speed_template_8);
  617. test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
  618. speed_template_8);
  619. test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
  620. speed_template_8);
  621. break;
  622. case 205:
  623. test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
  624. speed_template_16_24_32);
  625. test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
  626. speed_template_16_24_32);
  627. test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
  628. speed_template_16_24_32);
  629. test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
  630. speed_template_16_24_32);
  631. break;
  632. case 206:
  633. test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
  634. speed_template_16_32);
  635. break;
  636. case 300:
  637. /* fall through */
  638. case 301:
  639. test_hash_speed("md4", sec, generic_hash_speed_template);
  640. if (mode > 300 && mode < 400) break;
  641. case 302:
  642. test_hash_speed("md5", sec, generic_hash_speed_template);
  643. if (mode > 300 && mode < 400) break;
  644. case 303:
  645. test_hash_speed("sha1", sec, generic_hash_speed_template);
  646. if (mode > 300 && mode < 400) break;
  647. case 304:
  648. test_hash_speed("sha256", sec, generic_hash_speed_template);
  649. if (mode > 300 && mode < 400) break;
  650. case 305:
  651. test_hash_speed("sha384", sec, generic_hash_speed_template);
  652. if (mode > 300 && mode < 400) break;
  653. case 306:
  654. test_hash_speed("sha512", sec, generic_hash_speed_template);
  655. if (mode > 300 && mode < 400) break;
  656. case 307:
  657. test_hash_speed("wp256", sec, generic_hash_speed_template);
  658. if (mode > 300 && mode < 400) break;
  659. case 308:
  660. test_hash_speed("wp384", sec, generic_hash_speed_template);
  661. if (mode > 300 && mode < 400) break;
  662. case 309:
  663. test_hash_speed("wp512", sec, generic_hash_speed_template);
  664. if (mode > 300 && mode < 400) break;
  665. case 310:
  666. test_hash_speed("tgr128", sec, generic_hash_speed_template);
  667. if (mode > 300 && mode < 400) break;
  668. case 311:
  669. test_hash_speed("tgr160", sec, generic_hash_speed_template);
  670. if (mode > 300 && mode < 400) break;
  671. case 312:
  672. test_hash_speed("tgr192", sec, generic_hash_speed_template);
  673. if (mode > 300 && mode < 400) break;
  674. case 313:
  675. test_hash_speed("sha224", sec, generic_hash_speed_template);
  676. if (mode > 300 && mode < 400) break;
  677. case 314:
  678. test_hash_speed("rmd128", sec, generic_hash_speed_template);
  679. if (mode > 300 && mode < 400) break;
  680. case 315:
  681. test_hash_speed("rmd160", sec, generic_hash_speed_template);
  682. if (mode > 300 && mode < 400) break;
  683. case 316:
  684. test_hash_speed("rmd256", sec, generic_hash_speed_template);
  685. if (mode > 300 && mode < 400) break;
  686. case 317:
  687. test_hash_speed("rmd320", sec, generic_hash_speed_template);
  688. if (mode > 300 && mode < 400) break;
  689. case 399:
  690. break;
  691. case 1000:
  692. test_available();
  693. break;
  694. }
  695. }
  696. static int __init tcrypt_mod_init(void)
  697. {
  698. int err = -ENOMEM;
  699. int i;
  700. for (i = 0; i < TVMEMSIZE; i++) {
  701. tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
  702. if (!tvmem[i])
  703. goto err_free_tv;
  704. }
  705. do_test(mode);
  706. /* We intentionaly return -EAGAIN to prevent keeping
  707. * the module. It does all its work from init()
  708. * and doesn't offer any runtime functionality
  709. * => we don't need it in the memory, do we?
  710. * -- mludvig
  711. */
  712. err = -EAGAIN;
  713. err_free_tv:
  714. for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
  715. free_page((unsigned long)tvmem[i]);
  716. return err;
  717. }
  718. /*
  719. * If an init function is provided, an exit function must also be provided
  720. * to allow module unload.
  721. */
  722. static void __exit tcrypt_mod_fini(void) { }
  723. module_init(tcrypt_mod_init);
  724. module_exit(tcrypt_mod_fini);
  725. module_param(mode, int, 0);
  726. module_param(sec, uint, 0);
  727. MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
  728. "(defaults to zero which uses CPU cycles instead)");
  729. MODULE_LICENSE("GPL");
  730. MODULE_DESCRIPTION("Quick & dirty crypto testing module");
  731. MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");