testmgr.c 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166
  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. goto out;
  1283. tfm = crypto_alloc_shash(driver, type, mask);
  1284. if (IS_ERR(tfm)) {
  1285. printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
  1286. "%ld\n", driver, PTR_ERR(tfm));
  1287. err = PTR_ERR(tfm);
  1288. goto out;
  1289. }
  1290. do {
  1291. struct {
  1292. struct shash_desc shash;
  1293. char ctx[crypto_shash_descsize(tfm)];
  1294. } sdesc;
  1295. sdesc.shash.tfm = tfm;
  1296. sdesc.shash.flags = 0;
  1297. *(u32 *)sdesc.ctx = le32_to_cpu(420553207);
  1298. err = crypto_shash_final(&sdesc.shash, (u8 *)&val);
  1299. if (err) {
  1300. printk(KERN_ERR "alg: crc32c: Operation failed for "
  1301. "%s: %d\n", driver, err);
  1302. break;
  1303. }
  1304. if (val != ~420553207) {
  1305. printk(KERN_ERR "alg: crc32c: Test failed for %s: "
  1306. "%d\n", driver, val);
  1307. err = -EINVAL;
  1308. }
  1309. } while (0);
  1310. crypto_free_shash(tfm);
  1311. out:
  1312. return err;
  1313. }
  1314. static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
  1315. u32 type, u32 mask)
  1316. {
  1317. struct crypto_rng *rng;
  1318. int err;
  1319. rng = crypto_alloc_rng(driver, type, mask);
  1320. if (IS_ERR(rng)) {
  1321. printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
  1322. "%ld\n", driver, PTR_ERR(rng));
  1323. return PTR_ERR(rng);
  1324. }
  1325. err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
  1326. crypto_free_rng(rng);
  1327. return err;
  1328. }
  1329. #ifdef CONFIG_CRYPTO_DRBG
  1330. static int drbg_cavs_test(struct drbg_testvec *test, int pr,
  1331. const char *driver, u32 type, u32 mask)
  1332. {
  1333. int ret = -EAGAIN;
  1334. struct crypto_rng *drng;
  1335. struct drbg_test_data test_data;
  1336. struct drbg_string addtl, pers, testentropy;
  1337. unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
  1338. if (!buf)
  1339. return -ENOMEM;
  1340. drng = crypto_alloc_rng(driver, type, mask);
  1341. if (IS_ERR(drng)) {
  1342. printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
  1343. "%s\n", driver);
  1344. kzfree(buf);
  1345. return -ENOMEM;
  1346. }
  1347. test_data.testentropy = &testentropy;
  1348. drbg_string_fill(&testentropy, test->entropy, test->entropylen);
  1349. drbg_string_fill(&pers, test->pers, test->perslen);
  1350. ret = crypto_drbg_reset_test(drng, &pers, &test_data);
  1351. if (ret) {
  1352. printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
  1353. goto outbuf;
  1354. }
  1355. drbg_string_fill(&addtl, test->addtla, test->addtllen);
  1356. if (pr) {
  1357. drbg_string_fill(&testentropy, test->entpra, test->entprlen);
  1358. ret = crypto_drbg_get_bytes_addtl_test(drng,
  1359. buf, test->expectedlen, &addtl, &test_data);
  1360. } else {
  1361. ret = crypto_drbg_get_bytes_addtl(drng,
  1362. buf, test->expectedlen, &addtl);
  1363. }
  1364. if (ret <= 0) {
  1365. printk(KERN_ERR "alg: drbg: could not obtain random data for "
  1366. "driver %s\n", driver);
  1367. goto outbuf;
  1368. }
  1369. drbg_string_fill(&addtl, test->addtlb, test->addtllen);
  1370. if (pr) {
  1371. drbg_string_fill(&testentropy, test->entprb, test->entprlen);
  1372. ret = crypto_drbg_get_bytes_addtl_test(drng,
  1373. buf, test->expectedlen, &addtl, &test_data);
  1374. } else {
  1375. ret = crypto_drbg_get_bytes_addtl(drng,
  1376. buf, test->expectedlen, &addtl);
  1377. }
  1378. if (ret <= 0) {
  1379. printk(KERN_ERR "alg: drbg: could not obtain random data for "
  1380. "driver %s\n", driver);
  1381. goto outbuf;
  1382. }
  1383. ret = memcmp(test->expected, buf, test->expectedlen);
  1384. outbuf:
  1385. crypto_free_rng(drng);
  1386. kzfree(buf);
  1387. return ret;
  1388. }
  1389. static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
  1390. u32 type, u32 mask)
  1391. {
  1392. int err = 0;
  1393. int pr = 0;
  1394. int i = 0;
  1395. struct drbg_testvec *template = desc->suite.drbg.vecs;
  1396. unsigned int tcount = desc->suite.drbg.count;
  1397. if (0 == memcmp(driver, "drbg_pr_", 8))
  1398. pr = 1;
  1399. for (i = 0; i < tcount; i++) {
  1400. err = drbg_cavs_test(&template[i], pr, driver, type, mask);
  1401. if (err) {
  1402. printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
  1403. i, driver);
  1404. err = -EINVAL;
  1405. break;
  1406. }
  1407. }
  1408. return err;
  1409. }
  1410. #endif
  1411. static int alg_test_null(const struct alg_test_desc *desc,
  1412. const char *driver, u32 type, u32 mask)
  1413. {
  1414. return 0;
  1415. }
  1416. /* Please keep this list sorted by algorithm name. */
  1417. static const struct alg_test_desc alg_test_descs[] = {
  1418. {
  1419. .alg = "__cbc-serpent-sse2",
  1420. .test = alg_test_null,
  1421. .suite = {
  1422. .cipher = {
  1423. .enc = {
  1424. .vecs = NULL,
  1425. .count = 0
  1426. },
  1427. .dec = {
  1428. .vecs = NULL,
  1429. .count = 0
  1430. }
  1431. }
  1432. }
  1433. }, {
  1434. .alg = "__driver-cbc-aes-aesni",
  1435. .test = alg_test_null,
  1436. .suite = {
  1437. .cipher = {
  1438. .enc = {
  1439. .vecs = NULL,
  1440. .count = 0
  1441. },
  1442. .dec = {
  1443. .vecs = NULL,
  1444. .count = 0
  1445. }
  1446. }
  1447. }
  1448. }, {
  1449. .alg = "__driver-cbc-serpent-sse2",
  1450. .test = alg_test_null,
  1451. .suite = {
  1452. .cipher = {
  1453. .enc = {
  1454. .vecs = NULL,
  1455. .count = 0
  1456. },
  1457. .dec = {
  1458. .vecs = NULL,
  1459. .count = 0
  1460. }
  1461. }
  1462. }
  1463. }, {
  1464. .alg = "__driver-ecb-aes-aesni",
  1465. .test = alg_test_null,
  1466. .suite = {
  1467. .cipher = {
  1468. .enc = {
  1469. .vecs = NULL,
  1470. .count = 0
  1471. },
  1472. .dec = {
  1473. .vecs = NULL,
  1474. .count = 0
  1475. }
  1476. }
  1477. }
  1478. }, {
  1479. .alg = "__driver-ecb-serpent-sse2",
  1480. .test = alg_test_null,
  1481. .suite = {
  1482. .cipher = {
  1483. .enc = {
  1484. .vecs = NULL,
  1485. .count = 0
  1486. },
  1487. .dec = {
  1488. .vecs = NULL,
  1489. .count = 0
  1490. }
  1491. }
  1492. }
  1493. }, {
  1494. .alg = "__ghash-pclmulqdqni",
  1495. .test = alg_test_null,
  1496. .suite = {
  1497. .hash = {
  1498. .vecs = NULL,
  1499. .count = 0
  1500. }
  1501. }
  1502. }, {
  1503. .alg = "ansi_cprng",
  1504. .test = alg_test_cprng,
  1505. .fips_allowed = 1,
  1506. .suite = {
  1507. .cprng = {
  1508. .vecs = ansi_cprng_aes_tv_template,
  1509. .count = ANSI_CPRNG_AES_TEST_VECTORS
  1510. }
  1511. }
  1512. }, {
  1513. .alg = "cbc(aes)",
  1514. .test = alg_test_skcipher,
  1515. .fips_allowed = 1,
  1516. .suite = {
  1517. .cipher = {
  1518. .enc = {
  1519. .vecs = aes_cbc_enc_tv_template,
  1520. .count = AES_CBC_ENC_TEST_VECTORS
  1521. },
  1522. .dec = {
  1523. .vecs = aes_cbc_dec_tv_template,
  1524. .count = AES_CBC_DEC_TEST_VECTORS
  1525. }
  1526. }
  1527. }
  1528. }, {
  1529. .alg = "cbc(anubis)",
  1530. .test = alg_test_skcipher,
  1531. .suite = {
  1532. .cipher = {
  1533. .enc = {
  1534. .vecs = anubis_cbc_enc_tv_template,
  1535. .count = ANUBIS_CBC_ENC_TEST_VECTORS
  1536. },
  1537. .dec = {
  1538. .vecs = anubis_cbc_dec_tv_template,
  1539. .count = ANUBIS_CBC_DEC_TEST_VECTORS
  1540. }
  1541. }
  1542. }
  1543. }, {
  1544. .alg = "cbc(blowfish)",
  1545. .test = alg_test_skcipher,
  1546. .suite = {
  1547. .cipher = {
  1548. .enc = {
  1549. .vecs = bf_cbc_enc_tv_template,
  1550. .count = BF_CBC_ENC_TEST_VECTORS
  1551. },
  1552. .dec = {
  1553. .vecs = bf_cbc_dec_tv_template,
  1554. .count = BF_CBC_DEC_TEST_VECTORS
  1555. }
  1556. }
  1557. }
  1558. }, {
  1559. .alg = "cbc(camellia)",
  1560. .test = alg_test_skcipher,
  1561. .suite = {
  1562. .cipher = {
  1563. .enc = {
  1564. .vecs = camellia_cbc_enc_tv_template,
  1565. .count = CAMELLIA_CBC_ENC_TEST_VECTORS
  1566. },
  1567. .dec = {
  1568. .vecs = camellia_cbc_dec_tv_template,
  1569. .count = CAMELLIA_CBC_DEC_TEST_VECTORS
  1570. }
  1571. }
  1572. }
  1573. }, {
  1574. .alg = "cbc(des)",
  1575. .test = alg_test_skcipher,
  1576. .suite = {
  1577. .cipher = {
  1578. .enc = {
  1579. .vecs = des_cbc_enc_tv_template,
  1580. .count = DES_CBC_ENC_TEST_VECTORS
  1581. },
  1582. .dec = {
  1583. .vecs = des_cbc_dec_tv_template,
  1584. .count = DES_CBC_DEC_TEST_VECTORS
  1585. }
  1586. }
  1587. }
  1588. }, {
  1589. .alg = "cbc(des3_ede)",
  1590. .test = alg_test_skcipher,
  1591. .fips_allowed = 1,
  1592. .suite = {
  1593. .cipher = {
  1594. .enc = {
  1595. .vecs = des3_ede_cbc_enc_tv_template,
  1596. .count = DES3_EDE_CBC_ENC_TEST_VECTORS
  1597. },
  1598. .dec = {
  1599. .vecs = des3_ede_cbc_dec_tv_template,
  1600. .count = DES3_EDE_CBC_DEC_TEST_VECTORS
  1601. }
  1602. }
  1603. }
  1604. }, {
  1605. .alg = "cbc(serpent)",
  1606. .test = alg_test_skcipher,
  1607. .suite = {
  1608. .cipher = {
  1609. .enc = {
  1610. .vecs = serpent_cbc_enc_tv_template,
  1611. .count = SERPENT_CBC_ENC_TEST_VECTORS
  1612. },
  1613. .dec = {
  1614. .vecs = serpent_cbc_dec_tv_template,
  1615. .count = SERPENT_CBC_DEC_TEST_VECTORS
  1616. }
  1617. }
  1618. }
  1619. }, {
  1620. .alg = "cbc(twofish)",
  1621. .test = alg_test_skcipher,
  1622. .suite = {
  1623. .cipher = {
  1624. .enc = {
  1625. .vecs = tf_cbc_enc_tv_template,
  1626. .count = TF_CBC_ENC_TEST_VECTORS
  1627. },
  1628. .dec = {
  1629. .vecs = tf_cbc_dec_tv_template,
  1630. .count = TF_CBC_DEC_TEST_VECTORS
  1631. }
  1632. }
  1633. }
  1634. }, {
  1635. .alg = "ccm(aes)",
  1636. .test = alg_test_aead,
  1637. .fips_allowed = 1,
  1638. .suite = {
  1639. .aead = {
  1640. .enc = {
  1641. .vecs = aes_ccm_enc_tv_template,
  1642. .count = AES_CCM_ENC_TEST_VECTORS
  1643. },
  1644. .dec = {
  1645. .vecs = aes_ccm_dec_tv_template,
  1646. .count = AES_CCM_DEC_TEST_VECTORS
  1647. }
  1648. }
  1649. }
  1650. }, {
  1651. .alg = "crc32c",
  1652. .test = alg_test_crc32c,
  1653. .fips_allowed = 1,
  1654. .suite = {
  1655. .hash = {
  1656. .vecs = crc32c_tv_template,
  1657. .count = CRC32C_TEST_VECTORS
  1658. }
  1659. }
  1660. }, {
  1661. .alg = "cryptd(__driver-ecb-aes-aesni)",
  1662. .test = alg_test_null,
  1663. .suite = {
  1664. .cipher = {
  1665. .enc = {
  1666. .vecs = NULL,
  1667. .count = 0
  1668. },
  1669. .dec = {
  1670. .vecs = NULL,
  1671. .count = 0
  1672. }
  1673. }
  1674. }
  1675. }, {
  1676. .alg = "cryptd(__driver-ecb-serpent-sse2)",
  1677. .test = alg_test_null,
  1678. .suite = {
  1679. .cipher = {
  1680. .enc = {
  1681. .vecs = NULL,
  1682. .count = 0
  1683. },
  1684. .dec = {
  1685. .vecs = NULL,
  1686. .count = 0
  1687. }
  1688. }
  1689. }
  1690. }, {
  1691. .alg = "cryptd(__ghash-pclmulqdqni)",
  1692. .test = alg_test_null,
  1693. .suite = {
  1694. .hash = {
  1695. .vecs = NULL,
  1696. .count = 0
  1697. }
  1698. }
  1699. }, {
  1700. .alg = "ctr(aes)",
  1701. .test = alg_test_skcipher,
  1702. .fips_allowed = 1,
  1703. .suite = {
  1704. .cipher = {
  1705. .enc = {
  1706. .vecs = aes_ctr_enc_tv_template,
  1707. .count = AES_CTR_ENC_TEST_VECTORS
  1708. },
  1709. .dec = {
  1710. .vecs = aes_ctr_dec_tv_template,
  1711. .count = AES_CTR_DEC_TEST_VECTORS
  1712. }
  1713. }
  1714. }
  1715. }, {
  1716. .alg = "ctr(blowfish)",
  1717. .test = alg_test_skcipher,
  1718. .suite = {
  1719. .cipher = {
  1720. .enc = {
  1721. .vecs = bf_ctr_enc_tv_template,
  1722. .count = BF_CTR_ENC_TEST_VECTORS
  1723. },
  1724. .dec = {
  1725. .vecs = bf_ctr_dec_tv_template,
  1726. .count = BF_CTR_DEC_TEST_VECTORS
  1727. }
  1728. }
  1729. }
  1730. }, {
  1731. .alg = "ctr(camellia)",
  1732. .test = alg_test_skcipher,
  1733. .suite = {
  1734. .cipher = {
  1735. .enc = {
  1736. .vecs = camellia_ctr_enc_tv_template,
  1737. .count = CAMELLIA_CTR_ENC_TEST_VECTORS
  1738. },
  1739. .dec = {
  1740. .vecs = camellia_ctr_dec_tv_template,
  1741. .count = CAMELLIA_CTR_DEC_TEST_VECTORS
  1742. }
  1743. }
  1744. }
  1745. }, {
  1746. .alg = "ctr(serpent)",
  1747. .test = alg_test_skcipher,
  1748. .suite = {
  1749. .cipher = {
  1750. .enc = {
  1751. .vecs = serpent_ctr_enc_tv_template,
  1752. .count = SERPENT_CTR_ENC_TEST_VECTORS
  1753. },
  1754. .dec = {
  1755. .vecs = serpent_ctr_dec_tv_template,
  1756. .count = SERPENT_CTR_DEC_TEST_VECTORS
  1757. }
  1758. }
  1759. }
  1760. }, {
  1761. .alg = "ctr(twofish)",
  1762. .test = alg_test_skcipher,
  1763. .suite = {
  1764. .cipher = {
  1765. .enc = {
  1766. .vecs = tf_ctr_enc_tv_template,
  1767. .count = TF_CTR_ENC_TEST_VECTORS
  1768. },
  1769. .dec = {
  1770. .vecs = tf_ctr_dec_tv_template,
  1771. .count = TF_CTR_DEC_TEST_VECTORS
  1772. }
  1773. }
  1774. }
  1775. }, {
  1776. .alg = "cts(cbc(aes))",
  1777. .test = alg_test_skcipher,
  1778. .suite = {
  1779. .cipher = {
  1780. .enc = {
  1781. .vecs = cts_mode_enc_tv_template,
  1782. .count = CTS_MODE_ENC_TEST_VECTORS
  1783. },
  1784. .dec = {
  1785. .vecs = cts_mode_dec_tv_template,
  1786. .count = CTS_MODE_DEC_TEST_VECTORS
  1787. }
  1788. }
  1789. }
  1790. }, {
  1791. .alg = "deflate",
  1792. .test = alg_test_comp,
  1793. .suite = {
  1794. .comp = {
  1795. .comp = {
  1796. .vecs = deflate_comp_tv_template,
  1797. .count = DEFLATE_COMP_TEST_VECTORS
  1798. },
  1799. .decomp = {
  1800. .vecs = deflate_decomp_tv_template,
  1801. .count = DEFLATE_DECOMP_TEST_VECTORS
  1802. }
  1803. }
  1804. }
  1805. }, {
  1806. #ifdef CONFIG_CRYPTO_DRBG
  1807. .alg = "drbg_nopr_ctr_aes128",
  1808. .test = alg_test_drbg,
  1809. .fips_allowed = 1,
  1810. .suite = {
  1811. .drbg = {
  1812. .vecs = drbg_nopr_ctr_aes128_tv_template,
  1813. .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
  1814. }
  1815. }
  1816. }, {
  1817. .alg = "drbg_nopr_ctr_aes192",
  1818. .test = alg_test_drbg,
  1819. .fips_allowed = 1,
  1820. .suite = {
  1821. .drbg = {
  1822. .vecs = drbg_nopr_ctr_aes192_tv_template,
  1823. .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
  1824. }
  1825. }
  1826. }, {
  1827. .alg = "drbg_nopr_ctr_aes256",
  1828. .test = alg_test_drbg,
  1829. .fips_allowed = 1,
  1830. .suite = {
  1831. .drbg = {
  1832. .vecs = drbg_nopr_ctr_aes256_tv_template,
  1833. .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
  1834. }
  1835. }
  1836. }, {
  1837. /*
  1838. * There is no need to specifically test the DRBG with every
  1839. * backend cipher -- covered by drbg_nopr_hmac_sha256 test
  1840. */
  1841. .alg = "drbg_nopr_hmac_sha1",
  1842. .fips_allowed = 1,
  1843. .test = alg_test_null,
  1844. }, {
  1845. .alg = "drbg_nopr_hmac_sha256",
  1846. .test = alg_test_drbg,
  1847. .fips_allowed = 1,
  1848. .suite = {
  1849. .drbg = {
  1850. .vecs = drbg_nopr_hmac_sha256_tv_template,
  1851. .count =
  1852. ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
  1853. }
  1854. }
  1855. }, {
  1856. /* covered by drbg_nopr_hmac_sha256 test */
  1857. .alg = "drbg_nopr_hmac_sha384",
  1858. .fips_allowed = 1,
  1859. .test = alg_test_null,
  1860. }, {
  1861. .alg = "drbg_nopr_hmac_sha512",
  1862. .test = alg_test_null,
  1863. .fips_allowed = 1,
  1864. }, {
  1865. .alg = "drbg_nopr_sha1",
  1866. .fips_allowed = 1,
  1867. .test = alg_test_null,
  1868. }, {
  1869. .alg = "drbg_nopr_sha256",
  1870. .test = alg_test_drbg,
  1871. .fips_allowed = 1,
  1872. .suite = {
  1873. .drbg = {
  1874. .vecs = drbg_nopr_sha256_tv_template,
  1875. .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
  1876. }
  1877. }
  1878. }, {
  1879. /* covered by drbg_nopr_sha256 test */
  1880. .alg = "drbg_nopr_sha384",
  1881. .fips_allowed = 1,
  1882. .test = alg_test_null,
  1883. }, {
  1884. .alg = "drbg_nopr_sha512",
  1885. .fips_allowed = 1,
  1886. .test = alg_test_null,
  1887. }, {
  1888. .alg = "drbg_pr_ctr_aes128",
  1889. .test = alg_test_drbg,
  1890. .fips_allowed = 1,
  1891. .suite = {
  1892. .drbg = {
  1893. .vecs = drbg_pr_ctr_aes128_tv_template,
  1894. .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
  1895. }
  1896. }
  1897. }, {
  1898. /* covered by drbg_pr_ctr_aes128 test */
  1899. .alg = "drbg_pr_ctr_aes192",
  1900. .fips_allowed = 1,
  1901. .test = alg_test_null,
  1902. }, {
  1903. .alg = "drbg_pr_ctr_aes256",
  1904. .fips_allowed = 1,
  1905. .test = alg_test_null,
  1906. }, {
  1907. .alg = "drbg_pr_hmac_sha1",
  1908. .fips_allowed = 1,
  1909. .test = alg_test_null,
  1910. }, {
  1911. .alg = "drbg_pr_hmac_sha256",
  1912. .test = alg_test_drbg,
  1913. .fips_allowed = 1,
  1914. .suite = {
  1915. .drbg = {
  1916. .vecs = drbg_pr_hmac_sha256_tv_template,
  1917. .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
  1918. }
  1919. }
  1920. }, {
  1921. /* covered by drbg_pr_hmac_sha256 test */
  1922. .alg = "drbg_pr_hmac_sha384",
  1923. .fips_allowed = 1,
  1924. .test = alg_test_null,
  1925. }, {
  1926. .alg = "drbg_pr_hmac_sha512",
  1927. .test = alg_test_null,
  1928. .fips_allowed = 1,
  1929. }, {
  1930. .alg = "drbg_pr_sha1",
  1931. .fips_allowed = 1,
  1932. .test = alg_test_null,
  1933. }, {
  1934. .alg = "drbg_pr_sha256",
  1935. .test = alg_test_drbg,
  1936. .fips_allowed = 1,
  1937. .suite = {
  1938. .drbg = {
  1939. .vecs = drbg_pr_sha256_tv_template,
  1940. .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
  1941. }
  1942. }
  1943. }, {
  1944. /* covered by drbg_pr_sha256 test */
  1945. .alg = "drbg_pr_sha384",
  1946. .fips_allowed = 1,
  1947. .test = alg_test_null,
  1948. }, {
  1949. .alg = "drbg_pr_sha512",
  1950. .fips_allowed = 1,
  1951. .test = alg_test_null,
  1952. }, {
  1953. #endif /* CONFIG_CRYPTO_DRBG */
  1954. .alg = "ecb(__aes-aesni)",
  1955. .test = alg_test_null,
  1956. .suite = {
  1957. .cipher = {
  1958. .enc = {
  1959. .vecs = NULL,
  1960. .count = 0
  1961. },
  1962. .dec = {
  1963. .vecs = NULL,
  1964. .count = 0
  1965. }
  1966. }
  1967. }
  1968. }, {
  1969. .alg = "ecb(aes)",
  1970. .test = alg_test_skcipher,
  1971. .fips_allowed = 1,
  1972. .suite = {
  1973. .cipher = {
  1974. .enc = {
  1975. .vecs = aes_enc_tv_template,
  1976. .count = AES_ENC_TEST_VECTORS
  1977. },
  1978. .dec = {
  1979. .vecs = aes_dec_tv_template,
  1980. .count = AES_DEC_TEST_VECTORS
  1981. }
  1982. }
  1983. }
  1984. }, {
  1985. .alg = "ecb(anubis)",
  1986. .test = alg_test_skcipher,
  1987. .suite = {
  1988. .cipher = {
  1989. .enc = {
  1990. .vecs = anubis_enc_tv_template,
  1991. .count = ANUBIS_ENC_TEST_VECTORS
  1992. },
  1993. .dec = {
  1994. .vecs = anubis_dec_tv_template,
  1995. .count = ANUBIS_DEC_TEST_VECTORS
  1996. }
  1997. }
  1998. }
  1999. }, {
  2000. .alg = "ecb(arc4)",
  2001. .test = alg_test_skcipher,
  2002. .suite = {
  2003. .cipher = {
  2004. .enc = {
  2005. .vecs = arc4_enc_tv_template,
  2006. .count = ARC4_ENC_TEST_VECTORS
  2007. },
  2008. .dec = {
  2009. .vecs = arc4_dec_tv_template,
  2010. .count = ARC4_DEC_TEST_VECTORS
  2011. }
  2012. }
  2013. }
  2014. }, {
  2015. .alg = "ecb(blowfish)",
  2016. .test = alg_test_skcipher,
  2017. .suite = {
  2018. .cipher = {
  2019. .enc = {
  2020. .vecs = bf_enc_tv_template,
  2021. .count = BF_ENC_TEST_VECTORS
  2022. },
  2023. .dec = {
  2024. .vecs = bf_dec_tv_template,
  2025. .count = BF_DEC_TEST_VECTORS
  2026. }
  2027. }
  2028. }
  2029. }, {
  2030. .alg = "ecb(camellia)",
  2031. .test = alg_test_skcipher,
  2032. .suite = {
  2033. .cipher = {
  2034. .enc = {
  2035. .vecs = camellia_enc_tv_template,
  2036. .count = CAMELLIA_ENC_TEST_VECTORS
  2037. },
  2038. .dec = {
  2039. .vecs = camellia_dec_tv_template,
  2040. .count = CAMELLIA_DEC_TEST_VECTORS
  2041. }
  2042. }
  2043. }
  2044. }, {
  2045. .alg = "ecb(cast5)",
  2046. .test = alg_test_skcipher,
  2047. .suite = {
  2048. .cipher = {
  2049. .enc = {
  2050. .vecs = cast5_enc_tv_template,
  2051. .count = CAST5_ENC_TEST_VECTORS
  2052. },
  2053. .dec = {
  2054. .vecs = cast5_dec_tv_template,
  2055. .count = CAST5_DEC_TEST_VECTORS
  2056. }
  2057. }
  2058. }
  2059. }, {
  2060. .alg = "ecb(cast6)",
  2061. .test = alg_test_skcipher,
  2062. .suite = {
  2063. .cipher = {
  2064. .enc = {
  2065. .vecs = cast6_enc_tv_template,
  2066. .count = CAST6_ENC_TEST_VECTORS
  2067. },
  2068. .dec = {
  2069. .vecs = cast6_dec_tv_template,
  2070. .count = CAST6_DEC_TEST_VECTORS
  2071. }
  2072. }
  2073. }
  2074. }, {
  2075. .alg = "ecb(des)",
  2076. .test = alg_test_skcipher,
  2077. .fips_allowed = 1,
  2078. .suite = {
  2079. .cipher = {
  2080. .enc = {
  2081. .vecs = des_enc_tv_template,
  2082. .count = DES_ENC_TEST_VECTORS
  2083. },
  2084. .dec = {
  2085. .vecs = des_dec_tv_template,
  2086. .count = DES_DEC_TEST_VECTORS
  2087. }
  2088. }
  2089. }
  2090. }, {
  2091. .alg = "ecb(des3_ede)",
  2092. .test = alg_test_skcipher,
  2093. .fips_allowed = 1,
  2094. .suite = {
  2095. .cipher = {
  2096. .enc = {
  2097. .vecs = des3_ede_enc_tv_template,
  2098. .count = DES3_EDE_ENC_TEST_VECTORS
  2099. },
  2100. .dec = {
  2101. .vecs = des3_ede_dec_tv_template,
  2102. .count = DES3_EDE_DEC_TEST_VECTORS
  2103. }
  2104. }
  2105. }
  2106. }, {
  2107. .alg = "ecb(khazad)",
  2108. .test = alg_test_skcipher,
  2109. .suite = {
  2110. .cipher = {
  2111. .enc = {
  2112. .vecs = khazad_enc_tv_template,
  2113. .count = KHAZAD_ENC_TEST_VECTORS
  2114. },
  2115. .dec = {
  2116. .vecs = khazad_dec_tv_template,
  2117. .count = KHAZAD_DEC_TEST_VECTORS
  2118. }
  2119. }
  2120. }
  2121. }, {
  2122. .alg = "ecb(seed)",
  2123. .test = alg_test_skcipher,
  2124. .suite = {
  2125. .cipher = {
  2126. .enc = {
  2127. .vecs = seed_enc_tv_template,
  2128. .count = SEED_ENC_TEST_VECTORS
  2129. },
  2130. .dec = {
  2131. .vecs = seed_dec_tv_template,
  2132. .count = SEED_DEC_TEST_VECTORS
  2133. }
  2134. }
  2135. }
  2136. }, {
  2137. .alg = "ecb(serpent)",
  2138. .test = alg_test_skcipher,
  2139. .suite = {
  2140. .cipher = {
  2141. .enc = {
  2142. .vecs = serpent_enc_tv_template,
  2143. .count = SERPENT_ENC_TEST_VECTORS
  2144. },
  2145. .dec = {
  2146. .vecs = serpent_dec_tv_template,
  2147. .count = SERPENT_DEC_TEST_VECTORS
  2148. }
  2149. }
  2150. }
  2151. }, {
  2152. .alg = "ecb(tea)",
  2153. .test = alg_test_skcipher,
  2154. .suite = {
  2155. .cipher = {
  2156. .enc = {
  2157. .vecs = tea_enc_tv_template,
  2158. .count = TEA_ENC_TEST_VECTORS
  2159. },
  2160. .dec = {
  2161. .vecs = tea_dec_tv_template,
  2162. .count = TEA_DEC_TEST_VECTORS
  2163. }
  2164. }
  2165. }
  2166. }, {
  2167. .alg = "ecb(tnepres)",
  2168. .test = alg_test_skcipher,
  2169. .suite = {
  2170. .cipher = {
  2171. .enc = {
  2172. .vecs = tnepres_enc_tv_template,
  2173. .count = TNEPRES_ENC_TEST_VECTORS
  2174. },
  2175. .dec = {
  2176. .vecs = tnepres_dec_tv_template,
  2177. .count = TNEPRES_DEC_TEST_VECTORS
  2178. }
  2179. }
  2180. }
  2181. }, {
  2182. .alg = "ecb(twofish)",
  2183. .test = alg_test_skcipher,
  2184. .suite = {
  2185. .cipher = {
  2186. .enc = {
  2187. .vecs = tf_enc_tv_template,
  2188. .count = TF_ENC_TEST_VECTORS
  2189. },
  2190. .dec = {
  2191. .vecs = tf_dec_tv_template,
  2192. .count = TF_DEC_TEST_VECTORS
  2193. }
  2194. }
  2195. }
  2196. }, {
  2197. .alg = "ecb(xeta)",
  2198. .test = alg_test_skcipher,
  2199. .suite = {
  2200. .cipher = {
  2201. .enc = {
  2202. .vecs = xeta_enc_tv_template,
  2203. .count = XETA_ENC_TEST_VECTORS
  2204. },
  2205. .dec = {
  2206. .vecs = xeta_dec_tv_template,
  2207. .count = XETA_DEC_TEST_VECTORS
  2208. }
  2209. }
  2210. }
  2211. }, {
  2212. .alg = "ecb(xtea)",
  2213. .test = alg_test_skcipher,
  2214. .suite = {
  2215. .cipher = {
  2216. .enc = {
  2217. .vecs = xtea_enc_tv_template,
  2218. .count = XTEA_ENC_TEST_VECTORS
  2219. },
  2220. .dec = {
  2221. .vecs = xtea_dec_tv_template,
  2222. .count = XTEA_DEC_TEST_VECTORS
  2223. }
  2224. }
  2225. }
  2226. }, {
  2227. .alg = "gcm(aes)",
  2228. .test = alg_test_aead,
  2229. .fips_allowed = 1,
  2230. .suite = {
  2231. .aead = {
  2232. .enc = {
  2233. .vecs = aes_gcm_enc_tv_template,
  2234. .count = AES_GCM_ENC_TEST_VECTORS
  2235. },
  2236. .dec = {
  2237. .vecs = aes_gcm_dec_tv_template,
  2238. .count = AES_GCM_DEC_TEST_VECTORS
  2239. }
  2240. }
  2241. }
  2242. }, {
  2243. .alg = "ghash",
  2244. .test = alg_test_hash,
  2245. .fips_allowed = 1,
  2246. .suite = {
  2247. .hash = {
  2248. .vecs = ghash_tv_template,
  2249. .count = GHASH_TEST_VECTORS
  2250. }
  2251. }
  2252. }, {
  2253. .alg = "hmac(md5)",
  2254. .test = alg_test_hash,
  2255. .suite = {
  2256. .hash = {
  2257. .vecs = hmac_md5_tv_template,
  2258. .count = HMAC_MD5_TEST_VECTORS
  2259. }
  2260. }
  2261. }, {
  2262. .alg = "hmac(rmd128)",
  2263. .test = alg_test_hash,
  2264. .suite = {
  2265. .hash = {
  2266. .vecs = hmac_rmd128_tv_template,
  2267. .count = HMAC_RMD128_TEST_VECTORS
  2268. }
  2269. }
  2270. }, {
  2271. .alg = "hmac(rmd160)",
  2272. .test = alg_test_hash,
  2273. .suite = {
  2274. .hash = {
  2275. .vecs = hmac_rmd160_tv_template,
  2276. .count = HMAC_RMD160_TEST_VECTORS
  2277. }
  2278. }
  2279. }, {
  2280. .alg = "hmac(sha1)",
  2281. .test = alg_test_hash,
  2282. .fips_allowed = 1,
  2283. .suite = {
  2284. .hash = {
  2285. .vecs = hmac_sha1_tv_template,
  2286. .count = HMAC_SHA1_TEST_VECTORS
  2287. }
  2288. }
  2289. }, {
  2290. .alg = "hmac(sha224)",
  2291. .test = alg_test_hash,
  2292. .fips_allowed = 1,
  2293. .suite = {
  2294. .hash = {
  2295. .vecs = hmac_sha224_tv_template,
  2296. .count = HMAC_SHA224_TEST_VECTORS
  2297. }
  2298. }
  2299. }, {
  2300. .alg = "hmac(sha256)",
  2301. .test = alg_test_hash,
  2302. .fips_allowed = 1,
  2303. .suite = {
  2304. .hash = {
  2305. .vecs = hmac_sha256_tv_template,
  2306. .count = HMAC_SHA256_TEST_VECTORS
  2307. }
  2308. }
  2309. }, {
  2310. .alg = "hmac(sha384)",
  2311. .test = alg_test_hash,
  2312. .fips_allowed = 1,
  2313. .suite = {
  2314. .hash = {
  2315. .vecs = hmac_sha384_tv_template,
  2316. .count = HMAC_SHA384_TEST_VECTORS
  2317. }
  2318. }
  2319. }, {
  2320. .alg = "hmac(sha512)",
  2321. .test = alg_test_hash,
  2322. .fips_allowed = 1,
  2323. .suite = {
  2324. .hash = {
  2325. .vecs = hmac_sha512_tv_template,
  2326. .count = HMAC_SHA512_TEST_VECTORS
  2327. }
  2328. }
  2329. }, {
  2330. .alg = "lrw(aes)",
  2331. .test = alg_test_skcipher,
  2332. .suite = {
  2333. .cipher = {
  2334. .enc = {
  2335. .vecs = aes_lrw_enc_tv_template,
  2336. .count = AES_LRW_ENC_TEST_VECTORS
  2337. },
  2338. .dec = {
  2339. .vecs = aes_lrw_dec_tv_template,
  2340. .count = AES_LRW_DEC_TEST_VECTORS
  2341. }
  2342. }
  2343. }
  2344. }, {
  2345. .alg = "lrw(camellia)",
  2346. .test = alg_test_skcipher,
  2347. .suite = {
  2348. .cipher = {
  2349. .enc = {
  2350. .vecs = camellia_lrw_enc_tv_template,
  2351. .count = CAMELLIA_LRW_ENC_TEST_VECTORS
  2352. },
  2353. .dec = {
  2354. .vecs = camellia_lrw_dec_tv_template,
  2355. .count = CAMELLIA_LRW_DEC_TEST_VECTORS
  2356. }
  2357. }
  2358. }
  2359. }, {
  2360. .alg = "lrw(serpent)",
  2361. .test = alg_test_skcipher,
  2362. .suite = {
  2363. .cipher = {
  2364. .enc = {
  2365. .vecs = serpent_lrw_enc_tv_template,
  2366. .count = SERPENT_LRW_ENC_TEST_VECTORS
  2367. },
  2368. .dec = {
  2369. .vecs = serpent_lrw_dec_tv_template,
  2370. .count = SERPENT_LRW_DEC_TEST_VECTORS
  2371. }
  2372. }
  2373. }
  2374. }, {
  2375. .alg = "lrw(twofish)",
  2376. .test = alg_test_skcipher,
  2377. .suite = {
  2378. .cipher = {
  2379. .enc = {
  2380. .vecs = tf_lrw_enc_tv_template,
  2381. .count = TF_LRW_ENC_TEST_VECTORS
  2382. },
  2383. .dec = {
  2384. .vecs = tf_lrw_dec_tv_template,
  2385. .count = TF_LRW_DEC_TEST_VECTORS
  2386. }
  2387. }
  2388. }
  2389. }, {
  2390. .alg = "lz4",
  2391. .test = alg_test_comp,
  2392. .fips_allowed = 1,
  2393. .suite = {
  2394. .comp = {
  2395. .comp = {
  2396. .vecs = lz4_comp_tv_template,
  2397. .count = LZ4_COMP_TEST_VECTORS
  2398. },
  2399. .decomp = {
  2400. .vecs = lz4_decomp_tv_template,
  2401. .count = LZ4_DECOMP_TEST_VECTORS
  2402. }
  2403. }
  2404. }
  2405. }, {
  2406. .alg = "lz4hc",
  2407. .test = alg_test_comp,
  2408. .fips_allowed = 1,
  2409. .suite = {
  2410. .comp = {
  2411. .comp = {
  2412. .vecs = lz4hc_comp_tv_template,
  2413. .count = LZ4HC_COMP_TEST_VECTORS
  2414. },
  2415. .decomp = {
  2416. .vecs = lz4hc_decomp_tv_template,
  2417. .count = LZ4HC_DECOMP_TEST_VECTORS
  2418. }
  2419. }
  2420. }
  2421. }, {
  2422. .alg = "lzo",
  2423. .test = alg_test_comp,
  2424. .suite = {
  2425. .comp = {
  2426. .comp = {
  2427. .vecs = lzo_comp_tv_template,
  2428. .count = LZO_COMP_TEST_VECTORS
  2429. },
  2430. .decomp = {
  2431. .vecs = lzo_decomp_tv_template,
  2432. .count = LZO_DECOMP_TEST_VECTORS
  2433. }
  2434. }
  2435. }
  2436. }, {
  2437. .alg = "md4",
  2438. .test = alg_test_hash,
  2439. .suite = {
  2440. .hash = {
  2441. .vecs = md4_tv_template,
  2442. .count = MD4_TEST_VECTORS
  2443. }
  2444. }
  2445. }, {
  2446. .alg = "md5",
  2447. .test = alg_test_hash,
  2448. .suite = {
  2449. .hash = {
  2450. .vecs = md5_tv_template,
  2451. .count = MD5_TEST_VECTORS
  2452. }
  2453. }
  2454. }, {
  2455. .alg = "michael_mic",
  2456. .test = alg_test_hash,
  2457. .suite = {
  2458. .hash = {
  2459. .vecs = michael_mic_tv_template,
  2460. .count = MICHAEL_MIC_TEST_VECTORS
  2461. }
  2462. }
  2463. }, {
  2464. .alg = "ofb(aes)",
  2465. .test = alg_test_skcipher,
  2466. .fips_allowed = 1,
  2467. .suite = {
  2468. .cipher = {
  2469. .enc = {
  2470. .vecs = aes_ofb_enc_tv_template,
  2471. .count = AES_OFB_ENC_TEST_VECTORS
  2472. },
  2473. .dec = {
  2474. .vecs = aes_ofb_dec_tv_template,
  2475. .count = AES_OFB_DEC_TEST_VECTORS
  2476. }
  2477. }
  2478. }
  2479. }, {
  2480. .alg = "pcbc(fcrypt)",
  2481. .test = alg_test_skcipher,
  2482. .suite = {
  2483. .cipher = {
  2484. .enc = {
  2485. .vecs = fcrypt_pcbc_enc_tv_template,
  2486. .count = FCRYPT_ENC_TEST_VECTORS
  2487. },
  2488. .dec = {
  2489. .vecs = fcrypt_pcbc_dec_tv_template,
  2490. .count = FCRYPT_DEC_TEST_VECTORS
  2491. }
  2492. }
  2493. }
  2494. }, {
  2495. .alg = "rfc3686(ctr(aes))",
  2496. .test = alg_test_skcipher,
  2497. .fips_allowed = 1,
  2498. .suite = {
  2499. .cipher = {
  2500. .enc = {
  2501. .vecs = aes_ctr_rfc3686_enc_tv_template,
  2502. .count = AES_CTR_3686_ENC_TEST_VECTORS
  2503. },
  2504. .dec = {
  2505. .vecs = aes_ctr_rfc3686_dec_tv_template,
  2506. .count = AES_CTR_3686_DEC_TEST_VECTORS
  2507. }
  2508. }
  2509. }
  2510. }, {
  2511. .alg = "rfc4106(gcm(aes))",
  2512. .test = alg_test_aead,
  2513. .suite = {
  2514. .aead = {
  2515. .enc = {
  2516. .vecs = aes_gcm_rfc4106_enc_tv_template,
  2517. .count = AES_GCM_4106_ENC_TEST_VECTORS
  2518. },
  2519. .dec = {
  2520. .vecs = aes_gcm_rfc4106_dec_tv_template,
  2521. .count = AES_GCM_4106_DEC_TEST_VECTORS
  2522. }
  2523. }
  2524. }
  2525. }, {
  2526. .alg = "rfc4309(ccm(aes))",
  2527. .test = alg_test_aead,
  2528. .fips_allowed = 1,
  2529. .suite = {
  2530. .aead = {
  2531. .enc = {
  2532. .vecs = aes_ccm_rfc4309_enc_tv_template,
  2533. .count = AES_CCM_4309_ENC_TEST_VECTORS
  2534. },
  2535. .dec = {
  2536. .vecs = aes_ccm_rfc4309_dec_tv_template,
  2537. .count = AES_CCM_4309_DEC_TEST_VECTORS
  2538. }
  2539. }
  2540. }
  2541. }, {
  2542. .alg = "rmd128",
  2543. .test = alg_test_hash,
  2544. .suite = {
  2545. .hash = {
  2546. .vecs = rmd128_tv_template,
  2547. .count = RMD128_TEST_VECTORS
  2548. }
  2549. }
  2550. }, {
  2551. .alg = "rmd160",
  2552. .test = alg_test_hash,
  2553. .suite = {
  2554. .hash = {
  2555. .vecs = rmd160_tv_template,
  2556. .count = RMD160_TEST_VECTORS
  2557. }
  2558. }
  2559. }, {
  2560. .alg = "rmd256",
  2561. .test = alg_test_hash,
  2562. .suite = {
  2563. .hash = {
  2564. .vecs = rmd256_tv_template,
  2565. .count = RMD256_TEST_VECTORS
  2566. }
  2567. }
  2568. }, {
  2569. .alg = "rmd320",
  2570. .test = alg_test_hash,
  2571. .suite = {
  2572. .hash = {
  2573. .vecs = rmd320_tv_template,
  2574. .count = RMD320_TEST_VECTORS
  2575. }
  2576. }
  2577. }, {
  2578. .alg = "salsa20",
  2579. .test = alg_test_skcipher,
  2580. .suite = {
  2581. .cipher = {
  2582. .enc = {
  2583. .vecs = salsa20_stream_enc_tv_template,
  2584. .count = SALSA20_STREAM_ENC_TEST_VECTORS
  2585. }
  2586. }
  2587. }
  2588. }, {
  2589. .alg = "sha1",
  2590. .test = alg_test_hash,
  2591. .fips_allowed = 1,
  2592. .suite = {
  2593. .hash = {
  2594. .vecs = sha1_tv_template,
  2595. .count = SHA1_TEST_VECTORS
  2596. }
  2597. }
  2598. }, {
  2599. .alg = "sha224",
  2600. .test = alg_test_hash,
  2601. .fips_allowed = 1,
  2602. .suite = {
  2603. .hash = {
  2604. .vecs = sha224_tv_template,
  2605. .count = SHA224_TEST_VECTORS
  2606. }
  2607. }
  2608. }, {
  2609. .alg = "sha256",
  2610. .test = alg_test_hash,
  2611. .fips_allowed = 1,
  2612. .suite = {
  2613. .hash = {
  2614. .vecs = sha256_tv_template,
  2615. .count = SHA256_TEST_VECTORS
  2616. }
  2617. }
  2618. }, {
  2619. .alg = "sha384",
  2620. .test = alg_test_hash,
  2621. .fips_allowed = 1,
  2622. .suite = {
  2623. .hash = {
  2624. .vecs = sha384_tv_template,
  2625. .count = SHA384_TEST_VECTORS
  2626. }
  2627. }
  2628. }, {
  2629. .alg = "sha512",
  2630. .test = alg_test_hash,
  2631. .fips_allowed = 1,
  2632. .suite = {
  2633. .hash = {
  2634. .vecs = sha512_tv_template,
  2635. .count = SHA512_TEST_VECTORS
  2636. }
  2637. }
  2638. }, {
  2639. .alg = "tgr128",
  2640. .test = alg_test_hash,
  2641. .suite = {
  2642. .hash = {
  2643. .vecs = tgr128_tv_template,
  2644. .count = TGR128_TEST_VECTORS
  2645. }
  2646. }
  2647. }, {
  2648. .alg = "tgr160",
  2649. .test = alg_test_hash,
  2650. .suite = {
  2651. .hash = {
  2652. .vecs = tgr160_tv_template,
  2653. .count = TGR160_TEST_VECTORS
  2654. }
  2655. }
  2656. }, {
  2657. .alg = "tgr192",
  2658. .test = alg_test_hash,
  2659. .suite = {
  2660. .hash = {
  2661. .vecs = tgr192_tv_template,
  2662. .count = TGR192_TEST_VECTORS
  2663. }
  2664. }
  2665. }, {
  2666. .alg = "vmac(aes)",
  2667. .test = alg_test_hash,
  2668. .suite = {
  2669. .hash = {
  2670. .vecs = aes_vmac128_tv_template,
  2671. .count = VMAC_AES_TEST_VECTORS
  2672. }
  2673. }
  2674. }, {
  2675. .alg = "wp256",
  2676. .test = alg_test_hash,
  2677. .suite = {
  2678. .hash = {
  2679. .vecs = wp256_tv_template,
  2680. .count = WP256_TEST_VECTORS
  2681. }
  2682. }
  2683. }, {
  2684. .alg = "wp384",
  2685. .test = alg_test_hash,
  2686. .suite = {
  2687. .hash = {
  2688. .vecs = wp384_tv_template,
  2689. .count = WP384_TEST_VECTORS
  2690. }
  2691. }
  2692. }, {
  2693. .alg = "wp512",
  2694. .test = alg_test_hash,
  2695. .suite = {
  2696. .hash = {
  2697. .vecs = wp512_tv_template,
  2698. .count = WP512_TEST_VECTORS
  2699. }
  2700. }
  2701. }, {
  2702. .alg = "xcbc(aes)",
  2703. .test = alg_test_hash,
  2704. .suite = {
  2705. .hash = {
  2706. .vecs = aes_xcbc128_tv_template,
  2707. .count = XCBC_AES_TEST_VECTORS
  2708. }
  2709. }
  2710. }, {
  2711. .alg = "xts(aes)",
  2712. .test = alg_test_skcipher,
  2713. .fips_allowed = 1,
  2714. .suite = {
  2715. .cipher = {
  2716. .enc = {
  2717. .vecs = aes_xts_enc_tv_template,
  2718. .count = AES_XTS_ENC_TEST_VECTORS
  2719. },
  2720. .dec = {
  2721. .vecs = aes_xts_dec_tv_template,
  2722. .count = AES_XTS_DEC_TEST_VECTORS
  2723. }
  2724. }
  2725. }
  2726. }, {
  2727. .alg = "xts(camellia)",
  2728. .test = alg_test_skcipher,
  2729. .suite = {
  2730. .cipher = {
  2731. .enc = {
  2732. .vecs = camellia_xts_enc_tv_template,
  2733. .count = CAMELLIA_XTS_ENC_TEST_VECTORS
  2734. },
  2735. .dec = {
  2736. .vecs = camellia_xts_dec_tv_template,
  2737. .count = CAMELLIA_XTS_DEC_TEST_VECTORS
  2738. }
  2739. }
  2740. }
  2741. }, {
  2742. .alg = "xts(serpent)",
  2743. .test = alg_test_skcipher,
  2744. .suite = {
  2745. .cipher = {
  2746. .enc = {
  2747. .vecs = serpent_xts_enc_tv_template,
  2748. .count = SERPENT_XTS_ENC_TEST_VECTORS
  2749. },
  2750. .dec = {
  2751. .vecs = serpent_xts_dec_tv_template,
  2752. .count = SERPENT_XTS_DEC_TEST_VECTORS
  2753. }
  2754. }
  2755. }
  2756. }, {
  2757. .alg = "xts(twofish)",
  2758. .test = alg_test_skcipher,
  2759. .suite = {
  2760. .cipher = {
  2761. .enc = {
  2762. .vecs = tf_xts_enc_tv_template,
  2763. .count = TF_XTS_ENC_TEST_VECTORS
  2764. },
  2765. .dec = {
  2766. .vecs = tf_xts_dec_tv_template,
  2767. .count = TF_XTS_DEC_TEST_VECTORS
  2768. }
  2769. }
  2770. }
  2771. }, {
  2772. .alg = "zlib",
  2773. .test = alg_test_pcomp,
  2774. .suite = {
  2775. .pcomp = {
  2776. .comp = {
  2777. .vecs = zlib_comp_tv_template,
  2778. .count = ZLIB_COMP_TEST_VECTORS
  2779. },
  2780. .decomp = {
  2781. .vecs = zlib_decomp_tv_template,
  2782. .count = ZLIB_DECOMP_TEST_VECTORS
  2783. }
  2784. }
  2785. }
  2786. }
  2787. };
  2788. static int alg_find_test(const char *alg)
  2789. {
  2790. int start = 0;
  2791. int end = ARRAY_SIZE(alg_test_descs);
  2792. while (start < end) {
  2793. int i = (start + end) / 2;
  2794. int diff = strcmp(alg_test_descs[i].alg, alg);
  2795. if (diff > 0) {
  2796. end = i;
  2797. continue;
  2798. }
  2799. if (diff < 0) {
  2800. start = i + 1;
  2801. continue;
  2802. }
  2803. return i;
  2804. }
  2805. return -1;
  2806. }
  2807. int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
  2808. {
  2809. int i;
  2810. int j;
  2811. int rc = 0;
  2812. if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
  2813. char nalg[CRYPTO_MAX_ALG_NAME];
  2814. if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
  2815. sizeof(nalg))
  2816. return -ENAMETOOLONG;
  2817. i = alg_find_test(nalg);
  2818. if (i < 0)
  2819. goto notest;
  2820. if (fips_enabled && !alg_test_descs[i].fips_allowed)
  2821. goto non_fips_alg;
  2822. rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
  2823. goto test_done;
  2824. }
  2825. i = alg_find_test(alg);
  2826. j = alg_find_test(driver);
  2827. if (i < 0 && j < 0)
  2828. goto notest;
  2829. #if FIPS_FUNC_TEST == 3
  2830. // change@wtl.rsengott - FIPS mode self test Functional Test
  2831. if (fips_enabled)
  2832. printk(KERN_INFO "FIPS: %s: %s alg self test START in fips mode!\n",
  2833. driver, alg);
  2834. #endif
  2835. if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
  2836. (j >= 0 && !alg_test_descs[j].fips_allowed)))
  2837. goto non_fips_alg;
  2838. rc = 0;
  2839. if (i >= 0)
  2840. rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
  2841. type, mask);
  2842. if (j >= 0)
  2843. rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
  2844. type, mask);
  2845. test_done:
  2846. if (fips_enabled && rc) {
  2847. printk(KERN_INFO
  2848. "FIPS: %s: %s alg self test failed\n",
  2849. driver, alg);
  2850. #ifdef CONFIG_CRYPTO_FIPS
  2851. IN_FIPS_ERROR = FIPS_ERR;
  2852. #else
  2853. panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
  2854. #endif
  2855. return rc;
  2856. }
  2857. if (fips_enabled && !rc)
  2858. printk(KERN_INFO "FIPS: self-tests for %s (%s) passed\n",
  2859. driver, alg);
  2860. return rc;
  2861. notest:
  2862. printk(KERN_INFO "FIPS: No test for %s (%s)\n", alg, driver);
  2863. return 0;
  2864. non_fips_alg:
  2865. if (!rc)
  2866. printk(KERN_INFO
  2867. "FIPS: self-tests for non-FIPS %s (%s) passed\n",
  2868. driver, alg);
  2869. else
  2870. printk(KERN_INFO
  2871. "FIPS: self-tests for non-FIPS %s (%s) failed\n",
  2872. alg, driver);
  2873. return rc;
  2874. }
  2875. int testmgr_crypto_proc_init(void)
  2876. {
  2877. #ifdef CONFIG_CRYPTO_FIPS
  2878. crypto_init_proc(&IN_FIPS_ERROR);
  2879. #else
  2880. crypto_init_proc();
  2881. #endif
  2882. return 0;
  2883. }
  2884. #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
  2885. EXPORT_SYMBOL_GPL(alg_test);