tcrypt.c 50 KB

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