tcrypt.c 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259
  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. #include <crypto/aead.h>
  25. #include <crypto/hash.h>
  26. #include <linux/err.h>
  27. #include <linux/fips.h>
  28. #include <linux/init.h>
  29. #include <linux/gfp.h>
  30. #include <linux/module.h>
  31. #include <linux/scatterlist.h>
  32. #include <linux/string.h>
  33. #include <linux/moduleparam.h>
  34. #include <linux/jiffies.h>
  35. #include <linux/timex.h>
  36. #include <linux/interrupt.h>
  37. #include "tcrypt.h"
  38. /*
  39. * Need slab memory for testing (size in number of pages).
  40. */
  41. #define TVMEMSIZE 4
  42. /*
  43. * Used by test_cipher_speed()
  44. */
  45. #define ENCRYPT 1
  46. #define DECRYPT 0
  47. #define MAX_DIGEST_SIZE 64
  48. /*
  49. * return a string with the driver name
  50. */
  51. #define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm))
  52. /*
  53. * Used by test_cipher_speed()
  54. */
  55. static unsigned int sec;
  56. static char *alg = NULL;
  57. static u32 type;
  58. static u32 mask;
  59. static int mode;
  60. static char *tvmem[TVMEMSIZE];
  61. static char *check[] = {
  62. "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
  63. "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
  64. "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
  65. "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
  66. "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
  67. "lzo", "cts", "zlib", NULL
  68. };
  69. struct tcrypt_result {
  70. struct completion completion;
  71. int err;
  72. };
  73. static void tcrypt_complete(struct crypto_async_request *req, int err)
  74. {
  75. struct tcrypt_result *res = req->data;
  76. if (err == -EINPROGRESS)
  77. return;
  78. res->err = err;
  79. complete(&res->completion);
  80. }
  81. static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc,
  82. struct scatterlist *sg, int blen, int secs)
  83. {
  84. unsigned long start, end;
  85. int bcount;
  86. int ret;
  87. for (start = jiffies, end = start + secs * HZ, bcount = 0;
  88. time_before(jiffies, end); bcount++) {
  89. if (enc)
  90. ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
  91. else
  92. ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
  93. if (ret)
  94. return ret;
  95. }
  96. printk("%d operations in %d seconds (%ld bytes)\n",
  97. bcount, secs, (long)bcount * blen);
  98. return 0;
  99. }
  100. static int test_cipher_cycles(struct blkcipher_desc *desc, int enc,
  101. struct scatterlist *sg, int blen)
  102. {
  103. unsigned long cycles = 0;
  104. int ret = 0;
  105. int i;
  106. local_irq_disable();
  107. /* Warm-up run. */
  108. for (i = 0; i < 4; i++) {
  109. if (enc)
  110. ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
  111. else
  112. ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
  113. if (ret)
  114. goto out;
  115. }
  116. /* The real thing. */
  117. for (i = 0; i < 8; i++) {
  118. cycles_t start, end;
  119. start = get_cycles();
  120. if (enc)
  121. ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
  122. else
  123. ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
  124. end = get_cycles();
  125. if (ret)
  126. goto out;
  127. cycles += end - start;
  128. }
  129. out:
  130. local_irq_enable();
  131. if (ret == 0)
  132. printk("1 operation in %lu cycles (%d bytes)\n",
  133. (cycles + 4) / 8, blen);
  134. return ret;
  135. }
  136. static inline int do_one_aead_op(struct aead_request *req, int ret)
  137. {
  138. if (ret == -EINPROGRESS || ret == -EBUSY) {
  139. struct tcrypt_result *tr = req->base.data;
  140. ret = wait_for_completion_interruptible(&tr->completion);
  141. if (!ret)
  142. ret = tr->err;
  143. reinit_completion(&tr->completion);
  144. }
  145. return ret;
  146. }
  147. static int test_aead_jiffies(struct aead_request *req, int enc,
  148. int blen, int secs)
  149. {
  150. unsigned long start, end;
  151. int bcount;
  152. int ret;
  153. for (start = jiffies, end = start + secs * HZ, bcount = 0;
  154. time_before(jiffies, end); bcount++) {
  155. if (enc)
  156. ret = do_one_aead_op(req, crypto_aead_encrypt(req));
  157. else
  158. ret = do_one_aead_op(req, crypto_aead_decrypt(req));
  159. if (ret)
  160. return ret;
  161. }
  162. printk("%d operations in %d seconds (%ld bytes)\n",
  163. bcount, secs, (long)bcount * blen);
  164. return 0;
  165. }
  166. static int test_aead_cycles(struct aead_request *req, int enc, int blen)
  167. {
  168. unsigned long cycles = 0;
  169. int ret = 0;
  170. int i;
  171. local_irq_disable();
  172. /* Warm-up run. */
  173. for (i = 0; i < 4; i++) {
  174. if (enc)
  175. ret = do_one_aead_op(req, crypto_aead_encrypt(req));
  176. else
  177. ret = do_one_aead_op(req, crypto_aead_decrypt(req));
  178. if (ret)
  179. goto out;
  180. }
  181. /* The real thing. */
  182. for (i = 0; i < 8; i++) {
  183. cycles_t start, end;
  184. start = get_cycles();
  185. if (enc)
  186. ret = do_one_aead_op(req, crypto_aead_encrypt(req));
  187. else
  188. ret = do_one_aead_op(req, crypto_aead_decrypt(req));
  189. end = get_cycles();
  190. if (ret)
  191. goto out;
  192. cycles += end - start;
  193. }
  194. out:
  195. local_irq_enable();
  196. if (ret == 0)
  197. printk("1 operation in %lu cycles (%d bytes)\n",
  198. (cycles + 4) / 8, blen);
  199. return ret;
  200. }
  201. static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
  202. static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
  203. #define XBUFSIZE 8
  204. #define MAX_IVLEN 32
  205. static int testmgr_alloc_buf(char *buf[XBUFSIZE])
  206. {
  207. int i;
  208. for (i = 0; i < XBUFSIZE; i++) {
  209. buf[i] = (void *)__get_free_page(GFP_KERNEL);
  210. if (!buf[i])
  211. goto err_free_buf;
  212. }
  213. return 0;
  214. err_free_buf:
  215. while (i-- > 0)
  216. free_page((unsigned long)buf[i]);
  217. return -ENOMEM;
  218. }
  219. static void testmgr_free_buf(char *buf[XBUFSIZE])
  220. {
  221. int i;
  222. for (i = 0; i < XBUFSIZE; i++)
  223. free_page((unsigned long)buf[i]);
  224. }
  225. static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],
  226. unsigned int buflen)
  227. {
  228. int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
  229. int k, rem;
  230. if (np > XBUFSIZE) {
  231. rem = PAGE_SIZE;
  232. np = XBUFSIZE;
  233. } else {
  234. rem = buflen % PAGE_SIZE;
  235. }
  236. sg_init_table(sg, np + 1);
  237. if (rem)
  238. np--;
  239. for (k = 0; k < np; k++)
  240. sg_set_buf(&sg[k + 1], xbuf[k], PAGE_SIZE);
  241. if (rem)
  242. sg_set_buf(&sg[k + 1], xbuf[k], rem);
  243. }
  244. static void test_aead_speed(const char *algo, int enc, unsigned int secs,
  245. struct aead_speed_template *template,
  246. unsigned int tcount, u8 authsize,
  247. unsigned int aad_size, u8 *keysize)
  248. {
  249. unsigned int i, j;
  250. struct crypto_aead *tfm;
  251. int ret = -ENOMEM;
  252. const char *key;
  253. struct aead_request *req;
  254. struct scatterlist *sg;
  255. struct scatterlist *sgout;
  256. const char *e;
  257. void *assoc;
  258. char *iv;
  259. char *xbuf[XBUFSIZE];
  260. char *xoutbuf[XBUFSIZE];
  261. char *axbuf[XBUFSIZE];
  262. unsigned int *b_size;
  263. unsigned int iv_len;
  264. struct tcrypt_result result;
  265. iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
  266. if (!iv)
  267. return;
  268. if (aad_size >= PAGE_SIZE) {
  269. pr_err("associate data length (%u) too big\n", aad_size);
  270. goto out_noxbuf;
  271. }
  272. if (enc == ENCRYPT)
  273. e = "encryption";
  274. else
  275. e = "decryption";
  276. if (testmgr_alloc_buf(xbuf))
  277. goto out_noxbuf;
  278. if (testmgr_alloc_buf(axbuf))
  279. goto out_noaxbuf;
  280. if (testmgr_alloc_buf(xoutbuf))
  281. goto out_nooutbuf;
  282. sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL);
  283. if (!sg)
  284. goto out_nosg;
  285. sgout = &sg[9];
  286. tfm = crypto_alloc_aead(algo, 0, 0);
  287. if (IS_ERR(tfm)) {
  288. pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
  289. PTR_ERR(tfm));
  290. goto out_notfm;
  291. }
  292. init_completion(&result.completion);
  293. printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
  294. get_driver_name(crypto_aead, tfm), e);
  295. req = aead_request_alloc(tfm, GFP_KERNEL);
  296. if (!req) {
  297. pr_err("alg: aead: Failed to allocate request for %s\n",
  298. algo);
  299. goto out_noreq;
  300. }
  301. aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  302. tcrypt_complete, &result);
  303. i = 0;
  304. do {
  305. b_size = aead_sizes;
  306. do {
  307. assoc = axbuf[0];
  308. memset(assoc, 0xff, aad_size);
  309. if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
  310. pr_err("template (%u) too big for tvmem (%lu)\n",
  311. *keysize + *b_size,
  312. TVMEMSIZE * PAGE_SIZE);
  313. goto out;
  314. }
  315. key = tvmem[0];
  316. for (j = 0; j < tcount; j++) {
  317. if (template[j].klen == *keysize) {
  318. key = template[j].key;
  319. break;
  320. }
  321. }
  322. ret = crypto_aead_setkey(tfm, key, *keysize);
  323. ret = crypto_aead_setauthsize(tfm, authsize);
  324. iv_len = crypto_aead_ivsize(tfm);
  325. if (iv_len)
  326. memset(iv, 0xff, iv_len);
  327. crypto_aead_clear_flags(tfm, ~0);
  328. printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
  329. i, *keysize * 8, *b_size);
  330. memset(tvmem[0], 0xff, PAGE_SIZE);
  331. if (ret) {
  332. pr_err("setkey() failed flags=%x\n",
  333. crypto_aead_get_flags(tfm));
  334. goto out;
  335. }
  336. sg_init_aead(sg, xbuf,
  337. *b_size + (enc ? 0 : authsize));
  338. sg_init_aead(sgout, xoutbuf,
  339. *b_size + (enc ? authsize : 0));
  340. sg_set_buf(&sg[0], assoc, aad_size);
  341. sg_set_buf(&sgout[0], assoc, aad_size);
  342. aead_request_set_crypt(req, sg, sgout,
  343. *b_size + (enc ? 0 : authsize),
  344. iv);
  345. aead_request_set_ad(req, aad_size);
  346. if (secs)
  347. ret = test_aead_jiffies(req, enc, *b_size,
  348. secs);
  349. else
  350. ret = test_aead_cycles(req, enc, *b_size);
  351. if (ret) {
  352. pr_err("%s() failed return code=%d\n", e, ret);
  353. break;
  354. }
  355. b_size++;
  356. i++;
  357. } while (*b_size);
  358. keysize++;
  359. } while (*keysize);
  360. out:
  361. aead_request_free(req);
  362. out_noreq:
  363. crypto_free_aead(tfm);
  364. out_notfm:
  365. kfree(sg);
  366. out_nosg:
  367. testmgr_free_buf(xoutbuf);
  368. out_nooutbuf:
  369. testmgr_free_buf(axbuf);
  370. out_noaxbuf:
  371. testmgr_free_buf(xbuf);
  372. out_noxbuf:
  373. kfree(iv);
  374. return;
  375. }
  376. static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
  377. struct cipher_speed_template *template,
  378. unsigned int tcount, u8 *keysize)
  379. {
  380. unsigned int ret, i, j, iv_len;
  381. const char *key;
  382. char iv[128];
  383. struct crypto_blkcipher *tfm;
  384. struct blkcipher_desc desc;
  385. const char *e;
  386. u32 *b_size;
  387. if (enc == ENCRYPT)
  388. e = "encryption";
  389. else
  390. e = "decryption";
  391. tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
  392. if (IS_ERR(tfm)) {
  393. printk("failed to load transform for %s: %ld\n", algo,
  394. PTR_ERR(tfm));
  395. return;
  396. }
  397. desc.tfm = tfm;
  398. desc.flags = 0;
  399. printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
  400. get_driver_name(crypto_blkcipher, tfm), e);
  401. i = 0;
  402. do {
  403. b_size = block_sizes;
  404. do {
  405. struct scatterlist sg[TVMEMSIZE];
  406. if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
  407. printk("template (%u) too big for "
  408. "tvmem (%lu)\n", *keysize + *b_size,
  409. TVMEMSIZE * PAGE_SIZE);
  410. goto out;
  411. }
  412. printk("test %u (%d bit key, %d byte blocks): ", i,
  413. *keysize * 8, *b_size);
  414. memset(tvmem[0], 0xff, PAGE_SIZE);
  415. /* set key, plain text and IV */
  416. key = tvmem[0];
  417. for (j = 0; j < tcount; j++) {
  418. if (template[j].klen == *keysize) {
  419. key = template[j].key;
  420. break;
  421. }
  422. }
  423. ret = crypto_blkcipher_setkey(tfm, key, *keysize);
  424. if (ret) {
  425. printk("setkey() failed flags=%x\n",
  426. crypto_blkcipher_get_flags(tfm));
  427. goto out;
  428. }
  429. sg_init_table(sg, TVMEMSIZE);
  430. sg_set_buf(sg, tvmem[0] + *keysize,
  431. PAGE_SIZE - *keysize);
  432. for (j = 1; j < TVMEMSIZE; j++) {
  433. sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
  434. memset (tvmem[j], 0xff, PAGE_SIZE);
  435. }
  436. iv_len = crypto_blkcipher_ivsize(tfm);
  437. if (iv_len) {
  438. memset(&iv, 0xff, iv_len);
  439. crypto_blkcipher_set_iv(tfm, iv, iv_len);
  440. }
  441. if (secs)
  442. ret = test_cipher_jiffies(&desc, enc, sg,
  443. *b_size, secs);
  444. else
  445. ret = test_cipher_cycles(&desc, enc, sg,
  446. *b_size);
  447. if (ret) {
  448. printk("%s() failed flags=%x\n", e, desc.flags);
  449. break;
  450. }
  451. b_size++;
  452. i++;
  453. } while (*b_size);
  454. keysize++;
  455. } while (*keysize);
  456. out:
  457. crypto_free_blkcipher(tfm);
  458. }
  459. static int test_hash_jiffies_digest(struct hash_desc *desc,
  460. struct scatterlist *sg, int blen,
  461. char *out, int secs)
  462. {
  463. unsigned long start, end;
  464. int bcount;
  465. int ret;
  466. for (start = jiffies, end = start + secs * HZ, bcount = 0;
  467. time_before(jiffies, end); bcount++) {
  468. ret = crypto_hash_digest(desc, sg, blen, out);
  469. if (ret)
  470. return ret;
  471. }
  472. printk("%6u opers/sec, %9lu bytes/sec\n",
  473. bcount / secs, ((long)bcount * blen) / secs);
  474. return 0;
  475. }
  476. static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg,
  477. int blen, int plen, char *out, int secs)
  478. {
  479. unsigned long start, end;
  480. int bcount, pcount;
  481. int ret;
  482. if (plen == blen)
  483. return test_hash_jiffies_digest(desc, sg, blen, out, secs);
  484. for (start = jiffies, end = start + secs * HZ, bcount = 0;
  485. time_before(jiffies, end); bcount++) {
  486. ret = crypto_hash_init(desc);
  487. if (ret)
  488. return ret;
  489. for (pcount = 0; pcount < blen; pcount += plen) {
  490. ret = crypto_hash_update(desc, sg, plen);
  491. if (ret)
  492. return ret;
  493. }
  494. /* we assume there is enough space in 'out' for the result */
  495. ret = crypto_hash_final(desc, out);
  496. if (ret)
  497. return ret;
  498. }
  499. printk("%6u opers/sec, %9lu bytes/sec\n",
  500. bcount / secs, ((long)bcount * blen) / secs);
  501. return 0;
  502. }
  503. static int test_hash_cycles_digest(struct hash_desc *desc,
  504. struct scatterlist *sg, int blen, char *out)
  505. {
  506. unsigned long cycles = 0;
  507. int i;
  508. int ret;
  509. local_irq_disable();
  510. /* Warm-up run. */
  511. for (i = 0; i < 4; i++) {
  512. ret = crypto_hash_digest(desc, sg, blen, out);
  513. if (ret)
  514. goto out;
  515. }
  516. /* The real thing. */
  517. for (i = 0; i < 8; i++) {
  518. cycles_t start, end;
  519. start = get_cycles();
  520. ret = crypto_hash_digest(desc, sg, blen, out);
  521. if (ret)
  522. goto out;
  523. end = get_cycles();
  524. cycles += end - start;
  525. }
  526. out:
  527. local_irq_enable();
  528. if (ret)
  529. return ret;
  530. printk("%6lu cycles/operation, %4lu cycles/byte\n",
  531. cycles / 8, cycles / (8 * blen));
  532. return 0;
  533. }
  534. static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg,
  535. int blen, int plen, char *out)
  536. {
  537. unsigned long cycles = 0;
  538. int i, pcount;
  539. int ret;
  540. if (plen == blen)
  541. return test_hash_cycles_digest(desc, sg, blen, out);
  542. local_irq_disable();
  543. /* Warm-up run. */
  544. for (i = 0; i < 4; i++) {
  545. ret = crypto_hash_init(desc);
  546. if (ret)
  547. goto out;
  548. for (pcount = 0; pcount < blen; pcount += plen) {
  549. ret = crypto_hash_update(desc, sg, plen);
  550. if (ret)
  551. goto out;
  552. }
  553. ret = crypto_hash_final(desc, out);
  554. if (ret)
  555. goto out;
  556. }
  557. /* The real thing. */
  558. for (i = 0; i < 8; i++) {
  559. cycles_t start, end;
  560. start = get_cycles();
  561. ret = crypto_hash_init(desc);
  562. if (ret)
  563. goto out;
  564. for (pcount = 0; pcount < blen; pcount += plen) {
  565. ret = crypto_hash_update(desc, sg, plen);
  566. if (ret)
  567. goto out;
  568. }
  569. ret = crypto_hash_final(desc, out);
  570. if (ret)
  571. goto out;
  572. end = get_cycles();
  573. cycles += end - start;
  574. }
  575. out:
  576. local_irq_enable();
  577. if (ret)
  578. return ret;
  579. printk("%6lu cycles/operation, %4lu cycles/byte\n",
  580. cycles / 8, cycles / (8 * blen));
  581. return 0;
  582. }
  583. static void test_hash_sg_init(struct scatterlist *sg)
  584. {
  585. int i;
  586. sg_init_table(sg, TVMEMSIZE);
  587. for (i = 0; i < TVMEMSIZE; i++) {
  588. sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
  589. memset(tvmem[i], 0xff, PAGE_SIZE);
  590. }
  591. }
  592. static void test_hash_speed(const char *algo, unsigned int secs,
  593. struct hash_speed *speed)
  594. {
  595. struct scatterlist sg[TVMEMSIZE];
  596. struct crypto_hash *tfm;
  597. struct hash_desc desc;
  598. static char output[1024];
  599. int i;
  600. int ret;
  601. tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
  602. if (IS_ERR(tfm)) {
  603. printk(KERN_ERR "failed to load transform for %s: %ld\n", algo,
  604. PTR_ERR(tfm));
  605. return;
  606. }
  607. printk(KERN_INFO "\ntesting speed of %s (%s)\n", algo,
  608. get_driver_name(crypto_hash, tfm));
  609. desc.tfm = tfm;
  610. desc.flags = 0;
  611. if (crypto_hash_digestsize(tfm) > sizeof(output)) {
  612. printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n",
  613. crypto_hash_digestsize(tfm), sizeof(output));
  614. goto out;
  615. }
  616. test_hash_sg_init(sg);
  617. for (i = 0; speed[i].blen != 0; i++) {
  618. if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
  619. printk(KERN_ERR
  620. "template (%u) too big for tvmem (%lu)\n",
  621. speed[i].blen, TVMEMSIZE * PAGE_SIZE);
  622. goto out;
  623. }
  624. if (speed[i].klen)
  625. crypto_hash_setkey(tfm, tvmem[0], speed[i].klen);
  626. printk(KERN_INFO "test%3u "
  627. "(%5u byte blocks,%5u bytes per update,%4u updates): ",
  628. i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
  629. if (secs)
  630. ret = test_hash_jiffies(&desc, sg, speed[i].blen,
  631. speed[i].plen, output, secs);
  632. else
  633. ret = test_hash_cycles(&desc, sg, speed[i].blen,
  634. speed[i].plen, output);
  635. if (ret) {
  636. printk(KERN_ERR "hashing failed ret=%d\n", ret);
  637. break;
  638. }
  639. }
  640. out:
  641. crypto_free_hash(tfm);
  642. }
  643. static inline int do_one_ahash_op(struct ahash_request *req, int ret)
  644. {
  645. if (ret == -EINPROGRESS || ret == -EBUSY) {
  646. struct tcrypt_result *tr = req->base.data;
  647. wait_for_completion(&tr->completion);
  648. reinit_completion(&tr->completion);
  649. ret = tr->err;
  650. }
  651. return ret;
  652. }
  653. static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
  654. char *out, int secs)
  655. {
  656. unsigned long start, end;
  657. int bcount;
  658. int ret;
  659. for (start = jiffies, end = start + secs * HZ, bcount = 0;
  660. time_before(jiffies, end); bcount++) {
  661. ret = do_one_ahash_op(req, crypto_ahash_digest(req));
  662. if (ret)
  663. return ret;
  664. }
  665. printk("%6u opers/sec, %9lu bytes/sec\n",
  666. bcount / secs, ((long)bcount * blen) / secs);
  667. return 0;
  668. }
  669. static int test_ahash_jiffies(struct ahash_request *req, int blen,
  670. int plen, char *out, int secs)
  671. {
  672. unsigned long start, end;
  673. int bcount, pcount;
  674. int ret;
  675. if (plen == blen)
  676. return test_ahash_jiffies_digest(req, blen, out, secs);
  677. for (start = jiffies, end = start + secs * HZ, bcount = 0;
  678. time_before(jiffies, end); bcount++) {
  679. ret = do_one_ahash_op(req, crypto_ahash_init(req));
  680. if (ret)
  681. return ret;
  682. for (pcount = 0; pcount < blen; pcount += plen) {
  683. ret = do_one_ahash_op(req, crypto_ahash_update(req));
  684. if (ret)
  685. return ret;
  686. }
  687. /* we assume there is enough space in 'out' for the result */
  688. ret = do_one_ahash_op(req, crypto_ahash_final(req));
  689. if (ret)
  690. return ret;
  691. }
  692. pr_cont("%6u opers/sec, %9lu bytes/sec\n",
  693. bcount / secs, ((long)bcount * blen) / secs);
  694. return 0;
  695. }
  696. static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
  697. char *out)
  698. {
  699. unsigned long cycles = 0;
  700. int ret, i;
  701. /* Warm-up run. */
  702. for (i = 0; i < 4; i++) {
  703. ret = do_one_ahash_op(req, crypto_ahash_digest(req));
  704. if (ret)
  705. goto out;
  706. }
  707. /* The real thing. */
  708. for (i = 0; i < 8; i++) {
  709. cycles_t start, end;
  710. start = get_cycles();
  711. ret = do_one_ahash_op(req, crypto_ahash_digest(req));
  712. if (ret)
  713. goto out;
  714. end = get_cycles();
  715. cycles += end - start;
  716. }
  717. out:
  718. if (ret)
  719. return ret;
  720. pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
  721. cycles / 8, cycles / (8 * blen));
  722. return 0;
  723. }
  724. static int test_ahash_cycles(struct ahash_request *req, int blen,
  725. int plen, char *out)
  726. {
  727. unsigned long cycles = 0;
  728. int i, pcount, ret;
  729. if (plen == blen)
  730. return test_ahash_cycles_digest(req, blen, out);
  731. /* Warm-up run. */
  732. for (i = 0; i < 4; i++) {
  733. ret = do_one_ahash_op(req, crypto_ahash_init(req));
  734. if (ret)
  735. goto out;
  736. for (pcount = 0; pcount < blen; pcount += plen) {
  737. ret = do_one_ahash_op(req, crypto_ahash_update(req));
  738. if (ret)
  739. goto out;
  740. }
  741. ret = do_one_ahash_op(req, crypto_ahash_final(req));
  742. if (ret)
  743. goto out;
  744. }
  745. /* The real thing. */
  746. for (i = 0; i < 8; i++) {
  747. cycles_t start, end;
  748. start = get_cycles();
  749. ret = do_one_ahash_op(req, crypto_ahash_init(req));
  750. if (ret)
  751. goto out;
  752. for (pcount = 0; pcount < blen; pcount += plen) {
  753. ret = do_one_ahash_op(req, crypto_ahash_update(req));
  754. if (ret)
  755. goto out;
  756. }
  757. ret = do_one_ahash_op(req, crypto_ahash_final(req));
  758. if (ret)
  759. goto out;
  760. end = get_cycles();
  761. cycles += end - start;
  762. }
  763. out:
  764. if (ret)
  765. return ret;
  766. pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
  767. cycles / 8, cycles / (8 * blen));
  768. return 0;
  769. }
  770. static void test_ahash_speed(const char *algo, unsigned int secs,
  771. struct hash_speed *speed)
  772. {
  773. struct scatterlist sg[TVMEMSIZE];
  774. struct tcrypt_result tresult;
  775. struct ahash_request *req;
  776. struct crypto_ahash *tfm;
  777. char *output;
  778. int i, ret;
  779. tfm = crypto_alloc_ahash(algo, 0, 0);
  780. if (IS_ERR(tfm)) {
  781. pr_err("failed to load transform for %s: %ld\n",
  782. algo, PTR_ERR(tfm));
  783. return;
  784. }
  785. printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
  786. get_driver_name(crypto_ahash, tfm));
  787. if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) {
  788. pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm),
  789. MAX_DIGEST_SIZE);
  790. goto out;
  791. }
  792. test_hash_sg_init(sg);
  793. req = ahash_request_alloc(tfm, GFP_KERNEL);
  794. if (!req) {
  795. pr_err("ahash request allocation failure\n");
  796. goto out;
  797. }
  798. init_completion(&tresult.completion);
  799. ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  800. tcrypt_complete, &tresult);
  801. output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
  802. if (!output)
  803. goto out_nomem;
  804. for (i = 0; speed[i].blen != 0; i++) {
  805. if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
  806. pr_err("template (%u) too big for tvmem (%lu)\n",
  807. speed[i].blen, TVMEMSIZE * PAGE_SIZE);
  808. break;
  809. }
  810. pr_info("test%3u "
  811. "(%5u byte blocks,%5u bytes per update,%4u updates): ",
  812. i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
  813. ahash_request_set_crypt(req, sg, output, speed[i].plen);
  814. if (secs)
  815. ret = test_ahash_jiffies(req, speed[i].blen,
  816. speed[i].plen, output, secs);
  817. else
  818. ret = test_ahash_cycles(req, speed[i].blen,
  819. speed[i].plen, output);
  820. if (ret) {
  821. pr_err("hashing failed ret=%d\n", ret);
  822. break;
  823. }
  824. }
  825. kfree(output);
  826. out_nomem:
  827. ahash_request_free(req);
  828. out:
  829. crypto_free_ahash(tfm);
  830. }
  831. static inline int do_one_acipher_op(struct ablkcipher_request *req, int ret)
  832. {
  833. if (ret == -EINPROGRESS || ret == -EBUSY) {
  834. struct tcrypt_result *tr = req->base.data;
  835. wait_for_completion(&tr->completion);
  836. reinit_completion(&tr->completion);
  837. ret = tr->err;
  838. }
  839. return ret;
  840. }
  841. static int test_acipher_jiffies(struct ablkcipher_request *req, int enc,
  842. int blen, int secs)
  843. {
  844. unsigned long start, end;
  845. int bcount;
  846. int ret;
  847. for (start = jiffies, end = start + secs * HZ, bcount = 0;
  848. time_before(jiffies, end); bcount++) {
  849. if (enc)
  850. ret = do_one_acipher_op(req,
  851. crypto_ablkcipher_encrypt(req));
  852. else
  853. ret = do_one_acipher_op(req,
  854. crypto_ablkcipher_decrypt(req));
  855. if (ret)
  856. return ret;
  857. }
  858. pr_cont("%d operations in %d seconds (%ld bytes)\n",
  859. bcount, secs, (long)bcount * blen);
  860. return 0;
  861. }
  862. static int test_acipher_cycles(struct ablkcipher_request *req, int enc,
  863. int blen)
  864. {
  865. unsigned long cycles = 0;
  866. int ret = 0;
  867. int i;
  868. /* Warm-up run. */
  869. for (i = 0; i < 4; i++) {
  870. if (enc)
  871. ret = do_one_acipher_op(req,
  872. crypto_ablkcipher_encrypt(req));
  873. else
  874. ret = do_one_acipher_op(req,
  875. crypto_ablkcipher_decrypt(req));
  876. if (ret)
  877. goto out;
  878. }
  879. /* The real thing. */
  880. for (i = 0; i < 8; i++) {
  881. cycles_t start, end;
  882. start = get_cycles();
  883. if (enc)
  884. ret = do_one_acipher_op(req,
  885. crypto_ablkcipher_encrypt(req));
  886. else
  887. ret = do_one_acipher_op(req,
  888. crypto_ablkcipher_decrypt(req));
  889. end = get_cycles();
  890. if (ret)
  891. goto out;
  892. cycles += end - start;
  893. }
  894. out:
  895. if (ret == 0)
  896. pr_cont("1 operation in %lu cycles (%d bytes)\n",
  897. (cycles + 4) / 8, blen);
  898. return ret;
  899. }
  900. static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
  901. struct cipher_speed_template *template,
  902. unsigned int tcount, u8 *keysize)
  903. {
  904. unsigned int ret, i, j, k, iv_len;
  905. struct tcrypt_result tresult;
  906. const char *key;
  907. char iv[128];
  908. struct ablkcipher_request *req;
  909. struct crypto_ablkcipher *tfm;
  910. const char *e;
  911. u32 *b_size;
  912. if (enc == ENCRYPT)
  913. e = "encryption";
  914. else
  915. e = "decryption";
  916. init_completion(&tresult.completion);
  917. tfm = crypto_alloc_ablkcipher(algo, 0, 0);
  918. if (IS_ERR(tfm)) {
  919. pr_err("failed to load transform for %s: %ld\n", algo,
  920. PTR_ERR(tfm));
  921. return;
  922. }
  923. pr_info("\ntesting speed of async %s (%s) %s\n", algo,
  924. get_driver_name(crypto_ablkcipher, tfm), e);
  925. req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
  926. if (!req) {
  927. pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
  928. algo);
  929. goto out;
  930. }
  931. ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  932. tcrypt_complete, &tresult);
  933. i = 0;
  934. do {
  935. b_size = block_sizes;
  936. do {
  937. struct scatterlist sg[TVMEMSIZE];
  938. if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
  939. pr_err("template (%u) too big for "
  940. "tvmem (%lu)\n", *keysize + *b_size,
  941. TVMEMSIZE * PAGE_SIZE);
  942. goto out_free_req;
  943. }
  944. pr_info("test %u (%d bit key, %d byte blocks): ", i,
  945. *keysize * 8, *b_size);
  946. memset(tvmem[0], 0xff, PAGE_SIZE);
  947. /* set key, plain text and IV */
  948. key = tvmem[0];
  949. for (j = 0; j < tcount; j++) {
  950. if (template[j].klen == *keysize) {
  951. key = template[j].key;
  952. break;
  953. }
  954. }
  955. crypto_ablkcipher_clear_flags(tfm, ~0);
  956. ret = crypto_ablkcipher_setkey(tfm, key, *keysize);
  957. if (ret) {
  958. pr_err("setkey() failed flags=%x\n",
  959. crypto_ablkcipher_get_flags(tfm));
  960. goto out_free_req;
  961. }
  962. k = *keysize + *b_size;
  963. sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
  964. if (k > PAGE_SIZE) {
  965. sg_set_buf(sg, tvmem[0] + *keysize,
  966. PAGE_SIZE - *keysize);
  967. k -= PAGE_SIZE;
  968. j = 1;
  969. while (k > PAGE_SIZE) {
  970. sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
  971. memset(tvmem[j], 0xff, PAGE_SIZE);
  972. j++;
  973. k -= PAGE_SIZE;
  974. }
  975. sg_set_buf(sg + j, tvmem[j], k);
  976. memset(tvmem[j], 0xff, k);
  977. } else {
  978. sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
  979. }
  980. iv_len = crypto_ablkcipher_ivsize(tfm);
  981. if (iv_len)
  982. memset(&iv, 0xff, iv_len);
  983. ablkcipher_request_set_crypt(req, sg, sg, *b_size, iv);
  984. if (secs)
  985. ret = test_acipher_jiffies(req, enc,
  986. *b_size, secs);
  987. else
  988. ret = test_acipher_cycles(req, enc,
  989. *b_size);
  990. if (ret) {
  991. pr_err("%s() failed flags=%x\n", e,
  992. crypto_ablkcipher_get_flags(tfm));
  993. break;
  994. }
  995. b_size++;
  996. i++;
  997. } while (*b_size);
  998. keysize++;
  999. } while (*keysize);
  1000. out_free_req:
  1001. ablkcipher_request_free(req);
  1002. out:
  1003. crypto_free_ablkcipher(tfm);
  1004. }
  1005. static void test_available(void)
  1006. {
  1007. char **name = check;
  1008. while (*name) {
  1009. printk("alg %s ", *name);
  1010. printk(crypto_has_alg(*name, 0, 0) ?
  1011. "found\n" : "not found\n");
  1012. name++;
  1013. }
  1014. }
  1015. static inline int tcrypt_test(const char *alg)
  1016. {
  1017. int ret;
  1018. ret = alg_test(alg, alg, 0, 0);
  1019. /* non-fips algs return -EINVAL in fips mode */
  1020. if (fips_enabled && ret == -EINVAL)
  1021. ret = 0;
  1022. return ret;
  1023. }
  1024. static int do_test(const char *alg, u32 type, u32 mask, int m)
  1025. {
  1026. int i;
  1027. int ret = 0;
  1028. switch (m) {
  1029. case 0:
  1030. if (alg) {
  1031. if (!crypto_has_alg(alg, type,
  1032. mask ?: CRYPTO_ALG_TYPE_MASK))
  1033. ret = -ENOENT;
  1034. break;
  1035. }
  1036. for (i = 1; i < 200; i++)
  1037. ret += do_test(NULL, 0, 0, i);
  1038. break;
  1039. case 1:
  1040. ret += tcrypt_test("md5");
  1041. break;
  1042. case 2:
  1043. ret += tcrypt_test("sha1");
  1044. break;
  1045. case 3:
  1046. ret += tcrypt_test("ecb(des)");
  1047. ret += tcrypt_test("cbc(des)");
  1048. ret += tcrypt_test("ctr(des)");
  1049. break;
  1050. case 4:
  1051. ret += tcrypt_test("ecb(des3_ede)");
  1052. ret += tcrypt_test("cbc(des3_ede)");
  1053. ret += tcrypt_test("ctr(des3_ede)");
  1054. break;
  1055. case 5:
  1056. ret += tcrypt_test("md4");
  1057. break;
  1058. case 6:
  1059. ret += tcrypt_test("sha256");
  1060. break;
  1061. case 7:
  1062. ret += tcrypt_test("ecb(blowfish)");
  1063. ret += tcrypt_test("cbc(blowfish)");
  1064. ret += tcrypt_test("ctr(blowfish)");
  1065. break;
  1066. case 8:
  1067. ret += tcrypt_test("ecb(twofish)");
  1068. ret += tcrypt_test("cbc(twofish)");
  1069. ret += tcrypt_test("ctr(twofish)");
  1070. ret += tcrypt_test("lrw(twofish)");
  1071. ret += tcrypt_test("xts(twofish)");
  1072. break;
  1073. case 9:
  1074. ret += tcrypt_test("ecb(serpent)");
  1075. ret += tcrypt_test("cbc(serpent)");
  1076. ret += tcrypt_test("ctr(serpent)");
  1077. ret += tcrypt_test("lrw(serpent)");
  1078. ret += tcrypt_test("xts(serpent)");
  1079. break;
  1080. case 10:
  1081. ret += tcrypt_test("ecb(aes)");
  1082. ret += tcrypt_test("cbc(aes)");
  1083. ret += tcrypt_test("lrw(aes)");
  1084. ret += tcrypt_test("xts(aes)");
  1085. ret += tcrypt_test("ctr(aes)");
  1086. ret += tcrypt_test("rfc3686(ctr(aes))");
  1087. break;
  1088. case 11:
  1089. ret += tcrypt_test("sha384");
  1090. break;
  1091. case 12:
  1092. ret += tcrypt_test("sha512");
  1093. break;
  1094. case 13:
  1095. ret += tcrypt_test("deflate");
  1096. break;
  1097. case 14:
  1098. ret += tcrypt_test("ecb(cast5)");
  1099. ret += tcrypt_test("cbc(cast5)");
  1100. ret += tcrypt_test("ctr(cast5)");
  1101. break;
  1102. case 15:
  1103. ret += tcrypt_test("ecb(cast6)");
  1104. ret += tcrypt_test("cbc(cast6)");
  1105. ret += tcrypt_test("ctr(cast6)");
  1106. ret += tcrypt_test("lrw(cast6)");
  1107. ret += tcrypt_test("xts(cast6)");
  1108. break;
  1109. case 16:
  1110. ret += tcrypt_test("ecb(arc4)");
  1111. break;
  1112. case 17:
  1113. ret += tcrypt_test("michael_mic");
  1114. break;
  1115. case 18:
  1116. ret += tcrypt_test("crc32c");
  1117. break;
  1118. case 19:
  1119. ret += tcrypt_test("ecb(tea)");
  1120. break;
  1121. case 20:
  1122. ret += tcrypt_test("ecb(xtea)");
  1123. break;
  1124. case 21:
  1125. ret += tcrypt_test("ecb(khazad)");
  1126. break;
  1127. case 22:
  1128. ret += tcrypt_test("wp512");
  1129. break;
  1130. case 23:
  1131. ret += tcrypt_test("wp384");
  1132. break;
  1133. case 24:
  1134. ret += tcrypt_test("wp256");
  1135. break;
  1136. case 25:
  1137. ret += tcrypt_test("ecb(tnepres)");
  1138. break;
  1139. case 26:
  1140. ret += tcrypt_test("ecb(anubis)");
  1141. ret += tcrypt_test("cbc(anubis)");
  1142. break;
  1143. case 27:
  1144. ret += tcrypt_test("tgr192");
  1145. break;
  1146. case 28:
  1147. ret += tcrypt_test("tgr160");
  1148. break;
  1149. case 29:
  1150. ret += tcrypt_test("tgr128");
  1151. break;
  1152. case 30:
  1153. ret += tcrypt_test("ecb(xeta)");
  1154. break;
  1155. case 31:
  1156. ret += tcrypt_test("pcbc(fcrypt)");
  1157. break;
  1158. case 32:
  1159. ret += tcrypt_test("ecb(camellia)");
  1160. ret += tcrypt_test("cbc(camellia)");
  1161. ret += tcrypt_test("ctr(camellia)");
  1162. ret += tcrypt_test("lrw(camellia)");
  1163. ret += tcrypt_test("xts(camellia)");
  1164. break;
  1165. case 33:
  1166. ret += tcrypt_test("sha224");
  1167. break;
  1168. case 34:
  1169. ret += tcrypt_test("salsa20");
  1170. break;
  1171. case 35:
  1172. ret += tcrypt_test("gcm(aes)");
  1173. break;
  1174. case 36:
  1175. ret += tcrypt_test("lzo");
  1176. break;
  1177. case 37:
  1178. ret += tcrypt_test("ccm(aes)");
  1179. break;
  1180. case 38:
  1181. ret += tcrypt_test("cts(cbc(aes))");
  1182. break;
  1183. case 39:
  1184. ret += tcrypt_test("rmd128");
  1185. break;
  1186. case 40:
  1187. ret += tcrypt_test("rmd160");
  1188. break;
  1189. case 41:
  1190. ret += tcrypt_test("rmd256");
  1191. break;
  1192. case 42:
  1193. ret += tcrypt_test("rmd320");
  1194. break;
  1195. case 43:
  1196. ret += tcrypt_test("ecb(seed)");
  1197. break;
  1198. case 44:
  1199. ret += tcrypt_test("zlib");
  1200. break;
  1201. case 45:
  1202. ret += tcrypt_test("rfc4309(ccm(aes))");
  1203. break;
  1204. case 46:
  1205. ret += tcrypt_test("ghash");
  1206. break;
  1207. case 47:
  1208. ret += tcrypt_test("crct10dif");
  1209. break;
  1210. case 100:
  1211. ret += tcrypt_test("hmac(md5)");
  1212. break;
  1213. case 101:
  1214. ret += tcrypt_test("hmac(sha1)");
  1215. break;
  1216. case 102:
  1217. ret += tcrypt_test("hmac(sha256)");
  1218. break;
  1219. case 103:
  1220. ret += tcrypt_test("hmac(sha384)");
  1221. break;
  1222. case 104:
  1223. ret += tcrypt_test("hmac(sha512)");
  1224. break;
  1225. case 105:
  1226. ret += tcrypt_test("hmac(sha224)");
  1227. break;
  1228. case 106:
  1229. ret += tcrypt_test("xcbc(aes)");
  1230. break;
  1231. case 107:
  1232. ret += tcrypt_test("hmac(rmd128)");
  1233. break;
  1234. case 108:
  1235. ret += tcrypt_test("hmac(rmd160)");
  1236. break;
  1237. case 109:
  1238. ret += tcrypt_test("vmac(aes)");
  1239. break;
  1240. case 110:
  1241. ret += tcrypt_test("hmac(crc32)");
  1242. break;
  1243. case 150:
  1244. ret += tcrypt_test("ansi_cprng");
  1245. break;
  1246. case 151:
  1247. ret += tcrypt_test("rfc4106(gcm(aes))");
  1248. break;
  1249. case 152:
  1250. ret += tcrypt_test("rfc4543(gcm(aes))");
  1251. break;
  1252. case 153:
  1253. ret += tcrypt_test("cmac(aes)");
  1254. break;
  1255. case 154:
  1256. ret += tcrypt_test("cmac(des3_ede)");
  1257. break;
  1258. case 155:
  1259. ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
  1260. break;
  1261. case 156:
  1262. ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
  1263. break;
  1264. case 157:
  1265. ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
  1266. break;
  1267. case 181:
  1268. ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
  1269. break;
  1270. case 182:
  1271. ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
  1272. break;
  1273. case 183:
  1274. ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
  1275. break;
  1276. case 184:
  1277. ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
  1278. break;
  1279. case 185:
  1280. ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
  1281. break;
  1282. case 186:
  1283. ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
  1284. break;
  1285. case 187:
  1286. ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
  1287. break;
  1288. case 188:
  1289. ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
  1290. break;
  1291. case 189:
  1292. ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
  1293. break;
  1294. case 190:
  1295. ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
  1296. break;
  1297. case 200:
  1298. test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
  1299. speed_template_16_24_32);
  1300. test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
  1301. speed_template_16_24_32);
  1302. test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
  1303. speed_template_16_24_32);
  1304. test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
  1305. speed_template_16_24_32);
  1306. test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
  1307. speed_template_32_40_48);
  1308. test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
  1309. speed_template_32_40_48);
  1310. test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
  1311. speed_template_32_48_64);
  1312. test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
  1313. speed_template_32_48_64);
  1314. test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
  1315. speed_template_16_24_32);
  1316. test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
  1317. speed_template_16_24_32);
  1318. break;
  1319. case 201:
  1320. test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
  1321. des3_speed_template, DES3_SPEED_VECTORS,
  1322. speed_template_24);
  1323. test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
  1324. des3_speed_template, DES3_SPEED_VECTORS,
  1325. speed_template_24);
  1326. test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
  1327. des3_speed_template, DES3_SPEED_VECTORS,
  1328. speed_template_24);
  1329. test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
  1330. des3_speed_template, DES3_SPEED_VECTORS,
  1331. speed_template_24);
  1332. test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
  1333. des3_speed_template, DES3_SPEED_VECTORS,
  1334. speed_template_24);
  1335. test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
  1336. des3_speed_template, DES3_SPEED_VECTORS,
  1337. speed_template_24);
  1338. break;
  1339. case 202:
  1340. test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
  1341. speed_template_16_24_32);
  1342. test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
  1343. speed_template_16_24_32);
  1344. test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
  1345. speed_template_16_24_32);
  1346. test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
  1347. speed_template_16_24_32);
  1348. test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
  1349. speed_template_16_24_32);
  1350. test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
  1351. speed_template_16_24_32);
  1352. test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
  1353. speed_template_32_40_48);
  1354. test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
  1355. speed_template_32_40_48);
  1356. test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
  1357. speed_template_32_48_64);
  1358. test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
  1359. speed_template_32_48_64);
  1360. break;
  1361. case 203:
  1362. test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
  1363. speed_template_8_32);
  1364. test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
  1365. speed_template_8_32);
  1366. test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
  1367. speed_template_8_32);
  1368. test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
  1369. speed_template_8_32);
  1370. test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
  1371. speed_template_8_32);
  1372. test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
  1373. speed_template_8_32);
  1374. break;
  1375. case 204:
  1376. test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
  1377. speed_template_8);
  1378. test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
  1379. speed_template_8);
  1380. test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
  1381. speed_template_8);
  1382. test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
  1383. speed_template_8);
  1384. break;
  1385. case 205:
  1386. test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
  1387. speed_template_16_24_32);
  1388. test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
  1389. speed_template_16_24_32);
  1390. test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
  1391. speed_template_16_24_32);
  1392. test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
  1393. speed_template_16_24_32);
  1394. test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
  1395. speed_template_16_24_32);
  1396. test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
  1397. speed_template_16_24_32);
  1398. test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
  1399. speed_template_32_40_48);
  1400. test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
  1401. speed_template_32_40_48);
  1402. test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
  1403. speed_template_32_48_64);
  1404. test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
  1405. speed_template_32_48_64);
  1406. break;
  1407. case 206:
  1408. test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
  1409. speed_template_16_32);
  1410. break;
  1411. case 207:
  1412. test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
  1413. speed_template_16_32);
  1414. test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
  1415. speed_template_16_32);
  1416. test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
  1417. speed_template_16_32);
  1418. test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
  1419. speed_template_16_32);
  1420. test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
  1421. speed_template_16_32);
  1422. test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
  1423. speed_template_16_32);
  1424. test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
  1425. speed_template_32_48);
  1426. test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
  1427. speed_template_32_48);
  1428. test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
  1429. speed_template_32_64);
  1430. test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
  1431. speed_template_32_64);
  1432. break;
  1433. case 208:
  1434. test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
  1435. speed_template_8);
  1436. break;
  1437. case 209:
  1438. test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
  1439. speed_template_8_16);
  1440. test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
  1441. speed_template_8_16);
  1442. test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
  1443. speed_template_8_16);
  1444. test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
  1445. speed_template_8_16);
  1446. test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
  1447. speed_template_8_16);
  1448. test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
  1449. speed_template_8_16);
  1450. break;
  1451. case 210:
  1452. test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
  1453. speed_template_16_32);
  1454. test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
  1455. speed_template_16_32);
  1456. test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
  1457. speed_template_16_32);
  1458. test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
  1459. speed_template_16_32);
  1460. test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
  1461. speed_template_16_32);
  1462. test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
  1463. speed_template_16_32);
  1464. test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
  1465. speed_template_32_48);
  1466. test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
  1467. speed_template_32_48);
  1468. test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
  1469. speed_template_32_64);
  1470. test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
  1471. speed_template_32_64);
  1472. break;
  1473. case 211:
  1474. test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
  1475. NULL, 0, 16, 16, aead_speed_template_20);
  1476. test_aead_speed("gcm(aes)", ENCRYPT, sec,
  1477. NULL, 0, 16, 8, aead_speed_template_20);
  1478. break;
  1479. case 212:
  1480. test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
  1481. NULL, 0, 16, 16, aead_speed_template_19);
  1482. break;
  1483. case 213:
  1484. test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
  1485. NULL, 0, 16, 8, aead_speed_template_36);
  1486. break;
  1487. case 214:
  1488. test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
  1489. speed_template_32);
  1490. break;
  1491. case 300:
  1492. if (alg) {
  1493. test_hash_speed(alg, sec, generic_hash_speed_template);
  1494. break;
  1495. }
  1496. /* fall through */
  1497. case 301:
  1498. test_hash_speed("md4", sec, generic_hash_speed_template);
  1499. if (mode > 300 && mode < 400) break;
  1500. case 302:
  1501. test_hash_speed("md5", sec, generic_hash_speed_template);
  1502. if (mode > 300 && mode < 400) break;
  1503. case 303:
  1504. test_hash_speed("sha1", sec, generic_hash_speed_template);
  1505. if (mode > 300 && mode < 400) break;
  1506. case 304:
  1507. test_hash_speed("sha256", sec, generic_hash_speed_template);
  1508. if (mode > 300 && mode < 400) break;
  1509. case 305:
  1510. test_hash_speed("sha384", sec, generic_hash_speed_template);
  1511. if (mode > 300 && mode < 400) break;
  1512. case 306:
  1513. test_hash_speed("sha512", sec, generic_hash_speed_template);
  1514. if (mode > 300 && mode < 400) break;
  1515. case 307:
  1516. test_hash_speed("wp256", sec, generic_hash_speed_template);
  1517. if (mode > 300 && mode < 400) break;
  1518. case 308:
  1519. test_hash_speed("wp384", sec, generic_hash_speed_template);
  1520. if (mode > 300 && mode < 400) break;
  1521. case 309:
  1522. test_hash_speed("wp512", sec, generic_hash_speed_template);
  1523. if (mode > 300 && mode < 400) break;
  1524. case 310:
  1525. test_hash_speed("tgr128", sec, generic_hash_speed_template);
  1526. if (mode > 300 && mode < 400) break;
  1527. case 311:
  1528. test_hash_speed("tgr160", sec, generic_hash_speed_template);
  1529. if (mode > 300 && mode < 400) break;
  1530. case 312:
  1531. test_hash_speed("tgr192", sec, generic_hash_speed_template);
  1532. if (mode > 300 && mode < 400) break;
  1533. case 313:
  1534. test_hash_speed("sha224", sec, generic_hash_speed_template);
  1535. if (mode > 300 && mode < 400) break;
  1536. case 314:
  1537. test_hash_speed("rmd128", sec, generic_hash_speed_template);
  1538. if (mode > 300 && mode < 400) break;
  1539. case 315:
  1540. test_hash_speed("rmd160", sec, generic_hash_speed_template);
  1541. if (mode > 300 && mode < 400) break;
  1542. case 316:
  1543. test_hash_speed("rmd256", sec, generic_hash_speed_template);
  1544. if (mode > 300 && mode < 400) break;
  1545. case 317:
  1546. test_hash_speed("rmd320", sec, generic_hash_speed_template);
  1547. if (mode > 300 && mode < 400) break;
  1548. case 318:
  1549. test_hash_speed("ghash-generic", sec, hash_speed_template_16);
  1550. if (mode > 300 && mode < 400) break;
  1551. case 319:
  1552. test_hash_speed("crc32c", sec, generic_hash_speed_template);
  1553. if (mode > 300 && mode < 400) break;
  1554. case 320:
  1555. test_hash_speed("crct10dif", sec, generic_hash_speed_template);
  1556. if (mode > 300 && mode < 400) break;
  1557. case 321:
  1558. test_hash_speed("poly1305", sec, poly1305_speed_template);
  1559. if (mode > 300 && mode < 400) break;
  1560. case 399:
  1561. break;
  1562. case 400:
  1563. if (alg) {
  1564. test_ahash_speed(alg, sec, generic_hash_speed_template);
  1565. break;
  1566. }
  1567. /* fall through */
  1568. case 401:
  1569. test_ahash_speed("md4", sec, generic_hash_speed_template);
  1570. if (mode > 400 && mode < 500) break;
  1571. case 402:
  1572. test_ahash_speed("md5", sec, generic_hash_speed_template);
  1573. if (mode > 400 && mode < 500) break;
  1574. case 403:
  1575. test_ahash_speed("sha1", sec, generic_hash_speed_template);
  1576. if (mode > 400 && mode < 500) break;
  1577. case 404:
  1578. test_ahash_speed("sha256", sec, generic_hash_speed_template);
  1579. if (mode > 400 && mode < 500) break;
  1580. case 405:
  1581. test_ahash_speed("sha384", sec, generic_hash_speed_template);
  1582. if (mode > 400 && mode < 500) break;
  1583. case 406:
  1584. test_ahash_speed("sha512", sec, generic_hash_speed_template);
  1585. if (mode > 400 && mode < 500) break;
  1586. case 407:
  1587. test_ahash_speed("wp256", sec, generic_hash_speed_template);
  1588. if (mode > 400 && mode < 500) break;
  1589. case 408:
  1590. test_ahash_speed("wp384", sec, generic_hash_speed_template);
  1591. if (mode > 400 && mode < 500) break;
  1592. case 409:
  1593. test_ahash_speed("wp512", sec, generic_hash_speed_template);
  1594. if (mode > 400 && mode < 500) break;
  1595. case 410:
  1596. test_ahash_speed("tgr128", sec, generic_hash_speed_template);
  1597. if (mode > 400 && mode < 500) break;
  1598. case 411:
  1599. test_ahash_speed("tgr160", sec, generic_hash_speed_template);
  1600. if (mode > 400 && mode < 500) break;
  1601. case 412:
  1602. test_ahash_speed("tgr192", sec, generic_hash_speed_template);
  1603. if (mode > 400 && mode < 500) break;
  1604. case 413:
  1605. test_ahash_speed("sha224", sec, generic_hash_speed_template);
  1606. if (mode > 400 && mode < 500) break;
  1607. case 414:
  1608. test_ahash_speed("rmd128", sec, generic_hash_speed_template);
  1609. if (mode > 400 && mode < 500) break;
  1610. case 415:
  1611. test_ahash_speed("rmd160", sec, generic_hash_speed_template);
  1612. if (mode > 400 && mode < 500) break;
  1613. case 416:
  1614. test_ahash_speed("rmd256", sec, generic_hash_speed_template);
  1615. if (mode > 400 && mode < 500) break;
  1616. case 417:
  1617. test_ahash_speed("rmd320", sec, generic_hash_speed_template);
  1618. if (mode > 400 && mode < 500) break;
  1619. case 499:
  1620. break;
  1621. case 500:
  1622. test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
  1623. speed_template_16_24_32);
  1624. test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
  1625. speed_template_16_24_32);
  1626. test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
  1627. speed_template_16_24_32);
  1628. test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
  1629. speed_template_16_24_32);
  1630. test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
  1631. speed_template_32_40_48);
  1632. test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
  1633. speed_template_32_40_48);
  1634. test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
  1635. speed_template_32_48_64);
  1636. test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
  1637. speed_template_32_48_64);
  1638. test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
  1639. speed_template_16_24_32);
  1640. test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
  1641. speed_template_16_24_32);
  1642. test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
  1643. speed_template_16_24_32);
  1644. test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
  1645. speed_template_16_24_32);
  1646. test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
  1647. speed_template_16_24_32);
  1648. test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
  1649. speed_template_16_24_32);
  1650. test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
  1651. speed_template_20_28_36);
  1652. test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
  1653. speed_template_20_28_36);
  1654. break;
  1655. case 501:
  1656. test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
  1657. des3_speed_template, DES3_SPEED_VECTORS,
  1658. speed_template_24);
  1659. test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
  1660. des3_speed_template, DES3_SPEED_VECTORS,
  1661. speed_template_24);
  1662. test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
  1663. des3_speed_template, DES3_SPEED_VECTORS,
  1664. speed_template_24);
  1665. test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
  1666. des3_speed_template, DES3_SPEED_VECTORS,
  1667. speed_template_24);
  1668. test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
  1669. des3_speed_template, DES3_SPEED_VECTORS,
  1670. speed_template_24);
  1671. test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
  1672. des3_speed_template, DES3_SPEED_VECTORS,
  1673. speed_template_24);
  1674. test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
  1675. des3_speed_template, DES3_SPEED_VECTORS,
  1676. speed_template_24);
  1677. test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
  1678. des3_speed_template, DES3_SPEED_VECTORS,
  1679. speed_template_24);
  1680. break;
  1681. case 502:
  1682. test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
  1683. speed_template_8);
  1684. test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
  1685. speed_template_8);
  1686. test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
  1687. speed_template_8);
  1688. test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
  1689. speed_template_8);
  1690. test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
  1691. speed_template_8);
  1692. test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
  1693. speed_template_8);
  1694. test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
  1695. speed_template_8);
  1696. test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
  1697. speed_template_8);
  1698. break;
  1699. case 503:
  1700. test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
  1701. speed_template_16_32);
  1702. test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
  1703. speed_template_16_32);
  1704. test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
  1705. speed_template_16_32);
  1706. test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
  1707. speed_template_16_32);
  1708. test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
  1709. speed_template_16_32);
  1710. test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
  1711. speed_template_16_32);
  1712. test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
  1713. speed_template_32_48);
  1714. test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
  1715. speed_template_32_48);
  1716. test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
  1717. speed_template_32_64);
  1718. test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
  1719. speed_template_32_64);
  1720. break;
  1721. case 504:
  1722. test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
  1723. speed_template_16_24_32);
  1724. test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
  1725. speed_template_16_24_32);
  1726. test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
  1727. speed_template_16_24_32);
  1728. test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
  1729. speed_template_16_24_32);
  1730. test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
  1731. speed_template_16_24_32);
  1732. test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
  1733. speed_template_16_24_32);
  1734. test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
  1735. speed_template_32_40_48);
  1736. test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
  1737. speed_template_32_40_48);
  1738. test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
  1739. speed_template_32_48_64);
  1740. test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
  1741. speed_template_32_48_64);
  1742. break;
  1743. case 505:
  1744. test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
  1745. speed_template_8);
  1746. break;
  1747. case 506:
  1748. test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
  1749. speed_template_8_16);
  1750. test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
  1751. speed_template_8_16);
  1752. test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
  1753. speed_template_8_16);
  1754. test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
  1755. speed_template_8_16);
  1756. test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
  1757. speed_template_8_16);
  1758. test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
  1759. speed_template_8_16);
  1760. break;
  1761. case 507:
  1762. test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
  1763. speed_template_16_32);
  1764. test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
  1765. speed_template_16_32);
  1766. test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
  1767. speed_template_16_32);
  1768. test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
  1769. speed_template_16_32);
  1770. test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
  1771. speed_template_16_32);
  1772. test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
  1773. speed_template_16_32);
  1774. test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
  1775. speed_template_32_48);
  1776. test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
  1777. speed_template_32_48);
  1778. test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
  1779. speed_template_32_64);
  1780. test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
  1781. speed_template_32_64);
  1782. break;
  1783. case 508:
  1784. test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
  1785. speed_template_16_32);
  1786. test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
  1787. speed_template_16_32);
  1788. test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
  1789. speed_template_16_32);
  1790. test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
  1791. speed_template_16_32);
  1792. test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
  1793. speed_template_16_32);
  1794. test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
  1795. speed_template_16_32);
  1796. test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
  1797. speed_template_32_48);
  1798. test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
  1799. speed_template_32_48);
  1800. test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
  1801. speed_template_32_64);
  1802. test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
  1803. speed_template_32_64);
  1804. break;
  1805. case 509:
  1806. test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
  1807. speed_template_8_32);
  1808. test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
  1809. speed_template_8_32);
  1810. test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
  1811. speed_template_8_32);
  1812. test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
  1813. speed_template_8_32);
  1814. test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
  1815. speed_template_8_32);
  1816. test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
  1817. speed_template_8_32);
  1818. break;
  1819. case 1000:
  1820. test_available();
  1821. break;
  1822. }
  1823. return ret;
  1824. }
  1825. static int __init tcrypt_mod_init(void)
  1826. {
  1827. int err = -ENOMEM;
  1828. int i;
  1829. for (i = 0; i < TVMEMSIZE; i++) {
  1830. tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
  1831. if (!tvmem[i])
  1832. goto err_free_tv;
  1833. }
  1834. err = do_test(alg, type, mask, mode);
  1835. if (err) {
  1836. printk(KERN_ERR "tcrypt: one or more tests failed!\n");
  1837. goto err_free_tv;
  1838. }
  1839. /* We intentionaly return -EAGAIN to prevent keeping the module,
  1840. * unless we're running in fips mode. It does all its work from
  1841. * init() and doesn't offer any runtime functionality, but in
  1842. * the fips case, checking for a successful load is helpful.
  1843. * => we don't need it in the memory, do we?
  1844. * -- mludvig
  1845. */
  1846. if (!fips_enabled)
  1847. err = -EAGAIN;
  1848. err_free_tv:
  1849. for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
  1850. free_page((unsigned long)tvmem[i]);
  1851. return err;
  1852. }
  1853. /*
  1854. * If an init function is provided, an exit function must also be provided
  1855. * to allow module unload.
  1856. */
  1857. static void __exit tcrypt_mod_fini(void) { }
  1858. module_init(tcrypt_mod_init);
  1859. module_exit(tcrypt_mod_fini);
  1860. module_param(alg, charp, 0);
  1861. module_param(type, uint, 0);
  1862. module_param(mask, uint, 0);
  1863. module_param(mode, int, 0);
  1864. module_param(sec, uint, 0);
  1865. MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
  1866. "(defaults to zero which uses CPU cycles instead)");
  1867. MODULE_LICENSE("GPL");
  1868. MODULE_DESCRIPTION("Quick & dirty crypto testing module");
  1869. MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");