tcrypt.c 51 KB

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