testmgr.c 85 KB

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