tcrypt.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117
  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 <[email protected]>
  8. * Copyright (c) 2002 Jean-Francois Dive <[email protected]>
  9. * Copyright (c) 2007 Nokia Siemens Networks
  10. *
  11. * Updated RFC4106 AES-GCM testing.
  12. * Authors: Aidan O'Mahony ([email protected])
  13. * Adrian Hoban <[email protected]>
  14. * Gabriele Paoloni <[email protected]>
  15. * Tadeusz Struk ([email protected])
  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. if (speed[i].klen)
  595. crypto_ahash_setkey(tfm, tvmem[0], speed[i].klen);
  596. pr_info("test%3u "
  597. "(%5u byte blocks,%5u bytes per update,%4u updates): ",
  598. i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
  599. ahash_request_set_crypt(req, sg, output, speed[i].plen);
  600. if (secs)
  601. ret = test_ahash_jiffies(req, speed[i].blen,
  602. speed[i].plen, output, secs);
  603. else
  604. ret = test_ahash_cycles(req, speed[i].blen,
  605. speed[i].plen, output);
  606. if (ret) {
  607. pr_err("hashing failed ret=%d\n", ret);
  608. break;
  609. }
  610. }
  611. kfree(output);
  612. out_nomem:
  613. ahash_request_free(req);
  614. out:
  615. crypto_free_ahash(tfm);
  616. }
  617. static void test_ahash_speed(const char *algo, unsigned int secs,
  618. struct hash_speed *speed)
  619. {
  620. return test_ahash_speed_common(algo, secs, speed, 0);
  621. }
  622. static void test_hash_speed(const char *algo, unsigned int secs,
  623. struct hash_speed *speed)
  624. {
  625. return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC);
  626. }
  627. static inline int do_one_acipher_op(struct skcipher_request *req, int ret)
  628. {
  629. if (ret == -EINPROGRESS || ret == -EBUSY) {
  630. struct tcrypt_result *tr = req->base.data;
  631. wait_for_completion(&tr->completion);
  632. reinit_completion(&tr->completion);
  633. ret = tr->err;
  634. }
  635. return ret;
  636. }
  637. static int test_acipher_jiffies(struct skcipher_request *req, int enc,
  638. int blen, int secs)
  639. {
  640. unsigned long start, end;
  641. int bcount;
  642. int ret;
  643. for (start = jiffies, end = start + secs * HZ, bcount = 0;
  644. time_before(jiffies, end); bcount++) {
  645. if (enc)
  646. ret = do_one_acipher_op(req,
  647. crypto_skcipher_encrypt(req));
  648. else
  649. ret = do_one_acipher_op(req,
  650. crypto_skcipher_decrypt(req));
  651. if (ret)
  652. return ret;
  653. }
  654. pr_cont("%d operations in %d seconds (%ld bytes)\n",
  655. bcount, secs, (long)bcount * blen);
  656. return 0;
  657. }
  658. static int test_acipher_cycles(struct skcipher_request *req, int enc,
  659. int blen)
  660. {
  661. unsigned long cycles = 0;
  662. int ret = 0;
  663. int i;
  664. /* Warm-up run. */
  665. for (i = 0; i < 4; i++) {
  666. if (enc)
  667. ret = do_one_acipher_op(req,
  668. crypto_skcipher_encrypt(req));
  669. else
  670. ret = do_one_acipher_op(req,
  671. crypto_skcipher_decrypt(req));
  672. if (ret)
  673. goto out;
  674. }
  675. /* The real thing. */
  676. for (i = 0; i < 8; i++) {
  677. cycles_t start, end;
  678. start = get_cycles();
  679. if (enc)
  680. ret = do_one_acipher_op(req,
  681. crypto_skcipher_encrypt(req));
  682. else
  683. ret = do_one_acipher_op(req,
  684. crypto_skcipher_decrypt(req));
  685. end = get_cycles();
  686. if (ret)
  687. goto out;
  688. cycles += end - start;
  689. }
  690. out:
  691. if (ret == 0)
  692. pr_cont("1 operation in %lu cycles (%d bytes)\n",
  693. (cycles + 4) / 8, blen);
  694. return ret;
  695. }
  696. static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
  697. struct cipher_speed_template *template,
  698. unsigned int tcount, u8 *keysize, bool async)
  699. {
  700. unsigned int ret, i, j, k, iv_len;
  701. struct tcrypt_result tresult;
  702. const char *key;
  703. char iv[128];
  704. struct skcipher_request *req;
  705. struct crypto_skcipher *tfm;
  706. const char *e;
  707. u32 *b_size;
  708. if (enc == ENCRYPT)
  709. e = "encryption";
  710. else
  711. e = "decryption";
  712. init_completion(&tresult.completion);
  713. tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC);
  714. if (IS_ERR(tfm)) {
  715. pr_err("failed to load transform for %s: %ld\n", algo,
  716. PTR_ERR(tfm));
  717. return;
  718. }
  719. pr_info("\ntesting speed of async %s (%s) %s\n", algo,
  720. get_driver_name(crypto_skcipher, tfm), e);
  721. req = skcipher_request_alloc(tfm, GFP_KERNEL);
  722. if (!req) {
  723. pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
  724. algo);
  725. goto out;
  726. }
  727. skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  728. tcrypt_complete, &tresult);
  729. i = 0;
  730. do {
  731. b_size = block_sizes;
  732. do {
  733. struct scatterlist sg[TVMEMSIZE];
  734. if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
  735. pr_err("template (%u) too big for "
  736. "tvmem (%lu)\n", *keysize + *b_size,
  737. TVMEMSIZE * PAGE_SIZE);
  738. goto out_free_req;
  739. }
  740. pr_info("test %u (%d bit key, %d byte blocks): ", i,
  741. *keysize * 8, *b_size);
  742. memset(tvmem[0], 0xff, PAGE_SIZE);
  743. /* set key, plain text and IV */
  744. key = tvmem[0];
  745. for (j = 0; j < tcount; j++) {
  746. if (template[j].klen == *keysize) {
  747. key = template[j].key;
  748. break;
  749. }
  750. }
  751. crypto_skcipher_clear_flags(tfm, ~0);
  752. ret = crypto_skcipher_setkey(tfm, key, *keysize);
  753. if (ret) {
  754. pr_err("setkey() failed flags=%x\n",
  755. crypto_skcipher_get_flags(tfm));
  756. goto out_free_req;
  757. }
  758. k = *keysize + *b_size;
  759. sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
  760. if (k > PAGE_SIZE) {
  761. sg_set_buf(sg, tvmem[0] + *keysize,
  762. PAGE_SIZE - *keysize);
  763. k -= PAGE_SIZE;
  764. j = 1;
  765. while (k > PAGE_SIZE) {
  766. sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
  767. memset(tvmem[j], 0xff, PAGE_SIZE);
  768. j++;
  769. k -= PAGE_SIZE;
  770. }
  771. sg_set_buf(sg + j, tvmem[j], k);
  772. memset(tvmem[j], 0xff, k);
  773. } else {
  774. sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
  775. }
  776. iv_len = crypto_skcipher_ivsize(tfm);
  777. if (iv_len)
  778. memset(&iv, 0xff, iv_len);
  779. skcipher_request_set_crypt(req, sg, sg, *b_size, iv);
  780. if (secs)
  781. ret = test_acipher_jiffies(req, enc,
  782. *b_size, secs);
  783. else
  784. ret = test_acipher_cycles(req, enc,
  785. *b_size);
  786. if (ret) {
  787. pr_err("%s() failed flags=%x\n", e,
  788. crypto_skcipher_get_flags(tfm));
  789. break;
  790. }
  791. b_size++;
  792. i++;
  793. } while (*b_size);
  794. keysize++;
  795. } while (*keysize);
  796. out_free_req:
  797. skcipher_request_free(req);
  798. out:
  799. crypto_free_skcipher(tfm);
  800. }
  801. static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
  802. struct cipher_speed_template *template,
  803. unsigned int tcount, u8 *keysize)
  804. {
  805. return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
  806. true);
  807. }
  808. static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
  809. struct cipher_speed_template *template,
  810. unsigned int tcount, u8 *keysize)
  811. {
  812. return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
  813. false);
  814. }
  815. static void test_available(void)
  816. {
  817. char **name = check;
  818. while (*name) {
  819. printk("alg %s ", *name);
  820. printk(crypto_has_alg(*name, 0, 0) ?
  821. "found\n" : "not found\n");
  822. name++;
  823. }
  824. }
  825. static inline int tcrypt_test(const char *alg)
  826. {
  827. int ret;
  828. ret = alg_test(alg, alg, 0, 0);
  829. /* non-fips algs return -EINVAL in fips mode */
  830. if (fips_enabled && ret == -EINVAL)
  831. ret = 0;
  832. return ret;
  833. }
  834. static int do_test(const char *alg, u32 type, u32 mask, int m)
  835. {
  836. int i;
  837. int ret = 0;
  838. switch (m) {
  839. case 0:
  840. if (alg) {
  841. if (!crypto_has_alg(alg, type,
  842. mask ?: CRYPTO_ALG_TYPE_MASK))
  843. ret = -ENOENT;
  844. break;
  845. }
  846. for (i = 1; i < 200; i++)
  847. ret += do_test(NULL, 0, 0, i);
  848. break;
  849. case 1:
  850. ret += tcrypt_test("md5");
  851. break;
  852. case 2:
  853. ret += tcrypt_test("sha1");
  854. break;
  855. case 3:
  856. ret += tcrypt_test("ecb(des)");
  857. ret += tcrypt_test("cbc(des)");
  858. ret += tcrypt_test("ctr(des)");
  859. break;
  860. case 4:
  861. ret += tcrypt_test("ecb(des3_ede)");
  862. ret += tcrypt_test("cbc(des3_ede)");
  863. ret += tcrypt_test("ctr(des3_ede)");
  864. break;
  865. case 5:
  866. ret += tcrypt_test("md4");
  867. break;
  868. case 6:
  869. ret += tcrypt_test("sha256");
  870. break;
  871. case 7:
  872. ret += tcrypt_test("ecb(blowfish)");
  873. ret += tcrypt_test("cbc(blowfish)");
  874. ret += tcrypt_test("ctr(blowfish)");
  875. break;
  876. case 8:
  877. ret += tcrypt_test("ecb(twofish)");
  878. ret += tcrypt_test("cbc(twofish)");
  879. ret += tcrypt_test("ctr(twofish)");
  880. ret += tcrypt_test("lrw(twofish)");
  881. ret += tcrypt_test("xts(twofish)");
  882. break;
  883. case 9:
  884. ret += tcrypt_test("ecb(serpent)");
  885. ret += tcrypt_test("cbc(serpent)");
  886. ret += tcrypt_test("ctr(serpent)");
  887. ret += tcrypt_test("lrw(serpent)");
  888. ret += tcrypt_test("xts(serpent)");
  889. break;
  890. case 10:
  891. ret += tcrypt_test("ecb(aes)");
  892. ret += tcrypt_test("cbc(aes)");
  893. ret += tcrypt_test("lrw(aes)");
  894. ret += tcrypt_test("xts(aes)");
  895. ret += tcrypt_test("ctr(aes)");
  896. ret += tcrypt_test("rfc3686(ctr(aes))");
  897. break;
  898. case 11:
  899. ret += tcrypt_test("sha384");
  900. break;
  901. case 12:
  902. ret += tcrypt_test("sha512");
  903. break;
  904. case 13:
  905. ret += tcrypt_test("deflate");
  906. break;
  907. case 14:
  908. ret += tcrypt_test("ecb(cast5)");
  909. ret += tcrypt_test("cbc(cast5)");
  910. ret += tcrypt_test("ctr(cast5)");
  911. break;
  912. case 15:
  913. ret += tcrypt_test("ecb(cast6)");
  914. ret += tcrypt_test("cbc(cast6)");
  915. ret += tcrypt_test("ctr(cast6)");
  916. ret += tcrypt_test("lrw(cast6)");
  917. ret += tcrypt_test("xts(cast6)");
  918. break;
  919. case 16:
  920. ret += tcrypt_test("ecb(arc4)");
  921. break;
  922. case 17:
  923. ret += tcrypt_test("michael_mic");
  924. break;
  925. case 18:
  926. ret += tcrypt_test("crc32c");
  927. break;
  928. case 19:
  929. ret += tcrypt_test("ecb(tea)");
  930. break;
  931. case 20:
  932. ret += tcrypt_test("ecb(xtea)");
  933. break;
  934. case 21:
  935. ret += tcrypt_test("ecb(khazad)");
  936. break;
  937. case 22:
  938. ret += tcrypt_test("wp512");
  939. break;
  940. case 23:
  941. ret += tcrypt_test("wp384");
  942. break;
  943. case 24:
  944. ret += tcrypt_test("wp256");
  945. break;
  946. case 25:
  947. ret += tcrypt_test("ecb(tnepres)");
  948. break;
  949. case 26:
  950. ret += tcrypt_test("ecb(anubis)");
  951. ret += tcrypt_test("cbc(anubis)");
  952. break;
  953. case 27:
  954. ret += tcrypt_test("tgr192");
  955. break;
  956. case 28:
  957. ret += tcrypt_test("tgr160");
  958. break;
  959. case 29:
  960. ret += tcrypt_test("tgr128");
  961. break;
  962. case 30:
  963. ret += tcrypt_test("ecb(xeta)");
  964. break;
  965. case 31:
  966. ret += tcrypt_test("pcbc(fcrypt)");
  967. break;
  968. case 32:
  969. ret += tcrypt_test("ecb(camellia)");
  970. ret += tcrypt_test("cbc(camellia)");
  971. ret += tcrypt_test("ctr(camellia)");
  972. ret += tcrypt_test("lrw(camellia)");
  973. ret += tcrypt_test("xts(camellia)");
  974. break;
  975. case 33:
  976. ret += tcrypt_test("sha224");
  977. break;
  978. case 34:
  979. ret += tcrypt_test("salsa20");
  980. break;
  981. case 35:
  982. ret += tcrypt_test("gcm(aes)");
  983. break;
  984. case 36:
  985. ret += tcrypt_test("lzo");
  986. break;
  987. case 37:
  988. ret += tcrypt_test("ccm(aes)");
  989. break;
  990. case 38:
  991. ret += tcrypt_test("cts(cbc(aes))");
  992. break;
  993. case 39:
  994. ret += tcrypt_test("rmd128");
  995. break;
  996. case 40:
  997. ret += tcrypt_test("rmd160");
  998. break;
  999. case 41:
  1000. ret += tcrypt_test("rmd256");
  1001. break;
  1002. case 42:
  1003. ret += tcrypt_test("rmd320");
  1004. break;
  1005. case 43:
  1006. ret += tcrypt_test("ecb(seed)");
  1007. break;
  1008. case 44:
  1009. ret += tcrypt_test("zlib");
  1010. break;
  1011. case 45:
  1012. ret += tcrypt_test("rfc4309(ccm(aes))");
  1013. break;
  1014. case 46:
  1015. ret += tcrypt_test("ghash");
  1016. break;
  1017. case 47:
  1018. ret += tcrypt_test("crct10dif");
  1019. break;
  1020. case 48:
  1021. ret += tcrypt_test("sha3-224");
  1022. break;
  1023. case 49:
  1024. ret += tcrypt_test("sha3-256");
  1025. break;
  1026. case 50:
  1027. ret += tcrypt_test("sha3-384");
  1028. break;
  1029. case 51:
  1030. ret += tcrypt_test("sha3-512");
  1031. break;
  1032. case 100:
  1033. ret += tcrypt_test("hmac(md5)");
  1034. break;
  1035. case 101:
  1036. ret += tcrypt_test("hmac(sha1)");
  1037. break;
  1038. case 102:
  1039. ret += tcrypt_test("hmac(sha256)");
  1040. break;
  1041. case 103:
  1042. ret += tcrypt_test("hmac(sha384)");
  1043. break;
  1044. case 104:
  1045. ret += tcrypt_test("hmac(sha512)");
  1046. break;
  1047. case 105:
  1048. ret += tcrypt_test("hmac(sha224)");
  1049. break;
  1050. case 106:
  1051. ret += tcrypt_test("xcbc(aes)");
  1052. break;
  1053. case 107:
  1054. ret += tcrypt_test("hmac(rmd128)");
  1055. break;
  1056. case 108:
  1057. ret += tcrypt_test("hmac(rmd160)");
  1058. break;
  1059. case 109:
  1060. ret += tcrypt_test("vmac(aes)");
  1061. break;
  1062. case 110:
  1063. ret += tcrypt_test("hmac(crc32)");
  1064. break;
  1065. case 111:
  1066. ret += tcrypt_test("hmac(sha3-224)");
  1067. break;
  1068. case 112:
  1069. ret += tcrypt_test("hmac(sha3-256)");
  1070. break;
  1071. case 113:
  1072. ret += tcrypt_test("hmac(sha3-384)");
  1073. break;
  1074. case 114:
  1075. ret += tcrypt_test("hmac(sha3-512)");
  1076. break;
  1077. case 150:
  1078. ret += tcrypt_test("ansi_cprng");
  1079. break;
  1080. case 151:
  1081. ret += tcrypt_test("rfc4106(gcm(aes))");
  1082. break;
  1083. case 152:
  1084. ret += tcrypt_test("rfc4543(gcm(aes))");
  1085. break;
  1086. case 153:
  1087. ret += tcrypt_test("cmac(aes)");
  1088. break;
  1089. case 154:
  1090. ret += tcrypt_test("cmac(des3_ede)");
  1091. break;
  1092. case 155:
  1093. ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
  1094. break;
  1095. case 156:
  1096. ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
  1097. break;
  1098. case 157:
  1099. ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
  1100. break;
  1101. case 181:
  1102. ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
  1103. break;
  1104. case 182:
  1105. ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
  1106. break;
  1107. case 183:
  1108. ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
  1109. break;
  1110. case 184:
  1111. ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
  1112. break;
  1113. case 185:
  1114. ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
  1115. break;
  1116. case 186:
  1117. ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
  1118. break;
  1119. case 187:
  1120. ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
  1121. break;
  1122. case 188:
  1123. ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
  1124. break;
  1125. case 189:
  1126. ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
  1127. break;
  1128. case 190:
  1129. ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
  1130. break;
  1131. case 200:
  1132. test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
  1133. speed_template_16_24_32);
  1134. test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
  1135. speed_template_16_24_32);
  1136. test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
  1137. speed_template_16_24_32);
  1138. test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
  1139. speed_template_16_24_32);
  1140. test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
  1141. speed_template_32_40_48);
  1142. test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
  1143. speed_template_32_40_48);
  1144. test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
  1145. speed_template_32_48_64);
  1146. test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
  1147. speed_template_32_48_64);
  1148. test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
  1149. speed_template_16_24_32);
  1150. test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
  1151. speed_template_16_24_32);
  1152. test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
  1153. speed_template_16_24_32);
  1154. test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
  1155. speed_template_16_24_32);
  1156. break;
  1157. case 201:
  1158. test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
  1159. des3_speed_template, DES3_SPEED_VECTORS,
  1160. speed_template_24);
  1161. test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
  1162. des3_speed_template, DES3_SPEED_VECTORS,
  1163. speed_template_24);
  1164. test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
  1165. des3_speed_template, DES3_SPEED_VECTORS,
  1166. speed_template_24);
  1167. test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
  1168. des3_speed_template, DES3_SPEED_VECTORS,
  1169. speed_template_24);
  1170. test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
  1171. des3_speed_template, DES3_SPEED_VECTORS,
  1172. speed_template_24);
  1173. test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
  1174. des3_speed_template, DES3_SPEED_VECTORS,
  1175. speed_template_24);
  1176. break;
  1177. case 202:
  1178. test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
  1179. speed_template_16_24_32);
  1180. test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
  1181. speed_template_16_24_32);
  1182. test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
  1183. speed_template_16_24_32);
  1184. test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
  1185. speed_template_16_24_32);
  1186. test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
  1187. speed_template_16_24_32);
  1188. test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
  1189. speed_template_16_24_32);
  1190. test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
  1191. speed_template_32_40_48);
  1192. test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
  1193. speed_template_32_40_48);
  1194. test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
  1195. speed_template_32_48_64);
  1196. test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
  1197. speed_template_32_48_64);
  1198. break;
  1199. case 203:
  1200. test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
  1201. speed_template_8_32);
  1202. test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
  1203. speed_template_8_32);
  1204. test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
  1205. speed_template_8_32);
  1206. test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
  1207. speed_template_8_32);
  1208. test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
  1209. speed_template_8_32);
  1210. test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
  1211. speed_template_8_32);
  1212. break;
  1213. case 204:
  1214. test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
  1215. speed_template_8);
  1216. test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
  1217. speed_template_8);
  1218. test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
  1219. speed_template_8);
  1220. test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
  1221. speed_template_8);
  1222. break;
  1223. case 205:
  1224. test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
  1225. speed_template_16_24_32);
  1226. test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
  1227. speed_template_16_24_32);
  1228. test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
  1229. speed_template_16_24_32);
  1230. test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
  1231. speed_template_16_24_32);
  1232. test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
  1233. speed_template_16_24_32);
  1234. test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
  1235. speed_template_16_24_32);
  1236. test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
  1237. speed_template_32_40_48);
  1238. test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
  1239. speed_template_32_40_48);
  1240. test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
  1241. speed_template_32_48_64);
  1242. test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
  1243. speed_template_32_48_64);
  1244. break;
  1245. case 206:
  1246. test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
  1247. speed_template_16_32);
  1248. break;
  1249. case 207:
  1250. test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
  1251. speed_template_16_32);
  1252. test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
  1253. speed_template_16_32);
  1254. test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
  1255. speed_template_16_32);
  1256. test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
  1257. speed_template_16_32);
  1258. test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
  1259. speed_template_16_32);
  1260. test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
  1261. speed_template_16_32);
  1262. test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
  1263. speed_template_32_48);
  1264. test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
  1265. speed_template_32_48);
  1266. test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
  1267. speed_template_32_64);
  1268. test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
  1269. speed_template_32_64);
  1270. break;
  1271. case 208:
  1272. test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
  1273. speed_template_8);
  1274. break;
  1275. case 209:
  1276. test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
  1277. speed_template_8_16);
  1278. test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
  1279. speed_template_8_16);
  1280. test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
  1281. speed_template_8_16);
  1282. test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
  1283. speed_template_8_16);
  1284. test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
  1285. speed_template_8_16);
  1286. test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
  1287. speed_template_8_16);
  1288. break;
  1289. case 210:
  1290. test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
  1291. speed_template_16_32);
  1292. test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
  1293. speed_template_16_32);
  1294. test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
  1295. speed_template_16_32);
  1296. test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
  1297. speed_template_16_32);
  1298. test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
  1299. speed_template_16_32);
  1300. test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
  1301. speed_template_16_32);
  1302. test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
  1303. speed_template_32_48);
  1304. test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
  1305. speed_template_32_48);
  1306. test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
  1307. speed_template_32_64);
  1308. test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
  1309. speed_template_32_64);
  1310. break;
  1311. case 211:
  1312. test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
  1313. NULL, 0, 16, 16, aead_speed_template_20);
  1314. test_aead_speed("gcm(aes)", ENCRYPT, sec,
  1315. NULL, 0, 16, 8, speed_template_16_24_32);
  1316. break;
  1317. case 212:
  1318. test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
  1319. NULL, 0, 16, 16, aead_speed_template_19);
  1320. break;
  1321. case 213:
  1322. test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
  1323. NULL, 0, 16, 8, aead_speed_template_36);
  1324. break;
  1325. case 214:
  1326. test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
  1327. speed_template_32);
  1328. break;
  1329. case 219:
  1330. test_cipher_speed("adiantum(xchacha12,aes)", ENCRYPT, sec, NULL,
  1331. 0, speed_template_32);
  1332. test_cipher_speed("adiantum(xchacha12,aes)", DECRYPT, sec, NULL,
  1333. 0, speed_template_32);
  1334. test_cipher_speed("adiantum(xchacha20,aes)", ENCRYPT, sec, NULL,
  1335. 0, speed_template_32);
  1336. test_cipher_speed("adiantum(xchacha20,aes)", DECRYPT, sec, NULL,
  1337. 0, speed_template_32);
  1338. break;
  1339. case 300:
  1340. if (alg) {
  1341. test_hash_speed(alg, sec, generic_hash_speed_template);
  1342. break;
  1343. }
  1344. /* fall through */
  1345. case 301:
  1346. test_hash_speed("md4", sec, generic_hash_speed_template);
  1347. if (mode > 300 && mode < 400) break;
  1348. case 302:
  1349. test_hash_speed("md5", sec, generic_hash_speed_template);
  1350. if (mode > 300 && mode < 400) break;
  1351. case 303:
  1352. test_hash_speed("sha1", sec, generic_hash_speed_template);
  1353. if (mode > 300 && mode < 400) break;
  1354. case 304:
  1355. test_hash_speed("sha256", sec, generic_hash_speed_template);
  1356. if (mode > 300 && mode < 400) break;
  1357. case 305:
  1358. test_hash_speed("sha384", sec, generic_hash_speed_template);
  1359. if (mode > 300 && mode < 400) break;
  1360. case 306:
  1361. test_hash_speed("sha512", sec, generic_hash_speed_template);
  1362. if (mode > 300 && mode < 400) break;
  1363. case 307:
  1364. test_hash_speed("wp256", sec, generic_hash_speed_template);
  1365. if (mode > 300 && mode < 400) break;
  1366. case 308:
  1367. test_hash_speed("wp384", sec, generic_hash_speed_template);
  1368. if (mode > 300 && mode < 400) break;
  1369. case 309:
  1370. test_hash_speed("wp512", sec, generic_hash_speed_template);
  1371. if (mode > 300 && mode < 400) break;
  1372. case 310:
  1373. test_hash_speed("tgr128", sec, generic_hash_speed_template);
  1374. if (mode > 300 && mode < 400) break;
  1375. case 311:
  1376. test_hash_speed("tgr160", sec, generic_hash_speed_template);
  1377. if (mode > 300 && mode < 400) break;
  1378. case 312:
  1379. test_hash_speed("tgr192", sec, generic_hash_speed_template);
  1380. if (mode > 300 && mode < 400) break;
  1381. case 313:
  1382. test_hash_speed("sha224", sec, generic_hash_speed_template);
  1383. if (mode > 300 && mode < 400) break;
  1384. case 314:
  1385. test_hash_speed("rmd128", sec, generic_hash_speed_template);
  1386. if (mode > 300 && mode < 400) break;
  1387. case 315:
  1388. test_hash_speed("rmd160", sec, generic_hash_speed_template);
  1389. if (mode > 300 && mode < 400) break;
  1390. case 316:
  1391. test_hash_speed("rmd256", sec, generic_hash_speed_template);
  1392. if (mode > 300 && mode < 400) break;
  1393. case 317:
  1394. test_hash_speed("rmd320", sec, generic_hash_speed_template);
  1395. if (mode > 300 && mode < 400) break;
  1396. case 318:
  1397. test_hash_speed("ghash-generic", sec, hash_speed_template_16);
  1398. if (mode > 300 && mode < 400) break;
  1399. case 319:
  1400. test_hash_speed("crc32c", sec, generic_hash_speed_template);
  1401. if (mode > 300 && mode < 400) break;
  1402. case 320:
  1403. test_hash_speed("crct10dif", sec, generic_hash_speed_template);
  1404. if (mode > 300 && mode < 400) break;
  1405. case 321:
  1406. test_hash_speed("poly1305", sec, poly1305_speed_template);
  1407. if (mode > 300 && mode < 400) break;
  1408. case 322:
  1409. test_hash_speed("sha3-224", sec, generic_hash_speed_template);
  1410. if (mode > 300 && mode < 400) break;
  1411. case 323:
  1412. test_hash_speed("sha3-256", sec, generic_hash_speed_template);
  1413. if (mode > 300 && mode < 400) break;
  1414. case 324:
  1415. test_hash_speed("sha3-384", sec, generic_hash_speed_template);
  1416. if (mode > 300 && mode < 400) break;
  1417. case 325:
  1418. test_hash_speed("sha3-512", sec, generic_hash_speed_template);
  1419. if (mode > 300 && mode < 400) break;
  1420. case 399:
  1421. break;
  1422. case 400:
  1423. if (alg) {
  1424. test_ahash_speed(alg, sec, generic_hash_speed_template);
  1425. break;
  1426. }
  1427. /* fall through */
  1428. case 401:
  1429. test_ahash_speed("md4", sec, generic_hash_speed_template);
  1430. if (mode > 400 && mode < 500) break;
  1431. case 402:
  1432. test_ahash_speed("md5", sec, generic_hash_speed_template);
  1433. if (mode > 400 && mode < 500) break;
  1434. case 403:
  1435. test_ahash_speed("sha1", sec, generic_hash_speed_template);
  1436. if (mode > 400 && mode < 500) break;
  1437. case 404:
  1438. test_ahash_speed("sha256", sec, generic_hash_speed_template);
  1439. if (mode > 400 && mode < 500) break;
  1440. case 405:
  1441. test_ahash_speed("sha384", sec, generic_hash_speed_template);
  1442. if (mode > 400 && mode < 500) break;
  1443. case 406:
  1444. test_ahash_speed("sha512", sec, generic_hash_speed_template);
  1445. if (mode > 400 && mode < 500) break;
  1446. case 407:
  1447. test_ahash_speed("wp256", sec, generic_hash_speed_template);
  1448. if (mode > 400 && mode < 500) break;
  1449. case 408:
  1450. test_ahash_speed("wp384", sec, generic_hash_speed_template);
  1451. if (mode > 400 && mode < 500) break;
  1452. case 409:
  1453. test_ahash_speed("wp512", sec, generic_hash_speed_template);
  1454. if (mode > 400 && mode < 500) break;
  1455. case 410:
  1456. test_ahash_speed("tgr128", sec, generic_hash_speed_template);
  1457. if (mode > 400 && mode < 500) break;
  1458. case 411:
  1459. test_ahash_speed("tgr160", sec, generic_hash_speed_template);
  1460. if (mode > 400 && mode < 500) break;
  1461. case 412:
  1462. test_ahash_speed("tgr192", sec, generic_hash_speed_template);
  1463. if (mode > 400 && mode < 500) break;
  1464. case 413:
  1465. test_ahash_speed("sha224", sec, generic_hash_speed_template);
  1466. if (mode > 400 && mode < 500) break;
  1467. case 414:
  1468. test_ahash_speed("rmd128", sec, generic_hash_speed_template);
  1469. if (mode > 400 && mode < 500) break;
  1470. case 415:
  1471. test_ahash_speed("rmd160", sec, generic_hash_speed_template);
  1472. if (mode > 400 && mode < 500) break;
  1473. case 416:
  1474. test_ahash_speed("rmd256", sec, generic_hash_speed_template);
  1475. if (mode > 400 && mode < 500) break;
  1476. case 417:
  1477. test_ahash_speed("rmd320", sec, generic_hash_speed_template);
  1478. if (mode > 400 && mode < 500) break;
  1479. case 418:
  1480. test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
  1481. if (mode > 400 && mode < 500) break;
  1482. case 419:
  1483. test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
  1484. if (mode > 400 && mode < 500) break;
  1485. case 420:
  1486. test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
  1487. if (mode > 400 && mode < 500) break;
  1488. case 421:
  1489. test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
  1490. if (mode > 400 && mode < 500) break;
  1491. case 422:
  1492. test_mb_ahash_speed("sha1", sec, generic_hash_speed_template);
  1493. if (mode > 400 && mode < 500) break;
  1494. case 423:
  1495. test_mb_ahash_speed("sha256", sec, generic_hash_speed_template);
  1496. if (mode > 400 && mode < 500) break;
  1497. case 424:
  1498. test_mb_ahash_speed("sha512", sec, generic_hash_speed_template);
  1499. if (mode > 400 && mode < 500) break;
  1500. case 499:
  1501. break;
  1502. case 500:
  1503. test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
  1504. speed_template_16_24_32);
  1505. test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
  1506. speed_template_16_24_32);
  1507. test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
  1508. speed_template_16_24_32);
  1509. test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
  1510. speed_template_16_24_32);
  1511. test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
  1512. speed_template_32_40_48);
  1513. test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
  1514. speed_template_32_40_48);
  1515. test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
  1516. speed_template_32_48_64);
  1517. test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
  1518. speed_template_32_48_64);
  1519. test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
  1520. speed_template_16_24_32);
  1521. test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
  1522. speed_template_16_24_32);
  1523. test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
  1524. speed_template_16_24_32);
  1525. test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
  1526. speed_template_16_24_32);
  1527. test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
  1528. speed_template_16_24_32);
  1529. test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
  1530. speed_template_16_24_32);
  1531. test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
  1532. speed_template_16_24_32);
  1533. test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
  1534. speed_template_16_24_32);
  1535. test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
  1536. speed_template_20_28_36);
  1537. test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
  1538. speed_template_20_28_36);
  1539. break;
  1540. case 501:
  1541. test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
  1542. des3_speed_template, DES3_SPEED_VECTORS,
  1543. speed_template_24);
  1544. test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
  1545. des3_speed_template, DES3_SPEED_VECTORS,
  1546. speed_template_24);
  1547. test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
  1548. des3_speed_template, DES3_SPEED_VECTORS,
  1549. speed_template_24);
  1550. test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
  1551. des3_speed_template, DES3_SPEED_VECTORS,
  1552. speed_template_24);
  1553. test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
  1554. des3_speed_template, DES3_SPEED_VECTORS,
  1555. speed_template_24);
  1556. test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
  1557. des3_speed_template, DES3_SPEED_VECTORS,
  1558. speed_template_24);
  1559. test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
  1560. des3_speed_template, DES3_SPEED_VECTORS,
  1561. speed_template_24);
  1562. test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
  1563. des3_speed_template, DES3_SPEED_VECTORS,
  1564. speed_template_24);
  1565. break;
  1566. case 502:
  1567. test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
  1568. speed_template_8);
  1569. test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
  1570. speed_template_8);
  1571. test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
  1572. speed_template_8);
  1573. test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
  1574. speed_template_8);
  1575. test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
  1576. speed_template_8);
  1577. test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
  1578. speed_template_8);
  1579. test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
  1580. speed_template_8);
  1581. test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
  1582. speed_template_8);
  1583. break;
  1584. case 503:
  1585. test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
  1586. speed_template_16_32);
  1587. test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
  1588. speed_template_16_32);
  1589. test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
  1590. speed_template_16_32);
  1591. test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
  1592. speed_template_16_32);
  1593. test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
  1594. speed_template_16_32);
  1595. test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
  1596. speed_template_16_32);
  1597. test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
  1598. speed_template_32_48);
  1599. test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
  1600. speed_template_32_48);
  1601. test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
  1602. speed_template_32_64);
  1603. test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
  1604. speed_template_32_64);
  1605. break;
  1606. case 504:
  1607. test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
  1608. speed_template_16_24_32);
  1609. test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
  1610. speed_template_16_24_32);
  1611. test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
  1612. speed_template_16_24_32);
  1613. test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
  1614. speed_template_16_24_32);
  1615. test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
  1616. speed_template_16_24_32);
  1617. test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
  1618. speed_template_16_24_32);
  1619. test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
  1620. speed_template_32_40_48);
  1621. test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
  1622. speed_template_32_40_48);
  1623. test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
  1624. speed_template_32_48_64);
  1625. test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
  1626. speed_template_32_48_64);
  1627. break;
  1628. case 505:
  1629. test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
  1630. speed_template_8);
  1631. break;
  1632. case 506:
  1633. test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
  1634. speed_template_8_16);
  1635. test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
  1636. speed_template_8_16);
  1637. test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
  1638. speed_template_8_16);
  1639. test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
  1640. speed_template_8_16);
  1641. test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
  1642. speed_template_8_16);
  1643. test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
  1644. speed_template_8_16);
  1645. break;
  1646. case 507:
  1647. test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
  1648. speed_template_16_32);
  1649. test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
  1650. speed_template_16_32);
  1651. test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
  1652. speed_template_16_32);
  1653. test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
  1654. speed_template_16_32);
  1655. test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
  1656. speed_template_16_32);
  1657. test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
  1658. speed_template_16_32);
  1659. test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
  1660. speed_template_32_48);
  1661. test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
  1662. speed_template_32_48);
  1663. test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
  1664. speed_template_32_64);
  1665. test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
  1666. speed_template_32_64);
  1667. break;
  1668. case 508:
  1669. test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
  1670. speed_template_16_32);
  1671. test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
  1672. speed_template_16_32);
  1673. test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
  1674. speed_template_16_32);
  1675. test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
  1676. speed_template_16_32);
  1677. test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
  1678. speed_template_16_32);
  1679. test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
  1680. speed_template_16_32);
  1681. test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
  1682. speed_template_32_48);
  1683. test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
  1684. speed_template_32_48);
  1685. test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
  1686. speed_template_32_64);
  1687. test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
  1688. speed_template_32_64);
  1689. break;
  1690. case 509:
  1691. test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
  1692. speed_template_8_32);
  1693. test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
  1694. speed_template_8_32);
  1695. test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
  1696. speed_template_8_32);
  1697. test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
  1698. speed_template_8_32);
  1699. test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
  1700. speed_template_8_32);
  1701. test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
  1702. speed_template_8_32);
  1703. break;
  1704. case 1000:
  1705. test_available();
  1706. break;
  1707. }
  1708. return ret;
  1709. }
  1710. static int __init tcrypt_mod_init(void)
  1711. {
  1712. int err = -ENOMEM;
  1713. int i;
  1714. for (i = 0; i < TVMEMSIZE; i++) {
  1715. tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
  1716. if (!tvmem[i])
  1717. goto err_free_tv;
  1718. }
  1719. err = do_test(alg, type, mask, mode);
  1720. if (err) {
  1721. printk(KERN_ERR "tcrypt: one or more tests failed!\n");
  1722. goto err_free_tv;
  1723. }
  1724. /* We intentionaly return -EAGAIN to prevent keeping the module,
  1725. * unless we're running in fips mode. It does all its work from
  1726. * init() and doesn't offer any runtime functionality, but in
  1727. * the fips case, checking for a successful load is helpful.
  1728. * => we don't need it in the memory, do we?
  1729. * -- mludvig
  1730. */
  1731. if (!fips_enabled)
  1732. err = -EAGAIN;
  1733. err_free_tv:
  1734. for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
  1735. free_page((unsigned long)tvmem[i]);
  1736. return err;
  1737. }
  1738. /*
  1739. * If an init function is provided, an exit function must also be provided
  1740. * to allow module unload.
  1741. */
  1742. static void __exit tcrypt_mod_fini(void) { }
  1743. module_init(tcrypt_mod_init);
  1744. module_exit(tcrypt_mod_fini);
  1745. module_param(alg, charp, 0);
  1746. module_param(type, uint, 0);
  1747. module_param(mask, uint, 0);
  1748. module_param(mode, int, 0);
  1749. module_param(sec, uint, 0);
  1750. MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
  1751. "(defaults to zero which uses CPU cycles instead)");
  1752. MODULE_LICENSE("GPL");
  1753. MODULE_DESCRIPTION("Quick & dirty crypto testing module");
  1754. MODULE_AUTHOR("James Morris <[email protected]>");