testmgr.c 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951
  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. struct scatterlist src, dst, src_tab[2];
  1563. req = akcipher_request_alloc(tfm, GFP_KERNEL);
  1564. if (!req)
  1565. return err;
  1566. init_completion(&result.completion);
  1567. if (vecs->public_key_vec)
  1568. err = crypto_akcipher_set_pub_key(tfm, vecs->key,
  1569. vecs->key_len);
  1570. else
  1571. err = crypto_akcipher_set_priv_key(tfm, vecs->key,
  1572. vecs->key_len);
  1573. if (err)
  1574. goto free_req;
  1575. out_len_max = crypto_akcipher_maxsize(tfm);
  1576. outbuf_enc = kzalloc(out_len_max, GFP_KERNEL);
  1577. if (!outbuf_enc)
  1578. goto free_req;
  1579. sg_init_table(src_tab, 2);
  1580. sg_set_buf(&src_tab[0], vecs->m, 8);
  1581. sg_set_buf(&src_tab[1], vecs->m + 8, vecs->m_size - 8);
  1582. sg_init_one(&dst, outbuf_enc, out_len_max);
  1583. akcipher_request_set_crypt(req, src_tab, &dst, vecs->m_size,
  1584. out_len_max);
  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 (req->dst_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, sg_virt(req->dst), 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. sg_init_one(&src, vecs->c, vecs->c_size);
  1615. sg_init_one(&dst, outbuf_dec, out_len_max);
  1616. init_completion(&result.completion);
  1617. akcipher_request_set_crypt(req, &src, &dst, vecs->c_size, out_len_max);
  1618. /* Run RSA decrypt - m = c^d mod n;*/
  1619. err = wait_async_op(&result, crypto_akcipher_decrypt(req));
  1620. if (err) {
  1621. pr_err("alg: rsa: decrypt test failed. err %d\n", err);
  1622. goto free_all;
  1623. }
  1624. out_len = req->dst_len;
  1625. if (out_len != vecs->m_size) {
  1626. pr_err("alg: rsa: decrypt test failed. Invalid output len\n");
  1627. err = -EINVAL;
  1628. goto free_all;
  1629. }
  1630. /* verify that decrypted message is equal to the original msg */
  1631. if (memcmp(vecs->m, outbuf_dec, vecs->m_size)) {
  1632. pr_err("alg: rsa: decrypt test failed. Invalid output\n");
  1633. err = -EINVAL;
  1634. }
  1635. free_all:
  1636. kfree(outbuf_dec);
  1637. kfree(outbuf_enc);
  1638. free_req:
  1639. akcipher_request_free(req);
  1640. return err;
  1641. }
  1642. static int test_rsa(struct crypto_akcipher *tfm, struct akcipher_testvec *vecs,
  1643. unsigned int tcount)
  1644. {
  1645. int ret, i;
  1646. for (i = 0; i < tcount; i++) {
  1647. ret = do_test_rsa(tfm, vecs++);
  1648. if (ret) {
  1649. pr_err("alg: rsa: test failed on vector %d, err=%d\n",
  1650. i + 1, ret);
  1651. return ret;
  1652. }
  1653. }
  1654. return 0;
  1655. }
  1656. static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
  1657. struct akcipher_testvec *vecs, unsigned int tcount)
  1658. {
  1659. if (strncmp(alg, "rsa", 3) == 0)
  1660. return test_rsa(tfm, vecs, tcount);
  1661. return 0;
  1662. }
  1663. static int alg_test_akcipher(const struct alg_test_desc *desc,
  1664. const char *driver, u32 type, u32 mask)
  1665. {
  1666. struct crypto_akcipher *tfm;
  1667. int err = 0;
  1668. tfm = crypto_alloc_akcipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
  1669. if (IS_ERR(tfm)) {
  1670. pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
  1671. driver, PTR_ERR(tfm));
  1672. return PTR_ERR(tfm);
  1673. }
  1674. if (desc->suite.akcipher.vecs)
  1675. err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs,
  1676. desc->suite.akcipher.count);
  1677. crypto_free_akcipher(tfm);
  1678. return err;
  1679. }
  1680. static int alg_test_null(const struct alg_test_desc *desc,
  1681. const char *driver, u32 type, u32 mask)
  1682. {
  1683. return 0;
  1684. }
  1685. /* Please keep this list sorted by algorithm name. */
  1686. static const struct alg_test_desc alg_test_descs[] = {
  1687. {
  1688. .alg = "__cbc-cast5-avx",
  1689. .test = alg_test_null,
  1690. }, {
  1691. .alg = "__cbc-cast6-avx",
  1692. .test = alg_test_null,
  1693. }, {
  1694. .alg = "__cbc-serpent-avx",
  1695. .test = alg_test_null,
  1696. }, {
  1697. .alg = "__cbc-serpent-avx2",
  1698. .test = alg_test_null,
  1699. }, {
  1700. .alg = "__cbc-serpent-sse2",
  1701. .test = alg_test_null,
  1702. }, {
  1703. .alg = "__cbc-twofish-avx",
  1704. .test = alg_test_null,
  1705. }, {
  1706. .alg = "__driver-cbc-aes-aesni",
  1707. .test = alg_test_null,
  1708. .fips_allowed = 1,
  1709. }, {
  1710. .alg = "__driver-cbc-camellia-aesni",
  1711. .test = alg_test_null,
  1712. }, {
  1713. .alg = "__driver-cbc-camellia-aesni-avx2",
  1714. .test = alg_test_null,
  1715. }, {
  1716. .alg = "__driver-cbc-cast5-avx",
  1717. .test = alg_test_null,
  1718. }, {
  1719. .alg = "__driver-cbc-cast6-avx",
  1720. .test = alg_test_null,
  1721. }, {
  1722. .alg = "__driver-cbc-serpent-avx",
  1723. .test = alg_test_null,
  1724. }, {
  1725. .alg = "__driver-cbc-serpent-avx2",
  1726. .test = alg_test_null,
  1727. }, {
  1728. .alg = "__driver-cbc-serpent-sse2",
  1729. .test = alg_test_null,
  1730. }, {
  1731. .alg = "__driver-cbc-twofish-avx",
  1732. .test = alg_test_null,
  1733. }, {
  1734. .alg = "__driver-ecb-aes-aesni",
  1735. .test = alg_test_null,
  1736. .fips_allowed = 1,
  1737. }, {
  1738. .alg = "__driver-ecb-camellia-aesni",
  1739. .test = alg_test_null,
  1740. }, {
  1741. .alg = "__driver-ecb-camellia-aesni-avx2",
  1742. .test = alg_test_null,
  1743. }, {
  1744. .alg = "__driver-ecb-cast5-avx",
  1745. .test = alg_test_null,
  1746. }, {
  1747. .alg = "__driver-ecb-cast6-avx",
  1748. .test = alg_test_null,
  1749. }, {
  1750. .alg = "__driver-ecb-serpent-avx",
  1751. .test = alg_test_null,
  1752. }, {
  1753. .alg = "__driver-ecb-serpent-avx2",
  1754. .test = alg_test_null,
  1755. }, {
  1756. .alg = "__driver-ecb-serpent-sse2",
  1757. .test = alg_test_null,
  1758. }, {
  1759. .alg = "__driver-ecb-twofish-avx",
  1760. .test = alg_test_null,
  1761. }, {
  1762. .alg = "__driver-gcm-aes-aesni",
  1763. .test = alg_test_null,
  1764. .fips_allowed = 1,
  1765. }, {
  1766. .alg = "__ghash-pclmulqdqni",
  1767. .test = alg_test_null,
  1768. .fips_allowed = 1,
  1769. }, {
  1770. .alg = "ansi_cprng",
  1771. .test = alg_test_cprng,
  1772. .fips_allowed = 1,
  1773. .suite = {
  1774. .cprng = {
  1775. .vecs = ansi_cprng_aes_tv_template,
  1776. .count = ANSI_CPRNG_AES_TEST_VECTORS
  1777. }
  1778. }
  1779. }, {
  1780. .alg = "authenc(hmac(md5),ecb(cipher_null))",
  1781. .test = alg_test_aead,
  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. .suite = {
  1798. .aead = {
  1799. .enc = {
  1800. .vecs =
  1801. hmac_sha1_aes_cbc_enc_tv_temp,
  1802. .count =
  1803. HMAC_SHA1_AES_CBC_ENC_TEST_VEC
  1804. }
  1805. }
  1806. }
  1807. }, {
  1808. .alg = "authenc(hmac(sha1),cbc(des))",
  1809. .test = alg_test_aead,
  1810. .suite = {
  1811. .aead = {
  1812. .enc = {
  1813. .vecs =
  1814. hmac_sha1_des_cbc_enc_tv_temp,
  1815. .count =
  1816. HMAC_SHA1_DES_CBC_ENC_TEST_VEC
  1817. }
  1818. }
  1819. }
  1820. }, {
  1821. .alg = "authenc(hmac(sha1),cbc(des3_ede))",
  1822. .test = alg_test_aead,
  1823. .suite = {
  1824. .aead = {
  1825. .enc = {
  1826. .vecs =
  1827. hmac_sha1_des3_ede_cbc_enc_tv_temp,
  1828. .count =
  1829. HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
  1830. }
  1831. }
  1832. }
  1833. }, {
  1834. .alg = "authenc(hmac(sha1),ecb(cipher_null))",
  1835. .test = alg_test_aead,
  1836. .suite = {
  1837. .aead = {
  1838. .enc = {
  1839. .vecs =
  1840. hmac_sha1_ecb_cipher_null_enc_tv_temp,
  1841. .count =
  1842. HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
  1843. },
  1844. .dec = {
  1845. .vecs =
  1846. hmac_sha1_ecb_cipher_null_dec_tv_temp,
  1847. .count =
  1848. HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
  1849. }
  1850. }
  1851. }
  1852. }, {
  1853. .alg = "authenc(hmac(sha224),cbc(des))",
  1854. .test = alg_test_aead,
  1855. .suite = {
  1856. .aead = {
  1857. .enc = {
  1858. .vecs =
  1859. hmac_sha224_des_cbc_enc_tv_temp,
  1860. .count =
  1861. HMAC_SHA224_DES_CBC_ENC_TEST_VEC
  1862. }
  1863. }
  1864. }
  1865. }, {
  1866. .alg = "authenc(hmac(sha224),cbc(des3_ede))",
  1867. .test = alg_test_aead,
  1868. .suite = {
  1869. .aead = {
  1870. .enc = {
  1871. .vecs =
  1872. hmac_sha224_des3_ede_cbc_enc_tv_temp,
  1873. .count =
  1874. HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
  1875. }
  1876. }
  1877. }
  1878. }, {
  1879. .alg = "authenc(hmac(sha256),cbc(aes))",
  1880. .test = alg_test_aead,
  1881. .suite = {
  1882. .aead = {
  1883. .enc = {
  1884. .vecs =
  1885. hmac_sha256_aes_cbc_enc_tv_temp,
  1886. .count =
  1887. HMAC_SHA256_AES_CBC_ENC_TEST_VEC
  1888. }
  1889. }
  1890. }
  1891. }, {
  1892. .alg = "authenc(hmac(sha256),cbc(des))",
  1893. .test = alg_test_aead,
  1894. .suite = {
  1895. .aead = {
  1896. .enc = {
  1897. .vecs =
  1898. hmac_sha256_des_cbc_enc_tv_temp,
  1899. .count =
  1900. HMAC_SHA256_DES_CBC_ENC_TEST_VEC
  1901. }
  1902. }
  1903. }
  1904. }, {
  1905. .alg = "authenc(hmac(sha256),cbc(des3_ede))",
  1906. .test = alg_test_aead,
  1907. .suite = {
  1908. .aead = {
  1909. .enc = {
  1910. .vecs =
  1911. hmac_sha256_des3_ede_cbc_enc_tv_temp,
  1912. .count =
  1913. HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
  1914. }
  1915. }
  1916. }
  1917. }, {
  1918. .alg = "authenc(hmac(sha384),cbc(des))",
  1919. .test = alg_test_aead,
  1920. .suite = {
  1921. .aead = {
  1922. .enc = {
  1923. .vecs =
  1924. hmac_sha384_des_cbc_enc_tv_temp,
  1925. .count =
  1926. HMAC_SHA384_DES_CBC_ENC_TEST_VEC
  1927. }
  1928. }
  1929. }
  1930. }, {
  1931. .alg = "authenc(hmac(sha384),cbc(des3_ede))",
  1932. .test = alg_test_aead,
  1933. .suite = {
  1934. .aead = {
  1935. .enc = {
  1936. .vecs =
  1937. hmac_sha384_des3_ede_cbc_enc_tv_temp,
  1938. .count =
  1939. HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
  1940. }
  1941. }
  1942. }
  1943. }, {
  1944. .alg = "authenc(hmac(sha512),cbc(aes))",
  1945. .test = alg_test_aead,
  1946. .suite = {
  1947. .aead = {
  1948. .enc = {
  1949. .vecs =
  1950. hmac_sha512_aes_cbc_enc_tv_temp,
  1951. .count =
  1952. HMAC_SHA512_AES_CBC_ENC_TEST_VEC
  1953. }
  1954. }
  1955. }
  1956. }, {
  1957. .alg = "authenc(hmac(sha512),cbc(des))",
  1958. .test = alg_test_aead,
  1959. .suite = {
  1960. .aead = {
  1961. .enc = {
  1962. .vecs =
  1963. hmac_sha512_des_cbc_enc_tv_temp,
  1964. .count =
  1965. HMAC_SHA512_DES_CBC_ENC_TEST_VEC
  1966. }
  1967. }
  1968. }
  1969. }, {
  1970. .alg = "authenc(hmac(sha512),cbc(des3_ede))",
  1971. .test = alg_test_aead,
  1972. .suite = {
  1973. .aead = {
  1974. .enc = {
  1975. .vecs =
  1976. hmac_sha512_des3_ede_cbc_enc_tv_temp,
  1977. .count =
  1978. HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
  1979. }
  1980. }
  1981. }
  1982. }, {
  1983. .alg = "cbc(aes)",
  1984. .test = alg_test_skcipher,
  1985. .fips_allowed = 1,
  1986. .suite = {
  1987. .cipher = {
  1988. .enc = {
  1989. .vecs = aes_cbc_enc_tv_template,
  1990. .count = AES_CBC_ENC_TEST_VECTORS
  1991. },
  1992. .dec = {
  1993. .vecs = aes_cbc_dec_tv_template,
  1994. .count = AES_CBC_DEC_TEST_VECTORS
  1995. }
  1996. }
  1997. }
  1998. }, {
  1999. .alg = "cbc(anubis)",
  2000. .test = alg_test_skcipher,
  2001. .suite = {
  2002. .cipher = {
  2003. .enc = {
  2004. .vecs = anubis_cbc_enc_tv_template,
  2005. .count = ANUBIS_CBC_ENC_TEST_VECTORS
  2006. },
  2007. .dec = {
  2008. .vecs = anubis_cbc_dec_tv_template,
  2009. .count = ANUBIS_CBC_DEC_TEST_VECTORS
  2010. }
  2011. }
  2012. }
  2013. }, {
  2014. .alg = "cbc(blowfish)",
  2015. .test = alg_test_skcipher,
  2016. .suite = {
  2017. .cipher = {
  2018. .enc = {
  2019. .vecs = bf_cbc_enc_tv_template,
  2020. .count = BF_CBC_ENC_TEST_VECTORS
  2021. },
  2022. .dec = {
  2023. .vecs = bf_cbc_dec_tv_template,
  2024. .count = BF_CBC_DEC_TEST_VECTORS
  2025. }
  2026. }
  2027. }
  2028. }, {
  2029. .alg = "cbc(camellia)",
  2030. .test = alg_test_skcipher,
  2031. .suite = {
  2032. .cipher = {
  2033. .enc = {
  2034. .vecs = camellia_cbc_enc_tv_template,
  2035. .count = CAMELLIA_CBC_ENC_TEST_VECTORS
  2036. },
  2037. .dec = {
  2038. .vecs = camellia_cbc_dec_tv_template,
  2039. .count = CAMELLIA_CBC_DEC_TEST_VECTORS
  2040. }
  2041. }
  2042. }
  2043. }, {
  2044. .alg = "cbc(cast5)",
  2045. .test = alg_test_skcipher,
  2046. .suite = {
  2047. .cipher = {
  2048. .enc = {
  2049. .vecs = cast5_cbc_enc_tv_template,
  2050. .count = CAST5_CBC_ENC_TEST_VECTORS
  2051. },
  2052. .dec = {
  2053. .vecs = cast5_cbc_dec_tv_template,
  2054. .count = CAST5_CBC_DEC_TEST_VECTORS
  2055. }
  2056. }
  2057. }
  2058. }, {
  2059. .alg = "cbc(cast6)",
  2060. .test = alg_test_skcipher,
  2061. .suite = {
  2062. .cipher = {
  2063. .enc = {
  2064. .vecs = cast6_cbc_enc_tv_template,
  2065. .count = CAST6_CBC_ENC_TEST_VECTORS
  2066. },
  2067. .dec = {
  2068. .vecs = cast6_cbc_dec_tv_template,
  2069. .count = CAST6_CBC_DEC_TEST_VECTORS
  2070. }
  2071. }
  2072. }
  2073. }, {
  2074. .alg = "cbc(des)",
  2075. .test = alg_test_skcipher,
  2076. .suite = {
  2077. .cipher = {
  2078. .enc = {
  2079. .vecs = des_cbc_enc_tv_template,
  2080. .count = DES_CBC_ENC_TEST_VECTORS
  2081. },
  2082. .dec = {
  2083. .vecs = des_cbc_dec_tv_template,
  2084. .count = DES_CBC_DEC_TEST_VECTORS
  2085. }
  2086. }
  2087. }
  2088. }, {
  2089. .alg = "cbc(des3_ede)",
  2090. .test = alg_test_skcipher,
  2091. .fips_allowed = 1,
  2092. .suite = {
  2093. .cipher = {
  2094. .enc = {
  2095. .vecs = des3_ede_cbc_enc_tv_template,
  2096. .count = DES3_EDE_CBC_ENC_TEST_VECTORS
  2097. },
  2098. .dec = {
  2099. .vecs = des3_ede_cbc_dec_tv_template,
  2100. .count = DES3_EDE_CBC_DEC_TEST_VECTORS
  2101. }
  2102. }
  2103. }
  2104. }, {
  2105. .alg = "cbc(serpent)",
  2106. .test = alg_test_skcipher,
  2107. .suite = {
  2108. .cipher = {
  2109. .enc = {
  2110. .vecs = serpent_cbc_enc_tv_template,
  2111. .count = SERPENT_CBC_ENC_TEST_VECTORS
  2112. },
  2113. .dec = {
  2114. .vecs = serpent_cbc_dec_tv_template,
  2115. .count = SERPENT_CBC_DEC_TEST_VECTORS
  2116. }
  2117. }
  2118. }
  2119. }, {
  2120. .alg = "cbc(twofish)",
  2121. .test = alg_test_skcipher,
  2122. .suite = {
  2123. .cipher = {
  2124. .enc = {
  2125. .vecs = tf_cbc_enc_tv_template,
  2126. .count = TF_CBC_ENC_TEST_VECTORS
  2127. },
  2128. .dec = {
  2129. .vecs = tf_cbc_dec_tv_template,
  2130. .count = TF_CBC_DEC_TEST_VECTORS
  2131. }
  2132. }
  2133. }
  2134. }, {
  2135. .alg = "ccm(aes)",
  2136. .test = alg_test_aead,
  2137. .fips_allowed = 1,
  2138. .suite = {
  2139. .aead = {
  2140. .enc = {
  2141. .vecs = aes_ccm_enc_tv_template,
  2142. .count = AES_CCM_ENC_TEST_VECTORS
  2143. },
  2144. .dec = {
  2145. .vecs = aes_ccm_dec_tv_template,
  2146. .count = AES_CCM_DEC_TEST_VECTORS
  2147. }
  2148. }
  2149. }
  2150. }, {
  2151. .alg = "chacha20",
  2152. .test = alg_test_skcipher,
  2153. .suite = {
  2154. .cipher = {
  2155. .enc = {
  2156. .vecs = chacha20_enc_tv_template,
  2157. .count = CHACHA20_ENC_TEST_VECTORS
  2158. },
  2159. .dec = {
  2160. .vecs = chacha20_enc_tv_template,
  2161. .count = CHACHA20_ENC_TEST_VECTORS
  2162. },
  2163. }
  2164. }
  2165. }, {
  2166. .alg = "cmac(aes)",
  2167. .fips_allowed = 1,
  2168. .test = alg_test_hash,
  2169. .suite = {
  2170. .hash = {
  2171. .vecs = aes_cmac128_tv_template,
  2172. .count = CMAC_AES_TEST_VECTORS
  2173. }
  2174. }
  2175. }, {
  2176. .alg = "cmac(des3_ede)",
  2177. .fips_allowed = 1,
  2178. .test = alg_test_hash,
  2179. .suite = {
  2180. .hash = {
  2181. .vecs = des3_ede_cmac64_tv_template,
  2182. .count = CMAC_DES3_EDE_TEST_VECTORS
  2183. }
  2184. }
  2185. }, {
  2186. .alg = "compress_null",
  2187. .test = alg_test_null,
  2188. }, {
  2189. .alg = "crc32",
  2190. .test = alg_test_hash,
  2191. .suite = {
  2192. .hash = {
  2193. .vecs = crc32_tv_template,
  2194. .count = CRC32_TEST_VECTORS
  2195. }
  2196. }
  2197. }, {
  2198. .alg = "crc32c",
  2199. .test = alg_test_crc32c,
  2200. .fips_allowed = 1,
  2201. .suite = {
  2202. .hash = {
  2203. .vecs = crc32c_tv_template,
  2204. .count = CRC32C_TEST_VECTORS
  2205. }
  2206. }
  2207. }, {
  2208. .alg = "crct10dif",
  2209. .test = alg_test_hash,
  2210. .fips_allowed = 1,
  2211. .suite = {
  2212. .hash = {
  2213. .vecs = crct10dif_tv_template,
  2214. .count = CRCT10DIF_TEST_VECTORS
  2215. }
  2216. }
  2217. }, {
  2218. .alg = "cryptd(__driver-cbc-aes-aesni)",
  2219. .test = alg_test_null,
  2220. .fips_allowed = 1,
  2221. }, {
  2222. .alg = "cryptd(__driver-cbc-camellia-aesni)",
  2223. .test = alg_test_null,
  2224. }, {
  2225. .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
  2226. .test = alg_test_null,
  2227. }, {
  2228. .alg = "cryptd(__driver-cbc-serpent-avx2)",
  2229. .test = alg_test_null,
  2230. }, {
  2231. .alg = "cryptd(__driver-ecb-aes-aesni)",
  2232. .test = alg_test_null,
  2233. .fips_allowed = 1,
  2234. }, {
  2235. .alg = "cryptd(__driver-ecb-camellia-aesni)",
  2236. .test = alg_test_null,
  2237. }, {
  2238. .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
  2239. .test = alg_test_null,
  2240. }, {
  2241. .alg = "cryptd(__driver-ecb-cast5-avx)",
  2242. .test = alg_test_null,
  2243. }, {
  2244. .alg = "cryptd(__driver-ecb-cast6-avx)",
  2245. .test = alg_test_null,
  2246. }, {
  2247. .alg = "cryptd(__driver-ecb-serpent-avx)",
  2248. .test = alg_test_null,
  2249. }, {
  2250. .alg = "cryptd(__driver-ecb-serpent-avx2)",
  2251. .test = alg_test_null,
  2252. }, {
  2253. .alg = "cryptd(__driver-ecb-serpent-sse2)",
  2254. .test = alg_test_null,
  2255. }, {
  2256. .alg = "cryptd(__driver-ecb-twofish-avx)",
  2257. .test = alg_test_null,
  2258. }, {
  2259. .alg = "cryptd(__driver-gcm-aes-aesni)",
  2260. .test = alg_test_null,
  2261. .fips_allowed = 1,
  2262. }, {
  2263. .alg = "cryptd(__ghash-pclmulqdqni)",
  2264. .test = alg_test_null,
  2265. .fips_allowed = 1,
  2266. }, {
  2267. .alg = "ctr(aes)",
  2268. .test = alg_test_skcipher,
  2269. .fips_allowed = 1,
  2270. .suite = {
  2271. .cipher = {
  2272. .enc = {
  2273. .vecs = aes_ctr_enc_tv_template,
  2274. .count = AES_CTR_ENC_TEST_VECTORS
  2275. },
  2276. .dec = {
  2277. .vecs = aes_ctr_dec_tv_template,
  2278. .count = AES_CTR_DEC_TEST_VECTORS
  2279. }
  2280. }
  2281. }
  2282. }, {
  2283. .alg = "ctr(blowfish)",
  2284. .test = alg_test_skcipher,
  2285. .suite = {
  2286. .cipher = {
  2287. .enc = {
  2288. .vecs = bf_ctr_enc_tv_template,
  2289. .count = BF_CTR_ENC_TEST_VECTORS
  2290. },
  2291. .dec = {
  2292. .vecs = bf_ctr_dec_tv_template,
  2293. .count = BF_CTR_DEC_TEST_VECTORS
  2294. }
  2295. }
  2296. }
  2297. }, {
  2298. .alg = "ctr(camellia)",
  2299. .test = alg_test_skcipher,
  2300. .suite = {
  2301. .cipher = {
  2302. .enc = {
  2303. .vecs = camellia_ctr_enc_tv_template,
  2304. .count = CAMELLIA_CTR_ENC_TEST_VECTORS
  2305. },
  2306. .dec = {
  2307. .vecs = camellia_ctr_dec_tv_template,
  2308. .count = CAMELLIA_CTR_DEC_TEST_VECTORS
  2309. }
  2310. }
  2311. }
  2312. }, {
  2313. .alg = "ctr(cast5)",
  2314. .test = alg_test_skcipher,
  2315. .suite = {
  2316. .cipher = {
  2317. .enc = {
  2318. .vecs = cast5_ctr_enc_tv_template,
  2319. .count = CAST5_CTR_ENC_TEST_VECTORS
  2320. },
  2321. .dec = {
  2322. .vecs = cast5_ctr_dec_tv_template,
  2323. .count = CAST5_CTR_DEC_TEST_VECTORS
  2324. }
  2325. }
  2326. }
  2327. }, {
  2328. .alg = "ctr(cast6)",
  2329. .test = alg_test_skcipher,
  2330. .suite = {
  2331. .cipher = {
  2332. .enc = {
  2333. .vecs = cast6_ctr_enc_tv_template,
  2334. .count = CAST6_CTR_ENC_TEST_VECTORS
  2335. },
  2336. .dec = {
  2337. .vecs = cast6_ctr_dec_tv_template,
  2338. .count = CAST6_CTR_DEC_TEST_VECTORS
  2339. }
  2340. }
  2341. }
  2342. }, {
  2343. .alg = "ctr(des)",
  2344. .test = alg_test_skcipher,
  2345. .suite = {
  2346. .cipher = {
  2347. .enc = {
  2348. .vecs = des_ctr_enc_tv_template,
  2349. .count = DES_CTR_ENC_TEST_VECTORS
  2350. },
  2351. .dec = {
  2352. .vecs = des_ctr_dec_tv_template,
  2353. .count = DES_CTR_DEC_TEST_VECTORS
  2354. }
  2355. }
  2356. }
  2357. }, {
  2358. .alg = "ctr(des3_ede)",
  2359. .test = alg_test_skcipher,
  2360. .suite = {
  2361. .cipher = {
  2362. .enc = {
  2363. .vecs = des3_ede_ctr_enc_tv_template,
  2364. .count = DES3_EDE_CTR_ENC_TEST_VECTORS
  2365. },
  2366. .dec = {
  2367. .vecs = des3_ede_ctr_dec_tv_template,
  2368. .count = DES3_EDE_CTR_DEC_TEST_VECTORS
  2369. }
  2370. }
  2371. }
  2372. }, {
  2373. .alg = "ctr(serpent)",
  2374. .test = alg_test_skcipher,
  2375. .suite = {
  2376. .cipher = {
  2377. .enc = {
  2378. .vecs = serpent_ctr_enc_tv_template,
  2379. .count = SERPENT_CTR_ENC_TEST_VECTORS
  2380. },
  2381. .dec = {
  2382. .vecs = serpent_ctr_dec_tv_template,
  2383. .count = SERPENT_CTR_DEC_TEST_VECTORS
  2384. }
  2385. }
  2386. }
  2387. }, {
  2388. .alg = "ctr(twofish)",
  2389. .test = alg_test_skcipher,
  2390. .suite = {
  2391. .cipher = {
  2392. .enc = {
  2393. .vecs = tf_ctr_enc_tv_template,
  2394. .count = TF_CTR_ENC_TEST_VECTORS
  2395. },
  2396. .dec = {
  2397. .vecs = tf_ctr_dec_tv_template,
  2398. .count = TF_CTR_DEC_TEST_VECTORS
  2399. }
  2400. }
  2401. }
  2402. }, {
  2403. .alg = "cts(cbc(aes))",
  2404. .test = alg_test_skcipher,
  2405. .suite = {
  2406. .cipher = {
  2407. .enc = {
  2408. .vecs = cts_mode_enc_tv_template,
  2409. .count = CTS_MODE_ENC_TEST_VECTORS
  2410. },
  2411. .dec = {
  2412. .vecs = cts_mode_dec_tv_template,
  2413. .count = CTS_MODE_DEC_TEST_VECTORS
  2414. }
  2415. }
  2416. }
  2417. }, {
  2418. .alg = "deflate",
  2419. .test = alg_test_comp,
  2420. .fips_allowed = 1,
  2421. .suite = {
  2422. .comp = {
  2423. .comp = {
  2424. .vecs = deflate_comp_tv_template,
  2425. .count = DEFLATE_COMP_TEST_VECTORS
  2426. },
  2427. .decomp = {
  2428. .vecs = deflate_decomp_tv_template,
  2429. .count = DEFLATE_DECOMP_TEST_VECTORS
  2430. }
  2431. }
  2432. }
  2433. }, {
  2434. .alg = "digest_null",
  2435. .test = alg_test_null,
  2436. }, {
  2437. .alg = "drbg_nopr_ctr_aes128",
  2438. .test = alg_test_drbg,
  2439. .fips_allowed = 1,
  2440. .suite = {
  2441. .drbg = {
  2442. .vecs = drbg_nopr_ctr_aes128_tv_template,
  2443. .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
  2444. }
  2445. }
  2446. }, {
  2447. .alg = "drbg_nopr_ctr_aes192",
  2448. .test = alg_test_drbg,
  2449. .fips_allowed = 1,
  2450. .suite = {
  2451. .drbg = {
  2452. .vecs = drbg_nopr_ctr_aes192_tv_template,
  2453. .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
  2454. }
  2455. }
  2456. }, {
  2457. .alg = "drbg_nopr_ctr_aes256",
  2458. .test = alg_test_drbg,
  2459. .fips_allowed = 1,
  2460. .suite = {
  2461. .drbg = {
  2462. .vecs = drbg_nopr_ctr_aes256_tv_template,
  2463. .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
  2464. }
  2465. }
  2466. }, {
  2467. /*
  2468. * There is no need to specifically test the DRBG with every
  2469. * backend cipher -- covered by drbg_nopr_hmac_sha256 test
  2470. */
  2471. .alg = "drbg_nopr_hmac_sha1",
  2472. .fips_allowed = 1,
  2473. .test = alg_test_null,
  2474. }, {
  2475. .alg = "drbg_nopr_hmac_sha256",
  2476. .test = alg_test_drbg,
  2477. .fips_allowed = 1,
  2478. .suite = {
  2479. .drbg = {
  2480. .vecs = drbg_nopr_hmac_sha256_tv_template,
  2481. .count =
  2482. ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
  2483. }
  2484. }
  2485. }, {
  2486. /* covered by drbg_nopr_hmac_sha256 test */
  2487. .alg = "drbg_nopr_hmac_sha384",
  2488. .fips_allowed = 1,
  2489. .test = alg_test_null,
  2490. }, {
  2491. .alg = "drbg_nopr_hmac_sha512",
  2492. .test = alg_test_null,
  2493. .fips_allowed = 1,
  2494. }, {
  2495. .alg = "drbg_nopr_sha1",
  2496. .fips_allowed = 1,
  2497. .test = alg_test_null,
  2498. }, {
  2499. .alg = "drbg_nopr_sha256",
  2500. .test = alg_test_drbg,
  2501. .fips_allowed = 1,
  2502. .suite = {
  2503. .drbg = {
  2504. .vecs = drbg_nopr_sha256_tv_template,
  2505. .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
  2506. }
  2507. }
  2508. }, {
  2509. /* covered by drbg_nopr_sha256 test */
  2510. .alg = "drbg_nopr_sha384",
  2511. .fips_allowed = 1,
  2512. .test = alg_test_null,
  2513. }, {
  2514. .alg = "drbg_nopr_sha512",
  2515. .fips_allowed = 1,
  2516. .test = alg_test_null,
  2517. }, {
  2518. .alg = "drbg_pr_ctr_aes128",
  2519. .test = alg_test_drbg,
  2520. .fips_allowed = 1,
  2521. .suite = {
  2522. .drbg = {
  2523. .vecs = drbg_pr_ctr_aes128_tv_template,
  2524. .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
  2525. }
  2526. }
  2527. }, {
  2528. /* covered by drbg_pr_ctr_aes128 test */
  2529. .alg = "drbg_pr_ctr_aes192",
  2530. .fips_allowed = 1,
  2531. .test = alg_test_null,
  2532. }, {
  2533. .alg = "drbg_pr_ctr_aes256",
  2534. .fips_allowed = 1,
  2535. .test = alg_test_null,
  2536. }, {
  2537. .alg = "drbg_pr_hmac_sha1",
  2538. .fips_allowed = 1,
  2539. .test = alg_test_null,
  2540. }, {
  2541. .alg = "drbg_pr_hmac_sha256",
  2542. .test = alg_test_drbg,
  2543. .fips_allowed = 1,
  2544. .suite = {
  2545. .drbg = {
  2546. .vecs = drbg_pr_hmac_sha256_tv_template,
  2547. .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
  2548. }
  2549. }
  2550. }, {
  2551. /* covered by drbg_pr_hmac_sha256 test */
  2552. .alg = "drbg_pr_hmac_sha384",
  2553. .fips_allowed = 1,
  2554. .test = alg_test_null,
  2555. }, {
  2556. .alg = "drbg_pr_hmac_sha512",
  2557. .test = alg_test_null,
  2558. .fips_allowed = 1,
  2559. }, {
  2560. .alg = "drbg_pr_sha1",
  2561. .fips_allowed = 1,
  2562. .test = alg_test_null,
  2563. }, {
  2564. .alg = "drbg_pr_sha256",
  2565. .test = alg_test_drbg,
  2566. .fips_allowed = 1,
  2567. .suite = {
  2568. .drbg = {
  2569. .vecs = drbg_pr_sha256_tv_template,
  2570. .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
  2571. }
  2572. }
  2573. }, {
  2574. /* covered by drbg_pr_sha256 test */
  2575. .alg = "drbg_pr_sha384",
  2576. .fips_allowed = 1,
  2577. .test = alg_test_null,
  2578. }, {
  2579. .alg = "drbg_pr_sha512",
  2580. .fips_allowed = 1,
  2581. .test = alg_test_null,
  2582. }, {
  2583. .alg = "ecb(__aes-aesni)",
  2584. .test = alg_test_null,
  2585. .fips_allowed = 1,
  2586. }, {
  2587. .alg = "ecb(aes)",
  2588. .test = alg_test_skcipher,
  2589. .fips_allowed = 1,
  2590. .suite = {
  2591. .cipher = {
  2592. .enc = {
  2593. .vecs = aes_enc_tv_template,
  2594. .count = AES_ENC_TEST_VECTORS
  2595. },
  2596. .dec = {
  2597. .vecs = aes_dec_tv_template,
  2598. .count = AES_DEC_TEST_VECTORS
  2599. }
  2600. }
  2601. }
  2602. }, {
  2603. .alg = "ecb(anubis)",
  2604. .test = alg_test_skcipher,
  2605. .suite = {
  2606. .cipher = {
  2607. .enc = {
  2608. .vecs = anubis_enc_tv_template,
  2609. .count = ANUBIS_ENC_TEST_VECTORS
  2610. },
  2611. .dec = {
  2612. .vecs = anubis_dec_tv_template,
  2613. .count = ANUBIS_DEC_TEST_VECTORS
  2614. }
  2615. }
  2616. }
  2617. }, {
  2618. .alg = "ecb(arc4)",
  2619. .test = alg_test_skcipher,
  2620. .suite = {
  2621. .cipher = {
  2622. .enc = {
  2623. .vecs = arc4_enc_tv_template,
  2624. .count = ARC4_ENC_TEST_VECTORS
  2625. },
  2626. .dec = {
  2627. .vecs = arc4_dec_tv_template,
  2628. .count = ARC4_DEC_TEST_VECTORS
  2629. }
  2630. }
  2631. }
  2632. }, {
  2633. .alg = "ecb(blowfish)",
  2634. .test = alg_test_skcipher,
  2635. .suite = {
  2636. .cipher = {
  2637. .enc = {
  2638. .vecs = bf_enc_tv_template,
  2639. .count = BF_ENC_TEST_VECTORS
  2640. },
  2641. .dec = {
  2642. .vecs = bf_dec_tv_template,
  2643. .count = BF_DEC_TEST_VECTORS
  2644. }
  2645. }
  2646. }
  2647. }, {
  2648. .alg = "ecb(camellia)",
  2649. .test = alg_test_skcipher,
  2650. .suite = {
  2651. .cipher = {
  2652. .enc = {
  2653. .vecs = camellia_enc_tv_template,
  2654. .count = CAMELLIA_ENC_TEST_VECTORS
  2655. },
  2656. .dec = {
  2657. .vecs = camellia_dec_tv_template,
  2658. .count = CAMELLIA_DEC_TEST_VECTORS
  2659. }
  2660. }
  2661. }
  2662. }, {
  2663. .alg = "ecb(cast5)",
  2664. .test = alg_test_skcipher,
  2665. .suite = {
  2666. .cipher = {
  2667. .enc = {
  2668. .vecs = cast5_enc_tv_template,
  2669. .count = CAST5_ENC_TEST_VECTORS
  2670. },
  2671. .dec = {
  2672. .vecs = cast5_dec_tv_template,
  2673. .count = CAST5_DEC_TEST_VECTORS
  2674. }
  2675. }
  2676. }
  2677. }, {
  2678. .alg = "ecb(cast6)",
  2679. .test = alg_test_skcipher,
  2680. .suite = {
  2681. .cipher = {
  2682. .enc = {
  2683. .vecs = cast6_enc_tv_template,
  2684. .count = CAST6_ENC_TEST_VECTORS
  2685. },
  2686. .dec = {
  2687. .vecs = cast6_dec_tv_template,
  2688. .count = CAST6_DEC_TEST_VECTORS
  2689. }
  2690. }
  2691. }
  2692. }, {
  2693. .alg = "ecb(cipher_null)",
  2694. .test = alg_test_null,
  2695. }, {
  2696. .alg = "ecb(des)",
  2697. .test = alg_test_skcipher,
  2698. .suite = {
  2699. .cipher = {
  2700. .enc = {
  2701. .vecs = des_enc_tv_template,
  2702. .count = DES_ENC_TEST_VECTORS
  2703. },
  2704. .dec = {
  2705. .vecs = des_dec_tv_template,
  2706. .count = DES_DEC_TEST_VECTORS
  2707. }
  2708. }
  2709. }
  2710. }, {
  2711. .alg = "ecb(des3_ede)",
  2712. .test = alg_test_skcipher,
  2713. .fips_allowed = 1,
  2714. .suite = {
  2715. .cipher = {
  2716. .enc = {
  2717. .vecs = des3_ede_enc_tv_template,
  2718. .count = DES3_EDE_ENC_TEST_VECTORS
  2719. },
  2720. .dec = {
  2721. .vecs = des3_ede_dec_tv_template,
  2722. .count = DES3_EDE_DEC_TEST_VECTORS
  2723. }
  2724. }
  2725. }
  2726. }, {
  2727. .alg = "ecb(fcrypt)",
  2728. .test = alg_test_skcipher,
  2729. .suite = {
  2730. .cipher = {
  2731. .enc = {
  2732. .vecs = fcrypt_pcbc_enc_tv_template,
  2733. .count = 1
  2734. },
  2735. .dec = {
  2736. .vecs = fcrypt_pcbc_dec_tv_template,
  2737. .count = 1
  2738. }
  2739. }
  2740. }
  2741. }, {
  2742. .alg = "ecb(khazad)",
  2743. .test = alg_test_skcipher,
  2744. .suite = {
  2745. .cipher = {
  2746. .enc = {
  2747. .vecs = khazad_enc_tv_template,
  2748. .count = KHAZAD_ENC_TEST_VECTORS
  2749. },
  2750. .dec = {
  2751. .vecs = khazad_dec_tv_template,
  2752. .count = KHAZAD_DEC_TEST_VECTORS
  2753. }
  2754. }
  2755. }
  2756. }, {
  2757. .alg = "ecb(seed)",
  2758. .test = alg_test_skcipher,
  2759. .suite = {
  2760. .cipher = {
  2761. .enc = {
  2762. .vecs = seed_enc_tv_template,
  2763. .count = SEED_ENC_TEST_VECTORS
  2764. },
  2765. .dec = {
  2766. .vecs = seed_dec_tv_template,
  2767. .count = SEED_DEC_TEST_VECTORS
  2768. }
  2769. }
  2770. }
  2771. }, {
  2772. .alg = "ecb(serpent)",
  2773. .test = alg_test_skcipher,
  2774. .suite = {
  2775. .cipher = {
  2776. .enc = {
  2777. .vecs = serpent_enc_tv_template,
  2778. .count = SERPENT_ENC_TEST_VECTORS
  2779. },
  2780. .dec = {
  2781. .vecs = serpent_dec_tv_template,
  2782. .count = SERPENT_DEC_TEST_VECTORS
  2783. }
  2784. }
  2785. }
  2786. }, {
  2787. .alg = "ecb(tea)",
  2788. .test = alg_test_skcipher,
  2789. .suite = {
  2790. .cipher = {
  2791. .enc = {
  2792. .vecs = tea_enc_tv_template,
  2793. .count = TEA_ENC_TEST_VECTORS
  2794. },
  2795. .dec = {
  2796. .vecs = tea_dec_tv_template,
  2797. .count = TEA_DEC_TEST_VECTORS
  2798. }
  2799. }
  2800. }
  2801. }, {
  2802. .alg = "ecb(tnepres)",
  2803. .test = alg_test_skcipher,
  2804. .suite = {
  2805. .cipher = {
  2806. .enc = {
  2807. .vecs = tnepres_enc_tv_template,
  2808. .count = TNEPRES_ENC_TEST_VECTORS
  2809. },
  2810. .dec = {
  2811. .vecs = tnepres_dec_tv_template,
  2812. .count = TNEPRES_DEC_TEST_VECTORS
  2813. }
  2814. }
  2815. }
  2816. }, {
  2817. .alg = "ecb(twofish)",
  2818. .test = alg_test_skcipher,
  2819. .suite = {
  2820. .cipher = {
  2821. .enc = {
  2822. .vecs = tf_enc_tv_template,
  2823. .count = TF_ENC_TEST_VECTORS
  2824. },
  2825. .dec = {
  2826. .vecs = tf_dec_tv_template,
  2827. .count = TF_DEC_TEST_VECTORS
  2828. }
  2829. }
  2830. }
  2831. }, {
  2832. .alg = "ecb(xeta)",
  2833. .test = alg_test_skcipher,
  2834. .suite = {
  2835. .cipher = {
  2836. .enc = {
  2837. .vecs = xeta_enc_tv_template,
  2838. .count = XETA_ENC_TEST_VECTORS
  2839. },
  2840. .dec = {
  2841. .vecs = xeta_dec_tv_template,
  2842. .count = XETA_DEC_TEST_VECTORS
  2843. }
  2844. }
  2845. }
  2846. }, {
  2847. .alg = "ecb(xtea)",
  2848. .test = alg_test_skcipher,
  2849. .suite = {
  2850. .cipher = {
  2851. .enc = {
  2852. .vecs = xtea_enc_tv_template,
  2853. .count = XTEA_ENC_TEST_VECTORS
  2854. },
  2855. .dec = {
  2856. .vecs = xtea_dec_tv_template,
  2857. .count = XTEA_DEC_TEST_VECTORS
  2858. }
  2859. }
  2860. }
  2861. }, {
  2862. .alg = "gcm(aes)",
  2863. .test = alg_test_aead,
  2864. .fips_allowed = 1,
  2865. .suite = {
  2866. .aead = {
  2867. .enc = {
  2868. .vecs = aes_gcm_enc_tv_template,
  2869. .count = AES_GCM_ENC_TEST_VECTORS
  2870. },
  2871. .dec = {
  2872. .vecs = aes_gcm_dec_tv_template,
  2873. .count = AES_GCM_DEC_TEST_VECTORS
  2874. }
  2875. }
  2876. }
  2877. }, {
  2878. .alg = "ghash",
  2879. .test = alg_test_hash,
  2880. .fips_allowed = 1,
  2881. .suite = {
  2882. .hash = {
  2883. .vecs = ghash_tv_template,
  2884. .count = GHASH_TEST_VECTORS
  2885. }
  2886. }
  2887. }, {
  2888. .alg = "hmac(crc32)",
  2889. .test = alg_test_hash,
  2890. .suite = {
  2891. .hash = {
  2892. .vecs = bfin_crc_tv_template,
  2893. .count = BFIN_CRC_TEST_VECTORS
  2894. }
  2895. }
  2896. }, {
  2897. .alg = "hmac(md5)",
  2898. .test = alg_test_hash,
  2899. .suite = {
  2900. .hash = {
  2901. .vecs = hmac_md5_tv_template,
  2902. .count = HMAC_MD5_TEST_VECTORS
  2903. }
  2904. }
  2905. }, {
  2906. .alg = "hmac(rmd128)",
  2907. .test = alg_test_hash,
  2908. .suite = {
  2909. .hash = {
  2910. .vecs = hmac_rmd128_tv_template,
  2911. .count = HMAC_RMD128_TEST_VECTORS
  2912. }
  2913. }
  2914. }, {
  2915. .alg = "hmac(rmd160)",
  2916. .test = alg_test_hash,
  2917. .suite = {
  2918. .hash = {
  2919. .vecs = hmac_rmd160_tv_template,
  2920. .count = HMAC_RMD160_TEST_VECTORS
  2921. }
  2922. }
  2923. }, {
  2924. .alg = "hmac(sha1)",
  2925. .test = alg_test_hash,
  2926. .fips_allowed = 1,
  2927. .suite = {
  2928. .hash = {
  2929. .vecs = hmac_sha1_tv_template,
  2930. .count = HMAC_SHA1_TEST_VECTORS
  2931. }
  2932. }
  2933. }, {
  2934. .alg = "hmac(sha224)",
  2935. .test = alg_test_hash,
  2936. .fips_allowed = 1,
  2937. .suite = {
  2938. .hash = {
  2939. .vecs = hmac_sha224_tv_template,
  2940. .count = HMAC_SHA224_TEST_VECTORS
  2941. }
  2942. }
  2943. }, {
  2944. .alg = "hmac(sha256)",
  2945. .test = alg_test_hash,
  2946. .fips_allowed = 1,
  2947. .suite = {
  2948. .hash = {
  2949. .vecs = hmac_sha256_tv_template,
  2950. .count = HMAC_SHA256_TEST_VECTORS
  2951. }
  2952. }
  2953. }, {
  2954. .alg = "hmac(sha384)",
  2955. .test = alg_test_hash,
  2956. .fips_allowed = 1,
  2957. .suite = {
  2958. .hash = {
  2959. .vecs = hmac_sha384_tv_template,
  2960. .count = HMAC_SHA384_TEST_VECTORS
  2961. }
  2962. }
  2963. }, {
  2964. .alg = "hmac(sha512)",
  2965. .test = alg_test_hash,
  2966. .fips_allowed = 1,
  2967. .suite = {
  2968. .hash = {
  2969. .vecs = hmac_sha512_tv_template,
  2970. .count = HMAC_SHA512_TEST_VECTORS
  2971. }
  2972. }
  2973. }, {
  2974. .alg = "jitterentropy_rng",
  2975. .fips_allowed = 1,
  2976. .test = alg_test_null,
  2977. }, {
  2978. .alg = "lrw(aes)",
  2979. .test = alg_test_skcipher,
  2980. .suite = {
  2981. .cipher = {
  2982. .enc = {
  2983. .vecs = aes_lrw_enc_tv_template,
  2984. .count = AES_LRW_ENC_TEST_VECTORS
  2985. },
  2986. .dec = {
  2987. .vecs = aes_lrw_dec_tv_template,
  2988. .count = AES_LRW_DEC_TEST_VECTORS
  2989. }
  2990. }
  2991. }
  2992. }, {
  2993. .alg = "lrw(camellia)",
  2994. .test = alg_test_skcipher,
  2995. .suite = {
  2996. .cipher = {
  2997. .enc = {
  2998. .vecs = camellia_lrw_enc_tv_template,
  2999. .count = CAMELLIA_LRW_ENC_TEST_VECTORS
  3000. },
  3001. .dec = {
  3002. .vecs = camellia_lrw_dec_tv_template,
  3003. .count = CAMELLIA_LRW_DEC_TEST_VECTORS
  3004. }
  3005. }
  3006. }
  3007. }, {
  3008. .alg = "lrw(cast6)",
  3009. .test = alg_test_skcipher,
  3010. .suite = {
  3011. .cipher = {
  3012. .enc = {
  3013. .vecs = cast6_lrw_enc_tv_template,
  3014. .count = CAST6_LRW_ENC_TEST_VECTORS
  3015. },
  3016. .dec = {
  3017. .vecs = cast6_lrw_dec_tv_template,
  3018. .count = CAST6_LRW_DEC_TEST_VECTORS
  3019. }
  3020. }
  3021. }
  3022. }, {
  3023. .alg = "lrw(serpent)",
  3024. .test = alg_test_skcipher,
  3025. .suite = {
  3026. .cipher = {
  3027. .enc = {
  3028. .vecs = serpent_lrw_enc_tv_template,
  3029. .count = SERPENT_LRW_ENC_TEST_VECTORS
  3030. },
  3031. .dec = {
  3032. .vecs = serpent_lrw_dec_tv_template,
  3033. .count = SERPENT_LRW_DEC_TEST_VECTORS
  3034. }
  3035. }
  3036. }
  3037. }, {
  3038. .alg = "lrw(twofish)",
  3039. .test = alg_test_skcipher,
  3040. .suite = {
  3041. .cipher = {
  3042. .enc = {
  3043. .vecs = tf_lrw_enc_tv_template,
  3044. .count = TF_LRW_ENC_TEST_VECTORS
  3045. },
  3046. .dec = {
  3047. .vecs = tf_lrw_dec_tv_template,
  3048. .count = TF_LRW_DEC_TEST_VECTORS
  3049. }
  3050. }
  3051. }
  3052. }, {
  3053. .alg = "lz4",
  3054. .test = alg_test_comp,
  3055. .fips_allowed = 1,
  3056. .suite = {
  3057. .comp = {
  3058. .comp = {
  3059. .vecs = lz4_comp_tv_template,
  3060. .count = LZ4_COMP_TEST_VECTORS
  3061. },
  3062. .decomp = {
  3063. .vecs = lz4_decomp_tv_template,
  3064. .count = LZ4_DECOMP_TEST_VECTORS
  3065. }
  3066. }
  3067. }
  3068. }, {
  3069. .alg = "lz4hc",
  3070. .test = alg_test_comp,
  3071. .fips_allowed = 1,
  3072. .suite = {
  3073. .comp = {
  3074. .comp = {
  3075. .vecs = lz4hc_comp_tv_template,
  3076. .count = LZ4HC_COMP_TEST_VECTORS
  3077. },
  3078. .decomp = {
  3079. .vecs = lz4hc_decomp_tv_template,
  3080. .count = LZ4HC_DECOMP_TEST_VECTORS
  3081. }
  3082. }
  3083. }
  3084. }, {
  3085. .alg = "lzo",
  3086. .test = alg_test_comp,
  3087. .fips_allowed = 1,
  3088. .suite = {
  3089. .comp = {
  3090. .comp = {
  3091. .vecs = lzo_comp_tv_template,
  3092. .count = LZO_COMP_TEST_VECTORS
  3093. },
  3094. .decomp = {
  3095. .vecs = lzo_decomp_tv_template,
  3096. .count = LZO_DECOMP_TEST_VECTORS
  3097. }
  3098. }
  3099. }
  3100. }, {
  3101. .alg = "md4",
  3102. .test = alg_test_hash,
  3103. .suite = {
  3104. .hash = {
  3105. .vecs = md4_tv_template,
  3106. .count = MD4_TEST_VECTORS
  3107. }
  3108. }
  3109. }, {
  3110. .alg = "md5",
  3111. .test = alg_test_hash,
  3112. .suite = {
  3113. .hash = {
  3114. .vecs = md5_tv_template,
  3115. .count = MD5_TEST_VECTORS
  3116. }
  3117. }
  3118. }, {
  3119. .alg = "michael_mic",
  3120. .test = alg_test_hash,
  3121. .suite = {
  3122. .hash = {
  3123. .vecs = michael_mic_tv_template,
  3124. .count = MICHAEL_MIC_TEST_VECTORS
  3125. }
  3126. }
  3127. }, {
  3128. .alg = "ofb(aes)",
  3129. .test = alg_test_skcipher,
  3130. .fips_allowed = 1,
  3131. .suite = {
  3132. .cipher = {
  3133. .enc = {
  3134. .vecs = aes_ofb_enc_tv_template,
  3135. .count = AES_OFB_ENC_TEST_VECTORS
  3136. },
  3137. .dec = {
  3138. .vecs = aes_ofb_dec_tv_template,
  3139. .count = AES_OFB_DEC_TEST_VECTORS
  3140. }
  3141. }
  3142. }
  3143. }, {
  3144. .alg = "pcbc(fcrypt)",
  3145. .test = alg_test_skcipher,
  3146. .suite = {
  3147. .cipher = {
  3148. .enc = {
  3149. .vecs = fcrypt_pcbc_enc_tv_template,
  3150. .count = FCRYPT_ENC_TEST_VECTORS
  3151. },
  3152. .dec = {
  3153. .vecs = fcrypt_pcbc_dec_tv_template,
  3154. .count = FCRYPT_DEC_TEST_VECTORS
  3155. }
  3156. }
  3157. }
  3158. }, {
  3159. .alg = "poly1305",
  3160. .test = alg_test_hash,
  3161. .suite = {
  3162. .hash = {
  3163. .vecs = poly1305_tv_template,
  3164. .count = POLY1305_TEST_VECTORS
  3165. }
  3166. }
  3167. }, {
  3168. .alg = "rfc3686(ctr(aes))",
  3169. .test = alg_test_skcipher,
  3170. .fips_allowed = 1,
  3171. .suite = {
  3172. .cipher = {
  3173. .enc = {
  3174. .vecs = aes_ctr_rfc3686_enc_tv_template,
  3175. .count = AES_CTR_3686_ENC_TEST_VECTORS
  3176. },
  3177. .dec = {
  3178. .vecs = aes_ctr_rfc3686_dec_tv_template,
  3179. .count = AES_CTR_3686_DEC_TEST_VECTORS
  3180. }
  3181. }
  3182. }
  3183. }, {
  3184. .alg = "rfc4106(gcm(aes))",
  3185. .test = alg_test_aead,
  3186. .fips_allowed = 1,
  3187. .suite = {
  3188. .aead = {
  3189. .enc = {
  3190. .vecs = aes_gcm_rfc4106_enc_tv_template,
  3191. .count = AES_GCM_4106_ENC_TEST_VECTORS
  3192. },
  3193. .dec = {
  3194. .vecs = aes_gcm_rfc4106_dec_tv_template,
  3195. .count = AES_GCM_4106_DEC_TEST_VECTORS
  3196. }
  3197. }
  3198. }
  3199. }, {
  3200. .alg = "rfc4309(ccm(aes))",
  3201. .test = alg_test_aead,
  3202. .fips_allowed = 1,
  3203. .suite = {
  3204. .aead = {
  3205. .enc = {
  3206. .vecs = aes_ccm_rfc4309_enc_tv_template,
  3207. .count = AES_CCM_4309_ENC_TEST_VECTORS
  3208. },
  3209. .dec = {
  3210. .vecs = aes_ccm_rfc4309_dec_tv_template,
  3211. .count = AES_CCM_4309_DEC_TEST_VECTORS
  3212. }
  3213. }
  3214. }
  3215. }, {
  3216. .alg = "rfc4543(gcm(aes))",
  3217. .test = alg_test_aead,
  3218. .suite = {
  3219. .aead = {
  3220. .enc = {
  3221. .vecs = aes_gcm_rfc4543_enc_tv_template,
  3222. .count = AES_GCM_4543_ENC_TEST_VECTORS
  3223. },
  3224. .dec = {
  3225. .vecs = aes_gcm_rfc4543_dec_tv_template,
  3226. .count = AES_GCM_4543_DEC_TEST_VECTORS
  3227. },
  3228. }
  3229. }
  3230. }, {
  3231. .alg = "rfc7539(chacha20,poly1305)",
  3232. .test = alg_test_aead,
  3233. .suite = {
  3234. .aead = {
  3235. .enc = {
  3236. .vecs = rfc7539_enc_tv_template,
  3237. .count = RFC7539_ENC_TEST_VECTORS
  3238. },
  3239. .dec = {
  3240. .vecs = rfc7539_dec_tv_template,
  3241. .count = RFC7539_DEC_TEST_VECTORS
  3242. },
  3243. }
  3244. }
  3245. }, {
  3246. .alg = "rfc7539esp(chacha20,poly1305)",
  3247. .test = alg_test_aead,
  3248. .suite = {
  3249. .aead = {
  3250. .enc = {
  3251. .vecs = rfc7539esp_enc_tv_template,
  3252. .count = RFC7539ESP_ENC_TEST_VECTORS
  3253. },
  3254. .dec = {
  3255. .vecs = rfc7539esp_dec_tv_template,
  3256. .count = RFC7539ESP_DEC_TEST_VECTORS
  3257. },
  3258. }
  3259. }
  3260. }, {
  3261. .alg = "rmd128",
  3262. .test = alg_test_hash,
  3263. .suite = {
  3264. .hash = {
  3265. .vecs = rmd128_tv_template,
  3266. .count = RMD128_TEST_VECTORS
  3267. }
  3268. }
  3269. }, {
  3270. .alg = "rmd160",
  3271. .test = alg_test_hash,
  3272. .suite = {
  3273. .hash = {
  3274. .vecs = rmd160_tv_template,
  3275. .count = RMD160_TEST_VECTORS
  3276. }
  3277. }
  3278. }, {
  3279. .alg = "rmd256",
  3280. .test = alg_test_hash,
  3281. .suite = {
  3282. .hash = {
  3283. .vecs = rmd256_tv_template,
  3284. .count = RMD256_TEST_VECTORS
  3285. }
  3286. }
  3287. }, {
  3288. .alg = "rmd320",
  3289. .test = alg_test_hash,
  3290. .suite = {
  3291. .hash = {
  3292. .vecs = rmd320_tv_template,
  3293. .count = RMD320_TEST_VECTORS
  3294. }
  3295. }
  3296. }, {
  3297. .alg = "rsa",
  3298. .test = alg_test_akcipher,
  3299. .fips_allowed = 1,
  3300. .suite = {
  3301. .akcipher = {
  3302. .vecs = rsa_tv_template,
  3303. .count = RSA_TEST_VECTORS
  3304. }
  3305. }
  3306. }, {
  3307. .alg = "salsa20",
  3308. .test = alg_test_skcipher,
  3309. .suite = {
  3310. .cipher = {
  3311. .enc = {
  3312. .vecs = salsa20_stream_enc_tv_template,
  3313. .count = SALSA20_STREAM_ENC_TEST_VECTORS
  3314. }
  3315. }
  3316. }
  3317. }, {
  3318. .alg = "sha1",
  3319. .test = alg_test_hash,
  3320. .fips_allowed = 1,
  3321. .suite = {
  3322. .hash = {
  3323. .vecs = sha1_tv_template,
  3324. .count = SHA1_TEST_VECTORS
  3325. }
  3326. }
  3327. }, {
  3328. .alg = "sha224",
  3329. .test = alg_test_hash,
  3330. .fips_allowed = 1,
  3331. .suite = {
  3332. .hash = {
  3333. .vecs = sha224_tv_template,
  3334. .count = SHA224_TEST_VECTORS
  3335. }
  3336. }
  3337. }, {
  3338. .alg = "sha256",
  3339. .test = alg_test_hash,
  3340. .fips_allowed = 1,
  3341. .suite = {
  3342. .hash = {
  3343. .vecs = sha256_tv_template,
  3344. .count = SHA256_TEST_VECTORS
  3345. }
  3346. }
  3347. }, {
  3348. .alg = "sha384",
  3349. .test = alg_test_hash,
  3350. .fips_allowed = 1,
  3351. .suite = {
  3352. .hash = {
  3353. .vecs = sha384_tv_template,
  3354. .count = SHA384_TEST_VECTORS
  3355. }
  3356. }
  3357. }, {
  3358. .alg = "sha512",
  3359. .test = alg_test_hash,
  3360. .fips_allowed = 1,
  3361. .suite = {
  3362. .hash = {
  3363. .vecs = sha512_tv_template,
  3364. .count = SHA512_TEST_VECTORS
  3365. }
  3366. }
  3367. }, {
  3368. .alg = "tgr128",
  3369. .test = alg_test_hash,
  3370. .suite = {
  3371. .hash = {
  3372. .vecs = tgr128_tv_template,
  3373. .count = TGR128_TEST_VECTORS
  3374. }
  3375. }
  3376. }, {
  3377. .alg = "tgr160",
  3378. .test = alg_test_hash,
  3379. .suite = {
  3380. .hash = {
  3381. .vecs = tgr160_tv_template,
  3382. .count = TGR160_TEST_VECTORS
  3383. }
  3384. }
  3385. }, {
  3386. .alg = "tgr192",
  3387. .test = alg_test_hash,
  3388. .suite = {
  3389. .hash = {
  3390. .vecs = tgr192_tv_template,
  3391. .count = TGR192_TEST_VECTORS
  3392. }
  3393. }
  3394. }, {
  3395. .alg = "vmac(aes)",
  3396. .test = alg_test_hash,
  3397. .suite = {
  3398. .hash = {
  3399. .vecs = aes_vmac128_tv_template,
  3400. .count = VMAC_AES_TEST_VECTORS
  3401. }
  3402. }
  3403. }, {
  3404. .alg = "wp256",
  3405. .test = alg_test_hash,
  3406. .suite = {
  3407. .hash = {
  3408. .vecs = wp256_tv_template,
  3409. .count = WP256_TEST_VECTORS
  3410. }
  3411. }
  3412. }, {
  3413. .alg = "wp384",
  3414. .test = alg_test_hash,
  3415. .suite = {
  3416. .hash = {
  3417. .vecs = wp384_tv_template,
  3418. .count = WP384_TEST_VECTORS
  3419. }
  3420. }
  3421. }, {
  3422. .alg = "wp512",
  3423. .test = alg_test_hash,
  3424. .suite = {
  3425. .hash = {
  3426. .vecs = wp512_tv_template,
  3427. .count = WP512_TEST_VECTORS
  3428. }
  3429. }
  3430. }, {
  3431. .alg = "xcbc(aes)",
  3432. .test = alg_test_hash,
  3433. .suite = {
  3434. .hash = {
  3435. .vecs = aes_xcbc128_tv_template,
  3436. .count = XCBC_AES_TEST_VECTORS
  3437. }
  3438. }
  3439. }, {
  3440. .alg = "xts(aes)",
  3441. .test = alg_test_skcipher,
  3442. .fips_allowed = 1,
  3443. .suite = {
  3444. .cipher = {
  3445. .enc = {
  3446. .vecs = aes_xts_enc_tv_template,
  3447. .count = AES_XTS_ENC_TEST_VECTORS
  3448. },
  3449. .dec = {
  3450. .vecs = aes_xts_dec_tv_template,
  3451. .count = AES_XTS_DEC_TEST_VECTORS
  3452. }
  3453. }
  3454. }
  3455. }, {
  3456. .alg = "xts(camellia)",
  3457. .test = alg_test_skcipher,
  3458. .suite = {
  3459. .cipher = {
  3460. .enc = {
  3461. .vecs = camellia_xts_enc_tv_template,
  3462. .count = CAMELLIA_XTS_ENC_TEST_VECTORS
  3463. },
  3464. .dec = {
  3465. .vecs = camellia_xts_dec_tv_template,
  3466. .count = CAMELLIA_XTS_DEC_TEST_VECTORS
  3467. }
  3468. }
  3469. }
  3470. }, {
  3471. .alg = "xts(cast6)",
  3472. .test = alg_test_skcipher,
  3473. .suite = {
  3474. .cipher = {
  3475. .enc = {
  3476. .vecs = cast6_xts_enc_tv_template,
  3477. .count = CAST6_XTS_ENC_TEST_VECTORS
  3478. },
  3479. .dec = {
  3480. .vecs = cast6_xts_dec_tv_template,
  3481. .count = CAST6_XTS_DEC_TEST_VECTORS
  3482. }
  3483. }
  3484. }
  3485. }, {
  3486. .alg = "xts(serpent)",
  3487. .test = alg_test_skcipher,
  3488. .suite = {
  3489. .cipher = {
  3490. .enc = {
  3491. .vecs = serpent_xts_enc_tv_template,
  3492. .count = SERPENT_XTS_ENC_TEST_VECTORS
  3493. },
  3494. .dec = {
  3495. .vecs = serpent_xts_dec_tv_template,
  3496. .count = SERPENT_XTS_DEC_TEST_VECTORS
  3497. }
  3498. }
  3499. }
  3500. }, {
  3501. .alg = "xts(twofish)",
  3502. .test = alg_test_skcipher,
  3503. .suite = {
  3504. .cipher = {
  3505. .enc = {
  3506. .vecs = tf_xts_enc_tv_template,
  3507. .count = TF_XTS_ENC_TEST_VECTORS
  3508. },
  3509. .dec = {
  3510. .vecs = tf_xts_dec_tv_template,
  3511. .count = TF_XTS_DEC_TEST_VECTORS
  3512. }
  3513. }
  3514. }
  3515. }, {
  3516. .alg = "zlib",
  3517. .test = alg_test_pcomp,
  3518. .fips_allowed = 1,
  3519. .suite = {
  3520. .pcomp = {
  3521. .comp = {
  3522. .vecs = zlib_comp_tv_template,
  3523. .count = ZLIB_COMP_TEST_VECTORS
  3524. },
  3525. .decomp = {
  3526. .vecs = zlib_decomp_tv_template,
  3527. .count = ZLIB_DECOMP_TEST_VECTORS
  3528. }
  3529. }
  3530. }
  3531. }
  3532. };
  3533. static bool alg_test_descs_checked;
  3534. static void alg_test_descs_check_order(void)
  3535. {
  3536. int i;
  3537. /* only check once */
  3538. if (alg_test_descs_checked)
  3539. return;
  3540. alg_test_descs_checked = true;
  3541. for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
  3542. int diff = strcmp(alg_test_descs[i - 1].alg,
  3543. alg_test_descs[i].alg);
  3544. if (WARN_ON(diff > 0)) {
  3545. pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
  3546. alg_test_descs[i - 1].alg,
  3547. alg_test_descs[i].alg);
  3548. }
  3549. if (WARN_ON(diff == 0)) {
  3550. pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
  3551. alg_test_descs[i].alg);
  3552. }
  3553. }
  3554. }
  3555. static int alg_find_test(const char *alg)
  3556. {
  3557. int start = 0;
  3558. int end = ARRAY_SIZE(alg_test_descs);
  3559. while (start < end) {
  3560. int i = (start + end) / 2;
  3561. int diff = strcmp(alg_test_descs[i].alg, alg);
  3562. if (diff > 0) {
  3563. end = i;
  3564. continue;
  3565. }
  3566. if (diff < 0) {
  3567. start = i + 1;
  3568. continue;
  3569. }
  3570. return i;
  3571. }
  3572. return -1;
  3573. }
  3574. int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
  3575. {
  3576. int i;
  3577. int j;
  3578. int rc;
  3579. alg_test_descs_check_order();
  3580. if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
  3581. char nalg[CRYPTO_MAX_ALG_NAME];
  3582. if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
  3583. sizeof(nalg))
  3584. return -ENAMETOOLONG;
  3585. i = alg_find_test(nalg);
  3586. if (i < 0)
  3587. goto notest;
  3588. if (fips_enabled && !alg_test_descs[i].fips_allowed)
  3589. goto non_fips_alg;
  3590. rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
  3591. goto test_done;
  3592. }
  3593. i = alg_find_test(alg);
  3594. j = alg_find_test(driver);
  3595. if (i < 0 && j < 0)
  3596. goto notest;
  3597. if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
  3598. (j >= 0 && !alg_test_descs[j].fips_allowed)))
  3599. goto non_fips_alg;
  3600. rc = 0;
  3601. if (i >= 0)
  3602. rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
  3603. type, mask);
  3604. if (j >= 0 && j != i)
  3605. rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
  3606. type, mask);
  3607. test_done:
  3608. if (fips_enabled && rc)
  3609. panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
  3610. if (fips_enabled && !rc)
  3611. pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
  3612. return rc;
  3613. notest:
  3614. printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
  3615. return 0;
  3616. non_fips_alg:
  3617. return -EINVAL;
  3618. }
  3619. #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
  3620. EXPORT_SYMBOL_GPL(alg_test);