tcrypt.c 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631
  1. /*
  2. * Quick & dirty crypto testing module.
  3. *
  4. * This will only exist until we have a better testing mechanism
  5. * (e.g. a char device).
  6. *
  7. * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
  8. * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
  9. * Copyright (c) 2007 Nokia Siemens Networks
  10. *
  11. * Updated RFC4106 AES-GCM testing.
  12. * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
  13. * Adrian Hoban <adrian.hoban@intel.com>
  14. * Gabriele Paoloni <gabriele.paoloni@intel.com>
  15. * Tadeusz Struk (tadeusz.struk@intel.com)
  16. * Copyright (c) 2010, Intel Corporation.
  17. *
  18. * This program is free software; you can redistribute it and/or modify it
  19. * under the terms of the GNU General Public License as published by the Free
  20. * Software Foundation; either version 2 of the License, or (at your option)
  21. * any later version.
  22. *
  23. */
  24. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  25. #include <crypto/aead.h>
  26. #include <crypto/hash.h>
  27. #include <crypto/skcipher.h>
  28. #include <linux/err.h>
  29. #include <linux/fips.h>
  30. #include <linux/init.h>
  31. #include <linux/gfp.h>
  32. #include <linux/module.h>
  33. #include <linux/scatterlist.h>
  34. #include <linux/string.h>
  35. #include <linux/moduleparam.h>
  36. #include <linux/jiffies.h>
  37. #include <linux/timex.h>
  38. #include <linux/interrupt.h>
  39. #include "tcrypt.h"
  40. /*
  41. * Need slab memory for testing (size in number of pages).
  42. */
  43. #define TVMEMSIZE 4
  44. /*
  45. * Used by test_cipher_speed()
  46. */
  47. #define ENCRYPT 1
  48. #define DECRYPT 0
  49. #define MAX_DIGEST_SIZE 64
  50. /*
  51. * return a string with the driver name
  52. */
  53. #define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm))
  54. /*
  55. * Used by test_cipher_speed()
  56. */
  57. static unsigned int sec;
  58. static char *alg = NULL;
  59. static u32 type;
  60. static u32 mask;
  61. static int mode;
  62. static u32 num_mb = 8;
  63. static char *tvmem[TVMEMSIZE];
  64. static char *check[] = {
  65. "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", "sm3",
  66. "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
  67. "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
  68. "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
  69. "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
  70. "lzo", "cts", "zlib", "sha3-224", "sha3-256", "sha3-384", "sha3-512",
  71. NULL
  72. };
  73. static inline int do_one_aead_op(struct aead_request *req, int ret)
  74. {
  75. struct crypto_wait *wait = req->base.data;
  76. return crypto_wait_req(ret, wait);
  77. }
  78. static int test_aead_jiffies(struct aead_request *req, int enc,
  79. int blen, int secs)
  80. {
  81. unsigned long start, end;
  82. int bcount;
  83. int ret;
  84. for (start = jiffies, end = start + secs * HZ, bcount = 0;
  85. time_before(jiffies, end); bcount++) {
  86. if (enc)
  87. ret = do_one_aead_op(req, crypto_aead_encrypt(req));
  88. else
  89. ret = do_one_aead_op(req, crypto_aead_decrypt(req));
  90. if (ret)
  91. return ret;
  92. }
  93. printk("%d operations in %d seconds (%ld bytes)\n",
  94. bcount, secs, (long)bcount * blen);
  95. return 0;
  96. }
  97. static int test_aead_cycles(struct aead_request *req, int enc, int blen)
  98. {
  99. unsigned long cycles = 0;
  100. int ret = 0;
  101. int i;
  102. /* Warm-up run. */
  103. for (i = 0; i < 4; i++) {
  104. if (enc)
  105. ret = do_one_aead_op(req, crypto_aead_encrypt(req));
  106. else
  107. ret = do_one_aead_op(req, crypto_aead_decrypt(req));
  108. if (ret)
  109. goto out;
  110. }
  111. /* The real thing. */
  112. for (i = 0; i < 8; i++) {
  113. cycles_t start, end;
  114. start = get_cycles();
  115. if (enc)
  116. ret = do_one_aead_op(req, crypto_aead_encrypt(req));
  117. else
  118. ret = do_one_aead_op(req, crypto_aead_decrypt(req));
  119. end = get_cycles();
  120. if (ret)
  121. goto out;
  122. cycles += end - start;
  123. }
  124. out:
  125. if (ret == 0)
  126. printk("1 operation in %lu cycles (%d bytes)\n",
  127. (cycles + 4) / 8, blen);
  128. return ret;
  129. }
  130. static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
  131. static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
  132. #define XBUFSIZE 8
  133. #define MAX_IVLEN 32
  134. static int testmgr_alloc_buf(char *buf[XBUFSIZE])
  135. {
  136. int i;
  137. for (i = 0; i < XBUFSIZE; i++) {
  138. buf[i] = (void *)__get_free_page(GFP_KERNEL);
  139. if (!buf[i])
  140. goto err_free_buf;
  141. }
  142. return 0;
  143. err_free_buf:
  144. while (i-- > 0)
  145. free_page((unsigned long)buf[i]);
  146. return -ENOMEM;
  147. }
  148. static void testmgr_free_buf(char *buf[XBUFSIZE])
  149. {
  150. int i;
  151. for (i = 0; i < XBUFSIZE; i++)
  152. free_page((unsigned long)buf[i]);
  153. }
  154. static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],
  155. unsigned int buflen, const void *assoc,
  156. unsigned int aad_size)
  157. {
  158. int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
  159. int k, rem;
  160. if (np > XBUFSIZE) {
  161. rem = PAGE_SIZE;
  162. np = XBUFSIZE;
  163. } else {
  164. rem = buflen % PAGE_SIZE;
  165. }
  166. sg_init_table(sg, np + 1);
  167. sg_set_buf(&sg[0], assoc, aad_size);
  168. if (rem)
  169. np--;
  170. for (k = 0; k < np; k++)
  171. sg_set_buf(&sg[k + 1], xbuf[k], PAGE_SIZE);
  172. if (rem)
  173. sg_set_buf(&sg[k + 1], xbuf[k], rem);
  174. }
  175. static void test_aead_speed(const char *algo, int enc, unsigned int secs,
  176. struct aead_speed_template *template,
  177. unsigned int tcount, u8 authsize,
  178. unsigned int aad_size, u8 *keysize)
  179. {
  180. unsigned int i, j;
  181. struct crypto_aead *tfm;
  182. int ret = -ENOMEM;
  183. const char *key;
  184. struct aead_request *req;
  185. struct scatterlist *sg;
  186. struct scatterlist *sgout;
  187. const char *e;
  188. void *assoc;
  189. char *iv;
  190. char *xbuf[XBUFSIZE];
  191. char *xoutbuf[XBUFSIZE];
  192. char *axbuf[XBUFSIZE];
  193. unsigned int *b_size;
  194. unsigned int iv_len;
  195. struct crypto_wait wait;
  196. iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
  197. if (!iv)
  198. return;
  199. if (aad_size >= PAGE_SIZE) {
  200. pr_err("associate data length (%u) too big\n", aad_size);
  201. goto out_noxbuf;
  202. }
  203. if (enc == ENCRYPT)
  204. e = "encryption";
  205. else
  206. e = "decryption";
  207. if (testmgr_alloc_buf(xbuf))
  208. goto out_noxbuf;
  209. if (testmgr_alloc_buf(axbuf))
  210. goto out_noaxbuf;
  211. if (testmgr_alloc_buf(xoutbuf))
  212. goto out_nooutbuf;
  213. sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL);
  214. if (!sg)
  215. goto out_nosg;
  216. sgout = &sg[9];
  217. tfm = crypto_alloc_aead(algo, 0, 0);
  218. if (IS_ERR(tfm)) {
  219. pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
  220. PTR_ERR(tfm));
  221. goto out_notfm;
  222. }
  223. crypto_init_wait(&wait);
  224. printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
  225. get_driver_name(crypto_aead, tfm), e);
  226. req = aead_request_alloc(tfm, GFP_KERNEL);
  227. if (!req) {
  228. pr_err("alg: aead: Failed to allocate request for %s\n",
  229. algo);
  230. goto out_noreq;
  231. }
  232. aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  233. crypto_req_done, &wait);
  234. i = 0;
  235. do {
  236. b_size = aead_sizes;
  237. do {
  238. assoc = axbuf[0];
  239. memset(assoc, 0xff, aad_size);
  240. if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
  241. pr_err("template (%u) too big for tvmem (%lu)\n",
  242. *keysize + *b_size,
  243. TVMEMSIZE * PAGE_SIZE);
  244. goto out;
  245. }
  246. key = tvmem[0];
  247. for (j = 0; j < tcount; j++) {
  248. if (template[j].klen == *keysize) {
  249. key = template[j].key;
  250. break;
  251. }
  252. }
  253. ret = crypto_aead_setkey(tfm, key, *keysize);
  254. ret = crypto_aead_setauthsize(tfm, authsize);
  255. iv_len = crypto_aead_ivsize(tfm);
  256. if (iv_len)
  257. memset(iv, 0xff, iv_len);
  258. crypto_aead_clear_flags(tfm, ~0);
  259. printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
  260. i, *keysize * 8, *b_size);
  261. memset(tvmem[0], 0xff, PAGE_SIZE);
  262. if (ret) {
  263. pr_err("setkey() failed flags=%x\n",
  264. crypto_aead_get_flags(tfm));
  265. goto out;
  266. }
  267. sg_init_aead(sg, xbuf, *b_size + (enc ? 0 : authsize),
  268. assoc, aad_size);
  269. sg_init_aead(sgout, xoutbuf,
  270. *b_size + (enc ? authsize : 0), assoc,
  271. aad_size);
  272. aead_request_set_ad(req, aad_size);
  273. if (!enc) {
  274. /*
  275. * For decryption we need a proper auth so
  276. * we do the encryption path once with buffers
  277. * reversed (input <-> output) to calculate it
  278. */
  279. aead_request_set_crypt(req, sgout, sg,
  280. *b_size, iv);
  281. ret = do_one_aead_op(req,
  282. crypto_aead_encrypt(req));
  283. if (ret) {
  284. pr_err("calculating auth failed failed (%d)\n",
  285. ret);
  286. break;
  287. }
  288. }
  289. aead_request_set_crypt(req, sg, sgout,
  290. *b_size + (enc ? 0 : authsize),
  291. iv);
  292. if (secs)
  293. ret = test_aead_jiffies(req, enc, *b_size,
  294. secs);
  295. else
  296. ret = test_aead_cycles(req, enc, *b_size);
  297. if (ret) {
  298. pr_err("%s() failed return code=%d\n", e, ret);
  299. break;
  300. }
  301. b_size++;
  302. i++;
  303. } while (*b_size);
  304. keysize++;
  305. } while (*keysize);
  306. out:
  307. aead_request_free(req);
  308. out_noreq:
  309. crypto_free_aead(tfm);
  310. out_notfm:
  311. kfree(sg);
  312. out_nosg:
  313. testmgr_free_buf(xoutbuf);
  314. out_nooutbuf:
  315. testmgr_free_buf(axbuf);
  316. out_noaxbuf:
  317. testmgr_free_buf(xbuf);
  318. out_noxbuf:
  319. kfree(iv);
  320. }
  321. static void test_hash_sg_init(struct scatterlist *sg)
  322. {
  323. int i;
  324. sg_init_table(sg, TVMEMSIZE);
  325. for (i = 0; i < TVMEMSIZE; i++) {
  326. sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
  327. memset(tvmem[i], 0xff, PAGE_SIZE);
  328. }
  329. }
  330. static inline int do_one_ahash_op(struct ahash_request *req, int ret)
  331. {
  332. struct crypto_wait *wait = req->base.data;
  333. return crypto_wait_req(ret, wait);
  334. }
  335. struct test_mb_ahash_data {
  336. struct scatterlist sg[XBUFSIZE];
  337. char result[64];
  338. struct ahash_request *req;
  339. struct crypto_wait wait;
  340. char *xbuf[XBUFSIZE];
  341. };
  342. static inline int do_mult_ahash_op(struct test_mb_ahash_data *data, u32 num_mb)
  343. {
  344. int i, rc[num_mb], err = 0;
  345. /* Fire up a bunch of concurrent requests */
  346. for (i = 0; i < num_mb; i++)
  347. rc[i] = crypto_ahash_digest(data[i].req);
  348. /* Wait for all requests to finish */
  349. for (i = 0; i < num_mb; i++) {
  350. rc[i] = crypto_wait_req(rc[i], &data[i].wait);
  351. if (rc[i]) {
  352. pr_info("concurrent request %d error %d\n", i, rc[i]);
  353. err = rc[i];
  354. }
  355. }
  356. return err;
  357. }
  358. static int test_mb_ahash_jiffies(struct test_mb_ahash_data *data, int blen,
  359. int secs, u32 num_mb)
  360. {
  361. unsigned long start, end;
  362. int bcount;
  363. int ret;
  364. for (start = jiffies, end = start + secs * HZ, bcount = 0;
  365. time_before(jiffies, end); bcount++) {
  366. ret = do_mult_ahash_op(data, num_mb);
  367. if (ret)
  368. return ret;
  369. }
  370. pr_cont("%d operations in %d seconds (%ld bytes)\n",
  371. bcount * num_mb, secs, (long)bcount * blen * num_mb);
  372. return 0;
  373. }
  374. static int test_mb_ahash_cycles(struct test_mb_ahash_data *data, int blen,
  375. u32 num_mb)
  376. {
  377. unsigned long cycles = 0;
  378. int ret = 0;
  379. int i;
  380. /* Warm-up run. */
  381. for (i = 0; i < 4; i++) {
  382. ret = do_mult_ahash_op(data, num_mb);
  383. if (ret)
  384. goto out;
  385. }
  386. /* The real thing. */
  387. for (i = 0; i < 8; i++) {
  388. cycles_t start, end;
  389. start = get_cycles();
  390. ret = do_mult_ahash_op(data, num_mb);
  391. end = get_cycles();
  392. if (ret)
  393. goto out;
  394. cycles += end - start;
  395. }
  396. out:
  397. if (ret == 0)
  398. pr_cont("1 operation in %lu cycles (%d bytes)\n",
  399. (cycles + 4) / (8 * num_mb), blen);
  400. return ret;
  401. }
  402. static void test_mb_ahash_speed(const char *algo, unsigned int secs,
  403. struct hash_speed *speed, u32 num_mb)
  404. {
  405. struct test_mb_ahash_data *data;
  406. struct crypto_ahash *tfm;
  407. unsigned int i, j, k;
  408. int ret;
  409. data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
  410. if (!data)
  411. return;
  412. tfm = crypto_alloc_ahash(algo, 0, 0);
  413. if (IS_ERR(tfm)) {
  414. pr_err("failed to load transform for %s: %ld\n",
  415. algo, PTR_ERR(tfm));
  416. goto free_data;
  417. }
  418. for (i = 0; i < num_mb; ++i) {
  419. if (testmgr_alloc_buf(data[i].xbuf))
  420. goto out;
  421. crypto_init_wait(&data[i].wait);
  422. data[i].req = ahash_request_alloc(tfm, GFP_KERNEL);
  423. if (!data[i].req) {
  424. pr_err("alg: hash: Failed to allocate request for %s\n",
  425. algo);
  426. goto out;
  427. }
  428. ahash_request_set_callback(data[i].req, 0, crypto_req_done,
  429. &data[i].wait);
  430. sg_init_table(data[i].sg, XBUFSIZE);
  431. for (j = 0; j < XBUFSIZE; j++) {
  432. sg_set_buf(data[i].sg + j, data[i].xbuf[j], PAGE_SIZE);
  433. memset(data[i].xbuf[j], 0xff, PAGE_SIZE);
  434. }
  435. }
  436. pr_info("\ntesting speed of multibuffer %s (%s)\n", algo,
  437. get_driver_name(crypto_ahash, tfm));
  438. for (i = 0; speed[i].blen != 0; i++) {
  439. /* For some reason this only tests digests. */
  440. if (speed[i].blen != speed[i].plen)
  441. continue;
  442. if (speed[i].blen > XBUFSIZE * PAGE_SIZE) {
  443. pr_err("template (%u) too big for tvmem (%lu)\n",
  444. speed[i].blen, XBUFSIZE * PAGE_SIZE);
  445. goto out;
  446. }
  447. if (speed[i].klen)
  448. crypto_ahash_setkey(tfm, tvmem[0], speed[i].klen);
  449. for (k = 0; k < num_mb; k++)
  450. ahash_request_set_crypt(data[k].req, data[k].sg,
  451. data[k].result, speed[i].blen);
  452. pr_info("test%3u "
  453. "(%5u byte blocks,%5u bytes per update,%4u updates): ",
  454. i, speed[i].blen, speed[i].plen,
  455. speed[i].blen / speed[i].plen);
  456. if (secs)
  457. ret = test_mb_ahash_jiffies(data, speed[i].blen, secs,
  458. num_mb);
  459. else
  460. ret = test_mb_ahash_cycles(data, speed[i].blen, num_mb);
  461. if (ret) {
  462. pr_err("At least one hashing failed ret=%d\n", ret);
  463. break;
  464. }
  465. }
  466. out:
  467. for (k = 0; k < num_mb; ++k)
  468. ahash_request_free(data[k].req);
  469. for (k = 0; k < num_mb; ++k)
  470. testmgr_free_buf(data[k].xbuf);
  471. crypto_free_ahash(tfm);
  472. free_data:
  473. kfree(data);
  474. }
  475. static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
  476. char *out, int secs)
  477. {
  478. unsigned long start, end;
  479. int bcount;
  480. int ret;
  481. for (start = jiffies, end = start + secs * HZ, bcount = 0;
  482. time_before(jiffies, end); bcount++) {
  483. ret = do_one_ahash_op(req, crypto_ahash_digest(req));
  484. if (ret)
  485. return ret;
  486. }
  487. printk("%6u opers/sec, %9lu bytes/sec\n",
  488. bcount / secs, ((long)bcount * blen) / secs);
  489. return 0;
  490. }
  491. static int test_ahash_jiffies(struct ahash_request *req, int blen,
  492. int plen, char *out, int secs)
  493. {
  494. unsigned long start, end;
  495. int bcount, pcount;
  496. int ret;
  497. if (plen == blen)
  498. return test_ahash_jiffies_digest(req, blen, out, secs);
  499. for (start = jiffies, end = start + secs * HZ, bcount = 0;
  500. time_before(jiffies, end); bcount++) {
  501. ret = do_one_ahash_op(req, crypto_ahash_init(req));
  502. if (ret)
  503. return ret;
  504. for (pcount = 0; pcount < blen; pcount += plen) {
  505. ret = do_one_ahash_op(req, crypto_ahash_update(req));
  506. if (ret)
  507. return ret;
  508. }
  509. /* we assume there is enough space in 'out' for the result */
  510. ret = do_one_ahash_op(req, crypto_ahash_final(req));
  511. if (ret)
  512. return ret;
  513. }
  514. pr_cont("%6u opers/sec, %9lu bytes/sec\n",
  515. bcount / secs, ((long)bcount * blen) / secs);
  516. return 0;
  517. }
  518. static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
  519. char *out)
  520. {
  521. unsigned long cycles = 0;
  522. int ret, i;
  523. /* Warm-up run. */
  524. for (i = 0; i < 4; i++) {
  525. ret = do_one_ahash_op(req, crypto_ahash_digest(req));
  526. if (ret)
  527. goto out;
  528. }
  529. /* The real thing. */
  530. for (i = 0; i < 8; i++) {
  531. cycles_t start, end;
  532. start = get_cycles();
  533. ret = do_one_ahash_op(req, crypto_ahash_digest(req));
  534. if (ret)
  535. goto out;
  536. end = get_cycles();
  537. cycles += end - start;
  538. }
  539. out:
  540. if (ret)
  541. return ret;
  542. pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
  543. cycles / 8, cycles / (8 * blen));
  544. return 0;
  545. }
  546. static int test_ahash_cycles(struct ahash_request *req, int blen,
  547. int plen, char *out)
  548. {
  549. unsigned long cycles = 0;
  550. int i, pcount, ret;
  551. if (plen == blen)
  552. return test_ahash_cycles_digest(req, blen, out);
  553. /* Warm-up run. */
  554. for (i = 0; i < 4; i++) {
  555. ret = do_one_ahash_op(req, crypto_ahash_init(req));
  556. if (ret)
  557. goto out;
  558. for (pcount = 0; pcount < blen; pcount += plen) {
  559. ret = do_one_ahash_op(req, crypto_ahash_update(req));
  560. if (ret)
  561. goto out;
  562. }
  563. ret = do_one_ahash_op(req, crypto_ahash_final(req));
  564. if (ret)
  565. goto out;
  566. }
  567. /* The real thing. */
  568. for (i = 0; i < 8; i++) {
  569. cycles_t start, end;
  570. start = get_cycles();
  571. ret = do_one_ahash_op(req, crypto_ahash_init(req));
  572. if (ret)
  573. goto out;
  574. for (pcount = 0; pcount < blen; pcount += plen) {
  575. ret = do_one_ahash_op(req, crypto_ahash_update(req));
  576. if (ret)
  577. goto out;
  578. }
  579. ret = do_one_ahash_op(req, crypto_ahash_final(req));
  580. if (ret)
  581. goto out;
  582. end = get_cycles();
  583. cycles += end - start;
  584. }
  585. out:
  586. if (ret)
  587. return ret;
  588. pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
  589. cycles / 8, cycles / (8 * blen));
  590. return 0;
  591. }
  592. static void test_ahash_speed_common(const char *algo, unsigned int secs,
  593. struct hash_speed *speed, unsigned mask)
  594. {
  595. struct scatterlist sg[TVMEMSIZE];
  596. struct crypto_wait wait;
  597. struct ahash_request *req;
  598. struct crypto_ahash *tfm;
  599. char *output;
  600. int i, ret;
  601. tfm = crypto_alloc_ahash(algo, 0, mask);
  602. if (IS_ERR(tfm)) {
  603. pr_err("failed to load transform for %s: %ld\n",
  604. algo, PTR_ERR(tfm));
  605. return;
  606. }
  607. printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
  608. get_driver_name(crypto_ahash, tfm));
  609. if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) {
  610. pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm),
  611. MAX_DIGEST_SIZE);
  612. goto out;
  613. }
  614. test_hash_sg_init(sg);
  615. req = ahash_request_alloc(tfm, GFP_KERNEL);
  616. if (!req) {
  617. pr_err("ahash request allocation failure\n");
  618. goto out;
  619. }
  620. crypto_init_wait(&wait);
  621. ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  622. crypto_req_done, &wait);
  623. output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
  624. if (!output)
  625. goto out_nomem;
  626. for (i = 0; speed[i].blen != 0; i++) {
  627. if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
  628. pr_err("template (%u) too big for tvmem (%lu)\n",
  629. speed[i].blen, TVMEMSIZE * PAGE_SIZE);
  630. break;
  631. }
  632. pr_info("test%3u "
  633. "(%5u byte blocks,%5u bytes per update,%4u updates): ",
  634. i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
  635. ahash_request_set_crypt(req, sg, output, speed[i].plen);
  636. if (secs)
  637. ret = test_ahash_jiffies(req, speed[i].blen,
  638. speed[i].plen, output, secs);
  639. else
  640. ret = test_ahash_cycles(req, speed[i].blen,
  641. speed[i].plen, output);
  642. if (ret) {
  643. pr_err("hashing failed ret=%d\n", ret);
  644. break;
  645. }
  646. }
  647. kfree(output);
  648. out_nomem:
  649. ahash_request_free(req);
  650. out:
  651. crypto_free_ahash(tfm);
  652. }
  653. static void test_ahash_speed(const char *algo, unsigned int secs,
  654. struct hash_speed *speed)
  655. {
  656. return test_ahash_speed_common(algo, secs, speed, 0);
  657. }
  658. static void test_hash_speed(const char *algo, unsigned int secs,
  659. struct hash_speed *speed)
  660. {
  661. return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC);
  662. }
  663. struct test_mb_skcipher_data {
  664. struct scatterlist sg[XBUFSIZE];
  665. struct skcipher_request *req;
  666. struct crypto_wait wait;
  667. char *xbuf[XBUFSIZE];
  668. };
  669. static int do_mult_acipher_op(struct test_mb_skcipher_data *data, int enc,
  670. u32 num_mb)
  671. {
  672. int i, rc[num_mb], err = 0;
  673. /* Fire up a bunch of concurrent requests */
  674. for (i = 0; i < num_mb; i++) {
  675. if (enc == ENCRYPT)
  676. rc[i] = crypto_skcipher_encrypt(data[i].req);
  677. else
  678. rc[i] = crypto_skcipher_decrypt(data[i].req);
  679. }
  680. /* Wait for all requests to finish */
  681. for (i = 0; i < num_mb; i++) {
  682. rc[i] = crypto_wait_req(rc[i], &data[i].wait);
  683. if (rc[i]) {
  684. pr_info("concurrent request %d error %d\n", i, rc[i]);
  685. err = rc[i];
  686. }
  687. }
  688. return err;
  689. }
  690. static int test_mb_acipher_jiffies(struct test_mb_skcipher_data *data, int enc,
  691. int blen, int secs, u32 num_mb)
  692. {
  693. unsigned long start, end;
  694. int bcount;
  695. int ret;
  696. for (start = jiffies, end = start + secs * HZ, bcount = 0;
  697. time_before(jiffies, end); bcount++) {
  698. ret = do_mult_acipher_op(data, enc, num_mb);
  699. if (ret)
  700. return ret;
  701. }
  702. pr_cont("%d operations in %d seconds (%ld bytes)\n",
  703. bcount * num_mb, secs, (long)bcount * blen * num_mb);
  704. return 0;
  705. }
  706. static int test_mb_acipher_cycles(struct test_mb_skcipher_data *data, int enc,
  707. int blen, u32 num_mb)
  708. {
  709. unsigned long cycles = 0;
  710. int ret = 0;
  711. int i;
  712. /* Warm-up run. */
  713. for (i = 0; i < 4; i++) {
  714. ret = do_mult_acipher_op(data, enc, num_mb);
  715. if (ret)
  716. goto out;
  717. }
  718. /* The real thing. */
  719. for (i = 0; i < 8; i++) {
  720. cycles_t start, end;
  721. start = get_cycles();
  722. ret = do_mult_acipher_op(data, enc, num_mb);
  723. end = get_cycles();
  724. if (ret)
  725. goto out;
  726. cycles += end - start;
  727. }
  728. out:
  729. if (ret == 0)
  730. pr_cont("1 operation in %lu cycles (%d bytes)\n",
  731. (cycles + 4) / (8 * num_mb), blen);
  732. return ret;
  733. }
  734. static void test_mb_skcipher_speed(const char *algo, int enc, int secs,
  735. struct cipher_speed_template *template,
  736. unsigned int tcount, u8 *keysize, u32 num_mb)
  737. {
  738. struct test_mb_skcipher_data *data;
  739. struct crypto_skcipher *tfm;
  740. unsigned int i, j, iv_len;
  741. const char *key;
  742. const char *e;
  743. u32 *b_size;
  744. char iv[128];
  745. int ret;
  746. if (enc == ENCRYPT)
  747. e = "encryption";
  748. else
  749. e = "decryption";
  750. data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
  751. if (!data)
  752. return;
  753. tfm = crypto_alloc_skcipher(algo, 0, 0);
  754. if (IS_ERR(tfm)) {
  755. pr_err("failed to load transform for %s: %ld\n",
  756. algo, PTR_ERR(tfm));
  757. goto out_free_data;
  758. }
  759. for (i = 0; i < num_mb; ++i)
  760. if (testmgr_alloc_buf(data[i].xbuf)) {
  761. while (i--)
  762. testmgr_free_buf(data[i].xbuf);
  763. goto out_free_tfm;
  764. }
  765. for (i = 0; i < num_mb; ++i)
  766. if (testmgr_alloc_buf(data[i].xbuf)) {
  767. while (i--)
  768. testmgr_free_buf(data[i].xbuf);
  769. goto out_free_tfm;
  770. }
  771. for (i = 0; i < num_mb; ++i) {
  772. data[i].req = skcipher_request_alloc(tfm, GFP_KERNEL);
  773. if (!data[i].req) {
  774. pr_err("alg: skcipher: Failed to allocate request for %s\n",
  775. algo);
  776. while (i--)
  777. skcipher_request_free(data[i].req);
  778. goto out_free_xbuf;
  779. }
  780. }
  781. for (i = 0; i < num_mb; ++i) {
  782. skcipher_request_set_callback(data[i].req,
  783. CRYPTO_TFM_REQ_MAY_BACKLOG,
  784. crypto_req_done, &data[i].wait);
  785. crypto_init_wait(&data[i].wait);
  786. }
  787. pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo,
  788. get_driver_name(crypto_skcipher, tfm), e);
  789. i = 0;
  790. do {
  791. b_size = block_sizes;
  792. do {
  793. if (*b_size > XBUFSIZE * PAGE_SIZE) {
  794. pr_err("template (%u) too big for bufufer (%lu)\n",
  795. *b_size, XBUFSIZE * PAGE_SIZE);
  796. goto out;
  797. }
  798. pr_info("test %u (%d bit key, %d byte blocks): ", i,
  799. *keysize * 8, *b_size);
  800. /* Set up tfm global state, i.e. the key */
  801. memset(tvmem[0], 0xff, PAGE_SIZE);
  802. key = tvmem[0];
  803. for (j = 0; j < tcount; j++) {
  804. if (template[j].klen == *keysize) {
  805. key = template[j].key;
  806. break;
  807. }
  808. }
  809. crypto_skcipher_clear_flags(tfm, ~0);
  810. ret = crypto_skcipher_setkey(tfm, key, *keysize);
  811. if (ret) {
  812. pr_err("setkey() failed flags=%x\n",
  813. crypto_skcipher_get_flags(tfm));
  814. goto out;
  815. }
  816. iv_len = crypto_skcipher_ivsize(tfm);
  817. if (iv_len)
  818. memset(&iv, 0xff, iv_len);
  819. /* Now setup per request stuff, i.e. buffers */
  820. for (j = 0; j < num_mb; ++j) {
  821. struct test_mb_skcipher_data *cur = &data[j];
  822. unsigned int k = *b_size;
  823. unsigned int pages = DIV_ROUND_UP(k, PAGE_SIZE);
  824. unsigned int p = 0;
  825. sg_init_table(cur->sg, pages);
  826. while (k > PAGE_SIZE) {
  827. sg_set_buf(cur->sg + p, cur->xbuf[p],
  828. PAGE_SIZE);
  829. memset(cur->xbuf[p], 0xff, PAGE_SIZE);
  830. p++;
  831. k -= PAGE_SIZE;
  832. }
  833. sg_set_buf(cur->sg + p, cur->xbuf[p], k);
  834. memset(cur->xbuf[p], 0xff, k);
  835. skcipher_request_set_crypt(cur->req, cur->sg,
  836. cur->sg, *b_size,
  837. iv);
  838. }
  839. if (secs)
  840. ret = test_mb_acipher_jiffies(data, enc,
  841. *b_size, secs,
  842. num_mb);
  843. else
  844. ret = test_mb_acipher_cycles(data, enc,
  845. *b_size, num_mb);
  846. if (ret) {
  847. pr_err("%s() failed flags=%x\n", e,
  848. crypto_skcipher_get_flags(tfm));
  849. break;
  850. }
  851. b_size++;
  852. i++;
  853. } while (*b_size);
  854. keysize++;
  855. } while (*keysize);
  856. out:
  857. for (i = 0; i < num_mb; ++i)
  858. skcipher_request_free(data[i].req);
  859. out_free_xbuf:
  860. for (i = 0; i < num_mb; ++i)
  861. testmgr_free_buf(data[i].xbuf);
  862. out_free_tfm:
  863. crypto_free_skcipher(tfm);
  864. out_free_data:
  865. kfree(data);
  866. }
  867. static inline int do_one_acipher_op(struct skcipher_request *req, int ret)
  868. {
  869. struct crypto_wait *wait = req->base.data;
  870. return crypto_wait_req(ret, wait);
  871. }
  872. static int test_acipher_jiffies(struct skcipher_request *req, int enc,
  873. int blen, int secs)
  874. {
  875. unsigned long start, end;
  876. int bcount;
  877. int ret;
  878. for (start = jiffies, end = start + secs * HZ, bcount = 0;
  879. time_before(jiffies, end); bcount++) {
  880. if (enc)
  881. ret = do_one_acipher_op(req,
  882. crypto_skcipher_encrypt(req));
  883. else
  884. ret = do_one_acipher_op(req,
  885. crypto_skcipher_decrypt(req));
  886. if (ret)
  887. return ret;
  888. }
  889. pr_cont("%d operations in %d seconds (%ld bytes)\n",
  890. bcount, secs, (long)bcount * blen);
  891. return 0;
  892. }
  893. static int test_acipher_cycles(struct skcipher_request *req, int enc,
  894. int blen)
  895. {
  896. unsigned long cycles = 0;
  897. int ret = 0;
  898. int i;
  899. /* Warm-up run. */
  900. for (i = 0; i < 4; i++) {
  901. if (enc)
  902. ret = do_one_acipher_op(req,
  903. crypto_skcipher_encrypt(req));
  904. else
  905. ret = do_one_acipher_op(req,
  906. crypto_skcipher_decrypt(req));
  907. if (ret)
  908. goto out;
  909. }
  910. /* The real thing. */
  911. for (i = 0; i < 8; i++) {
  912. cycles_t start, end;
  913. start = get_cycles();
  914. if (enc)
  915. ret = do_one_acipher_op(req,
  916. crypto_skcipher_encrypt(req));
  917. else
  918. ret = do_one_acipher_op(req,
  919. crypto_skcipher_decrypt(req));
  920. end = get_cycles();
  921. if (ret)
  922. goto out;
  923. cycles += end - start;
  924. }
  925. out:
  926. if (ret == 0)
  927. pr_cont("1 operation in %lu cycles (%d bytes)\n",
  928. (cycles + 4) / 8, blen);
  929. return ret;
  930. }
  931. static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
  932. struct cipher_speed_template *template,
  933. unsigned int tcount, u8 *keysize, bool async)
  934. {
  935. unsigned int ret, i, j, k, iv_len;
  936. struct crypto_wait wait;
  937. const char *key;
  938. char iv[128];
  939. struct skcipher_request *req;
  940. struct crypto_skcipher *tfm;
  941. const char *e;
  942. u32 *b_size;
  943. if (enc == ENCRYPT)
  944. e = "encryption";
  945. else
  946. e = "decryption";
  947. crypto_init_wait(&wait);
  948. tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC);
  949. if (IS_ERR(tfm)) {
  950. pr_err("failed to load transform for %s: %ld\n", algo,
  951. PTR_ERR(tfm));
  952. return;
  953. }
  954. pr_info("\ntesting speed of async %s (%s) %s\n", algo,
  955. get_driver_name(crypto_skcipher, tfm), e);
  956. req = skcipher_request_alloc(tfm, GFP_KERNEL);
  957. if (!req) {
  958. pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
  959. algo);
  960. goto out;
  961. }
  962. skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  963. crypto_req_done, &wait);
  964. i = 0;
  965. do {
  966. b_size = block_sizes;
  967. do {
  968. struct scatterlist sg[TVMEMSIZE];
  969. if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
  970. pr_err("template (%u) too big for "
  971. "tvmem (%lu)\n", *keysize + *b_size,
  972. TVMEMSIZE * PAGE_SIZE);
  973. goto out_free_req;
  974. }
  975. pr_info("test %u (%d bit key, %d byte blocks): ", i,
  976. *keysize * 8, *b_size);
  977. memset(tvmem[0], 0xff, PAGE_SIZE);
  978. /* set key, plain text and IV */
  979. key = tvmem[0];
  980. for (j = 0; j < tcount; j++) {
  981. if (template[j].klen == *keysize) {
  982. key = template[j].key;
  983. break;
  984. }
  985. }
  986. crypto_skcipher_clear_flags(tfm, ~0);
  987. ret = crypto_skcipher_setkey(tfm, key, *keysize);
  988. if (ret) {
  989. pr_err("setkey() failed flags=%x\n",
  990. crypto_skcipher_get_flags(tfm));
  991. goto out_free_req;
  992. }
  993. k = *keysize + *b_size;
  994. sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
  995. if (k > PAGE_SIZE) {
  996. sg_set_buf(sg, tvmem[0] + *keysize,
  997. PAGE_SIZE - *keysize);
  998. k -= PAGE_SIZE;
  999. j = 1;
  1000. while (k > PAGE_SIZE) {
  1001. sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
  1002. memset(tvmem[j], 0xff, PAGE_SIZE);
  1003. j++;
  1004. k -= PAGE_SIZE;
  1005. }
  1006. sg_set_buf(sg + j, tvmem[j], k);
  1007. memset(tvmem[j], 0xff, k);
  1008. } else {
  1009. sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
  1010. }
  1011. iv_len = crypto_skcipher_ivsize(tfm);
  1012. if (iv_len)
  1013. memset(&iv, 0xff, iv_len);
  1014. skcipher_request_set_crypt(req, sg, sg, *b_size, iv);
  1015. if (secs)
  1016. ret = test_acipher_jiffies(req, enc,
  1017. *b_size, secs);
  1018. else
  1019. ret = test_acipher_cycles(req, enc,
  1020. *b_size);
  1021. if (ret) {
  1022. pr_err("%s() failed flags=%x\n", e,
  1023. crypto_skcipher_get_flags(tfm));
  1024. break;
  1025. }
  1026. b_size++;
  1027. i++;
  1028. } while (*b_size);
  1029. keysize++;
  1030. } while (*keysize);
  1031. out_free_req:
  1032. skcipher_request_free(req);
  1033. out:
  1034. crypto_free_skcipher(tfm);
  1035. }
  1036. static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
  1037. struct cipher_speed_template *template,
  1038. unsigned int tcount, u8 *keysize)
  1039. {
  1040. return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
  1041. true);
  1042. }
  1043. static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
  1044. struct cipher_speed_template *template,
  1045. unsigned int tcount, u8 *keysize)
  1046. {
  1047. return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
  1048. false);
  1049. }
  1050. static void test_available(void)
  1051. {
  1052. char **name = check;
  1053. while (*name) {
  1054. printk("alg %s ", *name);
  1055. printk(crypto_has_alg(*name, 0, 0) ?
  1056. "found\n" : "not found\n");
  1057. name++;
  1058. }
  1059. }
  1060. static inline int tcrypt_test(const char *alg)
  1061. {
  1062. int ret;
  1063. pr_debug("testing %s\n", alg);
  1064. ret = alg_test(alg, alg, 0, 0);
  1065. /* non-fips algs return -EINVAL in fips mode */
  1066. if (fips_enabled && ret == -EINVAL)
  1067. ret = 0;
  1068. return ret;
  1069. }
  1070. static int do_test(const char *alg, u32 type, u32 mask, int m)
  1071. {
  1072. int i;
  1073. int ret = 0;
  1074. switch (m) {
  1075. case 0:
  1076. if (alg) {
  1077. if (!crypto_has_alg(alg, type,
  1078. mask ?: CRYPTO_ALG_TYPE_MASK))
  1079. ret = -ENOENT;
  1080. break;
  1081. }
  1082. for (i = 1; i < 200; i++)
  1083. ret += do_test(NULL, 0, 0, i);
  1084. break;
  1085. case 1:
  1086. ret += tcrypt_test("md5");
  1087. break;
  1088. case 2:
  1089. ret += tcrypt_test("sha1");
  1090. break;
  1091. case 3:
  1092. ret += tcrypt_test("ecb(des)");
  1093. ret += tcrypt_test("cbc(des)");
  1094. ret += tcrypt_test("ctr(des)");
  1095. break;
  1096. case 4:
  1097. ret += tcrypt_test("ecb(des3_ede)");
  1098. ret += tcrypt_test("cbc(des3_ede)");
  1099. ret += tcrypt_test("ctr(des3_ede)");
  1100. break;
  1101. case 5:
  1102. ret += tcrypt_test("md4");
  1103. break;
  1104. case 6:
  1105. ret += tcrypt_test("sha256");
  1106. break;
  1107. case 7:
  1108. ret += tcrypt_test("ecb(blowfish)");
  1109. ret += tcrypt_test("cbc(blowfish)");
  1110. ret += tcrypt_test("ctr(blowfish)");
  1111. break;
  1112. case 8:
  1113. ret += tcrypt_test("ecb(twofish)");
  1114. ret += tcrypt_test("cbc(twofish)");
  1115. ret += tcrypt_test("ctr(twofish)");
  1116. ret += tcrypt_test("lrw(twofish)");
  1117. ret += tcrypt_test("xts(twofish)");
  1118. break;
  1119. case 9:
  1120. ret += tcrypt_test("ecb(serpent)");
  1121. ret += tcrypt_test("cbc(serpent)");
  1122. ret += tcrypt_test("ctr(serpent)");
  1123. ret += tcrypt_test("lrw(serpent)");
  1124. ret += tcrypt_test("xts(serpent)");
  1125. break;
  1126. case 10:
  1127. ret += tcrypt_test("ecb(aes)");
  1128. ret += tcrypt_test("cbc(aes)");
  1129. ret += tcrypt_test("lrw(aes)");
  1130. ret += tcrypt_test("xts(aes)");
  1131. ret += tcrypt_test("ctr(aes)");
  1132. ret += tcrypt_test("rfc3686(ctr(aes))");
  1133. break;
  1134. case 11:
  1135. ret += tcrypt_test("sha384");
  1136. break;
  1137. case 12:
  1138. ret += tcrypt_test("sha512");
  1139. break;
  1140. case 13:
  1141. ret += tcrypt_test("deflate");
  1142. break;
  1143. case 14:
  1144. ret += tcrypt_test("ecb(cast5)");
  1145. ret += tcrypt_test("cbc(cast5)");
  1146. ret += tcrypt_test("ctr(cast5)");
  1147. break;
  1148. case 15:
  1149. ret += tcrypt_test("ecb(cast6)");
  1150. ret += tcrypt_test("cbc(cast6)");
  1151. ret += tcrypt_test("ctr(cast6)");
  1152. ret += tcrypt_test("lrw(cast6)");
  1153. ret += tcrypt_test("xts(cast6)");
  1154. break;
  1155. case 16:
  1156. ret += tcrypt_test("ecb(arc4)");
  1157. break;
  1158. case 17:
  1159. ret += tcrypt_test("michael_mic");
  1160. break;
  1161. case 18:
  1162. ret += tcrypt_test("crc32c");
  1163. break;
  1164. case 19:
  1165. ret += tcrypt_test("ecb(tea)");
  1166. break;
  1167. case 20:
  1168. ret += tcrypt_test("ecb(xtea)");
  1169. break;
  1170. case 21:
  1171. ret += tcrypt_test("ecb(khazad)");
  1172. break;
  1173. case 22:
  1174. ret += tcrypt_test("wp512");
  1175. break;
  1176. case 23:
  1177. ret += tcrypt_test("wp384");
  1178. break;
  1179. case 24:
  1180. ret += tcrypt_test("wp256");
  1181. break;
  1182. case 25:
  1183. ret += tcrypt_test("ecb(tnepres)");
  1184. break;
  1185. case 26:
  1186. ret += tcrypt_test("ecb(anubis)");
  1187. ret += tcrypt_test("cbc(anubis)");
  1188. break;
  1189. case 27:
  1190. ret += tcrypt_test("tgr192");
  1191. break;
  1192. case 28:
  1193. ret += tcrypt_test("tgr160");
  1194. break;
  1195. case 29:
  1196. ret += tcrypt_test("tgr128");
  1197. break;
  1198. case 30:
  1199. ret += tcrypt_test("ecb(xeta)");
  1200. break;
  1201. case 31:
  1202. ret += tcrypt_test("pcbc(fcrypt)");
  1203. break;
  1204. case 32:
  1205. ret += tcrypt_test("ecb(camellia)");
  1206. ret += tcrypt_test("cbc(camellia)");
  1207. ret += tcrypt_test("ctr(camellia)");
  1208. ret += tcrypt_test("lrw(camellia)");
  1209. ret += tcrypt_test("xts(camellia)");
  1210. break;
  1211. case 33:
  1212. ret += tcrypt_test("sha224");
  1213. break;
  1214. case 34:
  1215. ret += tcrypt_test("salsa20");
  1216. break;
  1217. case 35:
  1218. ret += tcrypt_test("gcm(aes)");
  1219. break;
  1220. case 36:
  1221. ret += tcrypt_test("lzo");
  1222. break;
  1223. case 37:
  1224. ret += tcrypt_test("ccm(aes)");
  1225. break;
  1226. case 38:
  1227. ret += tcrypt_test("cts(cbc(aes))");
  1228. break;
  1229. case 39:
  1230. ret += tcrypt_test("rmd128");
  1231. break;
  1232. case 40:
  1233. ret += tcrypt_test("rmd160");
  1234. break;
  1235. case 41:
  1236. ret += tcrypt_test("rmd256");
  1237. break;
  1238. case 42:
  1239. ret += tcrypt_test("rmd320");
  1240. break;
  1241. case 43:
  1242. ret += tcrypt_test("ecb(seed)");
  1243. break;
  1244. case 44:
  1245. ret += tcrypt_test("zlib");
  1246. break;
  1247. case 45:
  1248. ret += tcrypt_test("rfc4309(ccm(aes))");
  1249. break;
  1250. case 46:
  1251. ret += tcrypt_test("ghash");
  1252. break;
  1253. case 47:
  1254. ret += tcrypt_test("crct10dif");
  1255. break;
  1256. case 48:
  1257. ret += tcrypt_test("sha3-224");
  1258. break;
  1259. case 49:
  1260. ret += tcrypt_test("sha3-256");
  1261. break;
  1262. case 50:
  1263. ret += tcrypt_test("sha3-384");
  1264. break;
  1265. case 51:
  1266. ret += tcrypt_test("sha3-512");
  1267. break;
  1268. case 52:
  1269. ret += tcrypt_test("sm3");
  1270. break;
  1271. case 100:
  1272. ret += tcrypt_test("hmac(md5)");
  1273. break;
  1274. case 101:
  1275. ret += tcrypt_test("hmac(sha1)");
  1276. break;
  1277. case 102:
  1278. ret += tcrypt_test("hmac(sha256)");
  1279. break;
  1280. case 103:
  1281. ret += tcrypt_test("hmac(sha384)");
  1282. break;
  1283. case 104:
  1284. ret += tcrypt_test("hmac(sha512)");
  1285. break;
  1286. case 105:
  1287. ret += tcrypt_test("hmac(sha224)");
  1288. break;
  1289. case 106:
  1290. ret += tcrypt_test("xcbc(aes)");
  1291. break;
  1292. case 107:
  1293. ret += tcrypt_test("hmac(rmd128)");
  1294. break;
  1295. case 108:
  1296. ret += tcrypt_test("hmac(rmd160)");
  1297. break;
  1298. case 109:
  1299. ret += tcrypt_test("vmac(aes)");
  1300. break;
  1301. case 110:
  1302. ret += tcrypt_test("hmac(crc32)");
  1303. break;
  1304. case 111:
  1305. ret += tcrypt_test("hmac(sha3-224)");
  1306. break;
  1307. case 112:
  1308. ret += tcrypt_test("hmac(sha3-256)");
  1309. break;
  1310. case 113:
  1311. ret += tcrypt_test("hmac(sha3-384)");
  1312. break;
  1313. case 114:
  1314. ret += tcrypt_test("hmac(sha3-512)");
  1315. break;
  1316. case 150:
  1317. ret += tcrypt_test("ansi_cprng");
  1318. break;
  1319. case 151:
  1320. ret += tcrypt_test("rfc4106(gcm(aes))");
  1321. break;
  1322. case 152:
  1323. ret += tcrypt_test("rfc4543(gcm(aes))");
  1324. break;
  1325. case 153:
  1326. ret += tcrypt_test("cmac(aes)");
  1327. break;
  1328. case 154:
  1329. ret += tcrypt_test("cmac(des3_ede)");
  1330. break;
  1331. case 155:
  1332. ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
  1333. break;
  1334. case 156:
  1335. ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
  1336. break;
  1337. case 157:
  1338. ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
  1339. break;
  1340. case 181:
  1341. ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
  1342. break;
  1343. case 182:
  1344. ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
  1345. break;
  1346. case 183:
  1347. ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
  1348. break;
  1349. case 184:
  1350. ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
  1351. break;
  1352. case 185:
  1353. ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
  1354. break;
  1355. case 186:
  1356. ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
  1357. break;
  1358. case 187:
  1359. ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
  1360. break;
  1361. case 188:
  1362. ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
  1363. break;
  1364. case 189:
  1365. ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
  1366. break;
  1367. case 190:
  1368. ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
  1369. break;
  1370. case 200:
  1371. test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
  1372. speed_template_16_24_32);
  1373. test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
  1374. speed_template_16_24_32);
  1375. test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
  1376. speed_template_16_24_32);
  1377. test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
  1378. speed_template_16_24_32);
  1379. test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
  1380. speed_template_32_40_48);
  1381. test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
  1382. speed_template_32_40_48);
  1383. test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
  1384. speed_template_32_64);
  1385. test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
  1386. speed_template_32_64);
  1387. test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
  1388. speed_template_16_24_32);
  1389. test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
  1390. speed_template_16_24_32);
  1391. test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
  1392. speed_template_16_24_32);
  1393. test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
  1394. speed_template_16_24_32);
  1395. break;
  1396. case 201:
  1397. test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
  1398. des3_speed_template, DES3_SPEED_VECTORS,
  1399. speed_template_24);
  1400. test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
  1401. des3_speed_template, DES3_SPEED_VECTORS,
  1402. speed_template_24);
  1403. test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
  1404. des3_speed_template, DES3_SPEED_VECTORS,
  1405. speed_template_24);
  1406. test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
  1407. des3_speed_template, DES3_SPEED_VECTORS,
  1408. speed_template_24);
  1409. test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
  1410. des3_speed_template, DES3_SPEED_VECTORS,
  1411. speed_template_24);
  1412. test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
  1413. des3_speed_template, DES3_SPEED_VECTORS,
  1414. speed_template_24);
  1415. break;
  1416. case 202:
  1417. test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
  1418. speed_template_16_24_32);
  1419. test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
  1420. speed_template_16_24_32);
  1421. test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
  1422. speed_template_16_24_32);
  1423. test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
  1424. speed_template_16_24_32);
  1425. test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
  1426. speed_template_16_24_32);
  1427. test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
  1428. speed_template_16_24_32);
  1429. test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
  1430. speed_template_32_40_48);
  1431. test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
  1432. speed_template_32_40_48);
  1433. test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
  1434. speed_template_32_48_64);
  1435. test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
  1436. speed_template_32_48_64);
  1437. break;
  1438. case 203:
  1439. test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
  1440. speed_template_8_32);
  1441. test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
  1442. speed_template_8_32);
  1443. test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
  1444. speed_template_8_32);
  1445. test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
  1446. speed_template_8_32);
  1447. test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
  1448. speed_template_8_32);
  1449. test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
  1450. speed_template_8_32);
  1451. break;
  1452. case 204:
  1453. test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
  1454. speed_template_8);
  1455. test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
  1456. speed_template_8);
  1457. test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
  1458. speed_template_8);
  1459. test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
  1460. speed_template_8);
  1461. break;
  1462. case 205:
  1463. test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
  1464. speed_template_16_24_32);
  1465. test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
  1466. speed_template_16_24_32);
  1467. test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
  1468. speed_template_16_24_32);
  1469. test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
  1470. speed_template_16_24_32);
  1471. test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
  1472. speed_template_16_24_32);
  1473. test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
  1474. speed_template_16_24_32);
  1475. test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
  1476. speed_template_32_40_48);
  1477. test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
  1478. speed_template_32_40_48);
  1479. test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
  1480. speed_template_32_48_64);
  1481. test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
  1482. speed_template_32_48_64);
  1483. break;
  1484. case 206:
  1485. test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
  1486. speed_template_16_32);
  1487. break;
  1488. case 207:
  1489. test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
  1490. speed_template_16_32);
  1491. test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
  1492. speed_template_16_32);
  1493. test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
  1494. speed_template_16_32);
  1495. test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
  1496. speed_template_16_32);
  1497. test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
  1498. speed_template_16_32);
  1499. test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
  1500. speed_template_16_32);
  1501. test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
  1502. speed_template_32_48);
  1503. test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
  1504. speed_template_32_48);
  1505. test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
  1506. speed_template_32_64);
  1507. test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
  1508. speed_template_32_64);
  1509. break;
  1510. case 208:
  1511. test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
  1512. speed_template_8);
  1513. break;
  1514. case 209:
  1515. test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
  1516. speed_template_8_16);
  1517. test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
  1518. speed_template_8_16);
  1519. test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
  1520. speed_template_8_16);
  1521. test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
  1522. speed_template_8_16);
  1523. test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
  1524. speed_template_8_16);
  1525. test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
  1526. speed_template_8_16);
  1527. break;
  1528. case 210:
  1529. test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
  1530. speed_template_16_32);
  1531. test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
  1532. speed_template_16_32);
  1533. test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
  1534. speed_template_16_32);
  1535. test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
  1536. speed_template_16_32);
  1537. test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
  1538. speed_template_16_32);
  1539. test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
  1540. speed_template_16_32);
  1541. test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
  1542. speed_template_32_48);
  1543. test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
  1544. speed_template_32_48);
  1545. test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
  1546. speed_template_32_64);
  1547. test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
  1548. speed_template_32_64);
  1549. break;
  1550. case 211:
  1551. test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
  1552. NULL, 0, 16, 16, aead_speed_template_20);
  1553. test_aead_speed("gcm(aes)", ENCRYPT, sec,
  1554. NULL, 0, 16, 8, speed_template_16_24_32);
  1555. test_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec,
  1556. NULL, 0, 16, 16, aead_speed_template_20);
  1557. test_aead_speed("gcm(aes)", DECRYPT, sec,
  1558. NULL, 0, 16, 8, speed_template_16_24_32);
  1559. break;
  1560. case 212:
  1561. test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
  1562. NULL, 0, 16, 16, aead_speed_template_19);
  1563. test_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec,
  1564. NULL, 0, 16, 16, aead_speed_template_19);
  1565. break;
  1566. case 213:
  1567. test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
  1568. NULL, 0, 16, 8, aead_speed_template_36);
  1569. test_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT, sec,
  1570. NULL, 0, 16, 8, aead_speed_template_36);
  1571. break;
  1572. case 214:
  1573. test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
  1574. speed_template_32);
  1575. break;
  1576. case 300:
  1577. if (alg) {
  1578. test_hash_speed(alg, sec, generic_hash_speed_template);
  1579. break;
  1580. }
  1581. /* fall through */
  1582. case 301:
  1583. test_hash_speed("md4", sec, generic_hash_speed_template);
  1584. if (mode > 300 && mode < 400) break;
  1585. /* fall through */
  1586. case 302:
  1587. test_hash_speed("md5", sec, generic_hash_speed_template);
  1588. if (mode > 300 && mode < 400) break;
  1589. /* fall through */
  1590. case 303:
  1591. test_hash_speed("sha1", sec, generic_hash_speed_template);
  1592. if (mode > 300 && mode < 400) break;
  1593. /* fall through */
  1594. case 304:
  1595. test_hash_speed("sha256", sec, generic_hash_speed_template);
  1596. if (mode > 300 && mode < 400) break;
  1597. /* fall through */
  1598. case 305:
  1599. test_hash_speed("sha384", sec, generic_hash_speed_template);
  1600. if (mode > 300 && mode < 400) break;
  1601. /* fall through */
  1602. case 306:
  1603. test_hash_speed("sha512", sec, generic_hash_speed_template);
  1604. if (mode > 300 && mode < 400) break;
  1605. /* fall through */
  1606. case 307:
  1607. test_hash_speed("wp256", sec, generic_hash_speed_template);
  1608. if (mode > 300 && mode < 400) break;
  1609. /* fall through */
  1610. case 308:
  1611. test_hash_speed("wp384", sec, generic_hash_speed_template);
  1612. if (mode > 300 && mode < 400) break;
  1613. /* fall through */
  1614. case 309:
  1615. test_hash_speed("wp512", sec, generic_hash_speed_template);
  1616. if (mode > 300 && mode < 400) break;
  1617. /* fall through */
  1618. case 310:
  1619. test_hash_speed("tgr128", sec, generic_hash_speed_template);
  1620. if (mode > 300 && mode < 400) break;
  1621. /* fall through */
  1622. case 311:
  1623. test_hash_speed("tgr160", sec, generic_hash_speed_template);
  1624. if (mode > 300 && mode < 400) break;
  1625. /* fall through */
  1626. case 312:
  1627. test_hash_speed("tgr192", sec, generic_hash_speed_template);
  1628. if (mode > 300 && mode < 400) break;
  1629. /* fall through */
  1630. case 313:
  1631. test_hash_speed("sha224", sec, generic_hash_speed_template);
  1632. if (mode > 300 && mode < 400) break;
  1633. /* fall through */
  1634. case 314:
  1635. test_hash_speed("rmd128", sec, generic_hash_speed_template);
  1636. if (mode > 300 && mode < 400) break;
  1637. /* fall through */
  1638. case 315:
  1639. test_hash_speed("rmd160", sec, generic_hash_speed_template);
  1640. if (mode > 300 && mode < 400) break;
  1641. /* fall through */
  1642. case 316:
  1643. test_hash_speed("rmd256", sec, generic_hash_speed_template);
  1644. if (mode > 300 && mode < 400) break;
  1645. /* fall through */
  1646. case 317:
  1647. test_hash_speed("rmd320", sec, generic_hash_speed_template);
  1648. if (mode > 300 && mode < 400) break;
  1649. /* fall through */
  1650. case 318:
  1651. test_hash_speed("ghash-generic", sec, hash_speed_template_16);
  1652. if (mode > 300 && mode < 400) break;
  1653. /* fall through */
  1654. case 319:
  1655. test_hash_speed("crc32c", sec, generic_hash_speed_template);
  1656. if (mode > 300 && mode < 400) break;
  1657. /* fall through */
  1658. case 320:
  1659. test_hash_speed("crct10dif", sec, generic_hash_speed_template);
  1660. if (mode > 300 && mode < 400) break;
  1661. /* fall through */
  1662. case 321:
  1663. test_hash_speed("poly1305", sec, poly1305_speed_template);
  1664. if (mode > 300 && mode < 400) break;
  1665. /* fall through */
  1666. case 322:
  1667. test_hash_speed("sha3-224", sec, generic_hash_speed_template);
  1668. if (mode > 300 && mode < 400) break;
  1669. /* fall through */
  1670. case 323:
  1671. test_hash_speed("sha3-256", sec, generic_hash_speed_template);
  1672. if (mode > 300 && mode < 400) break;
  1673. /* fall through */
  1674. case 324:
  1675. test_hash_speed("sha3-384", sec, generic_hash_speed_template);
  1676. if (mode > 300 && mode < 400) break;
  1677. /* fall through */
  1678. case 325:
  1679. test_hash_speed("sha3-512", sec, generic_hash_speed_template);
  1680. if (mode > 300 && mode < 400) break;
  1681. /* fall through */
  1682. case 326:
  1683. test_hash_speed("sm3", sec, generic_hash_speed_template);
  1684. if (mode > 300 && mode < 400) break;
  1685. /* fall through */
  1686. case 399:
  1687. break;
  1688. case 400:
  1689. if (alg) {
  1690. test_ahash_speed(alg, sec, generic_hash_speed_template);
  1691. break;
  1692. }
  1693. /* fall through */
  1694. case 401:
  1695. test_ahash_speed("md4", sec, generic_hash_speed_template);
  1696. if (mode > 400 && mode < 500) break;
  1697. /* fall through */
  1698. case 402:
  1699. test_ahash_speed("md5", sec, generic_hash_speed_template);
  1700. if (mode > 400 && mode < 500) break;
  1701. /* fall through */
  1702. case 403:
  1703. test_ahash_speed("sha1", sec, generic_hash_speed_template);
  1704. if (mode > 400 && mode < 500) break;
  1705. /* fall through */
  1706. case 404:
  1707. test_ahash_speed("sha256", sec, generic_hash_speed_template);
  1708. if (mode > 400 && mode < 500) break;
  1709. /* fall through */
  1710. case 405:
  1711. test_ahash_speed("sha384", sec, generic_hash_speed_template);
  1712. if (mode > 400 && mode < 500) break;
  1713. /* fall through */
  1714. case 406:
  1715. test_ahash_speed("sha512", sec, generic_hash_speed_template);
  1716. if (mode > 400 && mode < 500) break;
  1717. /* fall through */
  1718. case 407:
  1719. test_ahash_speed("wp256", sec, generic_hash_speed_template);
  1720. if (mode > 400 && mode < 500) break;
  1721. /* fall through */
  1722. case 408:
  1723. test_ahash_speed("wp384", sec, generic_hash_speed_template);
  1724. if (mode > 400 && mode < 500) break;
  1725. /* fall through */
  1726. case 409:
  1727. test_ahash_speed("wp512", sec, generic_hash_speed_template);
  1728. if (mode > 400 && mode < 500) break;
  1729. /* fall through */
  1730. case 410:
  1731. test_ahash_speed("tgr128", sec, generic_hash_speed_template);
  1732. if (mode > 400 && mode < 500) break;
  1733. /* fall through */
  1734. case 411:
  1735. test_ahash_speed("tgr160", sec, generic_hash_speed_template);
  1736. if (mode > 400 && mode < 500) break;
  1737. /* fall through */
  1738. case 412:
  1739. test_ahash_speed("tgr192", sec, generic_hash_speed_template);
  1740. if (mode > 400 && mode < 500) break;
  1741. /* fall through */
  1742. case 413:
  1743. test_ahash_speed("sha224", sec, generic_hash_speed_template);
  1744. if (mode > 400 && mode < 500) break;
  1745. /* fall through */
  1746. case 414:
  1747. test_ahash_speed("rmd128", sec, generic_hash_speed_template);
  1748. if (mode > 400 && mode < 500) break;
  1749. /* fall through */
  1750. case 415:
  1751. test_ahash_speed("rmd160", sec, generic_hash_speed_template);
  1752. if (mode > 400 && mode < 500) break;
  1753. /* fall through */
  1754. case 416:
  1755. test_ahash_speed("rmd256", sec, generic_hash_speed_template);
  1756. if (mode > 400 && mode < 500) break;
  1757. /* fall through */
  1758. case 417:
  1759. test_ahash_speed("rmd320", sec, generic_hash_speed_template);
  1760. if (mode > 400 && mode < 500) break;
  1761. /* fall through */
  1762. case 418:
  1763. test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
  1764. if (mode > 400 && mode < 500) break;
  1765. /* fall through */
  1766. case 419:
  1767. test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
  1768. if (mode > 400 && mode < 500) break;
  1769. /* fall through */
  1770. case 420:
  1771. test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
  1772. if (mode > 400 && mode < 500) break;
  1773. /* fall through */
  1774. case 421:
  1775. test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
  1776. if (mode > 400 && mode < 500) break;
  1777. /* fall through */
  1778. case 422:
  1779. test_mb_ahash_speed("sha1", sec, generic_hash_speed_template,
  1780. num_mb);
  1781. if (mode > 400 && mode < 500) break;
  1782. /* fall through */
  1783. case 423:
  1784. test_mb_ahash_speed("sha256", sec, generic_hash_speed_template,
  1785. num_mb);
  1786. if (mode > 400 && mode < 500) break;
  1787. /* fall through */
  1788. case 424:
  1789. test_mb_ahash_speed("sha512", sec, generic_hash_speed_template,
  1790. num_mb);
  1791. if (mode > 400 && mode < 500) break;
  1792. /* fall through */
  1793. case 425:
  1794. test_mb_ahash_speed("sm3", sec, generic_hash_speed_template,
  1795. num_mb);
  1796. if (mode > 400 && mode < 500) break;
  1797. /* fall through */
  1798. case 499:
  1799. break;
  1800. case 500:
  1801. test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
  1802. speed_template_16_24_32);
  1803. test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
  1804. speed_template_16_24_32);
  1805. test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
  1806. speed_template_16_24_32);
  1807. test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
  1808. speed_template_16_24_32);
  1809. test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
  1810. speed_template_32_40_48);
  1811. test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
  1812. speed_template_32_40_48);
  1813. test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
  1814. speed_template_32_64);
  1815. test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
  1816. speed_template_32_64);
  1817. test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
  1818. speed_template_16_24_32);
  1819. test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
  1820. speed_template_16_24_32);
  1821. test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
  1822. speed_template_16_24_32);
  1823. test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
  1824. speed_template_16_24_32);
  1825. test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
  1826. speed_template_16_24_32);
  1827. test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
  1828. speed_template_16_24_32);
  1829. test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
  1830. speed_template_16_24_32);
  1831. test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
  1832. speed_template_16_24_32);
  1833. test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
  1834. speed_template_20_28_36);
  1835. test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
  1836. speed_template_20_28_36);
  1837. break;
  1838. case 501:
  1839. test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
  1840. des3_speed_template, DES3_SPEED_VECTORS,
  1841. speed_template_24);
  1842. test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
  1843. des3_speed_template, DES3_SPEED_VECTORS,
  1844. speed_template_24);
  1845. test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
  1846. des3_speed_template, DES3_SPEED_VECTORS,
  1847. speed_template_24);
  1848. test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
  1849. des3_speed_template, DES3_SPEED_VECTORS,
  1850. speed_template_24);
  1851. test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
  1852. des3_speed_template, DES3_SPEED_VECTORS,
  1853. speed_template_24);
  1854. test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
  1855. des3_speed_template, DES3_SPEED_VECTORS,
  1856. speed_template_24);
  1857. test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
  1858. des3_speed_template, DES3_SPEED_VECTORS,
  1859. speed_template_24);
  1860. test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
  1861. des3_speed_template, DES3_SPEED_VECTORS,
  1862. speed_template_24);
  1863. break;
  1864. case 502:
  1865. test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
  1866. speed_template_8);
  1867. test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
  1868. speed_template_8);
  1869. test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
  1870. speed_template_8);
  1871. test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
  1872. speed_template_8);
  1873. test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
  1874. speed_template_8);
  1875. test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
  1876. speed_template_8);
  1877. test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
  1878. speed_template_8);
  1879. test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
  1880. speed_template_8);
  1881. break;
  1882. case 503:
  1883. test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
  1884. speed_template_16_32);
  1885. test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
  1886. speed_template_16_32);
  1887. test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
  1888. speed_template_16_32);
  1889. test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
  1890. speed_template_16_32);
  1891. test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
  1892. speed_template_16_32);
  1893. test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
  1894. speed_template_16_32);
  1895. test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
  1896. speed_template_32_48);
  1897. test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
  1898. speed_template_32_48);
  1899. test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
  1900. speed_template_32_64);
  1901. test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
  1902. speed_template_32_64);
  1903. break;
  1904. case 504:
  1905. test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
  1906. speed_template_16_24_32);
  1907. test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
  1908. speed_template_16_24_32);
  1909. test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
  1910. speed_template_16_24_32);
  1911. test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
  1912. speed_template_16_24_32);
  1913. test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
  1914. speed_template_16_24_32);
  1915. test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
  1916. speed_template_16_24_32);
  1917. test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
  1918. speed_template_32_40_48);
  1919. test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
  1920. speed_template_32_40_48);
  1921. test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
  1922. speed_template_32_48_64);
  1923. test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
  1924. speed_template_32_48_64);
  1925. break;
  1926. case 505:
  1927. test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
  1928. speed_template_8);
  1929. break;
  1930. case 506:
  1931. test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
  1932. speed_template_8_16);
  1933. test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
  1934. speed_template_8_16);
  1935. test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
  1936. speed_template_8_16);
  1937. test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
  1938. speed_template_8_16);
  1939. test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
  1940. speed_template_8_16);
  1941. test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
  1942. speed_template_8_16);
  1943. break;
  1944. case 507:
  1945. test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
  1946. speed_template_16_32);
  1947. test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
  1948. speed_template_16_32);
  1949. test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
  1950. speed_template_16_32);
  1951. test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
  1952. speed_template_16_32);
  1953. test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
  1954. speed_template_16_32);
  1955. test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
  1956. speed_template_16_32);
  1957. test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
  1958. speed_template_32_48);
  1959. test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
  1960. speed_template_32_48);
  1961. test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
  1962. speed_template_32_64);
  1963. test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
  1964. speed_template_32_64);
  1965. break;
  1966. case 508:
  1967. test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
  1968. speed_template_16_32);
  1969. test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
  1970. speed_template_16_32);
  1971. test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
  1972. speed_template_16_32);
  1973. test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
  1974. speed_template_16_32);
  1975. test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
  1976. speed_template_16_32);
  1977. test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
  1978. speed_template_16_32);
  1979. test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
  1980. speed_template_32_48);
  1981. test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
  1982. speed_template_32_48);
  1983. test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
  1984. speed_template_32_64);
  1985. test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
  1986. speed_template_32_64);
  1987. break;
  1988. case 509:
  1989. test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
  1990. speed_template_8_32);
  1991. test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
  1992. speed_template_8_32);
  1993. test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
  1994. speed_template_8_32);
  1995. test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
  1996. speed_template_8_32);
  1997. test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
  1998. speed_template_8_32);
  1999. test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
  2000. speed_template_8_32);
  2001. break;
  2002. case 600:
  2003. test_mb_skcipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
  2004. speed_template_16_24_32, num_mb);
  2005. test_mb_skcipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
  2006. speed_template_16_24_32, num_mb);
  2007. test_mb_skcipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
  2008. speed_template_16_24_32, num_mb);
  2009. test_mb_skcipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
  2010. speed_template_16_24_32, num_mb);
  2011. test_mb_skcipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
  2012. speed_template_32_40_48, num_mb);
  2013. test_mb_skcipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
  2014. speed_template_32_40_48, num_mb);
  2015. test_mb_skcipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
  2016. speed_template_32_64, num_mb);
  2017. test_mb_skcipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
  2018. speed_template_32_64, num_mb);
  2019. test_mb_skcipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
  2020. speed_template_16_24_32, num_mb);
  2021. test_mb_skcipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
  2022. speed_template_16_24_32, num_mb);
  2023. test_mb_skcipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
  2024. speed_template_16_24_32, num_mb);
  2025. test_mb_skcipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
  2026. speed_template_16_24_32, num_mb);
  2027. test_mb_skcipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
  2028. speed_template_16_24_32, num_mb);
  2029. test_mb_skcipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
  2030. speed_template_16_24_32, num_mb);
  2031. test_mb_skcipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
  2032. speed_template_16_24_32, num_mb);
  2033. test_mb_skcipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
  2034. speed_template_16_24_32, num_mb);
  2035. test_mb_skcipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL,
  2036. 0, speed_template_20_28_36, num_mb);
  2037. test_mb_skcipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL,
  2038. 0, speed_template_20_28_36, num_mb);
  2039. break;
  2040. case 601:
  2041. test_mb_skcipher_speed("ecb(des3_ede)", ENCRYPT, sec,
  2042. des3_speed_template, DES3_SPEED_VECTORS,
  2043. speed_template_24, num_mb);
  2044. test_mb_skcipher_speed("ecb(des3_ede)", DECRYPT, sec,
  2045. des3_speed_template, DES3_SPEED_VECTORS,
  2046. speed_template_24, num_mb);
  2047. test_mb_skcipher_speed("cbc(des3_ede)", ENCRYPT, sec,
  2048. des3_speed_template, DES3_SPEED_VECTORS,
  2049. speed_template_24, num_mb);
  2050. test_mb_skcipher_speed("cbc(des3_ede)", DECRYPT, sec,
  2051. des3_speed_template, DES3_SPEED_VECTORS,
  2052. speed_template_24, num_mb);
  2053. test_mb_skcipher_speed("cfb(des3_ede)", ENCRYPT, sec,
  2054. des3_speed_template, DES3_SPEED_VECTORS,
  2055. speed_template_24, num_mb);
  2056. test_mb_skcipher_speed("cfb(des3_ede)", DECRYPT, sec,
  2057. des3_speed_template, DES3_SPEED_VECTORS,
  2058. speed_template_24, num_mb);
  2059. test_mb_skcipher_speed("ofb(des3_ede)", ENCRYPT, sec,
  2060. des3_speed_template, DES3_SPEED_VECTORS,
  2061. speed_template_24, num_mb);
  2062. test_mb_skcipher_speed("ofb(des3_ede)", DECRYPT, sec,
  2063. des3_speed_template, DES3_SPEED_VECTORS,
  2064. speed_template_24, num_mb);
  2065. break;
  2066. case 602:
  2067. test_mb_skcipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
  2068. speed_template_8, num_mb);
  2069. test_mb_skcipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
  2070. speed_template_8, num_mb);
  2071. test_mb_skcipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
  2072. speed_template_8, num_mb);
  2073. test_mb_skcipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
  2074. speed_template_8, num_mb);
  2075. test_mb_skcipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
  2076. speed_template_8, num_mb);
  2077. test_mb_skcipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
  2078. speed_template_8, num_mb);
  2079. test_mb_skcipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
  2080. speed_template_8, num_mb);
  2081. test_mb_skcipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
  2082. speed_template_8, num_mb);
  2083. break;
  2084. case 603:
  2085. test_mb_skcipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
  2086. speed_template_16_32, num_mb);
  2087. test_mb_skcipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
  2088. speed_template_16_32, num_mb);
  2089. test_mb_skcipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
  2090. speed_template_16_32, num_mb);
  2091. test_mb_skcipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
  2092. speed_template_16_32, num_mb);
  2093. test_mb_skcipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
  2094. speed_template_16_32, num_mb);
  2095. test_mb_skcipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
  2096. speed_template_16_32, num_mb);
  2097. test_mb_skcipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
  2098. speed_template_32_48, num_mb);
  2099. test_mb_skcipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
  2100. speed_template_32_48, num_mb);
  2101. test_mb_skcipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
  2102. speed_template_32_64, num_mb);
  2103. test_mb_skcipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
  2104. speed_template_32_64, num_mb);
  2105. break;
  2106. case 604:
  2107. test_mb_skcipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
  2108. speed_template_16_24_32, num_mb);
  2109. test_mb_skcipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
  2110. speed_template_16_24_32, num_mb);
  2111. test_mb_skcipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
  2112. speed_template_16_24_32, num_mb);
  2113. test_mb_skcipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
  2114. speed_template_16_24_32, num_mb);
  2115. test_mb_skcipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
  2116. speed_template_16_24_32, num_mb);
  2117. test_mb_skcipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
  2118. speed_template_16_24_32, num_mb);
  2119. test_mb_skcipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
  2120. speed_template_32_40_48, num_mb);
  2121. test_mb_skcipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
  2122. speed_template_32_40_48, num_mb);
  2123. test_mb_skcipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
  2124. speed_template_32_48_64, num_mb);
  2125. test_mb_skcipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
  2126. speed_template_32_48_64, num_mb);
  2127. break;
  2128. case 605:
  2129. test_mb_skcipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
  2130. speed_template_8, num_mb);
  2131. break;
  2132. case 606:
  2133. test_mb_skcipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
  2134. speed_template_8_16, num_mb);
  2135. test_mb_skcipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
  2136. speed_template_8_16, num_mb);
  2137. test_mb_skcipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
  2138. speed_template_8_16, num_mb);
  2139. test_mb_skcipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
  2140. speed_template_8_16, num_mb);
  2141. test_mb_skcipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
  2142. speed_template_8_16, num_mb);
  2143. test_mb_skcipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
  2144. speed_template_8_16, num_mb);
  2145. break;
  2146. case 607:
  2147. test_mb_skcipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
  2148. speed_template_16_32, num_mb);
  2149. test_mb_skcipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
  2150. speed_template_16_32, num_mb);
  2151. test_mb_skcipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
  2152. speed_template_16_32, num_mb);
  2153. test_mb_skcipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
  2154. speed_template_16_32, num_mb);
  2155. test_mb_skcipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
  2156. speed_template_16_32, num_mb);
  2157. test_mb_skcipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
  2158. speed_template_16_32, num_mb);
  2159. test_mb_skcipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
  2160. speed_template_32_48, num_mb);
  2161. test_mb_skcipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
  2162. speed_template_32_48, num_mb);
  2163. test_mb_skcipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
  2164. speed_template_32_64, num_mb);
  2165. test_mb_skcipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
  2166. speed_template_32_64, num_mb);
  2167. break;
  2168. case 608:
  2169. test_mb_skcipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
  2170. speed_template_16_32, num_mb);
  2171. test_mb_skcipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
  2172. speed_template_16_32, num_mb);
  2173. test_mb_skcipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
  2174. speed_template_16_32, num_mb);
  2175. test_mb_skcipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
  2176. speed_template_16_32, num_mb);
  2177. test_mb_skcipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
  2178. speed_template_16_32, num_mb);
  2179. test_mb_skcipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
  2180. speed_template_16_32, num_mb);
  2181. test_mb_skcipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
  2182. speed_template_32_48, num_mb);
  2183. test_mb_skcipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
  2184. speed_template_32_48, num_mb);
  2185. test_mb_skcipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
  2186. speed_template_32_64, num_mb);
  2187. test_mb_skcipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
  2188. speed_template_32_64, num_mb);
  2189. break;
  2190. case 609:
  2191. test_mb_skcipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
  2192. speed_template_8_32, num_mb);
  2193. test_mb_skcipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
  2194. speed_template_8_32, num_mb);
  2195. test_mb_skcipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
  2196. speed_template_8_32, num_mb);
  2197. test_mb_skcipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
  2198. speed_template_8_32, num_mb);
  2199. test_mb_skcipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
  2200. speed_template_8_32, num_mb);
  2201. test_mb_skcipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
  2202. speed_template_8_32, num_mb);
  2203. break;
  2204. case 1000:
  2205. test_available();
  2206. break;
  2207. }
  2208. return ret;
  2209. }
  2210. static int __init tcrypt_mod_init(void)
  2211. {
  2212. int err = -ENOMEM;
  2213. int i;
  2214. for (i = 0; i < TVMEMSIZE; i++) {
  2215. tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
  2216. if (!tvmem[i])
  2217. goto err_free_tv;
  2218. }
  2219. err = do_test(alg, type, mask, mode);
  2220. if (err) {
  2221. printk(KERN_ERR "tcrypt: one or more tests failed!\n");
  2222. goto err_free_tv;
  2223. } else {
  2224. pr_debug("all tests passed\n");
  2225. }
  2226. /* We intentionaly return -EAGAIN to prevent keeping the module,
  2227. * unless we're running in fips mode. It does all its work from
  2228. * init() and doesn't offer any runtime functionality, but in
  2229. * the fips case, checking for a successful load is helpful.
  2230. * => we don't need it in the memory, do we?
  2231. * -- mludvig
  2232. */
  2233. if (!fips_enabled)
  2234. err = -EAGAIN;
  2235. err_free_tv:
  2236. for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
  2237. free_page((unsigned long)tvmem[i]);
  2238. return err;
  2239. }
  2240. /*
  2241. * If an init function is provided, an exit function must also be provided
  2242. * to allow module unload.
  2243. */
  2244. static void __exit tcrypt_mod_fini(void) { }
  2245. module_init(tcrypt_mod_init);
  2246. module_exit(tcrypt_mod_fini);
  2247. module_param(alg, charp, 0);
  2248. module_param(type, uint, 0);
  2249. module_param(mask, uint, 0);
  2250. module_param(mode, int, 0);
  2251. module_param(sec, uint, 0);
  2252. MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
  2253. "(defaults to zero which uses CPU cycles instead)");
  2254. module_param(num_mb, uint, 0000);
  2255. MODULE_PARM_DESC(num_mb, "Number of concurrent requests to be used in mb speed tests (defaults to 8)");
  2256. MODULE_LICENSE("GPL");
  2257. MODULE_DESCRIPTION("Quick & dirty crypto testing module");
  2258. MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");