testmgr.c 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172
  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/hash.h>
  23. #include <linux/err.h>
  24. #include <linux/module.h>
  25. #include <linux/scatterlist.h>
  26. #include <linux/slab.h>
  27. #include <linux/string.h>
  28. #include <crypto/rng.h>
  29. #ifdef CONFIG_CRYPTO_DRBG
  30. #include <crypto/drbg.h>
  31. #endif
  32. #include "internal.h"
  33. #ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
  34. /* a perfect nop */
  35. int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
  36. {
  37. return 0;
  38. }
  39. #ifdef CONFIG_CRYPTO_FIPS
  40. bool in_fips_err()
  41. {
  42. return false;
  43. }
  44. EXPORT_SYMBOL_GPL(in_fips_err);
  45. #endif
  46. #else
  47. #include "testmgr.h"
  48. /*
  49. * Need slab memory for testing (size in number of pages).
  50. */
  51. #define XBUFSIZE 8
  52. /*
  53. * Indexes into the xbuf to simulate cross-page access.
  54. */
  55. #define IDX1 32
  56. #define IDX2 32400
  57. #define IDX3 1
  58. #define IDX4 8193
  59. #define IDX5 22222
  60. #define IDX6 17101
  61. #define IDX7 27333
  62. #define IDX8 3000
  63. /*
  64. * Used by test_cipher()
  65. */
  66. #define ENCRYPT 1
  67. #define DECRYPT 0
  68. #ifdef CONFIG_CRYPTO_FIPS
  69. #define FIPS_ERR 1
  70. #define FIPS_NO_ERR 0
  71. static int IN_FIPS_ERROR = FIPS_NO_ERR;
  72. #endif
  73. struct tcrypt_result {
  74. struct completion completion;
  75. int err;
  76. };
  77. struct aead_test_suite {
  78. struct {
  79. struct aead_testvec *vecs;
  80. unsigned int count;
  81. } enc, dec;
  82. };
  83. struct cipher_test_suite {
  84. struct {
  85. struct cipher_testvec *vecs;
  86. unsigned int count;
  87. } enc, dec;
  88. };
  89. struct comp_test_suite {
  90. struct {
  91. struct comp_testvec *vecs;
  92. unsigned int count;
  93. } comp, decomp;
  94. };
  95. struct pcomp_test_suite {
  96. struct {
  97. struct pcomp_testvec *vecs;
  98. unsigned int count;
  99. } comp, decomp;
  100. };
  101. struct hash_test_suite {
  102. struct hash_testvec *vecs;
  103. unsigned int count;
  104. };
  105. struct cprng_test_suite {
  106. struct cprng_testvec *vecs;
  107. unsigned int count;
  108. };
  109. #ifdef CONFIG_CRYPTO_DRBG
  110. struct drbg_test_suite {
  111. struct drbg_testvec *vecs;
  112. unsigned int count;
  113. };
  114. #endif
  115. struct alg_test_desc {
  116. const char *alg;
  117. int (*test)(const struct alg_test_desc *desc, const char *driver,
  118. u32 type, u32 mask);
  119. int fips_allowed; /* set if alg is allowed in fips mode */
  120. union {
  121. struct aead_test_suite aead;
  122. struct cipher_test_suite cipher;
  123. struct comp_test_suite comp;
  124. struct pcomp_test_suite pcomp;
  125. struct hash_test_suite hash;
  126. struct cprng_test_suite cprng;
  127. #ifdef CONFIG_CRYPTO_DRBG
  128. struct drbg_test_suite drbg;
  129. #endif
  130. } suite;
  131. };
  132. static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
  133. #ifdef CONFIG_CRYPTO_FIPS
  134. bool in_fips_err()
  135. {
  136. return (IN_FIPS_ERROR == FIPS_ERR);
  137. }
  138. void set_in_fips_err()
  139. {
  140. IN_FIPS_ERROR = FIPS_ERR;
  141. }
  142. #endif
  143. #if FIPS_FUNC_TEST == 4
  144. void hexdump(unsigned char *buf, unsigned int len)
  145. #else
  146. static void hexdump(unsigned char *buf, unsigned int len)
  147. #endif
  148. {
  149. print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
  150. 16, 1,
  151. buf, len, false);
  152. }
  153. static void tcrypt_complete(struct crypto_async_request *req, int err)
  154. {
  155. struct tcrypt_result *res = req->data;
  156. if (err == -EINPROGRESS)
  157. return;
  158. res->err = err;
  159. complete(&res->completion);
  160. }
  161. static int testmgr_alloc_buf(char *buf[XBUFSIZE])
  162. {
  163. int i;
  164. for (i = 0; i < XBUFSIZE; i++) {
  165. buf[i] = (void *)__get_free_page(GFP_KERNEL);
  166. if (!buf[i])
  167. goto err_free_buf;
  168. }
  169. return 0;
  170. err_free_buf:
  171. while (i-- > 0)
  172. free_page((unsigned long)buf[i]);
  173. return -ENOMEM;
  174. }
  175. static void testmgr_free_buf(char *buf[XBUFSIZE])
  176. {
  177. int i;
  178. for (i = 0; i < XBUFSIZE; i++)
  179. free_page((unsigned long)buf[i]);
  180. }
  181. static int do_one_async_hash_op(struct ahash_request *req,
  182. struct tcrypt_result *tr,
  183. int ret)
  184. {
  185. if (ret == -EINPROGRESS || ret == -EBUSY) {
  186. ret = wait_for_completion_interruptible(&tr->completion);
  187. if (!ret)
  188. ret = tr->err;
  189. INIT_COMPLETION(tr->completion);
  190. }
  191. return ret;
  192. }
  193. static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
  194. unsigned int tcount, bool use_digest)
  195. {
  196. const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
  197. unsigned int i, j, k, temp;
  198. struct scatterlist sg[8];
  199. char result[64];
  200. struct ahash_request *req;
  201. struct tcrypt_result tresult;
  202. void *hash_buff;
  203. char *xbuf[XBUFSIZE];
  204. int ret = -ENOMEM;
  205. if (testmgr_alloc_buf(xbuf))
  206. goto out_nobuf;
  207. init_completion(&tresult.completion);
  208. req = ahash_request_alloc(tfm, GFP_KERNEL);
  209. if (!req) {
  210. printk(KERN_ERR "alg: hash: Failed to allocate request for "
  211. "%s\n", algo);
  212. goto out_noreq;
  213. }
  214. ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  215. tcrypt_complete, &tresult);
  216. j = 0;
  217. for (i = 0; i < tcount; i++) {
  218. if (template[i].np)
  219. continue;
  220. j++;
  221. memset(result, 0, 64);
  222. hash_buff = xbuf[0];
  223. memcpy(hash_buff, template[i].plaintext, template[i].psize);
  224. sg_init_one(&sg[0], hash_buff, template[i].psize);
  225. if (template[i].ksize) {
  226. crypto_ahash_clear_flags(tfm, ~0);
  227. ret = crypto_ahash_setkey(tfm, template[i].key,
  228. template[i].ksize);
  229. if (ret) {
  230. printk(KERN_ERR "alg: hash: setkey failed on "
  231. "test %d for %s: ret=%d\n", j, algo,
  232. -ret);
  233. goto out;
  234. }
  235. }
  236. ahash_request_set_crypt(req, sg, result, template[i].psize);
  237. if (use_digest) {
  238. ret = do_one_async_hash_op(req, &tresult,
  239. crypto_ahash_digest(req));
  240. if (ret) {
  241. pr_err("alg: hash: digest failed on test %d "
  242. "for %s: ret=%d\n", j, algo, -ret);
  243. goto out;
  244. }
  245. } else {
  246. ret = do_one_async_hash_op(req, &tresult,
  247. crypto_ahash_init(req));
  248. if (ret) {
  249. pr_err("alt: hash: init failed on test %d "
  250. "for %s: ret=%d\n", j, algo, -ret);
  251. goto out;
  252. }
  253. ret = do_one_async_hash_op(req, &tresult,
  254. crypto_ahash_update(req));
  255. if (ret) {
  256. pr_err("alt: hash: update failed on test %d "
  257. "for %s: ret=%d\n", j, algo, -ret);
  258. goto out;
  259. }
  260. ret = do_one_async_hash_op(req, &tresult,
  261. crypto_ahash_final(req));
  262. if (ret) {
  263. pr_err("alt: hash: final failed on test %d "
  264. "for %s: ret=%d\n", j, algo, -ret);
  265. goto out;
  266. }
  267. }
  268. if (memcmp(result, template[i].digest,
  269. crypto_ahash_digestsize(tfm))) {
  270. printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
  271. j, algo);
  272. hexdump(result, crypto_ahash_digestsize(tfm));
  273. ret = -EINVAL;
  274. goto out;
  275. }
  276. }
  277. j = 0;
  278. for (i = 0; i < tcount; i++) {
  279. if (template[i].np) {
  280. j++;
  281. memset(result, 0, 64);
  282. temp = 0;
  283. sg_init_table(sg, template[i].np);
  284. ret = -EINVAL;
  285. for (k = 0; k < template[i].np; k++) {
  286. if (WARN_ON(offset_in_page(IDX[k]) +
  287. template[i].tap[k] > PAGE_SIZE))
  288. goto out;
  289. sg_set_buf(&sg[k],
  290. memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
  291. offset_in_page(IDX[k]),
  292. template[i].plaintext + temp,
  293. template[i].tap[k]),
  294. template[i].tap[k]);
  295. temp += template[i].tap[k];
  296. }
  297. if (template[i].ksize) {
  298. crypto_ahash_clear_flags(tfm, ~0);
  299. ret = crypto_ahash_setkey(tfm, template[i].key,
  300. template[i].ksize);
  301. if (ret) {
  302. printk(KERN_ERR "alg: hash: setkey "
  303. "failed on chunking test %d "
  304. "for %s: ret=%d\n", j, algo,
  305. -ret);
  306. goto out;
  307. }
  308. }
  309. ahash_request_set_crypt(req, sg, result,
  310. template[i].psize);
  311. ret = crypto_ahash_digest(req);
  312. switch (ret) {
  313. case 0:
  314. break;
  315. case -EINPROGRESS:
  316. case -EBUSY:
  317. ret = wait_for_completion_interruptible(
  318. &tresult.completion);
  319. if (!ret && !(ret = tresult.err)) {
  320. INIT_COMPLETION(tresult.completion);
  321. break;
  322. }
  323. /* fall through */
  324. default:
  325. printk(KERN_ERR "alg: hash: digest failed "
  326. "on chunking test %d for %s: "
  327. "ret=%d\n", j, algo, -ret);
  328. goto out;
  329. }
  330. if (memcmp(result, template[i].digest,
  331. crypto_ahash_digestsize(tfm))) {
  332. printk(KERN_ERR "alg: hash: Chunking test %d "
  333. "failed for %s\n", j, algo);
  334. hexdump(result, crypto_ahash_digestsize(tfm));
  335. ret = -EINVAL;
  336. goto out;
  337. }
  338. }
  339. }
  340. ret = 0;
  341. out:
  342. ahash_request_free(req);
  343. out_noreq:
  344. testmgr_free_buf(xbuf);
  345. out_nobuf:
  346. return ret;
  347. }
  348. static int test_aead(struct crypto_aead *tfm, int enc,
  349. struct aead_testvec *template, unsigned int tcount)
  350. {
  351. const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
  352. unsigned int i, j, k, n, temp;
  353. int ret = -ENOMEM;
  354. char *q;
  355. char *key;
  356. struct aead_request *req;
  357. struct scatterlist sg[8];
  358. struct scatterlist asg[8];
  359. const char *e;
  360. struct tcrypt_result result;
  361. unsigned int authsize;
  362. void *input;
  363. void *assoc;
  364. char iv[MAX_IVLEN];
  365. char *xbuf[XBUFSIZE];
  366. char *axbuf[XBUFSIZE];
  367. if (testmgr_alloc_buf(xbuf))
  368. goto out_noxbuf;
  369. if (testmgr_alloc_buf(axbuf))
  370. goto out_noaxbuf;
  371. if (enc == ENCRYPT)
  372. e = "encryption";
  373. else
  374. e = "decryption";
  375. init_completion(&result.completion);
  376. req = aead_request_alloc(tfm, GFP_KERNEL);
  377. if (!req) {
  378. printk(KERN_ERR "alg: aead: Failed to allocate request for "
  379. "%s\n", algo);
  380. goto out;
  381. }
  382. aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  383. tcrypt_complete, &result);
  384. for (i = 0, j = 0; i < tcount; i++) {
  385. if (!template[i].np) {
  386. j++;
  387. /* some tepmplates have no input data but they will
  388. * touch input
  389. */
  390. input = xbuf[0];
  391. assoc = axbuf[0];
  392. ret = -EINVAL;
  393. if (WARN_ON(template[i].ilen > PAGE_SIZE ||
  394. template[i].alen > PAGE_SIZE))
  395. goto out;
  396. memcpy(input, template[i].input, template[i].ilen);
  397. memcpy(assoc, template[i].assoc, template[i].alen);
  398. if (template[i].iv)
  399. memcpy(iv, template[i].iv, MAX_IVLEN);
  400. else
  401. memset(iv, 0, MAX_IVLEN);
  402. crypto_aead_clear_flags(tfm, ~0);
  403. if (template[i].wk)
  404. crypto_aead_set_flags(
  405. tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  406. key = template[i].key;
  407. ret = crypto_aead_setkey(tfm, key,
  408. template[i].klen);
  409. if (!ret == template[i].fail) {
  410. printk(KERN_ERR "alg: aead: setkey failed on "
  411. "test %d for %s: flags=%x\n", j, algo,
  412. crypto_aead_get_flags(tfm));
  413. goto out;
  414. } else if (ret)
  415. continue;
  416. authsize = abs(template[i].rlen - template[i].ilen);
  417. ret = crypto_aead_setauthsize(tfm, authsize);
  418. if (ret) {
  419. printk(KERN_ERR "alg: aead: Failed to set "
  420. "authsize to %u on test %d for %s\n",
  421. authsize, j, algo);
  422. goto out;
  423. }
  424. sg_init_one(&sg[0], input,
  425. template[i].ilen + (enc ? authsize : 0));
  426. sg_init_one(&asg[0], assoc, template[i].alen);
  427. aead_request_set_crypt(req, sg, sg,
  428. template[i].ilen, iv);
  429. aead_request_set_assoc(req, asg, template[i].alen);
  430. ret = enc ?
  431. crypto_aead_encrypt(req) :
  432. crypto_aead_decrypt(req);
  433. switch (ret) {
  434. case 0:
  435. if (template[i].novrfy) {
  436. /* verification was supposed to fail */
  437. printk(KERN_ERR "alg: aead: %s failed "
  438. "on test %d for %s: ret was 0, "
  439. "expected -EBADMSG\n",
  440. e, j, algo);
  441. /* so really, we got a bad message */
  442. ret = -EBADMSG;
  443. goto out;
  444. }
  445. break;
  446. case -EINPROGRESS:
  447. case -EBUSY:
  448. ret = wait_for_completion_interruptible(
  449. &result.completion);
  450. if (!ret && !(ret = result.err)) {
  451. INIT_COMPLETION(result.completion);
  452. break;
  453. }
  454. case -EBADMSG:
  455. if (template[i].novrfy)
  456. /* verification failure was expected */
  457. continue;
  458. /* fall through */
  459. default:
  460. printk(KERN_ERR "alg: aead: %s failed on test "
  461. "%d for %s: ret=%d\n", e, j, algo, -ret);
  462. goto out;
  463. }
  464. q = input;
  465. if (memcmp(q, template[i].result, template[i].rlen)) {
  466. printk(KERN_ERR "alg: aead: Test %d failed on "
  467. "%s for %s\n", j, e, algo);
  468. hexdump(q, template[i].rlen);
  469. ret = -EINVAL;
  470. goto out;
  471. }
  472. }
  473. }
  474. for (i = 0, j = 0; i < tcount; i++) {
  475. if (template[i].np) {
  476. j++;
  477. if (template[i].iv)
  478. memcpy(iv, template[i].iv, MAX_IVLEN);
  479. else
  480. memset(iv, 0, MAX_IVLEN);
  481. crypto_aead_clear_flags(tfm, ~0);
  482. if (template[i].wk)
  483. crypto_aead_set_flags(
  484. tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  485. key = template[i].key;
  486. ret = crypto_aead_setkey(tfm, key, template[i].klen);
  487. if (!ret == template[i].fail) {
  488. printk(KERN_ERR "alg: aead: setkey failed on "
  489. "chunk test %d for %s: flags=%x\n", j,
  490. algo, crypto_aead_get_flags(tfm));
  491. goto out;
  492. } else if (ret)
  493. continue;
  494. authsize = abs(template[i].rlen - template[i].ilen);
  495. ret = -EINVAL;
  496. sg_init_table(sg, template[i].np);
  497. for (k = 0, temp = 0; k < template[i].np; k++) {
  498. if (WARN_ON(offset_in_page(IDX[k]) +
  499. template[i].tap[k] > PAGE_SIZE))
  500. goto out;
  501. q = xbuf[IDX[k] >> PAGE_SHIFT] +
  502. offset_in_page(IDX[k]);
  503. memcpy(q, template[i].input + temp,
  504. template[i].tap[k]);
  505. n = template[i].tap[k];
  506. if (k == template[i].np - 1 && enc)
  507. n += authsize;
  508. if (offset_in_page(q) + n < PAGE_SIZE)
  509. q[n] = 0;
  510. sg_set_buf(&sg[k], q, template[i].tap[k]);
  511. temp += template[i].tap[k];
  512. }
  513. ret = crypto_aead_setauthsize(tfm, authsize);
  514. if (ret) {
  515. printk(KERN_ERR "alg: aead: Failed to set "
  516. "authsize to %u on chunk test %d for "
  517. "%s\n", authsize, j, algo);
  518. goto out;
  519. }
  520. if (enc) {
  521. if (WARN_ON(sg[k - 1].offset +
  522. sg[k - 1].length + authsize >
  523. PAGE_SIZE)) {
  524. ret = -EINVAL;
  525. goto out;
  526. }
  527. sg[k - 1].length += authsize;
  528. }
  529. sg_init_table(asg, template[i].anp);
  530. ret = -EINVAL;
  531. for (k = 0, temp = 0; k < template[i].anp; k++) {
  532. if (WARN_ON(offset_in_page(IDX[k]) +
  533. template[i].atap[k] > PAGE_SIZE))
  534. goto out;
  535. sg_set_buf(&asg[k],
  536. memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
  537. offset_in_page(IDX[k]),
  538. template[i].assoc + temp,
  539. template[i].atap[k]),
  540. template[i].atap[k]);
  541. temp += template[i].atap[k];
  542. }
  543. aead_request_set_crypt(req, sg, sg,
  544. template[i].ilen,
  545. iv);
  546. aead_request_set_assoc(req, asg, template[i].alen);
  547. ret = enc ?
  548. crypto_aead_encrypt(req) :
  549. crypto_aead_decrypt(req);
  550. switch (ret) {
  551. case 0:
  552. if (template[i].novrfy) {
  553. /* verification was supposed to fail */
  554. printk(KERN_ERR "alg: aead: %s failed "
  555. "on chunk test %d for %s: ret "
  556. "was 0, expected -EBADMSG\n",
  557. e, j, algo);
  558. /* so really, we got a bad message */
  559. ret = -EBADMSG;
  560. goto out;
  561. }
  562. break;
  563. case -EINPROGRESS:
  564. case -EBUSY:
  565. ret = wait_for_completion_interruptible(
  566. &result.completion);
  567. if (!ret && !(ret = result.err)) {
  568. INIT_COMPLETION(result.completion);
  569. break;
  570. }
  571. case -EBADMSG:
  572. if (template[i].novrfy)
  573. /* verification failure was expected */
  574. continue;
  575. /* fall through */
  576. default:
  577. printk(KERN_ERR "alg: aead: %s failed on "
  578. "chunk test %d for %s: ret=%d\n", e, j,
  579. algo, -ret);
  580. goto out;
  581. }
  582. ret = -EINVAL;
  583. for (k = 0, temp = 0; k < template[i].np; k++) {
  584. q = xbuf[IDX[k] >> PAGE_SHIFT] +
  585. offset_in_page(IDX[k]);
  586. n = template[i].tap[k];
  587. if (k == template[i].np - 1)
  588. n += enc ? authsize : -authsize;
  589. if (memcmp(q, template[i].result + temp, n)) {
  590. printk(KERN_ERR "alg: aead: Chunk "
  591. "test %d failed on %s at page "
  592. "%u for %s\n", j, e, k, algo);
  593. hexdump(q, n);
  594. goto out;
  595. }
  596. q += n;
  597. if (k == template[i].np - 1 && !enc) {
  598. if (memcmp(q, template[i].input +
  599. temp + n, authsize))
  600. n = authsize;
  601. else
  602. n = 0;
  603. } else {
  604. for (n = 0; offset_in_page(q + n) &&
  605. q[n]; n++)
  606. ;
  607. }
  608. if (n) {
  609. printk(KERN_ERR "alg: aead: Result "
  610. "buffer corruption in chunk "
  611. "test %d on %s at page %u for "
  612. "%s: %u bytes:\n", j, e, k,
  613. algo, n);
  614. hexdump(q, n);
  615. goto out;
  616. }
  617. temp += template[i].tap[k];
  618. }
  619. }
  620. }
  621. ret = 0;
  622. out:
  623. aead_request_free(req);
  624. testmgr_free_buf(axbuf);
  625. out_noaxbuf:
  626. testmgr_free_buf(xbuf);
  627. out_noxbuf:
  628. return ret;
  629. }
  630. static int test_cipher(struct crypto_cipher *tfm, int enc,
  631. struct cipher_testvec *template, unsigned int tcount)
  632. {
  633. const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
  634. unsigned int i, j, k;
  635. char *q;
  636. const char *e;
  637. void *data;
  638. char *xbuf[XBUFSIZE];
  639. int ret = -ENOMEM;
  640. if (testmgr_alloc_buf(xbuf))
  641. goto out_nobuf;
  642. if (enc == ENCRYPT)
  643. e = "encryption";
  644. else
  645. e = "decryption";
  646. j = 0;
  647. for (i = 0; i < tcount; i++) {
  648. if (template[i].np)
  649. continue;
  650. j++;
  651. ret = -EINVAL;
  652. if (WARN_ON(template[i].ilen > PAGE_SIZE))
  653. goto out;
  654. data = xbuf[0];
  655. memcpy(data, template[i].input, template[i].ilen);
  656. crypto_cipher_clear_flags(tfm, ~0);
  657. if (template[i].wk)
  658. crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  659. ret = crypto_cipher_setkey(tfm, template[i].key,
  660. template[i].klen);
  661. if (!ret == template[i].fail) {
  662. printk(KERN_ERR "alg: cipher: setkey failed "
  663. "on test %d for %s: flags=%x\n", j,
  664. algo, crypto_cipher_get_flags(tfm));
  665. goto out;
  666. } else if (ret)
  667. continue;
  668. for (k = 0; k < template[i].ilen;
  669. k += crypto_cipher_blocksize(tfm)) {
  670. if (enc)
  671. crypto_cipher_encrypt_one(tfm, data + k,
  672. data + k);
  673. else
  674. crypto_cipher_decrypt_one(tfm, data + k,
  675. data + k);
  676. }
  677. q = data;
  678. if (memcmp(q, template[i].result, template[i].rlen)) {
  679. printk(KERN_ERR "alg: cipher: Test %d failed "
  680. "on %s for %s\n", j, e, algo);
  681. hexdump(q, template[i].rlen);
  682. ret = -EINVAL;
  683. goto out;
  684. }
  685. }
  686. ret = 0;
  687. out:
  688. testmgr_free_buf(xbuf);
  689. out_nobuf:
  690. return ret;
  691. }
  692. static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
  693. struct cipher_testvec *template, unsigned int tcount)
  694. {
  695. const char *algo =
  696. crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
  697. unsigned int i, j, k, n, temp;
  698. char *q;
  699. struct ablkcipher_request *req;
  700. struct scatterlist sg[8];
  701. const char *e;
  702. struct tcrypt_result result;
  703. void *data;
  704. char iv[MAX_IVLEN];
  705. char *xbuf[XBUFSIZE];
  706. int ret = -ENOMEM;
  707. if (testmgr_alloc_buf(xbuf))
  708. goto out_nobuf;
  709. if (enc == ENCRYPT)
  710. e = "encryption";
  711. else
  712. e = "decryption";
  713. init_completion(&result.completion);
  714. req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
  715. if (!req) {
  716. printk(KERN_ERR "alg: skcipher: Failed to allocate request "
  717. "for %s\n", algo);
  718. goto out;
  719. }
  720. ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  721. tcrypt_complete, &result);
  722. j = 0;
  723. for (i = 0; i < tcount; i++) {
  724. if (template[i].iv)
  725. memcpy(iv, template[i].iv, MAX_IVLEN);
  726. else
  727. memset(iv, 0, MAX_IVLEN);
  728. if (!(template[i].np)) {
  729. j++;
  730. ret = -EINVAL;
  731. if (WARN_ON(template[i].ilen > PAGE_SIZE))
  732. goto out;
  733. data = xbuf[0];
  734. memcpy(data, template[i].input, template[i].ilen);
  735. crypto_ablkcipher_clear_flags(tfm, ~0);
  736. if (template[i].wk)
  737. crypto_ablkcipher_set_flags(
  738. tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  739. ret = crypto_ablkcipher_setkey(tfm, template[i].key,
  740. template[i].klen);
  741. if (!ret == template[i].fail) {
  742. printk(KERN_ERR "alg: skcipher: setkey failed "
  743. "on test %d for %s: flags=%x\n", j,
  744. algo, crypto_ablkcipher_get_flags(tfm));
  745. goto out;
  746. } else if (ret)
  747. continue;
  748. sg_init_one(&sg[0], data, template[i].ilen);
  749. ablkcipher_request_set_crypt(req, sg, sg,
  750. template[i].ilen, iv);
  751. ret = enc ?
  752. crypto_ablkcipher_encrypt(req) :
  753. crypto_ablkcipher_decrypt(req);
  754. switch (ret) {
  755. case 0:
  756. break;
  757. case -EINPROGRESS:
  758. case -EBUSY:
  759. ret = wait_for_completion_interruptible(
  760. &result.completion);
  761. if (!ret && !((ret = result.err))) {
  762. INIT_COMPLETION(result.completion);
  763. break;
  764. }
  765. /* fall through */
  766. default:
  767. printk(KERN_ERR "alg: skcipher: %s failed on "
  768. "test %d for %s: ret=%d\n", e, j, algo,
  769. -ret);
  770. goto out;
  771. }
  772. q = data;
  773. if (memcmp(q, template[i].result, template[i].rlen)) {
  774. printk(KERN_ERR "alg: skcipher: Test %d "
  775. "failed on %s for %s\n", j, e, algo);
  776. hexdump(q, template[i].rlen);
  777. ret = -EINVAL;
  778. goto out;
  779. }
  780. }
  781. }
  782. j = 0;
  783. for (i = 0; i < tcount; i++) {
  784. if (template[i].iv)
  785. memcpy(iv, template[i].iv, MAX_IVLEN);
  786. else
  787. memset(iv, 0, MAX_IVLEN);
  788. if (template[i].np) {
  789. j++;
  790. crypto_ablkcipher_clear_flags(tfm, ~0);
  791. if (template[i].wk)
  792. crypto_ablkcipher_set_flags(
  793. tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  794. ret = crypto_ablkcipher_setkey(tfm, template[i].key,
  795. template[i].klen);
  796. if (!ret == template[i].fail) {
  797. printk(KERN_ERR "alg: skcipher: setkey failed "
  798. "on chunk test %d for %s: flags=%x\n",
  799. j, algo,
  800. crypto_ablkcipher_get_flags(tfm));
  801. goto out;
  802. } else if (ret)
  803. continue;
  804. temp = 0;
  805. ret = -EINVAL;
  806. sg_init_table(sg, template[i].np);
  807. for (k = 0; k < template[i].np; k++) {
  808. if (WARN_ON(offset_in_page(IDX[k]) +
  809. template[i].tap[k] > PAGE_SIZE))
  810. goto out;
  811. q = xbuf[IDX[k] >> PAGE_SHIFT] +
  812. offset_in_page(IDX[k]);
  813. memcpy(q, template[i].input + temp,
  814. template[i].tap[k]);
  815. if (offset_in_page(q) + template[i].tap[k] <
  816. PAGE_SIZE)
  817. q[template[i].tap[k]] = 0;
  818. sg_set_buf(&sg[k], q, template[i].tap[k]);
  819. temp += template[i].tap[k];
  820. }
  821. ablkcipher_request_set_crypt(req, sg, sg,
  822. template[i].ilen, iv);
  823. ret = enc ?
  824. crypto_ablkcipher_encrypt(req) :
  825. crypto_ablkcipher_decrypt(req);
  826. switch (ret) {
  827. case 0:
  828. break;
  829. case -EINPROGRESS:
  830. case -EBUSY:
  831. ret = wait_for_completion_interruptible(
  832. &result.completion);
  833. if (!ret && !((ret = result.err))) {
  834. INIT_COMPLETION(result.completion);
  835. break;
  836. }
  837. /* fall through */
  838. default:
  839. printk(KERN_ERR "alg: skcipher: %s failed on "
  840. "chunk test %d for %s: ret=%d\n", e, j,
  841. algo, -ret);
  842. goto out;
  843. }
  844. temp = 0;
  845. ret = -EINVAL;
  846. for (k = 0; k < template[i].np; k++) {
  847. q = xbuf[IDX[k] >> PAGE_SHIFT] +
  848. offset_in_page(IDX[k]);
  849. if (memcmp(q, template[i].result + temp,
  850. template[i].tap[k])) {
  851. printk(KERN_ERR "alg: skcipher: Chunk "
  852. "test %d failed on %s at page "
  853. "%u for %s\n", j, e, k, algo);
  854. hexdump(q, template[i].tap[k]);
  855. goto out;
  856. }
  857. q += template[i].tap[k];
  858. for (n = 0; offset_in_page(q + n) && q[n]; n++)
  859. ;
  860. if (n) {
  861. printk(KERN_ERR "alg: skcipher: "
  862. "Result buffer corruption in "
  863. "chunk test %d on %s at page "
  864. "%u for %s: %u bytes:\n", j, e,
  865. k, algo, n);
  866. hexdump(q, n);
  867. goto out;
  868. }
  869. temp += template[i].tap[k];
  870. }
  871. }
  872. }
  873. ret = 0;
  874. out:
  875. ablkcipher_request_free(req);
  876. testmgr_free_buf(xbuf);
  877. out_nobuf:
  878. return ret;
  879. }
  880. static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
  881. struct comp_testvec *dtemplate, int ctcount, int dtcount)
  882. {
  883. const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
  884. unsigned int i;
  885. char result[COMP_BUF_SIZE];
  886. int ret;
  887. for (i = 0; i < ctcount; i++) {
  888. int ilen;
  889. unsigned int dlen = COMP_BUF_SIZE;
  890. memset(result, 0, sizeof (result));
  891. ilen = ctemplate[i].inlen;
  892. ret = crypto_comp_compress(tfm, ctemplate[i].input,
  893. ilen, result, &dlen);
  894. if (ret) {
  895. printk(KERN_ERR "alg: comp: compression failed "
  896. "on test %d for %s: ret=%d\n", i + 1, algo,
  897. -ret);
  898. goto out;
  899. }
  900. if (dlen != ctemplate[i].outlen) {
  901. printk(KERN_ERR "alg: comp: Compression test %d "
  902. "failed for %s: output len = %d\n", i + 1, algo,
  903. dlen);
  904. ret = -EINVAL;
  905. goto out;
  906. }
  907. if (memcmp(result, ctemplate[i].output, dlen)) {
  908. printk(KERN_ERR "alg: comp: Compression test %d "
  909. "failed for %s\n", i + 1, algo);
  910. hexdump(result, dlen);
  911. ret = -EINVAL;
  912. goto out;
  913. }
  914. }
  915. for (i = 0; i < dtcount; i++) {
  916. int ilen;
  917. unsigned int dlen = COMP_BUF_SIZE;
  918. memset(result, 0, sizeof (result));
  919. ilen = dtemplate[i].inlen;
  920. ret = crypto_comp_decompress(tfm, dtemplate[i].input,
  921. ilen, result, &dlen);
  922. if (ret) {
  923. printk(KERN_ERR "alg: comp: decompression failed "
  924. "on test %d for %s: ret=%d\n", i + 1, algo,
  925. -ret);
  926. goto out;
  927. }
  928. if (dlen != dtemplate[i].outlen) {
  929. printk(KERN_ERR "alg: comp: Decompression test %d "
  930. "failed for %s: output len = %d\n", i + 1, algo,
  931. dlen);
  932. ret = -EINVAL;
  933. goto out;
  934. }
  935. if (memcmp(result, dtemplate[i].output, dlen)) {
  936. printk(KERN_ERR "alg: comp: Decompression test %d "
  937. "failed for %s\n", i + 1, algo);
  938. hexdump(result, dlen);
  939. ret = -EINVAL;
  940. goto out;
  941. }
  942. }
  943. ret = 0;
  944. out:
  945. return ret;
  946. }
  947. static int test_pcomp(struct crypto_pcomp *tfm,
  948. struct pcomp_testvec *ctemplate,
  949. struct pcomp_testvec *dtemplate, int ctcount,
  950. int dtcount)
  951. {
  952. const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
  953. unsigned int i;
  954. char result[COMP_BUF_SIZE];
  955. int res;
  956. for (i = 0; i < ctcount; i++) {
  957. struct comp_request req;
  958. unsigned int produced = 0;
  959. res = crypto_compress_setup(tfm, ctemplate[i].params,
  960. ctemplate[i].paramsize);
  961. if (res) {
  962. pr_err("alg: pcomp: compression setup failed on test "
  963. "%d for %s: error=%d\n", i + 1, algo, res);
  964. return res;
  965. }
  966. res = crypto_compress_init(tfm);
  967. if (res) {
  968. pr_err("alg: pcomp: compression init failed on test "
  969. "%d for %s: error=%d\n", i + 1, algo, res);
  970. return res;
  971. }
  972. memset(result, 0, sizeof(result));
  973. req.next_in = ctemplate[i].input;
  974. req.avail_in = ctemplate[i].inlen / 2;
  975. req.next_out = result;
  976. req.avail_out = ctemplate[i].outlen / 2;
  977. res = crypto_compress_update(tfm, &req);
  978. if (res < 0 && (res != -EAGAIN || req.avail_in)) {
  979. pr_err("alg: pcomp: compression update failed on test "
  980. "%d for %s: error=%d\n", i + 1, algo, res);
  981. return res;
  982. }
  983. if (res > 0)
  984. produced += res;
  985. /* Add remaining input data */
  986. req.avail_in += (ctemplate[i].inlen + 1) / 2;
  987. res = crypto_compress_update(tfm, &req);
  988. if (res < 0 && (res != -EAGAIN || req.avail_in)) {
  989. pr_err("alg: pcomp: compression update failed on test "
  990. "%d for %s: error=%d\n", i + 1, algo, res);
  991. return res;
  992. }
  993. if (res > 0)
  994. produced += res;
  995. /* Provide remaining output space */
  996. req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
  997. res = crypto_compress_final(tfm, &req);
  998. if (res < 0) {
  999. pr_err("alg: pcomp: compression final failed on test "
  1000. "%d for %s: error=%d\n", i + 1, algo, res);
  1001. return res;
  1002. }
  1003. produced += res;
  1004. if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
  1005. pr_err("alg: comp: Compression test %d failed for %s: "
  1006. "output len = %d (expected %d)\n", i + 1, algo,
  1007. COMP_BUF_SIZE - req.avail_out,
  1008. ctemplate[i].outlen);
  1009. return -EINVAL;
  1010. }
  1011. if (produced != ctemplate[i].outlen) {
  1012. pr_err("alg: comp: Compression test %d failed for %s: "
  1013. "returned len = %u (expected %d)\n", i + 1,
  1014. algo, produced, ctemplate[i].outlen);
  1015. return -EINVAL;
  1016. }
  1017. if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
  1018. pr_err("alg: pcomp: Compression test %d failed for "
  1019. "%s\n", i + 1, algo);
  1020. hexdump(result, ctemplate[i].outlen);
  1021. return -EINVAL;
  1022. }
  1023. }
  1024. for (i = 0; i < dtcount; i++) {
  1025. struct comp_request req;
  1026. unsigned int produced = 0;
  1027. res = crypto_decompress_setup(tfm, dtemplate[i].params,
  1028. dtemplate[i].paramsize);
  1029. if (res) {
  1030. pr_err("alg: pcomp: decompression setup failed on "
  1031. "test %d for %s: error=%d\n", i + 1, algo, res);
  1032. return res;
  1033. }
  1034. res = crypto_decompress_init(tfm);
  1035. if (res) {
  1036. pr_err("alg: pcomp: decompression init failed on test "
  1037. "%d for %s: error=%d\n", i + 1, algo, res);
  1038. return res;
  1039. }
  1040. memset(result, 0, sizeof(result));
  1041. req.next_in = dtemplate[i].input;
  1042. req.avail_in = dtemplate[i].inlen / 2;
  1043. req.next_out = result;
  1044. req.avail_out = dtemplate[i].outlen / 2;
  1045. res = crypto_decompress_update(tfm, &req);
  1046. if (res < 0 && (res != -EAGAIN || req.avail_in)) {
  1047. pr_err("alg: pcomp: decompression update failed on "
  1048. "test %d for %s: error=%d\n", i + 1, algo, res);
  1049. return res;
  1050. }
  1051. if (res > 0)
  1052. produced += res;
  1053. /* Add remaining input data */
  1054. req.avail_in += (dtemplate[i].inlen + 1) / 2;
  1055. res = crypto_decompress_update(tfm, &req);
  1056. if (res < 0 && (res != -EAGAIN || req.avail_in)) {
  1057. pr_err("alg: pcomp: decompression update failed on "
  1058. "test %d for %s: error=%d\n", i + 1, algo, res);
  1059. return res;
  1060. }
  1061. if (res > 0)
  1062. produced += res;
  1063. /* Provide remaining output space */
  1064. req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
  1065. res = crypto_decompress_final(tfm, &req);
  1066. if (res < 0 && (res != -EAGAIN || req.avail_in)) {
  1067. pr_err("alg: pcomp: decompression final failed on "
  1068. "test %d for %s: error=%d\n", i + 1, algo, res);
  1069. return res;
  1070. }
  1071. if (res > 0)
  1072. produced += res;
  1073. if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
  1074. pr_err("alg: comp: Decompression test %d failed for "
  1075. "%s: output len = %d (expected %d)\n", i + 1,
  1076. algo, COMP_BUF_SIZE - req.avail_out,
  1077. dtemplate[i].outlen);
  1078. return -EINVAL;
  1079. }
  1080. if (produced != dtemplate[i].outlen) {
  1081. pr_err("alg: comp: Decompression test %d failed for "
  1082. "%s: returned len = %u (expected %d)\n", i + 1,
  1083. algo, produced, dtemplate[i].outlen);
  1084. return -EINVAL;
  1085. }
  1086. if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
  1087. pr_err("alg: pcomp: Decompression test %d failed for "
  1088. "%s\n", i + 1, algo);
  1089. hexdump(result, dtemplate[i].outlen);
  1090. return -EINVAL;
  1091. }
  1092. }
  1093. return 0;
  1094. }
  1095. static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
  1096. unsigned int tcount)
  1097. {
  1098. const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
  1099. int err = 0, i, j, seedsize;
  1100. u8 *seed;
  1101. char result[32];
  1102. seedsize = crypto_rng_seedsize(tfm);
  1103. seed = kmalloc(seedsize, GFP_KERNEL);
  1104. if (!seed) {
  1105. printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
  1106. "for %s\n", algo);
  1107. return -ENOMEM;
  1108. }
  1109. for (i = 0; i < tcount; i++) {
  1110. memset(result, 0, 32);
  1111. memcpy(seed, template[i].v, template[i].vlen);
  1112. memcpy(seed + template[i].vlen, template[i].key,
  1113. template[i].klen);
  1114. memcpy(seed + template[i].vlen + template[i].klen,
  1115. template[i].dt, template[i].dtlen);
  1116. err = crypto_rng_reset(tfm, seed, seedsize);
  1117. if (err) {
  1118. printk(KERN_ERR "alg: cprng: Failed to reset rng "
  1119. "for %s\n", algo);
  1120. goto out;
  1121. }
  1122. for (j = 0; j < template[i].loops; j++) {
  1123. err = crypto_rng_get_bytes(tfm, result,
  1124. template[i].rlen);
  1125. if (err != template[i].rlen) {
  1126. printk(KERN_ERR "alg: cprng: Failed to obtain "
  1127. "the correct amount of random data for "
  1128. "%s (requested %d, got %d)\n", algo,
  1129. template[i].rlen, err);
  1130. goto out;
  1131. }
  1132. }
  1133. err = memcmp(result, template[i].result,
  1134. template[i].rlen);
  1135. if (err) {
  1136. printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
  1137. i, algo);
  1138. hexdump(result, template[i].rlen);
  1139. err = -EINVAL;
  1140. goto out;
  1141. }
  1142. }
  1143. out:
  1144. kfree(seed);
  1145. return err;
  1146. }
  1147. static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
  1148. u32 type, u32 mask)
  1149. {
  1150. struct crypto_aead *tfm;
  1151. int err = 0;
  1152. tfm = crypto_alloc_aead(driver, type, mask);
  1153. if (IS_ERR(tfm)) {
  1154. printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
  1155. "%ld\n", driver, PTR_ERR(tfm));
  1156. return PTR_ERR(tfm);
  1157. }
  1158. if (desc->suite.aead.enc.vecs) {
  1159. err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
  1160. desc->suite.aead.enc.count);
  1161. if (err)
  1162. goto out;
  1163. }
  1164. if (!err && desc->suite.aead.dec.vecs)
  1165. err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
  1166. desc->suite.aead.dec.count);
  1167. out:
  1168. crypto_free_aead(tfm);
  1169. return err;
  1170. }
  1171. static int alg_test_cipher(const struct alg_test_desc *desc,
  1172. const char *driver, u32 type, u32 mask)
  1173. {
  1174. struct crypto_cipher *tfm;
  1175. int err = 0;
  1176. tfm = crypto_alloc_cipher(driver, type, mask);
  1177. if (IS_ERR(tfm)) {
  1178. printk(KERN_ERR "alg: cipher: Failed to load transform for "
  1179. "%s: %ld\n", driver, PTR_ERR(tfm));
  1180. return PTR_ERR(tfm);
  1181. }
  1182. if (desc->suite.cipher.enc.vecs) {
  1183. err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
  1184. desc->suite.cipher.enc.count);
  1185. if (err)
  1186. goto out;
  1187. }
  1188. if (desc->suite.cipher.dec.vecs)
  1189. err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
  1190. desc->suite.cipher.dec.count);
  1191. out:
  1192. crypto_free_cipher(tfm);
  1193. return err;
  1194. }
  1195. static int alg_test_skcipher(const struct alg_test_desc *desc,
  1196. const char *driver, u32 type, u32 mask)
  1197. {
  1198. struct crypto_ablkcipher *tfm;
  1199. int err = 0;
  1200. tfm = crypto_alloc_ablkcipher(driver, type, mask);
  1201. if (IS_ERR(tfm)) {
  1202. printk(KERN_ERR "alg: skcipher: Failed to load transform for "
  1203. "%s: %ld\n", driver, PTR_ERR(tfm));
  1204. return PTR_ERR(tfm);
  1205. }
  1206. if (desc->suite.cipher.enc.vecs) {
  1207. err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
  1208. desc->suite.cipher.enc.count);
  1209. if (err)
  1210. goto out;
  1211. }
  1212. if (desc->suite.cipher.dec.vecs)
  1213. err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
  1214. desc->suite.cipher.dec.count);
  1215. out:
  1216. crypto_free_ablkcipher(tfm);
  1217. return err;
  1218. }
  1219. static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
  1220. u32 type, u32 mask)
  1221. {
  1222. struct crypto_comp *tfm;
  1223. int err;
  1224. tfm = crypto_alloc_comp(driver, type, mask);
  1225. if (IS_ERR(tfm)) {
  1226. printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
  1227. "%ld\n", driver, PTR_ERR(tfm));
  1228. return PTR_ERR(tfm);
  1229. }
  1230. err = test_comp(tfm, desc->suite.comp.comp.vecs,
  1231. desc->suite.comp.decomp.vecs,
  1232. desc->suite.comp.comp.count,
  1233. desc->suite.comp.decomp.count);
  1234. crypto_free_comp(tfm);
  1235. return err;
  1236. }
  1237. static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
  1238. u32 type, u32 mask)
  1239. {
  1240. struct crypto_pcomp *tfm;
  1241. int err;
  1242. tfm = crypto_alloc_pcomp(driver, type, mask);
  1243. if (IS_ERR(tfm)) {
  1244. pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
  1245. driver, PTR_ERR(tfm));
  1246. return PTR_ERR(tfm);
  1247. }
  1248. err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
  1249. desc->suite.pcomp.decomp.vecs,
  1250. desc->suite.pcomp.comp.count,
  1251. desc->suite.pcomp.decomp.count);
  1252. crypto_free_pcomp(tfm);
  1253. return err;
  1254. }
  1255. static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
  1256. u32 type, u32 mask)
  1257. {
  1258. struct crypto_ahash *tfm;
  1259. int err;
  1260. tfm = crypto_alloc_ahash(driver, type, mask);
  1261. if (IS_ERR(tfm)) {
  1262. printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
  1263. "%ld\n", driver, PTR_ERR(tfm));
  1264. return PTR_ERR(tfm);
  1265. }
  1266. err = test_hash(tfm, desc->suite.hash.vecs,
  1267. desc->suite.hash.count, true);
  1268. if (!err)
  1269. err = test_hash(tfm, desc->suite.hash.vecs,
  1270. desc->suite.hash.count, false);
  1271. crypto_free_ahash(tfm);
  1272. return err;
  1273. }
  1274. static int alg_test_crc32c(const struct alg_test_desc *desc,
  1275. const char *driver, u32 type, u32 mask)
  1276. {
  1277. struct crypto_shash *tfm;
  1278. u32 val;
  1279. int err;
  1280. err = alg_test_hash(desc, driver, type, mask);
  1281. if (err)
  1282. return err;
  1283. tfm = crypto_alloc_shash(driver, type, mask);
  1284. if (IS_ERR(tfm)) {
  1285. if (PTR_ERR(tfm) == -ENOENT) {
  1286. /*
  1287. * This crc32c implementation is only available through
  1288. * ahash API, not the shash API, so the remaining part
  1289. * of the test is not applicable to it.
  1290. */
  1291. return 0;
  1292. }
  1293. printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
  1294. "%ld\n", driver, PTR_ERR(tfm));
  1295. return PTR_ERR(tfm);
  1296. }
  1297. do {
  1298. struct {
  1299. struct shash_desc shash;
  1300. char ctx[crypto_shash_descsize(tfm)];
  1301. } sdesc;
  1302. sdesc.shash.tfm = tfm;
  1303. sdesc.shash.flags = 0;
  1304. *(u32 *)sdesc.ctx = le32_to_cpu(420553207);
  1305. err = crypto_shash_final(&sdesc.shash, (u8 *)&val);
  1306. if (err) {
  1307. printk(KERN_ERR "alg: crc32c: Operation failed for "
  1308. "%s: %d\n", driver, err);
  1309. break;
  1310. }
  1311. if (val != ~420553207) {
  1312. printk(KERN_ERR "alg: crc32c: Test failed for %s: "
  1313. "%d\n", driver, val);
  1314. err = -EINVAL;
  1315. }
  1316. } while (0);
  1317. crypto_free_shash(tfm);
  1318. return err;
  1319. }
  1320. static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
  1321. u32 type, u32 mask)
  1322. {
  1323. struct crypto_rng *rng;
  1324. int err;
  1325. rng = crypto_alloc_rng(driver, type, mask);
  1326. if (IS_ERR(rng)) {
  1327. printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
  1328. "%ld\n", driver, PTR_ERR(rng));
  1329. return PTR_ERR(rng);
  1330. }
  1331. err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
  1332. crypto_free_rng(rng);
  1333. return err;
  1334. }
  1335. #ifdef CONFIG_CRYPTO_DRBG
  1336. static int drbg_cavs_test(struct drbg_testvec *test, int pr,
  1337. const char *driver, u32 type, u32 mask)
  1338. {
  1339. int ret = -EAGAIN;
  1340. struct crypto_rng *drng;
  1341. struct drbg_test_data test_data;
  1342. struct drbg_string addtl, pers, testentropy;
  1343. unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
  1344. if (!buf)
  1345. return -ENOMEM;
  1346. drng = crypto_alloc_rng(driver, type, mask);
  1347. if (IS_ERR(drng)) {
  1348. printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
  1349. "%s\n", driver);
  1350. kzfree(buf);
  1351. return -ENOMEM;
  1352. }
  1353. test_data.testentropy = &testentropy;
  1354. drbg_string_fill(&testentropy, test->entropy, test->entropylen);
  1355. drbg_string_fill(&pers, test->pers, test->perslen);
  1356. ret = crypto_drbg_reset_test(drng, &pers, &test_data);
  1357. if (ret) {
  1358. printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
  1359. goto outbuf;
  1360. }
  1361. drbg_string_fill(&addtl, test->addtla, test->addtllen);
  1362. if (pr) {
  1363. drbg_string_fill(&testentropy, test->entpra, test->entprlen);
  1364. ret = crypto_drbg_get_bytes_addtl_test(drng,
  1365. buf, test->expectedlen, &addtl, &test_data);
  1366. } else {
  1367. ret = crypto_drbg_get_bytes_addtl(drng,
  1368. buf, test->expectedlen, &addtl);
  1369. }
  1370. if (ret <= 0) {
  1371. printk(KERN_ERR "alg: drbg: could not obtain random data for "
  1372. "driver %s\n", driver);
  1373. goto outbuf;
  1374. }
  1375. drbg_string_fill(&addtl, test->addtlb, test->addtllen);
  1376. if (pr) {
  1377. drbg_string_fill(&testentropy, test->entprb, test->entprlen);
  1378. ret = crypto_drbg_get_bytes_addtl_test(drng,
  1379. buf, test->expectedlen, &addtl, &test_data);
  1380. } else {
  1381. ret = crypto_drbg_get_bytes_addtl(drng,
  1382. buf, test->expectedlen, &addtl);
  1383. }
  1384. if (ret <= 0) {
  1385. printk(KERN_ERR "alg: drbg: could not obtain random data for "
  1386. "driver %s\n", driver);
  1387. goto outbuf;
  1388. }
  1389. ret = memcmp(test->expected, buf, test->expectedlen);
  1390. outbuf:
  1391. crypto_free_rng(drng);
  1392. kzfree(buf);
  1393. return ret;
  1394. }
  1395. static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
  1396. u32 type, u32 mask)
  1397. {
  1398. int err = 0;
  1399. int pr = 0;
  1400. int i = 0;
  1401. struct drbg_testvec *template = desc->suite.drbg.vecs;
  1402. unsigned int tcount = desc->suite.drbg.count;
  1403. if (0 == memcmp(driver, "drbg_pr_", 8))
  1404. pr = 1;
  1405. for (i = 0; i < tcount; i++) {
  1406. err = drbg_cavs_test(&template[i], pr, driver, type, mask);
  1407. if (err) {
  1408. printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
  1409. i, driver);
  1410. err = -EINVAL;
  1411. break;
  1412. }
  1413. }
  1414. return err;
  1415. }
  1416. #endif
  1417. static int alg_test_null(const struct alg_test_desc *desc,
  1418. const char *driver, u32 type, u32 mask)
  1419. {
  1420. return 0;
  1421. }
  1422. /* Please keep this list sorted by algorithm name. */
  1423. static const struct alg_test_desc alg_test_descs[] = {
  1424. {
  1425. .alg = "__cbc-serpent-sse2",
  1426. .test = alg_test_null,
  1427. .suite = {
  1428. .cipher = {
  1429. .enc = {
  1430. .vecs = NULL,
  1431. .count = 0
  1432. },
  1433. .dec = {
  1434. .vecs = NULL,
  1435. .count = 0
  1436. }
  1437. }
  1438. }
  1439. }, {
  1440. .alg = "__driver-cbc-aes-aesni",
  1441. .test = alg_test_null,
  1442. .suite = {
  1443. .cipher = {
  1444. .enc = {
  1445. .vecs = NULL,
  1446. .count = 0
  1447. },
  1448. .dec = {
  1449. .vecs = NULL,
  1450. .count = 0
  1451. }
  1452. }
  1453. }
  1454. }, {
  1455. .alg = "__driver-cbc-serpent-sse2",
  1456. .test = alg_test_null,
  1457. .suite = {
  1458. .cipher = {
  1459. .enc = {
  1460. .vecs = NULL,
  1461. .count = 0
  1462. },
  1463. .dec = {
  1464. .vecs = NULL,
  1465. .count = 0
  1466. }
  1467. }
  1468. }
  1469. }, {
  1470. .alg = "__driver-ecb-aes-aesni",
  1471. .test = alg_test_null,
  1472. .suite = {
  1473. .cipher = {
  1474. .enc = {
  1475. .vecs = NULL,
  1476. .count = 0
  1477. },
  1478. .dec = {
  1479. .vecs = NULL,
  1480. .count = 0
  1481. }
  1482. }
  1483. }
  1484. }, {
  1485. .alg = "__driver-ecb-serpent-sse2",
  1486. .test = alg_test_null,
  1487. .suite = {
  1488. .cipher = {
  1489. .enc = {
  1490. .vecs = NULL,
  1491. .count = 0
  1492. },
  1493. .dec = {
  1494. .vecs = NULL,
  1495. .count = 0
  1496. }
  1497. }
  1498. }
  1499. }, {
  1500. .alg = "__ghash-pclmulqdqni",
  1501. .test = alg_test_null,
  1502. .suite = {
  1503. .hash = {
  1504. .vecs = NULL,
  1505. .count = 0
  1506. }
  1507. }
  1508. }, {
  1509. .alg = "ansi_cprng",
  1510. .test = alg_test_cprng,
  1511. .fips_allowed = 1,
  1512. .suite = {
  1513. .cprng = {
  1514. .vecs = ansi_cprng_aes_tv_template,
  1515. .count = ANSI_CPRNG_AES_TEST_VECTORS
  1516. }
  1517. }
  1518. }, {
  1519. .alg = "cbc(aes)",
  1520. .test = alg_test_skcipher,
  1521. .fips_allowed = 1,
  1522. .suite = {
  1523. .cipher = {
  1524. .enc = {
  1525. .vecs = aes_cbc_enc_tv_template,
  1526. .count = AES_CBC_ENC_TEST_VECTORS
  1527. },
  1528. .dec = {
  1529. .vecs = aes_cbc_dec_tv_template,
  1530. .count = AES_CBC_DEC_TEST_VECTORS
  1531. }
  1532. }
  1533. }
  1534. }, {
  1535. .alg = "cbc(anubis)",
  1536. .test = alg_test_skcipher,
  1537. .suite = {
  1538. .cipher = {
  1539. .enc = {
  1540. .vecs = anubis_cbc_enc_tv_template,
  1541. .count = ANUBIS_CBC_ENC_TEST_VECTORS
  1542. },
  1543. .dec = {
  1544. .vecs = anubis_cbc_dec_tv_template,
  1545. .count = ANUBIS_CBC_DEC_TEST_VECTORS
  1546. }
  1547. }
  1548. }
  1549. }, {
  1550. .alg = "cbc(blowfish)",
  1551. .test = alg_test_skcipher,
  1552. .suite = {
  1553. .cipher = {
  1554. .enc = {
  1555. .vecs = bf_cbc_enc_tv_template,
  1556. .count = BF_CBC_ENC_TEST_VECTORS
  1557. },
  1558. .dec = {
  1559. .vecs = bf_cbc_dec_tv_template,
  1560. .count = BF_CBC_DEC_TEST_VECTORS
  1561. }
  1562. }
  1563. }
  1564. }, {
  1565. .alg = "cbc(camellia)",
  1566. .test = alg_test_skcipher,
  1567. .suite = {
  1568. .cipher = {
  1569. .enc = {
  1570. .vecs = camellia_cbc_enc_tv_template,
  1571. .count = CAMELLIA_CBC_ENC_TEST_VECTORS
  1572. },
  1573. .dec = {
  1574. .vecs = camellia_cbc_dec_tv_template,
  1575. .count = CAMELLIA_CBC_DEC_TEST_VECTORS
  1576. }
  1577. }
  1578. }
  1579. }, {
  1580. .alg = "cbc(des)",
  1581. .test = alg_test_skcipher,
  1582. .suite = {
  1583. .cipher = {
  1584. .enc = {
  1585. .vecs = des_cbc_enc_tv_template,
  1586. .count = DES_CBC_ENC_TEST_VECTORS
  1587. },
  1588. .dec = {
  1589. .vecs = des_cbc_dec_tv_template,
  1590. .count = DES_CBC_DEC_TEST_VECTORS
  1591. }
  1592. }
  1593. }
  1594. }, {
  1595. .alg = "cbc(des3_ede)",
  1596. .test = alg_test_skcipher,
  1597. .fips_allowed = 1,
  1598. .suite = {
  1599. .cipher = {
  1600. .enc = {
  1601. .vecs = des3_ede_cbc_enc_tv_template,
  1602. .count = DES3_EDE_CBC_ENC_TEST_VECTORS
  1603. },
  1604. .dec = {
  1605. .vecs = des3_ede_cbc_dec_tv_template,
  1606. .count = DES3_EDE_CBC_DEC_TEST_VECTORS
  1607. }
  1608. }
  1609. }
  1610. }, {
  1611. .alg = "cbc(serpent)",
  1612. .test = alg_test_skcipher,
  1613. .suite = {
  1614. .cipher = {
  1615. .enc = {
  1616. .vecs = serpent_cbc_enc_tv_template,
  1617. .count = SERPENT_CBC_ENC_TEST_VECTORS
  1618. },
  1619. .dec = {
  1620. .vecs = serpent_cbc_dec_tv_template,
  1621. .count = SERPENT_CBC_DEC_TEST_VECTORS
  1622. }
  1623. }
  1624. }
  1625. }, {
  1626. .alg = "cbc(twofish)",
  1627. .test = alg_test_skcipher,
  1628. .suite = {
  1629. .cipher = {
  1630. .enc = {
  1631. .vecs = tf_cbc_enc_tv_template,
  1632. .count = TF_CBC_ENC_TEST_VECTORS
  1633. },
  1634. .dec = {
  1635. .vecs = tf_cbc_dec_tv_template,
  1636. .count = TF_CBC_DEC_TEST_VECTORS
  1637. }
  1638. }
  1639. }
  1640. }, {
  1641. .alg = "ccm(aes)",
  1642. .test = alg_test_aead,
  1643. .fips_allowed = 1,
  1644. .suite = {
  1645. .aead = {
  1646. .enc = {
  1647. .vecs = aes_ccm_enc_tv_template,
  1648. .count = AES_CCM_ENC_TEST_VECTORS
  1649. },
  1650. .dec = {
  1651. .vecs = aes_ccm_dec_tv_template,
  1652. .count = AES_CCM_DEC_TEST_VECTORS
  1653. }
  1654. }
  1655. }
  1656. }, {
  1657. .alg = "crc32c",
  1658. .test = alg_test_crc32c,
  1659. .fips_allowed = 1,
  1660. .suite = {
  1661. .hash = {
  1662. .vecs = crc32c_tv_template,
  1663. .count = CRC32C_TEST_VECTORS
  1664. }
  1665. }
  1666. }, {
  1667. .alg = "cryptd(__driver-ecb-aes-aesni)",
  1668. .test = alg_test_null,
  1669. .suite = {
  1670. .cipher = {
  1671. .enc = {
  1672. .vecs = NULL,
  1673. .count = 0
  1674. },
  1675. .dec = {
  1676. .vecs = NULL,
  1677. .count = 0
  1678. }
  1679. }
  1680. }
  1681. }, {
  1682. .alg = "cryptd(__driver-ecb-serpent-sse2)",
  1683. .test = alg_test_null,
  1684. .suite = {
  1685. .cipher = {
  1686. .enc = {
  1687. .vecs = NULL,
  1688. .count = 0
  1689. },
  1690. .dec = {
  1691. .vecs = NULL,
  1692. .count = 0
  1693. }
  1694. }
  1695. }
  1696. }, {
  1697. .alg = "cryptd(__ghash-pclmulqdqni)",
  1698. .test = alg_test_null,
  1699. .suite = {
  1700. .hash = {
  1701. .vecs = NULL,
  1702. .count = 0
  1703. }
  1704. }
  1705. }, {
  1706. .alg = "ctr(aes)",
  1707. .test = alg_test_skcipher,
  1708. .fips_allowed = 1,
  1709. .suite = {
  1710. .cipher = {
  1711. .enc = {
  1712. .vecs = aes_ctr_enc_tv_template,
  1713. .count = AES_CTR_ENC_TEST_VECTORS
  1714. },
  1715. .dec = {
  1716. .vecs = aes_ctr_dec_tv_template,
  1717. .count = AES_CTR_DEC_TEST_VECTORS
  1718. }
  1719. }
  1720. }
  1721. }, {
  1722. .alg = "ctr(blowfish)",
  1723. .test = alg_test_skcipher,
  1724. .suite = {
  1725. .cipher = {
  1726. .enc = {
  1727. .vecs = bf_ctr_enc_tv_template,
  1728. .count = BF_CTR_ENC_TEST_VECTORS
  1729. },
  1730. .dec = {
  1731. .vecs = bf_ctr_dec_tv_template,
  1732. .count = BF_CTR_DEC_TEST_VECTORS
  1733. }
  1734. }
  1735. }
  1736. }, {
  1737. .alg = "ctr(camellia)",
  1738. .test = alg_test_skcipher,
  1739. .suite = {
  1740. .cipher = {
  1741. .enc = {
  1742. .vecs = camellia_ctr_enc_tv_template,
  1743. .count = CAMELLIA_CTR_ENC_TEST_VECTORS
  1744. },
  1745. .dec = {
  1746. .vecs = camellia_ctr_dec_tv_template,
  1747. .count = CAMELLIA_CTR_DEC_TEST_VECTORS
  1748. }
  1749. }
  1750. }
  1751. }, {
  1752. .alg = "ctr(serpent)",
  1753. .test = alg_test_skcipher,
  1754. .suite = {
  1755. .cipher = {
  1756. .enc = {
  1757. .vecs = serpent_ctr_enc_tv_template,
  1758. .count = SERPENT_CTR_ENC_TEST_VECTORS
  1759. },
  1760. .dec = {
  1761. .vecs = serpent_ctr_dec_tv_template,
  1762. .count = SERPENT_CTR_DEC_TEST_VECTORS
  1763. }
  1764. }
  1765. }
  1766. }, {
  1767. .alg = "ctr(twofish)",
  1768. .test = alg_test_skcipher,
  1769. .suite = {
  1770. .cipher = {
  1771. .enc = {
  1772. .vecs = tf_ctr_enc_tv_template,
  1773. .count = TF_CTR_ENC_TEST_VECTORS
  1774. },
  1775. .dec = {
  1776. .vecs = tf_ctr_dec_tv_template,
  1777. .count = TF_CTR_DEC_TEST_VECTORS
  1778. }
  1779. }
  1780. }
  1781. }, {
  1782. .alg = "cts(cbc(aes))",
  1783. .test = alg_test_skcipher,
  1784. .suite = {
  1785. .cipher = {
  1786. .enc = {
  1787. .vecs = cts_mode_enc_tv_template,
  1788. .count = CTS_MODE_ENC_TEST_VECTORS
  1789. },
  1790. .dec = {
  1791. .vecs = cts_mode_dec_tv_template,
  1792. .count = CTS_MODE_DEC_TEST_VECTORS
  1793. }
  1794. }
  1795. }
  1796. }, {
  1797. .alg = "deflate",
  1798. .test = alg_test_comp,
  1799. .suite = {
  1800. .comp = {
  1801. .comp = {
  1802. .vecs = deflate_comp_tv_template,
  1803. .count = DEFLATE_COMP_TEST_VECTORS
  1804. },
  1805. .decomp = {
  1806. .vecs = deflate_decomp_tv_template,
  1807. .count = DEFLATE_DECOMP_TEST_VECTORS
  1808. }
  1809. }
  1810. }
  1811. }, {
  1812. #ifdef CONFIG_CRYPTO_DRBG
  1813. .alg = "drbg_nopr_ctr_aes128",
  1814. .test = alg_test_drbg,
  1815. .fips_allowed = 1,
  1816. .suite = {
  1817. .drbg = {
  1818. .vecs = drbg_nopr_ctr_aes128_tv_template,
  1819. .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
  1820. }
  1821. }
  1822. }, {
  1823. .alg = "drbg_nopr_ctr_aes192",
  1824. .test = alg_test_drbg,
  1825. .fips_allowed = 1,
  1826. .suite = {
  1827. .drbg = {
  1828. .vecs = drbg_nopr_ctr_aes192_tv_template,
  1829. .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
  1830. }
  1831. }
  1832. }, {
  1833. .alg = "drbg_nopr_ctr_aes256",
  1834. .test = alg_test_drbg,
  1835. .fips_allowed = 1,
  1836. .suite = {
  1837. .drbg = {
  1838. .vecs = drbg_nopr_ctr_aes256_tv_template,
  1839. .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
  1840. }
  1841. }
  1842. }, {
  1843. /*
  1844. * There is no need to specifically test the DRBG with every
  1845. * backend cipher -- covered by drbg_nopr_hmac_sha256 test
  1846. */
  1847. .alg = "drbg_nopr_hmac_sha1",
  1848. .fips_allowed = 1,
  1849. .test = alg_test_null,
  1850. }, {
  1851. .alg = "drbg_nopr_hmac_sha256",
  1852. .test = alg_test_drbg,
  1853. .fips_allowed = 1,
  1854. .suite = {
  1855. .drbg = {
  1856. .vecs = drbg_nopr_hmac_sha256_tv_template,
  1857. .count =
  1858. ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
  1859. }
  1860. }
  1861. }, {
  1862. /* covered by drbg_nopr_hmac_sha256 test */
  1863. .alg = "drbg_nopr_hmac_sha384",
  1864. .fips_allowed = 1,
  1865. .test = alg_test_null,
  1866. }, {
  1867. .alg = "drbg_nopr_hmac_sha512",
  1868. .test = alg_test_null,
  1869. .fips_allowed = 1,
  1870. }, {
  1871. .alg = "drbg_nopr_sha1",
  1872. .fips_allowed = 1,
  1873. .test = alg_test_null,
  1874. }, {
  1875. .alg = "drbg_nopr_sha256",
  1876. .test = alg_test_drbg,
  1877. .fips_allowed = 1,
  1878. .suite = {
  1879. .drbg = {
  1880. .vecs = drbg_nopr_sha256_tv_template,
  1881. .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
  1882. }
  1883. }
  1884. }, {
  1885. /* covered by drbg_nopr_sha256 test */
  1886. .alg = "drbg_nopr_sha384",
  1887. .fips_allowed = 1,
  1888. .test = alg_test_null,
  1889. }, {
  1890. .alg = "drbg_nopr_sha512",
  1891. .fips_allowed = 1,
  1892. .test = alg_test_null,
  1893. }, {
  1894. .alg = "drbg_pr_ctr_aes128",
  1895. .test = alg_test_drbg,
  1896. .fips_allowed = 1,
  1897. .suite = {
  1898. .drbg = {
  1899. .vecs = drbg_pr_ctr_aes128_tv_template,
  1900. .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
  1901. }
  1902. }
  1903. }, {
  1904. /* covered by drbg_pr_ctr_aes128 test */
  1905. .alg = "drbg_pr_ctr_aes192",
  1906. .fips_allowed = 1,
  1907. .test = alg_test_null,
  1908. }, {
  1909. .alg = "drbg_pr_ctr_aes256",
  1910. .fips_allowed = 1,
  1911. .test = alg_test_null,
  1912. }, {
  1913. .alg = "drbg_pr_hmac_sha1",
  1914. .fips_allowed = 1,
  1915. .test = alg_test_null,
  1916. }, {
  1917. .alg = "drbg_pr_hmac_sha256",
  1918. .test = alg_test_drbg,
  1919. .fips_allowed = 1,
  1920. .suite = {
  1921. .drbg = {
  1922. .vecs = drbg_pr_hmac_sha256_tv_template,
  1923. .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
  1924. }
  1925. }
  1926. }, {
  1927. /* covered by drbg_pr_hmac_sha256 test */
  1928. .alg = "drbg_pr_hmac_sha384",
  1929. .fips_allowed = 1,
  1930. .test = alg_test_null,
  1931. }, {
  1932. .alg = "drbg_pr_hmac_sha512",
  1933. .test = alg_test_null,
  1934. .fips_allowed = 1,
  1935. }, {
  1936. .alg = "drbg_pr_sha1",
  1937. .fips_allowed = 1,
  1938. .test = alg_test_null,
  1939. }, {
  1940. .alg = "drbg_pr_sha256",
  1941. .test = alg_test_drbg,
  1942. .fips_allowed = 1,
  1943. .suite = {
  1944. .drbg = {
  1945. .vecs = drbg_pr_sha256_tv_template,
  1946. .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
  1947. }
  1948. }
  1949. }, {
  1950. /* covered by drbg_pr_sha256 test */
  1951. .alg = "drbg_pr_sha384",
  1952. .fips_allowed = 1,
  1953. .test = alg_test_null,
  1954. }, {
  1955. .alg = "drbg_pr_sha512",
  1956. .fips_allowed = 1,
  1957. .test = alg_test_null,
  1958. }, {
  1959. #endif /* CONFIG_CRYPTO_DRBG */
  1960. .alg = "ecb(__aes-aesni)",
  1961. .test = alg_test_null,
  1962. .suite = {
  1963. .cipher = {
  1964. .enc = {
  1965. .vecs = NULL,
  1966. .count = 0
  1967. },
  1968. .dec = {
  1969. .vecs = NULL,
  1970. .count = 0
  1971. }
  1972. }
  1973. }
  1974. }, {
  1975. .alg = "ecb(aes)",
  1976. .test = alg_test_skcipher,
  1977. .fips_allowed = 1,
  1978. .suite = {
  1979. .cipher = {
  1980. .enc = {
  1981. .vecs = aes_enc_tv_template,
  1982. .count = AES_ENC_TEST_VECTORS
  1983. },
  1984. .dec = {
  1985. .vecs = aes_dec_tv_template,
  1986. .count = AES_DEC_TEST_VECTORS
  1987. }
  1988. }
  1989. }
  1990. }, {
  1991. .alg = "ecb(anubis)",
  1992. .test = alg_test_skcipher,
  1993. .suite = {
  1994. .cipher = {
  1995. .enc = {
  1996. .vecs = anubis_enc_tv_template,
  1997. .count = ANUBIS_ENC_TEST_VECTORS
  1998. },
  1999. .dec = {
  2000. .vecs = anubis_dec_tv_template,
  2001. .count = ANUBIS_DEC_TEST_VECTORS
  2002. }
  2003. }
  2004. }
  2005. }, {
  2006. .alg = "ecb(arc4)",
  2007. .test = alg_test_skcipher,
  2008. .suite = {
  2009. .cipher = {
  2010. .enc = {
  2011. .vecs = arc4_enc_tv_template,
  2012. .count = ARC4_ENC_TEST_VECTORS
  2013. },
  2014. .dec = {
  2015. .vecs = arc4_dec_tv_template,
  2016. .count = ARC4_DEC_TEST_VECTORS
  2017. }
  2018. }
  2019. }
  2020. }, {
  2021. .alg = "ecb(blowfish)",
  2022. .test = alg_test_skcipher,
  2023. .suite = {
  2024. .cipher = {
  2025. .enc = {
  2026. .vecs = bf_enc_tv_template,
  2027. .count = BF_ENC_TEST_VECTORS
  2028. },
  2029. .dec = {
  2030. .vecs = bf_dec_tv_template,
  2031. .count = BF_DEC_TEST_VECTORS
  2032. }
  2033. }
  2034. }
  2035. }, {
  2036. .alg = "ecb(camellia)",
  2037. .test = alg_test_skcipher,
  2038. .suite = {
  2039. .cipher = {
  2040. .enc = {
  2041. .vecs = camellia_enc_tv_template,
  2042. .count = CAMELLIA_ENC_TEST_VECTORS
  2043. },
  2044. .dec = {
  2045. .vecs = camellia_dec_tv_template,
  2046. .count = CAMELLIA_DEC_TEST_VECTORS
  2047. }
  2048. }
  2049. }
  2050. }, {
  2051. .alg = "ecb(cast5)",
  2052. .test = alg_test_skcipher,
  2053. .suite = {
  2054. .cipher = {
  2055. .enc = {
  2056. .vecs = cast5_enc_tv_template,
  2057. .count = CAST5_ENC_TEST_VECTORS
  2058. },
  2059. .dec = {
  2060. .vecs = cast5_dec_tv_template,
  2061. .count = CAST5_DEC_TEST_VECTORS
  2062. }
  2063. }
  2064. }
  2065. }, {
  2066. .alg = "ecb(cast6)",
  2067. .test = alg_test_skcipher,
  2068. .suite = {
  2069. .cipher = {
  2070. .enc = {
  2071. .vecs = cast6_enc_tv_template,
  2072. .count = CAST6_ENC_TEST_VECTORS
  2073. },
  2074. .dec = {
  2075. .vecs = cast6_dec_tv_template,
  2076. .count = CAST6_DEC_TEST_VECTORS
  2077. }
  2078. }
  2079. }
  2080. }, {
  2081. .alg = "ecb(des)",
  2082. .test = alg_test_skcipher,
  2083. .fips_allowed = 1,
  2084. .suite = {
  2085. .cipher = {
  2086. .enc = {
  2087. .vecs = des_enc_tv_template,
  2088. .count = DES_ENC_TEST_VECTORS
  2089. },
  2090. .dec = {
  2091. .vecs = des_dec_tv_template,
  2092. .count = DES_DEC_TEST_VECTORS
  2093. }
  2094. }
  2095. }
  2096. }, {
  2097. .alg = "ecb(des3_ede)",
  2098. .test = alg_test_skcipher,
  2099. .fips_allowed = 1,
  2100. .suite = {
  2101. .cipher = {
  2102. .enc = {
  2103. .vecs = des3_ede_enc_tv_template,
  2104. .count = DES3_EDE_ENC_TEST_VECTORS
  2105. },
  2106. .dec = {
  2107. .vecs = des3_ede_dec_tv_template,
  2108. .count = DES3_EDE_DEC_TEST_VECTORS
  2109. }
  2110. }
  2111. }
  2112. }, {
  2113. .alg = "ecb(khazad)",
  2114. .test = alg_test_skcipher,
  2115. .suite = {
  2116. .cipher = {
  2117. .enc = {
  2118. .vecs = khazad_enc_tv_template,
  2119. .count = KHAZAD_ENC_TEST_VECTORS
  2120. },
  2121. .dec = {
  2122. .vecs = khazad_dec_tv_template,
  2123. .count = KHAZAD_DEC_TEST_VECTORS
  2124. }
  2125. }
  2126. }
  2127. }, {
  2128. .alg = "ecb(seed)",
  2129. .test = alg_test_skcipher,
  2130. .suite = {
  2131. .cipher = {
  2132. .enc = {
  2133. .vecs = seed_enc_tv_template,
  2134. .count = SEED_ENC_TEST_VECTORS
  2135. },
  2136. .dec = {
  2137. .vecs = seed_dec_tv_template,
  2138. .count = SEED_DEC_TEST_VECTORS
  2139. }
  2140. }
  2141. }
  2142. }, {
  2143. .alg = "ecb(serpent)",
  2144. .test = alg_test_skcipher,
  2145. .suite = {
  2146. .cipher = {
  2147. .enc = {
  2148. .vecs = serpent_enc_tv_template,
  2149. .count = SERPENT_ENC_TEST_VECTORS
  2150. },
  2151. .dec = {
  2152. .vecs = serpent_dec_tv_template,
  2153. .count = SERPENT_DEC_TEST_VECTORS
  2154. }
  2155. }
  2156. }
  2157. }, {
  2158. .alg = "ecb(tea)",
  2159. .test = alg_test_skcipher,
  2160. .suite = {
  2161. .cipher = {
  2162. .enc = {
  2163. .vecs = tea_enc_tv_template,
  2164. .count = TEA_ENC_TEST_VECTORS
  2165. },
  2166. .dec = {
  2167. .vecs = tea_dec_tv_template,
  2168. .count = TEA_DEC_TEST_VECTORS
  2169. }
  2170. }
  2171. }
  2172. }, {
  2173. .alg = "ecb(tnepres)",
  2174. .test = alg_test_skcipher,
  2175. .suite = {
  2176. .cipher = {
  2177. .enc = {
  2178. .vecs = tnepres_enc_tv_template,
  2179. .count = TNEPRES_ENC_TEST_VECTORS
  2180. },
  2181. .dec = {
  2182. .vecs = tnepres_dec_tv_template,
  2183. .count = TNEPRES_DEC_TEST_VECTORS
  2184. }
  2185. }
  2186. }
  2187. }, {
  2188. .alg = "ecb(twofish)",
  2189. .test = alg_test_skcipher,
  2190. .suite = {
  2191. .cipher = {
  2192. .enc = {
  2193. .vecs = tf_enc_tv_template,
  2194. .count = TF_ENC_TEST_VECTORS
  2195. },
  2196. .dec = {
  2197. .vecs = tf_dec_tv_template,
  2198. .count = TF_DEC_TEST_VECTORS
  2199. }
  2200. }
  2201. }
  2202. }, {
  2203. .alg = "ecb(xeta)",
  2204. .test = alg_test_skcipher,
  2205. .suite = {
  2206. .cipher = {
  2207. .enc = {
  2208. .vecs = xeta_enc_tv_template,
  2209. .count = XETA_ENC_TEST_VECTORS
  2210. },
  2211. .dec = {
  2212. .vecs = xeta_dec_tv_template,
  2213. .count = XETA_DEC_TEST_VECTORS
  2214. }
  2215. }
  2216. }
  2217. }, {
  2218. .alg = "ecb(xtea)",
  2219. .test = alg_test_skcipher,
  2220. .suite = {
  2221. .cipher = {
  2222. .enc = {
  2223. .vecs = xtea_enc_tv_template,
  2224. .count = XTEA_ENC_TEST_VECTORS
  2225. },
  2226. .dec = {
  2227. .vecs = xtea_dec_tv_template,
  2228. .count = XTEA_DEC_TEST_VECTORS
  2229. }
  2230. }
  2231. }
  2232. }, {
  2233. .alg = "gcm(aes)",
  2234. .test = alg_test_aead,
  2235. .fips_allowed = 1,
  2236. .suite = {
  2237. .aead = {
  2238. .enc = {
  2239. .vecs = aes_gcm_enc_tv_template,
  2240. .count = AES_GCM_ENC_TEST_VECTORS
  2241. },
  2242. .dec = {
  2243. .vecs = aes_gcm_dec_tv_template,
  2244. .count = AES_GCM_DEC_TEST_VECTORS
  2245. }
  2246. }
  2247. }
  2248. }, {
  2249. .alg = "ghash",
  2250. .test = alg_test_hash,
  2251. .fips_allowed = 1,
  2252. .suite = {
  2253. .hash = {
  2254. .vecs = ghash_tv_template,
  2255. .count = GHASH_TEST_VECTORS
  2256. }
  2257. }
  2258. }, {
  2259. .alg = "hmac(md5)",
  2260. .test = alg_test_hash,
  2261. .suite = {
  2262. .hash = {
  2263. .vecs = hmac_md5_tv_template,
  2264. .count = HMAC_MD5_TEST_VECTORS
  2265. }
  2266. }
  2267. }, {
  2268. .alg = "hmac(rmd128)",
  2269. .test = alg_test_hash,
  2270. .suite = {
  2271. .hash = {
  2272. .vecs = hmac_rmd128_tv_template,
  2273. .count = HMAC_RMD128_TEST_VECTORS
  2274. }
  2275. }
  2276. }, {
  2277. .alg = "hmac(rmd160)",
  2278. .test = alg_test_hash,
  2279. .suite = {
  2280. .hash = {
  2281. .vecs = hmac_rmd160_tv_template,
  2282. .count = HMAC_RMD160_TEST_VECTORS
  2283. }
  2284. }
  2285. }, {
  2286. .alg = "hmac(sha1)",
  2287. .test = alg_test_hash,
  2288. .fips_allowed = 1,
  2289. .suite = {
  2290. .hash = {
  2291. .vecs = hmac_sha1_tv_template,
  2292. .count = HMAC_SHA1_TEST_VECTORS
  2293. }
  2294. }
  2295. }, {
  2296. .alg = "hmac(sha224)",
  2297. .test = alg_test_hash,
  2298. .fips_allowed = 1,
  2299. .suite = {
  2300. .hash = {
  2301. .vecs = hmac_sha224_tv_template,
  2302. .count = HMAC_SHA224_TEST_VECTORS
  2303. }
  2304. }
  2305. }, {
  2306. .alg = "hmac(sha256)",
  2307. .test = alg_test_hash,
  2308. .fips_allowed = 1,
  2309. .suite = {
  2310. .hash = {
  2311. .vecs = hmac_sha256_tv_template,
  2312. .count = HMAC_SHA256_TEST_VECTORS
  2313. }
  2314. }
  2315. }, {
  2316. .alg = "hmac(sha384)",
  2317. .test = alg_test_hash,
  2318. .fips_allowed = 1,
  2319. .suite = {
  2320. .hash = {
  2321. .vecs = hmac_sha384_tv_template,
  2322. .count = HMAC_SHA384_TEST_VECTORS
  2323. }
  2324. }
  2325. }, {
  2326. .alg = "hmac(sha512)",
  2327. .test = alg_test_hash,
  2328. .fips_allowed = 1,
  2329. .suite = {
  2330. .hash = {
  2331. .vecs = hmac_sha512_tv_template,
  2332. .count = HMAC_SHA512_TEST_VECTORS
  2333. }
  2334. }
  2335. }, {
  2336. .alg = "lrw(aes)",
  2337. .test = alg_test_skcipher,
  2338. .suite = {
  2339. .cipher = {
  2340. .enc = {
  2341. .vecs = aes_lrw_enc_tv_template,
  2342. .count = AES_LRW_ENC_TEST_VECTORS
  2343. },
  2344. .dec = {
  2345. .vecs = aes_lrw_dec_tv_template,
  2346. .count = AES_LRW_DEC_TEST_VECTORS
  2347. }
  2348. }
  2349. }
  2350. }, {
  2351. .alg = "lrw(camellia)",
  2352. .test = alg_test_skcipher,
  2353. .suite = {
  2354. .cipher = {
  2355. .enc = {
  2356. .vecs = camellia_lrw_enc_tv_template,
  2357. .count = CAMELLIA_LRW_ENC_TEST_VECTORS
  2358. },
  2359. .dec = {
  2360. .vecs = camellia_lrw_dec_tv_template,
  2361. .count = CAMELLIA_LRW_DEC_TEST_VECTORS
  2362. }
  2363. }
  2364. }
  2365. }, {
  2366. .alg = "lrw(serpent)",
  2367. .test = alg_test_skcipher,
  2368. .suite = {
  2369. .cipher = {
  2370. .enc = {
  2371. .vecs = serpent_lrw_enc_tv_template,
  2372. .count = SERPENT_LRW_ENC_TEST_VECTORS
  2373. },
  2374. .dec = {
  2375. .vecs = serpent_lrw_dec_tv_template,
  2376. .count = SERPENT_LRW_DEC_TEST_VECTORS
  2377. }
  2378. }
  2379. }
  2380. }, {
  2381. .alg = "lrw(twofish)",
  2382. .test = alg_test_skcipher,
  2383. .suite = {
  2384. .cipher = {
  2385. .enc = {
  2386. .vecs = tf_lrw_enc_tv_template,
  2387. .count = TF_LRW_ENC_TEST_VECTORS
  2388. },
  2389. .dec = {
  2390. .vecs = tf_lrw_dec_tv_template,
  2391. .count = TF_LRW_DEC_TEST_VECTORS
  2392. }
  2393. }
  2394. }
  2395. }, {
  2396. .alg = "lz4",
  2397. .test = alg_test_comp,
  2398. .fips_allowed = 1,
  2399. .suite = {
  2400. .comp = {
  2401. .comp = {
  2402. .vecs = lz4_comp_tv_template,
  2403. .count = LZ4_COMP_TEST_VECTORS
  2404. },
  2405. .decomp = {
  2406. .vecs = lz4_decomp_tv_template,
  2407. .count = LZ4_DECOMP_TEST_VECTORS
  2408. }
  2409. }
  2410. }
  2411. }, {
  2412. .alg = "lz4hc",
  2413. .test = alg_test_comp,
  2414. .fips_allowed = 1,
  2415. .suite = {
  2416. .comp = {
  2417. .comp = {
  2418. .vecs = lz4hc_comp_tv_template,
  2419. .count = LZ4HC_COMP_TEST_VECTORS
  2420. },
  2421. .decomp = {
  2422. .vecs = lz4hc_decomp_tv_template,
  2423. .count = LZ4HC_DECOMP_TEST_VECTORS
  2424. }
  2425. }
  2426. }
  2427. }, {
  2428. .alg = "lzo",
  2429. .test = alg_test_comp,
  2430. .suite = {
  2431. .comp = {
  2432. .comp = {
  2433. .vecs = lzo_comp_tv_template,
  2434. .count = LZO_COMP_TEST_VECTORS
  2435. },
  2436. .decomp = {
  2437. .vecs = lzo_decomp_tv_template,
  2438. .count = LZO_DECOMP_TEST_VECTORS
  2439. }
  2440. }
  2441. }
  2442. }, {
  2443. .alg = "md4",
  2444. .test = alg_test_hash,
  2445. .suite = {
  2446. .hash = {
  2447. .vecs = md4_tv_template,
  2448. .count = MD4_TEST_VECTORS
  2449. }
  2450. }
  2451. }, {
  2452. .alg = "md5",
  2453. .test = alg_test_hash,
  2454. .suite = {
  2455. .hash = {
  2456. .vecs = md5_tv_template,
  2457. .count = MD5_TEST_VECTORS
  2458. }
  2459. }
  2460. }, {
  2461. .alg = "michael_mic",
  2462. .test = alg_test_hash,
  2463. .suite = {
  2464. .hash = {
  2465. .vecs = michael_mic_tv_template,
  2466. .count = MICHAEL_MIC_TEST_VECTORS
  2467. }
  2468. }
  2469. }, {
  2470. .alg = "ofb(aes)",
  2471. .test = alg_test_skcipher,
  2472. .fips_allowed = 1,
  2473. .suite = {
  2474. .cipher = {
  2475. .enc = {
  2476. .vecs = aes_ofb_enc_tv_template,
  2477. .count = AES_OFB_ENC_TEST_VECTORS
  2478. },
  2479. .dec = {
  2480. .vecs = aes_ofb_dec_tv_template,
  2481. .count = AES_OFB_DEC_TEST_VECTORS
  2482. }
  2483. }
  2484. }
  2485. }, {
  2486. .alg = "pcbc(fcrypt)",
  2487. .test = alg_test_skcipher,
  2488. .suite = {
  2489. .cipher = {
  2490. .enc = {
  2491. .vecs = fcrypt_pcbc_enc_tv_template,
  2492. .count = FCRYPT_ENC_TEST_VECTORS
  2493. },
  2494. .dec = {
  2495. .vecs = fcrypt_pcbc_dec_tv_template,
  2496. .count = FCRYPT_DEC_TEST_VECTORS
  2497. }
  2498. }
  2499. }
  2500. }, {
  2501. .alg = "rfc3686(ctr(aes))",
  2502. .test = alg_test_skcipher,
  2503. .fips_allowed = 1,
  2504. .suite = {
  2505. .cipher = {
  2506. .enc = {
  2507. .vecs = aes_ctr_rfc3686_enc_tv_template,
  2508. .count = AES_CTR_3686_ENC_TEST_VECTORS
  2509. },
  2510. .dec = {
  2511. .vecs = aes_ctr_rfc3686_dec_tv_template,
  2512. .count = AES_CTR_3686_DEC_TEST_VECTORS
  2513. }
  2514. }
  2515. }
  2516. }, {
  2517. .alg = "rfc4106(gcm(aes))",
  2518. .test = alg_test_aead,
  2519. .suite = {
  2520. .aead = {
  2521. .enc = {
  2522. .vecs = aes_gcm_rfc4106_enc_tv_template,
  2523. .count = AES_GCM_4106_ENC_TEST_VECTORS
  2524. },
  2525. .dec = {
  2526. .vecs = aes_gcm_rfc4106_dec_tv_template,
  2527. .count = AES_GCM_4106_DEC_TEST_VECTORS
  2528. }
  2529. }
  2530. }
  2531. }, {
  2532. .alg = "rfc4309(ccm(aes))",
  2533. .test = alg_test_aead,
  2534. .fips_allowed = 1,
  2535. .suite = {
  2536. .aead = {
  2537. .enc = {
  2538. .vecs = aes_ccm_rfc4309_enc_tv_template,
  2539. .count = AES_CCM_4309_ENC_TEST_VECTORS
  2540. },
  2541. .dec = {
  2542. .vecs = aes_ccm_rfc4309_dec_tv_template,
  2543. .count = AES_CCM_4309_DEC_TEST_VECTORS
  2544. }
  2545. }
  2546. }
  2547. }, {
  2548. .alg = "rmd128",
  2549. .test = alg_test_hash,
  2550. .suite = {
  2551. .hash = {
  2552. .vecs = rmd128_tv_template,
  2553. .count = RMD128_TEST_VECTORS
  2554. }
  2555. }
  2556. }, {
  2557. .alg = "rmd160",
  2558. .test = alg_test_hash,
  2559. .suite = {
  2560. .hash = {
  2561. .vecs = rmd160_tv_template,
  2562. .count = RMD160_TEST_VECTORS
  2563. }
  2564. }
  2565. }, {
  2566. .alg = "rmd256",
  2567. .test = alg_test_hash,
  2568. .suite = {
  2569. .hash = {
  2570. .vecs = rmd256_tv_template,
  2571. .count = RMD256_TEST_VECTORS
  2572. }
  2573. }
  2574. }, {
  2575. .alg = "rmd320",
  2576. .test = alg_test_hash,
  2577. .suite = {
  2578. .hash = {
  2579. .vecs = rmd320_tv_template,
  2580. .count = RMD320_TEST_VECTORS
  2581. }
  2582. }
  2583. }, {
  2584. .alg = "salsa20",
  2585. .test = alg_test_skcipher,
  2586. .suite = {
  2587. .cipher = {
  2588. .enc = {
  2589. .vecs = salsa20_stream_enc_tv_template,
  2590. .count = SALSA20_STREAM_ENC_TEST_VECTORS
  2591. }
  2592. }
  2593. }
  2594. }, {
  2595. .alg = "sha1",
  2596. .test = alg_test_hash,
  2597. .fips_allowed = 1,
  2598. .suite = {
  2599. .hash = {
  2600. .vecs = sha1_tv_template,
  2601. .count = SHA1_TEST_VECTORS
  2602. }
  2603. }
  2604. }, {
  2605. .alg = "sha224",
  2606. .test = alg_test_hash,
  2607. .fips_allowed = 1,
  2608. .suite = {
  2609. .hash = {
  2610. .vecs = sha224_tv_template,
  2611. .count = SHA224_TEST_VECTORS
  2612. }
  2613. }
  2614. }, {
  2615. .alg = "sha256",
  2616. .test = alg_test_hash,
  2617. .fips_allowed = 1,
  2618. .suite = {
  2619. .hash = {
  2620. .vecs = sha256_tv_template,
  2621. .count = SHA256_TEST_VECTORS
  2622. }
  2623. }
  2624. }, {
  2625. .alg = "sha384",
  2626. .test = alg_test_hash,
  2627. .fips_allowed = 1,
  2628. .suite = {
  2629. .hash = {
  2630. .vecs = sha384_tv_template,
  2631. .count = SHA384_TEST_VECTORS
  2632. }
  2633. }
  2634. }, {
  2635. .alg = "sha512",
  2636. .test = alg_test_hash,
  2637. .fips_allowed = 1,
  2638. .suite = {
  2639. .hash = {
  2640. .vecs = sha512_tv_template,
  2641. .count = SHA512_TEST_VECTORS
  2642. }
  2643. }
  2644. }, {
  2645. .alg = "tgr128",
  2646. .test = alg_test_hash,
  2647. .suite = {
  2648. .hash = {
  2649. .vecs = tgr128_tv_template,
  2650. .count = TGR128_TEST_VECTORS
  2651. }
  2652. }
  2653. }, {
  2654. .alg = "tgr160",
  2655. .test = alg_test_hash,
  2656. .suite = {
  2657. .hash = {
  2658. .vecs = tgr160_tv_template,
  2659. .count = TGR160_TEST_VECTORS
  2660. }
  2661. }
  2662. }, {
  2663. .alg = "tgr192",
  2664. .test = alg_test_hash,
  2665. .suite = {
  2666. .hash = {
  2667. .vecs = tgr192_tv_template,
  2668. .count = TGR192_TEST_VECTORS
  2669. }
  2670. }
  2671. }, {
  2672. .alg = "vmac(aes)",
  2673. .test = alg_test_hash,
  2674. .suite = {
  2675. .hash = {
  2676. .vecs = aes_vmac128_tv_template,
  2677. .count = VMAC_AES_TEST_VECTORS
  2678. }
  2679. }
  2680. }, {
  2681. .alg = "wp256",
  2682. .test = alg_test_hash,
  2683. .suite = {
  2684. .hash = {
  2685. .vecs = wp256_tv_template,
  2686. .count = WP256_TEST_VECTORS
  2687. }
  2688. }
  2689. }, {
  2690. .alg = "wp384",
  2691. .test = alg_test_hash,
  2692. .suite = {
  2693. .hash = {
  2694. .vecs = wp384_tv_template,
  2695. .count = WP384_TEST_VECTORS
  2696. }
  2697. }
  2698. }, {
  2699. .alg = "wp512",
  2700. .test = alg_test_hash,
  2701. .suite = {
  2702. .hash = {
  2703. .vecs = wp512_tv_template,
  2704. .count = WP512_TEST_VECTORS
  2705. }
  2706. }
  2707. }, {
  2708. .alg = "xcbc(aes)",
  2709. .test = alg_test_hash,
  2710. .suite = {
  2711. .hash = {
  2712. .vecs = aes_xcbc128_tv_template,
  2713. .count = XCBC_AES_TEST_VECTORS
  2714. }
  2715. }
  2716. }, {
  2717. .alg = "xts(aes)",
  2718. .test = alg_test_skcipher,
  2719. .fips_allowed = 1,
  2720. .suite = {
  2721. .cipher = {
  2722. .enc = {
  2723. .vecs = aes_xts_enc_tv_template,
  2724. .count = AES_XTS_ENC_TEST_VECTORS
  2725. },
  2726. .dec = {
  2727. .vecs = aes_xts_dec_tv_template,
  2728. .count = AES_XTS_DEC_TEST_VECTORS
  2729. }
  2730. }
  2731. }
  2732. }, {
  2733. .alg = "xts(camellia)",
  2734. .test = alg_test_skcipher,
  2735. .suite = {
  2736. .cipher = {
  2737. .enc = {
  2738. .vecs = camellia_xts_enc_tv_template,
  2739. .count = CAMELLIA_XTS_ENC_TEST_VECTORS
  2740. },
  2741. .dec = {
  2742. .vecs = camellia_xts_dec_tv_template,
  2743. .count = CAMELLIA_XTS_DEC_TEST_VECTORS
  2744. }
  2745. }
  2746. }
  2747. }, {
  2748. .alg = "xts(serpent)",
  2749. .test = alg_test_skcipher,
  2750. .suite = {
  2751. .cipher = {
  2752. .enc = {
  2753. .vecs = serpent_xts_enc_tv_template,
  2754. .count = SERPENT_XTS_ENC_TEST_VECTORS
  2755. },
  2756. .dec = {
  2757. .vecs = serpent_xts_dec_tv_template,
  2758. .count = SERPENT_XTS_DEC_TEST_VECTORS
  2759. }
  2760. }
  2761. }
  2762. }, {
  2763. .alg = "xts(twofish)",
  2764. .test = alg_test_skcipher,
  2765. .suite = {
  2766. .cipher = {
  2767. .enc = {
  2768. .vecs = tf_xts_enc_tv_template,
  2769. .count = TF_XTS_ENC_TEST_VECTORS
  2770. },
  2771. .dec = {
  2772. .vecs = tf_xts_dec_tv_template,
  2773. .count = TF_XTS_DEC_TEST_VECTORS
  2774. }
  2775. }
  2776. }
  2777. }, {
  2778. .alg = "zlib",
  2779. .test = alg_test_pcomp,
  2780. .suite = {
  2781. .pcomp = {
  2782. .comp = {
  2783. .vecs = zlib_comp_tv_template,
  2784. .count = ZLIB_COMP_TEST_VECTORS
  2785. },
  2786. .decomp = {
  2787. .vecs = zlib_decomp_tv_template,
  2788. .count = ZLIB_DECOMP_TEST_VECTORS
  2789. }
  2790. }
  2791. }
  2792. }
  2793. };
  2794. static int alg_find_test(const char *alg)
  2795. {
  2796. int start = 0;
  2797. int end = ARRAY_SIZE(alg_test_descs);
  2798. while (start < end) {
  2799. int i = (start + end) / 2;
  2800. int diff = strcmp(alg_test_descs[i].alg, alg);
  2801. if (diff > 0) {
  2802. end = i;
  2803. continue;
  2804. }
  2805. if (diff < 0) {
  2806. start = i + 1;
  2807. continue;
  2808. }
  2809. return i;
  2810. }
  2811. return -1;
  2812. }
  2813. int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
  2814. {
  2815. int i;
  2816. int j;
  2817. int rc = 0;
  2818. if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
  2819. char nalg[CRYPTO_MAX_ALG_NAME];
  2820. if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
  2821. sizeof(nalg))
  2822. return -ENAMETOOLONG;
  2823. i = alg_find_test(nalg);
  2824. if (i < 0)
  2825. goto notest;
  2826. if (fips_enabled && !alg_test_descs[i].fips_allowed)
  2827. goto non_fips_alg;
  2828. rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
  2829. goto test_done;
  2830. }
  2831. i = alg_find_test(alg);
  2832. j = alg_find_test(driver);
  2833. if (i < 0 && j < 0)
  2834. goto notest;
  2835. #if FIPS_FUNC_TEST == 3
  2836. // change@wtl.rsengott - FIPS mode self test Functional Test
  2837. if (fips_enabled)
  2838. printk(KERN_INFO "FIPS: %s: %s alg self test START in fips mode!\n",
  2839. driver, alg);
  2840. #endif
  2841. if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
  2842. (j >= 0 && !alg_test_descs[j].fips_allowed)))
  2843. goto non_fips_alg;
  2844. rc = 0;
  2845. if (i >= 0)
  2846. rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
  2847. type, mask);
  2848. if (j >= 0)
  2849. rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
  2850. type, mask);
  2851. test_done:
  2852. if (fips_enabled && rc) {
  2853. printk(KERN_INFO
  2854. "FIPS: %s: %s alg self test failed\n",
  2855. driver, alg);
  2856. #ifdef CONFIG_CRYPTO_FIPS
  2857. IN_FIPS_ERROR = FIPS_ERR;
  2858. #else
  2859. panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
  2860. #endif
  2861. return rc;
  2862. }
  2863. if (fips_enabled && !rc)
  2864. printk(KERN_INFO "FIPS: self-tests for %s (%s) passed\n",
  2865. driver, alg);
  2866. return rc;
  2867. notest:
  2868. printk(KERN_INFO "FIPS: No test for %s (%s)\n", alg, driver);
  2869. return 0;
  2870. non_fips_alg:
  2871. if (!rc)
  2872. printk(KERN_INFO
  2873. "FIPS: self-tests for non-FIPS %s (%s) passed\n",
  2874. driver, alg);
  2875. else
  2876. printk(KERN_INFO
  2877. "FIPS: self-tests for non-FIPS %s (%s) failed\n",
  2878. alg, driver);
  2879. return rc;
  2880. }
  2881. int testmgr_crypto_proc_init(void)
  2882. {
  2883. #ifdef CONFIG_CRYPTO_FIPS
  2884. crypto_init_proc(&IN_FIPS_ERROR);
  2885. #else
  2886. crypto_init_proc();
  2887. #endif
  2888. return 0;
  2889. }
  2890. #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
  2891. EXPORT_SYMBOL_GPL(alg_test);