tcrypt.c 45 KB

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