testmgr.c 84 KB

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