testmgr.c 84 KB

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