tcrypt.c 51 KB

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