testmgr.c 92 KB

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