testmgr.c 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966
  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 on %s for %s\n",
  886. d, j, e, algo);
  887. hexdump(q, template[i].rlen);
  888. ret = -EINVAL;
  889. goto out;
  890. }
  891. }
  892. j = 0;
  893. for (i = 0; i < tcount; i++) {
  894. /* alignment tests are only done with continuous buffers */
  895. if (align_offset != 0)
  896. break;
  897. if (!template[i].np)
  898. continue;
  899. if (template[i].iv)
  900. memcpy(iv, template[i].iv, ivsize);
  901. else
  902. memset(iv, 0, MAX_IVLEN);
  903. j++;
  904. crypto_skcipher_clear_flags(tfm, ~0);
  905. if (template[i].wk)
  906. crypto_skcipher_set_flags(tfm,
  907. CRYPTO_TFM_REQ_WEAK_KEY);
  908. ret = crypto_skcipher_setkey(tfm, template[i].key,
  909. template[i].klen);
  910. if (!ret == template[i].fail) {
  911. pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
  912. d, j, algo, crypto_skcipher_get_flags(tfm));
  913. goto out;
  914. } else if (ret)
  915. continue;
  916. temp = 0;
  917. ret = -EINVAL;
  918. sg_init_table(sg, template[i].np);
  919. if (diff_dst)
  920. sg_init_table(sgout, template[i].np);
  921. for (k = 0; k < template[i].np; k++) {
  922. if (WARN_ON(offset_in_page(IDX[k]) +
  923. template[i].tap[k] > PAGE_SIZE))
  924. goto out;
  925. q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
  926. memcpy(q, template[i].input + temp, template[i].tap[k]);
  927. if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
  928. q[template[i].tap[k]] = 0;
  929. sg_set_buf(&sg[k], q, template[i].tap[k]);
  930. if (diff_dst) {
  931. q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
  932. offset_in_page(IDX[k]);
  933. sg_set_buf(&sgout[k], q, template[i].tap[k]);
  934. memset(q, 0, template[i].tap[k]);
  935. if (offset_in_page(q) +
  936. template[i].tap[k] < PAGE_SIZE)
  937. q[template[i].tap[k]] = 0;
  938. }
  939. temp += template[i].tap[k];
  940. }
  941. skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
  942. template[i].ilen, iv);
  943. ret = enc ? crypto_skcipher_encrypt(req) :
  944. crypto_skcipher_decrypt(req);
  945. switch (ret) {
  946. case 0:
  947. break;
  948. case -EINPROGRESS:
  949. case -EBUSY:
  950. wait_for_completion(&result.completion);
  951. reinit_completion(&result.completion);
  952. ret = result.err;
  953. if (!ret)
  954. break;
  955. /* fall through */
  956. default:
  957. pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
  958. d, e, j, algo, -ret);
  959. goto out;
  960. }
  961. temp = 0;
  962. ret = -EINVAL;
  963. for (k = 0; k < template[i].np; k++) {
  964. if (diff_dst)
  965. q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
  966. offset_in_page(IDX[k]);
  967. else
  968. q = xbuf[IDX[k] >> PAGE_SHIFT] +
  969. offset_in_page(IDX[k]);
  970. if (memcmp(q, template[i].result + temp,
  971. template[i].tap[k])) {
  972. pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
  973. d, j, e, k, algo);
  974. hexdump(q, template[i].tap[k]);
  975. goto out;
  976. }
  977. q += template[i].tap[k];
  978. for (n = 0; offset_in_page(q + n) && q[n]; n++)
  979. ;
  980. if (n) {
  981. pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
  982. d, j, e, k, algo, n);
  983. hexdump(q, n);
  984. goto out;
  985. }
  986. temp += template[i].tap[k];
  987. }
  988. }
  989. ret = 0;
  990. out:
  991. skcipher_request_free(req);
  992. if (diff_dst)
  993. testmgr_free_buf(xoutbuf);
  994. out_nooutbuf:
  995. testmgr_free_buf(xbuf);
  996. out_nobuf:
  997. return ret;
  998. }
  999. static int test_skcipher(struct crypto_skcipher *tfm, int enc,
  1000. struct cipher_testvec *template, unsigned int tcount)
  1001. {
  1002. unsigned int alignmask;
  1003. int ret;
  1004. /* test 'dst == src' case */
  1005. ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
  1006. if (ret)
  1007. return ret;
  1008. /* test 'dst != src' case */
  1009. ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
  1010. if (ret)
  1011. return ret;
  1012. /* test unaligned buffers, check with one byte offset */
  1013. ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
  1014. if (ret)
  1015. return ret;
  1016. alignmask = crypto_tfm_alg_alignmask(&tfm->base);
  1017. if (alignmask) {
  1018. /* Check if alignment mask for tfm is correctly set. */
  1019. ret = __test_skcipher(tfm, enc, template, tcount, true,
  1020. alignmask + 1);
  1021. if (ret)
  1022. return ret;
  1023. }
  1024. return 0;
  1025. }
  1026. static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
  1027. struct comp_testvec *dtemplate, int ctcount, int dtcount)
  1028. {
  1029. const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
  1030. unsigned int i;
  1031. char result[COMP_BUF_SIZE];
  1032. int ret;
  1033. for (i = 0; i < ctcount; i++) {
  1034. int ilen;
  1035. unsigned int dlen = COMP_BUF_SIZE;
  1036. memset(result, 0, sizeof (result));
  1037. ilen = ctemplate[i].inlen;
  1038. ret = crypto_comp_compress(tfm, ctemplate[i].input,
  1039. ilen, result, &dlen);
  1040. if (ret) {
  1041. printk(KERN_ERR "alg: comp: compression failed "
  1042. "on test %d for %s: ret=%d\n", i + 1, algo,
  1043. -ret);
  1044. goto out;
  1045. }
  1046. if (dlen != ctemplate[i].outlen) {
  1047. printk(KERN_ERR "alg: comp: Compression test %d "
  1048. "failed for %s: output len = %d\n", i + 1, algo,
  1049. dlen);
  1050. ret = -EINVAL;
  1051. goto out;
  1052. }
  1053. if (memcmp(result, ctemplate[i].output, dlen)) {
  1054. printk(KERN_ERR "alg: comp: Compression test %d "
  1055. "failed for %s\n", i + 1, algo);
  1056. hexdump(result, dlen);
  1057. ret = -EINVAL;
  1058. goto out;
  1059. }
  1060. }
  1061. for (i = 0; i < dtcount; i++) {
  1062. int ilen;
  1063. unsigned int dlen = COMP_BUF_SIZE;
  1064. memset(result, 0, sizeof (result));
  1065. ilen = dtemplate[i].inlen;
  1066. ret = crypto_comp_decompress(tfm, dtemplate[i].input,
  1067. ilen, result, &dlen);
  1068. if (ret) {
  1069. printk(KERN_ERR "alg: comp: decompression failed "
  1070. "on test %d for %s: ret=%d\n", i + 1, algo,
  1071. -ret);
  1072. goto out;
  1073. }
  1074. if (dlen != dtemplate[i].outlen) {
  1075. printk(KERN_ERR "alg: comp: Decompression test %d "
  1076. "failed for %s: output len = %d\n", i + 1, algo,
  1077. dlen);
  1078. ret = -EINVAL;
  1079. goto out;
  1080. }
  1081. if (memcmp(result, dtemplate[i].output, dlen)) {
  1082. printk(KERN_ERR "alg: comp: Decompression test %d "
  1083. "failed for %s\n", i + 1, algo);
  1084. hexdump(result, dlen);
  1085. ret = -EINVAL;
  1086. goto out;
  1087. }
  1088. }
  1089. ret = 0;
  1090. out:
  1091. return ret;
  1092. }
  1093. static int test_pcomp(struct crypto_pcomp *tfm,
  1094. struct pcomp_testvec *ctemplate,
  1095. struct pcomp_testvec *dtemplate, int ctcount,
  1096. int dtcount)
  1097. {
  1098. const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
  1099. unsigned int i;
  1100. char result[COMP_BUF_SIZE];
  1101. int res;
  1102. for (i = 0; i < ctcount; i++) {
  1103. struct comp_request req;
  1104. unsigned int produced = 0;
  1105. res = crypto_compress_setup(tfm, ctemplate[i].params,
  1106. ctemplate[i].paramsize);
  1107. if (res) {
  1108. pr_err("alg: pcomp: compression setup failed on test "
  1109. "%d for %s: error=%d\n", i + 1, algo, res);
  1110. return res;
  1111. }
  1112. res = crypto_compress_init(tfm);
  1113. if (res) {
  1114. pr_err("alg: pcomp: compression init failed on test "
  1115. "%d for %s: error=%d\n", i + 1, algo, res);
  1116. return res;
  1117. }
  1118. memset(result, 0, sizeof(result));
  1119. req.next_in = ctemplate[i].input;
  1120. req.avail_in = ctemplate[i].inlen / 2;
  1121. req.next_out = result;
  1122. req.avail_out = ctemplate[i].outlen / 2;
  1123. res = crypto_compress_update(tfm, &req);
  1124. if (res < 0 && (res != -EAGAIN || req.avail_in)) {
  1125. pr_err("alg: pcomp: compression update failed on test "
  1126. "%d for %s: error=%d\n", i + 1, algo, res);
  1127. return res;
  1128. }
  1129. if (res > 0)
  1130. produced += res;
  1131. /* Add remaining input data */
  1132. req.avail_in += (ctemplate[i].inlen + 1) / 2;
  1133. res = crypto_compress_update(tfm, &req);
  1134. if (res < 0 && (res != -EAGAIN || req.avail_in)) {
  1135. pr_err("alg: pcomp: compression update failed on test "
  1136. "%d for %s: error=%d\n", i + 1, algo, res);
  1137. return res;
  1138. }
  1139. if (res > 0)
  1140. produced += res;
  1141. /* Provide remaining output space */
  1142. req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
  1143. res = crypto_compress_final(tfm, &req);
  1144. if (res < 0) {
  1145. pr_err("alg: pcomp: compression final failed on test "
  1146. "%d for %s: error=%d\n", i + 1, algo, res);
  1147. return res;
  1148. }
  1149. produced += res;
  1150. if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
  1151. pr_err("alg: comp: Compression test %d failed for %s: "
  1152. "output len = %d (expected %d)\n", i + 1, algo,
  1153. COMP_BUF_SIZE - req.avail_out,
  1154. ctemplate[i].outlen);
  1155. return -EINVAL;
  1156. }
  1157. if (produced != ctemplate[i].outlen) {
  1158. pr_err("alg: comp: Compression test %d failed for %s: "
  1159. "returned len = %u (expected %d)\n", i + 1,
  1160. algo, produced, ctemplate[i].outlen);
  1161. return -EINVAL;
  1162. }
  1163. if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
  1164. pr_err("alg: pcomp: Compression test %d failed for "
  1165. "%s\n", i + 1, algo);
  1166. hexdump(result, ctemplate[i].outlen);
  1167. return -EINVAL;
  1168. }
  1169. }
  1170. for (i = 0; i < dtcount; i++) {
  1171. struct comp_request req;
  1172. unsigned int produced = 0;
  1173. res = crypto_decompress_setup(tfm, dtemplate[i].params,
  1174. dtemplate[i].paramsize);
  1175. if (res) {
  1176. pr_err("alg: pcomp: decompression setup failed on "
  1177. "test %d for %s: error=%d\n", i + 1, algo, res);
  1178. return res;
  1179. }
  1180. res = crypto_decompress_init(tfm);
  1181. if (res) {
  1182. pr_err("alg: pcomp: decompression init failed on test "
  1183. "%d for %s: error=%d\n", i + 1, algo, res);
  1184. return res;
  1185. }
  1186. memset(result, 0, sizeof(result));
  1187. req.next_in = dtemplate[i].input;
  1188. req.avail_in = dtemplate[i].inlen / 2;
  1189. req.next_out = result;
  1190. req.avail_out = dtemplate[i].outlen / 2;
  1191. res = crypto_decompress_update(tfm, &req);
  1192. if (res < 0 && (res != -EAGAIN || req.avail_in)) {
  1193. pr_err("alg: pcomp: decompression update failed on "
  1194. "test %d for %s: error=%d\n", i + 1, algo, res);
  1195. return res;
  1196. }
  1197. if (res > 0)
  1198. produced += res;
  1199. /* Add remaining input data */
  1200. req.avail_in += (dtemplate[i].inlen + 1) / 2;
  1201. res = crypto_decompress_update(tfm, &req);
  1202. if (res < 0 && (res != -EAGAIN || req.avail_in)) {
  1203. pr_err("alg: pcomp: decompression update failed on "
  1204. "test %d for %s: error=%d\n", i + 1, algo, res);
  1205. return res;
  1206. }
  1207. if (res > 0)
  1208. produced += res;
  1209. /* Provide remaining output space */
  1210. req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
  1211. res = crypto_decompress_final(tfm, &req);
  1212. if (res < 0 && (res != -EAGAIN || req.avail_in)) {
  1213. pr_err("alg: pcomp: decompression final failed on "
  1214. "test %d for %s: error=%d\n", i + 1, algo, res);
  1215. return res;
  1216. }
  1217. if (res > 0)
  1218. produced += res;
  1219. if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
  1220. pr_err("alg: comp: Decompression test %d failed for "
  1221. "%s: output len = %d (expected %d)\n", i + 1,
  1222. algo, COMP_BUF_SIZE - req.avail_out,
  1223. dtemplate[i].outlen);
  1224. return -EINVAL;
  1225. }
  1226. if (produced != dtemplate[i].outlen) {
  1227. pr_err("alg: comp: Decompression test %d failed for "
  1228. "%s: returned len = %u (expected %d)\n", i + 1,
  1229. algo, produced, dtemplate[i].outlen);
  1230. return -EINVAL;
  1231. }
  1232. if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
  1233. pr_err("alg: pcomp: Decompression test %d failed for "
  1234. "%s\n", i + 1, algo);
  1235. hexdump(result, dtemplate[i].outlen);
  1236. return -EINVAL;
  1237. }
  1238. }
  1239. return 0;
  1240. }
  1241. static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
  1242. unsigned int tcount)
  1243. {
  1244. const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
  1245. int err = 0, i, j, seedsize;
  1246. u8 *seed;
  1247. char result[32];
  1248. seedsize = crypto_rng_seedsize(tfm);
  1249. seed = kmalloc(seedsize, GFP_KERNEL);
  1250. if (!seed) {
  1251. printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
  1252. "for %s\n", algo);
  1253. return -ENOMEM;
  1254. }
  1255. for (i = 0; i < tcount; i++) {
  1256. memset(result, 0, 32);
  1257. memcpy(seed, template[i].v, template[i].vlen);
  1258. memcpy(seed + template[i].vlen, template[i].key,
  1259. template[i].klen);
  1260. memcpy(seed + template[i].vlen + template[i].klen,
  1261. template[i].dt, template[i].dtlen);
  1262. err = crypto_rng_reset(tfm, seed, seedsize);
  1263. if (err) {
  1264. printk(KERN_ERR "alg: cprng: Failed to reset rng "
  1265. "for %s\n", algo);
  1266. goto out;
  1267. }
  1268. for (j = 0; j < template[i].loops; j++) {
  1269. err = crypto_rng_get_bytes(tfm, result,
  1270. template[i].rlen);
  1271. if (err < 0) {
  1272. printk(KERN_ERR "alg: cprng: Failed to obtain "
  1273. "the correct amount of random data for "
  1274. "%s (requested %d)\n", algo,
  1275. template[i].rlen);
  1276. goto out;
  1277. }
  1278. }
  1279. err = memcmp(result, template[i].result,
  1280. template[i].rlen);
  1281. if (err) {
  1282. printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
  1283. i, algo);
  1284. hexdump(result, template[i].rlen);
  1285. err = -EINVAL;
  1286. goto out;
  1287. }
  1288. }
  1289. out:
  1290. kfree(seed);
  1291. return err;
  1292. }
  1293. static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
  1294. u32 type, u32 mask)
  1295. {
  1296. struct crypto_aead *tfm;
  1297. int err = 0;
  1298. tfm = crypto_alloc_aead(driver, type | CRYPTO_ALG_INTERNAL, mask);
  1299. if (IS_ERR(tfm)) {
  1300. printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
  1301. "%ld\n", driver, PTR_ERR(tfm));
  1302. return PTR_ERR(tfm);
  1303. }
  1304. if (desc->suite.aead.enc.vecs) {
  1305. err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
  1306. desc->suite.aead.enc.count);
  1307. if (err)
  1308. goto out;
  1309. }
  1310. if (!err && desc->suite.aead.dec.vecs)
  1311. err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
  1312. desc->suite.aead.dec.count);
  1313. out:
  1314. crypto_free_aead(tfm);
  1315. return err;
  1316. }
  1317. static int alg_test_cipher(const struct alg_test_desc *desc,
  1318. const char *driver, u32 type, u32 mask)
  1319. {
  1320. struct crypto_cipher *tfm;
  1321. int err = 0;
  1322. tfm = crypto_alloc_cipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
  1323. if (IS_ERR(tfm)) {
  1324. printk(KERN_ERR "alg: cipher: Failed to load transform for "
  1325. "%s: %ld\n", driver, PTR_ERR(tfm));
  1326. return PTR_ERR(tfm);
  1327. }
  1328. if (desc->suite.cipher.enc.vecs) {
  1329. err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
  1330. desc->suite.cipher.enc.count);
  1331. if (err)
  1332. goto out;
  1333. }
  1334. if (desc->suite.cipher.dec.vecs)
  1335. err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
  1336. desc->suite.cipher.dec.count);
  1337. out:
  1338. crypto_free_cipher(tfm);
  1339. return err;
  1340. }
  1341. static int alg_test_skcipher(const struct alg_test_desc *desc,
  1342. const char *driver, u32 type, u32 mask)
  1343. {
  1344. struct crypto_skcipher *tfm;
  1345. int err = 0;
  1346. tfm = crypto_alloc_skcipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
  1347. if (IS_ERR(tfm)) {
  1348. printk(KERN_ERR "alg: skcipher: Failed to load transform for "
  1349. "%s: %ld\n", driver, PTR_ERR(tfm));
  1350. return PTR_ERR(tfm);
  1351. }
  1352. if (desc->suite.cipher.enc.vecs) {
  1353. err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
  1354. desc->suite.cipher.enc.count);
  1355. if (err)
  1356. goto out;
  1357. }
  1358. if (desc->suite.cipher.dec.vecs)
  1359. err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
  1360. desc->suite.cipher.dec.count);
  1361. out:
  1362. crypto_free_skcipher(tfm);
  1363. return err;
  1364. }
  1365. static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
  1366. u32 type, u32 mask)
  1367. {
  1368. struct crypto_comp *tfm;
  1369. int err;
  1370. tfm = crypto_alloc_comp(driver, type, mask);
  1371. if (IS_ERR(tfm)) {
  1372. printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
  1373. "%ld\n", driver, PTR_ERR(tfm));
  1374. return PTR_ERR(tfm);
  1375. }
  1376. err = test_comp(tfm, desc->suite.comp.comp.vecs,
  1377. desc->suite.comp.decomp.vecs,
  1378. desc->suite.comp.comp.count,
  1379. desc->suite.comp.decomp.count);
  1380. crypto_free_comp(tfm);
  1381. return err;
  1382. }
  1383. static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
  1384. u32 type, u32 mask)
  1385. {
  1386. struct crypto_pcomp *tfm;
  1387. int err;
  1388. tfm = crypto_alloc_pcomp(driver, type, mask);
  1389. if (IS_ERR(tfm)) {
  1390. pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
  1391. driver, PTR_ERR(tfm));
  1392. return PTR_ERR(tfm);
  1393. }
  1394. err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
  1395. desc->suite.pcomp.decomp.vecs,
  1396. desc->suite.pcomp.comp.count,
  1397. desc->suite.pcomp.decomp.count);
  1398. crypto_free_pcomp(tfm);
  1399. return err;
  1400. }
  1401. static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
  1402. u32 type, u32 mask)
  1403. {
  1404. struct crypto_ahash *tfm;
  1405. int err;
  1406. tfm = crypto_alloc_ahash(driver, type | CRYPTO_ALG_INTERNAL, mask);
  1407. if (IS_ERR(tfm)) {
  1408. printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
  1409. "%ld\n", driver, PTR_ERR(tfm));
  1410. return PTR_ERR(tfm);
  1411. }
  1412. err = test_hash(tfm, desc->suite.hash.vecs,
  1413. desc->suite.hash.count, true);
  1414. if (!err)
  1415. err = test_hash(tfm, desc->suite.hash.vecs,
  1416. desc->suite.hash.count, false);
  1417. crypto_free_ahash(tfm);
  1418. return err;
  1419. }
  1420. static int alg_test_crc32c(const struct alg_test_desc *desc,
  1421. const char *driver, u32 type, u32 mask)
  1422. {
  1423. struct crypto_shash *tfm;
  1424. u32 val;
  1425. int err;
  1426. err = alg_test_hash(desc, driver, type, mask);
  1427. if (err)
  1428. goto out;
  1429. tfm = crypto_alloc_shash(driver, type | CRYPTO_ALG_INTERNAL, mask);
  1430. if (IS_ERR(tfm)) {
  1431. printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
  1432. "%ld\n", driver, PTR_ERR(tfm));
  1433. err = PTR_ERR(tfm);
  1434. goto out;
  1435. }
  1436. do {
  1437. SHASH_DESC_ON_STACK(shash, tfm);
  1438. u32 *ctx = (u32 *)shash_desc_ctx(shash);
  1439. shash->tfm = tfm;
  1440. shash->flags = 0;
  1441. *ctx = le32_to_cpu(420553207);
  1442. err = crypto_shash_final(shash, (u8 *)&val);
  1443. if (err) {
  1444. printk(KERN_ERR "alg: crc32c: Operation failed for "
  1445. "%s: %d\n", driver, err);
  1446. break;
  1447. }
  1448. if (val != ~420553207) {
  1449. printk(KERN_ERR "alg: crc32c: Test failed for %s: "
  1450. "%d\n", driver, val);
  1451. err = -EINVAL;
  1452. }
  1453. } while (0);
  1454. crypto_free_shash(tfm);
  1455. out:
  1456. return err;
  1457. }
  1458. static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
  1459. u32 type, u32 mask)
  1460. {
  1461. struct crypto_rng *rng;
  1462. int err;
  1463. rng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
  1464. if (IS_ERR(rng)) {
  1465. printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
  1466. "%ld\n", driver, PTR_ERR(rng));
  1467. return PTR_ERR(rng);
  1468. }
  1469. err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
  1470. crypto_free_rng(rng);
  1471. return err;
  1472. }
  1473. static int drbg_cavs_test(struct drbg_testvec *test, int pr,
  1474. const char *driver, u32 type, u32 mask)
  1475. {
  1476. int ret = -EAGAIN;
  1477. struct crypto_rng *drng;
  1478. struct drbg_test_data test_data;
  1479. struct drbg_string addtl, pers, testentropy;
  1480. unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
  1481. if (!buf)
  1482. return -ENOMEM;
  1483. drng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
  1484. if (IS_ERR(drng)) {
  1485. printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
  1486. "%s\n", driver);
  1487. kzfree(buf);
  1488. return -ENOMEM;
  1489. }
  1490. test_data.testentropy = &testentropy;
  1491. drbg_string_fill(&testentropy, test->entropy, test->entropylen);
  1492. drbg_string_fill(&pers, test->pers, test->perslen);
  1493. ret = crypto_drbg_reset_test(drng, &pers, &test_data);
  1494. if (ret) {
  1495. printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
  1496. goto outbuf;
  1497. }
  1498. drbg_string_fill(&addtl, test->addtla, test->addtllen);
  1499. if (pr) {
  1500. drbg_string_fill(&testentropy, test->entpra, test->entprlen);
  1501. ret = crypto_drbg_get_bytes_addtl_test(drng,
  1502. buf, test->expectedlen, &addtl, &test_data);
  1503. } else {
  1504. ret = crypto_drbg_get_bytes_addtl(drng,
  1505. buf, test->expectedlen, &addtl);
  1506. }
  1507. if (ret < 0) {
  1508. printk(KERN_ERR "alg: drbg: could not obtain random data for "
  1509. "driver %s\n", driver);
  1510. goto outbuf;
  1511. }
  1512. drbg_string_fill(&addtl, test->addtlb, test->addtllen);
  1513. if (pr) {
  1514. drbg_string_fill(&testentropy, test->entprb, test->entprlen);
  1515. ret = crypto_drbg_get_bytes_addtl_test(drng,
  1516. buf, test->expectedlen, &addtl, &test_data);
  1517. } else {
  1518. ret = crypto_drbg_get_bytes_addtl(drng,
  1519. buf, test->expectedlen, &addtl);
  1520. }
  1521. if (ret < 0) {
  1522. printk(KERN_ERR "alg: drbg: could not obtain random data for "
  1523. "driver %s\n", driver);
  1524. goto outbuf;
  1525. }
  1526. ret = memcmp(test->expected, buf, test->expectedlen);
  1527. outbuf:
  1528. crypto_free_rng(drng);
  1529. kzfree(buf);
  1530. return ret;
  1531. }
  1532. static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
  1533. u32 type, u32 mask)
  1534. {
  1535. int err = 0;
  1536. int pr = 0;
  1537. int i = 0;
  1538. struct drbg_testvec *template = desc->suite.drbg.vecs;
  1539. unsigned int tcount = desc->suite.drbg.count;
  1540. if (0 == memcmp(driver, "drbg_pr_", 8))
  1541. pr = 1;
  1542. for (i = 0; i < tcount; i++) {
  1543. err = drbg_cavs_test(&template[i], pr, driver, type, mask);
  1544. if (err) {
  1545. printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
  1546. i, driver);
  1547. err = -EINVAL;
  1548. break;
  1549. }
  1550. }
  1551. return err;
  1552. }
  1553. static int do_test_rsa(struct crypto_akcipher *tfm,
  1554. struct akcipher_testvec *vecs)
  1555. {
  1556. struct akcipher_request *req;
  1557. void *outbuf_enc = NULL;
  1558. void *outbuf_dec = NULL;
  1559. struct tcrypt_result result;
  1560. unsigned int out_len_max, out_len = 0;
  1561. int err = -ENOMEM;
  1562. req = akcipher_request_alloc(tfm, GFP_KERNEL);
  1563. if (!req)
  1564. return err;
  1565. init_completion(&result.completion);
  1566. err = crypto_akcipher_setkey(tfm, vecs->key, vecs->key_len);
  1567. if (err)
  1568. goto free_req;
  1569. akcipher_request_set_crypt(req, vecs->m, outbuf_enc, vecs->m_size,
  1570. out_len);
  1571. /* expect this to fail, and update the required buf len */
  1572. crypto_akcipher_encrypt(req);
  1573. out_len = req->dst_len;
  1574. if (!out_len) {
  1575. err = -EINVAL;
  1576. goto free_req;
  1577. }
  1578. out_len_max = out_len;
  1579. err = -ENOMEM;
  1580. outbuf_enc = kzalloc(out_len_max, GFP_KERNEL);
  1581. if (!outbuf_enc)
  1582. goto free_req;
  1583. akcipher_request_set_crypt(req, vecs->m, outbuf_enc, vecs->m_size,
  1584. out_len);
  1585. akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  1586. tcrypt_complete, &result);
  1587. /* Run RSA encrypt - c = m^e mod n;*/
  1588. err = wait_async_op(&result, crypto_akcipher_encrypt(req));
  1589. if (err) {
  1590. pr_err("alg: rsa: encrypt test failed. err %d\n", err);
  1591. goto free_all;
  1592. }
  1593. if (out_len != vecs->c_size) {
  1594. pr_err("alg: rsa: encrypt test failed. Invalid output len\n");
  1595. err = -EINVAL;
  1596. goto free_all;
  1597. }
  1598. /* verify that encrypted message is equal to expected */
  1599. if (memcmp(vecs->c, outbuf_enc, vecs->c_size)) {
  1600. pr_err("alg: rsa: encrypt test failed. Invalid output\n");
  1601. err = -EINVAL;
  1602. goto free_all;
  1603. }
  1604. /* Don't invoke decrypt for vectors with public key */
  1605. if (vecs->public_key_vec) {
  1606. err = 0;
  1607. goto free_all;
  1608. }
  1609. outbuf_dec = kzalloc(out_len_max, GFP_KERNEL);
  1610. if (!outbuf_dec) {
  1611. err = -ENOMEM;
  1612. goto free_all;
  1613. }
  1614. init_completion(&result.completion);
  1615. akcipher_request_set_crypt(req, outbuf_enc, outbuf_dec, vecs->c_size,
  1616. out_len);
  1617. /* Run RSA decrypt - m = c^d mod n;*/
  1618. err = wait_async_op(&result, crypto_akcipher_decrypt(req));
  1619. if (err) {
  1620. pr_err("alg: rsa: decrypt test failed. err %d\n", err);
  1621. goto free_all;
  1622. }
  1623. out_len = req->dst_len;
  1624. if (out_len != vecs->m_size) {
  1625. pr_err("alg: rsa: decrypt test failed. Invalid output len\n");
  1626. err = -EINVAL;
  1627. goto free_all;
  1628. }
  1629. /* verify that decrypted message is equal to the original msg */
  1630. if (memcmp(vecs->m, outbuf_dec, vecs->m_size)) {
  1631. pr_err("alg: rsa: decrypt test failed. Invalid output\n");
  1632. err = -EINVAL;
  1633. }
  1634. free_all:
  1635. kfree(outbuf_dec);
  1636. kfree(outbuf_enc);
  1637. free_req:
  1638. akcipher_request_free(req);
  1639. return err;
  1640. }
  1641. static int test_rsa(struct crypto_akcipher *tfm, struct akcipher_testvec *vecs,
  1642. unsigned int tcount)
  1643. {
  1644. int ret, i;
  1645. for (i = 0; i < tcount; i++) {
  1646. ret = do_test_rsa(tfm, vecs++);
  1647. if (ret) {
  1648. pr_err("alg: rsa: test failed on vector %d, err=%d\n",
  1649. i + 1, ret);
  1650. return ret;
  1651. }
  1652. }
  1653. return 0;
  1654. }
  1655. static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
  1656. struct akcipher_testvec *vecs, unsigned int tcount)
  1657. {
  1658. if (strncmp(alg, "rsa", 3) == 0)
  1659. return test_rsa(tfm, vecs, tcount);
  1660. return 0;
  1661. }
  1662. static int alg_test_akcipher(const struct alg_test_desc *desc,
  1663. const char *driver, u32 type, u32 mask)
  1664. {
  1665. struct crypto_akcipher *tfm;
  1666. int err = 0;
  1667. tfm = crypto_alloc_akcipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
  1668. if (IS_ERR(tfm)) {
  1669. pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
  1670. driver, PTR_ERR(tfm));
  1671. return PTR_ERR(tfm);
  1672. }
  1673. if (desc->suite.akcipher.vecs)
  1674. err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs,
  1675. desc->suite.akcipher.count);
  1676. crypto_free_akcipher(tfm);
  1677. return err;
  1678. }
  1679. static int alg_test_null(const struct alg_test_desc *desc,
  1680. const char *driver, u32 type, u32 mask)
  1681. {
  1682. return 0;
  1683. }
  1684. /* Please keep this list sorted by algorithm name. */
  1685. static const struct alg_test_desc alg_test_descs[] = {
  1686. {
  1687. .alg = "__cbc-cast5-avx",
  1688. .test = alg_test_null,
  1689. }, {
  1690. .alg = "__cbc-cast6-avx",
  1691. .test = alg_test_null,
  1692. }, {
  1693. .alg = "__cbc-serpent-avx",
  1694. .test = alg_test_null,
  1695. }, {
  1696. .alg = "__cbc-serpent-avx2",
  1697. .test = alg_test_null,
  1698. }, {
  1699. .alg = "__cbc-serpent-sse2",
  1700. .test = alg_test_null,
  1701. }, {
  1702. .alg = "__cbc-twofish-avx",
  1703. .test = alg_test_null,
  1704. }, {
  1705. .alg = "__driver-cbc-aes-aesni",
  1706. .test = alg_test_null,
  1707. .fips_allowed = 1,
  1708. }, {
  1709. .alg = "__driver-cbc-camellia-aesni",
  1710. .test = alg_test_null,
  1711. }, {
  1712. .alg = "__driver-cbc-camellia-aesni-avx2",
  1713. .test = alg_test_null,
  1714. }, {
  1715. .alg = "__driver-cbc-cast5-avx",
  1716. .test = alg_test_null,
  1717. }, {
  1718. .alg = "__driver-cbc-cast6-avx",
  1719. .test = alg_test_null,
  1720. }, {
  1721. .alg = "__driver-cbc-serpent-avx",
  1722. .test = alg_test_null,
  1723. }, {
  1724. .alg = "__driver-cbc-serpent-avx2",
  1725. .test = alg_test_null,
  1726. }, {
  1727. .alg = "__driver-cbc-serpent-sse2",
  1728. .test = alg_test_null,
  1729. }, {
  1730. .alg = "__driver-cbc-twofish-avx",
  1731. .test = alg_test_null,
  1732. }, {
  1733. .alg = "__driver-ecb-aes-aesni",
  1734. .test = alg_test_null,
  1735. .fips_allowed = 1,
  1736. }, {
  1737. .alg = "__driver-ecb-camellia-aesni",
  1738. .test = alg_test_null,
  1739. }, {
  1740. .alg = "__driver-ecb-camellia-aesni-avx2",
  1741. .test = alg_test_null,
  1742. }, {
  1743. .alg = "__driver-ecb-cast5-avx",
  1744. .test = alg_test_null,
  1745. }, {
  1746. .alg = "__driver-ecb-cast6-avx",
  1747. .test = alg_test_null,
  1748. }, {
  1749. .alg = "__driver-ecb-serpent-avx",
  1750. .test = alg_test_null,
  1751. }, {
  1752. .alg = "__driver-ecb-serpent-avx2",
  1753. .test = alg_test_null,
  1754. }, {
  1755. .alg = "__driver-ecb-serpent-sse2",
  1756. .test = alg_test_null,
  1757. }, {
  1758. .alg = "__driver-ecb-twofish-avx",
  1759. .test = alg_test_null,
  1760. }, {
  1761. .alg = "__driver-gcm-aes-aesni",
  1762. .test = alg_test_null,
  1763. .fips_allowed = 1,
  1764. }, {
  1765. .alg = "__ghash-pclmulqdqni",
  1766. .test = alg_test_null,
  1767. .fips_allowed = 1,
  1768. }, {
  1769. .alg = "ansi_cprng",
  1770. .test = alg_test_cprng,
  1771. .fips_allowed = 1,
  1772. .suite = {
  1773. .cprng = {
  1774. .vecs = ansi_cprng_aes_tv_template,
  1775. .count = ANSI_CPRNG_AES_TEST_VECTORS
  1776. }
  1777. }
  1778. }, {
  1779. .alg = "authenc(hmac(md5),ecb(cipher_null))",
  1780. .test = alg_test_aead,
  1781. .fips_allowed = 1,
  1782. .suite = {
  1783. .aead = {
  1784. .enc = {
  1785. .vecs = hmac_md5_ecb_cipher_null_enc_tv_template,
  1786. .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
  1787. },
  1788. .dec = {
  1789. .vecs = hmac_md5_ecb_cipher_null_dec_tv_template,
  1790. .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
  1791. }
  1792. }
  1793. }
  1794. }, {
  1795. .alg = "authenc(hmac(sha1),cbc(aes))",
  1796. .test = alg_test_aead,
  1797. .fips_allowed = 1,
  1798. .suite = {
  1799. .aead = {
  1800. .enc = {
  1801. .vecs =
  1802. hmac_sha1_aes_cbc_enc_tv_temp,
  1803. .count =
  1804. HMAC_SHA1_AES_CBC_ENC_TEST_VEC
  1805. }
  1806. }
  1807. }
  1808. }, {
  1809. .alg = "authenc(hmac(sha1),cbc(des))",
  1810. .test = alg_test_aead,
  1811. .fips_allowed = 1,
  1812. .suite = {
  1813. .aead = {
  1814. .enc = {
  1815. .vecs =
  1816. hmac_sha1_des_cbc_enc_tv_temp,
  1817. .count =
  1818. HMAC_SHA1_DES_CBC_ENC_TEST_VEC
  1819. }
  1820. }
  1821. }
  1822. }, {
  1823. .alg = "authenc(hmac(sha1),cbc(des3_ede))",
  1824. .test = alg_test_aead,
  1825. .fips_allowed = 1,
  1826. .suite = {
  1827. .aead = {
  1828. .enc = {
  1829. .vecs =
  1830. hmac_sha1_des3_ede_cbc_enc_tv_temp,
  1831. .count =
  1832. HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
  1833. }
  1834. }
  1835. }
  1836. }, {
  1837. .alg = "authenc(hmac(sha1),ecb(cipher_null))",
  1838. .test = alg_test_aead,
  1839. .fips_allowed = 1,
  1840. .suite = {
  1841. .aead = {
  1842. .enc = {
  1843. .vecs =
  1844. hmac_sha1_ecb_cipher_null_enc_tv_temp,
  1845. .count =
  1846. HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
  1847. },
  1848. .dec = {
  1849. .vecs =
  1850. hmac_sha1_ecb_cipher_null_dec_tv_temp,
  1851. .count =
  1852. HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
  1853. }
  1854. }
  1855. }
  1856. }, {
  1857. .alg = "authenc(hmac(sha224),cbc(des))",
  1858. .test = alg_test_aead,
  1859. .fips_allowed = 1,
  1860. .suite = {
  1861. .aead = {
  1862. .enc = {
  1863. .vecs =
  1864. hmac_sha224_des_cbc_enc_tv_temp,
  1865. .count =
  1866. HMAC_SHA224_DES_CBC_ENC_TEST_VEC
  1867. }
  1868. }
  1869. }
  1870. }, {
  1871. .alg = "authenc(hmac(sha224),cbc(des3_ede))",
  1872. .test = alg_test_aead,
  1873. .fips_allowed = 1,
  1874. .suite = {
  1875. .aead = {
  1876. .enc = {
  1877. .vecs =
  1878. hmac_sha224_des3_ede_cbc_enc_tv_temp,
  1879. .count =
  1880. HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
  1881. }
  1882. }
  1883. }
  1884. }, {
  1885. .alg = "authenc(hmac(sha256),cbc(aes))",
  1886. .test = alg_test_aead,
  1887. .fips_allowed = 1,
  1888. .suite = {
  1889. .aead = {
  1890. .enc = {
  1891. .vecs =
  1892. hmac_sha256_aes_cbc_enc_tv_temp,
  1893. .count =
  1894. HMAC_SHA256_AES_CBC_ENC_TEST_VEC
  1895. }
  1896. }
  1897. }
  1898. }, {
  1899. .alg = "authenc(hmac(sha256),cbc(des))",
  1900. .test = alg_test_aead,
  1901. .fips_allowed = 1,
  1902. .suite = {
  1903. .aead = {
  1904. .enc = {
  1905. .vecs =
  1906. hmac_sha256_des_cbc_enc_tv_temp,
  1907. .count =
  1908. HMAC_SHA256_DES_CBC_ENC_TEST_VEC
  1909. }
  1910. }
  1911. }
  1912. }, {
  1913. .alg = "authenc(hmac(sha256),cbc(des3_ede))",
  1914. .test = alg_test_aead,
  1915. .fips_allowed = 1,
  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. .fips_allowed = 1,
  1930. .suite = {
  1931. .aead = {
  1932. .enc = {
  1933. .vecs =
  1934. hmac_sha384_des_cbc_enc_tv_temp,
  1935. .count =
  1936. HMAC_SHA384_DES_CBC_ENC_TEST_VEC
  1937. }
  1938. }
  1939. }
  1940. }, {
  1941. .alg = "authenc(hmac(sha384),cbc(des3_ede))",
  1942. .test = alg_test_aead,
  1943. .fips_allowed = 1,
  1944. .suite = {
  1945. .aead = {
  1946. .enc = {
  1947. .vecs =
  1948. hmac_sha384_des3_ede_cbc_enc_tv_temp,
  1949. .count =
  1950. HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
  1951. }
  1952. }
  1953. }
  1954. }, {
  1955. .alg = "authenc(hmac(sha512),cbc(aes))",
  1956. .test = alg_test_aead,
  1957. .fips_allowed = 1,
  1958. .suite = {
  1959. .aead = {
  1960. .enc = {
  1961. .vecs =
  1962. hmac_sha512_aes_cbc_enc_tv_temp,
  1963. .count =
  1964. HMAC_SHA512_AES_CBC_ENC_TEST_VEC
  1965. }
  1966. }
  1967. }
  1968. }, {
  1969. .alg = "authenc(hmac(sha512),cbc(des))",
  1970. .test = alg_test_aead,
  1971. .fips_allowed = 1,
  1972. .suite = {
  1973. .aead = {
  1974. .enc = {
  1975. .vecs =
  1976. hmac_sha512_des_cbc_enc_tv_temp,
  1977. .count =
  1978. HMAC_SHA512_DES_CBC_ENC_TEST_VEC
  1979. }
  1980. }
  1981. }
  1982. }, {
  1983. .alg = "authenc(hmac(sha512),cbc(des3_ede))",
  1984. .test = alg_test_aead,
  1985. .fips_allowed = 1,
  1986. .suite = {
  1987. .aead = {
  1988. .enc = {
  1989. .vecs =
  1990. hmac_sha512_des3_ede_cbc_enc_tv_temp,
  1991. .count =
  1992. HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
  1993. }
  1994. }
  1995. }
  1996. }, {
  1997. .alg = "cbc(aes)",
  1998. .test = alg_test_skcipher,
  1999. .fips_allowed = 1,
  2000. .suite = {
  2001. .cipher = {
  2002. .enc = {
  2003. .vecs = aes_cbc_enc_tv_template,
  2004. .count = AES_CBC_ENC_TEST_VECTORS
  2005. },
  2006. .dec = {
  2007. .vecs = aes_cbc_dec_tv_template,
  2008. .count = AES_CBC_DEC_TEST_VECTORS
  2009. }
  2010. }
  2011. }
  2012. }, {
  2013. .alg = "cbc(anubis)",
  2014. .test = alg_test_skcipher,
  2015. .suite = {
  2016. .cipher = {
  2017. .enc = {
  2018. .vecs = anubis_cbc_enc_tv_template,
  2019. .count = ANUBIS_CBC_ENC_TEST_VECTORS
  2020. },
  2021. .dec = {
  2022. .vecs = anubis_cbc_dec_tv_template,
  2023. .count = ANUBIS_CBC_DEC_TEST_VECTORS
  2024. }
  2025. }
  2026. }
  2027. }, {
  2028. .alg = "cbc(blowfish)",
  2029. .test = alg_test_skcipher,
  2030. .suite = {
  2031. .cipher = {
  2032. .enc = {
  2033. .vecs = bf_cbc_enc_tv_template,
  2034. .count = BF_CBC_ENC_TEST_VECTORS
  2035. },
  2036. .dec = {
  2037. .vecs = bf_cbc_dec_tv_template,
  2038. .count = BF_CBC_DEC_TEST_VECTORS
  2039. }
  2040. }
  2041. }
  2042. }, {
  2043. .alg = "cbc(camellia)",
  2044. .test = alg_test_skcipher,
  2045. .suite = {
  2046. .cipher = {
  2047. .enc = {
  2048. .vecs = camellia_cbc_enc_tv_template,
  2049. .count = CAMELLIA_CBC_ENC_TEST_VECTORS
  2050. },
  2051. .dec = {
  2052. .vecs = camellia_cbc_dec_tv_template,
  2053. .count = CAMELLIA_CBC_DEC_TEST_VECTORS
  2054. }
  2055. }
  2056. }
  2057. }, {
  2058. .alg = "cbc(cast5)",
  2059. .test = alg_test_skcipher,
  2060. .suite = {
  2061. .cipher = {
  2062. .enc = {
  2063. .vecs = cast5_cbc_enc_tv_template,
  2064. .count = CAST5_CBC_ENC_TEST_VECTORS
  2065. },
  2066. .dec = {
  2067. .vecs = cast5_cbc_dec_tv_template,
  2068. .count = CAST5_CBC_DEC_TEST_VECTORS
  2069. }
  2070. }
  2071. }
  2072. }, {
  2073. .alg = "cbc(cast6)",
  2074. .test = alg_test_skcipher,
  2075. .suite = {
  2076. .cipher = {
  2077. .enc = {
  2078. .vecs = cast6_cbc_enc_tv_template,
  2079. .count = CAST6_CBC_ENC_TEST_VECTORS
  2080. },
  2081. .dec = {
  2082. .vecs = cast6_cbc_dec_tv_template,
  2083. .count = CAST6_CBC_DEC_TEST_VECTORS
  2084. }
  2085. }
  2086. }
  2087. }, {
  2088. .alg = "cbc(des)",
  2089. .test = alg_test_skcipher,
  2090. .suite = {
  2091. .cipher = {
  2092. .enc = {
  2093. .vecs = des_cbc_enc_tv_template,
  2094. .count = DES_CBC_ENC_TEST_VECTORS
  2095. },
  2096. .dec = {
  2097. .vecs = des_cbc_dec_tv_template,
  2098. .count = DES_CBC_DEC_TEST_VECTORS
  2099. }
  2100. }
  2101. }
  2102. }, {
  2103. .alg = "cbc(des3_ede)",
  2104. .test = alg_test_skcipher,
  2105. .fips_allowed = 1,
  2106. .suite = {
  2107. .cipher = {
  2108. .enc = {
  2109. .vecs = des3_ede_cbc_enc_tv_template,
  2110. .count = DES3_EDE_CBC_ENC_TEST_VECTORS
  2111. },
  2112. .dec = {
  2113. .vecs = des3_ede_cbc_dec_tv_template,
  2114. .count = DES3_EDE_CBC_DEC_TEST_VECTORS
  2115. }
  2116. }
  2117. }
  2118. }, {
  2119. .alg = "cbc(serpent)",
  2120. .test = alg_test_skcipher,
  2121. .suite = {
  2122. .cipher = {
  2123. .enc = {
  2124. .vecs = serpent_cbc_enc_tv_template,
  2125. .count = SERPENT_CBC_ENC_TEST_VECTORS
  2126. },
  2127. .dec = {
  2128. .vecs = serpent_cbc_dec_tv_template,
  2129. .count = SERPENT_CBC_DEC_TEST_VECTORS
  2130. }
  2131. }
  2132. }
  2133. }, {
  2134. .alg = "cbc(twofish)",
  2135. .test = alg_test_skcipher,
  2136. .suite = {
  2137. .cipher = {
  2138. .enc = {
  2139. .vecs = tf_cbc_enc_tv_template,
  2140. .count = TF_CBC_ENC_TEST_VECTORS
  2141. },
  2142. .dec = {
  2143. .vecs = tf_cbc_dec_tv_template,
  2144. .count = TF_CBC_DEC_TEST_VECTORS
  2145. }
  2146. }
  2147. }
  2148. }, {
  2149. .alg = "ccm(aes)",
  2150. .test = alg_test_aead,
  2151. .fips_allowed = 1,
  2152. .suite = {
  2153. .aead = {
  2154. .enc = {
  2155. .vecs = aes_ccm_enc_tv_template,
  2156. .count = AES_CCM_ENC_TEST_VECTORS
  2157. },
  2158. .dec = {
  2159. .vecs = aes_ccm_dec_tv_template,
  2160. .count = AES_CCM_DEC_TEST_VECTORS
  2161. }
  2162. }
  2163. }
  2164. }, {
  2165. .alg = "chacha20",
  2166. .test = alg_test_skcipher,
  2167. .suite = {
  2168. .cipher = {
  2169. .enc = {
  2170. .vecs = chacha20_enc_tv_template,
  2171. .count = CHACHA20_ENC_TEST_VECTORS
  2172. },
  2173. .dec = {
  2174. .vecs = chacha20_enc_tv_template,
  2175. .count = CHACHA20_ENC_TEST_VECTORS
  2176. },
  2177. }
  2178. }
  2179. }, {
  2180. .alg = "cmac(aes)",
  2181. .fips_allowed = 1,
  2182. .test = alg_test_hash,
  2183. .suite = {
  2184. .hash = {
  2185. .vecs = aes_cmac128_tv_template,
  2186. .count = CMAC_AES_TEST_VECTORS
  2187. }
  2188. }
  2189. }, {
  2190. .alg = "cmac(des3_ede)",
  2191. .fips_allowed = 1,
  2192. .test = alg_test_hash,
  2193. .suite = {
  2194. .hash = {
  2195. .vecs = des3_ede_cmac64_tv_template,
  2196. .count = CMAC_DES3_EDE_TEST_VECTORS
  2197. }
  2198. }
  2199. }, {
  2200. .alg = "compress_null",
  2201. .test = alg_test_null,
  2202. }, {
  2203. .alg = "crc32",
  2204. .test = alg_test_hash,
  2205. .suite = {
  2206. .hash = {
  2207. .vecs = crc32_tv_template,
  2208. .count = CRC32_TEST_VECTORS
  2209. }
  2210. }
  2211. }, {
  2212. .alg = "crc32c",
  2213. .test = alg_test_crc32c,
  2214. .fips_allowed = 1,
  2215. .suite = {
  2216. .hash = {
  2217. .vecs = crc32c_tv_template,
  2218. .count = CRC32C_TEST_VECTORS
  2219. }
  2220. }
  2221. }, {
  2222. .alg = "crct10dif",
  2223. .test = alg_test_hash,
  2224. .fips_allowed = 1,
  2225. .suite = {
  2226. .hash = {
  2227. .vecs = crct10dif_tv_template,
  2228. .count = CRCT10DIF_TEST_VECTORS
  2229. }
  2230. }
  2231. }, {
  2232. .alg = "cryptd(__driver-cbc-aes-aesni)",
  2233. .test = alg_test_null,
  2234. .fips_allowed = 1,
  2235. }, {
  2236. .alg = "cryptd(__driver-cbc-camellia-aesni)",
  2237. .test = alg_test_null,
  2238. }, {
  2239. .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
  2240. .test = alg_test_null,
  2241. }, {
  2242. .alg = "cryptd(__driver-cbc-serpent-avx2)",
  2243. .test = alg_test_null,
  2244. }, {
  2245. .alg = "cryptd(__driver-ecb-aes-aesni)",
  2246. .test = alg_test_null,
  2247. .fips_allowed = 1,
  2248. }, {
  2249. .alg = "cryptd(__driver-ecb-camellia-aesni)",
  2250. .test = alg_test_null,
  2251. }, {
  2252. .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
  2253. .test = alg_test_null,
  2254. }, {
  2255. .alg = "cryptd(__driver-ecb-cast5-avx)",
  2256. .test = alg_test_null,
  2257. }, {
  2258. .alg = "cryptd(__driver-ecb-cast6-avx)",
  2259. .test = alg_test_null,
  2260. }, {
  2261. .alg = "cryptd(__driver-ecb-serpent-avx)",
  2262. .test = alg_test_null,
  2263. }, {
  2264. .alg = "cryptd(__driver-ecb-serpent-avx2)",
  2265. .test = alg_test_null,
  2266. }, {
  2267. .alg = "cryptd(__driver-ecb-serpent-sse2)",
  2268. .test = alg_test_null,
  2269. }, {
  2270. .alg = "cryptd(__driver-ecb-twofish-avx)",
  2271. .test = alg_test_null,
  2272. }, {
  2273. .alg = "cryptd(__driver-gcm-aes-aesni)",
  2274. .test = alg_test_null,
  2275. .fips_allowed = 1,
  2276. }, {
  2277. .alg = "cryptd(__ghash-pclmulqdqni)",
  2278. .test = alg_test_null,
  2279. .fips_allowed = 1,
  2280. }, {
  2281. .alg = "ctr(aes)",
  2282. .test = alg_test_skcipher,
  2283. .fips_allowed = 1,
  2284. .suite = {
  2285. .cipher = {
  2286. .enc = {
  2287. .vecs = aes_ctr_enc_tv_template,
  2288. .count = AES_CTR_ENC_TEST_VECTORS
  2289. },
  2290. .dec = {
  2291. .vecs = aes_ctr_dec_tv_template,
  2292. .count = AES_CTR_DEC_TEST_VECTORS
  2293. }
  2294. }
  2295. }
  2296. }, {
  2297. .alg = "ctr(blowfish)",
  2298. .test = alg_test_skcipher,
  2299. .suite = {
  2300. .cipher = {
  2301. .enc = {
  2302. .vecs = bf_ctr_enc_tv_template,
  2303. .count = BF_CTR_ENC_TEST_VECTORS
  2304. },
  2305. .dec = {
  2306. .vecs = bf_ctr_dec_tv_template,
  2307. .count = BF_CTR_DEC_TEST_VECTORS
  2308. }
  2309. }
  2310. }
  2311. }, {
  2312. .alg = "ctr(camellia)",
  2313. .test = alg_test_skcipher,
  2314. .suite = {
  2315. .cipher = {
  2316. .enc = {
  2317. .vecs = camellia_ctr_enc_tv_template,
  2318. .count = CAMELLIA_CTR_ENC_TEST_VECTORS
  2319. },
  2320. .dec = {
  2321. .vecs = camellia_ctr_dec_tv_template,
  2322. .count = CAMELLIA_CTR_DEC_TEST_VECTORS
  2323. }
  2324. }
  2325. }
  2326. }, {
  2327. .alg = "ctr(cast5)",
  2328. .test = alg_test_skcipher,
  2329. .suite = {
  2330. .cipher = {
  2331. .enc = {
  2332. .vecs = cast5_ctr_enc_tv_template,
  2333. .count = CAST5_CTR_ENC_TEST_VECTORS
  2334. },
  2335. .dec = {
  2336. .vecs = cast5_ctr_dec_tv_template,
  2337. .count = CAST5_CTR_DEC_TEST_VECTORS
  2338. }
  2339. }
  2340. }
  2341. }, {
  2342. .alg = "ctr(cast6)",
  2343. .test = alg_test_skcipher,
  2344. .suite = {
  2345. .cipher = {
  2346. .enc = {
  2347. .vecs = cast6_ctr_enc_tv_template,
  2348. .count = CAST6_CTR_ENC_TEST_VECTORS
  2349. },
  2350. .dec = {
  2351. .vecs = cast6_ctr_dec_tv_template,
  2352. .count = CAST6_CTR_DEC_TEST_VECTORS
  2353. }
  2354. }
  2355. }
  2356. }, {
  2357. .alg = "ctr(des)",
  2358. .test = alg_test_skcipher,
  2359. .suite = {
  2360. .cipher = {
  2361. .enc = {
  2362. .vecs = des_ctr_enc_tv_template,
  2363. .count = DES_CTR_ENC_TEST_VECTORS
  2364. },
  2365. .dec = {
  2366. .vecs = des_ctr_dec_tv_template,
  2367. .count = DES_CTR_DEC_TEST_VECTORS
  2368. }
  2369. }
  2370. }
  2371. }, {
  2372. .alg = "ctr(des3_ede)",
  2373. .test = alg_test_skcipher,
  2374. .suite = {
  2375. .cipher = {
  2376. .enc = {
  2377. .vecs = des3_ede_ctr_enc_tv_template,
  2378. .count = DES3_EDE_CTR_ENC_TEST_VECTORS
  2379. },
  2380. .dec = {
  2381. .vecs = des3_ede_ctr_dec_tv_template,
  2382. .count = DES3_EDE_CTR_DEC_TEST_VECTORS
  2383. }
  2384. }
  2385. }
  2386. }, {
  2387. .alg = "ctr(serpent)",
  2388. .test = alg_test_skcipher,
  2389. .suite = {
  2390. .cipher = {
  2391. .enc = {
  2392. .vecs = serpent_ctr_enc_tv_template,
  2393. .count = SERPENT_CTR_ENC_TEST_VECTORS
  2394. },
  2395. .dec = {
  2396. .vecs = serpent_ctr_dec_tv_template,
  2397. .count = SERPENT_CTR_DEC_TEST_VECTORS
  2398. }
  2399. }
  2400. }
  2401. }, {
  2402. .alg = "ctr(twofish)",
  2403. .test = alg_test_skcipher,
  2404. .suite = {
  2405. .cipher = {
  2406. .enc = {
  2407. .vecs = tf_ctr_enc_tv_template,
  2408. .count = TF_CTR_ENC_TEST_VECTORS
  2409. },
  2410. .dec = {
  2411. .vecs = tf_ctr_dec_tv_template,
  2412. .count = TF_CTR_DEC_TEST_VECTORS
  2413. }
  2414. }
  2415. }
  2416. }, {
  2417. .alg = "cts(cbc(aes))",
  2418. .test = alg_test_skcipher,
  2419. .suite = {
  2420. .cipher = {
  2421. .enc = {
  2422. .vecs = cts_mode_enc_tv_template,
  2423. .count = CTS_MODE_ENC_TEST_VECTORS
  2424. },
  2425. .dec = {
  2426. .vecs = cts_mode_dec_tv_template,
  2427. .count = CTS_MODE_DEC_TEST_VECTORS
  2428. }
  2429. }
  2430. }
  2431. }, {
  2432. .alg = "deflate",
  2433. .test = alg_test_comp,
  2434. .fips_allowed = 1,
  2435. .suite = {
  2436. .comp = {
  2437. .comp = {
  2438. .vecs = deflate_comp_tv_template,
  2439. .count = DEFLATE_COMP_TEST_VECTORS
  2440. },
  2441. .decomp = {
  2442. .vecs = deflate_decomp_tv_template,
  2443. .count = DEFLATE_DECOMP_TEST_VECTORS
  2444. }
  2445. }
  2446. }
  2447. }, {
  2448. .alg = "digest_null",
  2449. .test = alg_test_null,
  2450. }, {
  2451. .alg = "drbg_nopr_ctr_aes128",
  2452. .test = alg_test_drbg,
  2453. .fips_allowed = 1,
  2454. .suite = {
  2455. .drbg = {
  2456. .vecs = drbg_nopr_ctr_aes128_tv_template,
  2457. .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
  2458. }
  2459. }
  2460. }, {
  2461. .alg = "drbg_nopr_ctr_aes192",
  2462. .test = alg_test_drbg,
  2463. .fips_allowed = 1,
  2464. .suite = {
  2465. .drbg = {
  2466. .vecs = drbg_nopr_ctr_aes192_tv_template,
  2467. .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
  2468. }
  2469. }
  2470. }, {
  2471. .alg = "drbg_nopr_ctr_aes256",
  2472. .test = alg_test_drbg,
  2473. .fips_allowed = 1,
  2474. .suite = {
  2475. .drbg = {
  2476. .vecs = drbg_nopr_ctr_aes256_tv_template,
  2477. .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
  2478. }
  2479. }
  2480. }, {
  2481. /*
  2482. * There is no need to specifically test the DRBG with every
  2483. * backend cipher -- covered by drbg_nopr_hmac_sha256 test
  2484. */
  2485. .alg = "drbg_nopr_hmac_sha1",
  2486. .fips_allowed = 1,
  2487. .test = alg_test_null,
  2488. }, {
  2489. .alg = "drbg_nopr_hmac_sha256",
  2490. .test = alg_test_drbg,
  2491. .fips_allowed = 1,
  2492. .suite = {
  2493. .drbg = {
  2494. .vecs = drbg_nopr_hmac_sha256_tv_template,
  2495. .count =
  2496. ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
  2497. }
  2498. }
  2499. }, {
  2500. /* covered by drbg_nopr_hmac_sha256 test */
  2501. .alg = "drbg_nopr_hmac_sha384",
  2502. .fips_allowed = 1,
  2503. .test = alg_test_null,
  2504. }, {
  2505. .alg = "drbg_nopr_hmac_sha512",
  2506. .test = alg_test_null,
  2507. .fips_allowed = 1,
  2508. }, {
  2509. .alg = "drbg_nopr_sha1",
  2510. .fips_allowed = 1,
  2511. .test = alg_test_null,
  2512. }, {
  2513. .alg = "drbg_nopr_sha256",
  2514. .test = alg_test_drbg,
  2515. .fips_allowed = 1,
  2516. .suite = {
  2517. .drbg = {
  2518. .vecs = drbg_nopr_sha256_tv_template,
  2519. .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
  2520. }
  2521. }
  2522. }, {
  2523. /* covered by drbg_nopr_sha256 test */
  2524. .alg = "drbg_nopr_sha384",
  2525. .fips_allowed = 1,
  2526. .test = alg_test_null,
  2527. }, {
  2528. .alg = "drbg_nopr_sha512",
  2529. .fips_allowed = 1,
  2530. .test = alg_test_null,
  2531. }, {
  2532. .alg = "drbg_pr_ctr_aes128",
  2533. .test = alg_test_drbg,
  2534. .fips_allowed = 1,
  2535. .suite = {
  2536. .drbg = {
  2537. .vecs = drbg_pr_ctr_aes128_tv_template,
  2538. .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
  2539. }
  2540. }
  2541. }, {
  2542. /* covered by drbg_pr_ctr_aes128 test */
  2543. .alg = "drbg_pr_ctr_aes192",
  2544. .fips_allowed = 1,
  2545. .test = alg_test_null,
  2546. }, {
  2547. .alg = "drbg_pr_ctr_aes256",
  2548. .fips_allowed = 1,
  2549. .test = alg_test_null,
  2550. }, {
  2551. .alg = "drbg_pr_hmac_sha1",
  2552. .fips_allowed = 1,
  2553. .test = alg_test_null,
  2554. }, {
  2555. .alg = "drbg_pr_hmac_sha256",
  2556. .test = alg_test_drbg,
  2557. .fips_allowed = 1,
  2558. .suite = {
  2559. .drbg = {
  2560. .vecs = drbg_pr_hmac_sha256_tv_template,
  2561. .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
  2562. }
  2563. }
  2564. }, {
  2565. /* covered by drbg_pr_hmac_sha256 test */
  2566. .alg = "drbg_pr_hmac_sha384",
  2567. .fips_allowed = 1,
  2568. .test = alg_test_null,
  2569. }, {
  2570. .alg = "drbg_pr_hmac_sha512",
  2571. .test = alg_test_null,
  2572. .fips_allowed = 1,
  2573. }, {
  2574. .alg = "drbg_pr_sha1",
  2575. .fips_allowed = 1,
  2576. .test = alg_test_null,
  2577. }, {
  2578. .alg = "drbg_pr_sha256",
  2579. .test = alg_test_drbg,
  2580. .fips_allowed = 1,
  2581. .suite = {
  2582. .drbg = {
  2583. .vecs = drbg_pr_sha256_tv_template,
  2584. .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
  2585. }
  2586. }
  2587. }, {
  2588. /* covered by drbg_pr_sha256 test */
  2589. .alg = "drbg_pr_sha384",
  2590. .fips_allowed = 1,
  2591. .test = alg_test_null,
  2592. }, {
  2593. .alg = "drbg_pr_sha512",
  2594. .fips_allowed = 1,
  2595. .test = alg_test_null,
  2596. }, {
  2597. .alg = "ecb(__aes-aesni)",
  2598. .test = alg_test_null,
  2599. .fips_allowed = 1,
  2600. }, {
  2601. .alg = "ecb(aes)",
  2602. .test = alg_test_skcipher,
  2603. .fips_allowed = 1,
  2604. .suite = {
  2605. .cipher = {
  2606. .enc = {
  2607. .vecs = aes_enc_tv_template,
  2608. .count = AES_ENC_TEST_VECTORS
  2609. },
  2610. .dec = {
  2611. .vecs = aes_dec_tv_template,
  2612. .count = AES_DEC_TEST_VECTORS
  2613. }
  2614. }
  2615. }
  2616. }, {
  2617. .alg = "ecb(anubis)",
  2618. .test = alg_test_skcipher,
  2619. .suite = {
  2620. .cipher = {
  2621. .enc = {
  2622. .vecs = anubis_enc_tv_template,
  2623. .count = ANUBIS_ENC_TEST_VECTORS
  2624. },
  2625. .dec = {
  2626. .vecs = anubis_dec_tv_template,
  2627. .count = ANUBIS_DEC_TEST_VECTORS
  2628. }
  2629. }
  2630. }
  2631. }, {
  2632. .alg = "ecb(arc4)",
  2633. .test = alg_test_skcipher,
  2634. .suite = {
  2635. .cipher = {
  2636. .enc = {
  2637. .vecs = arc4_enc_tv_template,
  2638. .count = ARC4_ENC_TEST_VECTORS
  2639. },
  2640. .dec = {
  2641. .vecs = arc4_dec_tv_template,
  2642. .count = ARC4_DEC_TEST_VECTORS
  2643. }
  2644. }
  2645. }
  2646. }, {
  2647. .alg = "ecb(blowfish)",
  2648. .test = alg_test_skcipher,
  2649. .suite = {
  2650. .cipher = {
  2651. .enc = {
  2652. .vecs = bf_enc_tv_template,
  2653. .count = BF_ENC_TEST_VECTORS
  2654. },
  2655. .dec = {
  2656. .vecs = bf_dec_tv_template,
  2657. .count = BF_DEC_TEST_VECTORS
  2658. }
  2659. }
  2660. }
  2661. }, {
  2662. .alg = "ecb(camellia)",
  2663. .test = alg_test_skcipher,
  2664. .suite = {
  2665. .cipher = {
  2666. .enc = {
  2667. .vecs = camellia_enc_tv_template,
  2668. .count = CAMELLIA_ENC_TEST_VECTORS
  2669. },
  2670. .dec = {
  2671. .vecs = camellia_dec_tv_template,
  2672. .count = CAMELLIA_DEC_TEST_VECTORS
  2673. }
  2674. }
  2675. }
  2676. }, {
  2677. .alg = "ecb(cast5)",
  2678. .test = alg_test_skcipher,
  2679. .suite = {
  2680. .cipher = {
  2681. .enc = {
  2682. .vecs = cast5_enc_tv_template,
  2683. .count = CAST5_ENC_TEST_VECTORS
  2684. },
  2685. .dec = {
  2686. .vecs = cast5_dec_tv_template,
  2687. .count = CAST5_DEC_TEST_VECTORS
  2688. }
  2689. }
  2690. }
  2691. }, {
  2692. .alg = "ecb(cast6)",
  2693. .test = alg_test_skcipher,
  2694. .suite = {
  2695. .cipher = {
  2696. .enc = {
  2697. .vecs = cast6_enc_tv_template,
  2698. .count = CAST6_ENC_TEST_VECTORS
  2699. },
  2700. .dec = {
  2701. .vecs = cast6_dec_tv_template,
  2702. .count = CAST6_DEC_TEST_VECTORS
  2703. }
  2704. }
  2705. }
  2706. }, {
  2707. .alg = "ecb(cipher_null)",
  2708. .test = alg_test_null,
  2709. }, {
  2710. .alg = "ecb(des)",
  2711. .test = alg_test_skcipher,
  2712. .fips_allowed = 1,
  2713. .suite = {
  2714. .cipher = {
  2715. .enc = {
  2716. .vecs = des_enc_tv_template,
  2717. .count = DES_ENC_TEST_VECTORS
  2718. },
  2719. .dec = {
  2720. .vecs = des_dec_tv_template,
  2721. .count = DES_DEC_TEST_VECTORS
  2722. }
  2723. }
  2724. }
  2725. }, {
  2726. .alg = "ecb(des3_ede)",
  2727. .test = alg_test_skcipher,
  2728. .fips_allowed = 1,
  2729. .suite = {
  2730. .cipher = {
  2731. .enc = {
  2732. .vecs = des3_ede_enc_tv_template,
  2733. .count = DES3_EDE_ENC_TEST_VECTORS
  2734. },
  2735. .dec = {
  2736. .vecs = des3_ede_dec_tv_template,
  2737. .count = DES3_EDE_DEC_TEST_VECTORS
  2738. }
  2739. }
  2740. }
  2741. }, {
  2742. .alg = "ecb(fcrypt)",
  2743. .test = alg_test_skcipher,
  2744. .suite = {
  2745. .cipher = {
  2746. .enc = {
  2747. .vecs = fcrypt_pcbc_enc_tv_template,
  2748. .count = 1
  2749. },
  2750. .dec = {
  2751. .vecs = fcrypt_pcbc_dec_tv_template,
  2752. .count = 1
  2753. }
  2754. }
  2755. }
  2756. }, {
  2757. .alg = "ecb(khazad)",
  2758. .test = alg_test_skcipher,
  2759. .suite = {
  2760. .cipher = {
  2761. .enc = {
  2762. .vecs = khazad_enc_tv_template,
  2763. .count = KHAZAD_ENC_TEST_VECTORS
  2764. },
  2765. .dec = {
  2766. .vecs = khazad_dec_tv_template,
  2767. .count = KHAZAD_DEC_TEST_VECTORS
  2768. }
  2769. }
  2770. }
  2771. }, {
  2772. .alg = "ecb(seed)",
  2773. .test = alg_test_skcipher,
  2774. .suite = {
  2775. .cipher = {
  2776. .enc = {
  2777. .vecs = seed_enc_tv_template,
  2778. .count = SEED_ENC_TEST_VECTORS
  2779. },
  2780. .dec = {
  2781. .vecs = seed_dec_tv_template,
  2782. .count = SEED_DEC_TEST_VECTORS
  2783. }
  2784. }
  2785. }
  2786. }, {
  2787. .alg = "ecb(serpent)",
  2788. .test = alg_test_skcipher,
  2789. .suite = {
  2790. .cipher = {
  2791. .enc = {
  2792. .vecs = serpent_enc_tv_template,
  2793. .count = SERPENT_ENC_TEST_VECTORS
  2794. },
  2795. .dec = {
  2796. .vecs = serpent_dec_tv_template,
  2797. .count = SERPENT_DEC_TEST_VECTORS
  2798. }
  2799. }
  2800. }
  2801. }, {
  2802. .alg = "ecb(tea)",
  2803. .test = alg_test_skcipher,
  2804. .suite = {
  2805. .cipher = {
  2806. .enc = {
  2807. .vecs = tea_enc_tv_template,
  2808. .count = TEA_ENC_TEST_VECTORS
  2809. },
  2810. .dec = {
  2811. .vecs = tea_dec_tv_template,
  2812. .count = TEA_DEC_TEST_VECTORS
  2813. }
  2814. }
  2815. }
  2816. }, {
  2817. .alg = "ecb(tnepres)",
  2818. .test = alg_test_skcipher,
  2819. .suite = {
  2820. .cipher = {
  2821. .enc = {
  2822. .vecs = tnepres_enc_tv_template,
  2823. .count = TNEPRES_ENC_TEST_VECTORS
  2824. },
  2825. .dec = {
  2826. .vecs = tnepres_dec_tv_template,
  2827. .count = TNEPRES_DEC_TEST_VECTORS
  2828. }
  2829. }
  2830. }
  2831. }, {
  2832. .alg = "ecb(twofish)",
  2833. .test = alg_test_skcipher,
  2834. .suite = {
  2835. .cipher = {
  2836. .enc = {
  2837. .vecs = tf_enc_tv_template,
  2838. .count = TF_ENC_TEST_VECTORS
  2839. },
  2840. .dec = {
  2841. .vecs = tf_dec_tv_template,
  2842. .count = TF_DEC_TEST_VECTORS
  2843. }
  2844. }
  2845. }
  2846. }, {
  2847. .alg = "ecb(xeta)",
  2848. .test = alg_test_skcipher,
  2849. .suite = {
  2850. .cipher = {
  2851. .enc = {
  2852. .vecs = xeta_enc_tv_template,
  2853. .count = XETA_ENC_TEST_VECTORS
  2854. },
  2855. .dec = {
  2856. .vecs = xeta_dec_tv_template,
  2857. .count = XETA_DEC_TEST_VECTORS
  2858. }
  2859. }
  2860. }
  2861. }, {
  2862. .alg = "ecb(xtea)",
  2863. .test = alg_test_skcipher,
  2864. .suite = {
  2865. .cipher = {
  2866. .enc = {
  2867. .vecs = xtea_enc_tv_template,
  2868. .count = XTEA_ENC_TEST_VECTORS
  2869. },
  2870. .dec = {
  2871. .vecs = xtea_dec_tv_template,
  2872. .count = XTEA_DEC_TEST_VECTORS
  2873. }
  2874. }
  2875. }
  2876. }, {
  2877. .alg = "gcm(aes)",
  2878. .test = alg_test_aead,
  2879. .fips_allowed = 1,
  2880. .suite = {
  2881. .aead = {
  2882. .enc = {
  2883. .vecs = aes_gcm_enc_tv_template,
  2884. .count = AES_GCM_ENC_TEST_VECTORS
  2885. },
  2886. .dec = {
  2887. .vecs = aes_gcm_dec_tv_template,
  2888. .count = AES_GCM_DEC_TEST_VECTORS
  2889. }
  2890. }
  2891. }
  2892. }, {
  2893. .alg = "ghash",
  2894. .test = alg_test_hash,
  2895. .fips_allowed = 1,
  2896. .suite = {
  2897. .hash = {
  2898. .vecs = ghash_tv_template,
  2899. .count = GHASH_TEST_VECTORS
  2900. }
  2901. }
  2902. }, {
  2903. .alg = "hmac(crc32)",
  2904. .test = alg_test_hash,
  2905. .suite = {
  2906. .hash = {
  2907. .vecs = bfin_crc_tv_template,
  2908. .count = BFIN_CRC_TEST_VECTORS
  2909. }
  2910. }
  2911. }, {
  2912. .alg = "hmac(md5)",
  2913. .test = alg_test_hash,
  2914. .suite = {
  2915. .hash = {
  2916. .vecs = hmac_md5_tv_template,
  2917. .count = HMAC_MD5_TEST_VECTORS
  2918. }
  2919. }
  2920. }, {
  2921. .alg = "hmac(rmd128)",
  2922. .test = alg_test_hash,
  2923. .suite = {
  2924. .hash = {
  2925. .vecs = hmac_rmd128_tv_template,
  2926. .count = HMAC_RMD128_TEST_VECTORS
  2927. }
  2928. }
  2929. }, {
  2930. .alg = "hmac(rmd160)",
  2931. .test = alg_test_hash,
  2932. .suite = {
  2933. .hash = {
  2934. .vecs = hmac_rmd160_tv_template,
  2935. .count = HMAC_RMD160_TEST_VECTORS
  2936. }
  2937. }
  2938. }, {
  2939. .alg = "hmac(sha1)",
  2940. .test = alg_test_hash,
  2941. .fips_allowed = 1,
  2942. .suite = {
  2943. .hash = {
  2944. .vecs = hmac_sha1_tv_template,
  2945. .count = HMAC_SHA1_TEST_VECTORS
  2946. }
  2947. }
  2948. }, {
  2949. .alg = "hmac(sha224)",
  2950. .test = alg_test_hash,
  2951. .fips_allowed = 1,
  2952. .suite = {
  2953. .hash = {
  2954. .vecs = hmac_sha224_tv_template,
  2955. .count = HMAC_SHA224_TEST_VECTORS
  2956. }
  2957. }
  2958. }, {
  2959. .alg = "hmac(sha256)",
  2960. .test = alg_test_hash,
  2961. .fips_allowed = 1,
  2962. .suite = {
  2963. .hash = {
  2964. .vecs = hmac_sha256_tv_template,
  2965. .count = HMAC_SHA256_TEST_VECTORS
  2966. }
  2967. }
  2968. }, {
  2969. .alg = "hmac(sha384)",
  2970. .test = alg_test_hash,
  2971. .fips_allowed = 1,
  2972. .suite = {
  2973. .hash = {
  2974. .vecs = hmac_sha384_tv_template,
  2975. .count = HMAC_SHA384_TEST_VECTORS
  2976. }
  2977. }
  2978. }, {
  2979. .alg = "hmac(sha512)",
  2980. .test = alg_test_hash,
  2981. .fips_allowed = 1,
  2982. .suite = {
  2983. .hash = {
  2984. .vecs = hmac_sha512_tv_template,
  2985. .count = HMAC_SHA512_TEST_VECTORS
  2986. }
  2987. }
  2988. }, {
  2989. .alg = "jitterentropy_rng",
  2990. .fips_allowed = 1,
  2991. .test = alg_test_null,
  2992. }, {
  2993. .alg = "lrw(aes)",
  2994. .test = alg_test_skcipher,
  2995. .suite = {
  2996. .cipher = {
  2997. .enc = {
  2998. .vecs = aes_lrw_enc_tv_template,
  2999. .count = AES_LRW_ENC_TEST_VECTORS
  3000. },
  3001. .dec = {
  3002. .vecs = aes_lrw_dec_tv_template,
  3003. .count = AES_LRW_DEC_TEST_VECTORS
  3004. }
  3005. }
  3006. }
  3007. }, {
  3008. .alg = "lrw(camellia)",
  3009. .test = alg_test_skcipher,
  3010. .suite = {
  3011. .cipher = {
  3012. .enc = {
  3013. .vecs = camellia_lrw_enc_tv_template,
  3014. .count = CAMELLIA_LRW_ENC_TEST_VECTORS
  3015. },
  3016. .dec = {
  3017. .vecs = camellia_lrw_dec_tv_template,
  3018. .count = CAMELLIA_LRW_DEC_TEST_VECTORS
  3019. }
  3020. }
  3021. }
  3022. }, {
  3023. .alg = "lrw(cast6)",
  3024. .test = alg_test_skcipher,
  3025. .suite = {
  3026. .cipher = {
  3027. .enc = {
  3028. .vecs = cast6_lrw_enc_tv_template,
  3029. .count = CAST6_LRW_ENC_TEST_VECTORS
  3030. },
  3031. .dec = {
  3032. .vecs = cast6_lrw_dec_tv_template,
  3033. .count = CAST6_LRW_DEC_TEST_VECTORS
  3034. }
  3035. }
  3036. }
  3037. }, {
  3038. .alg = "lrw(serpent)",
  3039. .test = alg_test_skcipher,
  3040. .suite = {
  3041. .cipher = {
  3042. .enc = {
  3043. .vecs = serpent_lrw_enc_tv_template,
  3044. .count = SERPENT_LRW_ENC_TEST_VECTORS
  3045. },
  3046. .dec = {
  3047. .vecs = serpent_lrw_dec_tv_template,
  3048. .count = SERPENT_LRW_DEC_TEST_VECTORS
  3049. }
  3050. }
  3051. }
  3052. }, {
  3053. .alg = "lrw(twofish)",
  3054. .test = alg_test_skcipher,
  3055. .suite = {
  3056. .cipher = {
  3057. .enc = {
  3058. .vecs = tf_lrw_enc_tv_template,
  3059. .count = TF_LRW_ENC_TEST_VECTORS
  3060. },
  3061. .dec = {
  3062. .vecs = tf_lrw_dec_tv_template,
  3063. .count = TF_LRW_DEC_TEST_VECTORS
  3064. }
  3065. }
  3066. }
  3067. }, {
  3068. .alg = "lz4",
  3069. .test = alg_test_comp,
  3070. .fips_allowed = 1,
  3071. .suite = {
  3072. .comp = {
  3073. .comp = {
  3074. .vecs = lz4_comp_tv_template,
  3075. .count = LZ4_COMP_TEST_VECTORS
  3076. },
  3077. .decomp = {
  3078. .vecs = lz4_decomp_tv_template,
  3079. .count = LZ4_DECOMP_TEST_VECTORS
  3080. }
  3081. }
  3082. }
  3083. }, {
  3084. .alg = "lz4hc",
  3085. .test = alg_test_comp,
  3086. .fips_allowed = 1,
  3087. .suite = {
  3088. .comp = {
  3089. .comp = {
  3090. .vecs = lz4hc_comp_tv_template,
  3091. .count = LZ4HC_COMP_TEST_VECTORS
  3092. },
  3093. .decomp = {
  3094. .vecs = lz4hc_decomp_tv_template,
  3095. .count = LZ4HC_DECOMP_TEST_VECTORS
  3096. }
  3097. }
  3098. }
  3099. }, {
  3100. .alg = "lzo",
  3101. .test = alg_test_comp,
  3102. .fips_allowed = 1,
  3103. .suite = {
  3104. .comp = {
  3105. .comp = {
  3106. .vecs = lzo_comp_tv_template,
  3107. .count = LZO_COMP_TEST_VECTORS
  3108. },
  3109. .decomp = {
  3110. .vecs = lzo_decomp_tv_template,
  3111. .count = LZO_DECOMP_TEST_VECTORS
  3112. }
  3113. }
  3114. }
  3115. }, {
  3116. .alg = "md4",
  3117. .test = alg_test_hash,
  3118. .suite = {
  3119. .hash = {
  3120. .vecs = md4_tv_template,
  3121. .count = MD4_TEST_VECTORS
  3122. }
  3123. }
  3124. }, {
  3125. .alg = "md5",
  3126. .test = alg_test_hash,
  3127. .suite = {
  3128. .hash = {
  3129. .vecs = md5_tv_template,
  3130. .count = MD5_TEST_VECTORS
  3131. }
  3132. }
  3133. }, {
  3134. .alg = "michael_mic",
  3135. .test = alg_test_hash,
  3136. .suite = {
  3137. .hash = {
  3138. .vecs = michael_mic_tv_template,
  3139. .count = MICHAEL_MIC_TEST_VECTORS
  3140. }
  3141. }
  3142. }, {
  3143. .alg = "ofb(aes)",
  3144. .test = alg_test_skcipher,
  3145. .fips_allowed = 1,
  3146. .suite = {
  3147. .cipher = {
  3148. .enc = {
  3149. .vecs = aes_ofb_enc_tv_template,
  3150. .count = AES_OFB_ENC_TEST_VECTORS
  3151. },
  3152. .dec = {
  3153. .vecs = aes_ofb_dec_tv_template,
  3154. .count = AES_OFB_DEC_TEST_VECTORS
  3155. }
  3156. }
  3157. }
  3158. }, {
  3159. .alg = "pcbc(fcrypt)",
  3160. .test = alg_test_skcipher,
  3161. .suite = {
  3162. .cipher = {
  3163. .enc = {
  3164. .vecs = fcrypt_pcbc_enc_tv_template,
  3165. .count = FCRYPT_ENC_TEST_VECTORS
  3166. },
  3167. .dec = {
  3168. .vecs = fcrypt_pcbc_dec_tv_template,
  3169. .count = FCRYPT_DEC_TEST_VECTORS
  3170. }
  3171. }
  3172. }
  3173. }, {
  3174. .alg = "poly1305",
  3175. .test = alg_test_hash,
  3176. .suite = {
  3177. .hash = {
  3178. .vecs = poly1305_tv_template,
  3179. .count = POLY1305_TEST_VECTORS
  3180. }
  3181. }
  3182. }, {
  3183. .alg = "rfc3686(ctr(aes))",
  3184. .test = alg_test_skcipher,
  3185. .fips_allowed = 1,
  3186. .suite = {
  3187. .cipher = {
  3188. .enc = {
  3189. .vecs = aes_ctr_rfc3686_enc_tv_template,
  3190. .count = AES_CTR_3686_ENC_TEST_VECTORS
  3191. },
  3192. .dec = {
  3193. .vecs = aes_ctr_rfc3686_dec_tv_template,
  3194. .count = AES_CTR_3686_DEC_TEST_VECTORS
  3195. }
  3196. }
  3197. }
  3198. }, {
  3199. .alg = "rfc4106(gcm(aes))",
  3200. .test = alg_test_aead,
  3201. .fips_allowed = 1,
  3202. .suite = {
  3203. .aead = {
  3204. .enc = {
  3205. .vecs = aes_gcm_rfc4106_enc_tv_template,
  3206. .count = AES_GCM_4106_ENC_TEST_VECTORS
  3207. },
  3208. .dec = {
  3209. .vecs = aes_gcm_rfc4106_dec_tv_template,
  3210. .count = AES_GCM_4106_DEC_TEST_VECTORS
  3211. }
  3212. }
  3213. }
  3214. }, {
  3215. .alg = "rfc4309(ccm(aes))",
  3216. .test = alg_test_aead,
  3217. .fips_allowed = 1,
  3218. .suite = {
  3219. .aead = {
  3220. .enc = {
  3221. .vecs = aes_ccm_rfc4309_enc_tv_template,
  3222. .count = AES_CCM_4309_ENC_TEST_VECTORS
  3223. },
  3224. .dec = {
  3225. .vecs = aes_ccm_rfc4309_dec_tv_template,
  3226. .count = AES_CCM_4309_DEC_TEST_VECTORS
  3227. }
  3228. }
  3229. }
  3230. }, {
  3231. .alg = "rfc4543(gcm(aes))",
  3232. .test = alg_test_aead,
  3233. .suite = {
  3234. .aead = {
  3235. .enc = {
  3236. .vecs = aes_gcm_rfc4543_enc_tv_template,
  3237. .count = AES_GCM_4543_ENC_TEST_VECTORS
  3238. },
  3239. .dec = {
  3240. .vecs = aes_gcm_rfc4543_dec_tv_template,
  3241. .count = AES_GCM_4543_DEC_TEST_VECTORS
  3242. },
  3243. }
  3244. }
  3245. }, {
  3246. .alg = "rfc7539(chacha20,poly1305)",
  3247. .test = alg_test_aead,
  3248. .suite = {
  3249. .aead = {
  3250. .enc = {
  3251. .vecs = rfc7539_enc_tv_template,
  3252. .count = RFC7539_ENC_TEST_VECTORS
  3253. },
  3254. .dec = {
  3255. .vecs = rfc7539_dec_tv_template,
  3256. .count = RFC7539_DEC_TEST_VECTORS
  3257. },
  3258. }
  3259. }
  3260. }, {
  3261. .alg = "rfc7539esp(chacha20,poly1305)",
  3262. .test = alg_test_aead,
  3263. .suite = {
  3264. .aead = {
  3265. .enc = {
  3266. .vecs = rfc7539esp_enc_tv_template,
  3267. .count = RFC7539ESP_ENC_TEST_VECTORS
  3268. },
  3269. .dec = {
  3270. .vecs = rfc7539esp_dec_tv_template,
  3271. .count = RFC7539ESP_DEC_TEST_VECTORS
  3272. },
  3273. }
  3274. }
  3275. }, {
  3276. .alg = "rmd128",
  3277. .test = alg_test_hash,
  3278. .suite = {
  3279. .hash = {
  3280. .vecs = rmd128_tv_template,
  3281. .count = RMD128_TEST_VECTORS
  3282. }
  3283. }
  3284. }, {
  3285. .alg = "rmd160",
  3286. .test = alg_test_hash,
  3287. .suite = {
  3288. .hash = {
  3289. .vecs = rmd160_tv_template,
  3290. .count = RMD160_TEST_VECTORS
  3291. }
  3292. }
  3293. }, {
  3294. .alg = "rmd256",
  3295. .test = alg_test_hash,
  3296. .suite = {
  3297. .hash = {
  3298. .vecs = rmd256_tv_template,
  3299. .count = RMD256_TEST_VECTORS
  3300. }
  3301. }
  3302. }, {
  3303. .alg = "rmd320",
  3304. .test = alg_test_hash,
  3305. .suite = {
  3306. .hash = {
  3307. .vecs = rmd320_tv_template,
  3308. .count = RMD320_TEST_VECTORS
  3309. }
  3310. }
  3311. }, {
  3312. .alg = "rsa",
  3313. .test = alg_test_akcipher,
  3314. .fips_allowed = 1,
  3315. .suite = {
  3316. .akcipher = {
  3317. .vecs = rsa_tv_template,
  3318. .count = RSA_TEST_VECTORS
  3319. }
  3320. }
  3321. }, {
  3322. .alg = "salsa20",
  3323. .test = alg_test_skcipher,
  3324. .suite = {
  3325. .cipher = {
  3326. .enc = {
  3327. .vecs = salsa20_stream_enc_tv_template,
  3328. .count = SALSA20_STREAM_ENC_TEST_VECTORS
  3329. }
  3330. }
  3331. }
  3332. }, {
  3333. .alg = "sha1",
  3334. .test = alg_test_hash,
  3335. .fips_allowed = 1,
  3336. .suite = {
  3337. .hash = {
  3338. .vecs = sha1_tv_template,
  3339. .count = SHA1_TEST_VECTORS
  3340. }
  3341. }
  3342. }, {
  3343. .alg = "sha224",
  3344. .test = alg_test_hash,
  3345. .fips_allowed = 1,
  3346. .suite = {
  3347. .hash = {
  3348. .vecs = sha224_tv_template,
  3349. .count = SHA224_TEST_VECTORS
  3350. }
  3351. }
  3352. }, {
  3353. .alg = "sha256",
  3354. .test = alg_test_hash,
  3355. .fips_allowed = 1,
  3356. .suite = {
  3357. .hash = {
  3358. .vecs = sha256_tv_template,
  3359. .count = SHA256_TEST_VECTORS
  3360. }
  3361. }
  3362. }, {
  3363. .alg = "sha384",
  3364. .test = alg_test_hash,
  3365. .fips_allowed = 1,
  3366. .suite = {
  3367. .hash = {
  3368. .vecs = sha384_tv_template,
  3369. .count = SHA384_TEST_VECTORS
  3370. }
  3371. }
  3372. }, {
  3373. .alg = "sha512",
  3374. .test = alg_test_hash,
  3375. .fips_allowed = 1,
  3376. .suite = {
  3377. .hash = {
  3378. .vecs = sha512_tv_template,
  3379. .count = SHA512_TEST_VECTORS
  3380. }
  3381. }
  3382. }, {
  3383. .alg = "tgr128",
  3384. .test = alg_test_hash,
  3385. .suite = {
  3386. .hash = {
  3387. .vecs = tgr128_tv_template,
  3388. .count = TGR128_TEST_VECTORS
  3389. }
  3390. }
  3391. }, {
  3392. .alg = "tgr160",
  3393. .test = alg_test_hash,
  3394. .suite = {
  3395. .hash = {
  3396. .vecs = tgr160_tv_template,
  3397. .count = TGR160_TEST_VECTORS
  3398. }
  3399. }
  3400. }, {
  3401. .alg = "tgr192",
  3402. .test = alg_test_hash,
  3403. .suite = {
  3404. .hash = {
  3405. .vecs = tgr192_tv_template,
  3406. .count = TGR192_TEST_VECTORS
  3407. }
  3408. }
  3409. }, {
  3410. .alg = "vmac(aes)",
  3411. .test = alg_test_hash,
  3412. .suite = {
  3413. .hash = {
  3414. .vecs = aes_vmac128_tv_template,
  3415. .count = VMAC_AES_TEST_VECTORS
  3416. }
  3417. }
  3418. }, {
  3419. .alg = "wp256",
  3420. .test = alg_test_hash,
  3421. .suite = {
  3422. .hash = {
  3423. .vecs = wp256_tv_template,
  3424. .count = WP256_TEST_VECTORS
  3425. }
  3426. }
  3427. }, {
  3428. .alg = "wp384",
  3429. .test = alg_test_hash,
  3430. .suite = {
  3431. .hash = {
  3432. .vecs = wp384_tv_template,
  3433. .count = WP384_TEST_VECTORS
  3434. }
  3435. }
  3436. }, {
  3437. .alg = "wp512",
  3438. .test = alg_test_hash,
  3439. .suite = {
  3440. .hash = {
  3441. .vecs = wp512_tv_template,
  3442. .count = WP512_TEST_VECTORS
  3443. }
  3444. }
  3445. }, {
  3446. .alg = "xcbc(aes)",
  3447. .test = alg_test_hash,
  3448. .suite = {
  3449. .hash = {
  3450. .vecs = aes_xcbc128_tv_template,
  3451. .count = XCBC_AES_TEST_VECTORS
  3452. }
  3453. }
  3454. }, {
  3455. .alg = "xts(aes)",
  3456. .test = alg_test_skcipher,
  3457. .fips_allowed = 1,
  3458. .suite = {
  3459. .cipher = {
  3460. .enc = {
  3461. .vecs = aes_xts_enc_tv_template,
  3462. .count = AES_XTS_ENC_TEST_VECTORS
  3463. },
  3464. .dec = {
  3465. .vecs = aes_xts_dec_tv_template,
  3466. .count = AES_XTS_DEC_TEST_VECTORS
  3467. }
  3468. }
  3469. }
  3470. }, {
  3471. .alg = "xts(camellia)",
  3472. .test = alg_test_skcipher,
  3473. .suite = {
  3474. .cipher = {
  3475. .enc = {
  3476. .vecs = camellia_xts_enc_tv_template,
  3477. .count = CAMELLIA_XTS_ENC_TEST_VECTORS
  3478. },
  3479. .dec = {
  3480. .vecs = camellia_xts_dec_tv_template,
  3481. .count = CAMELLIA_XTS_DEC_TEST_VECTORS
  3482. }
  3483. }
  3484. }
  3485. }, {
  3486. .alg = "xts(cast6)",
  3487. .test = alg_test_skcipher,
  3488. .suite = {
  3489. .cipher = {
  3490. .enc = {
  3491. .vecs = cast6_xts_enc_tv_template,
  3492. .count = CAST6_XTS_ENC_TEST_VECTORS
  3493. },
  3494. .dec = {
  3495. .vecs = cast6_xts_dec_tv_template,
  3496. .count = CAST6_XTS_DEC_TEST_VECTORS
  3497. }
  3498. }
  3499. }
  3500. }, {
  3501. .alg = "xts(serpent)",
  3502. .test = alg_test_skcipher,
  3503. .suite = {
  3504. .cipher = {
  3505. .enc = {
  3506. .vecs = serpent_xts_enc_tv_template,
  3507. .count = SERPENT_XTS_ENC_TEST_VECTORS
  3508. },
  3509. .dec = {
  3510. .vecs = serpent_xts_dec_tv_template,
  3511. .count = SERPENT_XTS_DEC_TEST_VECTORS
  3512. }
  3513. }
  3514. }
  3515. }, {
  3516. .alg = "xts(twofish)",
  3517. .test = alg_test_skcipher,
  3518. .suite = {
  3519. .cipher = {
  3520. .enc = {
  3521. .vecs = tf_xts_enc_tv_template,
  3522. .count = TF_XTS_ENC_TEST_VECTORS
  3523. },
  3524. .dec = {
  3525. .vecs = tf_xts_dec_tv_template,
  3526. .count = TF_XTS_DEC_TEST_VECTORS
  3527. }
  3528. }
  3529. }
  3530. }, {
  3531. .alg = "zlib",
  3532. .test = alg_test_pcomp,
  3533. .fips_allowed = 1,
  3534. .suite = {
  3535. .pcomp = {
  3536. .comp = {
  3537. .vecs = zlib_comp_tv_template,
  3538. .count = ZLIB_COMP_TEST_VECTORS
  3539. },
  3540. .decomp = {
  3541. .vecs = zlib_decomp_tv_template,
  3542. .count = ZLIB_DECOMP_TEST_VECTORS
  3543. }
  3544. }
  3545. }
  3546. }
  3547. };
  3548. static bool alg_test_descs_checked;
  3549. static void alg_test_descs_check_order(void)
  3550. {
  3551. int i;
  3552. /* only check once */
  3553. if (alg_test_descs_checked)
  3554. return;
  3555. alg_test_descs_checked = true;
  3556. for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
  3557. int diff = strcmp(alg_test_descs[i - 1].alg,
  3558. alg_test_descs[i].alg);
  3559. if (WARN_ON(diff > 0)) {
  3560. pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
  3561. alg_test_descs[i - 1].alg,
  3562. alg_test_descs[i].alg);
  3563. }
  3564. if (WARN_ON(diff == 0)) {
  3565. pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
  3566. alg_test_descs[i].alg);
  3567. }
  3568. }
  3569. }
  3570. static int alg_find_test(const char *alg)
  3571. {
  3572. int start = 0;
  3573. int end = ARRAY_SIZE(alg_test_descs);
  3574. while (start < end) {
  3575. int i = (start + end) / 2;
  3576. int diff = strcmp(alg_test_descs[i].alg, alg);
  3577. if (diff > 0) {
  3578. end = i;
  3579. continue;
  3580. }
  3581. if (diff < 0) {
  3582. start = i + 1;
  3583. continue;
  3584. }
  3585. return i;
  3586. }
  3587. return -1;
  3588. }
  3589. int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
  3590. {
  3591. int i;
  3592. int j;
  3593. int rc;
  3594. alg_test_descs_check_order();
  3595. if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
  3596. char nalg[CRYPTO_MAX_ALG_NAME];
  3597. if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
  3598. sizeof(nalg))
  3599. return -ENAMETOOLONG;
  3600. i = alg_find_test(nalg);
  3601. if (i < 0)
  3602. goto notest;
  3603. if (fips_enabled && !alg_test_descs[i].fips_allowed)
  3604. goto non_fips_alg;
  3605. rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
  3606. goto test_done;
  3607. }
  3608. i = alg_find_test(alg);
  3609. j = alg_find_test(driver);
  3610. if (i < 0 && j < 0)
  3611. goto notest;
  3612. if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
  3613. (j >= 0 && !alg_test_descs[j].fips_allowed)))
  3614. goto non_fips_alg;
  3615. rc = 0;
  3616. if (i >= 0)
  3617. rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
  3618. type, mask);
  3619. if (j >= 0 && j != i)
  3620. rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
  3621. type, mask);
  3622. test_done:
  3623. if (fips_enabled && rc)
  3624. panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
  3625. if (fips_enabled && !rc)
  3626. pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
  3627. return rc;
  3628. notest:
  3629. printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
  3630. return 0;
  3631. non_fips_alg:
  3632. return -EINVAL;
  3633. }
  3634. #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
  3635. EXPORT_SYMBOL_GPL(alg_test);