testmgr.c 86 KB

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