testmgr.c 90 KB

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