tcrypt.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864
  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. * 2007-11-13 Added GCM tests
  17. * 2007-11-13 Added AEAD support
  18. * 2007-11-06 Added SHA-224 and SHA-224-HMAC tests
  19. * 2006-12-07 Added SHA384 HMAC and SHA512 HMAC tests
  20. * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>)
  21. * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt
  22. *
  23. */
  24. #include <linux/err.h>
  25. #include <linux/init.h>
  26. #include <linux/module.h>
  27. #include <linux/mm.h>
  28. #include <linux/slab.h>
  29. #include <linux/scatterlist.h>
  30. #include <linux/string.h>
  31. #include <linux/crypto.h>
  32. #include <linux/highmem.h>
  33. #include <linux/moduleparam.h>
  34. #include <linux/jiffies.h>
  35. #include <linux/timex.h>
  36. #include <linux/interrupt.h>
  37. #include "tcrypt.h"
  38. /*
  39. * Need to kmalloc() memory for testing kmap().
  40. */
  41. #define TVMEMSIZE 16384
  42. #define XBUFSIZE 32768
  43. /*
  44. * Indexes into the xbuf to simulate cross-page access.
  45. */
  46. #define IDX1 37
  47. #define IDX2 32400
  48. #define IDX3 1
  49. #define IDX4 8193
  50. #define IDX5 22222
  51. #define IDX6 17101
  52. #define IDX7 27333
  53. #define IDX8 3000
  54. /*
  55. * Used by test_cipher()
  56. */
  57. #define ENCRYPT 1
  58. #define DECRYPT 0
  59. struct tcrypt_result {
  60. struct completion completion;
  61. int err;
  62. };
  63. static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
  64. /*
  65. * Used by test_cipher_speed()
  66. */
  67. static unsigned int sec;
  68. static int mode;
  69. static char *xbuf;
  70. static char *axbuf;
  71. static char *tvmem;
  72. static char *check[] = {
  73. "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
  74. "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
  75. "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
  76. "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
  77. "camellia", "seed", "salsa20", "lzo", "cts", NULL
  78. };
  79. static void hexdump(unsigned char *buf, unsigned int len)
  80. {
  81. print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
  82. 16, 1,
  83. buf, len, false);
  84. }
  85. static void tcrypt_complete(struct crypto_async_request *req, int err)
  86. {
  87. struct tcrypt_result *res = req->data;
  88. if (err == -EINPROGRESS)
  89. return;
  90. res->err = err;
  91. complete(&res->completion);
  92. }
  93. static void test_hash(char *algo, struct hash_testvec *template,
  94. unsigned int tcount)
  95. {
  96. unsigned int i, j, k, temp;
  97. struct scatterlist sg[8];
  98. char result[64];
  99. struct crypto_hash *tfm;
  100. struct hash_desc desc;
  101. int ret;
  102. void *hash_buff;
  103. printk("\ntesting %s\n", algo);
  104. tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
  105. if (IS_ERR(tfm)) {
  106. printk("failed to load transform for %s: %ld\n", algo,
  107. PTR_ERR(tfm));
  108. return;
  109. }
  110. desc.tfm = tfm;
  111. desc.flags = 0;
  112. for (i = 0; i < tcount; i++) {
  113. printk("test %u:\n", i + 1);
  114. memset(result, 0, 64);
  115. hash_buff = kzalloc(template[i].psize, GFP_KERNEL);
  116. if (!hash_buff)
  117. continue;
  118. memcpy(hash_buff, template[i].plaintext, template[i].psize);
  119. sg_init_one(&sg[0], hash_buff, template[i].psize);
  120. if (template[i].ksize) {
  121. ret = crypto_hash_setkey(tfm, template[i].key,
  122. template[i].ksize);
  123. if (ret) {
  124. printk("setkey() failed ret=%d\n", ret);
  125. kfree(hash_buff);
  126. goto out;
  127. }
  128. }
  129. ret = crypto_hash_digest(&desc, sg, template[i].psize, result);
  130. if (ret) {
  131. printk("digest () failed ret=%d\n", ret);
  132. kfree(hash_buff);
  133. goto out;
  134. }
  135. hexdump(result, crypto_hash_digestsize(tfm));
  136. printk("%s\n",
  137. memcmp(result, template[i].digest,
  138. crypto_hash_digestsize(tfm)) ?
  139. "fail" : "pass");
  140. kfree(hash_buff);
  141. }
  142. printk("testing %s across pages\n", algo);
  143. /* setup the dummy buffer first */
  144. memset(xbuf, 0, XBUFSIZE);
  145. j = 0;
  146. for (i = 0; i < tcount; i++) {
  147. if (template[i].np) {
  148. j++;
  149. printk("test %u:\n", j);
  150. memset(result, 0, 64);
  151. temp = 0;
  152. sg_init_table(sg, template[i].np);
  153. for (k = 0; k < template[i].np; k++) {
  154. memcpy(&xbuf[IDX[k]],
  155. template[i].plaintext + temp,
  156. template[i].tap[k]);
  157. temp += template[i].tap[k];
  158. sg_set_buf(&sg[k], &xbuf[IDX[k]],
  159. template[i].tap[k]);
  160. }
  161. if (template[i].ksize) {
  162. ret = crypto_hash_setkey(tfm, template[i].key,
  163. template[i].ksize);
  164. if (ret) {
  165. printk("setkey() failed ret=%d\n", ret);
  166. goto out;
  167. }
  168. }
  169. ret = crypto_hash_digest(&desc, sg, template[i].psize,
  170. result);
  171. if (ret) {
  172. printk("digest () failed ret=%d\n", ret);
  173. goto out;
  174. }
  175. hexdump(result, crypto_hash_digestsize(tfm));
  176. printk("%s\n",
  177. memcmp(result, template[i].digest,
  178. crypto_hash_digestsize(tfm)) ?
  179. "fail" : "pass");
  180. }
  181. }
  182. out:
  183. crypto_free_hash(tfm);
  184. }
  185. static void test_aead(char *algo, int enc, struct aead_testvec *template,
  186. unsigned int tcount)
  187. {
  188. unsigned int ret, i, j, k, temp;
  189. char *q;
  190. struct crypto_aead *tfm;
  191. char *key;
  192. struct aead_request *req;
  193. struct scatterlist sg[8];
  194. struct scatterlist asg[8];
  195. const char *e;
  196. struct tcrypt_result result;
  197. unsigned int authsize;
  198. void *input;
  199. void *assoc;
  200. char iv[MAX_IVLEN];
  201. if (enc == ENCRYPT)
  202. e = "encryption";
  203. else
  204. e = "decryption";
  205. printk(KERN_INFO "\ntesting %s %s\n", algo, e);
  206. init_completion(&result.completion);
  207. tfm = crypto_alloc_aead(algo, 0, 0);
  208. if (IS_ERR(tfm)) {
  209. printk(KERN_INFO "failed to load transform for %s: %ld\n",
  210. algo, PTR_ERR(tfm));
  211. return;
  212. }
  213. req = aead_request_alloc(tfm, GFP_KERNEL);
  214. if (!req) {
  215. printk(KERN_INFO "failed to allocate request for %s\n", algo);
  216. goto out;
  217. }
  218. aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  219. tcrypt_complete, &result);
  220. for (i = 0, j = 0; i < tcount; i++) {
  221. if (!template[i].np) {
  222. printk(KERN_INFO "test %u (%d bit key):\n",
  223. ++j, template[i].klen * 8);
  224. /* some tepmplates have no input data but they will
  225. * touch input
  226. */
  227. input = kzalloc(template[i].ilen + template[i].rlen, GFP_KERNEL);
  228. if (!input)
  229. continue;
  230. assoc = kzalloc(template[i].alen, GFP_KERNEL);
  231. if (!assoc) {
  232. kfree(input);
  233. continue;
  234. }
  235. memcpy(input, template[i].input, template[i].ilen);
  236. memcpy(assoc, template[i].assoc, template[i].alen);
  237. if (template[i].iv)
  238. memcpy(iv, template[i].iv, MAX_IVLEN);
  239. else
  240. memset(iv, 0, MAX_IVLEN);
  241. crypto_aead_clear_flags(tfm, ~0);
  242. if (template[i].wk)
  243. crypto_aead_set_flags(
  244. tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  245. if (template[i].key)
  246. key = template[i].key;
  247. else
  248. key = kzalloc(template[i].klen, GFP_KERNEL);
  249. ret = crypto_aead_setkey(tfm, key,
  250. template[i].klen);
  251. if (ret) {
  252. printk(KERN_INFO "setkey() failed flags=%x\n",
  253. crypto_aead_get_flags(tfm));
  254. if (!template[i].fail)
  255. goto next_one;
  256. }
  257. authsize = abs(template[i].rlen - template[i].ilen);
  258. ret = crypto_aead_setauthsize(tfm, authsize);
  259. if (ret) {
  260. printk(KERN_INFO
  261. "failed to set authsize = %u\n",
  262. authsize);
  263. goto next_one;
  264. }
  265. sg_init_one(&sg[0], input,
  266. template[i].ilen + (enc ? authsize : 0));
  267. sg_init_one(&asg[0], assoc, template[i].alen);
  268. aead_request_set_crypt(req, sg, sg,
  269. template[i].ilen, iv);
  270. aead_request_set_assoc(req, asg, template[i].alen);
  271. ret = enc ?
  272. crypto_aead_encrypt(req) :
  273. crypto_aead_decrypt(req);
  274. switch (ret) {
  275. case 0:
  276. break;
  277. case -EINPROGRESS:
  278. case -EBUSY:
  279. ret = wait_for_completion_interruptible(
  280. &result.completion);
  281. if (!ret && !(ret = result.err)) {
  282. INIT_COMPLETION(result.completion);
  283. break;
  284. }
  285. /* fall through */
  286. default:
  287. printk(KERN_INFO "%s () failed err=%d\n",
  288. e, -ret);
  289. goto next_one;
  290. }
  291. q = kmap(sg_page(&sg[0])) + sg[0].offset;
  292. hexdump(q, template[i].rlen);
  293. printk(KERN_INFO "enc/dec: %s\n",
  294. memcmp(q, template[i].result,
  295. template[i].rlen) ? "fail" : "pass");
  296. kunmap(sg_page(&sg[0]));
  297. next_one:
  298. if (!template[i].key)
  299. kfree(key);
  300. kfree(assoc);
  301. kfree(input);
  302. }
  303. }
  304. printk(KERN_INFO "\ntesting %s %s across pages (chunking)\n", algo, e);
  305. memset(xbuf, 0, XBUFSIZE);
  306. memset(axbuf, 0, XBUFSIZE);
  307. for (i = 0, j = 0; i < tcount; i++) {
  308. if (template[i].np) {
  309. printk(KERN_INFO "test %u (%d bit key):\n",
  310. ++j, template[i].klen * 8);
  311. if (template[i].iv)
  312. memcpy(iv, template[i].iv, MAX_IVLEN);
  313. else
  314. memset(iv, 0, MAX_IVLEN);
  315. crypto_aead_clear_flags(tfm, ~0);
  316. if (template[i].wk)
  317. crypto_aead_set_flags(
  318. tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  319. key = template[i].key;
  320. ret = crypto_aead_setkey(tfm, key, template[i].klen);
  321. if (ret) {
  322. printk(KERN_INFO "setkey() failed flags=%x\n",
  323. crypto_aead_get_flags(tfm));
  324. if (!template[i].fail)
  325. goto out;
  326. }
  327. sg_init_table(sg, template[i].np);
  328. for (k = 0, temp = 0; k < template[i].np; k++) {
  329. memcpy(&xbuf[IDX[k]],
  330. template[i].input + temp,
  331. template[i].tap[k]);
  332. temp += template[i].tap[k];
  333. sg_set_buf(&sg[k], &xbuf[IDX[k]],
  334. template[i].tap[k]);
  335. }
  336. authsize = abs(template[i].rlen - template[i].ilen);
  337. ret = crypto_aead_setauthsize(tfm, authsize);
  338. if (ret) {
  339. printk(KERN_INFO
  340. "failed to set authsize = %u\n",
  341. authsize);
  342. goto out;
  343. }
  344. if (enc)
  345. sg[k - 1].length += authsize;
  346. sg_init_table(asg, template[i].anp);
  347. for (k = 0, temp = 0; k < template[i].anp; k++) {
  348. memcpy(&axbuf[IDX[k]],
  349. template[i].assoc + temp,
  350. template[i].atap[k]);
  351. temp += template[i].atap[k];
  352. sg_set_buf(&asg[k], &axbuf[IDX[k]],
  353. template[i].atap[k]);
  354. }
  355. aead_request_set_crypt(req, sg, sg,
  356. template[i].ilen,
  357. iv);
  358. aead_request_set_assoc(req, asg, template[i].alen);
  359. ret = enc ?
  360. crypto_aead_encrypt(req) :
  361. crypto_aead_decrypt(req);
  362. switch (ret) {
  363. case 0:
  364. break;
  365. case -EINPROGRESS:
  366. case -EBUSY:
  367. ret = wait_for_completion_interruptible(
  368. &result.completion);
  369. if (!ret && !(ret = result.err)) {
  370. INIT_COMPLETION(result.completion);
  371. break;
  372. }
  373. /* fall through */
  374. default:
  375. printk(KERN_INFO "%s () failed err=%d\n",
  376. e, -ret);
  377. goto out;
  378. }
  379. for (k = 0, temp = 0; k < template[i].np; k++) {
  380. printk(KERN_INFO "page %u\n", k);
  381. q = kmap(sg_page(&sg[k])) + sg[k].offset;
  382. hexdump(q, template[i].tap[k]);
  383. printk(KERN_INFO "%s\n",
  384. memcmp(q, template[i].result + temp,
  385. template[i].tap[k] -
  386. (k < template[i].np - 1 || enc ?
  387. 0 : authsize)) ?
  388. "fail" : "pass");
  389. temp += template[i].tap[k];
  390. kunmap(sg_page(&sg[k]));
  391. }
  392. }
  393. }
  394. out:
  395. crypto_free_aead(tfm);
  396. aead_request_free(req);
  397. }
  398. static void test_cipher(char *algo, int enc,
  399. struct cipher_testvec *template, unsigned int tcount)
  400. {
  401. unsigned int ret, i, j, k, temp;
  402. char *q;
  403. struct crypto_ablkcipher *tfm;
  404. struct ablkcipher_request *req;
  405. struct scatterlist sg[8];
  406. const char *e;
  407. struct tcrypt_result result;
  408. void *data;
  409. char iv[MAX_IVLEN];
  410. if (enc == ENCRYPT)
  411. e = "encryption";
  412. else
  413. e = "decryption";
  414. printk("\ntesting %s %s\n", algo, e);
  415. init_completion(&result.completion);
  416. tfm = crypto_alloc_ablkcipher(algo, 0, 0);
  417. if (IS_ERR(tfm)) {
  418. printk("failed to load transform for %s: %ld\n", algo,
  419. PTR_ERR(tfm));
  420. return;
  421. }
  422. req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
  423. if (!req) {
  424. printk("failed to allocate request for %s\n", algo);
  425. goto out;
  426. }
  427. ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  428. tcrypt_complete, &result);
  429. j = 0;
  430. for (i = 0; i < tcount; i++) {
  431. data = kzalloc(template[i].ilen, GFP_KERNEL);
  432. if (!data)
  433. continue;
  434. memcpy(data, template[i].input, template[i].ilen);
  435. if (template[i].iv)
  436. memcpy(iv, template[i].iv, MAX_IVLEN);
  437. else
  438. memset(iv, 0, MAX_IVLEN);
  439. if (!(template[i].np)) {
  440. j++;
  441. printk("test %u (%d bit key):\n",
  442. j, template[i].klen * 8);
  443. crypto_ablkcipher_clear_flags(tfm, ~0);
  444. if (template[i].wk)
  445. crypto_ablkcipher_set_flags(
  446. tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  447. ret = crypto_ablkcipher_setkey(tfm, template[i].key,
  448. template[i].klen);
  449. if (ret) {
  450. printk("setkey() failed flags=%x\n",
  451. crypto_ablkcipher_get_flags(tfm));
  452. if (!template[i].fail) {
  453. kfree(data);
  454. goto out;
  455. }
  456. }
  457. sg_init_one(&sg[0], data, template[i].ilen);
  458. ablkcipher_request_set_crypt(req, sg, sg,
  459. template[i].ilen, iv);
  460. ret = enc ?
  461. crypto_ablkcipher_encrypt(req) :
  462. crypto_ablkcipher_decrypt(req);
  463. switch (ret) {
  464. case 0:
  465. break;
  466. case -EINPROGRESS:
  467. case -EBUSY:
  468. ret = wait_for_completion_interruptible(
  469. &result.completion);
  470. if (!ret && !((ret = result.err))) {
  471. INIT_COMPLETION(result.completion);
  472. break;
  473. }
  474. /* fall through */
  475. default:
  476. printk("%s () failed err=%d\n", e, -ret);
  477. kfree(data);
  478. goto out;
  479. }
  480. q = kmap(sg_page(&sg[0])) + sg[0].offset;
  481. hexdump(q, template[i].rlen);
  482. printk("%s\n",
  483. memcmp(q, template[i].result,
  484. template[i].rlen) ? "fail" : "pass");
  485. kunmap(sg_page(&sg[0]));
  486. }
  487. kfree(data);
  488. }
  489. printk("\ntesting %s %s across pages (chunking)\n", algo, e);
  490. memset(xbuf, 0, XBUFSIZE);
  491. j = 0;
  492. for (i = 0; i < tcount; i++) {
  493. data = kzalloc(template[i].ilen, GFP_KERNEL);
  494. if (!data)
  495. continue;
  496. memcpy(data, template[i].input, template[i].ilen);
  497. if (template[i].iv)
  498. memcpy(iv, template[i].iv, MAX_IVLEN);
  499. else
  500. memset(iv, 0, MAX_IVLEN);
  501. if (template[i].np) {
  502. j++;
  503. printk("test %u (%d bit key):\n",
  504. j, template[i].klen * 8);
  505. crypto_ablkcipher_clear_flags(tfm, ~0);
  506. if (template[i].wk)
  507. crypto_ablkcipher_set_flags(
  508. tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  509. ret = crypto_ablkcipher_setkey(tfm, template[i].key,
  510. template[i].klen);
  511. if (ret) {
  512. printk("setkey() failed flags=%x\n",
  513. crypto_ablkcipher_get_flags(tfm));
  514. if (!template[i].fail) {
  515. kfree(data);
  516. goto out;
  517. }
  518. }
  519. temp = 0;
  520. sg_init_table(sg, template[i].np);
  521. for (k = 0; k < template[i].np; k++) {
  522. memcpy(&xbuf[IDX[k]],
  523. template[i].input + temp,
  524. template[i].tap[k]);
  525. temp += template[i].tap[k];
  526. sg_set_buf(&sg[k], &xbuf[IDX[k]],
  527. template[i].tap[k]);
  528. }
  529. ablkcipher_request_set_crypt(req, sg, sg,
  530. template[i].ilen, iv);
  531. ret = enc ?
  532. crypto_ablkcipher_encrypt(req) :
  533. crypto_ablkcipher_decrypt(req);
  534. switch (ret) {
  535. case 0:
  536. break;
  537. case -EINPROGRESS:
  538. case -EBUSY:
  539. ret = wait_for_completion_interruptible(
  540. &result.completion);
  541. if (!ret && !((ret = result.err))) {
  542. INIT_COMPLETION(result.completion);
  543. break;
  544. }
  545. /* fall through */
  546. default:
  547. printk("%s () failed err=%d\n", e, -ret);
  548. goto out;
  549. }
  550. temp = 0;
  551. for (k = 0; k < template[i].np; k++) {
  552. printk("page %u\n", k);
  553. q = kmap(sg_page(&sg[k])) + sg[k].offset;
  554. hexdump(q, template[i].tap[k]);
  555. printk("%s\n",
  556. memcmp(q, template[i].result + temp,
  557. template[i].tap[k]) ? "fail" :
  558. "pass");
  559. temp += template[i].tap[k];
  560. kunmap(sg_page(&sg[k]));
  561. }
  562. }
  563. }
  564. out:
  565. crypto_free_ablkcipher(tfm);
  566. ablkcipher_request_free(req);
  567. }
  568. static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
  569. int blen, int sec)
  570. {
  571. struct scatterlist sg[1];
  572. unsigned long start, end;
  573. int bcount;
  574. int ret;
  575. sg_init_one(sg, p, blen);
  576. for (start = jiffies, end = start + sec * HZ, bcount = 0;
  577. time_before(jiffies, end); bcount++) {
  578. if (enc)
  579. ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
  580. else
  581. ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
  582. if (ret)
  583. return ret;
  584. }
  585. printk("%d operations in %d seconds (%ld bytes)\n",
  586. bcount, sec, (long)bcount * blen);
  587. return 0;
  588. }
  589. static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p,
  590. int blen)
  591. {
  592. struct scatterlist sg[1];
  593. unsigned long cycles = 0;
  594. int ret = 0;
  595. int i;
  596. sg_init_one(sg, p, blen);
  597. local_bh_disable();
  598. local_irq_disable();
  599. /* Warm-up run. */
  600. for (i = 0; i < 4; i++) {
  601. if (enc)
  602. ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
  603. else
  604. ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
  605. if (ret)
  606. goto out;
  607. }
  608. /* The real thing. */
  609. for (i = 0; i < 8; i++) {
  610. cycles_t start, end;
  611. start = get_cycles();
  612. if (enc)
  613. ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
  614. else
  615. ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
  616. end = get_cycles();
  617. if (ret)
  618. goto out;
  619. cycles += end - start;
  620. }
  621. out:
  622. local_irq_enable();
  623. local_bh_enable();
  624. if (ret == 0)
  625. printk("1 operation in %lu cycles (%d bytes)\n",
  626. (cycles + 4) / 8, blen);
  627. return ret;
  628. }
  629. static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
  630. static void test_cipher_speed(char *algo, int enc, unsigned int sec,
  631. struct cipher_testvec *template,
  632. unsigned int tcount, u8 *keysize)
  633. {
  634. unsigned int ret, i, j, iv_len;
  635. unsigned char *key, *p, iv[128];
  636. struct crypto_blkcipher *tfm;
  637. struct blkcipher_desc desc;
  638. const char *e;
  639. u32 *b_size;
  640. if (enc == ENCRYPT)
  641. e = "encryption";
  642. else
  643. e = "decryption";
  644. printk("\ntesting speed of %s %s\n", algo, e);
  645. tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
  646. if (IS_ERR(tfm)) {
  647. printk("failed to load transform for %s: %ld\n", algo,
  648. PTR_ERR(tfm));
  649. return;
  650. }
  651. desc.tfm = tfm;
  652. desc.flags = 0;
  653. i = 0;
  654. do {
  655. b_size = block_sizes;
  656. do {
  657. if ((*keysize + *b_size) > TVMEMSIZE) {
  658. printk("template (%u) too big for tvmem (%u)\n",
  659. *keysize + *b_size, TVMEMSIZE);
  660. goto out;
  661. }
  662. printk("test %u (%d bit key, %d byte blocks): ", i,
  663. *keysize * 8, *b_size);
  664. memset(tvmem, 0xff, *keysize + *b_size);
  665. /* set key, plain text and IV */
  666. key = (unsigned char *)tvmem;
  667. for (j = 0; j < tcount; j++) {
  668. if (template[j].klen == *keysize) {
  669. key = template[j].key;
  670. break;
  671. }
  672. }
  673. p = (unsigned char *)tvmem + *keysize;
  674. ret = crypto_blkcipher_setkey(tfm, key, *keysize);
  675. if (ret) {
  676. printk("setkey() failed flags=%x\n",
  677. crypto_blkcipher_get_flags(tfm));
  678. goto out;
  679. }
  680. iv_len = crypto_blkcipher_ivsize(tfm);
  681. if (iv_len) {
  682. memset(&iv, 0xff, iv_len);
  683. crypto_blkcipher_set_iv(tfm, iv, iv_len);
  684. }
  685. if (sec)
  686. ret = test_cipher_jiffies(&desc, enc, p, *b_size, sec);
  687. else
  688. ret = test_cipher_cycles(&desc, enc, p, *b_size);
  689. if (ret) {
  690. printk("%s() failed flags=%x\n", e, desc.flags);
  691. break;
  692. }
  693. b_size++;
  694. i++;
  695. } while (*b_size);
  696. keysize++;
  697. } while (*keysize);
  698. out:
  699. crypto_free_blkcipher(tfm);
  700. }
  701. static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen,
  702. char *out, int sec)
  703. {
  704. struct scatterlist sg[1];
  705. unsigned long start, end;
  706. int bcount;
  707. int ret;
  708. sg_init_table(sg, 1);
  709. for (start = jiffies, end = start + sec * HZ, bcount = 0;
  710. time_before(jiffies, end); bcount++) {
  711. sg_set_buf(sg, p, blen);
  712. ret = crypto_hash_digest(desc, sg, blen, out);
  713. if (ret)
  714. return ret;
  715. }
  716. printk("%6u opers/sec, %9lu bytes/sec\n",
  717. bcount / sec, ((long)bcount * blen) / sec);
  718. return 0;
  719. }
  720. static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen,
  721. int plen, char *out, int sec)
  722. {
  723. struct scatterlist sg[1];
  724. unsigned long start, end;
  725. int bcount, pcount;
  726. int ret;
  727. if (plen == blen)
  728. return test_hash_jiffies_digest(desc, p, blen, out, sec);
  729. sg_init_table(sg, 1);
  730. for (start = jiffies, end = start + sec * HZ, bcount = 0;
  731. time_before(jiffies, end); bcount++) {
  732. ret = crypto_hash_init(desc);
  733. if (ret)
  734. return ret;
  735. for (pcount = 0; pcount < blen; pcount += plen) {
  736. sg_set_buf(sg, p + pcount, plen);
  737. ret = crypto_hash_update(desc, sg, plen);
  738. if (ret)
  739. return ret;
  740. }
  741. /* we assume there is enough space in 'out' for the result */
  742. ret = crypto_hash_final(desc, out);
  743. if (ret)
  744. return ret;
  745. }
  746. printk("%6u opers/sec, %9lu bytes/sec\n",
  747. bcount / sec, ((long)bcount * blen) / sec);
  748. return 0;
  749. }
  750. static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen,
  751. char *out)
  752. {
  753. struct scatterlist sg[1];
  754. unsigned long cycles = 0;
  755. int i;
  756. int ret;
  757. sg_init_table(sg, 1);
  758. local_bh_disable();
  759. local_irq_disable();
  760. /* Warm-up run. */
  761. for (i = 0; i < 4; i++) {
  762. sg_set_buf(sg, p, blen);
  763. ret = crypto_hash_digest(desc, sg, blen, out);
  764. if (ret)
  765. goto out;
  766. }
  767. /* The real thing. */
  768. for (i = 0; i < 8; i++) {
  769. cycles_t start, end;
  770. start = get_cycles();
  771. sg_set_buf(sg, p, blen);
  772. ret = crypto_hash_digest(desc, sg, blen, out);
  773. if (ret)
  774. goto out;
  775. end = get_cycles();
  776. cycles += end - start;
  777. }
  778. out:
  779. local_irq_enable();
  780. local_bh_enable();
  781. if (ret)
  782. return ret;
  783. printk("%6lu cycles/operation, %4lu cycles/byte\n",
  784. cycles / 8, cycles / (8 * blen));
  785. return 0;
  786. }
  787. static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
  788. int plen, char *out)
  789. {
  790. struct scatterlist sg[1];
  791. unsigned long cycles = 0;
  792. int i, pcount;
  793. int ret;
  794. if (plen == blen)
  795. return test_hash_cycles_digest(desc, p, blen, out);
  796. sg_init_table(sg, 1);
  797. local_bh_disable();
  798. local_irq_disable();
  799. /* Warm-up run. */
  800. for (i = 0; i < 4; i++) {
  801. ret = crypto_hash_init(desc);
  802. if (ret)
  803. goto out;
  804. for (pcount = 0; pcount < blen; pcount += plen) {
  805. sg_set_buf(sg, p + pcount, plen);
  806. ret = crypto_hash_update(desc, sg, plen);
  807. if (ret)
  808. goto out;
  809. }
  810. ret = crypto_hash_final(desc, out);
  811. if (ret)
  812. goto out;
  813. }
  814. /* The real thing. */
  815. for (i = 0; i < 8; i++) {
  816. cycles_t start, end;
  817. start = get_cycles();
  818. ret = crypto_hash_init(desc);
  819. if (ret)
  820. goto out;
  821. for (pcount = 0; pcount < blen; pcount += plen) {
  822. sg_set_buf(sg, p + pcount, plen);
  823. ret = crypto_hash_update(desc, sg, plen);
  824. if (ret)
  825. goto out;
  826. }
  827. ret = crypto_hash_final(desc, out);
  828. if (ret)
  829. goto out;
  830. end = get_cycles();
  831. cycles += end - start;
  832. }
  833. out:
  834. local_irq_enable();
  835. local_bh_enable();
  836. if (ret)
  837. return ret;
  838. printk("%6lu cycles/operation, %4lu cycles/byte\n",
  839. cycles / 8, cycles / (8 * blen));
  840. return 0;
  841. }
  842. static void test_hash_speed(char *algo, unsigned int sec,
  843. struct hash_speed *speed)
  844. {
  845. struct crypto_hash *tfm;
  846. struct hash_desc desc;
  847. char output[1024];
  848. int i;
  849. int ret;
  850. printk("\ntesting speed of %s\n", algo);
  851. tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
  852. if (IS_ERR(tfm)) {
  853. printk("failed to load transform for %s: %ld\n", algo,
  854. PTR_ERR(tfm));
  855. return;
  856. }
  857. desc.tfm = tfm;
  858. desc.flags = 0;
  859. if (crypto_hash_digestsize(tfm) > sizeof(output)) {
  860. printk("digestsize(%u) > outputbuffer(%zu)\n",
  861. crypto_hash_digestsize(tfm), sizeof(output));
  862. goto out;
  863. }
  864. for (i = 0; speed[i].blen != 0; i++) {
  865. if (speed[i].blen > TVMEMSIZE) {
  866. printk("template (%u) too big for tvmem (%u)\n",
  867. speed[i].blen, TVMEMSIZE);
  868. goto out;
  869. }
  870. printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
  871. i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
  872. memset(tvmem, 0xff, speed[i].blen);
  873. if (sec)
  874. ret = test_hash_jiffies(&desc, tvmem, speed[i].blen,
  875. speed[i].plen, output, sec);
  876. else
  877. ret = test_hash_cycles(&desc, tvmem, speed[i].blen,
  878. speed[i].plen, output);
  879. if (ret) {
  880. printk("hashing failed ret=%d\n", ret);
  881. break;
  882. }
  883. }
  884. out:
  885. crypto_free_hash(tfm);
  886. }
  887. static void test_comp(char *algo, struct comp_testvec *ctemplate,
  888. struct comp_testvec *dtemplate, int ctcount, int dtcount)
  889. {
  890. unsigned int i;
  891. char result[COMP_BUF_SIZE];
  892. struct crypto_comp *tfm;
  893. unsigned int tsize;
  894. printk("\ntesting %s compression\n", algo);
  895. tfm = crypto_alloc_comp(algo, 0, CRYPTO_ALG_ASYNC);
  896. if (IS_ERR(tfm)) {
  897. printk("failed to load transform for %s\n", algo);
  898. return;
  899. }
  900. for (i = 0; i < ctcount; i++) {
  901. int ilen, ret, dlen = COMP_BUF_SIZE;
  902. printk("test %u:\n", i + 1);
  903. memset(result, 0, sizeof (result));
  904. ilen = ctemplate[i].inlen;
  905. ret = crypto_comp_compress(tfm, ctemplate[i].input,
  906. ilen, result, &dlen);
  907. if (ret) {
  908. printk("fail: ret=%d\n", ret);
  909. continue;
  910. }
  911. hexdump(result, dlen);
  912. printk("%s (ratio %d:%d)\n",
  913. memcmp(result, ctemplate[i].output, dlen) ? "fail" : "pass",
  914. ilen, dlen);
  915. }
  916. printk("\ntesting %s decompression\n", algo);
  917. tsize = sizeof(struct comp_testvec);
  918. tsize *= dtcount;
  919. if (tsize > TVMEMSIZE) {
  920. printk("template (%u) too big for tvmem (%u)\n", tsize,
  921. TVMEMSIZE);
  922. goto out;
  923. }
  924. for (i = 0; i < dtcount; i++) {
  925. int ilen, ret, dlen = COMP_BUF_SIZE;
  926. printk("test %u:\n", i + 1);
  927. memset(result, 0, sizeof (result));
  928. ilen = dtemplate[i].inlen;
  929. ret = crypto_comp_decompress(tfm, dtemplate[i].input,
  930. ilen, result, &dlen);
  931. if (ret) {
  932. printk("fail: ret=%d\n", ret);
  933. continue;
  934. }
  935. hexdump(result, dlen);
  936. printk("%s (ratio %d:%d)\n",
  937. memcmp(result, dtemplate[i].output, dlen) ? "fail" : "pass",
  938. ilen, dlen);
  939. }
  940. out:
  941. crypto_free_comp(tfm);
  942. }
  943. static void test_available(void)
  944. {
  945. char **name = check;
  946. while (*name) {
  947. printk("alg %s ", *name);
  948. printk(crypto_has_alg(*name, 0, 0) ?
  949. "found\n" : "not found\n");
  950. name++;
  951. }
  952. }
  953. static void do_test(void)
  954. {
  955. switch (mode) {
  956. case 0:
  957. test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
  958. test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
  959. //DES
  960. test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
  961. DES_ENC_TEST_VECTORS);
  962. test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
  963. DES_DEC_TEST_VECTORS);
  964. test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
  965. DES_CBC_ENC_TEST_VECTORS);
  966. test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
  967. DES_CBC_DEC_TEST_VECTORS);
  968. //DES3_EDE
  969. test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
  970. DES3_EDE_ENC_TEST_VECTORS);
  971. test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
  972. DES3_EDE_DEC_TEST_VECTORS);
  973. test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
  974. test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
  975. test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
  976. //BLOWFISH
  977. test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
  978. BF_ENC_TEST_VECTORS);
  979. test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
  980. BF_DEC_TEST_VECTORS);
  981. test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
  982. BF_CBC_ENC_TEST_VECTORS);
  983. test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
  984. BF_CBC_DEC_TEST_VECTORS);
  985. //TWOFISH
  986. test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
  987. TF_ENC_TEST_VECTORS);
  988. test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
  989. TF_DEC_TEST_VECTORS);
  990. test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
  991. TF_CBC_ENC_TEST_VECTORS);
  992. test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
  993. TF_CBC_DEC_TEST_VECTORS);
  994. //SERPENT
  995. test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
  996. SERPENT_ENC_TEST_VECTORS);
  997. test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
  998. SERPENT_DEC_TEST_VECTORS);
  999. //TNEPRES
  1000. test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
  1001. TNEPRES_ENC_TEST_VECTORS);
  1002. test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
  1003. TNEPRES_DEC_TEST_VECTORS);
  1004. //AES
  1005. test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
  1006. AES_ENC_TEST_VECTORS);
  1007. test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
  1008. AES_DEC_TEST_VECTORS);
  1009. test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
  1010. AES_CBC_ENC_TEST_VECTORS);
  1011. test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
  1012. AES_CBC_DEC_TEST_VECTORS);
  1013. test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
  1014. AES_LRW_ENC_TEST_VECTORS);
  1015. test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
  1016. AES_LRW_DEC_TEST_VECTORS);
  1017. test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
  1018. AES_XTS_ENC_TEST_VECTORS);
  1019. test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
  1020. AES_XTS_DEC_TEST_VECTORS);
  1021. test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
  1022. AES_CTR_ENC_TEST_VECTORS);
  1023. test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
  1024. AES_CTR_DEC_TEST_VECTORS);
  1025. test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
  1026. AES_GCM_ENC_TEST_VECTORS);
  1027. test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
  1028. AES_GCM_DEC_TEST_VECTORS);
  1029. test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template,
  1030. AES_CCM_ENC_TEST_VECTORS);
  1031. test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template,
  1032. AES_CCM_DEC_TEST_VECTORS);
  1033. //CAST5
  1034. test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
  1035. CAST5_ENC_TEST_VECTORS);
  1036. test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
  1037. CAST5_DEC_TEST_VECTORS);
  1038. //CAST6
  1039. test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
  1040. CAST6_ENC_TEST_VECTORS);
  1041. test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
  1042. CAST6_DEC_TEST_VECTORS);
  1043. //ARC4
  1044. test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
  1045. ARC4_ENC_TEST_VECTORS);
  1046. test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
  1047. ARC4_DEC_TEST_VECTORS);
  1048. //TEA
  1049. test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
  1050. TEA_ENC_TEST_VECTORS);
  1051. test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
  1052. TEA_DEC_TEST_VECTORS);
  1053. //XTEA
  1054. test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
  1055. XTEA_ENC_TEST_VECTORS);
  1056. test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
  1057. XTEA_DEC_TEST_VECTORS);
  1058. //KHAZAD
  1059. test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
  1060. KHAZAD_ENC_TEST_VECTORS);
  1061. test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
  1062. KHAZAD_DEC_TEST_VECTORS);
  1063. //ANUBIS
  1064. test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
  1065. ANUBIS_ENC_TEST_VECTORS);
  1066. test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
  1067. ANUBIS_DEC_TEST_VECTORS);
  1068. test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
  1069. ANUBIS_CBC_ENC_TEST_VECTORS);
  1070. test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
  1071. ANUBIS_CBC_ENC_TEST_VECTORS);
  1072. //XETA
  1073. test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
  1074. XETA_ENC_TEST_VECTORS);
  1075. test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
  1076. XETA_DEC_TEST_VECTORS);
  1077. //FCrypt
  1078. test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
  1079. FCRYPT_ENC_TEST_VECTORS);
  1080. test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
  1081. FCRYPT_DEC_TEST_VECTORS);
  1082. //CAMELLIA
  1083. test_cipher("ecb(camellia)", ENCRYPT,
  1084. camellia_enc_tv_template,
  1085. CAMELLIA_ENC_TEST_VECTORS);
  1086. test_cipher("ecb(camellia)", DECRYPT,
  1087. camellia_dec_tv_template,
  1088. CAMELLIA_DEC_TEST_VECTORS);
  1089. test_cipher("cbc(camellia)", ENCRYPT,
  1090. camellia_cbc_enc_tv_template,
  1091. CAMELLIA_CBC_ENC_TEST_VECTORS);
  1092. test_cipher("cbc(camellia)", DECRYPT,
  1093. camellia_cbc_dec_tv_template,
  1094. CAMELLIA_CBC_DEC_TEST_VECTORS);
  1095. //SEED
  1096. test_cipher("ecb(seed)", ENCRYPT, seed_enc_tv_template,
  1097. SEED_ENC_TEST_VECTORS);
  1098. test_cipher("ecb(seed)", DECRYPT, seed_dec_tv_template,
  1099. SEED_DEC_TEST_VECTORS);
  1100. //CTS
  1101. test_cipher("cts(cbc(aes))", ENCRYPT, cts_mode_enc_tv_template,
  1102. CTS_MODE_ENC_TEST_VECTORS);
  1103. test_cipher("cts(cbc(aes))", DECRYPT, cts_mode_dec_tv_template,
  1104. CTS_MODE_DEC_TEST_VECTORS);
  1105. test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
  1106. test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
  1107. test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
  1108. test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
  1109. test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
  1110. test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
  1111. test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
  1112. test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
  1113. test_comp("deflate", deflate_comp_tv_template,
  1114. deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
  1115. DEFLATE_DECOMP_TEST_VECTORS);
  1116. test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template,
  1117. LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
  1118. test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
  1119. test_hash("hmac(md5)", hmac_md5_tv_template,
  1120. HMAC_MD5_TEST_VECTORS);
  1121. test_hash("hmac(sha1)", hmac_sha1_tv_template,
  1122. HMAC_SHA1_TEST_VECTORS);
  1123. test_hash("hmac(sha224)", hmac_sha224_tv_template,
  1124. HMAC_SHA224_TEST_VECTORS);
  1125. test_hash("hmac(sha256)", hmac_sha256_tv_template,
  1126. HMAC_SHA256_TEST_VECTORS);
  1127. test_hash("hmac(sha384)", hmac_sha384_tv_template,
  1128. HMAC_SHA384_TEST_VECTORS);
  1129. test_hash("hmac(sha512)", hmac_sha512_tv_template,
  1130. HMAC_SHA512_TEST_VECTORS);
  1131. test_hash("xcbc(aes)", aes_xcbc128_tv_template,
  1132. XCBC_AES_TEST_VECTORS);
  1133. test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
  1134. break;
  1135. case 1:
  1136. test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
  1137. break;
  1138. case 2:
  1139. test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
  1140. break;
  1141. case 3:
  1142. test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
  1143. DES_ENC_TEST_VECTORS);
  1144. test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
  1145. DES_DEC_TEST_VECTORS);
  1146. test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
  1147. DES_CBC_ENC_TEST_VECTORS);
  1148. test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
  1149. DES_CBC_DEC_TEST_VECTORS);
  1150. break;
  1151. case 4:
  1152. test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
  1153. DES3_EDE_ENC_TEST_VECTORS);
  1154. test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
  1155. DES3_EDE_DEC_TEST_VECTORS);
  1156. break;
  1157. case 5:
  1158. test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
  1159. break;
  1160. case 6:
  1161. test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
  1162. break;
  1163. case 7:
  1164. test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
  1165. BF_ENC_TEST_VECTORS);
  1166. test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
  1167. BF_DEC_TEST_VECTORS);
  1168. test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
  1169. BF_CBC_ENC_TEST_VECTORS);
  1170. test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
  1171. BF_CBC_DEC_TEST_VECTORS);
  1172. break;
  1173. case 8:
  1174. test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
  1175. TF_ENC_TEST_VECTORS);
  1176. test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
  1177. TF_DEC_TEST_VECTORS);
  1178. test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
  1179. TF_CBC_ENC_TEST_VECTORS);
  1180. test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
  1181. TF_CBC_DEC_TEST_VECTORS);
  1182. break;
  1183. case 9:
  1184. test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
  1185. SERPENT_ENC_TEST_VECTORS);
  1186. test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
  1187. SERPENT_DEC_TEST_VECTORS);
  1188. break;
  1189. case 10:
  1190. test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
  1191. AES_ENC_TEST_VECTORS);
  1192. test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
  1193. AES_DEC_TEST_VECTORS);
  1194. test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
  1195. AES_CBC_ENC_TEST_VECTORS);
  1196. test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
  1197. AES_CBC_DEC_TEST_VECTORS);
  1198. test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
  1199. AES_LRW_ENC_TEST_VECTORS);
  1200. test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
  1201. AES_LRW_DEC_TEST_VECTORS);
  1202. test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
  1203. AES_XTS_ENC_TEST_VECTORS);
  1204. test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
  1205. AES_XTS_DEC_TEST_VECTORS);
  1206. test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
  1207. AES_CTR_ENC_TEST_VECTORS);
  1208. test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
  1209. AES_CTR_DEC_TEST_VECTORS);
  1210. break;
  1211. case 11:
  1212. test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
  1213. break;
  1214. case 12:
  1215. test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
  1216. break;
  1217. case 13:
  1218. test_comp("deflate", deflate_comp_tv_template,
  1219. deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
  1220. DEFLATE_DECOMP_TEST_VECTORS);
  1221. break;
  1222. case 14:
  1223. test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
  1224. CAST5_ENC_TEST_VECTORS);
  1225. test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
  1226. CAST5_DEC_TEST_VECTORS);
  1227. break;
  1228. case 15:
  1229. test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
  1230. CAST6_ENC_TEST_VECTORS);
  1231. test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
  1232. CAST6_DEC_TEST_VECTORS);
  1233. break;
  1234. case 16:
  1235. test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
  1236. ARC4_ENC_TEST_VECTORS);
  1237. test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
  1238. ARC4_DEC_TEST_VECTORS);
  1239. break;
  1240. case 17:
  1241. test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
  1242. break;
  1243. case 18:
  1244. test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
  1245. break;
  1246. case 19:
  1247. test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
  1248. TEA_ENC_TEST_VECTORS);
  1249. test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
  1250. TEA_DEC_TEST_VECTORS);
  1251. break;
  1252. case 20:
  1253. test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
  1254. XTEA_ENC_TEST_VECTORS);
  1255. test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
  1256. XTEA_DEC_TEST_VECTORS);
  1257. break;
  1258. case 21:
  1259. test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
  1260. KHAZAD_ENC_TEST_VECTORS);
  1261. test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
  1262. KHAZAD_DEC_TEST_VECTORS);
  1263. break;
  1264. case 22:
  1265. test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
  1266. break;
  1267. case 23:
  1268. test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
  1269. break;
  1270. case 24:
  1271. test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
  1272. break;
  1273. case 25:
  1274. test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
  1275. TNEPRES_ENC_TEST_VECTORS);
  1276. test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
  1277. TNEPRES_DEC_TEST_VECTORS);
  1278. break;
  1279. case 26:
  1280. test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
  1281. ANUBIS_ENC_TEST_VECTORS);
  1282. test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
  1283. ANUBIS_DEC_TEST_VECTORS);
  1284. test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
  1285. ANUBIS_CBC_ENC_TEST_VECTORS);
  1286. test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
  1287. ANUBIS_CBC_ENC_TEST_VECTORS);
  1288. break;
  1289. case 27:
  1290. test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
  1291. break;
  1292. case 28:
  1293. test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
  1294. break;
  1295. case 29:
  1296. test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
  1297. break;
  1298. case 30:
  1299. test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
  1300. XETA_ENC_TEST_VECTORS);
  1301. test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
  1302. XETA_DEC_TEST_VECTORS);
  1303. break;
  1304. case 31:
  1305. test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
  1306. FCRYPT_ENC_TEST_VECTORS);
  1307. test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
  1308. FCRYPT_DEC_TEST_VECTORS);
  1309. break;
  1310. case 32:
  1311. test_cipher("ecb(camellia)", ENCRYPT,
  1312. camellia_enc_tv_template,
  1313. CAMELLIA_ENC_TEST_VECTORS);
  1314. test_cipher("ecb(camellia)", DECRYPT,
  1315. camellia_dec_tv_template,
  1316. CAMELLIA_DEC_TEST_VECTORS);
  1317. test_cipher("cbc(camellia)", ENCRYPT,
  1318. camellia_cbc_enc_tv_template,
  1319. CAMELLIA_CBC_ENC_TEST_VECTORS);
  1320. test_cipher("cbc(camellia)", DECRYPT,
  1321. camellia_cbc_dec_tv_template,
  1322. CAMELLIA_CBC_DEC_TEST_VECTORS);
  1323. break;
  1324. case 33:
  1325. test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
  1326. break;
  1327. case 34:
  1328. test_cipher("salsa20", ENCRYPT,
  1329. salsa20_stream_enc_tv_template,
  1330. SALSA20_STREAM_ENC_TEST_VECTORS);
  1331. break;
  1332. case 35:
  1333. test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
  1334. AES_GCM_ENC_TEST_VECTORS);
  1335. test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
  1336. AES_GCM_DEC_TEST_VECTORS);
  1337. break;
  1338. case 36:
  1339. test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template,
  1340. LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
  1341. break;
  1342. case 37:
  1343. test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template,
  1344. AES_CCM_ENC_TEST_VECTORS);
  1345. test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template,
  1346. AES_CCM_DEC_TEST_VECTORS);
  1347. break;
  1348. case 38:
  1349. test_cipher("cts(cbc(aes))", ENCRYPT, cts_mode_enc_tv_template,
  1350. CTS_MODE_ENC_TEST_VECTORS);
  1351. test_cipher("cts(cbc(aes))", DECRYPT, cts_mode_dec_tv_template,
  1352. CTS_MODE_DEC_TEST_VECTORS);
  1353. break;
  1354. case 100:
  1355. test_hash("hmac(md5)", hmac_md5_tv_template,
  1356. HMAC_MD5_TEST_VECTORS);
  1357. break;
  1358. case 101:
  1359. test_hash("hmac(sha1)", hmac_sha1_tv_template,
  1360. HMAC_SHA1_TEST_VECTORS);
  1361. break;
  1362. case 102:
  1363. test_hash("hmac(sha256)", hmac_sha256_tv_template,
  1364. HMAC_SHA256_TEST_VECTORS);
  1365. break;
  1366. case 103:
  1367. test_hash("hmac(sha384)", hmac_sha384_tv_template,
  1368. HMAC_SHA384_TEST_VECTORS);
  1369. break;
  1370. case 104:
  1371. test_hash("hmac(sha512)", hmac_sha512_tv_template,
  1372. HMAC_SHA512_TEST_VECTORS);
  1373. break;
  1374. case 105:
  1375. test_hash("hmac(sha224)", hmac_sha224_tv_template,
  1376. HMAC_SHA224_TEST_VECTORS);
  1377. break;
  1378. case 106:
  1379. test_hash("xcbc(aes)", aes_xcbc128_tv_template,
  1380. XCBC_AES_TEST_VECTORS);
  1381. break;
  1382. case 200:
  1383. test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
  1384. speed_template_16_24_32);
  1385. test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
  1386. speed_template_16_24_32);
  1387. test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
  1388. speed_template_16_24_32);
  1389. test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
  1390. speed_template_16_24_32);
  1391. test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
  1392. speed_template_32_40_48);
  1393. test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
  1394. speed_template_32_40_48);
  1395. test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
  1396. speed_template_32_48_64);
  1397. test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
  1398. speed_template_32_48_64);
  1399. break;
  1400. case 201:
  1401. test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
  1402. des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
  1403. speed_template_24);
  1404. test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
  1405. des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
  1406. speed_template_24);
  1407. test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
  1408. des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
  1409. speed_template_24);
  1410. test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
  1411. des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
  1412. speed_template_24);
  1413. break;
  1414. case 202:
  1415. test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
  1416. speed_template_16_24_32);
  1417. test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
  1418. speed_template_16_24_32);
  1419. test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
  1420. speed_template_16_24_32);
  1421. test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
  1422. speed_template_16_24_32);
  1423. break;
  1424. case 203:
  1425. test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
  1426. speed_template_8_32);
  1427. test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
  1428. speed_template_8_32);
  1429. test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
  1430. speed_template_8_32);
  1431. test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
  1432. speed_template_8_32);
  1433. break;
  1434. case 204:
  1435. test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
  1436. speed_template_8);
  1437. test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
  1438. speed_template_8);
  1439. test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
  1440. speed_template_8);
  1441. test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
  1442. speed_template_8);
  1443. break;
  1444. case 205:
  1445. test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
  1446. speed_template_16_24_32);
  1447. test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
  1448. speed_template_16_24_32);
  1449. test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
  1450. speed_template_16_24_32);
  1451. test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
  1452. speed_template_16_24_32);
  1453. break;
  1454. case 206:
  1455. test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
  1456. speed_template_16_32);
  1457. break;
  1458. case 300:
  1459. /* fall through */
  1460. case 301:
  1461. test_hash_speed("md4", sec, generic_hash_speed_template);
  1462. if (mode > 300 && mode < 400) break;
  1463. case 302:
  1464. test_hash_speed("md5", sec, generic_hash_speed_template);
  1465. if (mode > 300 && mode < 400) break;
  1466. case 303:
  1467. test_hash_speed("sha1", sec, generic_hash_speed_template);
  1468. if (mode > 300 && mode < 400) break;
  1469. case 304:
  1470. test_hash_speed("sha256", sec, generic_hash_speed_template);
  1471. if (mode > 300 && mode < 400) break;
  1472. case 305:
  1473. test_hash_speed("sha384", sec, generic_hash_speed_template);
  1474. if (mode > 300 && mode < 400) break;
  1475. case 306:
  1476. test_hash_speed("sha512", sec, generic_hash_speed_template);
  1477. if (mode > 300 && mode < 400) break;
  1478. case 307:
  1479. test_hash_speed("wp256", sec, generic_hash_speed_template);
  1480. if (mode > 300 && mode < 400) break;
  1481. case 308:
  1482. test_hash_speed("wp384", sec, generic_hash_speed_template);
  1483. if (mode > 300 && mode < 400) break;
  1484. case 309:
  1485. test_hash_speed("wp512", sec, generic_hash_speed_template);
  1486. if (mode > 300 && mode < 400) break;
  1487. case 310:
  1488. test_hash_speed("tgr128", sec, generic_hash_speed_template);
  1489. if (mode > 300 && mode < 400) break;
  1490. case 311:
  1491. test_hash_speed("tgr160", sec, generic_hash_speed_template);
  1492. if (mode > 300 && mode < 400) break;
  1493. case 312:
  1494. test_hash_speed("tgr192", sec, generic_hash_speed_template);
  1495. if (mode > 300 && mode < 400) break;
  1496. case 313:
  1497. test_hash_speed("sha224", sec, generic_hash_speed_template);
  1498. if (mode > 300 && mode < 400) break;
  1499. case 399:
  1500. break;
  1501. case 1000:
  1502. test_available();
  1503. break;
  1504. default:
  1505. /* useful for debugging */
  1506. printk("not testing anything\n");
  1507. break;
  1508. }
  1509. }
  1510. static int __init tcrypt_mod_init(void)
  1511. {
  1512. int err = -ENOMEM;
  1513. tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
  1514. if (tvmem == NULL)
  1515. return err;
  1516. xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
  1517. if (xbuf == NULL)
  1518. goto err_free_tv;
  1519. axbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
  1520. if (axbuf == NULL)
  1521. goto err_free_xbuf;
  1522. do_test();
  1523. /* We intentionaly return -EAGAIN to prevent keeping
  1524. * the module. It does all its work from init()
  1525. * and doesn't offer any runtime functionality
  1526. * => we don't need it in the memory, do we?
  1527. * -- mludvig
  1528. */
  1529. err = -EAGAIN;
  1530. kfree(axbuf);
  1531. err_free_xbuf:
  1532. kfree(xbuf);
  1533. err_free_tv:
  1534. kfree(tvmem);
  1535. return err;
  1536. }
  1537. /*
  1538. * If an init function is provided, an exit function must also be provided
  1539. * to allow module unload.
  1540. */
  1541. static void __exit tcrypt_mod_fini(void) { }
  1542. module_init(tcrypt_mod_init);
  1543. module_exit(tcrypt_mod_fini);
  1544. module_param(mode, int, 0);
  1545. module_param(sec, uint, 0);
  1546. MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
  1547. "(defaults to zero which uses CPU cycles instead)");
  1548. MODULE_LICENSE("GPL");
  1549. MODULE_DESCRIPTION("Quick & dirty crypto testing module");
  1550. MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");