testmgr.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138
  1. /*
  2. * Algorithm testing framework and tests.
  3. *
  4. * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
  5. * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
  6. * Copyright (c) 2007 Nokia Siemens Networks
  7. * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the Free
  11. * Software Foundation; either version 2 of the License, or (at your option)
  12. * any later version.
  13. *
  14. */
  15. #include <crypto/hash.h>
  16. #include <linux/err.h>
  17. #include <linux/module.h>
  18. #include <linux/scatterlist.h>
  19. #include <linux/slab.h>
  20. #include <linux/string.h>
  21. #include "internal.h"
  22. #include "testmgr.h"
  23. /*
  24. * Need slab memory for testing (size in number of pages).
  25. */
  26. #define XBUFSIZE 8
  27. /*
  28. * Indexes into the xbuf to simulate cross-page access.
  29. */
  30. #define IDX1 32
  31. #define IDX2 32400
  32. #define IDX3 1
  33. #define IDX4 8193
  34. #define IDX5 22222
  35. #define IDX6 17101
  36. #define IDX7 27333
  37. #define IDX8 3000
  38. /*
  39. * Used by test_cipher()
  40. */
  41. #define ENCRYPT 1
  42. #define DECRYPT 0
  43. struct tcrypt_result {
  44. struct completion completion;
  45. int err;
  46. };
  47. struct aead_test_suite {
  48. struct {
  49. struct aead_testvec *vecs;
  50. unsigned int count;
  51. } enc, dec;
  52. };
  53. struct cipher_test_suite {
  54. struct {
  55. struct cipher_testvec *vecs;
  56. unsigned int count;
  57. } enc, dec;
  58. };
  59. struct comp_test_suite {
  60. struct {
  61. struct comp_testvec *vecs;
  62. unsigned int count;
  63. } comp, decomp;
  64. };
  65. struct pcomp_test_suite {
  66. struct {
  67. struct pcomp_testvec *vecs;
  68. unsigned int count;
  69. } comp, decomp;
  70. };
  71. struct hash_test_suite {
  72. struct hash_testvec *vecs;
  73. unsigned int count;
  74. };
  75. struct alg_test_desc {
  76. const char *alg;
  77. int (*test)(const struct alg_test_desc *desc, const char *driver,
  78. u32 type, u32 mask);
  79. union {
  80. struct aead_test_suite aead;
  81. struct cipher_test_suite cipher;
  82. struct comp_test_suite comp;
  83. struct pcomp_test_suite pcomp;
  84. struct hash_test_suite hash;
  85. } suite;
  86. };
  87. static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
  88. static char *xbuf[XBUFSIZE];
  89. static char *axbuf[XBUFSIZE];
  90. static void hexdump(unsigned char *buf, unsigned int len)
  91. {
  92. print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
  93. 16, 1,
  94. buf, len, false);
  95. }
  96. static void tcrypt_complete(struct crypto_async_request *req, int err)
  97. {
  98. struct tcrypt_result *res = req->data;
  99. if (err == -EINPROGRESS)
  100. return;
  101. res->err = err;
  102. complete(&res->completion);
  103. }
  104. static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
  105. unsigned int tcount)
  106. {
  107. const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
  108. unsigned int i, j, k, temp;
  109. struct scatterlist sg[8];
  110. char result[64];
  111. struct ahash_request *req;
  112. struct tcrypt_result tresult;
  113. int ret;
  114. void *hash_buff;
  115. init_completion(&tresult.completion);
  116. req = ahash_request_alloc(tfm, GFP_KERNEL);
  117. if (!req) {
  118. printk(KERN_ERR "alg: hash: Failed to allocate request for "
  119. "%s\n", algo);
  120. ret = -ENOMEM;
  121. goto out_noreq;
  122. }
  123. ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  124. tcrypt_complete, &tresult);
  125. for (i = 0; i < tcount; i++) {
  126. memset(result, 0, 64);
  127. hash_buff = xbuf[0];
  128. memcpy(hash_buff, template[i].plaintext, template[i].psize);
  129. sg_init_one(&sg[0], hash_buff, template[i].psize);
  130. if (template[i].ksize) {
  131. crypto_ahash_clear_flags(tfm, ~0);
  132. ret = crypto_ahash_setkey(tfm, template[i].key,
  133. template[i].ksize);
  134. if (ret) {
  135. printk(KERN_ERR "alg: hash: setkey failed on "
  136. "test %d for %s: ret=%d\n", i + 1, algo,
  137. -ret);
  138. goto out;
  139. }
  140. }
  141. ahash_request_set_crypt(req, sg, result, template[i].psize);
  142. ret = crypto_ahash_digest(req);
  143. switch (ret) {
  144. case 0:
  145. break;
  146. case -EINPROGRESS:
  147. case -EBUSY:
  148. ret = wait_for_completion_interruptible(
  149. &tresult.completion);
  150. if (!ret && !(ret = tresult.err)) {
  151. INIT_COMPLETION(tresult.completion);
  152. break;
  153. }
  154. /* fall through */
  155. default:
  156. printk(KERN_ERR "alg: hash: digest failed on test %d "
  157. "for %s: ret=%d\n", i + 1, algo, -ret);
  158. goto out;
  159. }
  160. if (memcmp(result, template[i].digest,
  161. crypto_ahash_digestsize(tfm))) {
  162. printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
  163. i + 1, algo);
  164. hexdump(result, crypto_ahash_digestsize(tfm));
  165. ret = -EINVAL;
  166. goto out;
  167. }
  168. }
  169. j = 0;
  170. for (i = 0; i < tcount; i++) {
  171. if (template[i].np) {
  172. j++;
  173. memset(result, 0, 64);
  174. temp = 0;
  175. sg_init_table(sg, template[i].np);
  176. for (k = 0; k < template[i].np; k++) {
  177. sg_set_buf(&sg[k],
  178. memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
  179. offset_in_page(IDX[k]),
  180. template[i].plaintext + temp,
  181. template[i].tap[k]),
  182. template[i].tap[k]);
  183. temp += template[i].tap[k];
  184. }
  185. if (template[i].ksize) {
  186. crypto_ahash_clear_flags(tfm, ~0);
  187. ret = crypto_ahash_setkey(tfm, template[i].key,
  188. template[i].ksize);
  189. if (ret) {
  190. printk(KERN_ERR "alg: hash: setkey "
  191. "failed on chunking test %d "
  192. "for %s: ret=%d\n", j, algo,
  193. -ret);
  194. goto out;
  195. }
  196. }
  197. ahash_request_set_crypt(req, sg, result,
  198. template[i].psize);
  199. ret = crypto_ahash_digest(req);
  200. switch (ret) {
  201. case 0:
  202. break;
  203. case -EINPROGRESS:
  204. case -EBUSY:
  205. ret = wait_for_completion_interruptible(
  206. &tresult.completion);
  207. if (!ret && !(ret = tresult.err)) {
  208. INIT_COMPLETION(tresult.completion);
  209. break;
  210. }
  211. /* fall through */
  212. default:
  213. printk(KERN_ERR "alg: hash: digest failed "
  214. "on chunking test %d for %s: "
  215. "ret=%d\n", j, algo, -ret);
  216. goto out;
  217. }
  218. if (memcmp(result, template[i].digest,
  219. crypto_ahash_digestsize(tfm))) {
  220. printk(KERN_ERR "alg: hash: Chunking test %d "
  221. "failed for %s\n", j, algo);
  222. hexdump(result, crypto_ahash_digestsize(tfm));
  223. ret = -EINVAL;
  224. goto out;
  225. }
  226. }
  227. }
  228. ret = 0;
  229. out:
  230. ahash_request_free(req);
  231. out_noreq:
  232. return ret;
  233. }
  234. static int test_aead(struct crypto_aead *tfm, int enc,
  235. struct aead_testvec *template, unsigned int tcount)
  236. {
  237. const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
  238. unsigned int i, j, k, n, temp;
  239. int ret = 0;
  240. char *q;
  241. char *key;
  242. struct aead_request *req;
  243. struct scatterlist sg[8];
  244. struct scatterlist asg[8];
  245. const char *e;
  246. struct tcrypt_result result;
  247. unsigned int authsize;
  248. void *input;
  249. void *assoc;
  250. char iv[MAX_IVLEN];
  251. if (enc == ENCRYPT)
  252. e = "encryption";
  253. else
  254. e = "decryption";
  255. init_completion(&result.completion);
  256. req = aead_request_alloc(tfm, GFP_KERNEL);
  257. if (!req) {
  258. printk(KERN_ERR "alg: aead: Failed to allocate request for "
  259. "%s\n", algo);
  260. ret = -ENOMEM;
  261. goto out;
  262. }
  263. aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  264. tcrypt_complete, &result);
  265. for (i = 0, j = 0; i < tcount; i++) {
  266. if (!template[i].np) {
  267. j++;
  268. /* some tepmplates have no input data but they will
  269. * touch input
  270. */
  271. input = xbuf[0];
  272. assoc = axbuf[0];
  273. memcpy(input, template[i].input, template[i].ilen);
  274. memcpy(assoc, template[i].assoc, template[i].alen);
  275. if (template[i].iv)
  276. memcpy(iv, template[i].iv, MAX_IVLEN);
  277. else
  278. memset(iv, 0, MAX_IVLEN);
  279. crypto_aead_clear_flags(tfm, ~0);
  280. if (template[i].wk)
  281. crypto_aead_set_flags(
  282. tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  283. key = template[i].key;
  284. ret = crypto_aead_setkey(tfm, key,
  285. template[i].klen);
  286. if (!ret == template[i].fail) {
  287. printk(KERN_ERR "alg: aead: setkey failed on "
  288. "test %d for %s: flags=%x\n", j, algo,
  289. crypto_aead_get_flags(tfm));
  290. goto out;
  291. } else if (ret)
  292. continue;
  293. authsize = abs(template[i].rlen - template[i].ilen);
  294. ret = crypto_aead_setauthsize(tfm, authsize);
  295. if (ret) {
  296. printk(KERN_ERR "alg: aead: Failed to set "
  297. "authsize to %u on test %d for %s\n",
  298. authsize, j, algo);
  299. goto out;
  300. }
  301. sg_init_one(&sg[0], input,
  302. template[i].ilen + (enc ? authsize : 0));
  303. sg_init_one(&asg[0], assoc, template[i].alen);
  304. aead_request_set_crypt(req, sg, sg,
  305. template[i].ilen, iv);
  306. aead_request_set_assoc(req, asg, template[i].alen);
  307. ret = enc ?
  308. crypto_aead_encrypt(req) :
  309. crypto_aead_decrypt(req);
  310. switch (ret) {
  311. case 0:
  312. break;
  313. case -EINPROGRESS:
  314. case -EBUSY:
  315. ret = wait_for_completion_interruptible(
  316. &result.completion);
  317. if (!ret && !(ret = result.err)) {
  318. INIT_COMPLETION(result.completion);
  319. break;
  320. }
  321. /* fall through */
  322. default:
  323. printk(KERN_ERR "alg: aead: %s failed on test "
  324. "%d for %s: ret=%d\n", e, j, algo, -ret);
  325. goto out;
  326. }
  327. q = input;
  328. if (memcmp(q, template[i].result, template[i].rlen)) {
  329. printk(KERN_ERR "alg: aead: Test %d failed on "
  330. "%s for %s\n", j, e, algo);
  331. hexdump(q, template[i].rlen);
  332. ret = -EINVAL;
  333. goto out;
  334. }
  335. }
  336. }
  337. for (i = 0, j = 0; i < tcount; i++) {
  338. if (template[i].np) {
  339. j++;
  340. if (template[i].iv)
  341. memcpy(iv, template[i].iv, MAX_IVLEN);
  342. else
  343. memset(iv, 0, MAX_IVLEN);
  344. crypto_aead_clear_flags(tfm, ~0);
  345. if (template[i].wk)
  346. crypto_aead_set_flags(
  347. tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  348. key = template[i].key;
  349. ret = crypto_aead_setkey(tfm, key, template[i].klen);
  350. if (!ret == template[i].fail) {
  351. printk(KERN_ERR "alg: aead: setkey failed on "
  352. "chunk test %d for %s: flags=%x\n", j,
  353. algo, crypto_aead_get_flags(tfm));
  354. goto out;
  355. } else if (ret)
  356. continue;
  357. authsize = abs(template[i].rlen - template[i].ilen);
  358. ret = -EINVAL;
  359. sg_init_table(sg, template[i].np);
  360. for (k = 0, temp = 0; k < template[i].np; k++) {
  361. if (WARN_ON(offset_in_page(IDX[k]) +
  362. template[i].tap[k] > PAGE_SIZE))
  363. goto out;
  364. q = xbuf[IDX[k] >> PAGE_SHIFT] +
  365. offset_in_page(IDX[k]);
  366. memcpy(q, template[i].input + temp,
  367. template[i].tap[k]);
  368. n = template[i].tap[k];
  369. if (k == template[i].np - 1 && enc)
  370. n += authsize;
  371. if (offset_in_page(q) + n < PAGE_SIZE)
  372. q[n] = 0;
  373. sg_set_buf(&sg[k], q, template[i].tap[k]);
  374. temp += template[i].tap[k];
  375. }
  376. ret = crypto_aead_setauthsize(tfm, authsize);
  377. if (ret) {
  378. printk(KERN_ERR "alg: aead: Failed to set "
  379. "authsize to %u on chunk test %d for "
  380. "%s\n", authsize, j, algo);
  381. goto out;
  382. }
  383. if (enc) {
  384. if (WARN_ON(sg[k - 1].offset +
  385. sg[k - 1].length + authsize >
  386. PAGE_SIZE)) {
  387. ret = -EINVAL;
  388. goto out;
  389. }
  390. sg[k - 1].length += authsize;
  391. }
  392. sg_init_table(asg, template[i].anp);
  393. for (k = 0, temp = 0; k < template[i].anp; k++) {
  394. sg_set_buf(&asg[k],
  395. memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
  396. offset_in_page(IDX[k]),
  397. template[i].assoc + temp,
  398. template[i].atap[k]),
  399. template[i].atap[k]);
  400. temp += template[i].atap[k];
  401. }
  402. aead_request_set_crypt(req, sg, sg,
  403. template[i].ilen,
  404. iv);
  405. aead_request_set_assoc(req, asg, template[i].alen);
  406. ret = enc ?
  407. crypto_aead_encrypt(req) :
  408. crypto_aead_decrypt(req);
  409. switch (ret) {
  410. case 0:
  411. break;
  412. case -EINPROGRESS:
  413. case -EBUSY:
  414. ret = wait_for_completion_interruptible(
  415. &result.completion);
  416. if (!ret && !(ret = result.err)) {
  417. INIT_COMPLETION(result.completion);
  418. break;
  419. }
  420. /* fall through */
  421. default:
  422. printk(KERN_ERR "alg: aead: %s failed on "
  423. "chunk test %d for %s: ret=%d\n", e, j,
  424. algo, -ret);
  425. goto out;
  426. }
  427. ret = -EINVAL;
  428. for (k = 0, temp = 0; k < template[i].np; k++) {
  429. q = xbuf[IDX[k] >> PAGE_SHIFT] +
  430. offset_in_page(IDX[k]);
  431. n = template[i].tap[k];
  432. if (k == template[i].np - 1)
  433. n += enc ? authsize : -authsize;
  434. if (memcmp(q, template[i].result + temp, n)) {
  435. printk(KERN_ERR "alg: aead: Chunk "
  436. "test %d failed on %s at page "
  437. "%u for %s\n", j, e, k, algo);
  438. hexdump(q, n);
  439. goto out;
  440. }
  441. q += n;
  442. if (k == template[i].np - 1 && !enc) {
  443. if (memcmp(q, template[i].input +
  444. temp + n, authsize))
  445. n = authsize;
  446. else
  447. n = 0;
  448. } else {
  449. for (n = 0; offset_in_page(q + n) &&
  450. q[n]; n++)
  451. ;
  452. }
  453. if (n) {
  454. printk(KERN_ERR "alg: aead: Result "
  455. "buffer corruption in chunk "
  456. "test %d on %s at page %u for "
  457. "%s: %u bytes:\n", j, e, k,
  458. algo, n);
  459. hexdump(q, n);
  460. goto out;
  461. }
  462. temp += template[i].tap[k];
  463. }
  464. }
  465. }
  466. ret = 0;
  467. out:
  468. aead_request_free(req);
  469. return ret;
  470. }
  471. static int test_cipher(struct crypto_cipher *tfm, int enc,
  472. struct cipher_testvec *template, unsigned int tcount)
  473. {
  474. const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
  475. unsigned int i, j, k;
  476. int ret;
  477. char *q;
  478. const char *e;
  479. void *data;
  480. if (enc == ENCRYPT)
  481. e = "encryption";
  482. else
  483. e = "decryption";
  484. j = 0;
  485. for (i = 0; i < tcount; i++) {
  486. if (template[i].np)
  487. continue;
  488. j++;
  489. data = xbuf[0];
  490. memcpy(data, template[i].input, template[i].ilen);
  491. crypto_cipher_clear_flags(tfm, ~0);
  492. if (template[i].wk)
  493. crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  494. ret = crypto_cipher_setkey(tfm, template[i].key,
  495. template[i].klen);
  496. if (!ret == template[i].fail) {
  497. printk(KERN_ERR "alg: cipher: setkey failed "
  498. "on test %d for %s: flags=%x\n", j,
  499. algo, crypto_cipher_get_flags(tfm));
  500. goto out;
  501. } else if (ret)
  502. continue;
  503. for (k = 0; k < template[i].ilen;
  504. k += crypto_cipher_blocksize(tfm)) {
  505. if (enc)
  506. crypto_cipher_encrypt_one(tfm, data + k,
  507. data + k);
  508. else
  509. crypto_cipher_decrypt_one(tfm, data + k,
  510. data + k);
  511. }
  512. q = data;
  513. if (memcmp(q, template[i].result, template[i].rlen)) {
  514. printk(KERN_ERR "alg: cipher: Test %d failed "
  515. "on %s for %s\n", j, e, algo);
  516. hexdump(q, template[i].rlen);
  517. ret = -EINVAL;
  518. goto out;
  519. }
  520. }
  521. ret = 0;
  522. out:
  523. return ret;
  524. }
  525. static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
  526. struct cipher_testvec *template, unsigned int tcount)
  527. {
  528. const char *algo =
  529. crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
  530. unsigned int i, j, k, n, temp;
  531. int ret;
  532. char *q;
  533. struct ablkcipher_request *req;
  534. struct scatterlist sg[8];
  535. const char *e;
  536. struct tcrypt_result result;
  537. void *data;
  538. char iv[MAX_IVLEN];
  539. if (enc == ENCRYPT)
  540. e = "encryption";
  541. else
  542. e = "decryption";
  543. init_completion(&result.completion);
  544. req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
  545. if (!req) {
  546. printk(KERN_ERR "alg: skcipher: Failed to allocate request "
  547. "for %s\n", algo);
  548. ret = -ENOMEM;
  549. goto out;
  550. }
  551. ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  552. tcrypt_complete, &result);
  553. j = 0;
  554. for (i = 0; i < tcount; i++) {
  555. if (template[i].iv)
  556. memcpy(iv, template[i].iv, MAX_IVLEN);
  557. else
  558. memset(iv, 0, MAX_IVLEN);
  559. if (!(template[i].np)) {
  560. j++;
  561. data = xbuf[0];
  562. memcpy(data, template[i].input, template[i].ilen);
  563. crypto_ablkcipher_clear_flags(tfm, ~0);
  564. if (template[i].wk)
  565. crypto_ablkcipher_set_flags(
  566. tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  567. ret = crypto_ablkcipher_setkey(tfm, template[i].key,
  568. template[i].klen);
  569. if (!ret == template[i].fail) {
  570. printk(KERN_ERR "alg: skcipher: setkey failed "
  571. "on test %d for %s: flags=%x\n", j,
  572. algo, crypto_ablkcipher_get_flags(tfm));
  573. goto out;
  574. } else if (ret)
  575. continue;
  576. sg_init_one(&sg[0], data, template[i].ilen);
  577. ablkcipher_request_set_crypt(req, sg, sg,
  578. template[i].ilen, iv);
  579. ret = enc ?
  580. crypto_ablkcipher_encrypt(req) :
  581. crypto_ablkcipher_decrypt(req);
  582. switch (ret) {
  583. case 0:
  584. break;
  585. case -EINPROGRESS:
  586. case -EBUSY:
  587. ret = wait_for_completion_interruptible(
  588. &result.completion);
  589. if (!ret && !((ret = result.err))) {
  590. INIT_COMPLETION(result.completion);
  591. break;
  592. }
  593. /* fall through */
  594. default:
  595. printk(KERN_ERR "alg: skcipher: %s failed on "
  596. "test %d for %s: ret=%d\n", e, j, algo,
  597. -ret);
  598. goto out;
  599. }
  600. q = data;
  601. if (memcmp(q, template[i].result, template[i].rlen)) {
  602. printk(KERN_ERR "alg: skcipher: Test %d "
  603. "failed on %s for %s\n", j, e, algo);
  604. hexdump(q, template[i].rlen);
  605. ret = -EINVAL;
  606. goto out;
  607. }
  608. }
  609. }
  610. j = 0;
  611. for (i = 0; i < tcount; i++) {
  612. if (template[i].iv)
  613. memcpy(iv, template[i].iv, MAX_IVLEN);
  614. else
  615. memset(iv, 0, MAX_IVLEN);
  616. if (template[i].np) {
  617. j++;
  618. crypto_ablkcipher_clear_flags(tfm, ~0);
  619. if (template[i].wk)
  620. crypto_ablkcipher_set_flags(
  621. tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  622. ret = crypto_ablkcipher_setkey(tfm, template[i].key,
  623. template[i].klen);
  624. if (!ret == template[i].fail) {
  625. printk(KERN_ERR "alg: skcipher: setkey failed "
  626. "on chunk test %d for %s: flags=%x\n",
  627. j, algo,
  628. crypto_ablkcipher_get_flags(tfm));
  629. goto out;
  630. } else if (ret)
  631. continue;
  632. temp = 0;
  633. ret = -EINVAL;
  634. sg_init_table(sg, template[i].np);
  635. for (k = 0; k < template[i].np; k++) {
  636. if (WARN_ON(offset_in_page(IDX[k]) +
  637. template[i].tap[k] > PAGE_SIZE))
  638. goto out;
  639. q = xbuf[IDX[k] >> PAGE_SHIFT] +
  640. offset_in_page(IDX[k]);
  641. memcpy(q, template[i].input + temp,
  642. template[i].tap[k]);
  643. if (offset_in_page(q) + template[i].tap[k] <
  644. PAGE_SIZE)
  645. q[template[i].tap[k]] = 0;
  646. sg_set_buf(&sg[k], q, template[i].tap[k]);
  647. temp += template[i].tap[k];
  648. }
  649. ablkcipher_request_set_crypt(req, sg, sg,
  650. template[i].ilen, iv);
  651. ret = enc ?
  652. crypto_ablkcipher_encrypt(req) :
  653. crypto_ablkcipher_decrypt(req);
  654. switch (ret) {
  655. case 0:
  656. break;
  657. case -EINPROGRESS:
  658. case -EBUSY:
  659. ret = wait_for_completion_interruptible(
  660. &result.completion);
  661. if (!ret && !((ret = result.err))) {
  662. INIT_COMPLETION(result.completion);
  663. break;
  664. }
  665. /* fall through */
  666. default:
  667. printk(KERN_ERR "alg: skcipher: %s failed on "
  668. "chunk test %d for %s: ret=%d\n", e, j,
  669. algo, -ret);
  670. goto out;
  671. }
  672. temp = 0;
  673. ret = -EINVAL;
  674. for (k = 0; k < template[i].np; k++) {
  675. q = xbuf[IDX[k] >> PAGE_SHIFT] +
  676. offset_in_page(IDX[k]);
  677. if (memcmp(q, template[i].result + temp,
  678. template[i].tap[k])) {
  679. printk(KERN_ERR "alg: skcipher: Chunk "
  680. "test %d failed on %s at page "
  681. "%u for %s\n", j, e, k, algo);
  682. hexdump(q, template[i].tap[k]);
  683. goto out;
  684. }
  685. q += template[i].tap[k];
  686. for (n = 0; offset_in_page(q + n) && q[n]; n++)
  687. ;
  688. if (n) {
  689. printk(KERN_ERR "alg: skcipher: "
  690. "Result buffer corruption in "
  691. "chunk test %d on %s at page "
  692. "%u for %s: %u bytes:\n", j, e,
  693. k, algo, n);
  694. hexdump(q, n);
  695. goto out;
  696. }
  697. temp += template[i].tap[k];
  698. }
  699. }
  700. }
  701. ret = 0;
  702. out:
  703. ablkcipher_request_free(req);
  704. return ret;
  705. }
  706. static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
  707. struct comp_testvec *dtemplate, int ctcount, int dtcount)
  708. {
  709. const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
  710. unsigned int i;
  711. char result[COMP_BUF_SIZE];
  712. int ret;
  713. for (i = 0; i < ctcount; i++) {
  714. int ilen;
  715. unsigned int dlen = COMP_BUF_SIZE;
  716. memset(result, 0, sizeof (result));
  717. ilen = ctemplate[i].inlen;
  718. ret = crypto_comp_compress(tfm, ctemplate[i].input,
  719. ilen, result, &dlen);
  720. if (ret) {
  721. printk(KERN_ERR "alg: comp: compression failed "
  722. "on test %d for %s: ret=%d\n", i + 1, algo,
  723. -ret);
  724. goto out;
  725. }
  726. if (dlen != ctemplate[i].outlen) {
  727. printk(KERN_ERR "alg: comp: Compression test %d "
  728. "failed for %s: output len = %d\n", i + 1, algo,
  729. dlen);
  730. ret = -EINVAL;
  731. goto out;
  732. }
  733. if (memcmp(result, ctemplate[i].output, dlen)) {
  734. printk(KERN_ERR "alg: comp: Compression test %d "
  735. "failed for %s\n", i + 1, algo);
  736. hexdump(result, dlen);
  737. ret = -EINVAL;
  738. goto out;
  739. }
  740. }
  741. for (i = 0; i < dtcount; i++) {
  742. int ilen;
  743. unsigned int dlen = COMP_BUF_SIZE;
  744. memset(result, 0, sizeof (result));
  745. ilen = dtemplate[i].inlen;
  746. ret = crypto_comp_decompress(tfm, dtemplate[i].input,
  747. ilen, result, &dlen);
  748. if (ret) {
  749. printk(KERN_ERR "alg: comp: decompression failed "
  750. "on test %d for %s: ret=%d\n", i + 1, algo,
  751. -ret);
  752. goto out;
  753. }
  754. if (dlen != dtemplate[i].outlen) {
  755. printk(KERN_ERR "alg: comp: Decompression test %d "
  756. "failed for %s: output len = %d\n", i + 1, algo,
  757. dlen);
  758. ret = -EINVAL;
  759. goto out;
  760. }
  761. if (memcmp(result, dtemplate[i].output, dlen)) {
  762. printk(KERN_ERR "alg: comp: Decompression test %d "
  763. "failed for %s\n", i + 1, algo);
  764. hexdump(result, dlen);
  765. ret = -EINVAL;
  766. goto out;
  767. }
  768. }
  769. ret = 0;
  770. out:
  771. return ret;
  772. }
  773. static int test_pcomp(struct crypto_pcomp *tfm,
  774. struct pcomp_testvec *ctemplate,
  775. struct pcomp_testvec *dtemplate, int ctcount,
  776. int dtcount)
  777. {
  778. const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
  779. unsigned int i;
  780. char result[COMP_BUF_SIZE];
  781. int error;
  782. for (i = 0; i < ctcount; i++) {
  783. struct comp_request req;
  784. error = crypto_compress_setup(tfm, ctemplate[i].params,
  785. ctemplate[i].paramsize);
  786. if (error) {
  787. pr_err("alg: pcomp: compression setup failed on test "
  788. "%d for %s: error=%d\n", i + 1, algo, error);
  789. return error;
  790. }
  791. error = crypto_compress_init(tfm);
  792. if (error) {
  793. pr_err("alg: pcomp: compression init failed on test "
  794. "%d for %s: error=%d\n", i + 1, algo, error);
  795. return error;
  796. }
  797. memset(result, 0, sizeof(result));
  798. req.next_in = ctemplate[i].input;
  799. req.avail_in = ctemplate[i].inlen / 2;
  800. req.next_out = result;
  801. req.avail_out = ctemplate[i].outlen / 2;
  802. error = crypto_compress_update(tfm, &req);
  803. if (error && (error != -EAGAIN || req.avail_in)) {
  804. pr_err("alg: pcomp: compression update failed on test "
  805. "%d for %s: error=%d\n", i + 1, algo, error);
  806. return error;
  807. }
  808. /* Add remaining input data */
  809. req.avail_in += (ctemplate[i].inlen + 1) / 2;
  810. error = crypto_compress_update(tfm, &req);
  811. if (error && (error != -EAGAIN || req.avail_in)) {
  812. pr_err("alg: pcomp: compression update failed on test "
  813. "%d for %s: error=%d\n", i + 1, algo, error);
  814. return error;
  815. }
  816. /* Provide remaining output space */
  817. req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
  818. error = crypto_compress_final(tfm, &req);
  819. if (error) {
  820. pr_err("alg: pcomp: compression final failed on test "
  821. "%d for %s: error=%d\n", i + 1, algo, error);
  822. return error;
  823. }
  824. if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
  825. pr_err("alg: comp: Compression test %d failed for %s: "
  826. "output len = %d (expected %d)\n", i + 1, algo,
  827. COMP_BUF_SIZE - req.avail_out,
  828. ctemplate[i].outlen);
  829. return -EINVAL;
  830. }
  831. if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
  832. pr_err("alg: pcomp: Compression test %d failed for "
  833. "%s\n", i + 1, algo);
  834. hexdump(result, ctemplate[i].outlen);
  835. return -EINVAL;
  836. }
  837. }
  838. for (i = 0; i < dtcount; i++) {
  839. struct comp_request req;
  840. error = crypto_decompress_setup(tfm, dtemplate[i].params,
  841. dtemplate[i].paramsize);
  842. if (error) {
  843. pr_err("alg: pcomp: decompression setup failed on "
  844. "test %d for %s: error=%d\n", i + 1, algo,
  845. error);
  846. return error;
  847. }
  848. error = crypto_decompress_init(tfm);
  849. if (error) {
  850. pr_err("alg: pcomp: decompression init failed on test "
  851. "%d for %s: error=%d\n", i + 1, algo, error);
  852. return error;
  853. }
  854. memset(result, 0, sizeof(result));
  855. req.next_in = dtemplate[i].input;
  856. req.avail_in = dtemplate[i].inlen / 2;
  857. req.next_out = result;
  858. req.avail_out = dtemplate[i].outlen / 2;
  859. error = crypto_decompress_update(tfm, &req);
  860. if (error && (error != -EAGAIN || req.avail_in)) {
  861. pr_err("alg: pcomp: decompression update failed on "
  862. "test %d for %s: error=%d\n", i + 1, algo,
  863. error);
  864. return error;
  865. }
  866. /* Add remaining input data */
  867. req.avail_in += (dtemplate[i].inlen + 1) / 2;
  868. error = crypto_decompress_update(tfm, &req);
  869. if (error && (error != -EAGAIN || req.avail_in)) {
  870. pr_err("alg: pcomp: decompression update failed on "
  871. "test %d for %s: error=%d\n", i + 1, algo,
  872. error);
  873. return error;
  874. }
  875. /* Provide remaining output space */
  876. req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
  877. error = crypto_decompress_final(tfm, &req);
  878. if (error && (error != -EAGAIN || req.avail_in)) {
  879. pr_err("alg: pcomp: decompression final failed on "
  880. "test %d for %s: error=%d\n", i + 1, algo,
  881. error);
  882. return error;
  883. }
  884. if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
  885. pr_err("alg: comp: Decompression test %d failed for "
  886. "%s: output len = %d (expected %d)\n", i + 1,
  887. algo, COMP_BUF_SIZE - req.avail_out,
  888. dtemplate[i].outlen);
  889. return -EINVAL;
  890. }
  891. if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
  892. pr_err("alg: pcomp: Decompression test %d failed for "
  893. "%s\n", i + 1, algo);
  894. hexdump(result, dtemplate[i].outlen);
  895. return -EINVAL;
  896. }
  897. }
  898. return 0;
  899. }
  900. static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
  901. u32 type, u32 mask)
  902. {
  903. struct crypto_aead *tfm;
  904. int err = 0;
  905. tfm = crypto_alloc_aead(driver, type, mask);
  906. if (IS_ERR(tfm)) {
  907. printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
  908. "%ld\n", driver, PTR_ERR(tfm));
  909. return PTR_ERR(tfm);
  910. }
  911. if (desc->suite.aead.enc.vecs) {
  912. err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
  913. desc->suite.aead.enc.count);
  914. if (err)
  915. goto out;
  916. }
  917. if (!err && desc->suite.aead.dec.vecs)
  918. err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
  919. desc->suite.aead.dec.count);
  920. out:
  921. crypto_free_aead(tfm);
  922. return err;
  923. }
  924. static int alg_test_cipher(const struct alg_test_desc *desc,
  925. const char *driver, u32 type, u32 mask)
  926. {
  927. struct crypto_cipher *tfm;
  928. int err = 0;
  929. tfm = crypto_alloc_cipher(driver, type, mask);
  930. if (IS_ERR(tfm)) {
  931. printk(KERN_ERR "alg: cipher: Failed to load transform for "
  932. "%s: %ld\n", driver, PTR_ERR(tfm));
  933. return PTR_ERR(tfm);
  934. }
  935. if (desc->suite.cipher.enc.vecs) {
  936. err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
  937. desc->suite.cipher.enc.count);
  938. if (err)
  939. goto out;
  940. }
  941. if (desc->suite.cipher.dec.vecs)
  942. err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
  943. desc->suite.cipher.dec.count);
  944. out:
  945. crypto_free_cipher(tfm);
  946. return err;
  947. }
  948. static int alg_test_skcipher(const struct alg_test_desc *desc,
  949. const char *driver, u32 type, u32 mask)
  950. {
  951. struct crypto_ablkcipher *tfm;
  952. int err = 0;
  953. tfm = crypto_alloc_ablkcipher(driver, type, mask);
  954. if (IS_ERR(tfm)) {
  955. printk(KERN_ERR "alg: skcipher: Failed to load transform for "
  956. "%s: %ld\n", driver, PTR_ERR(tfm));
  957. return PTR_ERR(tfm);
  958. }
  959. if (desc->suite.cipher.enc.vecs) {
  960. err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
  961. desc->suite.cipher.enc.count);
  962. if (err)
  963. goto out;
  964. }
  965. if (desc->suite.cipher.dec.vecs)
  966. err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
  967. desc->suite.cipher.dec.count);
  968. out:
  969. crypto_free_ablkcipher(tfm);
  970. return err;
  971. }
  972. static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
  973. u32 type, u32 mask)
  974. {
  975. struct crypto_comp *tfm;
  976. int err;
  977. tfm = crypto_alloc_comp(driver, type, mask);
  978. if (IS_ERR(tfm)) {
  979. printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
  980. "%ld\n", driver, PTR_ERR(tfm));
  981. return PTR_ERR(tfm);
  982. }
  983. err = test_comp(tfm, desc->suite.comp.comp.vecs,
  984. desc->suite.comp.decomp.vecs,
  985. desc->suite.comp.comp.count,
  986. desc->suite.comp.decomp.count);
  987. crypto_free_comp(tfm);
  988. return err;
  989. }
  990. static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
  991. u32 type, u32 mask)
  992. {
  993. struct crypto_pcomp *tfm;
  994. int err;
  995. tfm = crypto_alloc_pcomp(driver, type, mask);
  996. if (IS_ERR(tfm)) {
  997. pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
  998. driver, PTR_ERR(tfm));
  999. return PTR_ERR(tfm);
  1000. }
  1001. err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
  1002. desc->suite.pcomp.decomp.vecs,
  1003. desc->suite.pcomp.comp.count,
  1004. desc->suite.pcomp.decomp.count);
  1005. crypto_free_pcomp(tfm);
  1006. return err;
  1007. }
  1008. static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
  1009. u32 type, u32 mask)
  1010. {
  1011. struct crypto_ahash *tfm;
  1012. int err;
  1013. tfm = crypto_alloc_ahash(driver, type, mask);
  1014. if (IS_ERR(tfm)) {
  1015. printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
  1016. "%ld\n", driver, PTR_ERR(tfm));
  1017. return PTR_ERR(tfm);
  1018. }
  1019. err = test_hash(tfm, desc->suite.hash.vecs, desc->suite.hash.count);
  1020. crypto_free_ahash(tfm);
  1021. return err;
  1022. }
  1023. static int alg_test_crc32c(const struct alg_test_desc *desc,
  1024. const char *driver, u32 type, u32 mask)
  1025. {
  1026. struct crypto_shash *tfm;
  1027. u32 val;
  1028. int err;
  1029. err = alg_test_hash(desc, driver, type, mask);
  1030. if (err)
  1031. goto out;
  1032. tfm = crypto_alloc_shash(driver, type, mask);
  1033. if (IS_ERR(tfm)) {
  1034. printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
  1035. "%ld\n", driver, PTR_ERR(tfm));
  1036. err = PTR_ERR(tfm);
  1037. goto out;
  1038. }
  1039. do {
  1040. struct {
  1041. struct shash_desc shash;
  1042. char ctx[crypto_shash_descsize(tfm)];
  1043. } sdesc;
  1044. sdesc.shash.tfm = tfm;
  1045. sdesc.shash.flags = 0;
  1046. *(u32 *)sdesc.ctx = le32_to_cpu(420553207);
  1047. err = crypto_shash_final(&sdesc.shash, (u8 *)&val);
  1048. if (err) {
  1049. printk(KERN_ERR "alg: crc32c: Operation failed for "
  1050. "%s: %d\n", driver, err);
  1051. break;
  1052. }
  1053. if (val != ~420553207) {
  1054. printk(KERN_ERR "alg: crc32c: Test failed for %s: "
  1055. "%d\n", driver, val);
  1056. err = -EINVAL;
  1057. }
  1058. } while (0);
  1059. crypto_free_shash(tfm);
  1060. out:
  1061. return err;
  1062. }
  1063. /* Please keep this list sorted by algorithm name. */
  1064. static const struct alg_test_desc alg_test_descs[] = {
  1065. {
  1066. .alg = "cbc(aes)",
  1067. .test = alg_test_skcipher,
  1068. .suite = {
  1069. .cipher = {
  1070. .enc = {
  1071. .vecs = aes_cbc_enc_tv_template,
  1072. .count = AES_CBC_ENC_TEST_VECTORS
  1073. },
  1074. .dec = {
  1075. .vecs = aes_cbc_dec_tv_template,
  1076. .count = AES_CBC_DEC_TEST_VECTORS
  1077. }
  1078. }
  1079. }
  1080. }, {
  1081. .alg = "cbc(anubis)",
  1082. .test = alg_test_skcipher,
  1083. .suite = {
  1084. .cipher = {
  1085. .enc = {
  1086. .vecs = anubis_cbc_enc_tv_template,
  1087. .count = ANUBIS_CBC_ENC_TEST_VECTORS
  1088. },
  1089. .dec = {
  1090. .vecs = anubis_cbc_dec_tv_template,
  1091. .count = ANUBIS_CBC_DEC_TEST_VECTORS
  1092. }
  1093. }
  1094. }
  1095. }, {
  1096. .alg = "cbc(blowfish)",
  1097. .test = alg_test_skcipher,
  1098. .suite = {
  1099. .cipher = {
  1100. .enc = {
  1101. .vecs = bf_cbc_enc_tv_template,
  1102. .count = BF_CBC_ENC_TEST_VECTORS
  1103. },
  1104. .dec = {
  1105. .vecs = bf_cbc_dec_tv_template,
  1106. .count = BF_CBC_DEC_TEST_VECTORS
  1107. }
  1108. }
  1109. }
  1110. }, {
  1111. .alg = "cbc(camellia)",
  1112. .test = alg_test_skcipher,
  1113. .suite = {
  1114. .cipher = {
  1115. .enc = {
  1116. .vecs = camellia_cbc_enc_tv_template,
  1117. .count = CAMELLIA_CBC_ENC_TEST_VECTORS
  1118. },
  1119. .dec = {
  1120. .vecs = camellia_cbc_dec_tv_template,
  1121. .count = CAMELLIA_CBC_DEC_TEST_VECTORS
  1122. }
  1123. }
  1124. }
  1125. }, {
  1126. .alg = "cbc(des)",
  1127. .test = alg_test_skcipher,
  1128. .suite = {
  1129. .cipher = {
  1130. .enc = {
  1131. .vecs = des_cbc_enc_tv_template,
  1132. .count = DES_CBC_ENC_TEST_VECTORS
  1133. },
  1134. .dec = {
  1135. .vecs = des_cbc_dec_tv_template,
  1136. .count = DES_CBC_DEC_TEST_VECTORS
  1137. }
  1138. }
  1139. }
  1140. }, {
  1141. .alg = "cbc(des3_ede)",
  1142. .test = alg_test_skcipher,
  1143. .suite = {
  1144. .cipher = {
  1145. .enc = {
  1146. .vecs = des3_ede_cbc_enc_tv_template,
  1147. .count = DES3_EDE_CBC_ENC_TEST_VECTORS
  1148. },
  1149. .dec = {
  1150. .vecs = des3_ede_cbc_dec_tv_template,
  1151. .count = DES3_EDE_CBC_DEC_TEST_VECTORS
  1152. }
  1153. }
  1154. }
  1155. }, {
  1156. .alg = "cbc(twofish)",
  1157. .test = alg_test_skcipher,
  1158. .suite = {
  1159. .cipher = {
  1160. .enc = {
  1161. .vecs = tf_cbc_enc_tv_template,
  1162. .count = TF_CBC_ENC_TEST_VECTORS
  1163. },
  1164. .dec = {
  1165. .vecs = tf_cbc_dec_tv_template,
  1166. .count = TF_CBC_DEC_TEST_VECTORS
  1167. }
  1168. }
  1169. }
  1170. }, {
  1171. .alg = "ccm(aes)",
  1172. .test = alg_test_aead,
  1173. .suite = {
  1174. .aead = {
  1175. .enc = {
  1176. .vecs = aes_ccm_enc_tv_template,
  1177. .count = AES_CCM_ENC_TEST_VECTORS
  1178. },
  1179. .dec = {
  1180. .vecs = aes_ccm_dec_tv_template,
  1181. .count = AES_CCM_DEC_TEST_VECTORS
  1182. }
  1183. }
  1184. }
  1185. }, {
  1186. .alg = "crc32c",
  1187. .test = alg_test_crc32c,
  1188. .suite = {
  1189. .hash = {
  1190. .vecs = crc32c_tv_template,
  1191. .count = CRC32C_TEST_VECTORS
  1192. }
  1193. }
  1194. }, {
  1195. .alg = "cts(cbc(aes))",
  1196. .test = alg_test_skcipher,
  1197. .suite = {
  1198. .cipher = {
  1199. .enc = {
  1200. .vecs = cts_mode_enc_tv_template,
  1201. .count = CTS_MODE_ENC_TEST_VECTORS
  1202. },
  1203. .dec = {
  1204. .vecs = cts_mode_dec_tv_template,
  1205. .count = CTS_MODE_DEC_TEST_VECTORS
  1206. }
  1207. }
  1208. }
  1209. }, {
  1210. .alg = "deflate",
  1211. .test = alg_test_comp,
  1212. .suite = {
  1213. .comp = {
  1214. .comp = {
  1215. .vecs = deflate_comp_tv_template,
  1216. .count = DEFLATE_COMP_TEST_VECTORS
  1217. },
  1218. .decomp = {
  1219. .vecs = deflate_decomp_tv_template,
  1220. .count = DEFLATE_DECOMP_TEST_VECTORS
  1221. }
  1222. }
  1223. }
  1224. }, {
  1225. .alg = "ecb(aes)",
  1226. .test = alg_test_skcipher,
  1227. .suite = {
  1228. .cipher = {
  1229. .enc = {
  1230. .vecs = aes_enc_tv_template,
  1231. .count = AES_ENC_TEST_VECTORS
  1232. },
  1233. .dec = {
  1234. .vecs = aes_dec_tv_template,
  1235. .count = AES_DEC_TEST_VECTORS
  1236. }
  1237. }
  1238. }
  1239. }, {
  1240. .alg = "ecb(anubis)",
  1241. .test = alg_test_skcipher,
  1242. .suite = {
  1243. .cipher = {
  1244. .enc = {
  1245. .vecs = anubis_enc_tv_template,
  1246. .count = ANUBIS_ENC_TEST_VECTORS
  1247. },
  1248. .dec = {
  1249. .vecs = anubis_dec_tv_template,
  1250. .count = ANUBIS_DEC_TEST_VECTORS
  1251. }
  1252. }
  1253. }
  1254. }, {
  1255. .alg = "ecb(arc4)",
  1256. .test = alg_test_skcipher,
  1257. .suite = {
  1258. .cipher = {
  1259. .enc = {
  1260. .vecs = arc4_enc_tv_template,
  1261. .count = ARC4_ENC_TEST_VECTORS
  1262. },
  1263. .dec = {
  1264. .vecs = arc4_dec_tv_template,
  1265. .count = ARC4_DEC_TEST_VECTORS
  1266. }
  1267. }
  1268. }
  1269. }, {
  1270. .alg = "ecb(blowfish)",
  1271. .test = alg_test_skcipher,
  1272. .suite = {
  1273. .cipher = {
  1274. .enc = {
  1275. .vecs = bf_enc_tv_template,
  1276. .count = BF_ENC_TEST_VECTORS
  1277. },
  1278. .dec = {
  1279. .vecs = bf_dec_tv_template,
  1280. .count = BF_DEC_TEST_VECTORS
  1281. }
  1282. }
  1283. }
  1284. }, {
  1285. .alg = "ecb(camellia)",
  1286. .test = alg_test_skcipher,
  1287. .suite = {
  1288. .cipher = {
  1289. .enc = {
  1290. .vecs = camellia_enc_tv_template,
  1291. .count = CAMELLIA_ENC_TEST_VECTORS
  1292. },
  1293. .dec = {
  1294. .vecs = camellia_dec_tv_template,
  1295. .count = CAMELLIA_DEC_TEST_VECTORS
  1296. }
  1297. }
  1298. }
  1299. }, {
  1300. .alg = "ecb(cast5)",
  1301. .test = alg_test_skcipher,
  1302. .suite = {
  1303. .cipher = {
  1304. .enc = {
  1305. .vecs = cast5_enc_tv_template,
  1306. .count = CAST5_ENC_TEST_VECTORS
  1307. },
  1308. .dec = {
  1309. .vecs = cast5_dec_tv_template,
  1310. .count = CAST5_DEC_TEST_VECTORS
  1311. }
  1312. }
  1313. }
  1314. }, {
  1315. .alg = "ecb(cast6)",
  1316. .test = alg_test_skcipher,
  1317. .suite = {
  1318. .cipher = {
  1319. .enc = {
  1320. .vecs = cast6_enc_tv_template,
  1321. .count = CAST6_ENC_TEST_VECTORS
  1322. },
  1323. .dec = {
  1324. .vecs = cast6_dec_tv_template,
  1325. .count = CAST6_DEC_TEST_VECTORS
  1326. }
  1327. }
  1328. }
  1329. }, {
  1330. .alg = "ecb(des)",
  1331. .test = alg_test_skcipher,
  1332. .suite = {
  1333. .cipher = {
  1334. .enc = {
  1335. .vecs = des_enc_tv_template,
  1336. .count = DES_ENC_TEST_VECTORS
  1337. },
  1338. .dec = {
  1339. .vecs = des_dec_tv_template,
  1340. .count = DES_DEC_TEST_VECTORS
  1341. }
  1342. }
  1343. }
  1344. }, {
  1345. .alg = "ecb(des3_ede)",
  1346. .test = alg_test_skcipher,
  1347. .suite = {
  1348. .cipher = {
  1349. .enc = {
  1350. .vecs = des3_ede_enc_tv_template,
  1351. .count = DES3_EDE_ENC_TEST_VECTORS
  1352. },
  1353. .dec = {
  1354. .vecs = des3_ede_dec_tv_template,
  1355. .count = DES3_EDE_DEC_TEST_VECTORS
  1356. }
  1357. }
  1358. }
  1359. }, {
  1360. .alg = "ecb(khazad)",
  1361. .test = alg_test_skcipher,
  1362. .suite = {
  1363. .cipher = {
  1364. .enc = {
  1365. .vecs = khazad_enc_tv_template,
  1366. .count = KHAZAD_ENC_TEST_VECTORS
  1367. },
  1368. .dec = {
  1369. .vecs = khazad_dec_tv_template,
  1370. .count = KHAZAD_DEC_TEST_VECTORS
  1371. }
  1372. }
  1373. }
  1374. }, {
  1375. .alg = "ecb(seed)",
  1376. .test = alg_test_skcipher,
  1377. .suite = {
  1378. .cipher = {
  1379. .enc = {
  1380. .vecs = seed_enc_tv_template,
  1381. .count = SEED_ENC_TEST_VECTORS
  1382. },
  1383. .dec = {
  1384. .vecs = seed_dec_tv_template,
  1385. .count = SEED_DEC_TEST_VECTORS
  1386. }
  1387. }
  1388. }
  1389. }, {
  1390. .alg = "ecb(serpent)",
  1391. .test = alg_test_skcipher,
  1392. .suite = {
  1393. .cipher = {
  1394. .enc = {
  1395. .vecs = serpent_enc_tv_template,
  1396. .count = SERPENT_ENC_TEST_VECTORS
  1397. },
  1398. .dec = {
  1399. .vecs = serpent_dec_tv_template,
  1400. .count = SERPENT_DEC_TEST_VECTORS
  1401. }
  1402. }
  1403. }
  1404. }, {
  1405. .alg = "ecb(tea)",
  1406. .test = alg_test_skcipher,
  1407. .suite = {
  1408. .cipher = {
  1409. .enc = {
  1410. .vecs = tea_enc_tv_template,
  1411. .count = TEA_ENC_TEST_VECTORS
  1412. },
  1413. .dec = {
  1414. .vecs = tea_dec_tv_template,
  1415. .count = TEA_DEC_TEST_VECTORS
  1416. }
  1417. }
  1418. }
  1419. }, {
  1420. .alg = "ecb(tnepres)",
  1421. .test = alg_test_skcipher,
  1422. .suite = {
  1423. .cipher = {
  1424. .enc = {
  1425. .vecs = tnepres_enc_tv_template,
  1426. .count = TNEPRES_ENC_TEST_VECTORS
  1427. },
  1428. .dec = {
  1429. .vecs = tnepres_dec_tv_template,
  1430. .count = TNEPRES_DEC_TEST_VECTORS
  1431. }
  1432. }
  1433. }
  1434. }, {
  1435. .alg = "ecb(twofish)",
  1436. .test = alg_test_skcipher,
  1437. .suite = {
  1438. .cipher = {
  1439. .enc = {
  1440. .vecs = tf_enc_tv_template,
  1441. .count = TF_ENC_TEST_VECTORS
  1442. },
  1443. .dec = {
  1444. .vecs = tf_dec_tv_template,
  1445. .count = TF_DEC_TEST_VECTORS
  1446. }
  1447. }
  1448. }
  1449. }, {
  1450. .alg = "ecb(xeta)",
  1451. .test = alg_test_skcipher,
  1452. .suite = {
  1453. .cipher = {
  1454. .enc = {
  1455. .vecs = xeta_enc_tv_template,
  1456. .count = XETA_ENC_TEST_VECTORS
  1457. },
  1458. .dec = {
  1459. .vecs = xeta_dec_tv_template,
  1460. .count = XETA_DEC_TEST_VECTORS
  1461. }
  1462. }
  1463. }
  1464. }, {
  1465. .alg = "ecb(xtea)",
  1466. .test = alg_test_skcipher,
  1467. .suite = {
  1468. .cipher = {
  1469. .enc = {
  1470. .vecs = xtea_enc_tv_template,
  1471. .count = XTEA_ENC_TEST_VECTORS
  1472. },
  1473. .dec = {
  1474. .vecs = xtea_dec_tv_template,
  1475. .count = XTEA_DEC_TEST_VECTORS
  1476. }
  1477. }
  1478. }
  1479. }, {
  1480. .alg = "gcm(aes)",
  1481. .test = alg_test_aead,
  1482. .suite = {
  1483. .aead = {
  1484. .enc = {
  1485. .vecs = aes_gcm_enc_tv_template,
  1486. .count = AES_GCM_ENC_TEST_VECTORS
  1487. },
  1488. .dec = {
  1489. .vecs = aes_gcm_dec_tv_template,
  1490. .count = AES_GCM_DEC_TEST_VECTORS
  1491. }
  1492. }
  1493. }
  1494. }, {
  1495. .alg = "hmac(md5)",
  1496. .test = alg_test_hash,
  1497. .suite = {
  1498. .hash = {
  1499. .vecs = hmac_md5_tv_template,
  1500. .count = HMAC_MD5_TEST_VECTORS
  1501. }
  1502. }
  1503. }, {
  1504. .alg = "hmac(rmd128)",
  1505. .test = alg_test_hash,
  1506. .suite = {
  1507. .hash = {
  1508. .vecs = hmac_rmd128_tv_template,
  1509. .count = HMAC_RMD128_TEST_VECTORS
  1510. }
  1511. }
  1512. }, {
  1513. .alg = "hmac(rmd160)",
  1514. .test = alg_test_hash,
  1515. .suite = {
  1516. .hash = {
  1517. .vecs = hmac_rmd160_tv_template,
  1518. .count = HMAC_RMD160_TEST_VECTORS
  1519. }
  1520. }
  1521. }, {
  1522. .alg = "hmac(sha1)",
  1523. .test = alg_test_hash,
  1524. .suite = {
  1525. .hash = {
  1526. .vecs = hmac_sha1_tv_template,
  1527. .count = HMAC_SHA1_TEST_VECTORS
  1528. }
  1529. }
  1530. }, {
  1531. .alg = "hmac(sha224)",
  1532. .test = alg_test_hash,
  1533. .suite = {
  1534. .hash = {
  1535. .vecs = hmac_sha224_tv_template,
  1536. .count = HMAC_SHA224_TEST_VECTORS
  1537. }
  1538. }
  1539. }, {
  1540. .alg = "hmac(sha256)",
  1541. .test = alg_test_hash,
  1542. .suite = {
  1543. .hash = {
  1544. .vecs = hmac_sha256_tv_template,
  1545. .count = HMAC_SHA256_TEST_VECTORS
  1546. }
  1547. }
  1548. }, {
  1549. .alg = "hmac(sha384)",
  1550. .test = alg_test_hash,
  1551. .suite = {
  1552. .hash = {
  1553. .vecs = hmac_sha384_tv_template,
  1554. .count = HMAC_SHA384_TEST_VECTORS
  1555. }
  1556. }
  1557. }, {
  1558. .alg = "hmac(sha512)",
  1559. .test = alg_test_hash,
  1560. .suite = {
  1561. .hash = {
  1562. .vecs = hmac_sha512_tv_template,
  1563. .count = HMAC_SHA512_TEST_VECTORS
  1564. }
  1565. }
  1566. }, {
  1567. .alg = "lrw(aes)",
  1568. .test = alg_test_skcipher,
  1569. .suite = {
  1570. .cipher = {
  1571. .enc = {
  1572. .vecs = aes_lrw_enc_tv_template,
  1573. .count = AES_LRW_ENC_TEST_VECTORS
  1574. },
  1575. .dec = {
  1576. .vecs = aes_lrw_dec_tv_template,
  1577. .count = AES_LRW_DEC_TEST_VECTORS
  1578. }
  1579. }
  1580. }
  1581. }, {
  1582. .alg = "lzo",
  1583. .test = alg_test_comp,
  1584. .suite = {
  1585. .comp = {
  1586. .comp = {
  1587. .vecs = lzo_comp_tv_template,
  1588. .count = LZO_COMP_TEST_VECTORS
  1589. },
  1590. .decomp = {
  1591. .vecs = lzo_decomp_tv_template,
  1592. .count = LZO_DECOMP_TEST_VECTORS
  1593. }
  1594. }
  1595. }
  1596. }, {
  1597. .alg = "md4",
  1598. .test = alg_test_hash,
  1599. .suite = {
  1600. .hash = {
  1601. .vecs = md4_tv_template,
  1602. .count = MD4_TEST_VECTORS
  1603. }
  1604. }
  1605. }, {
  1606. .alg = "md5",
  1607. .test = alg_test_hash,
  1608. .suite = {
  1609. .hash = {
  1610. .vecs = md5_tv_template,
  1611. .count = MD5_TEST_VECTORS
  1612. }
  1613. }
  1614. }, {
  1615. .alg = "michael_mic",
  1616. .test = alg_test_hash,
  1617. .suite = {
  1618. .hash = {
  1619. .vecs = michael_mic_tv_template,
  1620. .count = MICHAEL_MIC_TEST_VECTORS
  1621. }
  1622. }
  1623. }, {
  1624. .alg = "pcbc(fcrypt)",
  1625. .test = alg_test_skcipher,
  1626. .suite = {
  1627. .cipher = {
  1628. .enc = {
  1629. .vecs = fcrypt_pcbc_enc_tv_template,
  1630. .count = FCRYPT_ENC_TEST_VECTORS
  1631. },
  1632. .dec = {
  1633. .vecs = fcrypt_pcbc_dec_tv_template,
  1634. .count = FCRYPT_DEC_TEST_VECTORS
  1635. }
  1636. }
  1637. }
  1638. }, {
  1639. .alg = "rfc3686(ctr(aes))",
  1640. .test = alg_test_skcipher,
  1641. .suite = {
  1642. .cipher = {
  1643. .enc = {
  1644. .vecs = aes_ctr_enc_tv_template,
  1645. .count = AES_CTR_ENC_TEST_VECTORS
  1646. },
  1647. .dec = {
  1648. .vecs = aes_ctr_dec_tv_template,
  1649. .count = AES_CTR_DEC_TEST_VECTORS
  1650. }
  1651. }
  1652. }
  1653. }, {
  1654. .alg = "rmd128",
  1655. .test = alg_test_hash,
  1656. .suite = {
  1657. .hash = {
  1658. .vecs = rmd128_tv_template,
  1659. .count = RMD128_TEST_VECTORS
  1660. }
  1661. }
  1662. }, {
  1663. .alg = "rmd160",
  1664. .test = alg_test_hash,
  1665. .suite = {
  1666. .hash = {
  1667. .vecs = rmd160_tv_template,
  1668. .count = RMD160_TEST_VECTORS
  1669. }
  1670. }
  1671. }, {
  1672. .alg = "rmd256",
  1673. .test = alg_test_hash,
  1674. .suite = {
  1675. .hash = {
  1676. .vecs = rmd256_tv_template,
  1677. .count = RMD256_TEST_VECTORS
  1678. }
  1679. }
  1680. }, {
  1681. .alg = "rmd320",
  1682. .test = alg_test_hash,
  1683. .suite = {
  1684. .hash = {
  1685. .vecs = rmd320_tv_template,
  1686. .count = RMD320_TEST_VECTORS
  1687. }
  1688. }
  1689. }, {
  1690. .alg = "salsa20",
  1691. .test = alg_test_skcipher,
  1692. .suite = {
  1693. .cipher = {
  1694. .enc = {
  1695. .vecs = salsa20_stream_enc_tv_template,
  1696. .count = SALSA20_STREAM_ENC_TEST_VECTORS
  1697. }
  1698. }
  1699. }
  1700. }, {
  1701. .alg = "sha1",
  1702. .test = alg_test_hash,
  1703. .suite = {
  1704. .hash = {
  1705. .vecs = sha1_tv_template,
  1706. .count = SHA1_TEST_VECTORS
  1707. }
  1708. }
  1709. }, {
  1710. .alg = "sha224",
  1711. .test = alg_test_hash,
  1712. .suite = {
  1713. .hash = {
  1714. .vecs = sha224_tv_template,
  1715. .count = SHA224_TEST_VECTORS
  1716. }
  1717. }
  1718. }, {
  1719. .alg = "sha256",
  1720. .test = alg_test_hash,
  1721. .suite = {
  1722. .hash = {
  1723. .vecs = sha256_tv_template,
  1724. .count = SHA256_TEST_VECTORS
  1725. }
  1726. }
  1727. }, {
  1728. .alg = "sha384",
  1729. .test = alg_test_hash,
  1730. .suite = {
  1731. .hash = {
  1732. .vecs = sha384_tv_template,
  1733. .count = SHA384_TEST_VECTORS
  1734. }
  1735. }
  1736. }, {
  1737. .alg = "sha512",
  1738. .test = alg_test_hash,
  1739. .suite = {
  1740. .hash = {
  1741. .vecs = sha512_tv_template,
  1742. .count = SHA512_TEST_VECTORS
  1743. }
  1744. }
  1745. }, {
  1746. .alg = "tgr128",
  1747. .test = alg_test_hash,
  1748. .suite = {
  1749. .hash = {
  1750. .vecs = tgr128_tv_template,
  1751. .count = TGR128_TEST_VECTORS
  1752. }
  1753. }
  1754. }, {
  1755. .alg = "tgr160",
  1756. .test = alg_test_hash,
  1757. .suite = {
  1758. .hash = {
  1759. .vecs = tgr160_tv_template,
  1760. .count = TGR160_TEST_VECTORS
  1761. }
  1762. }
  1763. }, {
  1764. .alg = "tgr192",
  1765. .test = alg_test_hash,
  1766. .suite = {
  1767. .hash = {
  1768. .vecs = tgr192_tv_template,
  1769. .count = TGR192_TEST_VECTORS
  1770. }
  1771. }
  1772. }, {
  1773. .alg = "wp256",
  1774. .test = alg_test_hash,
  1775. .suite = {
  1776. .hash = {
  1777. .vecs = wp256_tv_template,
  1778. .count = WP256_TEST_VECTORS
  1779. }
  1780. }
  1781. }, {
  1782. .alg = "wp384",
  1783. .test = alg_test_hash,
  1784. .suite = {
  1785. .hash = {
  1786. .vecs = wp384_tv_template,
  1787. .count = WP384_TEST_VECTORS
  1788. }
  1789. }
  1790. }, {
  1791. .alg = "wp512",
  1792. .test = alg_test_hash,
  1793. .suite = {
  1794. .hash = {
  1795. .vecs = wp512_tv_template,
  1796. .count = WP512_TEST_VECTORS
  1797. }
  1798. }
  1799. }, {
  1800. .alg = "xcbc(aes)",
  1801. .test = alg_test_hash,
  1802. .suite = {
  1803. .hash = {
  1804. .vecs = aes_xcbc128_tv_template,
  1805. .count = XCBC_AES_TEST_VECTORS
  1806. }
  1807. }
  1808. }, {
  1809. .alg = "xts(aes)",
  1810. .test = alg_test_skcipher,
  1811. .suite = {
  1812. .cipher = {
  1813. .enc = {
  1814. .vecs = aes_xts_enc_tv_template,
  1815. .count = AES_XTS_ENC_TEST_VECTORS
  1816. },
  1817. .dec = {
  1818. .vecs = aes_xts_dec_tv_template,
  1819. .count = AES_XTS_DEC_TEST_VECTORS
  1820. }
  1821. }
  1822. }
  1823. }, {
  1824. .alg = "zlib",
  1825. .test = alg_test_pcomp,
  1826. .suite = {
  1827. .pcomp = {
  1828. .comp = {
  1829. .vecs = zlib_comp_tv_template,
  1830. .count = ZLIB_COMP_TEST_VECTORS
  1831. },
  1832. .decomp = {
  1833. .vecs = zlib_decomp_tv_template,
  1834. .count = ZLIB_DECOMP_TEST_VECTORS
  1835. }
  1836. }
  1837. }
  1838. }
  1839. };
  1840. static int alg_find_test(const char *alg)
  1841. {
  1842. int start = 0;
  1843. int end = ARRAY_SIZE(alg_test_descs);
  1844. while (start < end) {
  1845. int i = (start + end) / 2;
  1846. int diff = strcmp(alg_test_descs[i].alg, alg);
  1847. if (diff > 0) {
  1848. end = i;
  1849. continue;
  1850. }
  1851. if (diff < 0) {
  1852. start = i + 1;
  1853. continue;
  1854. }
  1855. return i;
  1856. }
  1857. return -1;
  1858. }
  1859. int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
  1860. {
  1861. int i;
  1862. int rc;
  1863. if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
  1864. char nalg[CRYPTO_MAX_ALG_NAME];
  1865. if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
  1866. sizeof(nalg))
  1867. return -ENAMETOOLONG;
  1868. i = alg_find_test(nalg);
  1869. if (i < 0)
  1870. goto notest;
  1871. return alg_test_cipher(alg_test_descs + i, driver, type, mask);
  1872. }
  1873. i = alg_find_test(alg);
  1874. if (i < 0)
  1875. goto notest;
  1876. rc = alg_test_descs[i].test(alg_test_descs + i, driver,
  1877. type, mask);
  1878. if (fips_enabled && rc)
  1879. panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
  1880. return rc;
  1881. notest:
  1882. printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
  1883. return 0;
  1884. }
  1885. EXPORT_SYMBOL_GPL(alg_test);
  1886. int __init testmgr_init(void)
  1887. {
  1888. int i;
  1889. for (i = 0; i < XBUFSIZE; i++) {
  1890. xbuf[i] = (void *)__get_free_page(GFP_KERNEL);
  1891. if (!xbuf[i])
  1892. goto err_free_xbuf;
  1893. }
  1894. for (i = 0; i < XBUFSIZE; i++) {
  1895. axbuf[i] = (void *)__get_free_page(GFP_KERNEL);
  1896. if (!axbuf[i])
  1897. goto err_free_axbuf;
  1898. }
  1899. return 0;
  1900. err_free_axbuf:
  1901. for (i = 0; i < XBUFSIZE && axbuf[i]; i++)
  1902. free_page((unsigned long)axbuf[i]);
  1903. err_free_xbuf:
  1904. for (i = 0; i < XBUFSIZE && xbuf[i]; i++)
  1905. free_page((unsigned long)xbuf[i]);
  1906. return -ENOMEM;
  1907. }
  1908. void testmgr_exit(void)
  1909. {
  1910. int i;
  1911. for (i = 0; i < XBUFSIZE; i++)
  1912. free_page((unsigned long)axbuf[i]);
  1913. for (i = 0; i < XBUFSIZE; i++)
  1914. free_page((unsigned long)xbuf[i]);
  1915. }