testmgr.c 90 KB

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