testmgr.c 91 KB

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