testmgr.c 86 KB

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