testmgr.c 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140
  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. * Updated RFC4106 AES-GCM testing.
  10. * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
  11. * Adrian Hoban <adrian.hoban@intel.com>
  12. * Gabriele Paoloni <gabriele.paoloni@intel.com>
  13. * Tadeusz Struk (tadeusz.struk@intel.com)
  14. * Copyright (c) 2010, Intel Corporation.
  15. *
  16. * This program is free software; you can redistribute it and/or modify it
  17. * under the terms of the GNU General Public License as published by the Free
  18. * Software Foundation; either version 2 of the License, or (at your option)
  19. * any later version.
  20. *
  21. */
  22. #include <crypto/hash.h>
  23. #include <linux/err.h>
  24. #include <linux/module.h>
  25. #include <linux/scatterlist.h>
  26. #include <linux/slab.h>
  27. #include <linux/string.h>
  28. #include <crypto/rng.h>
  29. #ifdef CONFIG_CRYPTO_DRBG
  30. #include <crypto/drbg.h>
  31. #endif
  32. #include "internal.h"
  33. #ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
  34. /* a perfect nop */
  35. int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
  36. {
  37. return 0;
  38. }
  39. #ifdef CONFIG_CRYPTO_FIPS
  40. bool in_fips_err()
  41. {
  42. return false;
  43. }
  44. EXPORT_SYMBOL_GPL(in_fips_err);
  45. #endif
  46. #else
  47. #include "testmgr.h"
  48. /*
  49. * Need slab memory for testing (size in number of pages).
  50. */
  51. #define XBUFSIZE 8
  52. /*
  53. * Indexes into the xbuf to simulate cross-page access.
  54. */
  55. #define IDX1 32
  56. #define IDX2 32400
  57. #define IDX3 1
  58. #define IDX4 8193
  59. #define IDX5 22222
  60. #define IDX6 17101
  61. #define IDX7 27333
  62. #define IDX8 3000
  63. /*
  64. * Used by test_cipher()
  65. */
  66. #define ENCRYPT 1
  67. #define DECRYPT 0
  68. #ifdef CONFIG_CRYPTO_FIPS
  69. #define FIPS_ERR 1
  70. #define FIPS_NO_ERR 0
  71. static int IN_FIPS_ERROR = FIPS_NO_ERR;
  72. #endif
  73. struct tcrypt_result {
  74. struct completion completion;
  75. int err;
  76. };
  77. struct aead_test_suite {
  78. struct {
  79. struct aead_testvec *vecs;
  80. unsigned int count;
  81. } enc, dec;
  82. };
  83. struct cipher_test_suite {
  84. struct {
  85. struct cipher_testvec *vecs;
  86. unsigned int count;
  87. } enc, dec;
  88. };
  89. struct comp_test_suite {
  90. struct {
  91. struct comp_testvec *vecs;
  92. unsigned int count;
  93. } comp, decomp;
  94. };
  95. struct pcomp_test_suite {
  96. struct {
  97. struct pcomp_testvec *vecs;
  98. unsigned int count;
  99. } comp, decomp;
  100. };
  101. struct hash_test_suite {
  102. struct hash_testvec *vecs;
  103. unsigned int count;
  104. };
  105. struct cprng_test_suite {
  106. struct cprng_testvec *vecs;
  107. unsigned int count;
  108. };
  109. #ifdef CONFIG_CRYPTO_DRBG
  110. struct drbg_test_suite {
  111. struct drbg_testvec *vecs;
  112. unsigned int count;
  113. };
  114. #endif
  115. struct alg_test_desc {
  116. const char *alg;
  117. int (*test)(const struct alg_test_desc *desc, const char *driver,
  118. u32 type, u32 mask);
  119. int fips_allowed; /* set if alg is allowed in fips mode */
  120. union {
  121. struct aead_test_suite aead;
  122. struct cipher_test_suite cipher;
  123. struct comp_test_suite comp;
  124. struct pcomp_test_suite pcomp;
  125. struct hash_test_suite hash;
  126. struct cprng_test_suite cprng;
  127. #ifdef CONFIG_CRYPTO_DRBG
  128. struct drbg_test_suite drbg;
  129. #endif
  130. } suite;
  131. };
  132. static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
  133. #ifdef CONFIG_CRYPTO_FIPS
  134. bool in_fips_err()
  135. {
  136. return (IN_FIPS_ERROR == FIPS_ERR);
  137. }
  138. void set_in_fips_err()
  139. {
  140. IN_FIPS_ERROR = FIPS_ERR;
  141. }
  142. #endif
  143. #if FIPS_FUNC_TEST == 4
  144. void hexdump(unsigned char *buf, unsigned int len)
  145. #else
  146. static void hexdump(unsigned char *buf, unsigned int len)
  147. #endif
  148. {
  149. print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
  150. 16, 1,
  151. buf, len, false);
  152. }
  153. static void tcrypt_complete(struct crypto_async_request *req, int err)
  154. {
  155. struct tcrypt_result *res = req->data;
  156. if (err == -EINPROGRESS)
  157. return;
  158. res->err = err;
  159. complete(&res->completion);
  160. }
  161. static int testmgr_alloc_buf(char *buf[XBUFSIZE])
  162. {
  163. int i;
  164. for (i = 0; i < XBUFSIZE; i++) {
  165. buf[i] = (void *)__get_free_page(GFP_KERNEL);
  166. if (!buf[i])
  167. goto err_free_buf;
  168. }
  169. return 0;
  170. err_free_buf:
  171. while (i-- > 0)
  172. free_page((unsigned long)buf[i]);
  173. return -ENOMEM;
  174. }
  175. static void testmgr_free_buf(char *buf[XBUFSIZE])
  176. {
  177. int i;
  178. for (i = 0; i < XBUFSIZE; i++)
  179. free_page((unsigned long)buf[i]);
  180. }
  181. static int do_one_async_hash_op(struct ahash_request *req,
  182. struct tcrypt_result *tr,
  183. int ret)
  184. {
  185. if (ret == -EINPROGRESS || ret == -EBUSY) {
  186. ret = wait_for_completion_interruptible(&tr->completion);
  187. if (!ret)
  188. ret = tr->err;
  189. INIT_COMPLETION(tr->completion);
  190. }
  191. return ret;
  192. }
  193. static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
  194. unsigned int tcount, bool use_digest)
  195. {
  196. const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
  197. unsigned int i, j, k, temp;
  198. struct scatterlist sg[8];
  199. char result[64];
  200. struct ahash_request *req;
  201. struct tcrypt_result tresult;
  202. void *hash_buff;
  203. char *xbuf[XBUFSIZE];
  204. int ret = -ENOMEM;
  205. if (testmgr_alloc_buf(xbuf))
  206. goto out_nobuf;
  207. init_completion(&tresult.completion);
  208. req = ahash_request_alloc(tfm, GFP_KERNEL);
  209. if (!req) {
  210. printk(KERN_ERR "alg: hash: Failed to allocate request for "
  211. "%s\n", algo);
  212. goto out_noreq;
  213. }
  214. ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  215. tcrypt_complete, &tresult);
  216. j = 0;
  217. for (i = 0; i < tcount; i++) {
  218. if (template[i].np)
  219. continue;
  220. j++;
  221. memset(result, 0, 64);
  222. hash_buff = xbuf[0];
  223. memcpy(hash_buff, template[i].plaintext, template[i].psize);
  224. sg_init_one(&sg[0], hash_buff, template[i].psize);
  225. if (template[i].ksize) {
  226. crypto_ahash_clear_flags(tfm, ~0);
  227. ret = crypto_ahash_setkey(tfm, template[i].key,
  228. template[i].ksize);
  229. if (ret) {
  230. printk(KERN_ERR "alg: hash: setkey failed on "
  231. "test %d for %s: ret=%d\n", j, algo,
  232. -ret);
  233. goto out;
  234. }
  235. }
  236. ahash_request_set_crypt(req, sg, result, template[i].psize);
  237. if (use_digest) {
  238. ret = do_one_async_hash_op(req, &tresult,
  239. crypto_ahash_digest(req));
  240. if (ret) {
  241. pr_err("alg: hash: digest failed on test %d "
  242. "for %s: ret=%d\n", j, algo, -ret);
  243. goto out;
  244. }
  245. } else {
  246. ret = do_one_async_hash_op(req, &tresult,
  247. crypto_ahash_init(req));
  248. if (ret) {
  249. pr_err("alt: hash: init failed on test %d "
  250. "for %s: ret=%d\n", j, algo, -ret);
  251. goto out;
  252. }
  253. ret = do_one_async_hash_op(req, &tresult,
  254. crypto_ahash_update(req));
  255. if (ret) {
  256. pr_err("alt: hash: update failed on test %d "
  257. "for %s: ret=%d\n", j, algo, -ret);
  258. goto out;
  259. }
  260. ret = do_one_async_hash_op(req, &tresult,
  261. crypto_ahash_final(req));
  262. if (ret) {
  263. pr_err("alt: hash: final failed on test %d "
  264. "for %s: ret=%d\n", j, algo, -ret);
  265. goto out;
  266. }
  267. }
  268. if (memcmp(result, template[i].digest,
  269. crypto_ahash_digestsize(tfm))) {
  270. printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
  271. j, algo);
  272. hexdump(result, crypto_ahash_digestsize(tfm));
  273. ret = -EINVAL;
  274. goto out;
  275. }
  276. }
  277. j = 0;
  278. for (i = 0; i < tcount; i++) {
  279. if (template[i].np) {
  280. j++;
  281. memset(result, 0, 64);
  282. temp = 0;
  283. sg_init_table(sg, template[i].np);
  284. ret = -EINVAL;
  285. for (k = 0; k < template[i].np; k++) {
  286. if (WARN_ON(offset_in_page(IDX[k]) +
  287. template[i].tap[k] > PAGE_SIZE))
  288. goto out;
  289. sg_set_buf(&sg[k],
  290. memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
  291. offset_in_page(IDX[k]),
  292. template[i].plaintext + temp,
  293. template[i].tap[k]),
  294. template[i].tap[k]);
  295. temp += template[i].tap[k];
  296. }
  297. if (template[i].ksize) {
  298. crypto_ahash_clear_flags(tfm, ~0);
  299. ret = crypto_ahash_setkey(tfm, template[i].key,
  300. template[i].ksize);
  301. if (ret) {
  302. printk(KERN_ERR "alg: hash: setkey "
  303. "failed on chunking test %d "
  304. "for %s: ret=%d\n", j, algo,
  305. -ret);
  306. goto out;
  307. }
  308. }
  309. ahash_request_set_crypt(req, sg, result,
  310. template[i].psize);
  311. ret = crypto_ahash_digest(req);
  312. switch (ret) {
  313. case 0:
  314. break;
  315. case -EINPROGRESS:
  316. case -EBUSY:
  317. ret = wait_for_completion_interruptible(
  318. &tresult.completion);
  319. if (!ret && !(ret = tresult.err)) {
  320. INIT_COMPLETION(tresult.completion);
  321. break;
  322. }
  323. /* fall through */
  324. default:
  325. printk(KERN_ERR "alg: hash: digest failed "
  326. "on chunking test %d for %s: "
  327. "ret=%d\n", j, algo, -ret);
  328. goto out;
  329. }
  330. if (memcmp(result, template[i].digest,
  331. crypto_ahash_digestsize(tfm))) {
  332. printk(KERN_ERR "alg: hash: Chunking test %d "
  333. "failed for %s\n", j, algo);
  334. hexdump(result, crypto_ahash_digestsize(tfm));
  335. ret = -EINVAL;
  336. goto out;
  337. }
  338. }
  339. }
  340. ret = 0;
  341. out:
  342. ahash_request_free(req);
  343. out_noreq:
  344. testmgr_free_buf(xbuf);
  345. out_nobuf:
  346. return ret;
  347. }
  348. static int test_aead(struct crypto_aead *tfm, int enc,
  349. struct aead_testvec *template, unsigned int tcount)
  350. {
  351. const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
  352. unsigned int i, j, k, n, temp;
  353. int ret = -ENOMEM;
  354. char *q;
  355. char *key;
  356. struct aead_request *req;
  357. struct scatterlist sg[8];
  358. struct scatterlist asg[8];
  359. const char *e;
  360. struct tcrypt_result result;
  361. unsigned int authsize;
  362. void *input;
  363. void *assoc;
  364. char iv[MAX_IVLEN];
  365. char *xbuf[XBUFSIZE];
  366. char *axbuf[XBUFSIZE];
  367. if (testmgr_alloc_buf(xbuf))
  368. goto out_noxbuf;
  369. if (testmgr_alloc_buf(axbuf))
  370. goto out_noaxbuf;
  371. if (enc == ENCRYPT)
  372. e = "encryption";
  373. else
  374. e = "decryption";
  375. init_completion(&result.completion);
  376. req = aead_request_alloc(tfm, GFP_KERNEL);
  377. if (!req) {
  378. printk(KERN_ERR "alg: aead: Failed to allocate request for "
  379. "%s\n", algo);
  380. goto out;
  381. }
  382. aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  383. tcrypt_complete, &result);
  384. for (i = 0, j = 0; i < tcount; i++) {
  385. if (!template[i].np) {
  386. j++;
  387. /* some tepmplates have no input data but they will
  388. * touch input
  389. */
  390. input = xbuf[0];
  391. assoc = axbuf[0];
  392. ret = -EINVAL;
  393. if (WARN_ON(template[i].ilen > PAGE_SIZE ||
  394. template[i].alen > PAGE_SIZE))
  395. goto out;
  396. memcpy(input, template[i].input, template[i].ilen);
  397. memcpy(assoc, template[i].assoc, template[i].alen);
  398. if (template[i].iv)
  399. memcpy(iv, template[i].iv, MAX_IVLEN);
  400. else
  401. memset(iv, 0, MAX_IVLEN);
  402. crypto_aead_clear_flags(tfm, ~0);
  403. if (template[i].wk)
  404. crypto_aead_set_flags(
  405. tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  406. key = template[i].key;
  407. ret = crypto_aead_setkey(tfm, key,
  408. template[i].klen);
  409. if (!ret == template[i].fail) {
  410. printk(KERN_ERR "alg: aead: setkey failed on "
  411. "test %d for %s: flags=%x\n", j, algo,
  412. crypto_aead_get_flags(tfm));
  413. goto out;
  414. } else if (ret)
  415. continue;
  416. authsize = abs(template[i].rlen - template[i].ilen);
  417. ret = crypto_aead_setauthsize(tfm, authsize);
  418. if (ret) {
  419. printk(KERN_ERR "alg: aead: Failed to set "
  420. "authsize to %u on test %d for %s\n",
  421. authsize, j, algo);
  422. goto out;
  423. }
  424. sg_init_one(&sg[0], input,
  425. template[i].ilen + (enc ? authsize : 0));
  426. sg_init_one(&asg[0], assoc, template[i].alen);
  427. aead_request_set_crypt(req, sg, sg,
  428. template[i].ilen, iv);
  429. aead_request_set_assoc(req, asg, template[i].alen);
  430. ret = enc ?
  431. crypto_aead_encrypt(req) :
  432. crypto_aead_decrypt(req);
  433. switch (ret) {
  434. case 0:
  435. if (template[i].novrfy) {
  436. /* verification was supposed to fail */
  437. printk(KERN_ERR "alg: aead: %s failed "
  438. "on test %d for %s: ret was 0, "
  439. "expected -EBADMSG\n",
  440. e, j, algo);
  441. /* so really, we got a bad message */
  442. ret = -EBADMSG;
  443. goto out;
  444. }
  445. break;
  446. case -EINPROGRESS:
  447. case -EBUSY:
  448. ret = wait_for_completion_interruptible(
  449. &result.completion);
  450. if (!ret && !(ret = result.err)) {
  451. INIT_COMPLETION(result.completion);
  452. break;
  453. }
  454. case -EBADMSG:
  455. if (template[i].novrfy)
  456. /* verification failure was expected */
  457. continue;
  458. /* fall through */
  459. default:
  460. printk(KERN_ERR "alg: aead: %s failed on test "
  461. "%d for %s: ret=%d\n", e, j, algo, -ret);
  462. goto out;
  463. }
  464. q = input;
  465. if (memcmp(q, template[i].result, template[i].rlen)) {
  466. printk(KERN_ERR "alg: aead: Test %d failed on "
  467. "%s for %s\n", j, e, algo);
  468. hexdump(q, template[i].rlen);
  469. ret = -EINVAL;
  470. goto out;
  471. }
  472. }
  473. }
  474. for (i = 0, j = 0; i < tcount; i++) {
  475. if (template[i].np) {
  476. j++;
  477. if (template[i].iv)
  478. memcpy(iv, template[i].iv, MAX_IVLEN);
  479. else
  480. memset(iv, 0, MAX_IVLEN);
  481. crypto_aead_clear_flags(tfm, ~0);
  482. if (template[i].wk)
  483. crypto_aead_set_flags(
  484. tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  485. key = template[i].key;
  486. ret = crypto_aead_setkey(tfm, key, template[i].klen);
  487. if (!ret == template[i].fail) {
  488. printk(KERN_ERR "alg: aead: setkey failed on "
  489. "chunk test %d for %s: flags=%x\n", j,
  490. algo, crypto_aead_get_flags(tfm));
  491. goto out;
  492. } else if (ret)
  493. continue;
  494. authsize = abs(template[i].rlen - template[i].ilen);
  495. ret = -EINVAL;
  496. sg_init_table(sg, template[i].np);
  497. for (k = 0, temp = 0; k < template[i].np; k++) {
  498. if (WARN_ON(offset_in_page(IDX[k]) +
  499. template[i].tap[k] > PAGE_SIZE))
  500. goto out;
  501. q = xbuf[IDX[k] >> PAGE_SHIFT] +
  502. offset_in_page(IDX[k]);
  503. memcpy(q, template[i].input + temp,
  504. template[i].tap[k]);
  505. n = template[i].tap[k];
  506. if (k == template[i].np - 1 && enc)
  507. n += authsize;
  508. if (offset_in_page(q) + n < PAGE_SIZE)
  509. q[n] = 0;
  510. sg_set_buf(&sg[k], q, template[i].tap[k]);
  511. temp += template[i].tap[k];
  512. }
  513. ret = crypto_aead_setauthsize(tfm, authsize);
  514. if (ret) {
  515. printk(KERN_ERR "alg: aead: Failed to set "
  516. "authsize to %u on chunk test %d for "
  517. "%s\n", authsize, j, algo);
  518. goto out;
  519. }
  520. if (enc) {
  521. if (WARN_ON(sg[k - 1].offset +
  522. sg[k - 1].length + authsize >
  523. PAGE_SIZE)) {
  524. ret = -EINVAL;
  525. goto out;
  526. }
  527. sg[k - 1].length += authsize;
  528. }
  529. sg_init_table(asg, template[i].anp);
  530. ret = -EINVAL;
  531. for (k = 0, temp = 0; k < template[i].anp; k++) {
  532. if (WARN_ON(offset_in_page(IDX[k]) +
  533. template[i].atap[k] > PAGE_SIZE))
  534. goto out;
  535. sg_set_buf(&asg[k],
  536. memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
  537. offset_in_page(IDX[k]),
  538. template[i].assoc + temp,
  539. template[i].atap[k]),
  540. template[i].atap[k]);
  541. temp += template[i].atap[k];
  542. }
  543. aead_request_set_crypt(req, sg, sg,
  544. template[i].ilen,
  545. iv);
  546. aead_request_set_assoc(req, asg, template[i].alen);
  547. ret = enc ?
  548. crypto_aead_encrypt(req) :
  549. crypto_aead_decrypt(req);
  550. switch (ret) {
  551. case 0:
  552. if (template[i].novrfy) {
  553. /* verification was supposed to fail */
  554. printk(KERN_ERR "alg: aead: %s failed "
  555. "on chunk test %d for %s: ret "
  556. "was 0, expected -EBADMSG\n",
  557. e, j, algo);
  558. /* so really, we got a bad message */
  559. ret = -EBADMSG;
  560. goto out;
  561. }
  562. break;
  563. case -EINPROGRESS:
  564. case -EBUSY:
  565. ret = wait_for_completion_interruptible(
  566. &result.completion);
  567. if (!ret && !(ret = result.err)) {
  568. INIT_COMPLETION(result.completion);
  569. break;
  570. }
  571. case -EBADMSG:
  572. if (template[i].novrfy)
  573. /* verification failure was expected */
  574. continue;
  575. /* fall through */
  576. default:
  577. printk(KERN_ERR "alg: aead: %s failed on "
  578. "chunk test %d for %s: ret=%d\n", e, j,
  579. algo, -ret);
  580. goto out;
  581. }
  582. ret = -EINVAL;
  583. for (k = 0, temp = 0; k < template[i].np; k++) {
  584. q = xbuf[IDX[k] >> PAGE_SHIFT] +
  585. offset_in_page(IDX[k]);
  586. n = template[i].tap[k];
  587. if (k == template[i].np - 1)
  588. n += enc ? authsize : -authsize;
  589. if (memcmp(q, template[i].result + temp, n)) {
  590. printk(KERN_ERR "alg: aead: Chunk "
  591. "test %d failed on %s at page "
  592. "%u for %s\n", j, e, k, algo);
  593. hexdump(q, n);
  594. goto out;
  595. }
  596. q += n;
  597. if (k == template[i].np - 1 && !enc) {
  598. if (memcmp(q, template[i].input +
  599. temp + n, authsize))
  600. n = authsize;
  601. else
  602. n = 0;
  603. } else {
  604. for (n = 0; offset_in_page(q + n) &&
  605. q[n]; n++)
  606. ;
  607. }
  608. if (n) {
  609. printk(KERN_ERR "alg: aead: Result "
  610. "buffer corruption in chunk "
  611. "test %d on %s at page %u for "
  612. "%s: %u bytes:\n", j, e, k,
  613. algo, n);
  614. hexdump(q, n);
  615. goto out;
  616. }
  617. temp += template[i].tap[k];
  618. }
  619. }
  620. }
  621. ret = 0;
  622. out:
  623. aead_request_free(req);
  624. testmgr_free_buf(axbuf);
  625. out_noaxbuf:
  626. testmgr_free_buf(xbuf);
  627. out_noxbuf:
  628. return ret;
  629. }
  630. static int test_cipher(struct crypto_cipher *tfm, int enc,
  631. struct cipher_testvec *template, unsigned int tcount)
  632. {
  633. const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
  634. unsigned int i, j, k;
  635. char *q;
  636. const char *e;
  637. void *data;
  638. char *xbuf[XBUFSIZE];
  639. int ret = -ENOMEM;
  640. if (testmgr_alloc_buf(xbuf))
  641. goto out_nobuf;
  642. if (enc == ENCRYPT)
  643. e = "encryption";
  644. else
  645. e = "decryption";
  646. j = 0;
  647. for (i = 0; i < tcount; i++) {
  648. if (template[i].np)
  649. continue;
  650. j++;
  651. ret = -EINVAL;
  652. if (WARN_ON(template[i].ilen > PAGE_SIZE))
  653. goto out;
  654. data = xbuf[0];
  655. memcpy(data, template[i].input, template[i].ilen);
  656. crypto_cipher_clear_flags(tfm, ~0);
  657. if (template[i].wk)
  658. crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  659. ret = crypto_cipher_setkey(tfm, template[i].key,
  660. template[i].klen);
  661. if (!ret == template[i].fail) {
  662. printk(KERN_ERR "alg: cipher: setkey failed "
  663. "on test %d for %s: flags=%x\n", j,
  664. algo, crypto_cipher_get_flags(tfm));
  665. goto out;
  666. } else if (ret)
  667. continue;
  668. for (k = 0; k < template[i].ilen;
  669. k += crypto_cipher_blocksize(tfm)) {
  670. if (enc)
  671. crypto_cipher_encrypt_one(tfm, data + k,
  672. data + k);
  673. else
  674. crypto_cipher_decrypt_one(tfm, data + k,
  675. data + k);
  676. }
  677. q = data;
  678. if (memcmp(q, template[i].result, template[i].rlen)) {
  679. printk(KERN_ERR "alg: cipher: Test %d failed "
  680. "on %s for %s\n", j, e, algo);
  681. hexdump(q, template[i].rlen);
  682. ret = -EINVAL;
  683. goto out;
  684. }
  685. }
  686. ret = 0;
  687. out:
  688. testmgr_free_buf(xbuf);
  689. out_nobuf:
  690. return ret;
  691. }
  692. static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
  693. struct cipher_testvec *template, unsigned int tcount)
  694. {
  695. const char *algo =
  696. crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
  697. unsigned int i, j, k, n, temp;
  698. char *q;
  699. struct ablkcipher_request *req;
  700. struct scatterlist sg[8];
  701. const char *e;
  702. struct tcrypt_result result;
  703. void *data;
  704. char iv[MAX_IVLEN];
  705. char *xbuf[XBUFSIZE];
  706. int ret = -ENOMEM;
  707. if (testmgr_alloc_buf(xbuf))
  708. goto out_nobuf;
  709. if (enc == ENCRYPT)
  710. e = "encryption";
  711. else
  712. e = "decryption";
  713. init_completion(&result.completion);
  714. req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
  715. if (!req) {
  716. printk(KERN_ERR "alg: skcipher: Failed to allocate request "
  717. "for %s\n", algo);
  718. goto out;
  719. }
  720. ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  721. tcrypt_complete, &result);
  722. j = 0;
  723. for (i = 0; i < tcount; i++) {
  724. if (template[i].iv)
  725. memcpy(iv, template[i].iv, MAX_IVLEN);
  726. else
  727. memset(iv, 0, MAX_IVLEN);
  728. if (!(template[i].np)) {
  729. j++;
  730. ret = -EINVAL;
  731. if (WARN_ON(template[i].ilen > PAGE_SIZE))
  732. goto out;
  733. data = xbuf[0];
  734. memcpy(data, template[i].input, template[i].ilen);
  735. crypto_ablkcipher_clear_flags(tfm, ~0);
  736. if (template[i].wk)
  737. crypto_ablkcipher_set_flags(
  738. tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  739. ret = crypto_ablkcipher_setkey(tfm, template[i].key,
  740. template[i].klen);
  741. if (!ret == template[i].fail) {
  742. printk(KERN_ERR "alg: skcipher: setkey failed "
  743. "on test %d for %s: flags=%x\n", j,
  744. algo, crypto_ablkcipher_get_flags(tfm));
  745. goto out;
  746. } else if (ret)
  747. continue;
  748. sg_init_one(&sg[0], data, template[i].ilen);
  749. ablkcipher_request_set_crypt(req, sg, sg,
  750. template[i].ilen, iv);
  751. ret = enc ?
  752. crypto_ablkcipher_encrypt(req) :
  753. crypto_ablkcipher_decrypt(req);
  754. switch (ret) {
  755. case 0:
  756. break;
  757. case -EINPROGRESS:
  758. case -EBUSY:
  759. ret = wait_for_completion_interruptible(
  760. &result.completion);
  761. if (!ret && !((ret = result.err))) {
  762. INIT_COMPLETION(result.completion);
  763. break;
  764. }
  765. /* fall through */
  766. default:
  767. printk(KERN_ERR "alg: skcipher: %s failed on "
  768. "test %d for %s: ret=%d\n", e, j, algo,
  769. -ret);
  770. goto out;
  771. }
  772. q = data;
  773. if (memcmp(q, template[i].result, template[i].rlen)) {
  774. printk(KERN_ERR "alg: skcipher: Test %d "
  775. "failed on %s for %s\n", j, e, algo);
  776. hexdump(q, template[i].rlen);
  777. ret = -EINVAL;
  778. goto out;
  779. }
  780. }
  781. }
  782. j = 0;
  783. for (i = 0; i < tcount; i++) {
  784. if (template[i].iv)
  785. memcpy(iv, template[i].iv, MAX_IVLEN);
  786. else
  787. memset(iv, 0, MAX_IVLEN);
  788. if (template[i].np) {
  789. j++;
  790. crypto_ablkcipher_clear_flags(tfm, ~0);
  791. if (template[i].wk)
  792. crypto_ablkcipher_set_flags(
  793. tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  794. ret = crypto_ablkcipher_setkey(tfm, template[i].key,
  795. template[i].klen);
  796. if (!ret == template[i].fail) {
  797. printk(KERN_ERR "alg: skcipher: setkey failed "
  798. "on chunk test %d for %s: flags=%x\n",
  799. j, algo,
  800. crypto_ablkcipher_get_flags(tfm));
  801. goto out;
  802. } else if (ret)
  803. continue;
  804. temp = 0;
  805. ret = -EINVAL;
  806. sg_init_table(sg, template[i].np);
  807. for (k = 0; k < template[i].np; k++) {
  808. if (WARN_ON(offset_in_page(IDX[k]) +
  809. template[i].tap[k] > PAGE_SIZE))
  810. goto out;
  811. q = xbuf[IDX[k] >> PAGE_SHIFT] +
  812. offset_in_page(IDX[k]);
  813. memcpy(q, template[i].input + temp,
  814. template[i].tap[k]);
  815. if (offset_in_page(q) + template[i].tap[k] <
  816. PAGE_SIZE)
  817. q[template[i].tap[k]] = 0;
  818. sg_set_buf(&sg[k], q, template[i].tap[k]);
  819. temp += template[i].tap[k];
  820. }
  821. ablkcipher_request_set_crypt(req, sg, sg,
  822. template[i].ilen, iv);
  823. ret = enc ?
  824. crypto_ablkcipher_encrypt(req) :
  825. crypto_ablkcipher_decrypt(req);
  826. switch (ret) {
  827. case 0:
  828. break;
  829. case -EINPROGRESS:
  830. case -EBUSY:
  831. ret = wait_for_completion_interruptible(
  832. &result.completion);
  833. if (!ret && !((ret = result.err))) {
  834. INIT_COMPLETION(result.completion);
  835. break;
  836. }
  837. /* fall through */
  838. default:
  839. printk(KERN_ERR "alg: skcipher: %s failed on "
  840. "chunk test %d for %s: ret=%d\n", e, j,
  841. algo, -ret);
  842. goto out;
  843. }
  844. temp = 0;
  845. ret = -EINVAL;
  846. for (k = 0; k < template[i].np; k++) {
  847. q = xbuf[IDX[k] >> PAGE_SHIFT] +
  848. offset_in_page(IDX[k]);
  849. if (memcmp(q, template[i].result + temp,
  850. template[i].tap[k])) {
  851. printk(KERN_ERR "alg: skcipher: Chunk "
  852. "test %d failed on %s at page "
  853. "%u for %s\n", j, e, k, algo);
  854. hexdump(q, template[i].tap[k]);
  855. goto out;
  856. }
  857. q += template[i].tap[k];
  858. for (n = 0; offset_in_page(q + n) && q[n]; n++)
  859. ;
  860. if (n) {
  861. printk(KERN_ERR "alg: skcipher: "
  862. "Result buffer corruption in "
  863. "chunk test %d on %s at page "
  864. "%u for %s: %u bytes:\n", j, e,
  865. k, algo, n);
  866. hexdump(q, n);
  867. goto out;
  868. }
  869. temp += template[i].tap[k];
  870. }
  871. }
  872. }
  873. ret = 0;
  874. out:
  875. ablkcipher_request_free(req);
  876. testmgr_free_buf(xbuf);
  877. out_nobuf:
  878. return ret;
  879. }
  880. static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
  881. struct comp_testvec *dtemplate, int ctcount, int dtcount)
  882. {
  883. const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
  884. unsigned int i;
  885. char result[COMP_BUF_SIZE];
  886. int ret;
  887. for (i = 0; i < ctcount; i++) {
  888. int ilen;
  889. unsigned int dlen = COMP_BUF_SIZE;
  890. memset(result, 0, sizeof (result));
  891. ilen = ctemplate[i].inlen;
  892. ret = crypto_comp_compress(tfm, ctemplate[i].input,
  893. ilen, result, &dlen);
  894. if (ret) {
  895. printk(KERN_ERR "alg: comp: compression failed "
  896. "on test %d for %s: ret=%d\n", i + 1, algo,
  897. -ret);
  898. goto out;
  899. }
  900. if (dlen != ctemplate[i].outlen) {
  901. printk(KERN_ERR "alg: comp: Compression test %d "
  902. "failed for %s: output len = %d\n", i + 1, algo,
  903. dlen);
  904. ret = -EINVAL;
  905. goto out;
  906. }
  907. if (memcmp(result, ctemplate[i].output, dlen)) {
  908. printk(KERN_ERR "alg: comp: Compression test %d "
  909. "failed for %s\n", i + 1, algo);
  910. hexdump(result, dlen);
  911. ret = -EINVAL;
  912. goto out;
  913. }
  914. }
  915. for (i = 0; i < dtcount; i++) {
  916. int ilen;
  917. unsigned int dlen = COMP_BUF_SIZE;
  918. memset(result, 0, sizeof (result));
  919. ilen = dtemplate[i].inlen;
  920. ret = crypto_comp_decompress(tfm, dtemplate[i].input,
  921. ilen, result, &dlen);
  922. if (ret) {
  923. printk(KERN_ERR "alg: comp: decompression failed "
  924. "on test %d for %s: ret=%d\n", i + 1, algo,
  925. -ret);
  926. goto out;
  927. }
  928. if (dlen != dtemplate[i].outlen) {
  929. printk(KERN_ERR "alg: comp: Decompression test %d "
  930. "failed for %s: output len = %d\n", i + 1, algo,
  931. dlen);
  932. ret = -EINVAL;
  933. goto out;
  934. }
  935. if (memcmp(result, dtemplate[i].output, dlen)) {
  936. printk(KERN_ERR "alg: comp: Decompression test %d "
  937. "failed for %s\n", i + 1, algo);
  938. hexdump(result, dlen);
  939. ret = -EINVAL;
  940. goto out;
  941. }
  942. }
  943. ret = 0;
  944. out:
  945. return ret;
  946. }
  947. static int test_pcomp(struct crypto_pcomp *tfm,
  948. struct pcomp_testvec *ctemplate,
  949. struct pcomp_testvec *dtemplate, int ctcount,
  950. int dtcount)
  951. {
  952. const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
  953. unsigned int i;
  954. char result[COMP_BUF_SIZE];
  955. int res;
  956. for (i = 0; i < ctcount; i++) {
  957. struct comp_request req;
  958. unsigned int produced = 0;
  959. res = crypto_compress_setup(tfm, ctemplate[i].params,
  960. ctemplate[i].paramsize);
  961. if (res) {
  962. pr_err("alg: pcomp: compression setup failed on test "
  963. "%d for %s: error=%d\n", i + 1, algo, res);
  964. return res;
  965. }
  966. res = crypto_compress_init(tfm);
  967. if (res) {
  968. pr_err("alg: pcomp: compression init failed on test "
  969. "%d for %s: error=%d\n", i + 1, algo, res);
  970. return res;
  971. }
  972. memset(result, 0, sizeof(result));
  973. req.next_in = ctemplate[i].input;
  974. req.avail_in = ctemplate[i].inlen / 2;
  975. req.next_out = result;
  976. req.avail_out = ctemplate[i].outlen / 2;
  977. res = crypto_compress_update(tfm, &req);
  978. if (res < 0 && (res != -EAGAIN || req.avail_in)) {
  979. pr_err("alg: pcomp: compression update failed on test "
  980. "%d for %s: error=%d\n", i + 1, algo, res);
  981. return res;
  982. }
  983. if (res > 0)
  984. produced += res;
  985. /* Add remaining input data */
  986. req.avail_in += (ctemplate[i].inlen + 1) / 2;
  987. res = crypto_compress_update(tfm, &req);
  988. if (res < 0 && (res != -EAGAIN || req.avail_in)) {
  989. pr_err("alg: pcomp: compression update failed on test "
  990. "%d for %s: error=%d\n", i + 1, algo, res);
  991. return res;
  992. }
  993. if (res > 0)
  994. produced += res;
  995. /* Provide remaining output space */
  996. req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
  997. res = crypto_compress_final(tfm, &req);
  998. if (res < 0) {
  999. pr_err("alg: pcomp: compression final failed on test "
  1000. "%d for %s: error=%d\n", i + 1, algo, res);
  1001. return res;
  1002. }
  1003. produced += res;
  1004. if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
  1005. pr_err("alg: comp: Compression test %d failed for %s: "
  1006. "output len = %d (expected %d)\n", i + 1, algo,
  1007. COMP_BUF_SIZE - req.avail_out,
  1008. ctemplate[i].outlen);
  1009. return -EINVAL;
  1010. }
  1011. if (produced != ctemplate[i].outlen) {
  1012. pr_err("alg: comp: Compression test %d failed for %s: "
  1013. "returned len = %u (expected %d)\n", i + 1,
  1014. algo, produced, ctemplate[i].outlen);
  1015. return -EINVAL;
  1016. }
  1017. if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
  1018. pr_err("alg: pcomp: Compression test %d failed for "
  1019. "%s\n", i + 1, algo);
  1020. hexdump(result, ctemplate[i].outlen);
  1021. return -EINVAL;
  1022. }
  1023. }
  1024. for (i = 0; i < dtcount; i++) {
  1025. struct comp_request req;
  1026. unsigned int produced = 0;
  1027. res = crypto_decompress_setup(tfm, dtemplate[i].params,
  1028. dtemplate[i].paramsize);
  1029. if (res) {
  1030. pr_err("alg: pcomp: decompression setup failed on "
  1031. "test %d for %s: error=%d\n", i + 1, algo, res);
  1032. return res;
  1033. }
  1034. res = crypto_decompress_init(tfm);
  1035. if (res) {
  1036. pr_err("alg: pcomp: decompression init failed on test "
  1037. "%d for %s: error=%d\n", i + 1, algo, res);
  1038. return res;
  1039. }
  1040. memset(result, 0, sizeof(result));
  1041. req.next_in = dtemplate[i].input;
  1042. req.avail_in = dtemplate[i].inlen / 2;
  1043. req.next_out = result;
  1044. req.avail_out = dtemplate[i].outlen / 2;
  1045. res = crypto_decompress_update(tfm, &req);
  1046. if (res < 0 && (res != -EAGAIN || req.avail_in)) {
  1047. pr_err("alg: pcomp: decompression update failed on "
  1048. "test %d for %s: error=%d\n", i + 1, algo, res);
  1049. return res;
  1050. }
  1051. if (res > 0)
  1052. produced += res;
  1053. /* Add remaining input data */
  1054. req.avail_in += (dtemplate[i].inlen + 1) / 2;
  1055. res = crypto_decompress_update(tfm, &req);
  1056. if (res < 0 && (res != -EAGAIN || req.avail_in)) {
  1057. pr_err("alg: pcomp: decompression update failed on "
  1058. "test %d for %s: error=%d\n", i + 1, algo, res);
  1059. return res;
  1060. }
  1061. if (res > 0)
  1062. produced += res;
  1063. /* Provide remaining output space */
  1064. req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
  1065. res = crypto_decompress_final(tfm, &req);
  1066. if (res < 0 && (res != -EAGAIN || req.avail_in)) {
  1067. pr_err("alg: pcomp: decompression final failed on "
  1068. "test %d for %s: error=%d\n", i + 1, algo, res);
  1069. return res;
  1070. }
  1071. if (res > 0)
  1072. produced += res;
  1073. if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
  1074. pr_err("alg: comp: Decompression test %d failed for "
  1075. "%s: output len = %d (expected %d)\n", i + 1,
  1076. algo, COMP_BUF_SIZE - req.avail_out,
  1077. dtemplate[i].outlen);
  1078. return -EINVAL;
  1079. }
  1080. if (produced != dtemplate[i].outlen) {
  1081. pr_err("alg: comp: Decompression test %d failed for "
  1082. "%s: returned len = %u (expected %d)\n", i + 1,
  1083. algo, produced, dtemplate[i].outlen);
  1084. return -EINVAL;
  1085. }
  1086. if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
  1087. pr_err("alg: pcomp: Decompression test %d failed for "
  1088. "%s\n", i + 1, algo);
  1089. hexdump(result, dtemplate[i].outlen);
  1090. return -EINVAL;
  1091. }
  1092. }
  1093. return 0;
  1094. }
  1095. static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
  1096. unsigned int tcount)
  1097. {
  1098. const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
  1099. int err = 0, i, j, seedsize;
  1100. u8 *seed;
  1101. char result[32];
  1102. seedsize = crypto_rng_seedsize(tfm);
  1103. seed = kmalloc(seedsize, GFP_KERNEL);
  1104. if (!seed) {
  1105. printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
  1106. "for %s\n", algo);
  1107. return -ENOMEM;
  1108. }
  1109. for (i = 0; i < tcount; i++) {
  1110. memset(result, 0, 32);
  1111. memcpy(seed, template[i].v, template[i].vlen);
  1112. memcpy(seed + template[i].vlen, template[i].key,
  1113. template[i].klen);
  1114. memcpy(seed + template[i].vlen + template[i].klen,
  1115. template[i].dt, template[i].dtlen);
  1116. err = crypto_rng_reset(tfm, seed, seedsize);
  1117. if (err) {
  1118. printk(KERN_ERR "alg: cprng: Failed to reset rng "
  1119. "for %s\n", algo);
  1120. goto out;
  1121. }
  1122. for (j = 0; j < template[i].loops; j++) {
  1123. err = crypto_rng_get_bytes(tfm, result,
  1124. template[i].rlen);
  1125. if (err != template[i].rlen) {
  1126. printk(KERN_ERR "alg: cprng: Failed to obtain "
  1127. "the correct amount of random data for "
  1128. "%s (requested %d, got %d)\n", algo,
  1129. template[i].rlen, err);
  1130. goto out;
  1131. }
  1132. }
  1133. err = memcmp(result, template[i].result,
  1134. template[i].rlen);
  1135. if (err) {
  1136. printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
  1137. i, algo);
  1138. hexdump(result, template[i].rlen);
  1139. err = -EINVAL;
  1140. goto out;
  1141. }
  1142. }
  1143. out:
  1144. kfree(seed);
  1145. return err;
  1146. }
  1147. static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
  1148. u32 type, u32 mask)
  1149. {
  1150. struct crypto_aead *tfm;
  1151. int err = 0;
  1152. tfm = crypto_alloc_aead(driver, type, mask);
  1153. if (IS_ERR(tfm)) {
  1154. printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
  1155. "%ld\n", driver, PTR_ERR(tfm));
  1156. return PTR_ERR(tfm);
  1157. }
  1158. if (desc->suite.aead.enc.vecs) {
  1159. err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
  1160. desc->suite.aead.enc.count);
  1161. if (err)
  1162. goto out;
  1163. }
  1164. if (!err && desc->suite.aead.dec.vecs)
  1165. err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
  1166. desc->suite.aead.dec.count);
  1167. out:
  1168. crypto_free_aead(tfm);
  1169. return err;
  1170. }
  1171. static int alg_test_cipher(const struct alg_test_desc *desc,
  1172. const char *driver, u32 type, u32 mask)
  1173. {
  1174. struct crypto_cipher *tfm;
  1175. int err = 0;
  1176. tfm = crypto_alloc_cipher(driver, type, mask);
  1177. if (IS_ERR(tfm)) {
  1178. printk(KERN_ERR "alg: cipher: Failed to load transform for "
  1179. "%s: %ld\n", driver, PTR_ERR(tfm));
  1180. return PTR_ERR(tfm);
  1181. }
  1182. if (desc->suite.cipher.enc.vecs) {
  1183. err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
  1184. desc->suite.cipher.enc.count);
  1185. if (err)
  1186. goto out;
  1187. }
  1188. if (desc->suite.cipher.dec.vecs)
  1189. err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
  1190. desc->suite.cipher.dec.count);
  1191. out:
  1192. crypto_free_cipher(tfm);
  1193. return err;
  1194. }
  1195. static int alg_test_skcipher(const struct alg_test_desc *desc,
  1196. const char *driver, u32 type, u32 mask)
  1197. {
  1198. struct crypto_ablkcipher *tfm;
  1199. int err = 0;
  1200. tfm = crypto_alloc_ablkcipher(driver, type, mask);
  1201. if (IS_ERR(tfm)) {
  1202. printk(KERN_ERR "alg: skcipher: Failed to load transform for "
  1203. "%s: %ld\n", driver, PTR_ERR(tfm));
  1204. return PTR_ERR(tfm);
  1205. }
  1206. if (desc->suite.cipher.enc.vecs) {
  1207. err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
  1208. desc->suite.cipher.enc.count);
  1209. if (err)
  1210. goto out;
  1211. }
  1212. if (desc->suite.cipher.dec.vecs)
  1213. err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
  1214. desc->suite.cipher.dec.count);
  1215. out:
  1216. crypto_free_ablkcipher(tfm);
  1217. return err;
  1218. }
  1219. static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
  1220. u32 type, u32 mask)
  1221. {
  1222. struct crypto_comp *tfm;
  1223. int err;
  1224. tfm = crypto_alloc_comp(driver, type, mask);
  1225. if (IS_ERR(tfm)) {
  1226. printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
  1227. "%ld\n", driver, PTR_ERR(tfm));
  1228. return PTR_ERR(tfm);
  1229. }
  1230. err = test_comp(tfm, desc->suite.comp.comp.vecs,
  1231. desc->suite.comp.decomp.vecs,
  1232. desc->suite.comp.comp.count,
  1233. desc->suite.comp.decomp.count);
  1234. crypto_free_comp(tfm);
  1235. return err;
  1236. }
  1237. static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
  1238. u32 type, u32 mask)
  1239. {
  1240. struct crypto_pcomp *tfm;
  1241. int err;
  1242. tfm = crypto_alloc_pcomp(driver, type, mask);
  1243. if (IS_ERR(tfm)) {
  1244. pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
  1245. driver, PTR_ERR(tfm));
  1246. return PTR_ERR(tfm);
  1247. }
  1248. err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
  1249. desc->suite.pcomp.decomp.vecs,
  1250. desc->suite.pcomp.comp.count,
  1251. desc->suite.pcomp.decomp.count);
  1252. crypto_free_pcomp(tfm);
  1253. return err;
  1254. }
  1255. static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
  1256. u32 type, u32 mask)
  1257. {
  1258. struct crypto_ahash *tfm;
  1259. int err;
  1260. tfm = crypto_alloc_ahash(driver, type, mask);
  1261. if (IS_ERR(tfm)) {
  1262. printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
  1263. "%ld\n", driver, PTR_ERR(tfm));
  1264. return PTR_ERR(tfm);
  1265. }
  1266. err = test_hash(tfm, desc->suite.hash.vecs,
  1267. desc->suite.hash.count, true);
  1268. if (!err)
  1269. err = test_hash(tfm, desc->suite.hash.vecs,
  1270. desc->suite.hash.count, false);
  1271. crypto_free_ahash(tfm);
  1272. return err;
  1273. }
  1274. static int alg_test_crc32c(const struct alg_test_desc *desc,
  1275. const char *driver, u32 type, u32 mask)
  1276. {
  1277. struct crypto_shash *tfm;
  1278. u32 val;
  1279. int err;
  1280. err = alg_test_hash(desc, driver, type, mask);
  1281. if (err)
  1282. return err;
  1283. tfm = crypto_alloc_shash(driver, type, mask);
  1284. if (IS_ERR(tfm)) {
  1285. if (PTR_ERR(tfm) == -ENOENT) {
  1286. /*
  1287. * This crc32c implementation is only available through
  1288. * ahash API, not the shash API, so the remaining part
  1289. * of the test is not applicable to it.
  1290. */
  1291. return 0;
  1292. }
  1293. printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
  1294. "%ld\n", driver, PTR_ERR(tfm));
  1295. return PTR_ERR(tfm);
  1296. }
  1297. do {
  1298. struct {
  1299. struct shash_desc shash;
  1300. char ctx[crypto_shash_descsize(tfm)];
  1301. } sdesc;
  1302. sdesc.shash.tfm = tfm;
  1303. sdesc.shash.flags = 0;
  1304. *(u32 *)sdesc.ctx = le32_to_cpu(420553207);
  1305. err = crypto_shash_final(&sdesc.shash, (u8 *)&val);
  1306. if (err) {
  1307. printk(KERN_ERR "alg: crc32c: Operation failed for "
  1308. "%s: %d\n", driver, err);
  1309. break;
  1310. }
  1311. if (val != ~420553207) {
  1312. printk(KERN_ERR "alg: crc32c: Test failed for %s: "
  1313. "%d\n", driver, val);
  1314. err = -EINVAL;
  1315. }
  1316. } while (0);
  1317. crypto_free_shash(tfm);
  1318. return err;
  1319. }
  1320. static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
  1321. u32 type, u32 mask)
  1322. {
  1323. struct crypto_rng *rng;
  1324. int err;
  1325. rng = crypto_alloc_rng(driver, type, mask);
  1326. if (IS_ERR(rng)) {
  1327. printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
  1328. "%ld\n", driver, PTR_ERR(rng));
  1329. return PTR_ERR(rng);
  1330. }
  1331. err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
  1332. crypto_free_rng(rng);
  1333. return err;
  1334. }
  1335. #ifdef CONFIG_CRYPTO_DRBG
  1336. static int drbg_cavs_test(struct drbg_testvec *test, int pr,
  1337. const char *driver, u32 type, u32 mask)
  1338. {
  1339. int ret = -EAGAIN;
  1340. struct crypto_rng *drng;
  1341. struct drbg_test_data test_data;
  1342. struct drbg_string addtl, pers, testentropy;
  1343. unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
  1344. if (!buf)
  1345. return -ENOMEM;
  1346. drng = crypto_alloc_rng(driver, type, mask);
  1347. if (IS_ERR(drng)) {
  1348. printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
  1349. "%s\n", driver);
  1350. kzfree(buf);
  1351. return -ENOMEM;
  1352. }
  1353. test_data.testentropy = &testentropy;
  1354. drbg_string_fill(&testentropy, test->entropy, test->entropylen);
  1355. drbg_string_fill(&pers, test->pers, test->perslen);
  1356. ret = crypto_drbg_reset_test(drng, &pers, &test_data);
  1357. if (ret) {
  1358. printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
  1359. goto outbuf;
  1360. }
  1361. drbg_string_fill(&addtl, test->addtla, test->addtllen);
  1362. if (pr) {
  1363. drbg_string_fill(&testentropy, test->entpra, test->entprlen);
  1364. ret = crypto_drbg_get_bytes_addtl_test(drng,
  1365. buf, test->expectedlen, &addtl, &test_data);
  1366. } else {
  1367. ret = crypto_drbg_get_bytes_addtl(drng,
  1368. buf, test->expectedlen, &addtl);
  1369. }
  1370. if (ret <= 0) {
  1371. printk(KERN_ERR "alg: drbg: could not obtain random data for "
  1372. "driver %s\n", driver);
  1373. goto outbuf;
  1374. }
  1375. drbg_string_fill(&addtl, test->addtlb, test->addtllen);
  1376. if (pr) {
  1377. drbg_string_fill(&testentropy, test->entprb, test->entprlen);
  1378. ret = crypto_drbg_get_bytes_addtl_test(drng,
  1379. buf, test->expectedlen, &addtl, &test_data);
  1380. } else {
  1381. ret = crypto_drbg_get_bytes_addtl(drng,
  1382. buf, test->expectedlen, &addtl);
  1383. }
  1384. if (ret <= 0) {
  1385. printk(KERN_ERR "alg: drbg: could not obtain random data for "
  1386. "driver %s\n", driver);
  1387. goto outbuf;
  1388. }
  1389. ret = memcmp(test->expected, buf, test->expectedlen);
  1390. outbuf:
  1391. crypto_free_rng(drng);
  1392. kzfree(buf);
  1393. return ret;
  1394. }
  1395. static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
  1396. u32 type, u32 mask)
  1397. {
  1398. int err = 0;
  1399. int pr = 0;
  1400. int i = 0;
  1401. struct drbg_testvec *template = desc->suite.drbg.vecs;
  1402. unsigned int tcount = desc->suite.drbg.count;
  1403. if (0 == memcmp(driver, "drbg_pr_", 8))
  1404. pr = 1;
  1405. for (i = 0; i < tcount; i++) {
  1406. err = drbg_cavs_test(&template[i], pr, driver, type, mask);
  1407. if (err) {
  1408. printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
  1409. i, driver);
  1410. err = -EINVAL;
  1411. break;
  1412. }
  1413. }
  1414. return err;
  1415. }
  1416. #endif
  1417. static int alg_test_null(const struct alg_test_desc *desc,
  1418. const char *driver, u32 type, u32 mask)
  1419. {
  1420. return 0;
  1421. }
  1422. /* Please keep this list sorted by algorithm name. */
  1423. static const struct alg_test_desc alg_test_descs[] = {
  1424. {
  1425. .alg = "__cbc-serpent-sse2",
  1426. .test = alg_test_null,
  1427. .suite = {
  1428. .cipher = {
  1429. .enc = {
  1430. .vecs = NULL,
  1431. .count = 0
  1432. },
  1433. .dec = {
  1434. .vecs = NULL,
  1435. .count = 0
  1436. }
  1437. }
  1438. }
  1439. }, {
  1440. .alg = "__driver-cbc-aes-aesni",
  1441. .test = alg_test_null,
  1442. .suite = {
  1443. .cipher = {
  1444. .enc = {
  1445. .vecs = NULL,
  1446. .count = 0
  1447. },
  1448. .dec = {
  1449. .vecs = NULL,
  1450. .count = 0
  1451. }
  1452. }
  1453. }
  1454. }, {
  1455. .alg = "__driver-cbc-serpent-sse2",
  1456. .test = alg_test_null,
  1457. .suite = {
  1458. .cipher = {
  1459. .enc = {
  1460. .vecs = NULL,
  1461. .count = 0
  1462. },
  1463. .dec = {
  1464. .vecs = NULL,
  1465. .count = 0
  1466. }
  1467. }
  1468. }
  1469. }, {
  1470. .alg = "__driver-ecb-aes-aesni",
  1471. .test = alg_test_null,
  1472. .suite = {
  1473. .cipher = {
  1474. .enc = {
  1475. .vecs = NULL,
  1476. .count = 0
  1477. },
  1478. .dec = {
  1479. .vecs = NULL,
  1480. .count = 0
  1481. }
  1482. }
  1483. }
  1484. }, {
  1485. .alg = "__driver-ecb-serpent-sse2",
  1486. .test = alg_test_null,
  1487. .suite = {
  1488. .cipher = {
  1489. .enc = {
  1490. .vecs = NULL,
  1491. .count = 0
  1492. },
  1493. .dec = {
  1494. .vecs = NULL,
  1495. .count = 0
  1496. }
  1497. }
  1498. }
  1499. }, {
  1500. .alg = "__ghash-pclmulqdqni",
  1501. .test = alg_test_null,
  1502. .suite = {
  1503. .hash = {
  1504. .vecs = NULL,
  1505. .count = 0
  1506. }
  1507. }
  1508. }, {
  1509. .alg = "ansi_cprng",
  1510. .test = alg_test_cprng,
  1511. .fips_allowed = 1,
  1512. .suite = {
  1513. .cprng = {
  1514. .vecs = ansi_cprng_aes_tv_template,
  1515. .count = ANSI_CPRNG_AES_TEST_VECTORS
  1516. }
  1517. }
  1518. }, {
  1519. .alg = "cbc(aes)",
  1520. .test = alg_test_skcipher,
  1521. .fips_allowed = 1,
  1522. .suite = {
  1523. .cipher = {
  1524. .enc = {
  1525. .vecs = aes_cbc_enc_tv_template,
  1526. .count = AES_CBC_ENC_TEST_VECTORS
  1527. },
  1528. .dec = {
  1529. .vecs = aes_cbc_dec_tv_template,
  1530. .count = AES_CBC_DEC_TEST_VECTORS
  1531. }
  1532. }
  1533. }
  1534. }, {
  1535. .alg = "cbc(anubis)",
  1536. .test = alg_test_skcipher,
  1537. .suite = {
  1538. .cipher = {
  1539. .enc = {
  1540. .vecs = anubis_cbc_enc_tv_template,
  1541. .count = ANUBIS_CBC_ENC_TEST_VECTORS
  1542. },
  1543. .dec = {
  1544. .vecs = anubis_cbc_dec_tv_template,
  1545. .count = ANUBIS_CBC_DEC_TEST_VECTORS
  1546. }
  1547. }
  1548. }
  1549. }, {
  1550. .alg = "cbc(blowfish)",
  1551. .test = alg_test_skcipher,
  1552. .suite = {
  1553. .cipher = {
  1554. .enc = {
  1555. .vecs = bf_cbc_enc_tv_template,
  1556. .count = BF_CBC_ENC_TEST_VECTORS
  1557. },
  1558. .dec = {
  1559. .vecs = bf_cbc_dec_tv_template,
  1560. .count = BF_CBC_DEC_TEST_VECTORS
  1561. }
  1562. }
  1563. }
  1564. }, {
  1565. .alg = "cbc(camellia)",
  1566. .test = alg_test_skcipher,
  1567. .suite = {
  1568. .cipher = {
  1569. .enc = {
  1570. .vecs = camellia_cbc_enc_tv_template,
  1571. .count = CAMELLIA_CBC_ENC_TEST_VECTORS
  1572. },
  1573. .dec = {
  1574. .vecs = camellia_cbc_dec_tv_template,
  1575. .count = CAMELLIA_CBC_DEC_TEST_VECTORS
  1576. }
  1577. }
  1578. }
  1579. }, {
  1580. .alg = "cbc(des)",
  1581. .test = alg_test_skcipher,
  1582. .suite = {
  1583. .cipher = {
  1584. .enc = {
  1585. .vecs = des_cbc_enc_tv_template,
  1586. .count = DES_CBC_ENC_TEST_VECTORS
  1587. },
  1588. .dec = {
  1589. .vecs = des_cbc_dec_tv_template,
  1590. .count = DES_CBC_DEC_TEST_VECTORS
  1591. }
  1592. }
  1593. }
  1594. }, {
  1595. .alg = "cbc(des3_ede)",
  1596. .test = alg_test_skcipher,
  1597. .fips_allowed = 1,
  1598. .suite = {
  1599. .cipher = {
  1600. .enc = {
  1601. .vecs = des3_ede_cbc_enc_tv_template,
  1602. .count = DES3_EDE_CBC_ENC_TEST_VECTORS
  1603. },
  1604. .dec = {
  1605. .vecs = des3_ede_cbc_dec_tv_template,
  1606. .count = DES3_EDE_CBC_DEC_TEST_VECTORS
  1607. }
  1608. }
  1609. }
  1610. }, {
  1611. .alg = "cbc(serpent)",
  1612. .test = alg_test_skcipher,
  1613. .suite = {
  1614. .cipher = {
  1615. .enc = {
  1616. .vecs = serpent_cbc_enc_tv_template,
  1617. .count = SERPENT_CBC_ENC_TEST_VECTORS
  1618. },
  1619. .dec = {
  1620. .vecs = serpent_cbc_dec_tv_template,
  1621. .count = SERPENT_CBC_DEC_TEST_VECTORS
  1622. }
  1623. }
  1624. }
  1625. }, {
  1626. .alg = "cbc(twofish)",
  1627. .test = alg_test_skcipher,
  1628. .suite = {
  1629. .cipher = {
  1630. .enc = {
  1631. .vecs = tf_cbc_enc_tv_template,
  1632. .count = TF_CBC_ENC_TEST_VECTORS
  1633. },
  1634. .dec = {
  1635. .vecs = tf_cbc_dec_tv_template,
  1636. .count = TF_CBC_DEC_TEST_VECTORS
  1637. }
  1638. }
  1639. }
  1640. }, {
  1641. .alg = "ccm(aes)",
  1642. .test = alg_test_aead,
  1643. .fips_allowed = 1,
  1644. .suite = {
  1645. .aead = {
  1646. .enc = {
  1647. .vecs = aes_ccm_enc_tv_template,
  1648. .count = AES_CCM_ENC_TEST_VECTORS
  1649. },
  1650. .dec = {
  1651. .vecs = aes_ccm_dec_tv_template,
  1652. .count = AES_CCM_DEC_TEST_VECTORS
  1653. }
  1654. }
  1655. }
  1656. }, {
  1657. .alg = "crc32c",
  1658. .test = alg_test_crc32c,
  1659. .fips_allowed = 1,
  1660. .suite = {
  1661. .hash = {
  1662. .vecs = crc32c_tv_template,
  1663. .count = CRC32C_TEST_VECTORS
  1664. }
  1665. }
  1666. }, {
  1667. .alg = "cryptd(__driver-ecb-aes-aesni)",
  1668. .test = alg_test_null,
  1669. .suite = {
  1670. .cipher = {
  1671. .enc = {
  1672. .vecs = NULL,
  1673. .count = 0
  1674. },
  1675. .dec = {
  1676. .vecs = NULL,
  1677. .count = 0
  1678. }
  1679. }
  1680. }
  1681. }, {
  1682. .alg = "cryptd(__driver-ecb-serpent-sse2)",
  1683. .test = alg_test_null,
  1684. .suite = {
  1685. .cipher = {
  1686. .enc = {
  1687. .vecs = NULL,
  1688. .count = 0
  1689. },
  1690. .dec = {
  1691. .vecs = NULL,
  1692. .count = 0
  1693. }
  1694. }
  1695. }
  1696. }, {
  1697. .alg = "cryptd(__ghash-pclmulqdqni)",
  1698. .test = alg_test_null,
  1699. .suite = {
  1700. .hash = {
  1701. .vecs = NULL,
  1702. .count = 0
  1703. }
  1704. }
  1705. }, {
  1706. .alg = "ctr(aes)",
  1707. .test = alg_test_skcipher,
  1708. .fips_allowed = 1,
  1709. .suite = {
  1710. .cipher = {
  1711. .enc = {
  1712. .vecs = aes_ctr_enc_tv_template,
  1713. .count = AES_CTR_ENC_TEST_VECTORS
  1714. },
  1715. .dec = {
  1716. .vecs = aes_ctr_dec_tv_template,
  1717. .count = AES_CTR_DEC_TEST_VECTORS
  1718. }
  1719. }
  1720. }
  1721. }, {
  1722. .alg = "ctr(blowfish)",
  1723. .test = alg_test_skcipher,
  1724. .suite = {
  1725. .cipher = {
  1726. .enc = {
  1727. .vecs = bf_ctr_enc_tv_template,
  1728. .count = BF_CTR_ENC_TEST_VECTORS
  1729. },
  1730. .dec = {
  1731. .vecs = bf_ctr_dec_tv_template,
  1732. .count = BF_CTR_DEC_TEST_VECTORS
  1733. }
  1734. }
  1735. }
  1736. }, {
  1737. .alg = "ctr(camellia)",
  1738. .test = alg_test_skcipher,
  1739. .suite = {
  1740. .cipher = {
  1741. .enc = {
  1742. .vecs = camellia_ctr_enc_tv_template,
  1743. .count = CAMELLIA_CTR_ENC_TEST_VECTORS
  1744. },
  1745. .dec = {
  1746. .vecs = camellia_ctr_dec_tv_template,
  1747. .count = CAMELLIA_CTR_DEC_TEST_VECTORS
  1748. }
  1749. }
  1750. }
  1751. }, {
  1752. .alg = "ctr(serpent)",
  1753. .test = alg_test_skcipher,
  1754. .suite = {
  1755. .cipher = {
  1756. .enc = {
  1757. .vecs = serpent_ctr_enc_tv_template,
  1758. .count = SERPENT_CTR_ENC_TEST_VECTORS
  1759. },
  1760. .dec = {
  1761. .vecs = serpent_ctr_dec_tv_template,
  1762. .count = SERPENT_CTR_DEC_TEST_VECTORS
  1763. }
  1764. }
  1765. }
  1766. }, {
  1767. .alg = "ctr(twofish)",
  1768. .test = alg_test_skcipher,
  1769. .suite = {
  1770. .cipher = {
  1771. .enc = {
  1772. .vecs = tf_ctr_enc_tv_template,
  1773. .count = TF_CTR_ENC_TEST_VECTORS
  1774. },
  1775. .dec = {
  1776. .vecs = tf_ctr_dec_tv_template,
  1777. .count = TF_CTR_DEC_TEST_VECTORS
  1778. }
  1779. }
  1780. }
  1781. }, {
  1782. .alg = "cts(cbc(aes))",
  1783. .test = alg_test_skcipher,
  1784. .suite = {
  1785. .cipher = {
  1786. .enc = {
  1787. .vecs = cts_mode_enc_tv_template,
  1788. .count = CTS_MODE_ENC_TEST_VECTORS
  1789. },
  1790. .dec = {
  1791. .vecs = cts_mode_dec_tv_template,
  1792. .count = CTS_MODE_DEC_TEST_VECTORS
  1793. }
  1794. }
  1795. }
  1796. }, {
  1797. .alg = "deflate",
  1798. .test = alg_test_comp,
  1799. .suite = {
  1800. .comp = {
  1801. .comp = {
  1802. .vecs = deflate_comp_tv_template,
  1803. .count = DEFLATE_COMP_TEST_VECTORS
  1804. },
  1805. .decomp = {
  1806. .vecs = deflate_decomp_tv_template,
  1807. .count = DEFLATE_DECOMP_TEST_VECTORS
  1808. }
  1809. }
  1810. }
  1811. }, {
  1812. #ifdef CONFIG_CRYPTO_DRBG
  1813. .alg = "drbg_nopr_ctr_aes128",
  1814. .test = alg_test_drbg,
  1815. .fips_allowed = 1,
  1816. .suite = {
  1817. .drbg = {
  1818. .vecs = drbg_nopr_ctr_aes128_tv_template,
  1819. .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
  1820. }
  1821. }
  1822. }, {
  1823. .alg = "drbg_nopr_ctr_aes192",
  1824. .test = alg_test_drbg,
  1825. .fips_allowed = 1,
  1826. .suite = {
  1827. .drbg = {
  1828. .vecs = drbg_nopr_ctr_aes192_tv_template,
  1829. .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
  1830. }
  1831. }
  1832. }, {
  1833. .alg = "drbg_nopr_ctr_aes256",
  1834. .test = alg_test_drbg,
  1835. .fips_allowed = 1,
  1836. .suite = {
  1837. .drbg = {
  1838. .vecs = drbg_nopr_ctr_aes256_tv_template,
  1839. .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
  1840. }
  1841. }
  1842. }, {
  1843. /*
  1844. * There is no need to specifically test the DRBG with every
  1845. * backend cipher -- covered by drbg_nopr_hmac_sha256 test
  1846. */
  1847. .alg = "drbg_nopr_hmac_sha1",
  1848. .fips_allowed = 1,
  1849. .test = alg_test_null,
  1850. }, {
  1851. .alg = "drbg_nopr_hmac_sha256",
  1852. .test = alg_test_drbg,
  1853. .fips_allowed = 1,
  1854. .suite = {
  1855. .drbg = {
  1856. .vecs = drbg_nopr_hmac_sha256_tv_template,
  1857. .count =
  1858. ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
  1859. }
  1860. }
  1861. }, {
  1862. /* covered by drbg_nopr_hmac_sha256 test */
  1863. .alg = "drbg_nopr_hmac_sha384",
  1864. .fips_allowed = 1,
  1865. .test = alg_test_null,
  1866. }, {
  1867. .alg = "drbg_nopr_hmac_sha512",
  1868. .test = alg_test_null,
  1869. .fips_allowed = 1,
  1870. }, {
  1871. .alg = "drbg_nopr_sha1",
  1872. .fips_allowed = 1,
  1873. .test = alg_test_null,
  1874. }, {
  1875. .alg = "drbg_nopr_sha256",
  1876. .test = alg_test_drbg,
  1877. .fips_allowed = 1,
  1878. .suite = {
  1879. .drbg = {
  1880. .vecs = drbg_nopr_sha256_tv_template,
  1881. .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
  1882. }
  1883. }
  1884. }, {
  1885. /* covered by drbg_nopr_sha256 test */
  1886. .alg = "drbg_nopr_sha384",
  1887. .fips_allowed = 1,
  1888. .test = alg_test_null,
  1889. }, {
  1890. .alg = "drbg_nopr_sha512",
  1891. .fips_allowed = 1,
  1892. .test = alg_test_null,
  1893. }, {
  1894. .alg = "drbg_pr_ctr_aes128",
  1895. .test = alg_test_drbg,
  1896. .fips_allowed = 1,
  1897. .suite = {
  1898. .drbg = {
  1899. .vecs = drbg_pr_ctr_aes128_tv_template,
  1900. .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
  1901. }
  1902. }
  1903. }, {
  1904. /* covered by drbg_pr_ctr_aes128 test */
  1905. .alg = "drbg_pr_ctr_aes192",
  1906. .fips_allowed = 1,
  1907. .test = alg_test_null,
  1908. }, {
  1909. .alg = "drbg_pr_ctr_aes256",
  1910. .fips_allowed = 1,
  1911. .test = alg_test_null,
  1912. }, {
  1913. .alg = "drbg_pr_hmac_sha1",
  1914. .fips_allowed = 1,
  1915. .test = alg_test_null,
  1916. }, {
  1917. .alg = "drbg_pr_hmac_sha256",
  1918. .test = alg_test_drbg,
  1919. .fips_allowed = 1,
  1920. .suite = {
  1921. .drbg = {
  1922. .vecs = drbg_pr_hmac_sha256_tv_template,
  1923. .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
  1924. }
  1925. }
  1926. }, {
  1927. /* covered by drbg_pr_hmac_sha256 test */
  1928. .alg = "drbg_pr_hmac_sha384",
  1929. .fips_allowed = 1,
  1930. .test = alg_test_null,
  1931. }, {
  1932. .alg = "drbg_pr_hmac_sha512",
  1933. .test = alg_test_null,
  1934. .fips_allowed = 1,
  1935. }, {
  1936. .alg = "drbg_pr_sha1",
  1937. .fips_allowed = 1,
  1938. .test = alg_test_null,
  1939. }, {
  1940. .alg = "drbg_pr_sha256",
  1941. .test = alg_test_drbg,
  1942. .fips_allowed = 1,
  1943. .suite = {
  1944. .drbg = {
  1945. .vecs = drbg_pr_sha256_tv_template,
  1946. .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
  1947. }
  1948. }
  1949. }, {
  1950. /* covered by drbg_pr_sha256 test */
  1951. .alg = "drbg_pr_sha384",
  1952. .fips_allowed = 1,
  1953. .test = alg_test_null,
  1954. }, {
  1955. .alg = "drbg_pr_sha512",
  1956. .fips_allowed = 1,
  1957. .test = alg_test_null,
  1958. }, {
  1959. #endif /* CONFIG_CRYPTO_DRBG */
  1960. .alg = "ecb(__aes-aesni)",
  1961. .test = alg_test_null,
  1962. .suite = {
  1963. .cipher = {
  1964. .enc = {
  1965. .vecs = NULL,
  1966. .count = 0
  1967. },
  1968. .dec = {
  1969. .vecs = NULL,
  1970. .count = 0
  1971. }
  1972. }
  1973. }
  1974. }, {
  1975. .alg = "ecb(aes)",
  1976. .test = alg_test_skcipher,
  1977. .fips_allowed = 1,
  1978. .suite = {
  1979. .cipher = {
  1980. .enc = {
  1981. .vecs = aes_enc_tv_template,
  1982. .count = AES_ENC_TEST_VECTORS
  1983. },
  1984. .dec = {
  1985. .vecs = aes_dec_tv_template,
  1986. .count = AES_DEC_TEST_VECTORS
  1987. }
  1988. }
  1989. }
  1990. }, {
  1991. .alg = "ecb(anubis)",
  1992. .test = alg_test_skcipher,
  1993. .suite = {
  1994. .cipher = {
  1995. .enc = {
  1996. .vecs = anubis_enc_tv_template,
  1997. .count = ANUBIS_ENC_TEST_VECTORS
  1998. },
  1999. .dec = {
  2000. .vecs = anubis_dec_tv_template,
  2001. .count = ANUBIS_DEC_TEST_VECTORS
  2002. }
  2003. }
  2004. }
  2005. }, {
  2006. .alg = "ecb(arc4)",
  2007. .test = alg_test_skcipher,
  2008. .suite = {
  2009. .cipher = {
  2010. .enc = {
  2011. .vecs = arc4_enc_tv_template,
  2012. .count = ARC4_ENC_TEST_VECTORS
  2013. },
  2014. .dec = {
  2015. .vecs = arc4_dec_tv_template,
  2016. .count = ARC4_DEC_TEST_VECTORS
  2017. }
  2018. }
  2019. }
  2020. }, {
  2021. .alg = "ecb(blowfish)",
  2022. .test = alg_test_skcipher,
  2023. .suite = {
  2024. .cipher = {
  2025. .enc = {
  2026. .vecs = bf_enc_tv_template,
  2027. .count = BF_ENC_TEST_VECTORS
  2028. },
  2029. .dec = {
  2030. .vecs = bf_dec_tv_template,
  2031. .count = BF_DEC_TEST_VECTORS
  2032. }
  2033. }
  2034. }
  2035. }, {
  2036. .alg = "ecb(camellia)",
  2037. .test = alg_test_skcipher,
  2038. .suite = {
  2039. .cipher = {
  2040. .enc = {
  2041. .vecs = camellia_enc_tv_template,
  2042. .count = CAMELLIA_ENC_TEST_VECTORS
  2043. },
  2044. .dec = {
  2045. .vecs = camellia_dec_tv_template,
  2046. .count = CAMELLIA_DEC_TEST_VECTORS
  2047. }
  2048. }
  2049. }
  2050. }, {
  2051. .alg = "ecb(cast5)",
  2052. .test = alg_test_skcipher,
  2053. .suite = {
  2054. .cipher = {
  2055. .enc = {
  2056. .vecs = cast5_enc_tv_template,
  2057. .count = CAST5_ENC_TEST_VECTORS
  2058. },
  2059. .dec = {
  2060. .vecs = cast5_dec_tv_template,
  2061. .count = CAST5_DEC_TEST_VECTORS
  2062. }
  2063. }
  2064. }
  2065. }, {
  2066. .alg = "ecb(cast6)",
  2067. .test = alg_test_skcipher,
  2068. .suite = {
  2069. .cipher = {
  2070. .enc = {
  2071. .vecs = cast6_enc_tv_template,
  2072. .count = CAST6_ENC_TEST_VECTORS
  2073. },
  2074. .dec = {
  2075. .vecs = cast6_dec_tv_template,
  2076. .count = CAST6_DEC_TEST_VECTORS
  2077. }
  2078. }
  2079. }
  2080. }, {
  2081. .alg = "ecb(des)",
  2082. .test = alg_test_skcipher,
  2083. .fips_allowed = 1,
  2084. .suite = {
  2085. .cipher = {
  2086. .enc = {
  2087. .vecs = des_enc_tv_template,
  2088. .count = DES_ENC_TEST_VECTORS
  2089. },
  2090. .dec = {
  2091. .vecs = des_dec_tv_template,
  2092. .count = DES_DEC_TEST_VECTORS
  2093. }
  2094. }
  2095. }
  2096. }, {
  2097. .alg = "ecb(des3_ede)",
  2098. .test = alg_test_skcipher,
  2099. .fips_allowed = 1,
  2100. .suite = {
  2101. .cipher = {
  2102. .enc = {
  2103. .vecs = des3_ede_enc_tv_template,
  2104. .count = DES3_EDE_ENC_TEST_VECTORS
  2105. },
  2106. .dec = {
  2107. .vecs = des3_ede_dec_tv_template,
  2108. .count = DES3_EDE_DEC_TEST_VECTORS
  2109. }
  2110. }
  2111. }
  2112. }, {
  2113. .alg = "ecb(khazad)",
  2114. .test = alg_test_skcipher,
  2115. .suite = {
  2116. .cipher = {
  2117. .enc = {
  2118. .vecs = khazad_enc_tv_template,
  2119. .count = KHAZAD_ENC_TEST_VECTORS
  2120. },
  2121. .dec = {
  2122. .vecs = khazad_dec_tv_template,
  2123. .count = KHAZAD_DEC_TEST_VECTORS
  2124. }
  2125. }
  2126. }
  2127. }, {
  2128. .alg = "ecb(seed)",
  2129. .test = alg_test_skcipher,
  2130. .suite = {
  2131. .cipher = {
  2132. .enc = {
  2133. .vecs = seed_enc_tv_template,
  2134. .count = SEED_ENC_TEST_VECTORS
  2135. },
  2136. .dec = {
  2137. .vecs = seed_dec_tv_template,
  2138. .count = SEED_DEC_TEST_VECTORS
  2139. }
  2140. }
  2141. }
  2142. }, {
  2143. .alg = "ecb(serpent)",
  2144. .test = alg_test_skcipher,
  2145. .suite = {
  2146. .cipher = {
  2147. .enc = {
  2148. .vecs = serpent_enc_tv_template,
  2149. .count = SERPENT_ENC_TEST_VECTORS
  2150. },
  2151. .dec = {
  2152. .vecs = serpent_dec_tv_template,
  2153. .count = SERPENT_DEC_TEST_VECTORS
  2154. }
  2155. }
  2156. }
  2157. }, {
  2158. .alg = "ecb(tea)",
  2159. .test = alg_test_skcipher,
  2160. .suite = {
  2161. .cipher = {
  2162. .enc = {
  2163. .vecs = tea_enc_tv_template,
  2164. .count = TEA_ENC_TEST_VECTORS
  2165. },
  2166. .dec = {
  2167. .vecs = tea_dec_tv_template,
  2168. .count = TEA_DEC_TEST_VECTORS
  2169. }
  2170. }
  2171. }
  2172. }, {
  2173. .alg = "ecb(tnepres)",
  2174. .test = alg_test_skcipher,
  2175. .suite = {
  2176. .cipher = {
  2177. .enc = {
  2178. .vecs = tnepres_enc_tv_template,
  2179. .count = TNEPRES_ENC_TEST_VECTORS
  2180. },
  2181. .dec = {
  2182. .vecs = tnepres_dec_tv_template,
  2183. .count = TNEPRES_DEC_TEST_VECTORS
  2184. }
  2185. }
  2186. }
  2187. }, {
  2188. .alg = "ecb(twofish)",
  2189. .test = alg_test_skcipher,
  2190. .suite = {
  2191. .cipher = {
  2192. .enc = {
  2193. .vecs = tf_enc_tv_template,
  2194. .count = TF_ENC_TEST_VECTORS
  2195. },
  2196. .dec = {
  2197. .vecs = tf_dec_tv_template,
  2198. .count = TF_DEC_TEST_VECTORS
  2199. }
  2200. }
  2201. }
  2202. }, {
  2203. .alg = "ecb(xeta)",
  2204. .test = alg_test_skcipher,
  2205. .suite = {
  2206. .cipher = {
  2207. .enc = {
  2208. .vecs = xeta_enc_tv_template,
  2209. .count = XETA_ENC_TEST_VECTORS
  2210. },
  2211. .dec = {
  2212. .vecs = xeta_dec_tv_template,
  2213. .count = XETA_DEC_TEST_VECTORS
  2214. }
  2215. }
  2216. }
  2217. }, {
  2218. .alg = "ecb(xtea)",
  2219. .test = alg_test_skcipher,
  2220. .suite = {
  2221. .cipher = {
  2222. .enc = {
  2223. .vecs = xtea_enc_tv_template,
  2224. .count = XTEA_ENC_TEST_VECTORS
  2225. },
  2226. .dec = {
  2227. .vecs = xtea_dec_tv_template,
  2228. .count = XTEA_DEC_TEST_VECTORS
  2229. }
  2230. }
  2231. }
  2232. }, {
  2233. .alg = "gcm(aes)",
  2234. .test = alg_test_aead,
  2235. .fips_allowed = 1,
  2236. .suite = {
  2237. .aead = {
  2238. .enc = {
  2239. .vecs = aes_gcm_enc_tv_template,
  2240. .count = AES_GCM_ENC_TEST_VECTORS
  2241. },
  2242. .dec = {
  2243. .vecs = aes_gcm_dec_tv_template,
  2244. .count = AES_GCM_DEC_TEST_VECTORS
  2245. }
  2246. }
  2247. }
  2248. }, {
  2249. .alg = "ghash",
  2250. .test = alg_test_hash,
  2251. .fips_allowed = 1,
  2252. .suite = {
  2253. .hash = {
  2254. .vecs = ghash_tv_template,
  2255. .count = GHASH_TEST_VECTORS
  2256. }
  2257. }
  2258. }, {
  2259. .alg = "hmac(md5)",
  2260. .test = alg_test_hash,
  2261. .suite = {
  2262. .hash = {
  2263. .vecs = hmac_md5_tv_template,
  2264. .count = HMAC_MD5_TEST_VECTORS
  2265. }
  2266. }
  2267. }, {
  2268. .alg = "hmac(rmd128)",
  2269. .test = alg_test_hash,
  2270. .suite = {
  2271. .hash = {
  2272. .vecs = hmac_rmd128_tv_template,
  2273. .count = HMAC_RMD128_TEST_VECTORS
  2274. }
  2275. }
  2276. }, {
  2277. .alg = "hmac(rmd160)",
  2278. .test = alg_test_hash,
  2279. .suite = {
  2280. .hash = {
  2281. .vecs = hmac_rmd160_tv_template,
  2282. .count = HMAC_RMD160_TEST_VECTORS
  2283. }
  2284. }
  2285. }, {
  2286. .alg = "hmac(sha1)",
  2287. .test = alg_test_hash,
  2288. .fips_allowed = 1,
  2289. .suite = {
  2290. .hash = {
  2291. .vecs = hmac_sha1_tv_template,
  2292. .count = HMAC_SHA1_TEST_VECTORS
  2293. }
  2294. }
  2295. }, {
  2296. .alg = "hmac(sha224)",
  2297. .test = alg_test_hash,
  2298. .fips_allowed = 1,
  2299. .suite = {
  2300. .hash = {
  2301. .vecs = hmac_sha224_tv_template,
  2302. .count = HMAC_SHA224_TEST_VECTORS
  2303. }
  2304. }
  2305. }, {
  2306. .alg = "hmac(sha256)",
  2307. .test = alg_test_hash,
  2308. .fips_allowed = 1,
  2309. .suite = {
  2310. .hash = {
  2311. .vecs = hmac_sha256_tv_template,
  2312. .count = HMAC_SHA256_TEST_VECTORS
  2313. }
  2314. }
  2315. }, {
  2316. .alg = "hmac(sha384)",
  2317. .test = alg_test_hash,
  2318. .fips_allowed = 1,
  2319. .suite = {
  2320. .hash = {
  2321. .vecs = hmac_sha384_tv_template,
  2322. .count = HMAC_SHA384_TEST_VECTORS
  2323. }
  2324. }
  2325. }, {
  2326. .alg = "hmac(sha512)",
  2327. .test = alg_test_hash,
  2328. .fips_allowed = 1,
  2329. .suite = {
  2330. .hash = {
  2331. .vecs = hmac_sha512_tv_template,
  2332. .count = HMAC_SHA512_TEST_VECTORS
  2333. }
  2334. }
  2335. }, {
  2336. .alg = "lrw(aes)",
  2337. .test = alg_test_skcipher,
  2338. .suite = {
  2339. .cipher = {
  2340. .enc = {
  2341. .vecs = aes_lrw_enc_tv_template,
  2342. .count = AES_LRW_ENC_TEST_VECTORS
  2343. },
  2344. .dec = {
  2345. .vecs = aes_lrw_dec_tv_template,
  2346. .count = AES_LRW_DEC_TEST_VECTORS
  2347. }
  2348. }
  2349. }
  2350. }, {
  2351. .alg = "lrw(camellia)",
  2352. .test = alg_test_skcipher,
  2353. .suite = {
  2354. .cipher = {
  2355. .enc = {
  2356. .vecs = camellia_lrw_enc_tv_template,
  2357. .count = CAMELLIA_LRW_ENC_TEST_VECTORS
  2358. },
  2359. .dec = {
  2360. .vecs = camellia_lrw_dec_tv_template,
  2361. .count = CAMELLIA_LRW_DEC_TEST_VECTORS
  2362. }
  2363. }
  2364. }
  2365. }, {
  2366. .alg = "lrw(serpent)",
  2367. .test = alg_test_skcipher,
  2368. .suite = {
  2369. .cipher = {
  2370. .enc = {
  2371. .vecs = serpent_lrw_enc_tv_template,
  2372. .count = SERPENT_LRW_ENC_TEST_VECTORS
  2373. },
  2374. .dec = {
  2375. .vecs = serpent_lrw_dec_tv_template,
  2376. .count = SERPENT_LRW_DEC_TEST_VECTORS
  2377. }
  2378. }
  2379. }
  2380. }, {
  2381. .alg = "lrw(twofish)",
  2382. .test = alg_test_skcipher,
  2383. .suite = {
  2384. .cipher = {
  2385. .enc = {
  2386. .vecs = tf_lrw_enc_tv_template,
  2387. .count = TF_LRW_ENC_TEST_VECTORS
  2388. },
  2389. .dec = {
  2390. .vecs = tf_lrw_dec_tv_template,
  2391. .count = TF_LRW_DEC_TEST_VECTORS
  2392. }
  2393. }
  2394. }
  2395. }, {
  2396. .alg = "lzo",
  2397. .test = alg_test_comp,
  2398. .suite = {
  2399. .comp = {
  2400. .comp = {
  2401. .vecs = lzo_comp_tv_template,
  2402. .count = LZO_COMP_TEST_VECTORS
  2403. },
  2404. .decomp = {
  2405. .vecs = lzo_decomp_tv_template,
  2406. .count = LZO_DECOMP_TEST_VECTORS
  2407. }
  2408. }
  2409. }
  2410. }, {
  2411. .alg = "md4",
  2412. .test = alg_test_hash,
  2413. .suite = {
  2414. .hash = {
  2415. .vecs = md4_tv_template,
  2416. .count = MD4_TEST_VECTORS
  2417. }
  2418. }
  2419. }, {
  2420. .alg = "md5",
  2421. .test = alg_test_hash,
  2422. .suite = {
  2423. .hash = {
  2424. .vecs = md5_tv_template,
  2425. .count = MD5_TEST_VECTORS
  2426. }
  2427. }
  2428. }, {
  2429. .alg = "michael_mic",
  2430. .test = alg_test_hash,
  2431. .suite = {
  2432. .hash = {
  2433. .vecs = michael_mic_tv_template,
  2434. .count = MICHAEL_MIC_TEST_VECTORS
  2435. }
  2436. }
  2437. }, {
  2438. .alg = "ofb(aes)",
  2439. .test = alg_test_skcipher,
  2440. .fips_allowed = 1,
  2441. .suite = {
  2442. .cipher = {
  2443. .enc = {
  2444. .vecs = aes_ofb_enc_tv_template,
  2445. .count = AES_OFB_ENC_TEST_VECTORS
  2446. },
  2447. .dec = {
  2448. .vecs = aes_ofb_dec_tv_template,
  2449. .count = AES_OFB_DEC_TEST_VECTORS
  2450. }
  2451. }
  2452. }
  2453. }, {
  2454. .alg = "pcbc(fcrypt)",
  2455. .test = alg_test_skcipher,
  2456. .suite = {
  2457. .cipher = {
  2458. .enc = {
  2459. .vecs = fcrypt_pcbc_enc_tv_template,
  2460. .count = FCRYPT_ENC_TEST_VECTORS
  2461. },
  2462. .dec = {
  2463. .vecs = fcrypt_pcbc_dec_tv_template,
  2464. .count = FCRYPT_DEC_TEST_VECTORS
  2465. }
  2466. }
  2467. }
  2468. }, {
  2469. .alg = "rfc3686(ctr(aes))",
  2470. .test = alg_test_skcipher,
  2471. .fips_allowed = 1,
  2472. .suite = {
  2473. .cipher = {
  2474. .enc = {
  2475. .vecs = aes_ctr_rfc3686_enc_tv_template,
  2476. .count = AES_CTR_3686_ENC_TEST_VECTORS
  2477. },
  2478. .dec = {
  2479. .vecs = aes_ctr_rfc3686_dec_tv_template,
  2480. .count = AES_CTR_3686_DEC_TEST_VECTORS
  2481. }
  2482. }
  2483. }
  2484. }, {
  2485. .alg = "rfc4106(gcm(aes))",
  2486. .test = alg_test_aead,
  2487. .suite = {
  2488. .aead = {
  2489. .enc = {
  2490. .vecs = aes_gcm_rfc4106_enc_tv_template,
  2491. .count = AES_GCM_4106_ENC_TEST_VECTORS
  2492. },
  2493. .dec = {
  2494. .vecs = aes_gcm_rfc4106_dec_tv_template,
  2495. .count = AES_GCM_4106_DEC_TEST_VECTORS
  2496. }
  2497. }
  2498. }
  2499. }, {
  2500. .alg = "rfc4309(ccm(aes))",
  2501. .test = alg_test_aead,
  2502. .fips_allowed = 1,
  2503. .suite = {
  2504. .aead = {
  2505. .enc = {
  2506. .vecs = aes_ccm_rfc4309_enc_tv_template,
  2507. .count = AES_CCM_4309_ENC_TEST_VECTORS
  2508. },
  2509. .dec = {
  2510. .vecs = aes_ccm_rfc4309_dec_tv_template,
  2511. .count = AES_CCM_4309_DEC_TEST_VECTORS
  2512. }
  2513. }
  2514. }
  2515. }, {
  2516. .alg = "rmd128",
  2517. .test = alg_test_hash,
  2518. .suite = {
  2519. .hash = {
  2520. .vecs = rmd128_tv_template,
  2521. .count = RMD128_TEST_VECTORS
  2522. }
  2523. }
  2524. }, {
  2525. .alg = "rmd160",
  2526. .test = alg_test_hash,
  2527. .suite = {
  2528. .hash = {
  2529. .vecs = rmd160_tv_template,
  2530. .count = RMD160_TEST_VECTORS
  2531. }
  2532. }
  2533. }, {
  2534. .alg = "rmd256",
  2535. .test = alg_test_hash,
  2536. .suite = {
  2537. .hash = {
  2538. .vecs = rmd256_tv_template,
  2539. .count = RMD256_TEST_VECTORS
  2540. }
  2541. }
  2542. }, {
  2543. .alg = "rmd320",
  2544. .test = alg_test_hash,
  2545. .suite = {
  2546. .hash = {
  2547. .vecs = rmd320_tv_template,
  2548. .count = RMD320_TEST_VECTORS
  2549. }
  2550. }
  2551. }, {
  2552. .alg = "salsa20",
  2553. .test = alg_test_skcipher,
  2554. .suite = {
  2555. .cipher = {
  2556. .enc = {
  2557. .vecs = salsa20_stream_enc_tv_template,
  2558. .count = SALSA20_STREAM_ENC_TEST_VECTORS
  2559. }
  2560. }
  2561. }
  2562. }, {
  2563. .alg = "sha1",
  2564. .test = alg_test_hash,
  2565. .fips_allowed = 1,
  2566. .suite = {
  2567. .hash = {
  2568. .vecs = sha1_tv_template,
  2569. .count = SHA1_TEST_VECTORS
  2570. }
  2571. }
  2572. }, {
  2573. .alg = "sha224",
  2574. .test = alg_test_hash,
  2575. .fips_allowed = 1,
  2576. .suite = {
  2577. .hash = {
  2578. .vecs = sha224_tv_template,
  2579. .count = SHA224_TEST_VECTORS
  2580. }
  2581. }
  2582. }, {
  2583. .alg = "sha256",
  2584. .test = alg_test_hash,
  2585. .fips_allowed = 1,
  2586. .suite = {
  2587. .hash = {
  2588. .vecs = sha256_tv_template,
  2589. .count = SHA256_TEST_VECTORS
  2590. }
  2591. }
  2592. }, {
  2593. .alg = "sha384",
  2594. .test = alg_test_hash,
  2595. .fips_allowed = 1,
  2596. .suite = {
  2597. .hash = {
  2598. .vecs = sha384_tv_template,
  2599. .count = SHA384_TEST_VECTORS
  2600. }
  2601. }
  2602. }, {
  2603. .alg = "sha512",
  2604. .test = alg_test_hash,
  2605. .fips_allowed = 1,
  2606. .suite = {
  2607. .hash = {
  2608. .vecs = sha512_tv_template,
  2609. .count = SHA512_TEST_VECTORS
  2610. }
  2611. }
  2612. }, {
  2613. .alg = "tgr128",
  2614. .test = alg_test_hash,
  2615. .suite = {
  2616. .hash = {
  2617. .vecs = tgr128_tv_template,
  2618. .count = TGR128_TEST_VECTORS
  2619. }
  2620. }
  2621. }, {
  2622. .alg = "tgr160",
  2623. .test = alg_test_hash,
  2624. .suite = {
  2625. .hash = {
  2626. .vecs = tgr160_tv_template,
  2627. .count = TGR160_TEST_VECTORS
  2628. }
  2629. }
  2630. }, {
  2631. .alg = "tgr192",
  2632. .test = alg_test_hash,
  2633. .suite = {
  2634. .hash = {
  2635. .vecs = tgr192_tv_template,
  2636. .count = TGR192_TEST_VECTORS
  2637. }
  2638. }
  2639. }, {
  2640. .alg = "vmac(aes)",
  2641. .test = alg_test_hash,
  2642. .suite = {
  2643. .hash = {
  2644. .vecs = aes_vmac128_tv_template,
  2645. .count = VMAC_AES_TEST_VECTORS
  2646. }
  2647. }
  2648. }, {
  2649. .alg = "wp256",
  2650. .test = alg_test_hash,
  2651. .suite = {
  2652. .hash = {
  2653. .vecs = wp256_tv_template,
  2654. .count = WP256_TEST_VECTORS
  2655. }
  2656. }
  2657. }, {
  2658. .alg = "wp384",
  2659. .test = alg_test_hash,
  2660. .suite = {
  2661. .hash = {
  2662. .vecs = wp384_tv_template,
  2663. .count = WP384_TEST_VECTORS
  2664. }
  2665. }
  2666. }, {
  2667. .alg = "wp512",
  2668. .test = alg_test_hash,
  2669. .suite = {
  2670. .hash = {
  2671. .vecs = wp512_tv_template,
  2672. .count = WP512_TEST_VECTORS
  2673. }
  2674. }
  2675. }, {
  2676. .alg = "xcbc(aes)",
  2677. .test = alg_test_hash,
  2678. .suite = {
  2679. .hash = {
  2680. .vecs = aes_xcbc128_tv_template,
  2681. .count = XCBC_AES_TEST_VECTORS
  2682. }
  2683. }
  2684. }, {
  2685. .alg = "xts(aes)",
  2686. .test = alg_test_skcipher,
  2687. .fips_allowed = 1,
  2688. .suite = {
  2689. .cipher = {
  2690. .enc = {
  2691. .vecs = aes_xts_enc_tv_template,
  2692. .count = AES_XTS_ENC_TEST_VECTORS
  2693. },
  2694. .dec = {
  2695. .vecs = aes_xts_dec_tv_template,
  2696. .count = AES_XTS_DEC_TEST_VECTORS
  2697. }
  2698. }
  2699. }
  2700. }, {
  2701. .alg = "xts(camellia)",
  2702. .test = alg_test_skcipher,
  2703. .suite = {
  2704. .cipher = {
  2705. .enc = {
  2706. .vecs = camellia_xts_enc_tv_template,
  2707. .count = CAMELLIA_XTS_ENC_TEST_VECTORS
  2708. },
  2709. .dec = {
  2710. .vecs = camellia_xts_dec_tv_template,
  2711. .count = CAMELLIA_XTS_DEC_TEST_VECTORS
  2712. }
  2713. }
  2714. }
  2715. }, {
  2716. .alg = "xts(serpent)",
  2717. .test = alg_test_skcipher,
  2718. .suite = {
  2719. .cipher = {
  2720. .enc = {
  2721. .vecs = serpent_xts_enc_tv_template,
  2722. .count = SERPENT_XTS_ENC_TEST_VECTORS
  2723. },
  2724. .dec = {
  2725. .vecs = serpent_xts_dec_tv_template,
  2726. .count = SERPENT_XTS_DEC_TEST_VECTORS
  2727. }
  2728. }
  2729. }
  2730. }, {
  2731. .alg = "xts(twofish)",
  2732. .test = alg_test_skcipher,
  2733. .suite = {
  2734. .cipher = {
  2735. .enc = {
  2736. .vecs = tf_xts_enc_tv_template,
  2737. .count = TF_XTS_ENC_TEST_VECTORS
  2738. },
  2739. .dec = {
  2740. .vecs = tf_xts_dec_tv_template,
  2741. .count = TF_XTS_DEC_TEST_VECTORS
  2742. }
  2743. }
  2744. }
  2745. }, {
  2746. .alg = "zlib",
  2747. .test = alg_test_pcomp,
  2748. .suite = {
  2749. .pcomp = {
  2750. .comp = {
  2751. .vecs = zlib_comp_tv_template,
  2752. .count = ZLIB_COMP_TEST_VECTORS
  2753. },
  2754. .decomp = {
  2755. .vecs = zlib_decomp_tv_template,
  2756. .count = ZLIB_DECOMP_TEST_VECTORS
  2757. }
  2758. }
  2759. }
  2760. }
  2761. };
  2762. static int alg_find_test(const char *alg)
  2763. {
  2764. int start = 0;
  2765. int end = ARRAY_SIZE(alg_test_descs);
  2766. while (start < end) {
  2767. int i = (start + end) / 2;
  2768. int diff = strcmp(alg_test_descs[i].alg, alg);
  2769. if (diff > 0) {
  2770. end = i;
  2771. continue;
  2772. }
  2773. if (diff < 0) {
  2774. start = i + 1;
  2775. continue;
  2776. }
  2777. return i;
  2778. }
  2779. return -1;
  2780. }
  2781. int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
  2782. {
  2783. int i;
  2784. int j;
  2785. int rc = 0;
  2786. if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
  2787. char nalg[CRYPTO_MAX_ALG_NAME];
  2788. if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
  2789. sizeof(nalg))
  2790. return -ENAMETOOLONG;
  2791. i = alg_find_test(nalg);
  2792. if (i < 0)
  2793. goto notest;
  2794. if (fips_enabled && !alg_test_descs[i].fips_allowed)
  2795. goto non_fips_alg;
  2796. rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
  2797. goto test_done;
  2798. }
  2799. i = alg_find_test(alg);
  2800. j = alg_find_test(driver);
  2801. if (i < 0 && j < 0)
  2802. goto notest;
  2803. #if FIPS_FUNC_TEST == 3
  2804. // change@wtl.rsengott - FIPS mode self test Functional Test
  2805. if (fips_enabled)
  2806. printk(KERN_INFO "FIPS: %s: %s alg self test START in fips mode!\n",
  2807. driver, alg);
  2808. #endif
  2809. if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
  2810. (j >= 0 && !alg_test_descs[j].fips_allowed)))
  2811. goto non_fips_alg;
  2812. rc = 0;
  2813. if (i >= 0)
  2814. rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
  2815. type, mask);
  2816. if (j >= 0)
  2817. rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
  2818. type, mask);
  2819. test_done:
  2820. if (fips_enabled && rc) {
  2821. printk(KERN_INFO
  2822. "FIPS: %s: %s alg self test failed\n",
  2823. driver, alg);
  2824. #ifdef CONFIG_CRYPTO_FIPS
  2825. IN_FIPS_ERROR = FIPS_ERR;
  2826. #else
  2827. panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
  2828. #endif
  2829. return rc;
  2830. }
  2831. if (fips_enabled && !rc)
  2832. printk(KERN_INFO "FIPS: self-tests for %s (%s) passed\n",
  2833. driver, alg);
  2834. return rc;
  2835. notest:
  2836. printk(KERN_INFO "FIPS: No test for %s (%s)\n", alg, driver);
  2837. return 0;
  2838. non_fips_alg:
  2839. if (!rc)
  2840. printk(KERN_INFO
  2841. "FIPS: self-tests for non-FIPS %s (%s) passed\n",
  2842. driver, alg);
  2843. else
  2844. printk(KERN_INFO
  2845. "FIPS: self-tests for non-FIPS %s (%s) failed\n",
  2846. alg, driver);
  2847. return rc;
  2848. }
  2849. int testmgr_crypto_proc_init(void)
  2850. {
  2851. #ifdef CONFIG_CRYPTO_FIPS
  2852. crypto_init_proc(&IN_FIPS_ERROR);
  2853. #else
  2854. crypto_init_proc();
  2855. #endif
  2856. return 0;
  2857. }
  2858. #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
  2859. EXPORT_SYMBOL_GPL(alg_test);