tcrypt.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135
  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. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the Free
  12. * Software Foundation; either version 2 of the License, or (at your option)
  13. * any later version.
  14. *
  15. * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>)
  16. * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt
  17. *
  18. */
  19. #include <linux/init.h>
  20. #include <linux/module.h>
  21. #include <linux/mm.h>
  22. #include <linux/slab.h>
  23. #include <linux/scatterlist.h>
  24. #include <linux/string.h>
  25. #include <linux/crypto.h>
  26. #include <linux/highmem.h>
  27. #include <linux/moduleparam.h>
  28. #include <linux/jiffies.h>
  29. #include <linux/timex.h>
  30. #include <linux/interrupt.h>
  31. #include "tcrypt.h"
  32. /*
  33. * Need to kmalloc() memory for testing kmap().
  34. */
  35. #define TVMEMSIZE 16384
  36. #define XBUFSIZE 32768
  37. /*
  38. * Indexes into the xbuf to simulate cross-page access.
  39. */
  40. #define IDX1 37
  41. #define IDX2 32400
  42. #define IDX3 1
  43. #define IDX4 8193
  44. #define IDX5 22222
  45. #define IDX6 17101
  46. #define IDX7 27333
  47. #define IDX8 3000
  48. /*
  49. * Used by test_cipher()
  50. */
  51. #define ENCRYPT 1
  52. #define DECRYPT 0
  53. #define MODE_ECB 1
  54. #define MODE_CBC 0
  55. static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
  56. /*
  57. * Used by test_cipher_speed()
  58. */
  59. static unsigned int sec;
  60. static int mode;
  61. static char *xbuf;
  62. static char *tvmem;
  63. static char *check[] = {
  64. "des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish",
  65. "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6",
  66. "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
  67. "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", NULL
  68. };
  69. static void hexdump(unsigned char *buf, unsigned int len)
  70. {
  71. while (len--)
  72. printk("%02x", *buf++);
  73. printk("\n");
  74. }
  75. static void test_hash(char *algo, struct hash_testvec *template,
  76. unsigned int tcount)
  77. {
  78. unsigned int i, j, k, temp;
  79. struct scatterlist sg[8];
  80. char result[64];
  81. struct crypto_tfm *tfm;
  82. struct hash_testvec *hash_tv;
  83. unsigned int tsize;
  84. printk("\ntesting %s\n", algo);
  85. tsize = sizeof(struct hash_testvec);
  86. tsize *= tcount;
  87. if (tsize > TVMEMSIZE) {
  88. printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE);
  89. return;
  90. }
  91. memcpy(tvmem, template, tsize);
  92. hash_tv = (void *)tvmem;
  93. tfm = crypto_alloc_tfm(algo, 0);
  94. if (tfm == NULL) {
  95. printk("failed to load transform for %s\n", algo);
  96. return;
  97. }
  98. for (i = 0; i < tcount; i++) {
  99. printk("test %u:\n", i + 1);
  100. memset(result, 0, 64);
  101. sg_set_buf(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize);
  102. crypto_digest_init(tfm);
  103. if (tfm->crt_u.digest.dit_setkey) {
  104. crypto_digest_setkey(tfm, hash_tv[i].key,
  105. hash_tv[i].ksize);
  106. }
  107. crypto_digest_update(tfm, sg, 1);
  108. crypto_digest_final(tfm, result);
  109. hexdump(result, crypto_tfm_alg_digestsize(tfm));
  110. printk("%s\n",
  111. memcmp(result, hash_tv[i].digest,
  112. crypto_tfm_alg_digestsize(tfm)) ?
  113. "fail" : "pass");
  114. }
  115. printk("testing %s across pages\n", algo);
  116. /* setup the dummy buffer first */
  117. memset(xbuf, 0, XBUFSIZE);
  118. j = 0;
  119. for (i = 0; i < tcount; i++) {
  120. if (hash_tv[i].np) {
  121. j++;
  122. printk("test %u:\n", j);
  123. memset(result, 0, 64);
  124. temp = 0;
  125. for (k = 0; k < hash_tv[i].np; k++) {
  126. memcpy(&xbuf[IDX[k]],
  127. hash_tv[i].plaintext + temp,
  128. hash_tv[i].tap[k]);
  129. temp += hash_tv[i].tap[k];
  130. sg_set_buf(&sg[k], &xbuf[IDX[k]],
  131. hash_tv[i].tap[k]);
  132. }
  133. crypto_digest_digest(tfm, sg, hash_tv[i].np, result);
  134. hexdump(result, crypto_tfm_alg_digestsize(tfm));
  135. printk("%s\n",
  136. memcmp(result, hash_tv[i].digest,
  137. crypto_tfm_alg_digestsize(tfm)) ?
  138. "fail" : "pass");
  139. }
  140. }
  141. crypto_free_tfm(tfm);
  142. }
  143. #ifdef CONFIG_CRYPTO_HMAC
  144. static void test_hmac(char *algo, struct hmac_testvec *template,
  145. unsigned int tcount)
  146. {
  147. unsigned int i, j, k, temp;
  148. struct scatterlist sg[8];
  149. char result[64];
  150. struct crypto_tfm *tfm;
  151. struct hmac_testvec *hmac_tv;
  152. unsigned int tsize, klen;
  153. tfm = crypto_alloc_tfm(algo, 0);
  154. if (tfm == NULL) {
  155. printk("failed to load transform for %s\n", algo);
  156. return;
  157. }
  158. printk("\ntesting hmac_%s\n", algo);
  159. tsize = sizeof(struct hmac_testvec);
  160. tsize *= tcount;
  161. if (tsize > TVMEMSIZE) {
  162. printk("template (%u) too big for tvmem (%u)\n", tsize,
  163. TVMEMSIZE);
  164. goto out;
  165. }
  166. memcpy(tvmem, template, tsize);
  167. hmac_tv = (void *)tvmem;
  168. for (i = 0; i < tcount; i++) {
  169. printk("test %u:\n", i + 1);
  170. memset(result, 0, sizeof (result));
  171. klen = hmac_tv[i].ksize;
  172. sg_set_buf(&sg[0], hmac_tv[i].plaintext, hmac_tv[i].psize);
  173. crypto_hmac(tfm, hmac_tv[i].key, &klen, sg, 1, result);
  174. hexdump(result, crypto_tfm_alg_digestsize(tfm));
  175. printk("%s\n",
  176. memcmp(result, hmac_tv[i].digest,
  177. crypto_tfm_alg_digestsize(tfm)) ? "fail" :
  178. "pass");
  179. }
  180. printk("\ntesting hmac_%s across pages\n", algo);
  181. memset(xbuf, 0, XBUFSIZE);
  182. j = 0;
  183. for (i = 0; i < tcount; i++) {
  184. if (hmac_tv[i].np) {
  185. j++;
  186. printk("test %u:\n",j);
  187. memset(result, 0, 64);
  188. temp = 0;
  189. klen = hmac_tv[i].ksize;
  190. for (k = 0; k < hmac_tv[i].np; k++) {
  191. memcpy(&xbuf[IDX[k]],
  192. hmac_tv[i].plaintext + temp,
  193. hmac_tv[i].tap[k]);
  194. temp += hmac_tv[i].tap[k];
  195. sg_set_buf(&sg[k], &xbuf[IDX[k]],
  196. hmac_tv[i].tap[k]);
  197. }
  198. crypto_hmac(tfm, hmac_tv[i].key, &klen, sg,
  199. hmac_tv[i].np, result);
  200. hexdump(result, crypto_tfm_alg_digestsize(tfm));
  201. printk("%s\n",
  202. memcmp(result, hmac_tv[i].digest,
  203. crypto_tfm_alg_digestsize(tfm)) ?
  204. "fail" : "pass");
  205. }
  206. }
  207. out:
  208. crypto_free_tfm(tfm);
  209. }
  210. #endif /* CONFIG_CRYPTO_HMAC */
  211. static void test_cipher(char *algo, int mode, int enc,
  212. struct cipher_testvec *template, unsigned int tcount)
  213. {
  214. unsigned int ret, i, j, k, temp;
  215. unsigned int tsize;
  216. char *q;
  217. struct crypto_tfm *tfm;
  218. char *key;
  219. struct cipher_testvec *cipher_tv;
  220. struct scatterlist sg[8];
  221. const char *e, *m;
  222. if (enc == ENCRYPT)
  223. e = "encryption";
  224. else
  225. e = "decryption";
  226. if (mode == MODE_ECB)
  227. m = "ECB";
  228. else
  229. m = "CBC";
  230. printk("\ntesting %s %s %s\n", algo, m, e);
  231. tsize = sizeof (struct cipher_testvec);
  232. tsize *= tcount;
  233. if (tsize > TVMEMSIZE) {
  234. printk("template (%u) too big for tvmem (%u)\n", tsize,
  235. TVMEMSIZE);
  236. return;
  237. }
  238. memcpy(tvmem, template, tsize);
  239. cipher_tv = (void *)tvmem;
  240. if (mode)
  241. tfm = crypto_alloc_tfm(algo, 0);
  242. else
  243. tfm = crypto_alloc_tfm(algo, CRYPTO_TFM_MODE_CBC);
  244. if (tfm == NULL) {
  245. printk("failed to load transform for %s %s\n", algo, m);
  246. return;
  247. }
  248. j = 0;
  249. for (i = 0; i < tcount; i++) {
  250. if (!(cipher_tv[i].np)) {
  251. j++;
  252. printk("test %u (%d bit key):\n",
  253. j, cipher_tv[i].klen * 8);
  254. tfm->crt_flags = 0;
  255. if (cipher_tv[i].wk)
  256. tfm->crt_flags |= CRYPTO_TFM_REQ_WEAK_KEY;
  257. key = cipher_tv[i].key;
  258. ret = crypto_cipher_setkey(tfm, key, cipher_tv[i].klen);
  259. if (ret) {
  260. printk("setkey() failed flags=%x\n", tfm->crt_flags);
  261. if (!cipher_tv[i].fail)
  262. goto out;
  263. }
  264. sg_set_buf(&sg[0], cipher_tv[i].input,
  265. cipher_tv[i].ilen);
  266. if (!mode) {
  267. crypto_cipher_set_iv(tfm, cipher_tv[i].iv,
  268. crypto_tfm_alg_ivsize(tfm));
  269. }
  270. if (enc)
  271. ret = crypto_cipher_encrypt(tfm, sg, sg, cipher_tv[i].ilen);
  272. else
  273. ret = crypto_cipher_decrypt(tfm, sg, sg, cipher_tv[i].ilen);
  274. if (ret) {
  275. printk("%s () failed flags=%x\n", e, tfm->crt_flags);
  276. goto out;
  277. }
  278. q = kmap(sg[0].page) + sg[0].offset;
  279. hexdump(q, cipher_tv[i].rlen);
  280. printk("%s\n",
  281. memcmp(q, cipher_tv[i].result,
  282. cipher_tv[i].rlen) ? "fail" : "pass");
  283. }
  284. }
  285. printk("\ntesting %s %s %s across pages (chunking)\n", algo, m, e);
  286. memset(xbuf, 0, XBUFSIZE);
  287. j = 0;
  288. for (i = 0; i < tcount; i++) {
  289. if (cipher_tv[i].np) {
  290. j++;
  291. printk("test %u (%d bit key):\n",
  292. j, cipher_tv[i].klen * 8);
  293. tfm->crt_flags = 0;
  294. if (cipher_tv[i].wk)
  295. tfm->crt_flags |= CRYPTO_TFM_REQ_WEAK_KEY;
  296. key = cipher_tv[i].key;
  297. ret = crypto_cipher_setkey(tfm, key, cipher_tv[i].klen);
  298. if (ret) {
  299. printk("setkey() failed flags=%x\n", tfm->crt_flags);
  300. if (!cipher_tv[i].fail)
  301. goto out;
  302. }
  303. temp = 0;
  304. for (k = 0; k < cipher_tv[i].np; k++) {
  305. memcpy(&xbuf[IDX[k]],
  306. cipher_tv[i].input + temp,
  307. cipher_tv[i].tap[k]);
  308. temp += cipher_tv[i].tap[k];
  309. sg_set_buf(&sg[k], &xbuf[IDX[k]],
  310. cipher_tv[i].tap[k]);
  311. }
  312. if (!mode) {
  313. crypto_cipher_set_iv(tfm, cipher_tv[i].iv,
  314. crypto_tfm_alg_ivsize(tfm));
  315. }
  316. if (enc)
  317. ret = crypto_cipher_encrypt(tfm, sg, sg, cipher_tv[i].ilen);
  318. else
  319. ret = crypto_cipher_decrypt(tfm, sg, sg, cipher_tv[i].ilen);
  320. if (ret) {
  321. printk("%s () failed flags=%x\n", e, tfm->crt_flags);
  322. goto out;
  323. }
  324. temp = 0;
  325. for (k = 0; k < cipher_tv[i].np; k++) {
  326. printk("page %u\n", k);
  327. q = kmap(sg[k].page) + sg[k].offset;
  328. hexdump(q, cipher_tv[i].tap[k]);
  329. printk("%s\n",
  330. memcmp(q, cipher_tv[i].result + temp,
  331. cipher_tv[i].tap[k]) ? "fail" :
  332. "pass");
  333. temp += cipher_tv[i].tap[k];
  334. }
  335. }
  336. }
  337. out:
  338. crypto_free_tfm(tfm);
  339. }
  340. static int test_cipher_jiffies(struct crypto_tfm *tfm, int enc, char *p,
  341. int blen, int sec)
  342. {
  343. struct scatterlist sg[1];
  344. unsigned long start, end;
  345. int bcount;
  346. int ret;
  347. sg_set_buf(sg, p, blen);
  348. for (start = jiffies, end = start + sec * HZ, bcount = 0;
  349. time_before(jiffies, end); bcount++) {
  350. if (enc)
  351. ret = crypto_cipher_encrypt(tfm, sg, sg, blen);
  352. else
  353. ret = crypto_cipher_decrypt(tfm, sg, sg, blen);
  354. if (ret)
  355. return ret;
  356. }
  357. printk("%d operations in %d seconds (%ld bytes)\n",
  358. bcount, sec, (long)bcount * blen);
  359. return 0;
  360. }
  361. static int test_cipher_cycles(struct crypto_tfm *tfm, int enc, char *p,
  362. int blen)
  363. {
  364. struct scatterlist sg[1];
  365. unsigned long cycles = 0;
  366. int ret = 0;
  367. int i;
  368. sg_set_buf(sg, p, blen);
  369. local_bh_disable();
  370. local_irq_disable();
  371. /* Warm-up run. */
  372. for (i = 0; i < 4; i++) {
  373. if (enc)
  374. ret = crypto_cipher_encrypt(tfm, sg, sg, blen);
  375. else
  376. ret = crypto_cipher_decrypt(tfm, sg, sg, blen);
  377. if (ret)
  378. goto out;
  379. }
  380. /* The real thing. */
  381. for (i = 0; i < 8; i++) {
  382. cycles_t start, end;
  383. start = get_cycles();
  384. if (enc)
  385. ret = crypto_cipher_encrypt(tfm, sg, sg, blen);
  386. else
  387. ret = crypto_cipher_decrypt(tfm, sg, sg, blen);
  388. end = get_cycles();
  389. if (ret)
  390. goto out;
  391. cycles += end - start;
  392. }
  393. out:
  394. local_irq_enable();
  395. local_bh_enable();
  396. if (ret == 0)
  397. printk("1 operation in %lu cycles (%d bytes)\n",
  398. (cycles + 4) / 8, blen);
  399. return ret;
  400. }
  401. static void test_cipher_speed(char *algo, int mode, int enc, unsigned int sec,
  402. struct cipher_testvec *template,
  403. unsigned int tcount, struct cipher_speed *speed)
  404. {
  405. unsigned int ret, i, j, iv_len;
  406. unsigned char *key, *p, iv[128];
  407. struct crypto_tfm *tfm;
  408. const char *e, *m;
  409. if (enc == ENCRYPT)
  410. e = "encryption";
  411. else
  412. e = "decryption";
  413. if (mode == MODE_ECB)
  414. m = "ECB";
  415. else
  416. m = "CBC";
  417. printk("\ntesting speed of %s %s %s\n", algo, m, e);
  418. if (mode)
  419. tfm = crypto_alloc_tfm(algo, 0);
  420. else
  421. tfm = crypto_alloc_tfm(algo, CRYPTO_TFM_MODE_CBC);
  422. if (tfm == NULL) {
  423. printk("failed to load transform for %s %s\n", algo, m);
  424. return;
  425. }
  426. for (i = 0; speed[i].klen != 0; i++) {
  427. if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) {
  428. printk("template (%u) too big for tvmem (%u)\n",
  429. speed[i].blen + speed[i].klen, TVMEMSIZE);
  430. goto out;
  431. }
  432. printk("test %u (%d bit key, %d byte blocks): ", i,
  433. speed[i].klen * 8, speed[i].blen);
  434. memset(tvmem, 0xff, speed[i].klen + speed[i].blen);
  435. /* set key, plain text and IV */
  436. key = (unsigned char *)tvmem;
  437. for (j = 0; j < tcount; j++) {
  438. if (template[j].klen == speed[i].klen) {
  439. key = template[j].key;
  440. break;
  441. }
  442. }
  443. p = (unsigned char *)tvmem + speed[i].klen;
  444. ret = crypto_cipher_setkey(tfm, key, speed[i].klen);
  445. if (ret) {
  446. printk("setkey() failed flags=%x\n", tfm->crt_flags);
  447. goto out;
  448. }
  449. if (!mode) {
  450. iv_len = crypto_tfm_alg_ivsize(tfm);
  451. memset(&iv, 0xff, iv_len);
  452. crypto_cipher_set_iv(tfm, iv, iv_len);
  453. }
  454. if (sec)
  455. ret = test_cipher_jiffies(tfm, enc, p, speed[i].blen,
  456. sec);
  457. else
  458. ret = test_cipher_cycles(tfm, enc, p, speed[i].blen);
  459. if (ret) {
  460. printk("%s() failed flags=%x\n", e, tfm->crt_flags);
  461. break;
  462. }
  463. }
  464. out:
  465. crypto_free_tfm(tfm);
  466. }
  467. static void test_deflate(void)
  468. {
  469. unsigned int i;
  470. char result[COMP_BUF_SIZE];
  471. struct crypto_tfm *tfm;
  472. struct comp_testvec *tv;
  473. unsigned int tsize;
  474. printk("\ntesting deflate compression\n");
  475. tsize = sizeof (deflate_comp_tv_template);
  476. if (tsize > TVMEMSIZE) {
  477. printk("template (%u) too big for tvmem (%u)\n", tsize,
  478. TVMEMSIZE);
  479. return;
  480. }
  481. memcpy(tvmem, deflate_comp_tv_template, tsize);
  482. tv = (void *)tvmem;
  483. tfm = crypto_alloc_tfm("deflate", 0);
  484. if (tfm == NULL) {
  485. printk("failed to load transform for deflate\n");
  486. return;
  487. }
  488. for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) {
  489. int ilen, ret, dlen = COMP_BUF_SIZE;
  490. printk("test %u:\n", i + 1);
  491. memset(result, 0, sizeof (result));
  492. ilen = tv[i].inlen;
  493. ret = crypto_comp_compress(tfm, tv[i].input,
  494. ilen, result, &dlen);
  495. if (ret) {
  496. printk("fail: ret=%d\n", ret);
  497. continue;
  498. }
  499. hexdump(result, dlen);
  500. printk("%s (ratio %d:%d)\n",
  501. memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
  502. ilen, dlen);
  503. }
  504. printk("\ntesting deflate decompression\n");
  505. tsize = sizeof (deflate_decomp_tv_template);
  506. if (tsize > TVMEMSIZE) {
  507. printk("template (%u) too big for tvmem (%u)\n", tsize,
  508. TVMEMSIZE);
  509. goto out;
  510. }
  511. memcpy(tvmem, deflate_decomp_tv_template, tsize);
  512. tv = (void *)tvmem;
  513. for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) {
  514. int ilen, ret, dlen = COMP_BUF_SIZE;
  515. printk("test %u:\n", i + 1);
  516. memset(result, 0, sizeof (result));
  517. ilen = tv[i].inlen;
  518. ret = crypto_comp_decompress(tfm, tv[i].input,
  519. ilen, result, &dlen);
  520. if (ret) {
  521. printk("fail: ret=%d\n", ret);
  522. continue;
  523. }
  524. hexdump(result, dlen);
  525. printk("%s (ratio %d:%d)\n",
  526. memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
  527. ilen, dlen);
  528. }
  529. out:
  530. crypto_free_tfm(tfm);
  531. }
  532. static void test_crc32c(void)
  533. {
  534. #define NUMVEC 6
  535. #define VECSIZE 40
  536. int i, j, pass;
  537. u32 crc;
  538. u8 b, test_vec[NUMVEC][VECSIZE];
  539. static u32 vec_results[NUMVEC] = {
  540. 0x0e2c157f, 0xe980ebf6, 0xde74bded,
  541. 0xd579c862, 0xba979ad0, 0x2b29d913
  542. };
  543. static u32 tot_vec_results = 0x24c5d375;
  544. struct scatterlist sg[NUMVEC];
  545. struct crypto_tfm *tfm;
  546. char *fmtdata = "testing crc32c initialized to %08x: %s\n";
  547. #define SEEDTESTVAL 0xedcba987
  548. u32 seed;
  549. printk("\ntesting crc32c\n");
  550. tfm = crypto_alloc_tfm("crc32c", 0);
  551. if (tfm == NULL) {
  552. printk("failed to load transform for crc32c\n");
  553. return;
  554. }
  555. crypto_digest_init(tfm);
  556. crypto_digest_final(tfm, (u8*)&crc);
  557. printk(fmtdata, crc, (crc == 0) ? "pass" : "ERROR");
  558. /*
  559. * stuff test_vec with known values, simple incrementing
  560. * byte values.
  561. */
  562. b = 0;
  563. for (i = 0; i < NUMVEC; i++) {
  564. for (j = 0; j < VECSIZE; j++)
  565. test_vec[i][j] = ++b;
  566. sg_set_buf(&sg[i], test_vec[i], VECSIZE);
  567. }
  568. seed = SEEDTESTVAL;
  569. (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32));
  570. crypto_digest_final(tfm, (u8*)&crc);
  571. printk("testing crc32c setkey returns %08x : %s\n", crc, (crc == (SEEDTESTVAL ^ ~(u32)0)) ?
  572. "pass" : "ERROR");
  573. printk("testing crc32c using update/final:\n");
  574. pass = 1; /* assume all is well */
  575. for (i = 0; i < NUMVEC; i++) {
  576. seed = ~(u32)0;
  577. (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32));
  578. crypto_digest_update(tfm, &sg[i], 1);
  579. crypto_digest_final(tfm, (u8*)&crc);
  580. if (crc == vec_results[i]) {
  581. printk(" %08x:OK", crc);
  582. } else {
  583. printk(" %08x:BAD, wanted %08x\n", crc, vec_results[i]);
  584. pass = 0;
  585. }
  586. }
  587. printk("\ntesting crc32c using incremental accumulator:\n");
  588. crc = 0;
  589. for (i = 0; i < NUMVEC; i++) {
  590. seed = (crc ^ ~(u32)0);
  591. (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32));
  592. crypto_digest_update(tfm, &sg[i], 1);
  593. crypto_digest_final(tfm, (u8*)&crc);
  594. }
  595. if (crc == tot_vec_results) {
  596. printk(" %08x:OK", crc);
  597. } else {
  598. printk(" %08x:BAD, wanted %08x\n", crc, tot_vec_results);
  599. pass = 0;
  600. }
  601. printk("\ntesting crc32c using digest:\n");
  602. seed = ~(u32)0;
  603. (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32));
  604. crypto_digest_digest(tfm, sg, NUMVEC, (u8*)&crc);
  605. if (crc == tot_vec_results) {
  606. printk(" %08x:OK", crc);
  607. } else {
  608. printk(" %08x:BAD, wanted %08x\n", crc, tot_vec_results);
  609. pass = 0;
  610. }
  611. printk("\n%s\n", pass ? "pass" : "ERROR");
  612. crypto_free_tfm(tfm);
  613. printk("crc32c test complete\n");
  614. }
  615. static void test_available(void)
  616. {
  617. char **name = check;
  618. while (*name) {
  619. printk("alg %s ", *name);
  620. printk((crypto_alg_available(*name, 0)) ?
  621. "found\n" : "not found\n");
  622. name++;
  623. }
  624. }
  625. static void do_test(void)
  626. {
  627. switch (mode) {
  628. case 0:
  629. test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
  630. test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
  631. //DES
  632. test_cipher ("des", MODE_ECB, ENCRYPT, des_enc_tv_template, DES_ENC_TEST_VECTORS);
  633. test_cipher ("des", MODE_ECB, DECRYPT, des_dec_tv_template, DES_DEC_TEST_VECTORS);
  634. test_cipher ("des", MODE_CBC, ENCRYPT, des_cbc_enc_tv_template, DES_CBC_ENC_TEST_VECTORS);
  635. test_cipher ("des", MODE_CBC, DECRYPT, des_cbc_dec_tv_template, DES_CBC_DEC_TEST_VECTORS);
  636. //DES3_EDE
  637. test_cipher ("des3_ede", MODE_ECB, ENCRYPT, des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS);
  638. test_cipher ("des3_ede", MODE_ECB, DECRYPT, des3_ede_dec_tv_template, DES3_EDE_DEC_TEST_VECTORS);
  639. test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
  640. test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
  641. //BLOWFISH
  642. test_cipher ("blowfish", MODE_ECB, ENCRYPT, bf_enc_tv_template, BF_ENC_TEST_VECTORS);
  643. test_cipher ("blowfish", MODE_ECB, DECRYPT, bf_dec_tv_template, BF_DEC_TEST_VECTORS);
  644. test_cipher ("blowfish", MODE_CBC, ENCRYPT, bf_cbc_enc_tv_template, BF_CBC_ENC_TEST_VECTORS);
  645. test_cipher ("blowfish", MODE_CBC, DECRYPT, bf_cbc_dec_tv_template, BF_CBC_DEC_TEST_VECTORS);
  646. //TWOFISH
  647. test_cipher ("twofish", MODE_ECB, ENCRYPT, tf_enc_tv_template, TF_ENC_TEST_VECTORS);
  648. test_cipher ("twofish", MODE_ECB, DECRYPT, tf_dec_tv_template, TF_DEC_TEST_VECTORS);
  649. test_cipher ("twofish", MODE_CBC, ENCRYPT, tf_cbc_enc_tv_template, TF_CBC_ENC_TEST_VECTORS);
  650. test_cipher ("twofish", MODE_CBC, DECRYPT, tf_cbc_dec_tv_template, TF_CBC_DEC_TEST_VECTORS);
  651. //SERPENT
  652. test_cipher ("serpent", MODE_ECB, ENCRYPT, serpent_enc_tv_template, SERPENT_ENC_TEST_VECTORS);
  653. test_cipher ("serpent", MODE_ECB, DECRYPT, serpent_dec_tv_template, SERPENT_DEC_TEST_VECTORS);
  654. //TNEPRES
  655. test_cipher ("tnepres", MODE_ECB, ENCRYPT, tnepres_enc_tv_template, TNEPRES_ENC_TEST_VECTORS);
  656. test_cipher ("tnepres", MODE_ECB, DECRYPT, tnepres_dec_tv_template, TNEPRES_DEC_TEST_VECTORS);
  657. //AES
  658. test_cipher ("aes", MODE_ECB, ENCRYPT, aes_enc_tv_template, AES_ENC_TEST_VECTORS);
  659. test_cipher ("aes", MODE_ECB, DECRYPT, aes_dec_tv_template, AES_DEC_TEST_VECTORS);
  660. test_cipher ("aes", MODE_CBC, ENCRYPT, aes_cbc_enc_tv_template, AES_CBC_ENC_TEST_VECTORS);
  661. test_cipher ("aes", MODE_CBC, DECRYPT, aes_cbc_dec_tv_template, AES_CBC_DEC_TEST_VECTORS);
  662. //CAST5
  663. test_cipher ("cast5", MODE_ECB, ENCRYPT, cast5_enc_tv_template, CAST5_ENC_TEST_VECTORS);
  664. test_cipher ("cast5", MODE_ECB, DECRYPT, cast5_dec_tv_template, CAST5_DEC_TEST_VECTORS);
  665. //CAST6
  666. test_cipher ("cast6", MODE_ECB, ENCRYPT, cast6_enc_tv_template, CAST6_ENC_TEST_VECTORS);
  667. test_cipher ("cast6", MODE_ECB, DECRYPT, cast6_dec_tv_template, CAST6_DEC_TEST_VECTORS);
  668. //ARC4
  669. test_cipher ("arc4", MODE_ECB, ENCRYPT, arc4_enc_tv_template, ARC4_ENC_TEST_VECTORS);
  670. test_cipher ("arc4", MODE_ECB, DECRYPT, arc4_dec_tv_template, ARC4_DEC_TEST_VECTORS);
  671. //TEA
  672. test_cipher ("tea", MODE_ECB, ENCRYPT, tea_enc_tv_template, TEA_ENC_TEST_VECTORS);
  673. test_cipher ("tea", MODE_ECB, DECRYPT, tea_dec_tv_template, TEA_DEC_TEST_VECTORS);
  674. //XTEA
  675. test_cipher ("xtea", MODE_ECB, ENCRYPT, xtea_enc_tv_template, XTEA_ENC_TEST_VECTORS);
  676. test_cipher ("xtea", MODE_ECB, DECRYPT, xtea_dec_tv_template, XTEA_DEC_TEST_VECTORS);
  677. //KHAZAD
  678. test_cipher ("khazad", MODE_ECB, ENCRYPT, khazad_enc_tv_template, KHAZAD_ENC_TEST_VECTORS);
  679. test_cipher ("khazad", MODE_ECB, DECRYPT, khazad_dec_tv_template, KHAZAD_DEC_TEST_VECTORS);
  680. //ANUBIS
  681. test_cipher ("anubis", MODE_ECB, ENCRYPT, anubis_enc_tv_template, ANUBIS_ENC_TEST_VECTORS);
  682. test_cipher ("anubis", MODE_ECB, DECRYPT, anubis_dec_tv_template, ANUBIS_DEC_TEST_VECTORS);
  683. test_cipher ("anubis", MODE_CBC, ENCRYPT, anubis_cbc_enc_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS);
  684. test_cipher ("anubis", MODE_CBC, DECRYPT, anubis_cbc_dec_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS);
  685. //XETA
  686. test_cipher ("xeta", MODE_ECB, ENCRYPT, xeta_enc_tv_template, XETA_ENC_TEST_VECTORS);
  687. test_cipher ("xeta", MODE_ECB, DECRYPT, xeta_dec_tv_template, XETA_DEC_TEST_VECTORS);
  688. test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
  689. test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
  690. test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
  691. test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
  692. test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
  693. test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
  694. test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
  695. test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
  696. test_deflate();
  697. test_crc32c();
  698. #ifdef CONFIG_CRYPTO_HMAC
  699. test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS);
  700. test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS);
  701. test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS);
  702. #endif
  703. test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
  704. break;
  705. case 1:
  706. test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
  707. break;
  708. case 2:
  709. test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
  710. break;
  711. case 3:
  712. test_cipher ("des", MODE_ECB, ENCRYPT, des_enc_tv_template, DES_ENC_TEST_VECTORS);
  713. test_cipher ("des", MODE_ECB, DECRYPT, des_dec_tv_template, DES_DEC_TEST_VECTORS);
  714. test_cipher ("des", MODE_CBC, ENCRYPT, des_cbc_enc_tv_template, DES_CBC_ENC_TEST_VECTORS);
  715. test_cipher ("des", MODE_CBC, DECRYPT, des_cbc_dec_tv_template, DES_CBC_DEC_TEST_VECTORS);
  716. break;
  717. case 4:
  718. test_cipher ("des3_ede", MODE_ECB, ENCRYPT, des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS);
  719. test_cipher ("des3_ede", MODE_ECB, DECRYPT, des3_ede_dec_tv_template, DES3_EDE_DEC_TEST_VECTORS);
  720. break;
  721. case 5:
  722. test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
  723. break;
  724. case 6:
  725. test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
  726. break;
  727. case 7:
  728. test_cipher ("blowfish", MODE_ECB, ENCRYPT, bf_enc_tv_template, BF_ENC_TEST_VECTORS);
  729. test_cipher ("blowfish", MODE_ECB, DECRYPT, bf_dec_tv_template, BF_DEC_TEST_VECTORS);
  730. test_cipher ("blowfish", MODE_CBC, ENCRYPT, bf_cbc_enc_tv_template, BF_CBC_ENC_TEST_VECTORS);
  731. test_cipher ("blowfish", MODE_CBC, DECRYPT, bf_cbc_dec_tv_template, BF_CBC_DEC_TEST_VECTORS);
  732. break;
  733. case 8:
  734. test_cipher ("twofish", MODE_ECB, ENCRYPT, tf_enc_tv_template, TF_ENC_TEST_VECTORS);
  735. test_cipher ("twofish", MODE_ECB, DECRYPT, tf_dec_tv_template, TF_DEC_TEST_VECTORS);
  736. test_cipher ("twofish", MODE_CBC, ENCRYPT, tf_cbc_enc_tv_template, TF_CBC_ENC_TEST_VECTORS);
  737. test_cipher ("twofish", MODE_CBC, DECRYPT, tf_cbc_dec_tv_template, TF_CBC_DEC_TEST_VECTORS);
  738. break;
  739. case 9:
  740. test_cipher ("serpent", MODE_ECB, ENCRYPT, serpent_enc_tv_template, SERPENT_ENC_TEST_VECTORS);
  741. test_cipher ("serpent", MODE_ECB, DECRYPT, serpent_dec_tv_template, SERPENT_DEC_TEST_VECTORS);
  742. break;
  743. case 10:
  744. test_cipher ("aes", MODE_ECB, ENCRYPT, aes_enc_tv_template, AES_ENC_TEST_VECTORS);
  745. test_cipher ("aes", MODE_ECB, DECRYPT, aes_dec_tv_template, AES_DEC_TEST_VECTORS);
  746. test_cipher ("aes", MODE_CBC, ENCRYPT, aes_cbc_enc_tv_template, AES_CBC_ENC_TEST_VECTORS);
  747. test_cipher ("aes", MODE_CBC, DECRYPT, aes_cbc_dec_tv_template, AES_CBC_DEC_TEST_VECTORS);
  748. break;
  749. case 11:
  750. test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
  751. break;
  752. case 12:
  753. test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
  754. break;
  755. case 13:
  756. test_deflate();
  757. break;
  758. case 14:
  759. test_cipher ("cast5", MODE_ECB, ENCRYPT, cast5_enc_tv_template, CAST5_ENC_TEST_VECTORS);
  760. test_cipher ("cast5", MODE_ECB, DECRYPT, cast5_dec_tv_template, CAST5_DEC_TEST_VECTORS);
  761. break;
  762. case 15:
  763. test_cipher ("cast6", MODE_ECB, ENCRYPT, cast6_enc_tv_template, CAST6_ENC_TEST_VECTORS);
  764. test_cipher ("cast6", MODE_ECB, DECRYPT, cast6_dec_tv_template, CAST6_DEC_TEST_VECTORS);
  765. break;
  766. case 16:
  767. test_cipher ("arc4", MODE_ECB, ENCRYPT, arc4_enc_tv_template, ARC4_ENC_TEST_VECTORS);
  768. test_cipher ("arc4", MODE_ECB, DECRYPT, arc4_dec_tv_template, ARC4_DEC_TEST_VECTORS);
  769. break;
  770. case 17:
  771. test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
  772. break;
  773. case 18:
  774. test_crc32c();
  775. break;
  776. case 19:
  777. test_cipher ("tea", MODE_ECB, ENCRYPT, tea_enc_tv_template, TEA_ENC_TEST_VECTORS);
  778. test_cipher ("tea", MODE_ECB, DECRYPT, tea_dec_tv_template, TEA_DEC_TEST_VECTORS);
  779. break;
  780. case 20:
  781. test_cipher ("xtea", MODE_ECB, ENCRYPT, xtea_enc_tv_template, XTEA_ENC_TEST_VECTORS);
  782. test_cipher ("xtea", MODE_ECB, DECRYPT, xtea_dec_tv_template, XTEA_DEC_TEST_VECTORS);
  783. break;
  784. case 21:
  785. test_cipher ("khazad", MODE_ECB, ENCRYPT, khazad_enc_tv_template, KHAZAD_ENC_TEST_VECTORS);
  786. test_cipher ("khazad", MODE_ECB, DECRYPT, khazad_dec_tv_template, KHAZAD_DEC_TEST_VECTORS);
  787. break;
  788. case 22:
  789. test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
  790. break;
  791. case 23:
  792. test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
  793. break;
  794. case 24:
  795. test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
  796. break;
  797. case 25:
  798. test_cipher ("tnepres", MODE_ECB, ENCRYPT, tnepres_enc_tv_template, TNEPRES_ENC_TEST_VECTORS);
  799. test_cipher ("tnepres", MODE_ECB, DECRYPT, tnepres_dec_tv_template, TNEPRES_DEC_TEST_VECTORS);
  800. break;
  801. case 26:
  802. test_cipher ("anubis", MODE_ECB, ENCRYPT, anubis_enc_tv_template, ANUBIS_ENC_TEST_VECTORS);
  803. test_cipher ("anubis", MODE_ECB, DECRYPT, anubis_dec_tv_template, ANUBIS_DEC_TEST_VECTORS);
  804. test_cipher ("anubis", MODE_CBC, ENCRYPT, anubis_cbc_enc_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS);
  805. test_cipher ("anubis", MODE_CBC, DECRYPT, anubis_cbc_dec_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS);
  806. break;
  807. case 27:
  808. test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
  809. break;
  810. case 28:
  811. test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
  812. break;
  813. case 29:
  814. test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
  815. break;
  816. case 30:
  817. test_cipher ("xeta", MODE_ECB, ENCRYPT, xeta_enc_tv_template, XETA_ENC_TEST_VECTORS);
  818. test_cipher ("xeta", MODE_ECB, DECRYPT, xeta_dec_tv_template, XETA_DEC_TEST_VECTORS);
  819. break;
  820. #ifdef CONFIG_CRYPTO_HMAC
  821. case 100:
  822. test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS);
  823. break;
  824. case 101:
  825. test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS);
  826. break;
  827. case 102:
  828. test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS);
  829. break;
  830. #endif
  831. case 200:
  832. test_cipher_speed("aes", MODE_ECB, ENCRYPT, sec, NULL, 0,
  833. aes_speed_template);
  834. test_cipher_speed("aes", MODE_ECB, DECRYPT, sec, NULL, 0,
  835. aes_speed_template);
  836. test_cipher_speed("aes", MODE_CBC, ENCRYPT, sec, NULL, 0,
  837. aes_speed_template);
  838. test_cipher_speed("aes", MODE_CBC, DECRYPT, sec, NULL, 0,
  839. aes_speed_template);
  840. break;
  841. case 201:
  842. test_cipher_speed("des3_ede", MODE_ECB, ENCRYPT, sec,
  843. des3_ede_enc_tv_template,
  844. DES3_EDE_ENC_TEST_VECTORS,
  845. des3_ede_speed_template);
  846. test_cipher_speed("des3_ede", MODE_ECB, DECRYPT, sec,
  847. des3_ede_dec_tv_template,
  848. DES3_EDE_DEC_TEST_VECTORS,
  849. des3_ede_speed_template);
  850. test_cipher_speed("des3_ede", MODE_CBC, ENCRYPT, sec,
  851. des3_ede_enc_tv_template,
  852. DES3_EDE_ENC_TEST_VECTORS,
  853. des3_ede_speed_template);
  854. test_cipher_speed("des3_ede", MODE_CBC, DECRYPT, sec,
  855. des3_ede_dec_tv_template,
  856. DES3_EDE_DEC_TEST_VECTORS,
  857. des3_ede_speed_template);
  858. break;
  859. case 202:
  860. test_cipher_speed("twofish", MODE_ECB, ENCRYPT, sec, NULL, 0,
  861. twofish_speed_template);
  862. test_cipher_speed("twofish", MODE_ECB, DECRYPT, sec, NULL, 0,
  863. twofish_speed_template);
  864. test_cipher_speed("twofish", MODE_CBC, ENCRYPT, sec, NULL, 0,
  865. twofish_speed_template);
  866. test_cipher_speed("twofish", MODE_CBC, DECRYPT, sec, NULL, 0,
  867. twofish_speed_template);
  868. break;
  869. case 203:
  870. test_cipher_speed("blowfish", MODE_ECB, ENCRYPT, sec, NULL, 0,
  871. blowfish_speed_template);
  872. test_cipher_speed("blowfish", MODE_ECB, DECRYPT, sec, NULL, 0,
  873. blowfish_speed_template);
  874. test_cipher_speed("blowfish", MODE_CBC, ENCRYPT, sec, NULL, 0,
  875. blowfish_speed_template);
  876. test_cipher_speed("blowfish", MODE_CBC, DECRYPT, sec, NULL, 0,
  877. blowfish_speed_template);
  878. break;
  879. case 204:
  880. test_cipher_speed("des", MODE_ECB, ENCRYPT, sec, NULL, 0,
  881. des_speed_template);
  882. test_cipher_speed("des", MODE_ECB, DECRYPT, sec, NULL, 0,
  883. des_speed_template);
  884. test_cipher_speed("des", MODE_CBC, ENCRYPT, sec, NULL, 0,
  885. des_speed_template);
  886. test_cipher_speed("des", MODE_CBC, DECRYPT, sec, NULL, 0,
  887. des_speed_template);
  888. break;
  889. case 1000:
  890. test_available();
  891. break;
  892. default:
  893. /* useful for debugging */
  894. printk("not testing anything\n");
  895. break;
  896. }
  897. }
  898. static int __init init(void)
  899. {
  900. tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
  901. if (tvmem == NULL)
  902. return -ENOMEM;
  903. xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
  904. if (xbuf == NULL) {
  905. kfree(tvmem);
  906. return -ENOMEM;
  907. }
  908. do_test();
  909. kfree(xbuf);
  910. kfree(tvmem);
  911. return 0;
  912. }
  913. /*
  914. * If an init function is provided, an exit function must also be provided
  915. * to allow module unload.
  916. */
  917. static void __exit fini(void) { }
  918. module_init(init);
  919. module_exit(fini);
  920. module_param(mode, int, 0);
  921. module_param(sec, uint, 0);
  922. MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
  923. "(defaults to zero which uses CPU cycles instead)");
  924. MODULE_LICENSE("GPL");
  925. MODULE_DESCRIPTION("Quick & dirty crypto testing module");
  926. MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");