tcrypt.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856
  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. if (template[i].iv)
  494. memcpy(iv, template[i].iv, MAX_IVLEN);
  495. else
  496. memset(iv, 0, MAX_IVLEN);
  497. if (template[i].np) {
  498. j++;
  499. printk("test %u (%d bit key):\n",
  500. j, template[i].klen * 8);
  501. crypto_ablkcipher_clear_flags(tfm, ~0);
  502. if (template[i].wk)
  503. crypto_ablkcipher_set_flags(
  504. tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  505. ret = crypto_ablkcipher_setkey(tfm, template[i].key,
  506. template[i].klen);
  507. if (ret) {
  508. printk("setkey() failed flags=%x\n",
  509. crypto_ablkcipher_get_flags(tfm));
  510. if (!template[i].fail)
  511. goto out;
  512. }
  513. temp = 0;
  514. sg_init_table(sg, template[i].np);
  515. for (k = 0; k < template[i].np; k++) {
  516. memcpy(&xbuf[IDX[k]],
  517. template[i].input + temp,
  518. template[i].tap[k]);
  519. temp += template[i].tap[k];
  520. sg_set_buf(&sg[k], &xbuf[IDX[k]],
  521. template[i].tap[k]);
  522. }
  523. ablkcipher_request_set_crypt(req, sg, sg,
  524. template[i].ilen, iv);
  525. ret = enc ?
  526. crypto_ablkcipher_encrypt(req) :
  527. crypto_ablkcipher_decrypt(req);
  528. switch (ret) {
  529. case 0:
  530. break;
  531. case -EINPROGRESS:
  532. case -EBUSY:
  533. ret = wait_for_completion_interruptible(
  534. &result.completion);
  535. if (!ret && !((ret = result.err))) {
  536. INIT_COMPLETION(result.completion);
  537. break;
  538. }
  539. /* fall through */
  540. default:
  541. printk("%s () failed err=%d\n", e, -ret);
  542. goto out;
  543. }
  544. temp = 0;
  545. for (k = 0; k < template[i].np; k++) {
  546. printk("page %u\n", k);
  547. q = kmap(sg_page(&sg[k])) + sg[k].offset;
  548. hexdump(q, template[i].tap[k]);
  549. printk("%s\n",
  550. memcmp(q, template[i].result + temp,
  551. template[i].tap[k]) ? "fail" :
  552. "pass");
  553. temp += template[i].tap[k];
  554. kunmap(sg_page(&sg[k]));
  555. }
  556. }
  557. }
  558. out:
  559. crypto_free_ablkcipher(tfm);
  560. ablkcipher_request_free(req);
  561. }
  562. static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
  563. int blen, int sec)
  564. {
  565. struct scatterlist sg[1];
  566. unsigned long start, end;
  567. int bcount;
  568. int ret;
  569. sg_init_one(sg, p, blen);
  570. for (start = jiffies, end = start + sec * HZ, bcount = 0;
  571. time_before(jiffies, end); bcount++) {
  572. if (enc)
  573. ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
  574. else
  575. ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
  576. if (ret)
  577. return ret;
  578. }
  579. printk("%d operations in %d seconds (%ld bytes)\n",
  580. bcount, sec, (long)bcount * blen);
  581. return 0;
  582. }
  583. static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p,
  584. int blen)
  585. {
  586. struct scatterlist sg[1];
  587. unsigned long cycles = 0;
  588. int ret = 0;
  589. int i;
  590. sg_init_one(sg, p, blen);
  591. local_bh_disable();
  592. local_irq_disable();
  593. /* Warm-up run. */
  594. for (i = 0; i < 4; i++) {
  595. if (enc)
  596. ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
  597. else
  598. ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
  599. if (ret)
  600. goto out;
  601. }
  602. /* The real thing. */
  603. for (i = 0; i < 8; i++) {
  604. cycles_t start, end;
  605. start = get_cycles();
  606. if (enc)
  607. ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
  608. else
  609. ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
  610. end = get_cycles();
  611. if (ret)
  612. goto out;
  613. cycles += end - start;
  614. }
  615. out:
  616. local_irq_enable();
  617. local_bh_enable();
  618. if (ret == 0)
  619. printk("1 operation in %lu cycles (%d bytes)\n",
  620. (cycles + 4) / 8, blen);
  621. return ret;
  622. }
  623. static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
  624. static void test_cipher_speed(char *algo, int enc, unsigned int sec,
  625. struct cipher_testvec *template,
  626. unsigned int tcount, u8 *keysize)
  627. {
  628. unsigned int ret, i, j, iv_len;
  629. unsigned char *key, *p, iv[128];
  630. struct crypto_blkcipher *tfm;
  631. struct blkcipher_desc desc;
  632. const char *e;
  633. u32 *b_size;
  634. if (enc == ENCRYPT)
  635. e = "encryption";
  636. else
  637. e = "decryption";
  638. printk("\ntesting speed of %s %s\n", algo, e);
  639. tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
  640. if (IS_ERR(tfm)) {
  641. printk("failed to load transform for %s: %ld\n", algo,
  642. PTR_ERR(tfm));
  643. return;
  644. }
  645. desc.tfm = tfm;
  646. desc.flags = 0;
  647. i = 0;
  648. do {
  649. b_size = block_sizes;
  650. do {
  651. if ((*keysize + *b_size) > TVMEMSIZE) {
  652. printk("template (%u) too big for tvmem (%u)\n",
  653. *keysize + *b_size, TVMEMSIZE);
  654. goto out;
  655. }
  656. printk("test %u (%d bit key, %d byte blocks): ", i,
  657. *keysize * 8, *b_size);
  658. memset(tvmem, 0xff, *keysize + *b_size);
  659. /* set key, plain text and IV */
  660. key = (unsigned char *)tvmem;
  661. for (j = 0; j < tcount; j++) {
  662. if (template[j].klen == *keysize) {
  663. key = template[j].key;
  664. break;
  665. }
  666. }
  667. p = (unsigned char *)tvmem + *keysize;
  668. ret = crypto_blkcipher_setkey(tfm, key, *keysize);
  669. if (ret) {
  670. printk("setkey() failed flags=%x\n",
  671. crypto_blkcipher_get_flags(tfm));
  672. goto out;
  673. }
  674. iv_len = crypto_blkcipher_ivsize(tfm);
  675. if (iv_len) {
  676. memset(&iv, 0xff, iv_len);
  677. crypto_blkcipher_set_iv(tfm, iv, iv_len);
  678. }
  679. if (sec)
  680. ret = test_cipher_jiffies(&desc, enc, p, *b_size, sec);
  681. else
  682. ret = test_cipher_cycles(&desc, enc, p, *b_size);
  683. if (ret) {
  684. printk("%s() failed flags=%x\n", e, desc.flags);
  685. break;
  686. }
  687. b_size++;
  688. i++;
  689. } while (*b_size);
  690. keysize++;
  691. } while (*keysize);
  692. out:
  693. crypto_free_blkcipher(tfm);
  694. }
  695. static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen,
  696. char *out, int sec)
  697. {
  698. struct scatterlist sg[1];
  699. unsigned long start, end;
  700. int bcount;
  701. int ret;
  702. sg_init_table(sg, 1);
  703. for (start = jiffies, end = start + sec * HZ, bcount = 0;
  704. time_before(jiffies, end); bcount++) {
  705. sg_set_buf(sg, p, blen);
  706. ret = crypto_hash_digest(desc, sg, blen, out);
  707. if (ret)
  708. return ret;
  709. }
  710. printk("%6u opers/sec, %9lu bytes/sec\n",
  711. bcount / sec, ((long)bcount * blen) / sec);
  712. return 0;
  713. }
  714. static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen,
  715. int plen, char *out, int sec)
  716. {
  717. struct scatterlist sg[1];
  718. unsigned long start, end;
  719. int bcount, pcount;
  720. int ret;
  721. if (plen == blen)
  722. return test_hash_jiffies_digest(desc, p, blen, out, sec);
  723. sg_init_table(sg, 1);
  724. for (start = jiffies, end = start + sec * HZ, bcount = 0;
  725. time_before(jiffies, end); bcount++) {
  726. ret = crypto_hash_init(desc);
  727. if (ret)
  728. return ret;
  729. for (pcount = 0; pcount < blen; pcount += plen) {
  730. sg_set_buf(sg, p + pcount, plen);
  731. ret = crypto_hash_update(desc, sg, plen);
  732. if (ret)
  733. return ret;
  734. }
  735. /* we assume there is enough space in 'out' for the result */
  736. ret = crypto_hash_final(desc, out);
  737. if (ret)
  738. return ret;
  739. }
  740. printk("%6u opers/sec, %9lu bytes/sec\n",
  741. bcount / sec, ((long)bcount * blen) / sec);
  742. return 0;
  743. }
  744. static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen,
  745. char *out)
  746. {
  747. struct scatterlist sg[1];
  748. unsigned long cycles = 0;
  749. int i;
  750. int ret;
  751. sg_init_table(sg, 1);
  752. local_bh_disable();
  753. local_irq_disable();
  754. /* Warm-up run. */
  755. for (i = 0; i < 4; i++) {
  756. sg_set_buf(sg, p, blen);
  757. ret = crypto_hash_digest(desc, sg, blen, out);
  758. if (ret)
  759. goto out;
  760. }
  761. /* The real thing. */
  762. for (i = 0; i < 8; i++) {
  763. cycles_t start, end;
  764. start = get_cycles();
  765. sg_set_buf(sg, p, blen);
  766. ret = crypto_hash_digest(desc, sg, blen, out);
  767. if (ret)
  768. goto out;
  769. end = get_cycles();
  770. cycles += end - start;
  771. }
  772. out:
  773. local_irq_enable();
  774. local_bh_enable();
  775. if (ret)
  776. return ret;
  777. printk("%6lu cycles/operation, %4lu cycles/byte\n",
  778. cycles / 8, cycles / (8 * blen));
  779. return 0;
  780. }
  781. static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
  782. int plen, char *out)
  783. {
  784. struct scatterlist sg[1];
  785. unsigned long cycles = 0;
  786. int i, pcount;
  787. int ret;
  788. if (plen == blen)
  789. return test_hash_cycles_digest(desc, p, blen, out);
  790. sg_init_table(sg, 1);
  791. local_bh_disable();
  792. local_irq_disable();
  793. /* Warm-up run. */
  794. for (i = 0; i < 4; i++) {
  795. ret = crypto_hash_init(desc);
  796. if (ret)
  797. goto out;
  798. for (pcount = 0; pcount < blen; pcount += plen) {
  799. sg_set_buf(sg, p + pcount, plen);
  800. ret = crypto_hash_update(desc, sg, plen);
  801. if (ret)
  802. goto out;
  803. }
  804. ret = crypto_hash_final(desc, out);
  805. if (ret)
  806. goto out;
  807. }
  808. /* The real thing. */
  809. for (i = 0; i < 8; i++) {
  810. cycles_t start, end;
  811. start = get_cycles();
  812. ret = crypto_hash_init(desc);
  813. if (ret)
  814. goto out;
  815. for (pcount = 0; pcount < blen; pcount += plen) {
  816. sg_set_buf(sg, p + pcount, plen);
  817. ret = crypto_hash_update(desc, sg, plen);
  818. if (ret)
  819. goto out;
  820. }
  821. ret = crypto_hash_final(desc, out);
  822. if (ret)
  823. goto out;
  824. end = get_cycles();
  825. cycles += end - start;
  826. }
  827. out:
  828. local_irq_enable();
  829. local_bh_enable();
  830. if (ret)
  831. return ret;
  832. printk("%6lu cycles/operation, %4lu cycles/byte\n",
  833. cycles / 8, cycles / (8 * blen));
  834. return 0;
  835. }
  836. static void test_hash_speed(char *algo, unsigned int sec,
  837. struct hash_speed *speed)
  838. {
  839. struct crypto_hash *tfm;
  840. struct hash_desc desc;
  841. char output[1024];
  842. int i;
  843. int ret;
  844. printk("\ntesting speed of %s\n", algo);
  845. tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
  846. if (IS_ERR(tfm)) {
  847. printk("failed to load transform for %s: %ld\n", algo,
  848. PTR_ERR(tfm));
  849. return;
  850. }
  851. desc.tfm = tfm;
  852. desc.flags = 0;
  853. if (crypto_hash_digestsize(tfm) > sizeof(output)) {
  854. printk("digestsize(%u) > outputbuffer(%zu)\n",
  855. crypto_hash_digestsize(tfm), sizeof(output));
  856. goto out;
  857. }
  858. for (i = 0; speed[i].blen != 0; i++) {
  859. if (speed[i].blen > TVMEMSIZE) {
  860. printk("template (%u) too big for tvmem (%u)\n",
  861. speed[i].blen, TVMEMSIZE);
  862. goto out;
  863. }
  864. printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
  865. i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
  866. memset(tvmem, 0xff, speed[i].blen);
  867. if (sec)
  868. ret = test_hash_jiffies(&desc, tvmem, speed[i].blen,
  869. speed[i].plen, output, sec);
  870. else
  871. ret = test_hash_cycles(&desc, tvmem, speed[i].blen,
  872. speed[i].plen, output);
  873. if (ret) {
  874. printk("hashing failed ret=%d\n", ret);
  875. break;
  876. }
  877. }
  878. out:
  879. crypto_free_hash(tfm);
  880. }
  881. static void test_comp(char *algo, struct comp_testvec *ctemplate,
  882. struct comp_testvec *dtemplate, int ctcount, int dtcount)
  883. {
  884. unsigned int i;
  885. char result[COMP_BUF_SIZE];
  886. struct crypto_comp *tfm;
  887. unsigned int tsize;
  888. printk("\ntesting %s compression\n", algo);
  889. tfm = crypto_alloc_comp(algo, 0, CRYPTO_ALG_ASYNC);
  890. if (IS_ERR(tfm)) {
  891. printk("failed to load transform for %s\n", algo);
  892. return;
  893. }
  894. for (i = 0; i < ctcount; i++) {
  895. int ilen, ret, dlen = COMP_BUF_SIZE;
  896. printk("test %u:\n", i + 1);
  897. memset(result, 0, sizeof (result));
  898. ilen = ctemplate[i].inlen;
  899. ret = crypto_comp_compress(tfm, ctemplate[i].input,
  900. ilen, result, &dlen);
  901. if (ret) {
  902. printk("fail: ret=%d\n", ret);
  903. continue;
  904. }
  905. hexdump(result, dlen);
  906. printk("%s (ratio %d:%d)\n",
  907. memcmp(result, ctemplate[i].output, dlen) ? "fail" : "pass",
  908. ilen, dlen);
  909. }
  910. printk("\ntesting %s decompression\n", algo);
  911. tsize = sizeof(struct comp_testvec);
  912. tsize *= dtcount;
  913. if (tsize > TVMEMSIZE) {
  914. printk("template (%u) too big for tvmem (%u)\n", tsize,
  915. TVMEMSIZE);
  916. goto out;
  917. }
  918. for (i = 0; i < dtcount; i++) {
  919. int ilen, ret, dlen = COMP_BUF_SIZE;
  920. printk("test %u:\n", i + 1);
  921. memset(result, 0, sizeof (result));
  922. ilen = dtemplate[i].inlen;
  923. ret = crypto_comp_decompress(tfm, dtemplate[i].input,
  924. ilen, result, &dlen);
  925. if (ret) {
  926. printk("fail: ret=%d\n", ret);
  927. continue;
  928. }
  929. hexdump(result, dlen);
  930. printk("%s (ratio %d:%d)\n",
  931. memcmp(result, dtemplate[i].output, dlen) ? "fail" : "pass",
  932. ilen, dlen);
  933. }
  934. out:
  935. crypto_free_comp(tfm);
  936. }
  937. static void test_available(void)
  938. {
  939. char **name = check;
  940. while (*name) {
  941. printk("alg %s ", *name);
  942. printk(crypto_has_alg(*name, 0, 0) ?
  943. "found\n" : "not found\n");
  944. name++;
  945. }
  946. }
  947. static void do_test(void)
  948. {
  949. switch (mode) {
  950. case 0:
  951. test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
  952. test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
  953. //DES
  954. test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
  955. DES_ENC_TEST_VECTORS);
  956. test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
  957. DES_DEC_TEST_VECTORS);
  958. test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
  959. DES_CBC_ENC_TEST_VECTORS);
  960. test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
  961. DES_CBC_DEC_TEST_VECTORS);
  962. //DES3_EDE
  963. test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
  964. DES3_EDE_ENC_TEST_VECTORS);
  965. test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
  966. DES3_EDE_DEC_TEST_VECTORS);
  967. test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
  968. test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
  969. test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
  970. //BLOWFISH
  971. test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
  972. BF_ENC_TEST_VECTORS);
  973. test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
  974. BF_DEC_TEST_VECTORS);
  975. test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
  976. BF_CBC_ENC_TEST_VECTORS);
  977. test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
  978. BF_CBC_DEC_TEST_VECTORS);
  979. //TWOFISH
  980. test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
  981. TF_ENC_TEST_VECTORS);
  982. test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
  983. TF_DEC_TEST_VECTORS);
  984. test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
  985. TF_CBC_ENC_TEST_VECTORS);
  986. test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
  987. TF_CBC_DEC_TEST_VECTORS);
  988. //SERPENT
  989. test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
  990. SERPENT_ENC_TEST_VECTORS);
  991. test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
  992. SERPENT_DEC_TEST_VECTORS);
  993. //TNEPRES
  994. test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
  995. TNEPRES_ENC_TEST_VECTORS);
  996. test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
  997. TNEPRES_DEC_TEST_VECTORS);
  998. //AES
  999. test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
  1000. AES_ENC_TEST_VECTORS);
  1001. test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
  1002. AES_DEC_TEST_VECTORS);
  1003. test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
  1004. AES_CBC_ENC_TEST_VECTORS);
  1005. test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
  1006. AES_CBC_DEC_TEST_VECTORS);
  1007. test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
  1008. AES_LRW_ENC_TEST_VECTORS);
  1009. test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
  1010. AES_LRW_DEC_TEST_VECTORS);
  1011. test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
  1012. AES_XTS_ENC_TEST_VECTORS);
  1013. test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
  1014. AES_XTS_DEC_TEST_VECTORS);
  1015. test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
  1016. AES_CTR_ENC_TEST_VECTORS);
  1017. test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
  1018. AES_CTR_DEC_TEST_VECTORS);
  1019. test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
  1020. AES_GCM_ENC_TEST_VECTORS);
  1021. test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
  1022. AES_GCM_DEC_TEST_VECTORS);
  1023. test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template,
  1024. AES_CCM_ENC_TEST_VECTORS);
  1025. test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template,
  1026. AES_CCM_DEC_TEST_VECTORS);
  1027. //CAST5
  1028. test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
  1029. CAST5_ENC_TEST_VECTORS);
  1030. test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
  1031. CAST5_DEC_TEST_VECTORS);
  1032. //CAST6
  1033. test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
  1034. CAST6_ENC_TEST_VECTORS);
  1035. test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
  1036. CAST6_DEC_TEST_VECTORS);
  1037. //ARC4
  1038. test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
  1039. ARC4_ENC_TEST_VECTORS);
  1040. test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
  1041. ARC4_DEC_TEST_VECTORS);
  1042. //TEA
  1043. test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
  1044. TEA_ENC_TEST_VECTORS);
  1045. test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
  1046. TEA_DEC_TEST_VECTORS);
  1047. //XTEA
  1048. test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
  1049. XTEA_ENC_TEST_VECTORS);
  1050. test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
  1051. XTEA_DEC_TEST_VECTORS);
  1052. //KHAZAD
  1053. test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
  1054. KHAZAD_ENC_TEST_VECTORS);
  1055. test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
  1056. KHAZAD_DEC_TEST_VECTORS);
  1057. //ANUBIS
  1058. test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
  1059. ANUBIS_ENC_TEST_VECTORS);
  1060. test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
  1061. ANUBIS_DEC_TEST_VECTORS);
  1062. test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
  1063. ANUBIS_CBC_ENC_TEST_VECTORS);
  1064. test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
  1065. ANUBIS_CBC_ENC_TEST_VECTORS);
  1066. //XETA
  1067. test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
  1068. XETA_ENC_TEST_VECTORS);
  1069. test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
  1070. XETA_DEC_TEST_VECTORS);
  1071. //FCrypt
  1072. test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
  1073. FCRYPT_ENC_TEST_VECTORS);
  1074. test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
  1075. FCRYPT_DEC_TEST_VECTORS);
  1076. //CAMELLIA
  1077. test_cipher("ecb(camellia)", ENCRYPT,
  1078. camellia_enc_tv_template,
  1079. CAMELLIA_ENC_TEST_VECTORS);
  1080. test_cipher("ecb(camellia)", DECRYPT,
  1081. camellia_dec_tv_template,
  1082. CAMELLIA_DEC_TEST_VECTORS);
  1083. test_cipher("cbc(camellia)", ENCRYPT,
  1084. camellia_cbc_enc_tv_template,
  1085. CAMELLIA_CBC_ENC_TEST_VECTORS);
  1086. test_cipher("cbc(camellia)", DECRYPT,
  1087. camellia_cbc_dec_tv_template,
  1088. CAMELLIA_CBC_DEC_TEST_VECTORS);
  1089. //SEED
  1090. test_cipher("ecb(seed)", ENCRYPT, seed_enc_tv_template,
  1091. SEED_ENC_TEST_VECTORS);
  1092. test_cipher("ecb(seed)", DECRYPT, seed_dec_tv_template,
  1093. SEED_DEC_TEST_VECTORS);
  1094. //CTS
  1095. test_cipher("cts(cbc(aes))", ENCRYPT, cts_mode_enc_tv_template,
  1096. CTS_MODE_ENC_TEST_VECTORS);
  1097. test_cipher("cts(cbc(aes))", DECRYPT, cts_mode_dec_tv_template,
  1098. CTS_MODE_DEC_TEST_VECTORS);
  1099. test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
  1100. test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
  1101. test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
  1102. test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
  1103. test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
  1104. test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
  1105. test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
  1106. test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
  1107. test_comp("deflate", deflate_comp_tv_template,
  1108. deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
  1109. DEFLATE_DECOMP_TEST_VECTORS);
  1110. test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template,
  1111. LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
  1112. test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
  1113. test_hash("hmac(md5)", hmac_md5_tv_template,
  1114. HMAC_MD5_TEST_VECTORS);
  1115. test_hash("hmac(sha1)", hmac_sha1_tv_template,
  1116. HMAC_SHA1_TEST_VECTORS);
  1117. test_hash("hmac(sha224)", hmac_sha224_tv_template,
  1118. HMAC_SHA224_TEST_VECTORS);
  1119. test_hash("hmac(sha256)", hmac_sha256_tv_template,
  1120. HMAC_SHA256_TEST_VECTORS);
  1121. test_hash("hmac(sha384)", hmac_sha384_tv_template,
  1122. HMAC_SHA384_TEST_VECTORS);
  1123. test_hash("hmac(sha512)", hmac_sha512_tv_template,
  1124. HMAC_SHA512_TEST_VECTORS);
  1125. test_hash("xcbc(aes)", aes_xcbc128_tv_template,
  1126. XCBC_AES_TEST_VECTORS);
  1127. test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
  1128. break;
  1129. case 1:
  1130. test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
  1131. break;
  1132. case 2:
  1133. test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
  1134. break;
  1135. case 3:
  1136. test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
  1137. DES_ENC_TEST_VECTORS);
  1138. test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
  1139. DES_DEC_TEST_VECTORS);
  1140. test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
  1141. DES_CBC_ENC_TEST_VECTORS);
  1142. test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
  1143. DES_CBC_DEC_TEST_VECTORS);
  1144. break;
  1145. case 4:
  1146. test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
  1147. DES3_EDE_ENC_TEST_VECTORS);
  1148. test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
  1149. DES3_EDE_DEC_TEST_VECTORS);
  1150. break;
  1151. case 5:
  1152. test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
  1153. break;
  1154. case 6:
  1155. test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
  1156. break;
  1157. case 7:
  1158. test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
  1159. BF_ENC_TEST_VECTORS);
  1160. test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
  1161. BF_DEC_TEST_VECTORS);
  1162. test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
  1163. BF_CBC_ENC_TEST_VECTORS);
  1164. test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
  1165. BF_CBC_DEC_TEST_VECTORS);
  1166. break;
  1167. case 8:
  1168. test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
  1169. TF_ENC_TEST_VECTORS);
  1170. test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
  1171. TF_DEC_TEST_VECTORS);
  1172. test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
  1173. TF_CBC_ENC_TEST_VECTORS);
  1174. test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
  1175. TF_CBC_DEC_TEST_VECTORS);
  1176. break;
  1177. case 9:
  1178. test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
  1179. SERPENT_ENC_TEST_VECTORS);
  1180. test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
  1181. SERPENT_DEC_TEST_VECTORS);
  1182. break;
  1183. case 10:
  1184. test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
  1185. AES_ENC_TEST_VECTORS);
  1186. test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
  1187. AES_DEC_TEST_VECTORS);
  1188. test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
  1189. AES_CBC_ENC_TEST_VECTORS);
  1190. test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
  1191. AES_CBC_DEC_TEST_VECTORS);
  1192. test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
  1193. AES_LRW_ENC_TEST_VECTORS);
  1194. test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
  1195. AES_LRW_DEC_TEST_VECTORS);
  1196. test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
  1197. AES_XTS_ENC_TEST_VECTORS);
  1198. test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
  1199. AES_XTS_DEC_TEST_VECTORS);
  1200. test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
  1201. AES_CTR_ENC_TEST_VECTORS);
  1202. test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
  1203. AES_CTR_DEC_TEST_VECTORS);
  1204. break;
  1205. case 11:
  1206. test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
  1207. break;
  1208. case 12:
  1209. test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
  1210. break;
  1211. case 13:
  1212. test_comp("deflate", deflate_comp_tv_template,
  1213. deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
  1214. DEFLATE_DECOMP_TEST_VECTORS);
  1215. break;
  1216. case 14:
  1217. test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
  1218. CAST5_ENC_TEST_VECTORS);
  1219. test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
  1220. CAST5_DEC_TEST_VECTORS);
  1221. break;
  1222. case 15:
  1223. test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
  1224. CAST6_ENC_TEST_VECTORS);
  1225. test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
  1226. CAST6_DEC_TEST_VECTORS);
  1227. break;
  1228. case 16:
  1229. test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
  1230. ARC4_ENC_TEST_VECTORS);
  1231. test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
  1232. ARC4_DEC_TEST_VECTORS);
  1233. break;
  1234. case 17:
  1235. test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
  1236. break;
  1237. case 18:
  1238. test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
  1239. break;
  1240. case 19:
  1241. test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
  1242. TEA_ENC_TEST_VECTORS);
  1243. test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
  1244. TEA_DEC_TEST_VECTORS);
  1245. break;
  1246. case 20:
  1247. test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
  1248. XTEA_ENC_TEST_VECTORS);
  1249. test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
  1250. XTEA_DEC_TEST_VECTORS);
  1251. break;
  1252. case 21:
  1253. test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
  1254. KHAZAD_ENC_TEST_VECTORS);
  1255. test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
  1256. KHAZAD_DEC_TEST_VECTORS);
  1257. break;
  1258. case 22:
  1259. test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
  1260. break;
  1261. case 23:
  1262. test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
  1263. break;
  1264. case 24:
  1265. test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
  1266. break;
  1267. case 25:
  1268. test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
  1269. TNEPRES_ENC_TEST_VECTORS);
  1270. test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
  1271. TNEPRES_DEC_TEST_VECTORS);
  1272. break;
  1273. case 26:
  1274. test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
  1275. ANUBIS_ENC_TEST_VECTORS);
  1276. test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
  1277. ANUBIS_DEC_TEST_VECTORS);
  1278. test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
  1279. ANUBIS_CBC_ENC_TEST_VECTORS);
  1280. test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
  1281. ANUBIS_CBC_ENC_TEST_VECTORS);
  1282. break;
  1283. case 27:
  1284. test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
  1285. break;
  1286. case 28:
  1287. test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
  1288. break;
  1289. case 29:
  1290. test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
  1291. break;
  1292. case 30:
  1293. test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
  1294. XETA_ENC_TEST_VECTORS);
  1295. test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
  1296. XETA_DEC_TEST_VECTORS);
  1297. break;
  1298. case 31:
  1299. test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
  1300. FCRYPT_ENC_TEST_VECTORS);
  1301. test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
  1302. FCRYPT_DEC_TEST_VECTORS);
  1303. break;
  1304. case 32:
  1305. test_cipher("ecb(camellia)", ENCRYPT,
  1306. camellia_enc_tv_template,
  1307. CAMELLIA_ENC_TEST_VECTORS);
  1308. test_cipher("ecb(camellia)", DECRYPT,
  1309. camellia_dec_tv_template,
  1310. CAMELLIA_DEC_TEST_VECTORS);
  1311. test_cipher("cbc(camellia)", ENCRYPT,
  1312. camellia_cbc_enc_tv_template,
  1313. CAMELLIA_CBC_ENC_TEST_VECTORS);
  1314. test_cipher("cbc(camellia)", DECRYPT,
  1315. camellia_cbc_dec_tv_template,
  1316. CAMELLIA_CBC_DEC_TEST_VECTORS);
  1317. break;
  1318. case 33:
  1319. test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
  1320. break;
  1321. case 34:
  1322. test_cipher("salsa20", ENCRYPT,
  1323. salsa20_stream_enc_tv_template,
  1324. SALSA20_STREAM_ENC_TEST_VECTORS);
  1325. break;
  1326. case 35:
  1327. test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
  1328. AES_GCM_ENC_TEST_VECTORS);
  1329. test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
  1330. AES_GCM_DEC_TEST_VECTORS);
  1331. break;
  1332. case 36:
  1333. test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template,
  1334. LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
  1335. break;
  1336. case 37:
  1337. test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template,
  1338. AES_CCM_ENC_TEST_VECTORS);
  1339. test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template,
  1340. AES_CCM_DEC_TEST_VECTORS);
  1341. break;
  1342. case 38:
  1343. test_cipher("cts(cbc(aes))", ENCRYPT, cts_mode_enc_tv_template,
  1344. CTS_MODE_ENC_TEST_VECTORS);
  1345. test_cipher("cts(cbc(aes))", DECRYPT, cts_mode_dec_tv_template,
  1346. CTS_MODE_DEC_TEST_VECTORS);
  1347. break;
  1348. case 100:
  1349. test_hash("hmac(md5)", hmac_md5_tv_template,
  1350. HMAC_MD5_TEST_VECTORS);
  1351. break;
  1352. case 101:
  1353. test_hash("hmac(sha1)", hmac_sha1_tv_template,
  1354. HMAC_SHA1_TEST_VECTORS);
  1355. break;
  1356. case 102:
  1357. test_hash("hmac(sha256)", hmac_sha256_tv_template,
  1358. HMAC_SHA256_TEST_VECTORS);
  1359. break;
  1360. case 103:
  1361. test_hash("hmac(sha384)", hmac_sha384_tv_template,
  1362. HMAC_SHA384_TEST_VECTORS);
  1363. break;
  1364. case 104:
  1365. test_hash("hmac(sha512)", hmac_sha512_tv_template,
  1366. HMAC_SHA512_TEST_VECTORS);
  1367. break;
  1368. case 105:
  1369. test_hash("hmac(sha224)", hmac_sha224_tv_template,
  1370. HMAC_SHA224_TEST_VECTORS);
  1371. break;
  1372. case 106:
  1373. test_hash("xcbc(aes)", aes_xcbc128_tv_template,
  1374. XCBC_AES_TEST_VECTORS);
  1375. break;
  1376. case 200:
  1377. test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
  1378. speed_template_16_24_32);
  1379. test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
  1380. speed_template_16_24_32);
  1381. test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
  1382. speed_template_16_24_32);
  1383. test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
  1384. speed_template_16_24_32);
  1385. test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
  1386. speed_template_32_40_48);
  1387. test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
  1388. speed_template_32_40_48);
  1389. test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
  1390. speed_template_32_48_64);
  1391. test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
  1392. speed_template_32_48_64);
  1393. break;
  1394. case 201:
  1395. test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
  1396. des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
  1397. speed_template_24);
  1398. test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
  1399. des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
  1400. speed_template_24);
  1401. test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
  1402. des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
  1403. speed_template_24);
  1404. test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
  1405. des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
  1406. speed_template_24);
  1407. break;
  1408. case 202:
  1409. test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
  1410. speed_template_16_24_32);
  1411. test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
  1412. speed_template_16_24_32);
  1413. test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
  1414. speed_template_16_24_32);
  1415. test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
  1416. speed_template_16_24_32);
  1417. break;
  1418. case 203:
  1419. test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
  1420. speed_template_8_32);
  1421. test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
  1422. speed_template_8_32);
  1423. test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
  1424. speed_template_8_32);
  1425. test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
  1426. speed_template_8_32);
  1427. break;
  1428. case 204:
  1429. test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
  1430. speed_template_8);
  1431. test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
  1432. speed_template_8);
  1433. test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
  1434. speed_template_8);
  1435. test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
  1436. speed_template_8);
  1437. break;
  1438. case 205:
  1439. test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
  1440. speed_template_16_24_32);
  1441. test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
  1442. speed_template_16_24_32);
  1443. test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
  1444. speed_template_16_24_32);
  1445. test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
  1446. speed_template_16_24_32);
  1447. break;
  1448. case 206:
  1449. test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
  1450. speed_template_16_32);
  1451. break;
  1452. case 300:
  1453. /* fall through */
  1454. case 301:
  1455. test_hash_speed("md4", sec, generic_hash_speed_template);
  1456. if (mode > 300 && mode < 400) break;
  1457. case 302:
  1458. test_hash_speed("md5", sec, generic_hash_speed_template);
  1459. if (mode > 300 && mode < 400) break;
  1460. case 303:
  1461. test_hash_speed("sha1", sec, generic_hash_speed_template);
  1462. if (mode > 300 && mode < 400) break;
  1463. case 304:
  1464. test_hash_speed("sha256", sec, generic_hash_speed_template);
  1465. if (mode > 300 && mode < 400) break;
  1466. case 305:
  1467. test_hash_speed("sha384", sec, generic_hash_speed_template);
  1468. if (mode > 300 && mode < 400) break;
  1469. case 306:
  1470. test_hash_speed("sha512", sec, generic_hash_speed_template);
  1471. if (mode > 300 && mode < 400) break;
  1472. case 307:
  1473. test_hash_speed("wp256", sec, generic_hash_speed_template);
  1474. if (mode > 300 && mode < 400) break;
  1475. case 308:
  1476. test_hash_speed("wp384", sec, generic_hash_speed_template);
  1477. if (mode > 300 && mode < 400) break;
  1478. case 309:
  1479. test_hash_speed("wp512", sec, generic_hash_speed_template);
  1480. if (mode > 300 && mode < 400) break;
  1481. case 310:
  1482. test_hash_speed("tgr128", sec, generic_hash_speed_template);
  1483. if (mode > 300 && mode < 400) break;
  1484. case 311:
  1485. test_hash_speed("tgr160", sec, generic_hash_speed_template);
  1486. if (mode > 300 && mode < 400) break;
  1487. case 312:
  1488. test_hash_speed("tgr192", sec, generic_hash_speed_template);
  1489. if (mode > 300 && mode < 400) break;
  1490. case 313:
  1491. test_hash_speed("sha224", sec, generic_hash_speed_template);
  1492. if (mode > 300 && mode < 400) break;
  1493. case 399:
  1494. break;
  1495. case 1000:
  1496. test_available();
  1497. break;
  1498. default:
  1499. /* useful for debugging */
  1500. printk("not testing anything\n");
  1501. break;
  1502. }
  1503. }
  1504. static int __init tcrypt_mod_init(void)
  1505. {
  1506. int err = -ENOMEM;
  1507. tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
  1508. if (tvmem == NULL)
  1509. return err;
  1510. xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
  1511. if (xbuf == NULL)
  1512. goto err_free_tv;
  1513. axbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
  1514. if (axbuf == NULL)
  1515. goto err_free_xbuf;
  1516. do_test();
  1517. /* We intentionaly return -EAGAIN to prevent keeping
  1518. * the module. It does all its work from init()
  1519. * and doesn't offer any runtime functionality
  1520. * => we don't need it in the memory, do we?
  1521. * -- mludvig
  1522. */
  1523. err = -EAGAIN;
  1524. kfree(axbuf);
  1525. err_free_xbuf:
  1526. kfree(xbuf);
  1527. err_free_tv:
  1528. kfree(tvmem);
  1529. return err;
  1530. }
  1531. /*
  1532. * If an init function is provided, an exit function must also be provided
  1533. * to allow module unload.
  1534. */
  1535. static void __exit tcrypt_mod_fini(void) { }
  1536. module_init(tcrypt_mod_init);
  1537. module_exit(tcrypt_mod_fini);
  1538. module_param(mode, int, 0);
  1539. module_param(sec, uint, 0);
  1540. MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
  1541. "(defaults to zero which uses CPU cycles instead)");
  1542. MODULE_LICENSE("GPL");
  1543. MODULE_DESCRIPTION("Quick & dirty crypto testing module");
  1544. MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");