testmgr.c 90 KB

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