testmgr.c 66 KB

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