testmgr.c 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851
  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/aead.h>
  23. #include <crypto/hash.h>
  24. #include <crypto/skcipher.h>
  25. #include <linux/err.h>
  26. #include <linux/fips.h>
  27. #include <linux/module.h>
  28. #include <linux/scatterlist.h>
  29. #include <linux/slab.h>
  30. #include <linux/string.h>
  31. #include <crypto/rng.h>
  32. #include <crypto/drbg.h>
  33. #include <crypto/akcipher.h>
  34. #include <crypto/kpp.h>
  35. #include <crypto/acompress.h>
  36. #include "internal.h"
  37. static bool notests;
  38. module_param(notests, bool, 0644);
  39. MODULE_PARM_DESC(notests, "disable crypto self-tests");
  40. #ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
  41. /* a perfect nop */
  42. int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
  43. {
  44. return 0;
  45. }
  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 1511
  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. struct aead_test_suite {
  69. struct {
  70. const struct aead_testvec *vecs;
  71. unsigned int count;
  72. } enc, dec;
  73. };
  74. struct cipher_test_suite {
  75. struct {
  76. const struct cipher_testvec *vecs;
  77. unsigned int count;
  78. } enc, dec;
  79. };
  80. struct comp_test_suite {
  81. struct {
  82. const struct comp_testvec *vecs;
  83. unsigned int count;
  84. } comp, decomp;
  85. };
  86. struct hash_test_suite {
  87. const struct hash_testvec *vecs;
  88. unsigned int count;
  89. };
  90. struct cprng_test_suite {
  91. const struct cprng_testvec *vecs;
  92. unsigned int count;
  93. };
  94. struct drbg_test_suite {
  95. const struct drbg_testvec *vecs;
  96. unsigned int count;
  97. };
  98. struct akcipher_test_suite {
  99. const struct akcipher_testvec *vecs;
  100. unsigned int count;
  101. };
  102. struct kpp_test_suite {
  103. const struct kpp_testvec *vecs;
  104. unsigned int count;
  105. };
  106. struct alg_test_desc {
  107. const char *alg;
  108. int (*test)(const struct alg_test_desc *desc, const char *driver,
  109. u32 type, u32 mask);
  110. int fips_allowed; /* set if alg is allowed in fips mode */
  111. union {
  112. struct aead_test_suite aead;
  113. struct cipher_test_suite cipher;
  114. struct comp_test_suite comp;
  115. struct hash_test_suite hash;
  116. struct cprng_test_suite cprng;
  117. struct drbg_test_suite drbg;
  118. struct akcipher_test_suite akcipher;
  119. struct kpp_test_suite kpp;
  120. } suite;
  121. };
  122. static const unsigned int IDX[8] = {
  123. IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
  124. static void hexdump(unsigned char *buf, unsigned int len)
  125. {
  126. print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
  127. 16, 1,
  128. buf, len, false);
  129. }
  130. static int testmgr_alloc_buf(char *buf[XBUFSIZE])
  131. {
  132. int i;
  133. for (i = 0; i < XBUFSIZE; i++) {
  134. buf[i] = (void *)__get_free_page(GFP_KERNEL);
  135. if (!buf[i])
  136. goto err_free_buf;
  137. }
  138. return 0;
  139. err_free_buf:
  140. while (i-- > 0)
  141. free_page((unsigned long)buf[i]);
  142. return -ENOMEM;
  143. }
  144. static void testmgr_free_buf(char *buf[XBUFSIZE])
  145. {
  146. int i;
  147. for (i = 0; i < XBUFSIZE; i++)
  148. free_page((unsigned long)buf[i]);
  149. }
  150. static int ahash_guard_result(char *result, char c, int size)
  151. {
  152. int i;
  153. for (i = 0; i < size; i++) {
  154. if (result[i] != c)
  155. return -EINVAL;
  156. }
  157. return 0;
  158. }
  159. static int ahash_partial_update(struct ahash_request **preq,
  160. struct crypto_ahash *tfm, const struct hash_testvec *template,
  161. void *hash_buff, int k, int temp, struct scatterlist *sg,
  162. const char *algo, char *result, struct crypto_wait *wait)
  163. {
  164. char *state;
  165. struct ahash_request *req;
  166. int statesize, ret = -EINVAL;
  167. static const unsigned char guard[] = { 0x00, 0xba, 0xad, 0x00 };
  168. int digestsize = crypto_ahash_digestsize(tfm);
  169. req = *preq;
  170. statesize = crypto_ahash_statesize(
  171. crypto_ahash_reqtfm(req));
  172. state = kmalloc(statesize + sizeof(guard), GFP_KERNEL);
  173. if (!state) {
  174. pr_err("alg: hash: Failed to alloc state for %s\n", algo);
  175. goto out_nostate;
  176. }
  177. memcpy(state + statesize, guard, sizeof(guard));
  178. memset(result, 1, digestsize);
  179. ret = crypto_ahash_export(req, state);
  180. WARN_ON(memcmp(state + statesize, guard, sizeof(guard)));
  181. if (ret) {
  182. pr_err("alg: hash: Failed to export() for %s\n", algo);
  183. goto out;
  184. }
  185. ret = ahash_guard_result(result, 1, digestsize);
  186. if (ret) {
  187. pr_err("alg: hash: Failed, export used req->result for %s\n",
  188. algo);
  189. goto out;
  190. }
  191. ahash_request_free(req);
  192. req = ahash_request_alloc(tfm, GFP_KERNEL);
  193. if (!req) {
  194. pr_err("alg: hash: Failed to alloc request for %s\n", algo);
  195. goto out_noreq;
  196. }
  197. ahash_request_set_callback(req,
  198. CRYPTO_TFM_REQ_MAY_BACKLOG,
  199. crypto_req_done, wait);
  200. memcpy(hash_buff, template->plaintext + temp,
  201. template->tap[k]);
  202. sg_init_one(&sg[0], hash_buff, template->tap[k]);
  203. ahash_request_set_crypt(req, sg, result, template->tap[k]);
  204. ret = crypto_ahash_import(req, state);
  205. if (ret) {
  206. pr_err("alg: hash: Failed to import() for %s\n", algo);
  207. goto out;
  208. }
  209. ret = ahash_guard_result(result, 1, digestsize);
  210. if (ret) {
  211. pr_err("alg: hash: Failed, import used req->result for %s\n",
  212. algo);
  213. goto out;
  214. }
  215. ret = crypto_wait_req(crypto_ahash_update(req), wait);
  216. if (ret)
  217. goto out;
  218. *preq = req;
  219. ret = 0;
  220. goto out_noreq;
  221. out:
  222. ahash_request_free(req);
  223. out_noreq:
  224. kfree(state);
  225. out_nostate:
  226. return ret;
  227. }
  228. static int __test_hash(struct crypto_ahash *tfm,
  229. const struct hash_testvec *template, unsigned int tcount,
  230. bool use_digest, const int align_offset)
  231. {
  232. const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
  233. size_t digest_size = crypto_ahash_digestsize(tfm);
  234. unsigned int i, j, k, temp;
  235. struct scatterlist sg[8];
  236. char *result;
  237. char *key;
  238. struct ahash_request *req;
  239. struct crypto_wait wait;
  240. void *hash_buff;
  241. char *xbuf[XBUFSIZE];
  242. int ret = -ENOMEM;
  243. result = kmalloc(digest_size, GFP_KERNEL);
  244. if (!result)
  245. return ret;
  246. key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
  247. if (!key)
  248. goto out_nobuf;
  249. if (testmgr_alloc_buf(xbuf))
  250. goto out_nobuf;
  251. crypto_init_wait(&wait);
  252. req = ahash_request_alloc(tfm, GFP_KERNEL);
  253. if (!req) {
  254. printk(KERN_ERR "alg: hash: Failed to allocate request for "
  255. "%s\n", algo);
  256. goto out_noreq;
  257. }
  258. ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  259. crypto_req_done, &wait);
  260. j = 0;
  261. for (i = 0; i < tcount; i++) {
  262. if (template[i].np)
  263. continue;
  264. ret = -EINVAL;
  265. if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE))
  266. goto out;
  267. j++;
  268. memset(result, 0, digest_size);
  269. hash_buff = xbuf[0];
  270. hash_buff += align_offset;
  271. memcpy(hash_buff, template[i].plaintext, template[i].psize);
  272. sg_init_one(&sg[0], hash_buff, template[i].psize);
  273. if (template[i].ksize) {
  274. crypto_ahash_clear_flags(tfm, ~0);
  275. if (template[i].ksize > MAX_KEYLEN) {
  276. pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
  277. j, algo, template[i].ksize, MAX_KEYLEN);
  278. ret = -EINVAL;
  279. goto out;
  280. }
  281. memcpy(key, template[i].key, template[i].ksize);
  282. ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
  283. if (ret) {
  284. printk(KERN_ERR "alg: hash: setkey failed on "
  285. "test %d for %s: ret=%d\n", j, algo,
  286. -ret);
  287. goto out;
  288. }
  289. }
  290. ahash_request_set_crypt(req, sg, result, template[i].psize);
  291. if (use_digest) {
  292. ret = crypto_wait_req(crypto_ahash_digest(req), &wait);
  293. if (ret) {
  294. pr_err("alg: hash: digest failed on test %d "
  295. "for %s: ret=%d\n", j, algo, -ret);
  296. goto out;
  297. }
  298. } else {
  299. memset(result, 1, digest_size);
  300. ret = crypto_wait_req(crypto_ahash_init(req), &wait);
  301. if (ret) {
  302. pr_err("alg: hash: init failed on test %d "
  303. "for %s: ret=%d\n", j, algo, -ret);
  304. goto out;
  305. }
  306. ret = ahash_guard_result(result, 1, digest_size);
  307. if (ret) {
  308. pr_err("alg: hash: init failed on test %d "
  309. "for %s: used req->result\n", j, algo);
  310. goto out;
  311. }
  312. ret = crypto_wait_req(crypto_ahash_update(req), &wait);
  313. if (ret) {
  314. pr_err("alg: hash: update failed on test %d "
  315. "for %s: ret=%d\n", j, algo, -ret);
  316. goto out;
  317. }
  318. ret = ahash_guard_result(result, 1, digest_size);
  319. if (ret) {
  320. pr_err("alg: hash: update failed on test %d "
  321. "for %s: used req->result\n", j, algo);
  322. goto out;
  323. }
  324. ret = crypto_wait_req(crypto_ahash_final(req), &wait);
  325. if (ret) {
  326. pr_err("alg: hash: final failed on test %d "
  327. "for %s: ret=%d\n", j, algo, -ret);
  328. goto out;
  329. }
  330. }
  331. if (memcmp(result, template[i].digest,
  332. crypto_ahash_digestsize(tfm))) {
  333. printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
  334. j, algo);
  335. hexdump(result, crypto_ahash_digestsize(tfm));
  336. ret = -EINVAL;
  337. goto out;
  338. }
  339. }
  340. j = 0;
  341. for (i = 0; i < tcount; i++) {
  342. /* alignment tests are only done with continuous buffers */
  343. if (align_offset != 0)
  344. break;
  345. if (!template[i].np)
  346. continue;
  347. j++;
  348. memset(result, 0, digest_size);
  349. temp = 0;
  350. sg_init_table(sg, template[i].np);
  351. ret = -EINVAL;
  352. for (k = 0; k < template[i].np; k++) {
  353. if (WARN_ON(offset_in_page(IDX[k]) +
  354. template[i].tap[k] > PAGE_SIZE))
  355. goto out;
  356. sg_set_buf(&sg[k],
  357. memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
  358. offset_in_page(IDX[k]),
  359. template[i].plaintext + temp,
  360. template[i].tap[k]),
  361. template[i].tap[k]);
  362. temp += template[i].tap[k];
  363. }
  364. if (template[i].ksize) {
  365. if (template[i].ksize > MAX_KEYLEN) {
  366. pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
  367. j, algo, template[i].ksize, MAX_KEYLEN);
  368. ret = -EINVAL;
  369. goto out;
  370. }
  371. crypto_ahash_clear_flags(tfm, ~0);
  372. memcpy(key, template[i].key, template[i].ksize);
  373. ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
  374. if (ret) {
  375. printk(KERN_ERR "alg: hash: setkey "
  376. "failed on chunking test %d "
  377. "for %s: ret=%d\n", j, algo, -ret);
  378. goto out;
  379. }
  380. }
  381. ahash_request_set_crypt(req, sg, result, template[i].psize);
  382. ret = crypto_wait_req(crypto_ahash_digest(req), &wait);
  383. if (ret) {
  384. pr_err("alg: hash: digest failed on chunking test %d for %s: ret=%d\n",
  385. j, algo, -ret);
  386. goto out;
  387. }
  388. if (memcmp(result, template[i].digest,
  389. crypto_ahash_digestsize(tfm))) {
  390. printk(KERN_ERR "alg: hash: Chunking test %d "
  391. "failed for %s\n", j, algo);
  392. hexdump(result, crypto_ahash_digestsize(tfm));
  393. ret = -EINVAL;
  394. goto out;
  395. }
  396. }
  397. /* partial update exercise */
  398. j = 0;
  399. for (i = 0; i < tcount; i++) {
  400. /* alignment tests are only done with continuous buffers */
  401. if (align_offset != 0)
  402. break;
  403. if (template[i].np < 2)
  404. continue;
  405. j++;
  406. memset(result, 0, digest_size);
  407. ret = -EINVAL;
  408. hash_buff = xbuf[0];
  409. memcpy(hash_buff, template[i].plaintext,
  410. template[i].tap[0]);
  411. sg_init_one(&sg[0], hash_buff, template[i].tap[0]);
  412. if (template[i].ksize) {
  413. crypto_ahash_clear_flags(tfm, ~0);
  414. if (template[i].ksize > MAX_KEYLEN) {
  415. pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
  416. j, algo, template[i].ksize, MAX_KEYLEN);
  417. ret = -EINVAL;
  418. goto out;
  419. }
  420. memcpy(key, template[i].key, template[i].ksize);
  421. ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
  422. if (ret) {
  423. pr_err("alg: hash: setkey failed on test %d for %s: ret=%d\n",
  424. j, algo, -ret);
  425. goto out;
  426. }
  427. }
  428. ahash_request_set_crypt(req, sg, result, template[i].tap[0]);
  429. ret = crypto_wait_req(crypto_ahash_init(req), &wait);
  430. if (ret) {
  431. pr_err("alg: hash: init failed on test %d for %s: ret=%d\n",
  432. j, algo, -ret);
  433. goto out;
  434. }
  435. ret = crypto_wait_req(crypto_ahash_update(req), &wait);
  436. if (ret) {
  437. pr_err("alg: hash: update failed on test %d for %s: ret=%d\n",
  438. j, algo, -ret);
  439. goto out;
  440. }
  441. temp = template[i].tap[0];
  442. for (k = 1; k < template[i].np; k++) {
  443. ret = ahash_partial_update(&req, tfm, &template[i],
  444. hash_buff, k, temp, &sg[0], algo, result,
  445. &wait);
  446. if (ret) {
  447. pr_err("alg: hash: partial update failed on test %d for %s: ret=%d\n",
  448. j, algo, -ret);
  449. goto out_noreq;
  450. }
  451. temp += template[i].tap[k];
  452. }
  453. ret = crypto_wait_req(crypto_ahash_final(req), &wait);
  454. if (ret) {
  455. pr_err("alg: hash: final failed on test %d for %s: ret=%d\n",
  456. j, algo, -ret);
  457. goto out;
  458. }
  459. if (memcmp(result, template[i].digest,
  460. crypto_ahash_digestsize(tfm))) {
  461. pr_err("alg: hash: Partial Test %d failed for %s\n",
  462. j, algo);
  463. hexdump(result, crypto_ahash_digestsize(tfm));
  464. ret = -EINVAL;
  465. goto out;
  466. }
  467. }
  468. ret = 0;
  469. out:
  470. ahash_request_free(req);
  471. out_noreq:
  472. testmgr_free_buf(xbuf);
  473. out_nobuf:
  474. kfree(key);
  475. kfree(result);
  476. return ret;
  477. }
  478. static int test_hash(struct crypto_ahash *tfm,
  479. const struct hash_testvec *template,
  480. unsigned int tcount, bool use_digest)
  481. {
  482. unsigned int alignmask;
  483. int ret;
  484. ret = __test_hash(tfm, template, tcount, use_digest, 0);
  485. if (ret)
  486. return ret;
  487. /* test unaligned buffers, check with one byte offset */
  488. ret = __test_hash(tfm, template, tcount, use_digest, 1);
  489. if (ret)
  490. return ret;
  491. alignmask = crypto_tfm_alg_alignmask(&tfm->base);
  492. if (alignmask) {
  493. /* Check if alignment mask for tfm is correctly set. */
  494. ret = __test_hash(tfm, template, tcount, use_digest,
  495. alignmask + 1);
  496. if (ret)
  497. return ret;
  498. }
  499. return 0;
  500. }
  501. static int __test_aead(struct crypto_aead *tfm, int enc,
  502. const struct aead_testvec *template, unsigned int tcount,
  503. const bool diff_dst, const int align_offset)
  504. {
  505. const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
  506. unsigned int i, j, k, n, temp;
  507. int ret = -ENOMEM;
  508. char *q;
  509. char *key;
  510. struct aead_request *req;
  511. struct scatterlist *sg;
  512. struct scatterlist *sgout;
  513. const char *e, *d;
  514. struct crypto_wait wait;
  515. unsigned int authsize, iv_len;
  516. void *input;
  517. void *output;
  518. void *assoc;
  519. char *iv;
  520. char *xbuf[XBUFSIZE];
  521. char *xoutbuf[XBUFSIZE];
  522. char *axbuf[XBUFSIZE];
  523. iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
  524. if (!iv)
  525. return ret;
  526. key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
  527. if (!key)
  528. goto out_noxbuf;
  529. if (testmgr_alloc_buf(xbuf))
  530. goto out_noxbuf;
  531. if (testmgr_alloc_buf(axbuf))
  532. goto out_noaxbuf;
  533. if (diff_dst && testmgr_alloc_buf(xoutbuf))
  534. goto out_nooutbuf;
  535. /* avoid "the frame size is larger than 1024 bytes" compiler warning */
  536. sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 4 : 2), GFP_KERNEL);
  537. if (!sg)
  538. goto out_nosg;
  539. sgout = &sg[16];
  540. if (diff_dst)
  541. d = "-ddst";
  542. else
  543. d = "";
  544. if (enc == ENCRYPT)
  545. e = "encryption";
  546. else
  547. e = "decryption";
  548. crypto_init_wait(&wait);
  549. req = aead_request_alloc(tfm, GFP_KERNEL);
  550. if (!req) {
  551. pr_err("alg: aead%s: Failed to allocate request for %s\n",
  552. d, algo);
  553. goto out;
  554. }
  555. aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  556. crypto_req_done, &wait);
  557. iv_len = crypto_aead_ivsize(tfm);
  558. for (i = 0, j = 0; i < tcount; i++) {
  559. if (template[i].np)
  560. continue;
  561. j++;
  562. /* some templates have no input data but they will
  563. * touch input
  564. */
  565. input = xbuf[0];
  566. input += align_offset;
  567. assoc = axbuf[0];
  568. ret = -EINVAL;
  569. if (WARN_ON(align_offset + template[i].ilen >
  570. PAGE_SIZE || template[i].alen > PAGE_SIZE))
  571. goto out;
  572. memcpy(input, template[i].input, template[i].ilen);
  573. memcpy(assoc, template[i].assoc, template[i].alen);
  574. if (template[i].iv)
  575. memcpy(iv, template[i].iv, iv_len);
  576. else
  577. memset(iv, 0, iv_len);
  578. crypto_aead_clear_flags(tfm, ~0);
  579. if (template[i].wk)
  580. crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  581. if (template[i].klen > MAX_KEYLEN) {
  582. pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
  583. d, j, algo, template[i].klen,
  584. MAX_KEYLEN);
  585. ret = -EINVAL;
  586. goto out;
  587. }
  588. memcpy(key, template[i].key, template[i].klen);
  589. ret = crypto_aead_setkey(tfm, key, template[i].klen);
  590. if (template[i].fail == !ret) {
  591. pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
  592. d, j, algo, crypto_aead_get_flags(tfm));
  593. goto out;
  594. } else if (ret)
  595. continue;
  596. authsize = abs(template[i].rlen - template[i].ilen);
  597. ret = crypto_aead_setauthsize(tfm, authsize);
  598. if (ret) {
  599. pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
  600. d, authsize, j, algo);
  601. goto out;
  602. }
  603. k = !!template[i].alen;
  604. sg_init_table(sg, k + 1);
  605. sg_set_buf(&sg[0], assoc, template[i].alen);
  606. sg_set_buf(&sg[k], input,
  607. template[i].ilen + (enc ? authsize : 0));
  608. output = input;
  609. if (diff_dst) {
  610. sg_init_table(sgout, k + 1);
  611. sg_set_buf(&sgout[0], assoc, template[i].alen);
  612. output = xoutbuf[0];
  613. output += align_offset;
  614. sg_set_buf(&sgout[k], output,
  615. template[i].rlen + (enc ? 0 : authsize));
  616. }
  617. aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
  618. template[i].ilen, iv);
  619. aead_request_set_ad(req, template[i].alen);
  620. ret = crypto_wait_req(enc ? crypto_aead_encrypt(req)
  621. : crypto_aead_decrypt(req), &wait);
  622. switch (ret) {
  623. case 0:
  624. if (template[i].novrfy) {
  625. /* verification was supposed to fail */
  626. pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
  627. d, e, j, algo);
  628. /* so really, we got a bad message */
  629. ret = -EBADMSG;
  630. goto out;
  631. }
  632. break;
  633. case -EBADMSG:
  634. if (template[i].novrfy)
  635. /* verification failure was expected */
  636. continue;
  637. /* fall through */
  638. default:
  639. pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
  640. d, e, j, algo, -ret);
  641. goto out;
  642. }
  643. q = output;
  644. if (memcmp(q, template[i].result, template[i].rlen)) {
  645. pr_err("alg: aead%s: Test %d failed on %s for %s\n",
  646. d, j, e, algo);
  647. hexdump(q, template[i].rlen);
  648. ret = -EINVAL;
  649. goto out;
  650. }
  651. }
  652. for (i = 0, j = 0; i < tcount; i++) {
  653. /* alignment tests are only done with continuous buffers */
  654. if (align_offset != 0)
  655. break;
  656. if (!template[i].np)
  657. continue;
  658. j++;
  659. if (template[i].iv)
  660. memcpy(iv, template[i].iv, iv_len);
  661. else
  662. memset(iv, 0, MAX_IVLEN);
  663. crypto_aead_clear_flags(tfm, ~0);
  664. if (template[i].wk)
  665. crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  666. if (template[i].klen > MAX_KEYLEN) {
  667. pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
  668. d, j, algo, template[i].klen, MAX_KEYLEN);
  669. ret = -EINVAL;
  670. goto out;
  671. }
  672. memcpy(key, template[i].key, template[i].klen);
  673. ret = crypto_aead_setkey(tfm, key, template[i].klen);
  674. if (template[i].fail == !ret) {
  675. pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
  676. d, j, algo, crypto_aead_get_flags(tfm));
  677. goto out;
  678. } else if (ret)
  679. continue;
  680. authsize = abs(template[i].rlen - template[i].ilen);
  681. ret = -EINVAL;
  682. sg_init_table(sg, template[i].anp + template[i].np);
  683. if (diff_dst)
  684. sg_init_table(sgout, template[i].anp + template[i].np);
  685. ret = -EINVAL;
  686. for (k = 0, temp = 0; k < template[i].anp; k++) {
  687. if (WARN_ON(offset_in_page(IDX[k]) +
  688. template[i].atap[k] > PAGE_SIZE))
  689. goto out;
  690. sg_set_buf(&sg[k],
  691. memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
  692. offset_in_page(IDX[k]),
  693. template[i].assoc + temp,
  694. template[i].atap[k]),
  695. template[i].atap[k]);
  696. if (diff_dst)
  697. sg_set_buf(&sgout[k],
  698. axbuf[IDX[k] >> PAGE_SHIFT] +
  699. offset_in_page(IDX[k]),
  700. template[i].atap[k]);
  701. temp += template[i].atap[k];
  702. }
  703. for (k = 0, temp = 0; k < template[i].np; k++) {
  704. if (WARN_ON(offset_in_page(IDX[k]) +
  705. template[i].tap[k] > PAGE_SIZE))
  706. goto out;
  707. q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
  708. memcpy(q, template[i].input + temp, template[i].tap[k]);
  709. sg_set_buf(&sg[template[i].anp + k],
  710. q, template[i].tap[k]);
  711. if (diff_dst) {
  712. q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
  713. offset_in_page(IDX[k]);
  714. memset(q, 0, template[i].tap[k]);
  715. sg_set_buf(&sgout[template[i].anp + k],
  716. q, template[i].tap[k]);
  717. }
  718. n = template[i].tap[k];
  719. if (k == template[i].np - 1 && enc)
  720. n += authsize;
  721. if (offset_in_page(q) + n < PAGE_SIZE)
  722. q[n] = 0;
  723. temp += template[i].tap[k];
  724. }
  725. ret = crypto_aead_setauthsize(tfm, authsize);
  726. if (ret) {
  727. pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
  728. d, authsize, j, algo);
  729. goto out;
  730. }
  731. if (enc) {
  732. if (WARN_ON(sg[template[i].anp + k - 1].offset +
  733. sg[template[i].anp + k - 1].length +
  734. authsize > PAGE_SIZE)) {
  735. ret = -EINVAL;
  736. goto out;
  737. }
  738. if (diff_dst)
  739. sgout[template[i].anp + k - 1].length +=
  740. authsize;
  741. sg[template[i].anp + k - 1].length += authsize;
  742. }
  743. aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
  744. template[i].ilen,
  745. iv);
  746. aead_request_set_ad(req, template[i].alen);
  747. ret = crypto_wait_req(enc ? crypto_aead_encrypt(req)
  748. : crypto_aead_decrypt(req), &wait);
  749. switch (ret) {
  750. case 0:
  751. if (template[i].novrfy) {
  752. /* verification was supposed to fail */
  753. pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
  754. d, e, j, algo);
  755. /* so really, we got a bad message */
  756. ret = -EBADMSG;
  757. goto out;
  758. }
  759. break;
  760. case -EBADMSG:
  761. if (template[i].novrfy)
  762. /* verification failure was expected */
  763. continue;
  764. /* fall through */
  765. default:
  766. pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
  767. d, e, j, algo, -ret);
  768. goto out;
  769. }
  770. ret = -EINVAL;
  771. for (k = 0, temp = 0; k < template[i].np; k++) {
  772. if (diff_dst)
  773. q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
  774. offset_in_page(IDX[k]);
  775. else
  776. q = xbuf[IDX[k] >> PAGE_SHIFT] +
  777. offset_in_page(IDX[k]);
  778. n = template[i].tap[k];
  779. if (k == template[i].np - 1)
  780. n += enc ? authsize : -authsize;
  781. if (memcmp(q, template[i].result + temp, n)) {
  782. pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
  783. d, j, e, k, algo);
  784. hexdump(q, n);
  785. goto out;
  786. }
  787. q += n;
  788. if (k == template[i].np - 1 && !enc) {
  789. if (!diff_dst &&
  790. memcmp(q, template[i].input +
  791. temp + n, authsize))
  792. n = authsize;
  793. else
  794. n = 0;
  795. } else {
  796. for (n = 0; offset_in_page(q + n) && q[n]; n++)
  797. ;
  798. }
  799. if (n) {
  800. pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
  801. d, j, e, k, algo, n);
  802. hexdump(q, n);
  803. goto out;
  804. }
  805. temp += template[i].tap[k];
  806. }
  807. }
  808. ret = 0;
  809. out:
  810. aead_request_free(req);
  811. kfree(sg);
  812. out_nosg:
  813. if (diff_dst)
  814. testmgr_free_buf(xoutbuf);
  815. out_nooutbuf:
  816. testmgr_free_buf(axbuf);
  817. out_noaxbuf:
  818. testmgr_free_buf(xbuf);
  819. out_noxbuf:
  820. kfree(key);
  821. kfree(iv);
  822. return ret;
  823. }
  824. static int test_aead(struct crypto_aead *tfm, int enc,
  825. const struct aead_testvec *template, unsigned int tcount)
  826. {
  827. unsigned int alignmask;
  828. int ret;
  829. /* test 'dst == src' case */
  830. ret = __test_aead(tfm, enc, template, tcount, false, 0);
  831. if (ret)
  832. return ret;
  833. /* test 'dst != src' case */
  834. ret = __test_aead(tfm, enc, template, tcount, true, 0);
  835. if (ret)
  836. return ret;
  837. /* test unaligned buffers, check with one byte offset */
  838. ret = __test_aead(tfm, enc, template, tcount, true, 1);
  839. if (ret)
  840. return ret;
  841. alignmask = crypto_tfm_alg_alignmask(&tfm->base);
  842. if (alignmask) {
  843. /* Check if alignment mask for tfm is correctly set. */
  844. ret = __test_aead(tfm, enc, template, tcount, true,
  845. alignmask + 1);
  846. if (ret)
  847. return ret;
  848. }
  849. return 0;
  850. }
  851. static int test_cipher(struct crypto_cipher *tfm, int enc,
  852. const struct cipher_testvec *template,
  853. unsigned int tcount)
  854. {
  855. const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
  856. unsigned int i, j, k;
  857. char *q;
  858. const char *e;
  859. void *data;
  860. char *xbuf[XBUFSIZE];
  861. int ret = -ENOMEM;
  862. if (testmgr_alloc_buf(xbuf))
  863. goto out_nobuf;
  864. if (enc == ENCRYPT)
  865. e = "encryption";
  866. else
  867. e = "decryption";
  868. j = 0;
  869. for (i = 0; i < tcount; i++) {
  870. if (template[i].np)
  871. continue;
  872. if (fips_enabled && template[i].fips_skip)
  873. continue;
  874. j++;
  875. ret = -EINVAL;
  876. if (WARN_ON(template[i].ilen > PAGE_SIZE))
  877. goto out;
  878. data = xbuf[0];
  879. memcpy(data, template[i].input, template[i].ilen);
  880. crypto_cipher_clear_flags(tfm, ~0);
  881. if (template[i].wk)
  882. crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  883. ret = crypto_cipher_setkey(tfm, template[i].key,
  884. template[i].klen);
  885. if (template[i].fail == !ret) {
  886. printk(KERN_ERR "alg: cipher: setkey failed "
  887. "on test %d for %s: flags=%x\n", j,
  888. algo, crypto_cipher_get_flags(tfm));
  889. goto out;
  890. } else if (ret)
  891. continue;
  892. for (k = 0; k < template[i].ilen;
  893. k += crypto_cipher_blocksize(tfm)) {
  894. if (enc)
  895. crypto_cipher_encrypt_one(tfm, data + k,
  896. data + k);
  897. else
  898. crypto_cipher_decrypt_one(tfm, data + k,
  899. data + k);
  900. }
  901. q = data;
  902. if (memcmp(q, template[i].result, template[i].rlen)) {
  903. printk(KERN_ERR "alg: cipher: Test %d failed "
  904. "on %s for %s\n", j, e, algo);
  905. hexdump(q, template[i].rlen);
  906. ret = -EINVAL;
  907. goto out;
  908. }
  909. }
  910. ret = 0;
  911. out:
  912. testmgr_free_buf(xbuf);
  913. out_nobuf:
  914. return ret;
  915. }
  916. static int __test_skcipher(struct crypto_skcipher *tfm, int enc,
  917. const struct cipher_testvec *template,
  918. unsigned int tcount,
  919. const bool diff_dst, const int align_offset)
  920. {
  921. const char *algo =
  922. crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm));
  923. unsigned int i, j, k, n, temp;
  924. char *q;
  925. struct skcipher_request *req;
  926. struct scatterlist sg[8];
  927. struct scatterlist sgout[8];
  928. const char *e, *d;
  929. struct crypto_wait wait;
  930. void *data;
  931. char iv[MAX_IVLEN];
  932. char *xbuf[XBUFSIZE];
  933. char *xoutbuf[XBUFSIZE];
  934. int ret = -ENOMEM;
  935. unsigned int ivsize = crypto_skcipher_ivsize(tfm);
  936. if (testmgr_alloc_buf(xbuf))
  937. goto out_nobuf;
  938. if (diff_dst && testmgr_alloc_buf(xoutbuf))
  939. goto out_nooutbuf;
  940. if (diff_dst)
  941. d = "-ddst";
  942. else
  943. d = "";
  944. if (enc == ENCRYPT)
  945. e = "encryption";
  946. else
  947. e = "decryption";
  948. crypto_init_wait(&wait);
  949. req = skcipher_request_alloc(tfm, GFP_KERNEL);
  950. if (!req) {
  951. pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
  952. d, algo);
  953. goto out;
  954. }
  955. skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  956. crypto_req_done, &wait);
  957. j = 0;
  958. for (i = 0; i < tcount; i++) {
  959. if (template[i].np && !template[i].also_non_np)
  960. continue;
  961. if (fips_enabled && template[i].fips_skip)
  962. continue;
  963. if (template[i].iv)
  964. memcpy(iv, template[i].iv, ivsize);
  965. else
  966. memset(iv, 0, MAX_IVLEN);
  967. j++;
  968. ret = -EINVAL;
  969. if (WARN_ON(align_offset + template[i].ilen > PAGE_SIZE))
  970. goto out;
  971. data = xbuf[0];
  972. data += align_offset;
  973. memcpy(data, template[i].input, template[i].ilen);
  974. crypto_skcipher_clear_flags(tfm, ~0);
  975. if (template[i].wk)
  976. crypto_skcipher_set_flags(tfm,
  977. CRYPTO_TFM_REQ_WEAK_KEY);
  978. ret = crypto_skcipher_setkey(tfm, template[i].key,
  979. template[i].klen);
  980. if (template[i].fail == !ret) {
  981. pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
  982. d, j, algo, crypto_skcipher_get_flags(tfm));
  983. goto out;
  984. } else if (ret)
  985. continue;
  986. sg_init_one(&sg[0], data, template[i].ilen);
  987. if (diff_dst) {
  988. data = xoutbuf[0];
  989. data += align_offset;
  990. sg_init_one(&sgout[0], data, template[i].ilen);
  991. }
  992. skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
  993. template[i].ilen, iv);
  994. ret = crypto_wait_req(enc ? crypto_skcipher_encrypt(req) :
  995. crypto_skcipher_decrypt(req), &wait);
  996. if (ret) {
  997. pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
  998. d, e, j, algo, -ret);
  999. goto out;
  1000. }
  1001. q = data;
  1002. if (memcmp(q, template[i].result, template[i].rlen)) {
  1003. pr_err("alg: skcipher%s: Test %d failed (invalid result) on %s for %s\n",
  1004. d, j, e, algo);
  1005. hexdump(q, template[i].rlen);
  1006. ret = -EINVAL;
  1007. goto out;
  1008. }
  1009. if (template[i].iv_out &&
  1010. memcmp(iv, template[i].iv_out,
  1011. crypto_skcipher_ivsize(tfm))) {
  1012. pr_err("alg: skcipher%s: Test %d failed (invalid output IV) on %s for %s\n",
  1013. d, j, e, algo);
  1014. hexdump(iv, crypto_skcipher_ivsize(tfm));
  1015. ret = -EINVAL;
  1016. goto out;
  1017. }
  1018. }
  1019. j = 0;
  1020. for (i = 0; i < tcount; i++) {
  1021. /* alignment tests are only done with continuous buffers */
  1022. if (align_offset != 0)
  1023. break;
  1024. if (!template[i].np)
  1025. continue;
  1026. if (fips_enabled && template[i].fips_skip)
  1027. continue;
  1028. if (template[i].iv)
  1029. memcpy(iv, template[i].iv, ivsize);
  1030. else
  1031. memset(iv, 0, MAX_IVLEN);
  1032. j++;
  1033. crypto_skcipher_clear_flags(tfm, ~0);
  1034. if (template[i].wk)
  1035. crypto_skcipher_set_flags(tfm,
  1036. CRYPTO_TFM_REQ_WEAK_KEY);
  1037. ret = crypto_skcipher_setkey(tfm, template[i].key,
  1038. template[i].klen);
  1039. if (template[i].fail == !ret) {
  1040. pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
  1041. d, j, algo, crypto_skcipher_get_flags(tfm));
  1042. goto out;
  1043. } else if (ret)
  1044. continue;
  1045. temp = 0;
  1046. ret = -EINVAL;
  1047. sg_init_table(sg, template[i].np);
  1048. if (diff_dst)
  1049. sg_init_table(sgout, template[i].np);
  1050. for (k = 0; k < template[i].np; k++) {
  1051. if (WARN_ON(offset_in_page(IDX[k]) +
  1052. template[i].tap[k] > PAGE_SIZE))
  1053. goto out;
  1054. q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
  1055. memcpy(q, template[i].input + temp, template[i].tap[k]);
  1056. if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
  1057. q[template[i].tap[k]] = 0;
  1058. sg_set_buf(&sg[k], q, template[i].tap[k]);
  1059. if (diff_dst) {
  1060. q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
  1061. offset_in_page(IDX[k]);
  1062. sg_set_buf(&sgout[k], q, template[i].tap[k]);
  1063. memset(q, 0, template[i].tap[k]);
  1064. if (offset_in_page(q) +
  1065. template[i].tap[k] < PAGE_SIZE)
  1066. q[template[i].tap[k]] = 0;
  1067. }
  1068. temp += template[i].tap[k];
  1069. }
  1070. skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
  1071. template[i].ilen, iv);
  1072. ret = crypto_wait_req(enc ? crypto_skcipher_encrypt(req) :
  1073. crypto_skcipher_decrypt(req), &wait);
  1074. if (ret) {
  1075. pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
  1076. d, e, j, algo, -ret);
  1077. goto out;
  1078. }
  1079. temp = 0;
  1080. ret = -EINVAL;
  1081. for (k = 0; k < template[i].np; k++) {
  1082. if (diff_dst)
  1083. q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
  1084. offset_in_page(IDX[k]);
  1085. else
  1086. q = xbuf[IDX[k] >> PAGE_SHIFT] +
  1087. offset_in_page(IDX[k]);
  1088. if (memcmp(q, template[i].result + temp,
  1089. template[i].tap[k])) {
  1090. pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
  1091. d, j, e, k, algo);
  1092. hexdump(q, template[i].tap[k]);
  1093. goto out;
  1094. }
  1095. q += template[i].tap[k];
  1096. for (n = 0; offset_in_page(q + n) && q[n]; n++)
  1097. ;
  1098. if (n) {
  1099. pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
  1100. d, j, e, k, algo, n);
  1101. hexdump(q, n);
  1102. goto out;
  1103. }
  1104. temp += template[i].tap[k];
  1105. }
  1106. }
  1107. ret = 0;
  1108. out:
  1109. skcipher_request_free(req);
  1110. if (diff_dst)
  1111. testmgr_free_buf(xoutbuf);
  1112. out_nooutbuf:
  1113. testmgr_free_buf(xbuf);
  1114. out_nobuf:
  1115. return ret;
  1116. }
  1117. static int test_skcipher(struct crypto_skcipher *tfm, int enc,
  1118. const struct cipher_testvec *template,
  1119. unsigned int tcount)
  1120. {
  1121. unsigned int alignmask;
  1122. int ret;
  1123. /* test 'dst == src' case */
  1124. ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
  1125. if (ret)
  1126. return ret;
  1127. /* test 'dst != src' case */
  1128. ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
  1129. if (ret)
  1130. return ret;
  1131. /* test unaligned buffers, check with one byte offset */
  1132. ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
  1133. if (ret)
  1134. return ret;
  1135. alignmask = crypto_tfm_alg_alignmask(&tfm->base);
  1136. if (alignmask) {
  1137. /* Check if alignment mask for tfm is correctly set. */
  1138. ret = __test_skcipher(tfm, enc, template, tcount, true,
  1139. alignmask + 1);
  1140. if (ret)
  1141. return ret;
  1142. }
  1143. return 0;
  1144. }
  1145. static int test_comp(struct crypto_comp *tfm,
  1146. const struct comp_testvec *ctemplate,
  1147. const struct comp_testvec *dtemplate,
  1148. int ctcount, int dtcount)
  1149. {
  1150. const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
  1151. char *output, *decomp_output;
  1152. unsigned int i;
  1153. int ret;
  1154. output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
  1155. if (!output)
  1156. return -ENOMEM;
  1157. decomp_output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
  1158. if (!decomp_output) {
  1159. kfree(output);
  1160. return -ENOMEM;
  1161. }
  1162. for (i = 0; i < ctcount; i++) {
  1163. int ilen;
  1164. unsigned int dlen = COMP_BUF_SIZE;
  1165. memset(output, 0, sizeof(COMP_BUF_SIZE));
  1166. memset(decomp_output, 0, sizeof(COMP_BUF_SIZE));
  1167. ilen = ctemplate[i].inlen;
  1168. ret = crypto_comp_compress(tfm, ctemplate[i].input,
  1169. ilen, output, &dlen);
  1170. if (ret) {
  1171. printk(KERN_ERR "alg: comp: compression failed "
  1172. "on test %d for %s: ret=%d\n", i + 1, algo,
  1173. -ret);
  1174. goto out;
  1175. }
  1176. ilen = dlen;
  1177. dlen = COMP_BUF_SIZE;
  1178. ret = crypto_comp_decompress(tfm, output,
  1179. ilen, decomp_output, &dlen);
  1180. if (ret) {
  1181. pr_err("alg: comp: compression failed: decompress: on test %d for %s failed: ret=%d\n",
  1182. i + 1, algo, -ret);
  1183. goto out;
  1184. }
  1185. if (dlen != ctemplate[i].inlen) {
  1186. printk(KERN_ERR "alg: comp: Compression test %d "
  1187. "failed for %s: output len = %d\n", i + 1, algo,
  1188. dlen);
  1189. ret = -EINVAL;
  1190. goto out;
  1191. }
  1192. if (memcmp(decomp_output, ctemplate[i].input,
  1193. ctemplate[i].inlen)) {
  1194. pr_err("alg: comp: compression failed: output differs: on test %d for %s\n",
  1195. i + 1, algo);
  1196. hexdump(decomp_output, dlen);
  1197. ret = -EINVAL;
  1198. goto out;
  1199. }
  1200. }
  1201. for (i = 0; i < dtcount; i++) {
  1202. int ilen;
  1203. unsigned int dlen = COMP_BUF_SIZE;
  1204. memset(decomp_output, 0, sizeof(COMP_BUF_SIZE));
  1205. ilen = dtemplate[i].inlen;
  1206. ret = crypto_comp_decompress(tfm, dtemplate[i].input,
  1207. ilen, decomp_output, &dlen);
  1208. if (ret) {
  1209. printk(KERN_ERR "alg: comp: decompression failed "
  1210. "on test %d for %s: ret=%d\n", i + 1, algo,
  1211. -ret);
  1212. goto out;
  1213. }
  1214. if (dlen != dtemplate[i].outlen) {
  1215. printk(KERN_ERR "alg: comp: Decompression test %d "
  1216. "failed for %s: output len = %d\n", i + 1, algo,
  1217. dlen);
  1218. ret = -EINVAL;
  1219. goto out;
  1220. }
  1221. if (memcmp(decomp_output, dtemplate[i].output, dlen)) {
  1222. printk(KERN_ERR "alg: comp: Decompression test %d "
  1223. "failed for %s\n", i + 1, algo);
  1224. hexdump(decomp_output, dlen);
  1225. ret = -EINVAL;
  1226. goto out;
  1227. }
  1228. }
  1229. ret = 0;
  1230. out:
  1231. kfree(decomp_output);
  1232. kfree(output);
  1233. return ret;
  1234. }
  1235. static int test_acomp(struct crypto_acomp *tfm,
  1236. const struct comp_testvec *ctemplate,
  1237. const struct comp_testvec *dtemplate,
  1238. int ctcount, int dtcount)
  1239. {
  1240. const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm));
  1241. unsigned int i;
  1242. char *output, *decomp_out;
  1243. int ret;
  1244. struct scatterlist src, dst;
  1245. struct acomp_req *req;
  1246. struct crypto_wait wait;
  1247. output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
  1248. if (!output)
  1249. return -ENOMEM;
  1250. decomp_out = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
  1251. if (!decomp_out) {
  1252. kfree(output);
  1253. return -ENOMEM;
  1254. }
  1255. for (i = 0; i < ctcount; i++) {
  1256. unsigned int dlen = COMP_BUF_SIZE;
  1257. int ilen = ctemplate[i].inlen;
  1258. void *input_vec;
  1259. input_vec = kmemdup(ctemplate[i].input, ilen, GFP_KERNEL);
  1260. if (!input_vec) {
  1261. ret = -ENOMEM;
  1262. goto out;
  1263. }
  1264. memset(output, 0, dlen);
  1265. crypto_init_wait(&wait);
  1266. sg_init_one(&src, input_vec, ilen);
  1267. sg_init_one(&dst, output, dlen);
  1268. req = acomp_request_alloc(tfm);
  1269. if (!req) {
  1270. pr_err("alg: acomp: request alloc failed for %s\n",
  1271. algo);
  1272. kfree(input_vec);
  1273. ret = -ENOMEM;
  1274. goto out;
  1275. }
  1276. acomp_request_set_params(req, &src, &dst, ilen, dlen);
  1277. acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  1278. crypto_req_done, &wait);
  1279. ret = crypto_wait_req(crypto_acomp_compress(req), &wait);
  1280. if (ret) {
  1281. pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
  1282. i + 1, algo, -ret);
  1283. kfree(input_vec);
  1284. acomp_request_free(req);
  1285. goto out;
  1286. }
  1287. ilen = req->dlen;
  1288. dlen = COMP_BUF_SIZE;
  1289. sg_init_one(&src, output, ilen);
  1290. sg_init_one(&dst, decomp_out, dlen);
  1291. crypto_init_wait(&wait);
  1292. acomp_request_set_params(req, &src, &dst, ilen, dlen);
  1293. ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
  1294. if (ret) {
  1295. pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
  1296. i + 1, algo, -ret);
  1297. kfree(input_vec);
  1298. acomp_request_free(req);
  1299. goto out;
  1300. }
  1301. if (req->dlen != ctemplate[i].inlen) {
  1302. pr_err("alg: acomp: Compression test %d failed for %s: output len = %d\n",
  1303. i + 1, algo, req->dlen);
  1304. ret = -EINVAL;
  1305. kfree(input_vec);
  1306. acomp_request_free(req);
  1307. goto out;
  1308. }
  1309. if (memcmp(input_vec, decomp_out, req->dlen)) {
  1310. pr_err("alg: acomp: Compression test %d failed for %s\n",
  1311. i + 1, algo);
  1312. hexdump(output, req->dlen);
  1313. ret = -EINVAL;
  1314. kfree(input_vec);
  1315. acomp_request_free(req);
  1316. goto out;
  1317. }
  1318. kfree(input_vec);
  1319. acomp_request_free(req);
  1320. }
  1321. for (i = 0; i < dtcount; i++) {
  1322. unsigned int dlen = COMP_BUF_SIZE;
  1323. int ilen = dtemplate[i].inlen;
  1324. void *input_vec;
  1325. input_vec = kmemdup(dtemplate[i].input, ilen, GFP_KERNEL);
  1326. if (!input_vec) {
  1327. ret = -ENOMEM;
  1328. goto out;
  1329. }
  1330. memset(output, 0, dlen);
  1331. crypto_init_wait(&wait);
  1332. sg_init_one(&src, input_vec, ilen);
  1333. sg_init_one(&dst, output, dlen);
  1334. req = acomp_request_alloc(tfm);
  1335. if (!req) {
  1336. pr_err("alg: acomp: request alloc failed for %s\n",
  1337. algo);
  1338. kfree(input_vec);
  1339. ret = -ENOMEM;
  1340. goto out;
  1341. }
  1342. acomp_request_set_params(req, &src, &dst, ilen, dlen);
  1343. acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  1344. crypto_req_done, &wait);
  1345. ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
  1346. if (ret) {
  1347. pr_err("alg: acomp: decompression failed on test %d for %s: ret=%d\n",
  1348. i + 1, algo, -ret);
  1349. kfree(input_vec);
  1350. acomp_request_free(req);
  1351. goto out;
  1352. }
  1353. if (req->dlen != dtemplate[i].outlen) {
  1354. pr_err("alg: acomp: Decompression test %d failed for %s: output len = %d\n",
  1355. i + 1, algo, req->dlen);
  1356. ret = -EINVAL;
  1357. kfree(input_vec);
  1358. acomp_request_free(req);
  1359. goto out;
  1360. }
  1361. if (memcmp(output, dtemplate[i].output, req->dlen)) {
  1362. pr_err("alg: acomp: Decompression test %d failed for %s\n",
  1363. i + 1, algo);
  1364. hexdump(output, req->dlen);
  1365. ret = -EINVAL;
  1366. kfree(input_vec);
  1367. acomp_request_free(req);
  1368. goto out;
  1369. }
  1370. kfree(input_vec);
  1371. acomp_request_free(req);
  1372. }
  1373. ret = 0;
  1374. out:
  1375. kfree(decomp_out);
  1376. kfree(output);
  1377. return ret;
  1378. }
  1379. static int test_cprng(struct crypto_rng *tfm,
  1380. const struct cprng_testvec *template,
  1381. unsigned int tcount)
  1382. {
  1383. const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
  1384. int err = 0, i, j, seedsize;
  1385. u8 *seed;
  1386. char result[32];
  1387. seedsize = crypto_rng_seedsize(tfm);
  1388. seed = kmalloc(seedsize, GFP_KERNEL);
  1389. if (!seed) {
  1390. printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
  1391. "for %s\n", algo);
  1392. return -ENOMEM;
  1393. }
  1394. for (i = 0; i < tcount; i++) {
  1395. memset(result, 0, 32);
  1396. memcpy(seed, template[i].v, template[i].vlen);
  1397. memcpy(seed + template[i].vlen, template[i].key,
  1398. template[i].klen);
  1399. memcpy(seed + template[i].vlen + template[i].klen,
  1400. template[i].dt, template[i].dtlen);
  1401. err = crypto_rng_reset(tfm, seed, seedsize);
  1402. if (err) {
  1403. printk(KERN_ERR "alg: cprng: Failed to reset rng "
  1404. "for %s\n", algo);
  1405. goto out;
  1406. }
  1407. for (j = 0; j < template[i].loops; j++) {
  1408. err = crypto_rng_get_bytes(tfm, result,
  1409. template[i].rlen);
  1410. if (err < 0) {
  1411. printk(KERN_ERR "alg: cprng: Failed to obtain "
  1412. "the correct amount of random data for "
  1413. "%s (requested %d)\n", algo,
  1414. template[i].rlen);
  1415. goto out;
  1416. }
  1417. }
  1418. err = memcmp(result, template[i].result,
  1419. template[i].rlen);
  1420. if (err) {
  1421. printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
  1422. i, algo);
  1423. hexdump(result, template[i].rlen);
  1424. err = -EINVAL;
  1425. goto out;
  1426. }
  1427. }
  1428. out:
  1429. kfree(seed);
  1430. return err;
  1431. }
  1432. static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
  1433. u32 type, u32 mask)
  1434. {
  1435. struct crypto_aead *tfm;
  1436. int err = 0;
  1437. tfm = crypto_alloc_aead(driver, type, mask);
  1438. if (IS_ERR(tfm)) {
  1439. printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
  1440. "%ld\n", driver, PTR_ERR(tfm));
  1441. return PTR_ERR(tfm);
  1442. }
  1443. if (desc->suite.aead.enc.vecs) {
  1444. err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
  1445. desc->suite.aead.enc.count);
  1446. if (err)
  1447. goto out;
  1448. }
  1449. if (!err && desc->suite.aead.dec.vecs)
  1450. err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
  1451. desc->suite.aead.dec.count);
  1452. out:
  1453. crypto_free_aead(tfm);
  1454. return err;
  1455. }
  1456. static int alg_test_cipher(const struct alg_test_desc *desc,
  1457. const char *driver, u32 type, u32 mask)
  1458. {
  1459. struct crypto_cipher *tfm;
  1460. int err = 0;
  1461. tfm = crypto_alloc_cipher(driver, type, mask);
  1462. if (IS_ERR(tfm)) {
  1463. printk(KERN_ERR "alg: cipher: Failed to load transform for "
  1464. "%s: %ld\n", driver, PTR_ERR(tfm));
  1465. return PTR_ERR(tfm);
  1466. }
  1467. if (desc->suite.cipher.enc.vecs) {
  1468. err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
  1469. desc->suite.cipher.enc.count);
  1470. if (err)
  1471. goto out;
  1472. }
  1473. if (desc->suite.cipher.dec.vecs)
  1474. err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
  1475. desc->suite.cipher.dec.count);
  1476. out:
  1477. crypto_free_cipher(tfm);
  1478. return err;
  1479. }
  1480. static int alg_test_skcipher(const struct alg_test_desc *desc,
  1481. const char *driver, u32 type, u32 mask)
  1482. {
  1483. struct crypto_skcipher *tfm;
  1484. int err = 0;
  1485. tfm = crypto_alloc_skcipher(driver, type, mask);
  1486. if (IS_ERR(tfm)) {
  1487. printk(KERN_ERR "alg: skcipher: Failed to load transform for "
  1488. "%s: %ld\n", driver, PTR_ERR(tfm));
  1489. return PTR_ERR(tfm);
  1490. }
  1491. if (desc->suite.cipher.enc.vecs) {
  1492. err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
  1493. desc->suite.cipher.enc.count);
  1494. if (err)
  1495. goto out;
  1496. }
  1497. if (desc->suite.cipher.dec.vecs)
  1498. err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
  1499. desc->suite.cipher.dec.count);
  1500. out:
  1501. crypto_free_skcipher(tfm);
  1502. return err;
  1503. }
  1504. static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
  1505. u32 type, u32 mask)
  1506. {
  1507. struct crypto_comp *comp;
  1508. struct crypto_acomp *acomp;
  1509. int err;
  1510. u32 algo_type = type & CRYPTO_ALG_TYPE_ACOMPRESS_MASK;
  1511. if (algo_type == CRYPTO_ALG_TYPE_ACOMPRESS) {
  1512. acomp = crypto_alloc_acomp(driver, type, mask);
  1513. if (IS_ERR(acomp)) {
  1514. pr_err("alg: acomp: Failed to load transform for %s: %ld\n",
  1515. driver, PTR_ERR(acomp));
  1516. return PTR_ERR(acomp);
  1517. }
  1518. err = test_acomp(acomp, desc->suite.comp.comp.vecs,
  1519. desc->suite.comp.decomp.vecs,
  1520. desc->suite.comp.comp.count,
  1521. desc->suite.comp.decomp.count);
  1522. crypto_free_acomp(acomp);
  1523. } else {
  1524. comp = crypto_alloc_comp(driver, type, mask);
  1525. if (IS_ERR(comp)) {
  1526. pr_err("alg: comp: Failed to load transform for %s: %ld\n",
  1527. driver, PTR_ERR(comp));
  1528. return PTR_ERR(comp);
  1529. }
  1530. err = test_comp(comp, desc->suite.comp.comp.vecs,
  1531. desc->suite.comp.decomp.vecs,
  1532. desc->suite.comp.comp.count,
  1533. desc->suite.comp.decomp.count);
  1534. crypto_free_comp(comp);
  1535. }
  1536. return err;
  1537. }
  1538. static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
  1539. u32 type, u32 mask)
  1540. {
  1541. struct crypto_ahash *tfm;
  1542. int err;
  1543. tfm = crypto_alloc_ahash(driver, type, mask);
  1544. if (IS_ERR(tfm)) {
  1545. printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
  1546. "%ld\n", driver, PTR_ERR(tfm));
  1547. return PTR_ERR(tfm);
  1548. }
  1549. err = test_hash(tfm, desc->suite.hash.vecs,
  1550. desc->suite.hash.count, true);
  1551. if (!err)
  1552. err = test_hash(tfm, desc->suite.hash.vecs,
  1553. desc->suite.hash.count, false);
  1554. crypto_free_ahash(tfm);
  1555. return err;
  1556. }
  1557. static int alg_test_crc32c(const struct alg_test_desc *desc,
  1558. const char *driver, u32 type, u32 mask)
  1559. {
  1560. struct crypto_shash *tfm;
  1561. u32 val;
  1562. int err;
  1563. err = alg_test_hash(desc, driver, type, mask);
  1564. if (err)
  1565. goto out;
  1566. tfm = crypto_alloc_shash(driver, type, mask);
  1567. if (IS_ERR(tfm)) {
  1568. printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
  1569. "%ld\n", driver, PTR_ERR(tfm));
  1570. err = PTR_ERR(tfm);
  1571. goto out;
  1572. }
  1573. do {
  1574. SHASH_DESC_ON_STACK(shash, tfm);
  1575. u32 *ctx = (u32 *)shash_desc_ctx(shash);
  1576. shash->tfm = tfm;
  1577. shash->flags = 0;
  1578. *ctx = le32_to_cpu(420553207);
  1579. err = crypto_shash_final(shash, (u8 *)&val);
  1580. if (err) {
  1581. printk(KERN_ERR "alg: crc32c: Operation failed for "
  1582. "%s: %d\n", driver, err);
  1583. break;
  1584. }
  1585. if (val != ~420553207) {
  1586. printk(KERN_ERR "alg: crc32c: Test failed for %s: "
  1587. "%d\n", driver, val);
  1588. err = -EINVAL;
  1589. }
  1590. } while (0);
  1591. crypto_free_shash(tfm);
  1592. out:
  1593. return err;
  1594. }
  1595. static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
  1596. u32 type, u32 mask)
  1597. {
  1598. struct crypto_rng *rng;
  1599. int err;
  1600. rng = crypto_alloc_rng(driver, type, mask);
  1601. if (IS_ERR(rng)) {
  1602. printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
  1603. "%ld\n", driver, PTR_ERR(rng));
  1604. return PTR_ERR(rng);
  1605. }
  1606. err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
  1607. crypto_free_rng(rng);
  1608. return err;
  1609. }
  1610. static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
  1611. const char *driver, u32 type, u32 mask)
  1612. {
  1613. int ret = -EAGAIN;
  1614. struct crypto_rng *drng;
  1615. struct drbg_test_data test_data;
  1616. struct drbg_string addtl, pers, testentropy;
  1617. unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
  1618. if (!buf)
  1619. return -ENOMEM;
  1620. drng = crypto_alloc_rng(driver, type, mask);
  1621. if (IS_ERR(drng)) {
  1622. printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
  1623. "%s\n", driver);
  1624. kzfree(buf);
  1625. return -ENOMEM;
  1626. }
  1627. test_data.testentropy = &testentropy;
  1628. drbg_string_fill(&testentropy, test->entropy, test->entropylen);
  1629. drbg_string_fill(&pers, test->pers, test->perslen);
  1630. ret = crypto_drbg_reset_test(drng, &pers, &test_data);
  1631. if (ret) {
  1632. printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
  1633. goto outbuf;
  1634. }
  1635. drbg_string_fill(&addtl, test->addtla, test->addtllen);
  1636. if (pr) {
  1637. drbg_string_fill(&testentropy, test->entpra, test->entprlen);
  1638. ret = crypto_drbg_get_bytes_addtl_test(drng,
  1639. buf, test->expectedlen, &addtl, &test_data);
  1640. } else {
  1641. ret = crypto_drbg_get_bytes_addtl(drng,
  1642. buf, test->expectedlen, &addtl);
  1643. }
  1644. if (ret < 0) {
  1645. printk(KERN_ERR "alg: drbg: could not obtain random data for "
  1646. "driver %s\n", driver);
  1647. goto outbuf;
  1648. }
  1649. drbg_string_fill(&addtl, test->addtlb, test->addtllen);
  1650. if (pr) {
  1651. drbg_string_fill(&testentropy, test->entprb, test->entprlen);
  1652. ret = crypto_drbg_get_bytes_addtl_test(drng,
  1653. buf, test->expectedlen, &addtl, &test_data);
  1654. } else {
  1655. ret = crypto_drbg_get_bytes_addtl(drng,
  1656. buf, test->expectedlen, &addtl);
  1657. }
  1658. if (ret < 0) {
  1659. printk(KERN_ERR "alg: drbg: could not obtain random data for "
  1660. "driver %s\n", driver);
  1661. goto outbuf;
  1662. }
  1663. ret = memcmp(test->expected, buf, test->expectedlen);
  1664. outbuf:
  1665. crypto_free_rng(drng);
  1666. kzfree(buf);
  1667. return ret;
  1668. }
  1669. static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
  1670. u32 type, u32 mask)
  1671. {
  1672. int err = 0;
  1673. int pr = 0;
  1674. int i = 0;
  1675. const struct drbg_testvec *template = desc->suite.drbg.vecs;
  1676. unsigned int tcount = desc->suite.drbg.count;
  1677. if (0 == memcmp(driver, "drbg_pr_", 8))
  1678. pr = 1;
  1679. for (i = 0; i < tcount; i++) {
  1680. err = drbg_cavs_test(&template[i], pr, driver, type, mask);
  1681. if (err) {
  1682. printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
  1683. i, driver);
  1684. err = -EINVAL;
  1685. break;
  1686. }
  1687. }
  1688. return err;
  1689. }
  1690. static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec,
  1691. const char *alg)
  1692. {
  1693. struct kpp_request *req;
  1694. void *input_buf = NULL;
  1695. void *output_buf = NULL;
  1696. void *a_public = NULL;
  1697. void *a_ss = NULL;
  1698. void *shared_secret = NULL;
  1699. struct crypto_wait wait;
  1700. unsigned int out_len_max;
  1701. int err = -ENOMEM;
  1702. struct scatterlist src, dst;
  1703. req = kpp_request_alloc(tfm, GFP_KERNEL);
  1704. if (!req)
  1705. return err;
  1706. crypto_init_wait(&wait);
  1707. err = crypto_kpp_set_secret(tfm, vec->secret, vec->secret_size);
  1708. if (err < 0)
  1709. goto free_req;
  1710. out_len_max = crypto_kpp_maxsize(tfm);
  1711. output_buf = kzalloc(out_len_max, GFP_KERNEL);
  1712. if (!output_buf) {
  1713. err = -ENOMEM;
  1714. goto free_req;
  1715. }
  1716. /* Use appropriate parameter as base */
  1717. kpp_request_set_input(req, NULL, 0);
  1718. sg_init_one(&dst, output_buf, out_len_max);
  1719. kpp_request_set_output(req, &dst, out_len_max);
  1720. kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  1721. crypto_req_done, &wait);
  1722. /* Compute party A's public key */
  1723. err = crypto_wait_req(crypto_kpp_generate_public_key(req), &wait);
  1724. if (err) {
  1725. pr_err("alg: %s: Party A: generate public key test failed. err %d\n",
  1726. alg, err);
  1727. goto free_output;
  1728. }
  1729. if (vec->genkey) {
  1730. /* Save party A's public key */
  1731. a_public = kzalloc(out_len_max, GFP_KERNEL);
  1732. if (!a_public) {
  1733. err = -ENOMEM;
  1734. goto free_output;
  1735. }
  1736. memcpy(a_public, sg_virt(req->dst), out_len_max);
  1737. } else {
  1738. /* Verify calculated public key */
  1739. if (memcmp(vec->expected_a_public, sg_virt(req->dst),
  1740. vec->expected_a_public_size)) {
  1741. pr_err("alg: %s: Party A: generate public key test failed. Invalid output\n",
  1742. alg);
  1743. err = -EINVAL;
  1744. goto free_output;
  1745. }
  1746. }
  1747. /* Calculate shared secret key by using counter part (b) public key. */
  1748. input_buf = kzalloc(vec->b_public_size, GFP_KERNEL);
  1749. if (!input_buf) {
  1750. err = -ENOMEM;
  1751. goto free_output;
  1752. }
  1753. memcpy(input_buf, vec->b_public, vec->b_public_size);
  1754. sg_init_one(&src, input_buf, vec->b_public_size);
  1755. sg_init_one(&dst, output_buf, out_len_max);
  1756. kpp_request_set_input(req, &src, vec->b_public_size);
  1757. kpp_request_set_output(req, &dst, out_len_max);
  1758. kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  1759. crypto_req_done, &wait);
  1760. err = crypto_wait_req(crypto_kpp_compute_shared_secret(req), &wait);
  1761. if (err) {
  1762. pr_err("alg: %s: Party A: compute shared secret test failed. err %d\n",
  1763. alg, err);
  1764. goto free_all;
  1765. }
  1766. if (vec->genkey) {
  1767. /* Save the shared secret obtained by party A */
  1768. a_ss = kzalloc(vec->expected_ss_size, GFP_KERNEL);
  1769. if (!a_ss) {
  1770. err = -ENOMEM;
  1771. goto free_all;
  1772. }
  1773. memcpy(a_ss, sg_virt(req->dst), vec->expected_ss_size);
  1774. /*
  1775. * Calculate party B's shared secret by using party A's
  1776. * public key.
  1777. */
  1778. err = crypto_kpp_set_secret(tfm, vec->b_secret,
  1779. vec->b_secret_size);
  1780. if (err < 0)
  1781. goto free_all;
  1782. sg_init_one(&src, a_public, vec->expected_a_public_size);
  1783. sg_init_one(&dst, output_buf, out_len_max);
  1784. kpp_request_set_input(req, &src, vec->expected_a_public_size);
  1785. kpp_request_set_output(req, &dst, out_len_max);
  1786. kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  1787. crypto_req_done, &wait);
  1788. err = crypto_wait_req(crypto_kpp_compute_shared_secret(req),
  1789. &wait);
  1790. if (err) {
  1791. pr_err("alg: %s: Party B: compute shared secret failed. err %d\n",
  1792. alg, err);
  1793. goto free_all;
  1794. }
  1795. shared_secret = a_ss;
  1796. } else {
  1797. shared_secret = (void *)vec->expected_ss;
  1798. }
  1799. /*
  1800. * verify shared secret from which the user will derive
  1801. * secret key by executing whatever hash it has chosen
  1802. */
  1803. if (memcmp(shared_secret, sg_virt(req->dst),
  1804. vec->expected_ss_size)) {
  1805. pr_err("alg: %s: compute shared secret test failed. Invalid output\n",
  1806. alg);
  1807. err = -EINVAL;
  1808. }
  1809. free_all:
  1810. kfree(a_ss);
  1811. kfree(input_buf);
  1812. free_output:
  1813. kfree(a_public);
  1814. kfree(output_buf);
  1815. free_req:
  1816. kpp_request_free(req);
  1817. return err;
  1818. }
  1819. static int test_kpp(struct crypto_kpp *tfm, const char *alg,
  1820. const struct kpp_testvec *vecs, unsigned int tcount)
  1821. {
  1822. int ret, i;
  1823. for (i = 0; i < tcount; i++) {
  1824. ret = do_test_kpp(tfm, vecs++, alg);
  1825. if (ret) {
  1826. pr_err("alg: %s: test failed on vector %d, err=%d\n",
  1827. alg, i + 1, ret);
  1828. return ret;
  1829. }
  1830. }
  1831. return 0;
  1832. }
  1833. static int alg_test_kpp(const struct alg_test_desc *desc, const char *driver,
  1834. u32 type, u32 mask)
  1835. {
  1836. struct crypto_kpp *tfm;
  1837. int err = 0;
  1838. tfm = crypto_alloc_kpp(driver, type, mask);
  1839. if (IS_ERR(tfm)) {
  1840. pr_err("alg: kpp: Failed to load tfm for %s: %ld\n",
  1841. driver, PTR_ERR(tfm));
  1842. return PTR_ERR(tfm);
  1843. }
  1844. if (desc->suite.kpp.vecs)
  1845. err = test_kpp(tfm, desc->alg, desc->suite.kpp.vecs,
  1846. desc->suite.kpp.count);
  1847. crypto_free_kpp(tfm);
  1848. return err;
  1849. }
  1850. static int test_akcipher_one(struct crypto_akcipher *tfm,
  1851. const struct akcipher_testvec *vecs)
  1852. {
  1853. char *xbuf[XBUFSIZE];
  1854. struct akcipher_request *req;
  1855. void *outbuf_enc = NULL;
  1856. void *outbuf_dec = NULL;
  1857. struct crypto_wait wait;
  1858. unsigned int out_len_max, out_len = 0;
  1859. int err = -ENOMEM;
  1860. struct scatterlist src, dst, src_tab[2];
  1861. if (testmgr_alloc_buf(xbuf))
  1862. return err;
  1863. req = akcipher_request_alloc(tfm, GFP_KERNEL);
  1864. if (!req)
  1865. goto free_xbuf;
  1866. crypto_init_wait(&wait);
  1867. if (vecs->public_key_vec)
  1868. err = crypto_akcipher_set_pub_key(tfm, vecs->key,
  1869. vecs->key_len);
  1870. else
  1871. err = crypto_akcipher_set_priv_key(tfm, vecs->key,
  1872. vecs->key_len);
  1873. if (err)
  1874. goto free_req;
  1875. err = -ENOMEM;
  1876. out_len_max = crypto_akcipher_maxsize(tfm);
  1877. outbuf_enc = kzalloc(out_len_max, GFP_KERNEL);
  1878. if (!outbuf_enc)
  1879. goto free_req;
  1880. if (WARN_ON(vecs->m_size > PAGE_SIZE))
  1881. goto free_all;
  1882. memcpy(xbuf[0], vecs->m, vecs->m_size);
  1883. sg_init_table(src_tab, 2);
  1884. sg_set_buf(&src_tab[0], xbuf[0], 8);
  1885. sg_set_buf(&src_tab[1], xbuf[0] + 8, vecs->m_size - 8);
  1886. sg_init_one(&dst, outbuf_enc, out_len_max);
  1887. akcipher_request_set_crypt(req, src_tab, &dst, vecs->m_size,
  1888. out_len_max);
  1889. akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  1890. crypto_req_done, &wait);
  1891. err = crypto_wait_req(vecs->siggen_sigver_test ?
  1892. /* Run asymmetric signature generation */
  1893. crypto_akcipher_sign(req) :
  1894. /* Run asymmetric encrypt */
  1895. crypto_akcipher_encrypt(req), &wait);
  1896. if (err) {
  1897. pr_err("alg: akcipher: encrypt test failed. err %d\n", err);
  1898. goto free_all;
  1899. }
  1900. if (req->dst_len != vecs->c_size) {
  1901. pr_err("alg: akcipher: encrypt test failed. Invalid output len\n");
  1902. err = -EINVAL;
  1903. goto free_all;
  1904. }
  1905. /* verify that encrypted message is equal to expected */
  1906. if (memcmp(vecs->c, outbuf_enc, vecs->c_size)) {
  1907. pr_err("alg: akcipher: encrypt test failed. Invalid output\n");
  1908. hexdump(outbuf_enc, vecs->c_size);
  1909. err = -EINVAL;
  1910. goto free_all;
  1911. }
  1912. /* Don't invoke decrypt for vectors with public key */
  1913. if (vecs->public_key_vec) {
  1914. err = 0;
  1915. goto free_all;
  1916. }
  1917. outbuf_dec = kzalloc(out_len_max, GFP_KERNEL);
  1918. if (!outbuf_dec) {
  1919. err = -ENOMEM;
  1920. goto free_all;
  1921. }
  1922. if (WARN_ON(vecs->c_size > PAGE_SIZE))
  1923. goto free_all;
  1924. memcpy(xbuf[0], vecs->c, vecs->c_size);
  1925. sg_init_one(&src, xbuf[0], vecs->c_size);
  1926. sg_init_one(&dst, outbuf_dec, out_len_max);
  1927. crypto_init_wait(&wait);
  1928. akcipher_request_set_crypt(req, &src, &dst, vecs->c_size, out_len_max);
  1929. err = crypto_wait_req(vecs->siggen_sigver_test ?
  1930. /* Run asymmetric signature verification */
  1931. crypto_akcipher_verify(req) :
  1932. /* Run asymmetric decrypt */
  1933. crypto_akcipher_decrypt(req), &wait);
  1934. if (err) {
  1935. pr_err("alg: akcipher: decrypt test failed. err %d\n", err);
  1936. goto free_all;
  1937. }
  1938. out_len = req->dst_len;
  1939. if (out_len < vecs->m_size) {
  1940. pr_err("alg: akcipher: decrypt test failed. "
  1941. "Invalid output len %u\n", out_len);
  1942. err = -EINVAL;
  1943. goto free_all;
  1944. }
  1945. /* verify that decrypted message is equal to the original msg */
  1946. if (memchr_inv(outbuf_dec, 0, out_len - vecs->m_size) ||
  1947. memcmp(vecs->m, outbuf_dec + out_len - vecs->m_size,
  1948. vecs->m_size)) {
  1949. pr_err("alg: akcipher: decrypt test failed. Invalid output\n");
  1950. hexdump(outbuf_dec, out_len);
  1951. err = -EINVAL;
  1952. }
  1953. free_all:
  1954. kfree(outbuf_dec);
  1955. kfree(outbuf_enc);
  1956. free_req:
  1957. akcipher_request_free(req);
  1958. free_xbuf:
  1959. testmgr_free_buf(xbuf);
  1960. return err;
  1961. }
  1962. static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
  1963. const struct akcipher_testvec *vecs,
  1964. unsigned int tcount)
  1965. {
  1966. const char *algo =
  1967. crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm));
  1968. int ret, i;
  1969. for (i = 0; i < tcount; i++) {
  1970. ret = test_akcipher_one(tfm, vecs++);
  1971. if (!ret)
  1972. continue;
  1973. pr_err("alg: akcipher: test %d failed for %s, err=%d\n",
  1974. i + 1, algo, ret);
  1975. return ret;
  1976. }
  1977. return 0;
  1978. }
  1979. static int alg_test_akcipher(const struct alg_test_desc *desc,
  1980. const char *driver, u32 type, u32 mask)
  1981. {
  1982. struct crypto_akcipher *tfm;
  1983. int err = 0;
  1984. tfm = crypto_alloc_akcipher(driver, type, mask);
  1985. if (IS_ERR(tfm)) {
  1986. pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
  1987. driver, PTR_ERR(tfm));
  1988. return PTR_ERR(tfm);
  1989. }
  1990. if (desc->suite.akcipher.vecs)
  1991. err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs,
  1992. desc->suite.akcipher.count);
  1993. crypto_free_akcipher(tfm);
  1994. return err;
  1995. }
  1996. static int alg_test_null(const struct alg_test_desc *desc,
  1997. const char *driver, u32 type, u32 mask)
  1998. {
  1999. return 0;
  2000. }
  2001. #define __VECS(tv) { .vecs = tv, .count = ARRAY_SIZE(tv) }
  2002. /* Please keep this list sorted by algorithm name. */
  2003. static const struct alg_test_desc alg_test_descs[] = {
  2004. {
  2005. .alg = "aegis128",
  2006. .test = alg_test_aead,
  2007. .suite = {
  2008. .aead = {
  2009. .enc = __VECS(aegis128_enc_tv_template),
  2010. .dec = __VECS(aegis128_dec_tv_template),
  2011. }
  2012. }
  2013. }, {
  2014. .alg = "aegis128l",
  2015. .test = alg_test_aead,
  2016. .suite = {
  2017. .aead = {
  2018. .enc = __VECS(aegis128l_enc_tv_template),
  2019. .dec = __VECS(aegis128l_dec_tv_template),
  2020. }
  2021. }
  2022. }, {
  2023. .alg = "aegis256",
  2024. .test = alg_test_aead,
  2025. .suite = {
  2026. .aead = {
  2027. .enc = __VECS(aegis256_enc_tv_template),
  2028. .dec = __VECS(aegis256_dec_tv_template),
  2029. }
  2030. }
  2031. }, {
  2032. .alg = "ansi_cprng",
  2033. .test = alg_test_cprng,
  2034. .suite = {
  2035. .cprng = __VECS(ansi_cprng_aes_tv_template)
  2036. }
  2037. }, {
  2038. .alg = "authenc(hmac(md5),ecb(cipher_null))",
  2039. .test = alg_test_aead,
  2040. .suite = {
  2041. .aead = {
  2042. .enc = __VECS(hmac_md5_ecb_cipher_null_enc_tv_template),
  2043. .dec = __VECS(hmac_md5_ecb_cipher_null_dec_tv_template)
  2044. }
  2045. }
  2046. }, {
  2047. .alg = "authenc(hmac(sha1),cbc(aes))",
  2048. .test = alg_test_aead,
  2049. .fips_allowed = 1,
  2050. .suite = {
  2051. .aead = {
  2052. .enc = __VECS(hmac_sha1_aes_cbc_enc_tv_temp)
  2053. }
  2054. }
  2055. }, {
  2056. .alg = "authenc(hmac(sha1),cbc(des))",
  2057. .test = alg_test_aead,
  2058. .suite = {
  2059. .aead = {
  2060. .enc = __VECS(hmac_sha1_des_cbc_enc_tv_temp)
  2061. }
  2062. }
  2063. }, {
  2064. .alg = "authenc(hmac(sha1),cbc(des3_ede))",
  2065. .test = alg_test_aead,
  2066. .fips_allowed = 1,
  2067. .suite = {
  2068. .aead = {
  2069. .enc = __VECS(hmac_sha1_des3_ede_cbc_enc_tv_temp)
  2070. }
  2071. }
  2072. }, {
  2073. .alg = "authenc(hmac(sha1),ctr(aes))",
  2074. .test = alg_test_null,
  2075. .fips_allowed = 1,
  2076. }, {
  2077. .alg = "authenc(hmac(sha1),ecb(cipher_null))",
  2078. .test = alg_test_aead,
  2079. .suite = {
  2080. .aead = {
  2081. .enc = __VECS(hmac_sha1_ecb_cipher_null_enc_tv_temp),
  2082. .dec = __VECS(hmac_sha1_ecb_cipher_null_dec_tv_temp)
  2083. }
  2084. }
  2085. }, {
  2086. .alg = "authenc(hmac(sha1),rfc3686(ctr(aes)))",
  2087. .test = alg_test_null,
  2088. .fips_allowed = 1,
  2089. }, {
  2090. .alg = "authenc(hmac(sha224),cbc(des))",
  2091. .test = alg_test_aead,
  2092. .suite = {
  2093. .aead = {
  2094. .enc = __VECS(hmac_sha224_des_cbc_enc_tv_temp)
  2095. }
  2096. }
  2097. }, {
  2098. .alg = "authenc(hmac(sha224),cbc(des3_ede))",
  2099. .test = alg_test_aead,
  2100. .fips_allowed = 1,
  2101. .suite = {
  2102. .aead = {
  2103. .enc = __VECS(hmac_sha224_des3_ede_cbc_enc_tv_temp)
  2104. }
  2105. }
  2106. }, {
  2107. .alg = "authenc(hmac(sha256),cbc(aes))",
  2108. .test = alg_test_aead,
  2109. .fips_allowed = 1,
  2110. .suite = {
  2111. .aead = {
  2112. .enc = __VECS(hmac_sha256_aes_cbc_enc_tv_temp)
  2113. }
  2114. }
  2115. }, {
  2116. .alg = "authenc(hmac(sha256),cbc(des))",
  2117. .test = alg_test_aead,
  2118. .suite = {
  2119. .aead = {
  2120. .enc = __VECS(hmac_sha256_des_cbc_enc_tv_temp)
  2121. }
  2122. }
  2123. }, {
  2124. .alg = "authenc(hmac(sha256),cbc(des3_ede))",
  2125. .test = alg_test_aead,
  2126. .fips_allowed = 1,
  2127. .suite = {
  2128. .aead = {
  2129. .enc = __VECS(hmac_sha256_des3_ede_cbc_enc_tv_temp)
  2130. }
  2131. }
  2132. }, {
  2133. .alg = "authenc(hmac(sha256),ctr(aes))",
  2134. .test = alg_test_null,
  2135. .fips_allowed = 1,
  2136. }, {
  2137. .alg = "authenc(hmac(sha256),rfc3686(ctr(aes)))",
  2138. .test = alg_test_null,
  2139. .fips_allowed = 1,
  2140. }, {
  2141. .alg = "authenc(hmac(sha384),cbc(des))",
  2142. .test = alg_test_aead,
  2143. .suite = {
  2144. .aead = {
  2145. .enc = __VECS(hmac_sha384_des_cbc_enc_tv_temp)
  2146. }
  2147. }
  2148. }, {
  2149. .alg = "authenc(hmac(sha384),cbc(des3_ede))",
  2150. .test = alg_test_aead,
  2151. .fips_allowed = 1,
  2152. .suite = {
  2153. .aead = {
  2154. .enc = __VECS(hmac_sha384_des3_ede_cbc_enc_tv_temp)
  2155. }
  2156. }
  2157. }, {
  2158. .alg = "authenc(hmac(sha384),ctr(aes))",
  2159. .test = alg_test_null,
  2160. .fips_allowed = 1,
  2161. }, {
  2162. .alg = "authenc(hmac(sha384),rfc3686(ctr(aes)))",
  2163. .test = alg_test_null,
  2164. .fips_allowed = 1,
  2165. }, {
  2166. .alg = "authenc(hmac(sha512),cbc(aes))",
  2167. .fips_allowed = 1,
  2168. .test = alg_test_aead,
  2169. .suite = {
  2170. .aead = {
  2171. .enc = __VECS(hmac_sha512_aes_cbc_enc_tv_temp)
  2172. }
  2173. }
  2174. }, {
  2175. .alg = "authenc(hmac(sha512),cbc(des))",
  2176. .test = alg_test_aead,
  2177. .suite = {
  2178. .aead = {
  2179. .enc = __VECS(hmac_sha512_des_cbc_enc_tv_temp)
  2180. }
  2181. }
  2182. }, {
  2183. .alg = "authenc(hmac(sha512),cbc(des3_ede))",
  2184. .test = alg_test_aead,
  2185. .fips_allowed = 1,
  2186. .suite = {
  2187. .aead = {
  2188. .enc = __VECS(hmac_sha512_des3_ede_cbc_enc_tv_temp)
  2189. }
  2190. }
  2191. }, {
  2192. .alg = "authenc(hmac(sha512),ctr(aes))",
  2193. .test = alg_test_null,
  2194. .fips_allowed = 1,
  2195. }, {
  2196. .alg = "authenc(hmac(sha512),rfc3686(ctr(aes)))",
  2197. .test = alg_test_null,
  2198. .fips_allowed = 1,
  2199. }, {
  2200. .alg = "cbc(aes)",
  2201. .test = alg_test_skcipher,
  2202. .fips_allowed = 1,
  2203. .suite = {
  2204. .cipher = {
  2205. .enc = __VECS(aes_cbc_enc_tv_template),
  2206. .dec = __VECS(aes_cbc_dec_tv_template)
  2207. }
  2208. }
  2209. }, {
  2210. .alg = "cbc(anubis)",
  2211. .test = alg_test_skcipher,
  2212. .suite = {
  2213. .cipher = {
  2214. .enc = __VECS(anubis_cbc_enc_tv_template),
  2215. .dec = __VECS(anubis_cbc_dec_tv_template)
  2216. }
  2217. }
  2218. }, {
  2219. .alg = "cbc(blowfish)",
  2220. .test = alg_test_skcipher,
  2221. .suite = {
  2222. .cipher = {
  2223. .enc = __VECS(bf_cbc_enc_tv_template),
  2224. .dec = __VECS(bf_cbc_dec_tv_template)
  2225. }
  2226. }
  2227. }, {
  2228. .alg = "cbc(camellia)",
  2229. .test = alg_test_skcipher,
  2230. .suite = {
  2231. .cipher = {
  2232. .enc = __VECS(camellia_cbc_enc_tv_template),
  2233. .dec = __VECS(camellia_cbc_dec_tv_template)
  2234. }
  2235. }
  2236. }, {
  2237. .alg = "cbc(cast5)",
  2238. .test = alg_test_skcipher,
  2239. .suite = {
  2240. .cipher = {
  2241. .enc = __VECS(cast5_cbc_enc_tv_template),
  2242. .dec = __VECS(cast5_cbc_dec_tv_template)
  2243. }
  2244. }
  2245. }, {
  2246. .alg = "cbc(cast6)",
  2247. .test = alg_test_skcipher,
  2248. .suite = {
  2249. .cipher = {
  2250. .enc = __VECS(cast6_cbc_enc_tv_template),
  2251. .dec = __VECS(cast6_cbc_dec_tv_template)
  2252. }
  2253. }
  2254. }, {
  2255. .alg = "cbc(des)",
  2256. .test = alg_test_skcipher,
  2257. .suite = {
  2258. .cipher = {
  2259. .enc = __VECS(des_cbc_enc_tv_template),
  2260. .dec = __VECS(des_cbc_dec_tv_template)
  2261. }
  2262. }
  2263. }, {
  2264. .alg = "cbc(des3_ede)",
  2265. .test = alg_test_skcipher,
  2266. .fips_allowed = 1,
  2267. .suite = {
  2268. .cipher = {
  2269. .enc = __VECS(des3_ede_cbc_enc_tv_template),
  2270. .dec = __VECS(des3_ede_cbc_dec_tv_template)
  2271. }
  2272. }
  2273. }, {
  2274. /* Same as cbc(aes) except the key is stored in
  2275. * hardware secure memory which we reference by index
  2276. */
  2277. .alg = "cbc(paes)",
  2278. .test = alg_test_null,
  2279. .fips_allowed = 1,
  2280. }, {
  2281. .alg = "cbc(serpent)",
  2282. .test = alg_test_skcipher,
  2283. .suite = {
  2284. .cipher = {
  2285. .enc = __VECS(serpent_cbc_enc_tv_template),
  2286. .dec = __VECS(serpent_cbc_dec_tv_template)
  2287. }
  2288. }
  2289. }, {
  2290. .alg = "cbc(twofish)",
  2291. .test = alg_test_skcipher,
  2292. .suite = {
  2293. .cipher = {
  2294. .enc = __VECS(tf_cbc_enc_tv_template),
  2295. .dec = __VECS(tf_cbc_dec_tv_template)
  2296. }
  2297. }
  2298. }, {
  2299. .alg = "cbcmac(aes)",
  2300. .fips_allowed = 1,
  2301. .test = alg_test_hash,
  2302. .suite = {
  2303. .hash = __VECS(aes_cbcmac_tv_template)
  2304. }
  2305. }, {
  2306. .alg = "ccm(aes)",
  2307. .test = alg_test_aead,
  2308. .fips_allowed = 1,
  2309. .suite = {
  2310. .aead = {
  2311. .enc = __VECS(aes_ccm_enc_tv_template),
  2312. .dec = __VECS(aes_ccm_dec_tv_template)
  2313. }
  2314. }
  2315. }, {
  2316. .alg = "chacha20",
  2317. .test = alg_test_skcipher,
  2318. .suite = {
  2319. .cipher = {
  2320. .enc = __VECS(chacha20_enc_tv_template),
  2321. .dec = __VECS(chacha20_enc_tv_template),
  2322. }
  2323. }
  2324. }, {
  2325. .alg = "cmac(aes)",
  2326. .fips_allowed = 1,
  2327. .test = alg_test_hash,
  2328. .suite = {
  2329. .hash = __VECS(aes_cmac128_tv_template)
  2330. }
  2331. }, {
  2332. .alg = "cmac(des3_ede)",
  2333. .fips_allowed = 1,
  2334. .test = alg_test_hash,
  2335. .suite = {
  2336. .hash = __VECS(des3_ede_cmac64_tv_template)
  2337. }
  2338. }, {
  2339. .alg = "compress_null",
  2340. .test = alg_test_null,
  2341. }, {
  2342. .alg = "crc32",
  2343. .test = alg_test_hash,
  2344. .suite = {
  2345. .hash = __VECS(crc32_tv_template)
  2346. }
  2347. }, {
  2348. .alg = "crc32c",
  2349. .test = alg_test_crc32c,
  2350. .fips_allowed = 1,
  2351. .suite = {
  2352. .hash = __VECS(crc32c_tv_template)
  2353. }
  2354. }, {
  2355. .alg = "crct10dif",
  2356. .test = alg_test_hash,
  2357. .fips_allowed = 1,
  2358. .suite = {
  2359. .hash = __VECS(crct10dif_tv_template)
  2360. }
  2361. }, {
  2362. .alg = "ctr(aes)",
  2363. .test = alg_test_skcipher,
  2364. .fips_allowed = 1,
  2365. .suite = {
  2366. .cipher = {
  2367. .enc = __VECS(aes_ctr_enc_tv_template),
  2368. .dec = __VECS(aes_ctr_dec_tv_template)
  2369. }
  2370. }
  2371. }, {
  2372. .alg = "ctr(blowfish)",
  2373. .test = alg_test_skcipher,
  2374. .suite = {
  2375. .cipher = {
  2376. .enc = __VECS(bf_ctr_enc_tv_template),
  2377. .dec = __VECS(bf_ctr_dec_tv_template)
  2378. }
  2379. }
  2380. }, {
  2381. .alg = "ctr(camellia)",
  2382. .test = alg_test_skcipher,
  2383. .suite = {
  2384. .cipher = {
  2385. .enc = __VECS(camellia_ctr_enc_tv_template),
  2386. .dec = __VECS(camellia_ctr_dec_tv_template)
  2387. }
  2388. }
  2389. }, {
  2390. .alg = "ctr(cast5)",
  2391. .test = alg_test_skcipher,
  2392. .suite = {
  2393. .cipher = {
  2394. .enc = __VECS(cast5_ctr_enc_tv_template),
  2395. .dec = __VECS(cast5_ctr_dec_tv_template)
  2396. }
  2397. }
  2398. }, {
  2399. .alg = "ctr(cast6)",
  2400. .test = alg_test_skcipher,
  2401. .suite = {
  2402. .cipher = {
  2403. .enc = __VECS(cast6_ctr_enc_tv_template),
  2404. .dec = __VECS(cast6_ctr_dec_tv_template)
  2405. }
  2406. }
  2407. }, {
  2408. .alg = "ctr(des)",
  2409. .test = alg_test_skcipher,
  2410. .suite = {
  2411. .cipher = {
  2412. .enc = __VECS(des_ctr_enc_tv_template),
  2413. .dec = __VECS(des_ctr_dec_tv_template)
  2414. }
  2415. }
  2416. }, {
  2417. .alg = "ctr(des3_ede)",
  2418. .test = alg_test_skcipher,
  2419. .fips_allowed = 1,
  2420. .suite = {
  2421. .cipher = {
  2422. .enc = __VECS(des3_ede_ctr_enc_tv_template),
  2423. .dec = __VECS(des3_ede_ctr_dec_tv_template)
  2424. }
  2425. }
  2426. }, {
  2427. /* Same as ctr(aes) except the key is stored in
  2428. * hardware secure memory which we reference by index
  2429. */
  2430. .alg = "ctr(paes)",
  2431. .test = alg_test_null,
  2432. .fips_allowed = 1,
  2433. }, {
  2434. .alg = "ctr(serpent)",
  2435. .test = alg_test_skcipher,
  2436. .suite = {
  2437. .cipher = {
  2438. .enc = __VECS(serpent_ctr_enc_tv_template),
  2439. .dec = __VECS(serpent_ctr_dec_tv_template)
  2440. }
  2441. }
  2442. }, {
  2443. .alg = "ctr(twofish)",
  2444. .test = alg_test_skcipher,
  2445. .suite = {
  2446. .cipher = {
  2447. .enc = __VECS(tf_ctr_enc_tv_template),
  2448. .dec = __VECS(tf_ctr_dec_tv_template)
  2449. }
  2450. }
  2451. }, {
  2452. .alg = "cts(cbc(aes))",
  2453. .test = alg_test_skcipher,
  2454. .suite = {
  2455. .cipher = {
  2456. .enc = __VECS(cts_mode_enc_tv_template),
  2457. .dec = __VECS(cts_mode_dec_tv_template)
  2458. }
  2459. }
  2460. }, {
  2461. .alg = "deflate",
  2462. .test = alg_test_comp,
  2463. .fips_allowed = 1,
  2464. .suite = {
  2465. .comp = {
  2466. .comp = __VECS(deflate_comp_tv_template),
  2467. .decomp = __VECS(deflate_decomp_tv_template)
  2468. }
  2469. }
  2470. }, {
  2471. .alg = "dh",
  2472. .test = alg_test_kpp,
  2473. .fips_allowed = 1,
  2474. .suite = {
  2475. .kpp = __VECS(dh_tv_template)
  2476. }
  2477. }, {
  2478. .alg = "digest_null",
  2479. .test = alg_test_null,
  2480. }, {
  2481. .alg = "drbg_nopr_ctr_aes128",
  2482. .test = alg_test_drbg,
  2483. .fips_allowed = 1,
  2484. .suite = {
  2485. .drbg = __VECS(drbg_nopr_ctr_aes128_tv_template)
  2486. }
  2487. }, {
  2488. .alg = "drbg_nopr_ctr_aes192",
  2489. .test = alg_test_drbg,
  2490. .fips_allowed = 1,
  2491. .suite = {
  2492. .drbg = __VECS(drbg_nopr_ctr_aes192_tv_template)
  2493. }
  2494. }, {
  2495. .alg = "drbg_nopr_ctr_aes256",
  2496. .test = alg_test_drbg,
  2497. .fips_allowed = 1,
  2498. .suite = {
  2499. .drbg = __VECS(drbg_nopr_ctr_aes256_tv_template)
  2500. }
  2501. }, {
  2502. /*
  2503. * There is no need to specifically test the DRBG with every
  2504. * backend cipher -- covered by drbg_nopr_hmac_sha256 test
  2505. */
  2506. .alg = "drbg_nopr_hmac_sha1",
  2507. .fips_allowed = 1,
  2508. .test = alg_test_null,
  2509. }, {
  2510. .alg = "drbg_nopr_hmac_sha256",
  2511. .test = alg_test_drbg,
  2512. .fips_allowed = 1,
  2513. .suite = {
  2514. .drbg = __VECS(drbg_nopr_hmac_sha256_tv_template)
  2515. }
  2516. }, {
  2517. /* covered by drbg_nopr_hmac_sha256 test */
  2518. .alg = "drbg_nopr_hmac_sha384",
  2519. .fips_allowed = 1,
  2520. .test = alg_test_null,
  2521. }, {
  2522. .alg = "drbg_nopr_hmac_sha512",
  2523. .test = alg_test_null,
  2524. .fips_allowed = 1,
  2525. }, {
  2526. .alg = "drbg_nopr_sha1",
  2527. .fips_allowed = 1,
  2528. .test = alg_test_null,
  2529. }, {
  2530. .alg = "drbg_nopr_sha256",
  2531. .test = alg_test_drbg,
  2532. .fips_allowed = 1,
  2533. .suite = {
  2534. .drbg = __VECS(drbg_nopr_sha256_tv_template)
  2535. }
  2536. }, {
  2537. /* covered by drbg_nopr_sha256 test */
  2538. .alg = "drbg_nopr_sha384",
  2539. .fips_allowed = 1,
  2540. .test = alg_test_null,
  2541. }, {
  2542. .alg = "drbg_nopr_sha512",
  2543. .fips_allowed = 1,
  2544. .test = alg_test_null,
  2545. }, {
  2546. .alg = "drbg_pr_ctr_aes128",
  2547. .test = alg_test_drbg,
  2548. .fips_allowed = 1,
  2549. .suite = {
  2550. .drbg = __VECS(drbg_pr_ctr_aes128_tv_template)
  2551. }
  2552. }, {
  2553. /* covered by drbg_pr_ctr_aes128 test */
  2554. .alg = "drbg_pr_ctr_aes192",
  2555. .fips_allowed = 1,
  2556. .test = alg_test_null,
  2557. }, {
  2558. .alg = "drbg_pr_ctr_aes256",
  2559. .fips_allowed = 1,
  2560. .test = alg_test_null,
  2561. }, {
  2562. .alg = "drbg_pr_hmac_sha1",
  2563. .fips_allowed = 1,
  2564. .test = alg_test_null,
  2565. }, {
  2566. .alg = "drbg_pr_hmac_sha256",
  2567. .test = alg_test_drbg,
  2568. .fips_allowed = 1,
  2569. .suite = {
  2570. .drbg = __VECS(drbg_pr_hmac_sha256_tv_template)
  2571. }
  2572. }, {
  2573. /* covered by drbg_pr_hmac_sha256 test */
  2574. .alg = "drbg_pr_hmac_sha384",
  2575. .fips_allowed = 1,
  2576. .test = alg_test_null,
  2577. }, {
  2578. .alg = "drbg_pr_hmac_sha512",
  2579. .test = alg_test_null,
  2580. .fips_allowed = 1,
  2581. }, {
  2582. .alg = "drbg_pr_sha1",
  2583. .fips_allowed = 1,
  2584. .test = alg_test_null,
  2585. }, {
  2586. .alg = "drbg_pr_sha256",
  2587. .test = alg_test_drbg,
  2588. .fips_allowed = 1,
  2589. .suite = {
  2590. .drbg = __VECS(drbg_pr_sha256_tv_template)
  2591. }
  2592. }, {
  2593. /* covered by drbg_pr_sha256 test */
  2594. .alg = "drbg_pr_sha384",
  2595. .fips_allowed = 1,
  2596. .test = alg_test_null,
  2597. }, {
  2598. .alg = "drbg_pr_sha512",
  2599. .fips_allowed = 1,
  2600. .test = alg_test_null,
  2601. }, {
  2602. .alg = "ecb(aes)",
  2603. .test = alg_test_skcipher,
  2604. .fips_allowed = 1,
  2605. .suite = {
  2606. .cipher = {
  2607. .enc = __VECS(aes_enc_tv_template),
  2608. .dec = __VECS(aes_dec_tv_template)
  2609. }
  2610. }
  2611. }, {
  2612. .alg = "ecb(anubis)",
  2613. .test = alg_test_skcipher,
  2614. .suite = {
  2615. .cipher = {
  2616. .enc = __VECS(anubis_enc_tv_template),
  2617. .dec = __VECS(anubis_dec_tv_template)
  2618. }
  2619. }
  2620. }, {
  2621. .alg = "ecb(arc4)",
  2622. .test = alg_test_skcipher,
  2623. .suite = {
  2624. .cipher = {
  2625. .enc = __VECS(arc4_enc_tv_template),
  2626. .dec = __VECS(arc4_dec_tv_template)
  2627. }
  2628. }
  2629. }, {
  2630. .alg = "ecb(blowfish)",
  2631. .test = alg_test_skcipher,
  2632. .suite = {
  2633. .cipher = {
  2634. .enc = __VECS(bf_enc_tv_template),
  2635. .dec = __VECS(bf_dec_tv_template)
  2636. }
  2637. }
  2638. }, {
  2639. .alg = "ecb(camellia)",
  2640. .test = alg_test_skcipher,
  2641. .suite = {
  2642. .cipher = {
  2643. .enc = __VECS(camellia_enc_tv_template),
  2644. .dec = __VECS(camellia_dec_tv_template)
  2645. }
  2646. }
  2647. }, {
  2648. .alg = "ecb(cast5)",
  2649. .test = alg_test_skcipher,
  2650. .suite = {
  2651. .cipher = {
  2652. .enc = __VECS(cast5_enc_tv_template),
  2653. .dec = __VECS(cast5_dec_tv_template)
  2654. }
  2655. }
  2656. }, {
  2657. .alg = "ecb(cast6)",
  2658. .test = alg_test_skcipher,
  2659. .suite = {
  2660. .cipher = {
  2661. .enc = __VECS(cast6_enc_tv_template),
  2662. .dec = __VECS(cast6_dec_tv_template)
  2663. }
  2664. }
  2665. }, {
  2666. .alg = "ecb(cipher_null)",
  2667. .test = alg_test_null,
  2668. .fips_allowed = 1,
  2669. }, {
  2670. .alg = "ecb(des)",
  2671. .test = alg_test_skcipher,
  2672. .suite = {
  2673. .cipher = {
  2674. .enc = __VECS(des_enc_tv_template),
  2675. .dec = __VECS(des_dec_tv_template)
  2676. }
  2677. }
  2678. }, {
  2679. .alg = "ecb(des3_ede)",
  2680. .test = alg_test_skcipher,
  2681. .fips_allowed = 1,
  2682. .suite = {
  2683. .cipher = {
  2684. .enc = __VECS(des3_ede_enc_tv_template),
  2685. .dec = __VECS(des3_ede_dec_tv_template)
  2686. }
  2687. }
  2688. }, {
  2689. .alg = "ecb(fcrypt)",
  2690. .test = alg_test_skcipher,
  2691. .suite = {
  2692. .cipher = {
  2693. .enc = {
  2694. .vecs = fcrypt_pcbc_enc_tv_template,
  2695. .count = 1
  2696. },
  2697. .dec = {
  2698. .vecs = fcrypt_pcbc_dec_tv_template,
  2699. .count = 1
  2700. }
  2701. }
  2702. }
  2703. }, {
  2704. .alg = "ecb(khazad)",
  2705. .test = alg_test_skcipher,
  2706. .suite = {
  2707. .cipher = {
  2708. .enc = __VECS(khazad_enc_tv_template),
  2709. .dec = __VECS(khazad_dec_tv_template)
  2710. }
  2711. }
  2712. }, {
  2713. /* Same as ecb(aes) except the key is stored in
  2714. * hardware secure memory which we reference by index
  2715. */
  2716. .alg = "ecb(paes)",
  2717. .test = alg_test_null,
  2718. .fips_allowed = 1,
  2719. }, {
  2720. .alg = "ecb(seed)",
  2721. .test = alg_test_skcipher,
  2722. .suite = {
  2723. .cipher = {
  2724. .enc = __VECS(seed_enc_tv_template),
  2725. .dec = __VECS(seed_dec_tv_template)
  2726. }
  2727. }
  2728. }, {
  2729. .alg = "ecb(serpent)",
  2730. .test = alg_test_skcipher,
  2731. .suite = {
  2732. .cipher = {
  2733. .enc = __VECS(serpent_enc_tv_template),
  2734. .dec = __VECS(serpent_dec_tv_template)
  2735. }
  2736. }
  2737. }, {
  2738. .alg = "ecb(sm4)",
  2739. .test = alg_test_skcipher,
  2740. .suite = {
  2741. .cipher = {
  2742. .enc = __VECS(sm4_enc_tv_template),
  2743. .dec = __VECS(sm4_dec_tv_template)
  2744. }
  2745. }
  2746. }, {
  2747. .alg = "ecb(speck128)",
  2748. .test = alg_test_skcipher,
  2749. .suite = {
  2750. .cipher = {
  2751. .enc = __VECS(speck128_enc_tv_template),
  2752. .dec = __VECS(speck128_dec_tv_template)
  2753. }
  2754. }
  2755. }, {
  2756. .alg = "ecb(speck64)",
  2757. .test = alg_test_skcipher,
  2758. .suite = {
  2759. .cipher = {
  2760. .enc = __VECS(speck64_enc_tv_template),
  2761. .dec = __VECS(speck64_dec_tv_template)
  2762. }
  2763. }
  2764. }, {
  2765. .alg = "ecb(tea)",
  2766. .test = alg_test_skcipher,
  2767. .suite = {
  2768. .cipher = {
  2769. .enc = __VECS(tea_enc_tv_template),
  2770. .dec = __VECS(tea_dec_tv_template)
  2771. }
  2772. }
  2773. }, {
  2774. .alg = "ecb(tnepres)",
  2775. .test = alg_test_skcipher,
  2776. .suite = {
  2777. .cipher = {
  2778. .enc = __VECS(tnepres_enc_tv_template),
  2779. .dec = __VECS(tnepres_dec_tv_template)
  2780. }
  2781. }
  2782. }, {
  2783. .alg = "ecb(twofish)",
  2784. .test = alg_test_skcipher,
  2785. .suite = {
  2786. .cipher = {
  2787. .enc = __VECS(tf_enc_tv_template),
  2788. .dec = __VECS(tf_dec_tv_template)
  2789. }
  2790. }
  2791. }, {
  2792. .alg = "ecb(xeta)",
  2793. .test = alg_test_skcipher,
  2794. .suite = {
  2795. .cipher = {
  2796. .enc = __VECS(xeta_enc_tv_template),
  2797. .dec = __VECS(xeta_dec_tv_template)
  2798. }
  2799. }
  2800. }, {
  2801. .alg = "ecb(xtea)",
  2802. .test = alg_test_skcipher,
  2803. .suite = {
  2804. .cipher = {
  2805. .enc = __VECS(xtea_enc_tv_template),
  2806. .dec = __VECS(xtea_dec_tv_template)
  2807. }
  2808. }
  2809. }, {
  2810. .alg = "ecdh",
  2811. .test = alg_test_kpp,
  2812. .fips_allowed = 1,
  2813. .suite = {
  2814. .kpp = __VECS(ecdh_tv_template)
  2815. }
  2816. }, {
  2817. .alg = "gcm(aes)",
  2818. .test = alg_test_aead,
  2819. .fips_allowed = 1,
  2820. .suite = {
  2821. .aead = {
  2822. .enc = __VECS(aes_gcm_enc_tv_template),
  2823. .dec = __VECS(aes_gcm_dec_tv_template)
  2824. }
  2825. }
  2826. }, {
  2827. .alg = "ghash",
  2828. .test = alg_test_hash,
  2829. .fips_allowed = 1,
  2830. .suite = {
  2831. .hash = __VECS(ghash_tv_template)
  2832. }
  2833. }, {
  2834. .alg = "hmac(crc32)",
  2835. .test = alg_test_hash,
  2836. .suite = {
  2837. .hash = __VECS(bfin_crc_tv_template)
  2838. }
  2839. }, {
  2840. .alg = "hmac(md5)",
  2841. .test = alg_test_hash,
  2842. .suite = {
  2843. .hash = __VECS(hmac_md5_tv_template)
  2844. }
  2845. }, {
  2846. .alg = "hmac(rmd128)",
  2847. .test = alg_test_hash,
  2848. .suite = {
  2849. .hash = __VECS(hmac_rmd128_tv_template)
  2850. }
  2851. }, {
  2852. .alg = "hmac(rmd160)",
  2853. .test = alg_test_hash,
  2854. .suite = {
  2855. .hash = __VECS(hmac_rmd160_tv_template)
  2856. }
  2857. }, {
  2858. .alg = "hmac(sha1)",
  2859. .test = alg_test_hash,
  2860. .fips_allowed = 1,
  2861. .suite = {
  2862. .hash = __VECS(hmac_sha1_tv_template)
  2863. }
  2864. }, {
  2865. .alg = "hmac(sha224)",
  2866. .test = alg_test_hash,
  2867. .fips_allowed = 1,
  2868. .suite = {
  2869. .hash = __VECS(hmac_sha224_tv_template)
  2870. }
  2871. }, {
  2872. .alg = "hmac(sha256)",
  2873. .test = alg_test_hash,
  2874. .fips_allowed = 1,
  2875. .suite = {
  2876. .hash = __VECS(hmac_sha256_tv_template)
  2877. }
  2878. }, {
  2879. .alg = "hmac(sha3-224)",
  2880. .test = alg_test_hash,
  2881. .fips_allowed = 1,
  2882. .suite = {
  2883. .hash = __VECS(hmac_sha3_224_tv_template)
  2884. }
  2885. }, {
  2886. .alg = "hmac(sha3-256)",
  2887. .test = alg_test_hash,
  2888. .fips_allowed = 1,
  2889. .suite = {
  2890. .hash = __VECS(hmac_sha3_256_tv_template)
  2891. }
  2892. }, {
  2893. .alg = "hmac(sha3-384)",
  2894. .test = alg_test_hash,
  2895. .fips_allowed = 1,
  2896. .suite = {
  2897. .hash = __VECS(hmac_sha3_384_tv_template)
  2898. }
  2899. }, {
  2900. .alg = "hmac(sha3-512)",
  2901. .test = alg_test_hash,
  2902. .fips_allowed = 1,
  2903. .suite = {
  2904. .hash = __VECS(hmac_sha3_512_tv_template)
  2905. }
  2906. }, {
  2907. .alg = "hmac(sha384)",
  2908. .test = alg_test_hash,
  2909. .fips_allowed = 1,
  2910. .suite = {
  2911. .hash = __VECS(hmac_sha384_tv_template)
  2912. }
  2913. }, {
  2914. .alg = "hmac(sha512)",
  2915. .test = alg_test_hash,
  2916. .fips_allowed = 1,
  2917. .suite = {
  2918. .hash = __VECS(hmac_sha512_tv_template)
  2919. }
  2920. }, {
  2921. .alg = "jitterentropy_rng",
  2922. .fips_allowed = 1,
  2923. .test = alg_test_null,
  2924. }, {
  2925. .alg = "kw(aes)",
  2926. .test = alg_test_skcipher,
  2927. .fips_allowed = 1,
  2928. .suite = {
  2929. .cipher = {
  2930. .enc = __VECS(aes_kw_enc_tv_template),
  2931. .dec = __VECS(aes_kw_dec_tv_template)
  2932. }
  2933. }
  2934. }, {
  2935. .alg = "lrw(aes)",
  2936. .test = alg_test_skcipher,
  2937. .suite = {
  2938. .cipher = {
  2939. .enc = __VECS(aes_lrw_enc_tv_template),
  2940. .dec = __VECS(aes_lrw_dec_tv_template)
  2941. }
  2942. }
  2943. }, {
  2944. .alg = "lrw(camellia)",
  2945. .test = alg_test_skcipher,
  2946. .suite = {
  2947. .cipher = {
  2948. .enc = __VECS(camellia_lrw_enc_tv_template),
  2949. .dec = __VECS(camellia_lrw_dec_tv_template)
  2950. }
  2951. }
  2952. }, {
  2953. .alg = "lrw(cast6)",
  2954. .test = alg_test_skcipher,
  2955. .suite = {
  2956. .cipher = {
  2957. .enc = __VECS(cast6_lrw_enc_tv_template),
  2958. .dec = __VECS(cast6_lrw_dec_tv_template)
  2959. }
  2960. }
  2961. }, {
  2962. .alg = "lrw(serpent)",
  2963. .test = alg_test_skcipher,
  2964. .suite = {
  2965. .cipher = {
  2966. .enc = __VECS(serpent_lrw_enc_tv_template),
  2967. .dec = __VECS(serpent_lrw_dec_tv_template)
  2968. }
  2969. }
  2970. }, {
  2971. .alg = "lrw(twofish)",
  2972. .test = alg_test_skcipher,
  2973. .suite = {
  2974. .cipher = {
  2975. .enc = __VECS(tf_lrw_enc_tv_template),
  2976. .dec = __VECS(tf_lrw_dec_tv_template)
  2977. }
  2978. }
  2979. }, {
  2980. .alg = "lz4",
  2981. .test = alg_test_comp,
  2982. .fips_allowed = 1,
  2983. .suite = {
  2984. .comp = {
  2985. .comp = __VECS(lz4_comp_tv_template),
  2986. .decomp = __VECS(lz4_decomp_tv_template)
  2987. }
  2988. }
  2989. }, {
  2990. .alg = "lz4hc",
  2991. .test = alg_test_comp,
  2992. .fips_allowed = 1,
  2993. .suite = {
  2994. .comp = {
  2995. .comp = __VECS(lz4hc_comp_tv_template),
  2996. .decomp = __VECS(lz4hc_decomp_tv_template)
  2997. }
  2998. }
  2999. }, {
  3000. .alg = "lzo",
  3001. .test = alg_test_comp,
  3002. .fips_allowed = 1,
  3003. .suite = {
  3004. .comp = {
  3005. .comp = __VECS(lzo_comp_tv_template),
  3006. .decomp = __VECS(lzo_decomp_tv_template)
  3007. }
  3008. }
  3009. }, {
  3010. .alg = "md4",
  3011. .test = alg_test_hash,
  3012. .suite = {
  3013. .hash = __VECS(md4_tv_template)
  3014. }
  3015. }, {
  3016. .alg = "md5",
  3017. .test = alg_test_hash,
  3018. .suite = {
  3019. .hash = __VECS(md5_tv_template)
  3020. }
  3021. }, {
  3022. .alg = "michael_mic",
  3023. .test = alg_test_hash,
  3024. .suite = {
  3025. .hash = __VECS(michael_mic_tv_template)
  3026. }
  3027. }, {
  3028. .alg = "ofb(aes)",
  3029. .test = alg_test_skcipher,
  3030. .fips_allowed = 1,
  3031. .suite = {
  3032. .cipher = {
  3033. .enc = __VECS(aes_ofb_enc_tv_template),
  3034. .dec = __VECS(aes_ofb_dec_tv_template)
  3035. }
  3036. }
  3037. }, {
  3038. /* Same as ofb(aes) except the key is stored in
  3039. * hardware secure memory which we reference by index
  3040. */
  3041. .alg = "ofb(paes)",
  3042. .test = alg_test_null,
  3043. .fips_allowed = 1,
  3044. }, {
  3045. .alg = "pcbc(fcrypt)",
  3046. .test = alg_test_skcipher,
  3047. .suite = {
  3048. .cipher = {
  3049. .enc = __VECS(fcrypt_pcbc_enc_tv_template),
  3050. .dec = __VECS(fcrypt_pcbc_dec_tv_template)
  3051. }
  3052. }
  3053. }, {
  3054. .alg = "pkcs1pad(rsa,sha224)",
  3055. .test = alg_test_null,
  3056. .fips_allowed = 1,
  3057. }, {
  3058. .alg = "pkcs1pad(rsa,sha256)",
  3059. .test = alg_test_akcipher,
  3060. .fips_allowed = 1,
  3061. .suite = {
  3062. .akcipher = __VECS(pkcs1pad_rsa_tv_template)
  3063. }
  3064. }, {
  3065. .alg = "pkcs1pad(rsa,sha384)",
  3066. .test = alg_test_null,
  3067. .fips_allowed = 1,
  3068. }, {
  3069. .alg = "pkcs1pad(rsa,sha512)",
  3070. .test = alg_test_null,
  3071. .fips_allowed = 1,
  3072. }, {
  3073. .alg = "poly1305",
  3074. .test = alg_test_hash,
  3075. .suite = {
  3076. .hash = __VECS(poly1305_tv_template)
  3077. }
  3078. }, {
  3079. .alg = "rfc3686(ctr(aes))",
  3080. .test = alg_test_skcipher,
  3081. .fips_allowed = 1,
  3082. .suite = {
  3083. .cipher = {
  3084. .enc = __VECS(aes_ctr_rfc3686_enc_tv_template),
  3085. .dec = __VECS(aes_ctr_rfc3686_dec_tv_template)
  3086. }
  3087. }
  3088. }, {
  3089. .alg = "rfc4106(gcm(aes))",
  3090. .test = alg_test_aead,
  3091. .fips_allowed = 1,
  3092. .suite = {
  3093. .aead = {
  3094. .enc = __VECS(aes_gcm_rfc4106_enc_tv_template),
  3095. .dec = __VECS(aes_gcm_rfc4106_dec_tv_template)
  3096. }
  3097. }
  3098. }, {
  3099. .alg = "rfc4309(ccm(aes))",
  3100. .test = alg_test_aead,
  3101. .fips_allowed = 1,
  3102. .suite = {
  3103. .aead = {
  3104. .enc = __VECS(aes_ccm_rfc4309_enc_tv_template),
  3105. .dec = __VECS(aes_ccm_rfc4309_dec_tv_template)
  3106. }
  3107. }
  3108. }, {
  3109. .alg = "rfc4543(gcm(aes))",
  3110. .test = alg_test_aead,
  3111. .suite = {
  3112. .aead = {
  3113. .enc = __VECS(aes_gcm_rfc4543_enc_tv_template),
  3114. .dec = __VECS(aes_gcm_rfc4543_dec_tv_template),
  3115. }
  3116. }
  3117. }, {
  3118. .alg = "rfc7539(chacha20,poly1305)",
  3119. .test = alg_test_aead,
  3120. .suite = {
  3121. .aead = {
  3122. .enc = __VECS(rfc7539_enc_tv_template),
  3123. .dec = __VECS(rfc7539_dec_tv_template),
  3124. }
  3125. }
  3126. }, {
  3127. .alg = "rfc7539esp(chacha20,poly1305)",
  3128. .test = alg_test_aead,
  3129. .suite = {
  3130. .aead = {
  3131. .enc = __VECS(rfc7539esp_enc_tv_template),
  3132. .dec = __VECS(rfc7539esp_dec_tv_template),
  3133. }
  3134. }
  3135. }, {
  3136. .alg = "rmd128",
  3137. .test = alg_test_hash,
  3138. .suite = {
  3139. .hash = __VECS(rmd128_tv_template)
  3140. }
  3141. }, {
  3142. .alg = "rmd160",
  3143. .test = alg_test_hash,
  3144. .suite = {
  3145. .hash = __VECS(rmd160_tv_template)
  3146. }
  3147. }, {
  3148. .alg = "rmd256",
  3149. .test = alg_test_hash,
  3150. .suite = {
  3151. .hash = __VECS(rmd256_tv_template)
  3152. }
  3153. }, {
  3154. .alg = "rmd320",
  3155. .test = alg_test_hash,
  3156. .suite = {
  3157. .hash = __VECS(rmd320_tv_template)
  3158. }
  3159. }, {
  3160. .alg = "rsa",
  3161. .test = alg_test_akcipher,
  3162. .fips_allowed = 1,
  3163. .suite = {
  3164. .akcipher = __VECS(rsa_tv_template)
  3165. }
  3166. }, {
  3167. .alg = "salsa20",
  3168. .test = alg_test_skcipher,
  3169. .suite = {
  3170. .cipher = {
  3171. .enc = __VECS(salsa20_stream_enc_tv_template)
  3172. }
  3173. }
  3174. }, {
  3175. .alg = "sha1",
  3176. .test = alg_test_hash,
  3177. .fips_allowed = 1,
  3178. .suite = {
  3179. .hash = __VECS(sha1_tv_template)
  3180. }
  3181. }, {
  3182. .alg = "sha224",
  3183. .test = alg_test_hash,
  3184. .fips_allowed = 1,
  3185. .suite = {
  3186. .hash = __VECS(sha224_tv_template)
  3187. }
  3188. }, {
  3189. .alg = "sha256",
  3190. .test = alg_test_hash,
  3191. .fips_allowed = 1,
  3192. .suite = {
  3193. .hash = __VECS(sha256_tv_template)
  3194. }
  3195. }, {
  3196. .alg = "sha3-224",
  3197. .test = alg_test_hash,
  3198. .fips_allowed = 1,
  3199. .suite = {
  3200. .hash = __VECS(sha3_224_tv_template)
  3201. }
  3202. }, {
  3203. .alg = "sha3-256",
  3204. .test = alg_test_hash,
  3205. .fips_allowed = 1,
  3206. .suite = {
  3207. .hash = __VECS(sha3_256_tv_template)
  3208. }
  3209. }, {
  3210. .alg = "sha3-384",
  3211. .test = alg_test_hash,
  3212. .fips_allowed = 1,
  3213. .suite = {
  3214. .hash = __VECS(sha3_384_tv_template)
  3215. }
  3216. }, {
  3217. .alg = "sha3-512",
  3218. .test = alg_test_hash,
  3219. .fips_allowed = 1,
  3220. .suite = {
  3221. .hash = __VECS(sha3_512_tv_template)
  3222. }
  3223. }, {
  3224. .alg = "sha384",
  3225. .test = alg_test_hash,
  3226. .fips_allowed = 1,
  3227. .suite = {
  3228. .hash = __VECS(sha384_tv_template)
  3229. }
  3230. }, {
  3231. .alg = "sha512",
  3232. .test = alg_test_hash,
  3233. .fips_allowed = 1,
  3234. .suite = {
  3235. .hash = __VECS(sha512_tv_template)
  3236. }
  3237. }, {
  3238. .alg = "sm3",
  3239. .test = alg_test_hash,
  3240. .suite = {
  3241. .hash = __VECS(sm3_tv_template)
  3242. }
  3243. }, {
  3244. .alg = "tgr128",
  3245. .test = alg_test_hash,
  3246. .suite = {
  3247. .hash = __VECS(tgr128_tv_template)
  3248. }
  3249. }, {
  3250. .alg = "tgr160",
  3251. .test = alg_test_hash,
  3252. .suite = {
  3253. .hash = __VECS(tgr160_tv_template)
  3254. }
  3255. }, {
  3256. .alg = "tgr192",
  3257. .test = alg_test_hash,
  3258. .suite = {
  3259. .hash = __VECS(tgr192_tv_template)
  3260. }
  3261. }, {
  3262. .alg = "vmac(aes)",
  3263. .test = alg_test_hash,
  3264. .suite = {
  3265. .hash = __VECS(aes_vmac128_tv_template)
  3266. }
  3267. }, {
  3268. .alg = "wp256",
  3269. .test = alg_test_hash,
  3270. .suite = {
  3271. .hash = __VECS(wp256_tv_template)
  3272. }
  3273. }, {
  3274. .alg = "wp384",
  3275. .test = alg_test_hash,
  3276. .suite = {
  3277. .hash = __VECS(wp384_tv_template)
  3278. }
  3279. }, {
  3280. .alg = "wp512",
  3281. .test = alg_test_hash,
  3282. .suite = {
  3283. .hash = __VECS(wp512_tv_template)
  3284. }
  3285. }, {
  3286. .alg = "xcbc(aes)",
  3287. .test = alg_test_hash,
  3288. .suite = {
  3289. .hash = __VECS(aes_xcbc128_tv_template)
  3290. }
  3291. }, {
  3292. .alg = "xts(aes)",
  3293. .test = alg_test_skcipher,
  3294. .fips_allowed = 1,
  3295. .suite = {
  3296. .cipher = {
  3297. .enc = __VECS(aes_xts_enc_tv_template),
  3298. .dec = __VECS(aes_xts_dec_tv_template)
  3299. }
  3300. }
  3301. }, {
  3302. .alg = "xts(camellia)",
  3303. .test = alg_test_skcipher,
  3304. .suite = {
  3305. .cipher = {
  3306. .enc = __VECS(camellia_xts_enc_tv_template),
  3307. .dec = __VECS(camellia_xts_dec_tv_template)
  3308. }
  3309. }
  3310. }, {
  3311. .alg = "xts(cast6)",
  3312. .test = alg_test_skcipher,
  3313. .suite = {
  3314. .cipher = {
  3315. .enc = __VECS(cast6_xts_enc_tv_template),
  3316. .dec = __VECS(cast6_xts_dec_tv_template)
  3317. }
  3318. }
  3319. }, {
  3320. /* Same as xts(aes) except the key is stored in
  3321. * hardware secure memory which we reference by index
  3322. */
  3323. .alg = "xts(paes)",
  3324. .test = alg_test_null,
  3325. .fips_allowed = 1,
  3326. }, {
  3327. .alg = "xts(serpent)",
  3328. .test = alg_test_skcipher,
  3329. .suite = {
  3330. .cipher = {
  3331. .enc = __VECS(serpent_xts_enc_tv_template),
  3332. .dec = __VECS(serpent_xts_dec_tv_template)
  3333. }
  3334. }
  3335. }, {
  3336. .alg = "xts(speck128)",
  3337. .test = alg_test_skcipher,
  3338. .suite = {
  3339. .cipher = {
  3340. .enc = __VECS(speck128_xts_enc_tv_template),
  3341. .dec = __VECS(speck128_xts_dec_tv_template)
  3342. }
  3343. }
  3344. }, {
  3345. .alg = "xts(speck64)",
  3346. .test = alg_test_skcipher,
  3347. .suite = {
  3348. .cipher = {
  3349. .enc = __VECS(speck64_xts_enc_tv_template),
  3350. .dec = __VECS(speck64_xts_dec_tv_template)
  3351. }
  3352. }
  3353. }, {
  3354. .alg = "xts(twofish)",
  3355. .test = alg_test_skcipher,
  3356. .suite = {
  3357. .cipher = {
  3358. .enc = __VECS(tf_xts_enc_tv_template),
  3359. .dec = __VECS(tf_xts_dec_tv_template)
  3360. }
  3361. }
  3362. }, {
  3363. .alg = "xts4096(paes)",
  3364. .test = alg_test_null,
  3365. .fips_allowed = 1,
  3366. }, {
  3367. .alg = "xts512(paes)",
  3368. .test = alg_test_null,
  3369. .fips_allowed = 1,
  3370. }, {
  3371. .alg = "zlib-deflate",
  3372. .test = alg_test_comp,
  3373. .fips_allowed = 1,
  3374. .suite = {
  3375. .comp = {
  3376. .comp = __VECS(zlib_deflate_comp_tv_template),
  3377. .decomp = __VECS(zlib_deflate_decomp_tv_template)
  3378. }
  3379. }
  3380. }, {
  3381. .alg = "zstd",
  3382. .test = alg_test_comp,
  3383. .fips_allowed = 1,
  3384. .suite = {
  3385. .comp = {
  3386. .comp = __VECS(zstd_comp_tv_template),
  3387. .decomp = __VECS(zstd_decomp_tv_template)
  3388. }
  3389. }
  3390. }
  3391. };
  3392. static bool alg_test_descs_checked;
  3393. static void alg_test_descs_check_order(void)
  3394. {
  3395. int i;
  3396. /* only check once */
  3397. if (alg_test_descs_checked)
  3398. return;
  3399. alg_test_descs_checked = true;
  3400. for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
  3401. int diff = strcmp(alg_test_descs[i - 1].alg,
  3402. alg_test_descs[i].alg);
  3403. if (WARN_ON(diff > 0)) {
  3404. pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
  3405. alg_test_descs[i - 1].alg,
  3406. alg_test_descs[i].alg);
  3407. }
  3408. if (WARN_ON(diff == 0)) {
  3409. pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
  3410. alg_test_descs[i].alg);
  3411. }
  3412. }
  3413. }
  3414. static int alg_find_test(const char *alg)
  3415. {
  3416. int start = 0;
  3417. int end = ARRAY_SIZE(alg_test_descs);
  3418. while (start < end) {
  3419. int i = (start + end) / 2;
  3420. int diff = strcmp(alg_test_descs[i].alg, alg);
  3421. if (diff > 0) {
  3422. end = i;
  3423. continue;
  3424. }
  3425. if (diff < 0) {
  3426. start = i + 1;
  3427. continue;
  3428. }
  3429. return i;
  3430. }
  3431. return -1;
  3432. }
  3433. int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
  3434. {
  3435. int i;
  3436. int j;
  3437. int rc;
  3438. if (!fips_enabled && notests) {
  3439. printk_once(KERN_INFO "alg: self-tests disabled\n");
  3440. return 0;
  3441. }
  3442. alg_test_descs_check_order();
  3443. if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
  3444. char nalg[CRYPTO_MAX_ALG_NAME];
  3445. if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
  3446. sizeof(nalg))
  3447. return -ENAMETOOLONG;
  3448. i = alg_find_test(nalg);
  3449. if (i < 0)
  3450. goto notest;
  3451. if (fips_enabled && !alg_test_descs[i].fips_allowed)
  3452. goto non_fips_alg;
  3453. rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
  3454. goto test_done;
  3455. }
  3456. i = alg_find_test(alg);
  3457. j = alg_find_test(driver);
  3458. if (i < 0 && j < 0)
  3459. goto notest;
  3460. if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
  3461. (j >= 0 && !alg_test_descs[j].fips_allowed)))
  3462. goto non_fips_alg;
  3463. rc = 0;
  3464. if (i >= 0)
  3465. rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
  3466. type, mask);
  3467. if (j >= 0 && j != i)
  3468. rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
  3469. type, mask);
  3470. test_done:
  3471. if (fips_enabled && rc)
  3472. panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
  3473. if (fips_enabled && !rc)
  3474. pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
  3475. return rc;
  3476. notest:
  3477. printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
  3478. return 0;
  3479. non_fips_alg:
  3480. return -EINVAL;
  3481. }
  3482. #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
  3483. EXPORT_SYMBOL_GPL(alg_test);