testmgr.c 85 KB

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