tcrypt.c 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010
  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 u32 num_mb = 8;
  63. static char *tvmem[TVMEMSIZE];
  64. static char *check[] = {
  65. "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", "sm3",
  66. "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
  67. "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
  68. "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
  69. "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
  70. "lzo", "cts", "zlib", "sha3-224", "sha3-256", "sha3-384", "sha3-512",
  71. NULL
  72. };
  73. static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
  74. static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
  75. #define XBUFSIZE 8
  76. #define MAX_IVLEN 32
  77. static int testmgr_alloc_buf(char *buf[XBUFSIZE])
  78. {
  79. int i;
  80. for (i = 0; i < XBUFSIZE; i++) {
  81. buf[i] = (void *)__get_free_page(GFP_KERNEL);
  82. if (!buf[i])
  83. goto err_free_buf;
  84. }
  85. return 0;
  86. err_free_buf:
  87. while (i-- > 0)
  88. free_page((unsigned long)buf[i]);
  89. return -ENOMEM;
  90. }
  91. static void testmgr_free_buf(char *buf[XBUFSIZE])
  92. {
  93. int i;
  94. for (i = 0; i < XBUFSIZE; i++)
  95. free_page((unsigned long)buf[i]);
  96. }
  97. static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],
  98. unsigned int buflen, const void *assoc,
  99. unsigned int aad_size)
  100. {
  101. int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
  102. int k, rem;
  103. if (np > XBUFSIZE) {
  104. rem = PAGE_SIZE;
  105. np = XBUFSIZE;
  106. } else {
  107. rem = buflen % PAGE_SIZE;
  108. }
  109. sg_init_table(sg, np + 1);
  110. sg_set_buf(&sg[0], assoc, aad_size);
  111. if (rem)
  112. np--;
  113. for (k = 0; k < np; k++)
  114. sg_set_buf(&sg[k + 1], xbuf[k], PAGE_SIZE);
  115. if (rem)
  116. sg_set_buf(&sg[k + 1], xbuf[k], rem);
  117. }
  118. static inline int do_one_aead_op(struct aead_request *req, int ret)
  119. {
  120. struct crypto_wait *wait = req->base.data;
  121. return crypto_wait_req(ret, wait);
  122. }
  123. struct test_mb_aead_data {
  124. struct scatterlist sg[XBUFSIZE];
  125. struct scatterlist sgout[XBUFSIZE];
  126. struct aead_request *req;
  127. struct crypto_wait wait;
  128. char *xbuf[XBUFSIZE];
  129. char *xoutbuf[XBUFSIZE];
  130. char *axbuf[XBUFSIZE];
  131. };
  132. static int do_mult_aead_op(struct test_mb_aead_data *data, int enc,
  133. u32 num_mb, int *rc)
  134. {
  135. int i, err = 0;
  136. /* Fire up a bunch of concurrent requests */
  137. for (i = 0; i < num_mb; i++) {
  138. if (enc == ENCRYPT)
  139. rc[i] = crypto_aead_encrypt(data[i].req);
  140. else
  141. rc[i] = crypto_aead_decrypt(data[i].req);
  142. }
  143. /* Wait for all requests to finish */
  144. for (i = 0; i < num_mb; i++) {
  145. rc[i] = crypto_wait_req(rc[i], &data[i].wait);
  146. if (rc[i]) {
  147. pr_info("concurrent request %d error %d\n", i, rc[i]);
  148. err = rc[i];
  149. }
  150. }
  151. return err;
  152. }
  153. static int test_mb_aead_jiffies(struct test_mb_aead_data *data, int enc,
  154. int blen, int secs, u32 num_mb)
  155. {
  156. unsigned long start, end;
  157. int bcount;
  158. int ret = 0;
  159. int *rc;
  160. rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
  161. if (!rc)
  162. return -ENOMEM;
  163. for (start = jiffies, end = start + secs * HZ, bcount = 0;
  164. time_before(jiffies, end); bcount++) {
  165. ret = do_mult_aead_op(data, enc, num_mb, rc);
  166. if (ret)
  167. goto out;
  168. }
  169. pr_cont("%d operations in %d seconds (%ld bytes)\n",
  170. bcount * num_mb, secs, (long)bcount * blen * num_mb);
  171. out:
  172. kfree(rc);
  173. return ret;
  174. }
  175. static int test_mb_aead_cycles(struct test_mb_aead_data *data, int enc,
  176. int blen, u32 num_mb)
  177. {
  178. unsigned long cycles = 0;
  179. int ret = 0;
  180. int i;
  181. int *rc;
  182. rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
  183. if (!rc)
  184. return -ENOMEM;
  185. /* Warm-up run. */
  186. for (i = 0; i < 4; i++) {
  187. ret = do_mult_aead_op(data, enc, num_mb, rc);
  188. if (ret)
  189. goto out;
  190. }
  191. /* The real thing. */
  192. for (i = 0; i < 8; i++) {
  193. cycles_t start, end;
  194. start = get_cycles();
  195. ret = do_mult_aead_op(data, enc, num_mb, rc);
  196. end = get_cycles();
  197. if (ret)
  198. goto out;
  199. cycles += end - start;
  200. }
  201. pr_cont("1 operation in %lu cycles (%d bytes)\n",
  202. (cycles + 4) / (8 * num_mb), blen);
  203. out:
  204. kfree(rc);
  205. return ret;
  206. }
  207. static void test_mb_aead_speed(const char *algo, int enc, int secs,
  208. struct aead_speed_template *template,
  209. unsigned int tcount, u8 authsize,
  210. unsigned int aad_size, u8 *keysize, u32 num_mb)
  211. {
  212. struct test_mb_aead_data *data;
  213. struct crypto_aead *tfm;
  214. unsigned int i, j, iv_len;
  215. const char *key;
  216. const char *e;
  217. void *assoc;
  218. u32 *b_size;
  219. char *iv;
  220. int ret;
  221. if (aad_size >= PAGE_SIZE) {
  222. pr_err("associate data length (%u) too big\n", aad_size);
  223. return;
  224. }
  225. iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
  226. if (!iv)
  227. return;
  228. if (enc == ENCRYPT)
  229. e = "encryption";
  230. else
  231. e = "decryption";
  232. data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
  233. if (!data)
  234. goto out_free_iv;
  235. tfm = crypto_alloc_aead(algo, 0, 0);
  236. if (IS_ERR(tfm)) {
  237. pr_err("failed to load transform for %s: %ld\n",
  238. algo, PTR_ERR(tfm));
  239. goto out_free_data;
  240. }
  241. ret = crypto_aead_setauthsize(tfm, authsize);
  242. for (i = 0; i < num_mb; ++i)
  243. if (testmgr_alloc_buf(data[i].xbuf)) {
  244. while (i--)
  245. testmgr_free_buf(data[i].xbuf);
  246. goto out_free_tfm;
  247. }
  248. for (i = 0; i < num_mb; ++i)
  249. if (testmgr_alloc_buf(data[i].axbuf)) {
  250. while (i--)
  251. testmgr_free_buf(data[i].axbuf);
  252. goto out_free_xbuf;
  253. }
  254. for (i = 0; i < num_mb; ++i)
  255. if (testmgr_alloc_buf(data[i].xoutbuf)) {
  256. while (i--)
  257. testmgr_free_buf(data[i].xoutbuf);
  258. goto out_free_axbuf;
  259. }
  260. for (i = 0; i < num_mb; ++i) {
  261. data[i].req = aead_request_alloc(tfm, GFP_KERNEL);
  262. if (!data[i].req) {
  263. pr_err("alg: skcipher: Failed to allocate request for %s\n",
  264. algo);
  265. while (i--)
  266. aead_request_free(data[i].req);
  267. goto out_free_xoutbuf;
  268. }
  269. }
  270. for (i = 0; i < num_mb; ++i) {
  271. crypto_init_wait(&data[i].wait);
  272. aead_request_set_callback(data[i].req,
  273. CRYPTO_TFM_REQ_MAY_BACKLOG,
  274. crypto_req_done, &data[i].wait);
  275. }
  276. pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo,
  277. get_driver_name(crypto_aead, tfm), e);
  278. i = 0;
  279. do {
  280. b_size = aead_sizes;
  281. do {
  282. if (*b_size + authsize > XBUFSIZE * PAGE_SIZE) {
  283. pr_err("template (%u) too big for buffer (%lu)\n",
  284. authsize + *b_size,
  285. XBUFSIZE * PAGE_SIZE);
  286. goto out;
  287. }
  288. pr_info("test %u (%d bit key, %d byte blocks): ", i,
  289. *keysize * 8, *b_size);
  290. /* Set up tfm global state, i.e. the key */
  291. memset(tvmem[0], 0xff, PAGE_SIZE);
  292. key = tvmem[0];
  293. for (j = 0; j < tcount; j++) {
  294. if (template[j].klen == *keysize) {
  295. key = template[j].key;
  296. break;
  297. }
  298. }
  299. crypto_aead_clear_flags(tfm, ~0);
  300. ret = crypto_aead_setkey(tfm, key, *keysize);
  301. if (ret) {
  302. pr_err("setkey() failed flags=%x\n",
  303. crypto_aead_get_flags(tfm));
  304. goto out;
  305. }
  306. iv_len = crypto_aead_ivsize(tfm);
  307. if (iv_len)
  308. memset(iv, 0xff, iv_len);
  309. /* Now setup per request stuff, i.e. buffers */
  310. for (j = 0; j < num_mb; ++j) {
  311. struct test_mb_aead_data *cur = &data[j];
  312. assoc = cur->axbuf[0];
  313. memset(assoc, 0xff, aad_size);
  314. sg_init_aead(cur->sg, cur->xbuf,
  315. *b_size + (enc ? 0 : authsize),
  316. assoc, aad_size);
  317. sg_init_aead(cur->sgout, cur->xoutbuf,
  318. *b_size + (enc ? authsize : 0),
  319. assoc, aad_size);
  320. aead_request_set_ad(cur->req, aad_size);
  321. if (!enc) {
  322. aead_request_set_crypt(cur->req,
  323. cur->sgout,
  324. cur->sg,
  325. *b_size, iv);
  326. ret = crypto_aead_encrypt(cur->req);
  327. ret = do_one_aead_op(cur->req, ret);
  328. if (ret) {
  329. pr_err("calculating auth failed failed (%d)\n",
  330. ret);
  331. break;
  332. }
  333. }
  334. aead_request_set_crypt(cur->req, cur->sg,
  335. cur->sgout, *b_size +
  336. (enc ? 0 : authsize),
  337. iv);
  338. }
  339. if (secs) {
  340. ret = test_mb_aead_jiffies(data, enc, *b_size,
  341. secs, num_mb);
  342. cond_resched();
  343. } else {
  344. ret = test_mb_aead_cycles(data, enc, *b_size,
  345. num_mb);
  346. }
  347. if (ret) {
  348. pr_err("%s() failed return code=%d\n", e, ret);
  349. break;
  350. }
  351. b_size++;
  352. i++;
  353. } while (*b_size);
  354. keysize++;
  355. } while (*keysize);
  356. out:
  357. for (i = 0; i < num_mb; ++i)
  358. aead_request_free(data[i].req);
  359. out_free_xoutbuf:
  360. for (i = 0; i < num_mb; ++i)
  361. testmgr_free_buf(data[i].xoutbuf);
  362. out_free_axbuf:
  363. for (i = 0; i < num_mb; ++i)
  364. testmgr_free_buf(data[i].axbuf);
  365. out_free_xbuf:
  366. for (i = 0; i < num_mb; ++i)
  367. testmgr_free_buf(data[i].xbuf);
  368. out_free_tfm:
  369. crypto_free_aead(tfm);
  370. out_free_data:
  371. kfree(data);
  372. out_free_iv:
  373. kfree(iv);
  374. }
  375. static int test_aead_jiffies(struct aead_request *req, int enc,
  376. int blen, int secs)
  377. {
  378. unsigned long start, end;
  379. int bcount;
  380. int ret;
  381. for (start = jiffies, end = start + secs * HZ, bcount = 0;
  382. time_before(jiffies, end); bcount++) {
  383. if (enc)
  384. ret = do_one_aead_op(req, crypto_aead_encrypt(req));
  385. else
  386. ret = do_one_aead_op(req, crypto_aead_decrypt(req));
  387. if (ret)
  388. return ret;
  389. }
  390. printk("%d operations in %d seconds (%ld bytes)\n",
  391. bcount, secs, (long)bcount * blen);
  392. return 0;
  393. }
  394. static int test_aead_cycles(struct aead_request *req, int enc, int blen)
  395. {
  396. unsigned long cycles = 0;
  397. int ret = 0;
  398. int i;
  399. /* Warm-up run. */
  400. for (i = 0; i < 4; i++) {
  401. if (enc)
  402. ret = do_one_aead_op(req, crypto_aead_encrypt(req));
  403. else
  404. ret = do_one_aead_op(req, crypto_aead_decrypt(req));
  405. if (ret)
  406. goto out;
  407. }
  408. /* The real thing. */
  409. for (i = 0; i < 8; i++) {
  410. cycles_t start, end;
  411. start = get_cycles();
  412. if (enc)
  413. ret = do_one_aead_op(req, crypto_aead_encrypt(req));
  414. else
  415. ret = do_one_aead_op(req, crypto_aead_decrypt(req));
  416. end = get_cycles();
  417. if (ret)
  418. goto out;
  419. cycles += end - start;
  420. }
  421. out:
  422. if (ret == 0)
  423. printk("1 operation in %lu cycles (%d bytes)\n",
  424. (cycles + 4) / 8, blen);
  425. return ret;
  426. }
  427. static void test_aead_speed(const char *algo, int enc, unsigned int secs,
  428. struct aead_speed_template *template,
  429. unsigned int tcount, u8 authsize,
  430. unsigned int aad_size, u8 *keysize)
  431. {
  432. unsigned int i, j;
  433. struct crypto_aead *tfm;
  434. int ret = -ENOMEM;
  435. const char *key;
  436. struct aead_request *req;
  437. struct scatterlist *sg;
  438. struct scatterlist *sgout;
  439. const char *e;
  440. void *assoc;
  441. char *iv;
  442. char *xbuf[XBUFSIZE];
  443. char *xoutbuf[XBUFSIZE];
  444. char *axbuf[XBUFSIZE];
  445. unsigned int *b_size;
  446. unsigned int iv_len;
  447. struct crypto_wait wait;
  448. iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
  449. if (!iv)
  450. return;
  451. if (aad_size >= PAGE_SIZE) {
  452. pr_err("associate data length (%u) too big\n", aad_size);
  453. goto out_noxbuf;
  454. }
  455. if (enc == ENCRYPT)
  456. e = "encryption";
  457. else
  458. e = "decryption";
  459. if (testmgr_alloc_buf(xbuf))
  460. goto out_noxbuf;
  461. if (testmgr_alloc_buf(axbuf))
  462. goto out_noaxbuf;
  463. if (testmgr_alloc_buf(xoutbuf))
  464. goto out_nooutbuf;
  465. sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL);
  466. if (!sg)
  467. goto out_nosg;
  468. sgout = &sg[9];
  469. tfm = crypto_alloc_aead(algo, 0, 0);
  470. if (IS_ERR(tfm)) {
  471. pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
  472. PTR_ERR(tfm));
  473. goto out_notfm;
  474. }
  475. crypto_init_wait(&wait);
  476. printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
  477. get_driver_name(crypto_aead, tfm), e);
  478. req = aead_request_alloc(tfm, GFP_KERNEL);
  479. if (!req) {
  480. pr_err("alg: aead: Failed to allocate request for %s\n",
  481. algo);
  482. goto out_noreq;
  483. }
  484. aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  485. crypto_req_done, &wait);
  486. i = 0;
  487. do {
  488. b_size = aead_sizes;
  489. do {
  490. assoc = axbuf[0];
  491. memset(assoc, 0xff, aad_size);
  492. if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
  493. pr_err("template (%u) too big for tvmem (%lu)\n",
  494. *keysize + *b_size,
  495. TVMEMSIZE * PAGE_SIZE);
  496. goto out;
  497. }
  498. key = tvmem[0];
  499. for (j = 0; j < tcount; j++) {
  500. if (template[j].klen == *keysize) {
  501. key = template[j].key;
  502. break;
  503. }
  504. }
  505. ret = crypto_aead_setkey(tfm, key, *keysize);
  506. ret = crypto_aead_setauthsize(tfm, authsize);
  507. iv_len = crypto_aead_ivsize(tfm);
  508. if (iv_len)
  509. memset(iv, 0xff, iv_len);
  510. crypto_aead_clear_flags(tfm, ~0);
  511. printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
  512. i, *keysize * 8, *b_size);
  513. memset(tvmem[0], 0xff, PAGE_SIZE);
  514. if (ret) {
  515. pr_err("setkey() failed flags=%x\n",
  516. crypto_aead_get_flags(tfm));
  517. goto out;
  518. }
  519. sg_init_aead(sg, xbuf, *b_size + (enc ? 0 : authsize),
  520. assoc, aad_size);
  521. sg_init_aead(sgout, xoutbuf,
  522. *b_size + (enc ? authsize : 0), assoc,
  523. aad_size);
  524. aead_request_set_ad(req, aad_size);
  525. if (!enc) {
  526. /*
  527. * For decryption we need a proper auth so
  528. * we do the encryption path once with buffers
  529. * reversed (input <-> output) to calculate it
  530. */
  531. aead_request_set_crypt(req, sgout, sg,
  532. *b_size, iv);
  533. ret = do_one_aead_op(req,
  534. crypto_aead_encrypt(req));
  535. if (ret) {
  536. pr_err("calculating auth failed failed (%d)\n",
  537. ret);
  538. break;
  539. }
  540. }
  541. aead_request_set_crypt(req, sg, sgout,
  542. *b_size + (enc ? 0 : authsize),
  543. iv);
  544. if (secs) {
  545. ret = test_aead_jiffies(req, enc, *b_size,
  546. secs);
  547. cond_resched();
  548. } else {
  549. ret = test_aead_cycles(req, enc, *b_size);
  550. }
  551. if (ret) {
  552. pr_err("%s() failed return code=%d\n", e, ret);
  553. break;
  554. }
  555. b_size++;
  556. i++;
  557. } while (*b_size);
  558. keysize++;
  559. } while (*keysize);
  560. out:
  561. aead_request_free(req);
  562. out_noreq:
  563. crypto_free_aead(tfm);
  564. out_notfm:
  565. kfree(sg);
  566. out_nosg:
  567. testmgr_free_buf(xoutbuf);
  568. out_nooutbuf:
  569. testmgr_free_buf(axbuf);
  570. out_noaxbuf:
  571. testmgr_free_buf(xbuf);
  572. out_noxbuf:
  573. kfree(iv);
  574. }
  575. static void test_hash_sg_init(struct scatterlist *sg)
  576. {
  577. int i;
  578. sg_init_table(sg, TVMEMSIZE);
  579. for (i = 0; i < TVMEMSIZE; i++) {
  580. sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
  581. memset(tvmem[i], 0xff, PAGE_SIZE);
  582. }
  583. }
  584. static inline int do_one_ahash_op(struct ahash_request *req, int ret)
  585. {
  586. struct crypto_wait *wait = req->base.data;
  587. return crypto_wait_req(ret, wait);
  588. }
  589. struct test_mb_ahash_data {
  590. struct scatterlist sg[XBUFSIZE];
  591. char result[64];
  592. struct ahash_request *req;
  593. struct crypto_wait wait;
  594. char *xbuf[XBUFSIZE];
  595. };
  596. static inline int do_mult_ahash_op(struct test_mb_ahash_data *data, u32 num_mb,
  597. int *rc)
  598. {
  599. int i, err = 0;
  600. /* Fire up a bunch of concurrent requests */
  601. for (i = 0; i < num_mb; i++)
  602. rc[i] = crypto_ahash_digest(data[i].req);
  603. /* Wait for all requests to finish */
  604. for (i = 0; i < num_mb; i++) {
  605. rc[i] = crypto_wait_req(rc[i], &data[i].wait);
  606. if (rc[i]) {
  607. pr_info("concurrent request %d error %d\n", i, rc[i]);
  608. err = rc[i];
  609. }
  610. }
  611. return err;
  612. }
  613. static int test_mb_ahash_jiffies(struct test_mb_ahash_data *data, int blen,
  614. int secs, u32 num_mb)
  615. {
  616. unsigned long start, end;
  617. int bcount;
  618. int ret = 0;
  619. int *rc;
  620. rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
  621. if (!rc)
  622. return -ENOMEM;
  623. for (start = jiffies, end = start + secs * HZ, bcount = 0;
  624. time_before(jiffies, end); bcount++) {
  625. ret = do_mult_ahash_op(data, num_mb, rc);
  626. if (ret)
  627. goto out;
  628. }
  629. pr_cont("%d operations in %d seconds (%ld bytes)\n",
  630. bcount * num_mb, secs, (long)bcount * blen * num_mb);
  631. out:
  632. kfree(rc);
  633. return ret;
  634. }
  635. static int test_mb_ahash_cycles(struct test_mb_ahash_data *data, int blen,
  636. u32 num_mb)
  637. {
  638. unsigned long cycles = 0;
  639. int ret = 0;
  640. int i;
  641. int *rc;
  642. rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
  643. if (!rc)
  644. return -ENOMEM;
  645. /* Warm-up run. */
  646. for (i = 0; i < 4; i++) {
  647. ret = do_mult_ahash_op(data, num_mb, rc);
  648. if (ret)
  649. goto out;
  650. }
  651. /* The real thing. */
  652. for (i = 0; i < 8; i++) {
  653. cycles_t start, end;
  654. start = get_cycles();
  655. ret = do_mult_ahash_op(data, num_mb, rc);
  656. end = get_cycles();
  657. if (ret)
  658. goto out;
  659. cycles += end - start;
  660. }
  661. pr_cont("1 operation in %lu cycles (%d bytes)\n",
  662. (cycles + 4) / (8 * num_mb), blen);
  663. out:
  664. kfree(rc);
  665. return ret;
  666. }
  667. static void test_mb_ahash_speed(const char *algo, unsigned int secs,
  668. struct hash_speed *speed, u32 num_mb)
  669. {
  670. struct test_mb_ahash_data *data;
  671. struct crypto_ahash *tfm;
  672. unsigned int i, j, k;
  673. int ret;
  674. data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
  675. if (!data)
  676. return;
  677. tfm = crypto_alloc_ahash(algo, 0, 0);
  678. if (IS_ERR(tfm)) {
  679. pr_err("failed to load transform for %s: %ld\n",
  680. algo, PTR_ERR(tfm));
  681. goto free_data;
  682. }
  683. for (i = 0; i < num_mb; ++i) {
  684. if (testmgr_alloc_buf(data[i].xbuf))
  685. goto out;
  686. crypto_init_wait(&data[i].wait);
  687. data[i].req = ahash_request_alloc(tfm, GFP_KERNEL);
  688. if (!data[i].req) {
  689. pr_err("alg: hash: Failed to allocate request for %s\n",
  690. algo);
  691. goto out;
  692. }
  693. ahash_request_set_callback(data[i].req, 0, crypto_req_done,
  694. &data[i].wait);
  695. sg_init_table(data[i].sg, XBUFSIZE);
  696. for (j = 0; j < XBUFSIZE; j++) {
  697. sg_set_buf(data[i].sg + j, data[i].xbuf[j], PAGE_SIZE);
  698. memset(data[i].xbuf[j], 0xff, PAGE_SIZE);
  699. }
  700. }
  701. pr_info("\ntesting speed of multibuffer %s (%s)\n", algo,
  702. get_driver_name(crypto_ahash, tfm));
  703. for (i = 0; speed[i].blen != 0; i++) {
  704. /* For some reason this only tests digests. */
  705. if (speed[i].blen != speed[i].plen)
  706. continue;
  707. if (speed[i].blen > XBUFSIZE * PAGE_SIZE) {
  708. pr_err("template (%u) too big for tvmem (%lu)\n",
  709. speed[i].blen, XBUFSIZE * PAGE_SIZE);
  710. goto out;
  711. }
  712. if (speed[i].klen)
  713. crypto_ahash_setkey(tfm, tvmem[0], speed[i].klen);
  714. for (k = 0; k < num_mb; k++)
  715. ahash_request_set_crypt(data[k].req, data[k].sg,
  716. data[k].result, speed[i].blen);
  717. pr_info("test%3u "
  718. "(%5u byte blocks,%5u bytes per update,%4u updates): ",
  719. i, speed[i].blen, speed[i].plen,
  720. speed[i].blen / speed[i].plen);
  721. if (secs) {
  722. ret = test_mb_ahash_jiffies(data, speed[i].blen, secs,
  723. num_mb);
  724. cond_resched();
  725. } else {
  726. ret = test_mb_ahash_cycles(data, speed[i].blen, num_mb);
  727. }
  728. if (ret) {
  729. pr_err("At least one hashing failed ret=%d\n", ret);
  730. break;
  731. }
  732. }
  733. out:
  734. for (k = 0; k < num_mb; ++k)
  735. ahash_request_free(data[k].req);
  736. for (k = 0; k < num_mb; ++k)
  737. testmgr_free_buf(data[k].xbuf);
  738. crypto_free_ahash(tfm);
  739. free_data:
  740. kfree(data);
  741. }
  742. static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
  743. char *out, int secs)
  744. {
  745. unsigned long start, end;
  746. int bcount;
  747. int ret;
  748. for (start = jiffies, end = start + secs * HZ, bcount = 0;
  749. time_before(jiffies, end); bcount++) {
  750. ret = do_one_ahash_op(req, crypto_ahash_digest(req));
  751. if (ret)
  752. return ret;
  753. }
  754. printk("%6u opers/sec, %9lu bytes/sec\n",
  755. bcount / secs, ((long)bcount * blen) / secs);
  756. return 0;
  757. }
  758. static int test_ahash_jiffies(struct ahash_request *req, int blen,
  759. int plen, char *out, int secs)
  760. {
  761. unsigned long start, end;
  762. int bcount, pcount;
  763. int ret;
  764. if (plen == blen)
  765. return test_ahash_jiffies_digest(req, blen, out, secs);
  766. for (start = jiffies, end = start + secs * HZ, bcount = 0;
  767. time_before(jiffies, end); bcount++) {
  768. ret = do_one_ahash_op(req, crypto_ahash_init(req));
  769. if (ret)
  770. return ret;
  771. for (pcount = 0; pcount < blen; pcount += plen) {
  772. ret = do_one_ahash_op(req, crypto_ahash_update(req));
  773. if (ret)
  774. return ret;
  775. }
  776. /* we assume there is enough space in 'out' for the result */
  777. ret = do_one_ahash_op(req, crypto_ahash_final(req));
  778. if (ret)
  779. return ret;
  780. }
  781. pr_cont("%6u opers/sec, %9lu bytes/sec\n",
  782. bcount / secs, ((long)bcount * blen) / secs);
  783. return 0;
  784. }
  785. static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
  786. char *out)
  787. {
  788. unsigned long cycles = 0;
  789. int ret, i;
  790. /* Warm-up run. */
  791. for (i = 0; i < 4; i++) {
  792. ret = do_one_ahash_op(req, crypto_ahash_digest(req));
  793. if (ret)
  794. goto out;
  795. }
  796. /* The real thing. */
  797. for (i = 0; i < 8; i++) {
  798. cycles_t start, end;
  799. start = get_cycles();
  800. ret = do_one_ahash_op(req, crypto_ahash_digest(req));
  801. if (ret)
  802. goto out;
  803. end = get_cycles();
  804. cycles += end - start;
  805. }
  806. out:
  807. if (ret)
  808. return ret;
  809. pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
  810. cycles / 8, cycles / (8 * blen));
  811. return 0;
  812. }
  813. static int test_ahash_cycles(struct ahash_request *req, int blen,
  814. int plen, char *out)
  815. {
  816. unsigned long cycles = 0;
  817. int i, pcount, ret;
  818. if (plen == blen)
  819. return test_ahash_cycles_digest(req, blen, out);
  820. /* Warm-up run. */
  821. for (i = 0; i < 4; i++) {
  822. ret = do_one_ahash_op(req, crypto_ahash_init(req));
  823. if (ret)
  824. goto out;
  825. for (pcount = 0; pcount < blen; pcount += plen) {
  826. ret = do_one_ahash_op(req, crypto_ahash_update(req));
  827. if (ret)
  828. goto out;
  829. }
  830. ret = do_one_ahash_op(req, crypto_ahash_final(req));
  831. if (ret)
  832. goto out;
  833. }
  834. /* The real thing. */
  835. for (i = 0; i < 8; i++) {
  836. cycles_t start, end;
  837. start = get_cycles();
  838. ret = do_one_ahash_op(req, crypto_ahash_init(req));
  839. if (ret)
  840. goto out;
  841. for (pcount = 0; pcount < blen; pcount += plen) {
  842. ret = do_one_ahash_op(req, crypto_ahash_update(req));
  843. if (ret)
  844. goto out;
  845. }
  846. ret = do_one_ahash_op(req, crypto_ahash_final(req));
  847. if (ret)
  848. goto out;
  849. end = get_cycles();
  850. cycles += end - start;
  851. }
  852. out:
  853. if (ret)
  854. return ret;
  855. pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
  856. cycles / 8, cycles / (8 * blen));
  857. return 0;
  858. }
  859. static void test_ahash_speed_common(const char *algo, unsigned int secs,
  860. struct hash_speed *speed, unsigned mask)
  861. {
  862. struct scatterlist sg[TVMEMSIZE];
  863. struct crypto_wait wait;
  864. struct ahash_request *req;
  865. struct crypto_ahash *tfm;
  866. char *output;
  867. int i, ret;
  868. tfm = crypto_alloc_ahash(algo, 0, mask);
  869. if (IS_ERR(tfm)) {
  870. pr_err("failed to load transform for %s: %ld\n",
  871. algo, PTR_ERR(tfm));
  872. return;
  873. }
  874. printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
  875. get_driver_name(crypto_ahash, tfm));
  876. if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) {
  877. pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm),
  878. MAX_DIGEST_SIZE);
  879. goto out;
  880. }
  881. test_hash_sg_init(sg);
  882. req = ahash_request_alloc(tfm, GFP_KERNEL);
  883. if (!req) {
  884. pr_err("ahash request allocation failure\n");
  885. goto out;
  886. }
  887. crypto_init_wait(&wait);
  888. ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  889. crypto_req_done, &wait);
  890. output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
  891. if (!output)
  892. goto out_nomem;
  893. for (i = 0; speed[i].blen != 0; i++) {
  894. if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
  895. pr_err("template (%u) too big for tvmem (%lu)\n",
  896. speed[i].blen, TVMEMSIZE * PAGE_SIZE);
  897. break;
  898. }
  899. if (speed[i].klen)
  900. crypto_ahash_setkey(tfm, tvmem[0], speed[i].klen);
  901. pr_info("test%3u "
  902. "(%5u byte blocks,%5u bytes per update,%4u updates): ",
  903. i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
  904. ahash_request_set_crypt(req, sg, output, speed[i].plen);
  905. if (secs) {
  906. ret = test_ahash_jiffies(req, speed[i].blen,
  907. speed[i].plen, output, secs);
  908. cond_resched();
  909. } else {
  910. ret = test_ahash_cycles(req, speed[i].blen,
  911. speed[i].plen, output);
  912. }
  913. if (ret) {
  914. pr_err("hashing failed ret=%d\n", ret);
  915. break;
  916. }
  917. }
  918. kfree(output);
  919. out_nomem:
  920. ahash_request_free(req);
  921. out:
  922. crypto_free_ahash(tfm);
  923. }
  924. static void test_ahash_speed(const char *algo, unsigned int secs,
  925. struct hash_speed *speed)
  926. {
  927. return test_ahash_speed_common(algo, secs, speed, 0);
  928. }
  929. static void test_hash_speed(const char *algo, unsigned int secs,
  930. struct hash_speed *speed)
  931. {
  932. return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC);
  933. }
  934. struct test_mb_skcipher_data {
  935. struct scatterlist sg[XBUFSIZE];
  936. struct skcipher_request *req;
  937. struct crypto_wait wait;
  938. char *xbuf[XBUFSIZE];
  939. };
  940. static int do_mult_acipher_op(struct test_mb_skcipher_data *data, int enc,
  941. u32 num_mb, int *rc)
  942. {
  943. int i, err = 0;
  944. /* Fire up a bunch of concurrent requests */
  945. for (i = 0; i < num_mb; i++) {
  946. if (enc == ENCRYPT)
  947. rc[i] = crypto_skcipher_encrypt(data[i].req);
  948. else
  949. rc[i] = crypto_skcipher_decrypt(data[i].req);
  950. }
  951. /* Wait for all requests to finish */
  952. for (i = 0; i < num_mb; i++) {
  953. rc[i] = crypto_wait_req(rc[i], &data[i].wait);
  954. if (rc[i]) {
  955. pr_info("concurrent request %d error %d\n", i, rc[i]);
  956. err = rc[i];
  957. }
  958. }
  959. return err;
  960. }
  961. static int test_mb_acipher_jiffies(struct test_mb_skcipher_data *data, int enc,
  962. int blen, int secs, u32 num_mb)
  963. {
  964. unsigned long start, end;
  965. int bcount;
  966. int ret = 0;
  967. int *rc;
  968. rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
  969. if (!rc)
  970. return -ENOMEM;
  971. for (start = jiffies, end = start + secs * HZ, bcount = 0;
  972. time_before(jiffies, end); bcount++) {
  973. ret = do_mult_acipher_op(data, enc, num_mb, rc);
  974. if (ret)
  975. goto out;
  976. }
  977. pr_cont("%d operations in %d seconds (%ld bytes)\n",
  978. bcount * num_mb, secs, (long)bcount * blen * num_mb);
  979. out:
  980. kfree(rc);
  981. return ret;
  982. }
  983. static int test_mb_acipher_cycles(struct test_mb_skcipher_data *data, int enc,
  984. int blen, u32 num_mb)
  985. {
  986. unsigned long cycles = 0;
  987. int ret = 0;
  988. int i;
  989. int *rc;
  990. rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
  991. if (!rc)
  992. return -ENOMEM;
  993. /* Warm-up run. */
  994. for (i = 0; i < 4; i++) {
  995. ret = do_mult_acipher_op(data, enc, num_mb, rc);
  996. if (ret)
  997. goto out;
  998. }
  999. /* The real thing. */
  1000. for (i = 0; i < 8; i++) {
  1001. cycles_t start, end;
  1002. start = get_cycles();
  1003. ret = do_mult_acipher_op(data, enc, num_mb, rc);
  1004. end = get_cycles();
  1005. if (ret)
  1006. goto out;
  1007. cycles += end - start;
  1008. }
  1009. pr_cont("1 operation in %lu cycles (%d bytes)\n",
  1010. (cycles + 4) / (8 * num_mb), blen);
  1011. out:
  1012. kfree(rc);
  1013. return ret;
  1014. }
  1015. static void test_mb_skcipher_speed(const char *algo, int enc, int secs,
  1016. struct cipher_speed_template *template,
  1017. unsigned int tcount, u8 *keysize, u32 num_mb)
  1018. {
  1019. struct test_mb_skcipher_data *data;
  1020. struct crypto_skcipher *tfm;
  1021. unsigned int i, j, iv_len;
  1022. const char *key;
  1023. const char *e;
  1024. u32 *b_size;
  1025. char iv[128];
  1026. int ret;
  1027. if (enc == ENCRYPT)
  1028. e = "encryption";
  1029. else
  1030. e = "decryption";
  1031. data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
  1032. if (!data)
  1033. return;
  1034. tfm = crypto_alloc_skcipher(algo, 0, 0);
  1035. if (IS_ERR(tfm)) {
  1036. pr_err("failed to load transform for %s: %ld\n",
  1037. algo, PTR_ERR(tfm));
  1038. goto out_free_data;
  1039. }
  1040. for (i = 0; i < num_mb; ++i)
  1041. if (testmgr_alloc_buf(data[i].xbuf)) {
  1042. while (i--)
  1043. testmgr_free_buf(data[i].xbuf);
  1044. goto out_free_tfm;
  1045. }
  1046. for (i = 0; i < num_mb; ++i)
  1047. if (testmgr_alloc_buf(data[i].xbuf)) {
  1048. while (i--)
  1049. testmgr_free_buf(data[i].xbuf);
  1050. goto out_free_tfm;
  1051. }
  1052. for (i = 0; i < num_mb; ++i) {
  1053. data[i].req = skcipher_request_alloc(tfm, GFP_KERNEL);
  1054. if (!data[i].req) {
  1055. pr_err("alg: skcipher: Failed to allocate request for %s\n",
  1056. algo);
  1057. while (i--)
  1058. skcipher_request_free(data[i].req);
  1059. goto out_free_xbuf;
  1060. }
  1061. }
  1062. for (i = 0; i < num_mb; ++i) {
  1063. skcipher_request_set_callback(data[i].req,
  1064. CRYPTO_TFM_REQ_MAY_BACKLOG,
  1065. crypto_req_done, &data[i].wait);
  1066. crypto_init_wait(&data[i].wait);
  1067. }
  1068. pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo,
  1069. get_driver_name(crypto_skcipher, tfm), e);
  1070. i = 0;
  1071. do {
  1072. b_size = block_sizes;
  1073. do {
  1074. if (*b_size > XBUFSIZE * PAGE_SIZE) {
  1075. pr_err("template (%u) too big for buffer (%lu)\n",
  1076. *b_size, XBUFSIZE * PAGE_SIZE);
  1077. goto out;
  1078. }
  1079. pr_info("test %u (%d bit key, %d byte blocks): ", i,
  1080. *keysize * 8, *b_size);
  1081. /* Set up tfm global state, i.e. the key */
  1082. memset(tvmem[0], 0xff, PAGE_SIZE);
  1083. key = tvmem[0];
  1084. for (j = 0; j < tcount; j++) {
  1085. if (template[j].klen == *keysize) {
  1086. key = template[j].key;
  1087. break;
  1088. }
  1089. }
  1090. crypto_skcipher_clear_flags(tfm, ~0);
  1091. ret = crypto_skcipher_setkey(tfm, key, *keysize);
  1092. if (ret) {
  1093. pr_err("setkey() failed flags=%x\n",
  1094. crypto_skcipher_get_flags(tfm));
  1095. goto out;
  1096. }
  1097. iv_len = crypto_skcipher_ivsize(tfm);
  1098. if (iv_len)
  1099. memset(&iv, 0xff, iv_len);
  1100. /* Now setup per request stuff, i.e. buffers */
  1101. for (j = 0; j < num_mb; ++j) {
  1102. struct test_mb_skcipher_data *cur = &data[j];
  1103. unsigned int k = *b_size;
  1104. unsigned int pages = DIV_ROUND_UP(k, PAGE_SIZE);
  1105. unsigned int p = 0;
  1106. sg_init_table(cur->sg, pages);
  1107. while (k > PAGE_SIZE) {
  1108. sg_set_buf(cur->sg + p, cur->xbuf[p],
  1109. PAGE_SIZE);
  1110. memset(cur->xbuf[p], 0xff, PAGE_SIZE);
  1111. p++;
  1112. k -= PAGE_SIZE;
  1113. }
  1114. sg_set_buf(cur->sg + p, cur->xbuf[p], k);
  1115. memset(cur->xbuf[p], 0xff, k);
  1116. skcipher_request_set_crypt(cur->req, cur->sg,
  1117. cur->sg, *b_size,
  1118. iv);
  1119. }
  1120. if (secs) {
  1121. ret = test_mb_acipher_jiffies(data, enc,
  1122. *b_size, secs,
  1123. num_mb);
  1124. cond_resched();
  1125. } else {
  1126. ret = test_mb_acipher_cycles(data, enc,
  1127. *b_size, num_mb);
  1128. }
  1129. if (ret) {
  1130. pr_err("%s() failed flags=%x\n", e,
  1131. crypto_skcipher_get_flags(tfm));
  1132. break;
  1133. }
  1134. b_size++;
  1135. i++;
  1136. } while (*b_size);
  1137. keysize++;
  1138. } while (*keysize);
  1139. out:
  1140. for (i = 0; i < num_mb; ++i)
  1141. skcipher_request_free(data[i].req);
  1142. out_free_xbuf:
  1143. for (i = 0; i < num_mb; ++i)
  1144. testmgr_free_buf(data[i].xbuf);
  1145. out_free_tfm:
  1146. crypto_free_skcipher(tfm);
  1147. out_free_data:
  1148. kfree(data);
  1149. }
  1150. static inline int do_one_acipher_op(struct skcipher_request *req, int ret)
  1151. {
  1152. struct crypto_wait *wait = req->base.data;
  1153. return crypto_wait_req(ret, wait);
  1154. }
  1155. static int test_acipher_jiffies(struct skcipher_request *req, int enc,
  1156. int blen, int secs)
  1157. {
  1158. unsigned long start, end;
  1159. int bcount;
  1160. int ret;
  1161. for (start = jiffies, end = start + secs * HZ, bcount = 0;
  1162. time_before(jiffies, end); bcount++) {
  1163. if (enc)
  1164. ret = do_one_acipher_op(req,
  1165. crypto_skcipher_encrypt(req));
  1166. else
  1167. ret = do_one_acipher_op(req,
  1168. crypto_skcipher_decrypt(req));
  1169. if (ret)
  1170. return ret;
  1171. }
  1172. pr_cont("%d operations in %d seconds (%ld bytes)\n",
  1173. bcount, secs, (long)bcount * blen);
  1174. return 0;
  1175. }
  1176. static int test_acipher_cycles(struct skcipher_request *req, int enc,
  1177. int blen)
  1178. {
  1179. unsigned long cycles = 0;
  1180. int ret = 0;
  1181. int i;
  1182. /* Warm-up run. */
  1183. for (i = 0; i < 4; i++) {
  1184. if (enc)
  1185. ret = do_one_acipher_op(req,
  1186. crypto_skcipher_encrypt(req));
  1187. else
  1188. ret = do_one_acipher_op(req,
  1189. crypto_skcipher_decrypt(req));
  1190. if (ret)
  1191. goto out;
  1192. }
  1193. /* The real thing. */
  1194. for (i = 0; i < 8; i++) {
  1195. cycles_t start, end;
  1196. start = get_cycles();
  1197. if (enc)
  1198. ret = do_one_acipher_op(req,
  1199. crypto_skcipher_encrypt(req));
  1200. else
  1201. ret = do_one_acipher_op(req,
  1202. crypto_skcipher_decrypt(req));
  1203. end = get_cycles();
  1204. if (ret)
  1205. goto out;
  1206. cycles += end - start;
  1207. }
  1208. out:
  1209. if (ret == 0)
  1210. pr_cont("1 operation in %lu cycles (%d bytes)\n",
  1211. (cycles + 4) / 8, blen);
  1212. return ret;
  1213. }
  1214. static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
  1215. struct cipher_speed_template *template,
  1216. unsigned int tcount, u8 *keysize, bool async)
  1217. {
  1218. unsigned int ret, i, j, k, iv_len;
  1219. struct crypto_wait wait;
  1220. const char *key;
  1221. char iv[128];
  1222. struct skcipher_request *req;
  1223. struct crypto_skcipher *tfm;
  1224. const char *e;
  1225. u32 *b_size;
  1226. if (enc == ENCRYPT)
  1227. e = "encryption";
  1228. else
  1229. e = "decryption";
  1230. crypto_init_wait(&wait);
  1231. tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC);
  1232. if (IS_ERR(tfm)) {
  1233. pr_err("failed to load transform for %s: %ld\n", algo,
  1234. PTR_ERR(tfm));
  1235. return;
  1236. }
  1237. pr_info("\ntesting speed of async %s (%s) %s\n", algo,
  1238. get_driver_name(crypto_skcipher, tfm), e);
  1239. req = skcipher_request_alloc(tfm, GFP_KERNEL);
  1240. if (!req) {
  1241. pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
  1242. algo);
  1243. goto out;
  1244. }
  1245. skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  1246. crypto_req_done, &wait);
  1247. i = 0;
  1248. do {
  1249. b_size = block_sizes;
  1250. do {
  1251. struct scatterlist sg[TVMEMSIZE];
  1252. if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
  1253. pr_err("template (%u) too big for "
  1254. "tvmem (%lu)\n", *keysize + *b_size,
  1255. TVMEMSIZE * PAGE_SIZE);
  1256. goto out_free_req;
  1257. }
  1258. pr_info("test %u (%d bit key, %d byte blocks): ", i,
  1259. *keysize * 8, *b_size);
  1260. memset(tvmem[0], 0xff, PAGE_SIZE);
  1261. /* set key, plain text and IV */
  1262. key = tvmem[0];
  1263. for (j = 0; j < tcount; j++) {
  1264. if (template[j].klen == *keysize) {
  1265. key = template[j].key;
  1266. break;
  1267. }
  1268. }
  1269. crypto_skcipher_clear_flags(tfm, ~0);
  1270. ret = crypto_skcipher_setkey(tfm, key, *keysize);
  1271. if (ret) {
  1272. pr_err("setkey() failed flags=%x\n",
  1273. crypto_skcipher_get_flags(tfm));
  1274. goto out_free_req;
  1275. }
  1276. k = *keysize + *b_size;
  1277. sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
  1278. if (k > PAGE_SIZE) {
  1279. sg_set_buf(sg, tvmem[0] + *keysize,
  1280. PAGE_SIZE - *keysize);
  1281. k -= PAGE_SIZE;
  1282. j = 1;
  1283. while (k > PAGE_SIZE) {
  1284. sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
  1285. memset(tvmem[j], 0xff, PAGE_SIZE);
  1286. j++;
  1287. k -= PAGE_SIZE;
  1288. }
  1289. sg_set_buf(sg + j, tvmem[j], k);
  1290. memset(tvmem[j], 0xff, k);
  1291. } else {
  1292. sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
  1293. }
  1294. iv_len = crypto_skcipher_ivsize(tfm);
  1295. if (iv_len)
  1296. memset(&iv, 0xff, iv_len);
  1297. skcipher_request_set_crypt(req, sg, sg, *b_size, iv);
  1298. if (secs) {
  1299. ret = test_acipher_jiffies(req, enc,
  1300. *b_size, secs);
  1301. cond_resched();
  1302. } else {
  1303. ret = test_acipher_cycles(req, enc,
  1304. *b_size);
  1305. }
  1306. if (ret) {
  1307. pr_err("%s() failed flags=%x\n", e,
  1308. crypto_skcipher_get_flags(tfm));
  1309. break;
  1310. }
  1311. b_size++;
  1312. i++;
  1313. } while (*b_size);
  1314. keysize++;
  1315. } while (*keysize);
  1316. out_free_req:
  1317. skcipher_request_free(req);
  1318. out:
  1319. crypto_free_skcipher(tfm);
  1320. }
  1321. static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
  1322. struct cipher_speed_template *template,
  1323. unsigned int tcount, u8 *keysize)
  1324. {
  1325. return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
  1326. true);
  1327. }
  1328. static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
  1329. struct cipher_speed_template *template,
  1330. unsigned int tcount, u8 *keysize)
  1331. {
  1332. return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
  1333. false);
  1334. }
  1335. static void test_available(void)
  1336. {
  1337. char **name = check;
  1338. while (*name) {
  1339. printk("alg %s ", *name);
  1340. printk(crypto_has_alg(*name, 0, 0) ?
  1341. "found\n" : "not found\n");
  1342. name++;
  1343. }
  1344. }
  1345. static inline int tcrypt_test(const char *alg)
  1346. {
  1347. int ret;
  1348. pr_debug("testing %s\n", alg);
  1349. ret = alg_test(alg, alg, 0, 0);
  1350. /* non-fips algs return -EINVAL in fips mode */
  1351. if (fips_enabled && ret == -EINVAL)
  1352. ret = 0;
  1353. return ret;
  1354. }
  1355. static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)
  1356. {
  1357. int i;
  1358. int ret = 0;
  1359. switch (m) {
  1360. case 0:
  1361. if (alg) {
  1362. if (!crypto_has_alg(alg, type,
  1363. mask ?: CRYPTO_ALG_TYPE_MASK))
  1364. ret = -ENOENT;
  1365. break;
  1366. }
  1367. for (i = 1; i < 200; i++)
  1368. ret += do_test(NULL, 0, 0, i, num_mb);
  1369. break;
  1370. case 1:
  1371. ret += tcrypt_test("md5");
  1372. break;
  1373. case 2:
  1374. ret += tcrypt_test("sha1");
  1375. break;
  1376. case 3:
  1377. ret += tcrypt_test("ecb(des)");
  1378. ret += tcrypt_test("cbc(des)");
  1379. ret += tcrypt_test("ctr(des)");
  1380. break;
  1381. case 4:
  1382. ret += tcrypt_test("ecb(des3_ede)");
  1383. ret += tcrypt_test("cbc(des3_ede)");
  1384. ret += tcrypt_test("ctr(des3_ede)");
  1385. break;
  1386. case 5:
  1387. ret += tcrypt_test("md4");
  1388. break;
  1389. case 6:
  1390. ret += tcrypt_test("sha256");
  1391. break;
  1392. case 7:
  1393. ret += tcrypt_test("ecb(blowfish)");
  1394. ret += tcrypt_test("cbc(blowfish)");
  1395. ret += tcrypt_test("ctr(blowfish)");
  1396. break;
  1397. case 8:
  1398. ret += tcrypt_test("ecb(twofish)");
  1399. ret += tcrypt_test("cbc(twofish)");
  1400. ret += tcrypt_test("ctr(twofish)");
  1401. ret += tcrypt_test("lrw(twofish)");
  1402. ret += tcrypt_test("xts(twofish)");
  1403. break;
  1404. case 9:
  1405. ret += tcrypt_test("ecb(serpent)");
  1406. ret += tcrypt_test("cbc(serpent)");
  1407. ret += tcrypt_test("ctr(serpent)");
  1408. ret += tcrypt_test("lrw(serpent)");
  1409. ret += tcrypt_test("xts(serpent)");
  1410. break;
  1411. case 10:
  1412. ret += tcrypt_test("ecb(aes)");
  1413. ret += tcrypt_test("cbc(aes)");
  1414. ret += tcrypt_test("lrw(aes)");
  1415. ret += tcrypt_test("xts(aes)");
  1416. ret += tcrypt_test("ctr(aes)");
  1417. ret += tcrypt_test("rfc3686(ctr(aes))");
  1418. ret += tcrypt_test("cfb(aes)");
  1419. break;
  1420. case 11:
  1421. ret += tcrypt_test("sha384");
  1422. break;
  1423. case 12:
  1424. ret += tcrypt_test("sha512");
  1425. break;
  1426. case 13:
  1427. ret += tcrypt_test("deflate");
  1428. break;
  1429. case 14:
  1430. ret += tcrypt_test("ecb(cast5)");
  1431. ret += tcrypt_test("cbc(cast5)");
  1432. ret += tcrypt_test("ctr(cast5)");
  1433. break;
  1434. case 15:
  1435. ret += tcrypt_test("ecb(cast6)");
  1436. ret += tcrypt_test("cbc(cast6)");
  1437. ret += tcrypt_test("ctr(cast6)");
  1438. ret += tcrypt_test("lrw(cast6)");
  1439. ret += tcrypt_test("xts(cast6)");
  1440. break;
  1441. case 16:
  1442. ret += tcrypt_test("ecb(arc4)");
  1443. break;
  1444. case 17:
  1445. ret += tcrypt_test("michael_mic");
  1446. break;
  1447. case 18:
  1448. ret += tcrypt_test("crc32c");
  1449. break;
  1450. case 19:
  1451. ret += tcrypt_test("ecb(tea)");
  1452. break;
  1453. case 20:
  1454. ret += tcrypt_test("ecb(xtea)");
  1455. break;
  1456. case 21:
  1457. ret += tcrypt_test("ecb(khazad)");
  1458. break;
  1459. case 22:
  1460. ret += tcrypt_test("wp512");
  1461. break;
  1462. case 23:
  1463. ret += tcrypt_test("wp384");
  1464. break;
  1465. case 24:
  1466. ret += tcrypt_test("wp256");
  1467. break;
  1468. case 25:
  1469. ret += tcrypt_test("ecb(tnepres)");
  1470. break;
  1471. case 26:
  1472. ret += tcrypt_test("ecb(anubis)");
  1473. ret += tcrypt_test("cbc(anubis)");
  1474. break;
  1475. case 27:
  1476. ret += tcrypt_test("tgr192");
  1477. break;
  1478. case 28:
  1479. ret += tcrypt_test("tgr160");
  1480. break;
  1481. case 29:
  1482. ret += tcrypt_test("tgr128");
  1483. break;
  1484. case 30:
  1485. ret += tcrypt_test("ecb(xeta)");
  1486. break;
  1487. case 31:
  1488. ret += tcrypt_test("pcbc(fcrypt)");
  1489. break;
  1490. case 32:
  1491. ret += tcrypt_test("ecb(camellia)");
  1492. ret += tcrypt_test("cbc(camellia)");
  1493. ret += tcrypt_test("ctr(camellia)");
  1494. ret += tcrypt_test("lrw(camellia)");
  1495. ret += tcrypt_test("xts(camellia)");
  1496. break;
  1497. case 33:
  1498. ret += tcrypt_test("sha224");
  1499. break;
  1500. case 34:
  1501. ret += tcrypt_test("salsa20");
  1502. break;
  1503. case 35:
  1504. ret += tcrypt_test("gcm(aes)");
  1505. break;
  1506. case 36:
  1507. ret += tcrypt_test("lzo");
  1508. break;
  1509. case 37:
  1510. ret += tcrypt_test("ccm(aes)");
  1511. break;
  1512. case 38:
  1513. ret += tcrypt_test("cts(cbc(aes))");
  1514. break;
  1515. case 39:
  1516. ret += tcrypt_test("rmd128");
  1517. break;
  1518. case 40:
  1519. ret += tcrypt_test("rmd160");
  1520. break;
  1521. case 41:
  1522. ret += tcrypt_test("rmd256");
  1523. break;
  1524. case 42:
  1525. ret += tcrypt_test("rmd320");
  1526. break;
  1527. case 43:
  1528. ret += tcrypt_test("ecb(seed)");
  1529. break;
  1530. case 44:
  1531. ret += tcrypt_test("zlib");
  1532. break;
  1533. case 45:
  1534. ret += tcrypt_test("rfc4309(ccm(aes))");
  1535. break;
  1536. case 46:
  1537. ret += tcrypt_test("ghash");
  1538. break;
  1539. case 47:
  1540. ret += tcrypt_test("crct10dif");
  1541. break;
  1542. case 48:
  1543. ret += tcrypt_test("sha3-224");
  1544. break;
  1545. case 49:
  1546. ret += tcrypt_test("sha3-256");
  1547. break;
  1548. case 50:
  1549. ret += tcrypt_test("sha3-384");
  1550. break;
  1551. case 51:
  1552. ret += tcrypt_test("sha3-512");
  1553. break;
  1554. case 52:
  1555. ret += tcrypt_test("sm3");
  1556. break;
  1557. case 100:
  1558. ret += tcrypt_test("hmac(md5)");
  1559. break;
  1560. case 101:
  1561. ret += tcrypt_test("hmac(sha1)");
  1562. break;
  1563. case 102:
  1564. ret += tcrypt_test("hmac(sha256)");
  1565. break;
  1566. case 103:
  1567. ret += tcrypt_test("hmac(sha384)");
  1568. break;
  1569. case 104:
  1570. ret += tcrypt_test("hmac(sha512)");
  1571. break;
  1572. case 105:
  1573. ret += tcrypt_test("hmac(sha224)");
  1574. break;
  1575. case 106:
  1576. ret += tcrypt_test("xcbc(aes)");
  1577. break;
  1578. case 107:
  1579. ret += tcrypt_test("hmac(rmd128)");
  1580. break;
  1581. case 108:
  1582. ret += tcrypt_test("hmac(rmd160)");
  1583. break;
  1584. case 109:
  1585. ret += tcrypt_test("vmac64(aes)");
  1586. break;
  1587. case 111:
  1588. ret += tcrypt_test("hmac(sha3-224)");
  1589. break;
  1590. case 112:
  1591. ret += tcrypt_test("hmac(sha3-256)");
  1592. break;
  1593. case 113:
  1594. ret += tcrypt_test("hmac(sha3-384)");
  1595. break;
  1596. case 114:
  1597. ret += tcrypt_test("hmac(sha3-512)");
  1598. break;
  1599. case 150:
  1600. ret += tcrypt_test("ansi_cprng");
  1601. break;
  1602. case 151:
  1603. ret += tcrypt_test("rfc4106(gcm(aes))");
  1604. break;
  1605. case 152:
  1606. ret += tcrypt_test("rfc4543(gcm(aes))");
  1607. break;
  1608. case 153:
  1609. ret += tcrypt_test("cmac(aes)");
  1610. break;
  1611. case 154:
  1612. ret += tcrypt_test("cmac(des3_ede)");
  1613. break;
  1614. case 155:
  1615. ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
  1616. break;
  1617. case 156:
  1618. ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
  1619. break;
  1620. case 157:
  1621. ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
  1622. break;
  1623. case 181:
  1624. ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
  1625. break;
  1626. case 182:
  1627. ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
  1628. break;
  1629. case 183:
  1630. ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
  1631. break;
  1632. case 184:
  1633. ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
  1634. break;
  1635. case 185:
  1636. ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
  1637. break;
  1638. case 186:
  1639. ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
  1640. break;
  1641. case 187:
  1642. ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
  1643. break;
  1644. case 188:
  1645. ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
  1646. break;
  1647. case 189:
  1648. ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
  1649. break;
  1650. case 190:
  1651. ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
  1652. break;
  1653. case 191:
  1654. ret += tcrypt_test("ecb(sm4)");
  1655. break;
  1656. case 200:
  1657. test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
  1658. speed_template_16_24_32);
  1659. test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
  1660. speed_template_16_24_32);
  1661. test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
  1662. speed_template_16_24_32);
  1663. test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
  1664. speed_template_16_24_32);
  1665. test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
  1666. speed_template_32_40_48);
  1667. test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
  1668. speed_template_32_40_48);
  1669. test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
  1670. speed_template_32_64);
  1671. test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
  1672. speed_template_32_64);
  1673. test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
  1674. speed_template_16_24_32);
  1675. test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
  1676. speed_template_16_24_32);
  1677. test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
  1678. speed_template_16_24_32);
  1679. test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
  1680. speed_template_16_24_32);
  1681. test_cipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
  1682. speed_template_16_24_32);
  1683. test_cipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
  1684. speed_template_16_24_32);
  1685. break;
  1686. case 201:
  1687. test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
  1688. des3_speed_template, DES3_SPEED_VECTORS,
  1689. speed_template_24);
  1690. test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
  1691. des3_speed_template, DES3_SPEED_VECTORS,
  1692. speed_template_24);
  1693. test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
  1694. des3_speed_template, DES3_SPEED_VECTORS,
  1695. speed_template_24);
  1696. test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
  1697. des3_speed_template, DES3_SPEED_VECTORS,
  1698. speed_template_24);
  1699. test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
  1700. des3_speed_template, DES3_SPEED_VECTORS,
  1701. speed_template_24);
  1702. test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
  1703. des3_speed_template, DES3_SPEED_VECTORS,
  1704. speed_template_24);
  1705. break;
  1706. case 202:
  1707. test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
  1708. speed_template_16_24_32);
  1709. test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
  1710. speed_template_16_24_32);
  1711. test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
  1712. speed_template_16_24_32);
  1713. test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
  1714. speed_template_16_24_32);
  1715. test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
  1716. speed_template_16_24_32);
  1717. test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
  1718. speed_template_16_24_32);
  1719. test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
  1720. speed_template_32_40_48);
  1721. test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
  1722. speed_template_32_40_48);
  1723. test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
  1724. speed_template_32_48_64);
  1725. test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
  1726. speed_template_32_48_64);
  1727. break;
  1728. case 203:
  1729. test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
  1730. speed_template_8_32);
  1731. test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
  1732. speed_template_8_32);
  1733. test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
  1734. speed_template_8_32);
  1735. test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
  1736. speed_template_8_32);
  1737. test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
  1738. speed_template_8_32);
  1739. test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
  1740. speed_template_8_32);
  1741. break;
  1742. case 204:
  1743. test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
  1744. speed_template_8);
  1745. test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
  1746. speed_template_8);
  1747. test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
  1748. speed_template_8);
  1749. test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
  1750. speed_template_8);
  1751. break;
  1752. case 205:
  1753. test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
  1754. speed_template_16_24_32);
  1755. test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
  1756. speed_template_16_24_32);
  1757. test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
  1758. speed_template_16_24_32);
  1759. test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
  1760. speed_template_16_24_32);
  1761. test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
  1762. speed_template_16_24_32);
  1763. test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
  1764. speed_template_16_24_32);
  1765. test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
  1766. speed_template_32_40_48);
  1767. test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
  1768. speed_template_32_40_48);
  1769. test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
  1770. speed_template_32_48_64);
  1771. test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
  1772. speed_template_32_48_64);
  1773. break;
  1774. case 206:
  1775. test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
  1776. speed_template_16_32);
  1777. break;
  1778. case 207:
  1779. test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
  1780. speed_template_16_32);
  1781. test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
  1782. speed_template_16_32);
  1783. test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
  1784. speed_template_16_32);
  1785. test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
  1786. speed_template_16_32);
  1787. test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
  1788. speed_template_16_32);
  1789. test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
  1790. speed_template_16_32);
  1791. test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
  1792. speed_template_32_48);
  1793. test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
  1794. speed_template_32_48);
  1795. test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
  1796. speed_template_32_64);
  1797. test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
  1798. speed_template_32_64);
  1799. break;
  1800. case 208:
  1801. test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
  1802. speed_template_8);
  1803. break;
  1804. case 209:
  1805. test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
  1806. speed_template_8_16);
  1807. test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
  1808. speed_template_8_16);
  1809. test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
  1810. speed_template_8_16);
  1811. test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
  1812. speed_template_8_16);
  1813. test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
  1814. speed_template_8_16);
  1815. test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
  1816. speed_template_8_16);
  1817. break;
  1818. case 210:
  1819. test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
  1820. speed_template_16_32);
  1821. test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
  1822. speed_template_16_32);
  1823. test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
  1824. speed_template_16_32);
  1825. test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
  1826. speed_template_16_32);
  1827. test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
  1828. speed_template_16_32);
  1829. test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
  1830. speed_template_16_32);
  1831. test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
  1832. speed_template_32_48);
  1833. test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
  1834. speed_template_32_48);
  1835. test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
  1836. speed_template_32_64);
  1837. test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
  1838. speed_template_32_64);
  1839. break;
  1840. case 211:
  1841. test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
  1842. NULL, 0, 16, 16, aead_speed_template_20);
  1843. test_aead_speed("gcm(aes)", ENCRYPT, sec,
  1844. NULL, 0, 16, 8, speed_template_16_24_32);
  1845. test_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec,
  1846. NULL, 0, 16, 16, aead_speed_template_20);
  1847. test_aead_speed("gcm(aes)", DECRYPT, sec,
  1848. NULL, 0, 16, 8, speed_template_16_24_32);
  1849. break;
  1850. case 212:
  1851. test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
  1852. NULL, 0, 16, 16, aead_speed_template_19);
  1853. test_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec,
  1854. NULL, 0, 16, 16, aead_speed_template_19);
  1855. break;
  1856. case 213:
  1857. test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
  1858. NULL, 0, 16, 8, aead_speed_template_36);
  1859. test_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT, sec,
  1860. NULL, 0, 16, 8, aead_speed_template_36);
  1861. break;
  1862. case 214:
  1863. test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
  1864. speed_template_32);
  1865. break;
  1866. case 215:
  1867. test_mb_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec, NULL,
  1868. 0, 16, 16, aead_speed_template_20, num_mb);
  1869. test_mb_aead_speed("gcm(aes)", ENCRYPT, sec, NULL, 0, 16, 8,
  1870. speed_template_16_24_32, num_mb);
  1871. test_mb_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec, NULL,
  1872. 0, 16, 16, aead_speed_template_20, num_mb);
  1873. test_mb_aead_speed("gcm(aes)", DECRYPT, sec, NULL, 0, 16, 8,
  1874. speed_template_16_24_32, num_mb);
  1875. break;
  1876. case 216:
  1877. test_mb_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec, NULL, 0,
  1878. 16, 16, aead_speed_template_19, num_mb);
  1879. test_mb_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec, NULL, 0,
  1880. 16, 16, aead_speed_template_19, num_mb);
  1881. break;
  1882. case 217:
  1883. test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT,
  1884. sec, NULL, 0, 16, 8, aead_speed_template_36,
  1885. num_mb);
  1886. test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT,
  1887. sec, NULL, 0, 16, 8, aead_speed_template_36,
  1888. num_mb);
  1889. break;
  1890. case 300:
  1891. if (alg) {
  1892. test_hash_speed(alg, sec, generic_hash_speed_template);
  1893. break;
  1894. }
  1895. /* fall through */
  1896. case 301:
  1897. test_hash_speed("md4", sec, generic_hash_speed_template);
  1898. if (mode > 300 && mode < 400) break;
  1899. /* fall through */
  1900. case 302:
  1901. test_hash_speed("md5", sec, generic_hash_speed_template);
  1902. if (mode > 300 && mode < 400) break;
  1903. /* fall through */
  1904. case 303:
  1905. test_hash_speed("sha1", sec, generic_hash_speed_template);
  1906. if (mode > 300 && mode < 400) break;
  1907. /* fall through */
  1908. case 304:
  1909. test_hash_speed("sha256", sec, generic_hash_speed_template);
  1910. if (mode > 300 && mode < 400) break;
  1911. /* fall through */
  1912. case 305:
  1913. test_hash_speed("sha384", sec, generic_hash_speed_template);
  1914. if (mode > 300 && mode < 400) break;
  1915. /* fall through */
  1916. case 306:
  1917. test_hash_speed("sha512", sec, generic_hash_speed_template);
  1918. if (mode > 300 && mode < 400) break;
  1919. /* fall through */
  1920. case 307:
  1921. test_hash_speed("wp256", sec, generic_hash_speed_template);
  1922. if (mode > 300 && mode < 400) break;
  1923. /* fall through */
  1924. case 308:
  1925. test_hash_speed("wp384", sec, generic_hash_speed_template);
  1926. if (mode > 300 && mode < 400) break;
  1927. /* fall through */
  1928. case 309:
  1929. test_hash_speed("wp512", sec, generic_hash_speed_template);
  1930. if (mode > 300 && mode < 400) break;
  1931. /* fall through */
  1932. case 310:
  1933. test_hash_speed("tgr128", sec, generic_hash_speed_template);
  1934. if (mode > 300 && mode < 400) break;
  1935. /* fall through */
  1936. case 311:
  1937. test_hash_speed("tgr160", sec, generic_hash_speed_template);
  1938. if (mode > 300 && mode < 400) break;
  1939. /* fall through */
  1940. case 312:
  1941. test_hash_speed("tgr192", sec, generic_hash_speed_template);
  1942. if (mode > 300 && mode < 400) break;
  1943. /* fall through */
  1944. case 313:
  1945. test_hash_speed("sha224", sec, generic_hash_speed_template);
  1946. if (mode > 300 && mode < 400) break;
  1947. /* fall through */
  1948. case 314:
  1949. test_hash_speed("rmd128", sec, generic_hash_speed_template);
  1950. if (mode > 300 && mode < 400) break;
  1951. /* fall through */
  1952. case 315:
  1953. test_hash_speed("rmd160", sec, generic_hash_speed_template);
  1954. if (mode > 300 && mode < 400) break;
  1955. /* fall through */
  1956. case 316:
  1957. test_hash_speed("rmd256", sec, generic_hash_speed_template);
  1958. if (mode > 300 && mode < 400) break;
  1959. /* fall through */
  1960. case 317:
  1961. test_hash_speed("rmd320", sec, generic_hash_speed_template);
  1962. if (mode > 300 && mode < 400) break;
  1963. /* fall through */
  1964. case 318:
  1965. test_hash_speed("ghash-generic", sec, hash_speed_template_16);
  1966. if (mode > 300 && mode < 400) break;
  1967. /* fall through */
  1968. case 319:
  1969. test_hash_speed("crc32c", sec, generic_hash_speed_template);
  1970. if (mode > 300 && mode < 400) break;
  1971. /* fall through */
  1972. case 320:
  1973. test_hash_speed("crct10dif", sec, generic_hash_speed_template);
  1974. if (mode > 300 && mode < 400) break;
  1975. /* fall through */
  1976. case 321:
  1977. test_hash_speed("poly1305", sec, poly1305_speed_template);
  1978. if (mode > 300 && mode < 400) break;
  1979. /* fall through */
  1980. case 322:
  1981. test_hash_speed("sha3-224", sec, generic_hash_speed_template);
  1982. if (mode > 300 && mode < 400) break;
  1983. /* fall through */
  1984. case 323:
  1985. test_hash_speed("sha3-256", sec, generic_hash_speed_template);
  1986. if (mode > 300 && mode < 400) break;
  1987. /* fall through */
  1988. case 324:
  1989. test_hash_speed("sha3-384", sec, generic_hash_speed_template);
  1990. if (mode > 300 && mode < 400) break;
  1991. /* fall through */
  1992. case 325:
  1993. test_hash_speed("sha3-512", sec, generic_hash_speed_template);
  1994. if (mode > 300 && mode < 400) break;
  1995. /* fall through */
  1996. case 326:
  1997. test_hash_speed("sm3", sec, generic_hash_speed_template);
  1998. if (mode > 300 && mode < 400) break;
  1999. /* fall through */
  2000. case 399:
  2001. break;
  2002. case 400:
  2003. if (alg) {
  2004. test_ahash_speed(alg, sec, generic_hash_speed_template);
  2005. break;
  2006. }
  2007. /* fall through */
  2008. case 401:
  2009. test_ahash_speed("md4", sec, generic_hash_speed_template);
  2010. if (mode > 400 && mode < 500) break;
  2011. /* fall through */
  2012. case 402:
  2013. test_ahash_speed("md5", sec, generic_hash_speed_template);
  2014. if (mode > 400 && mode < 500) break;
  2015. /* fall through */
  2016. case 403:
  2017. test_ahash_speed("sha1", sec, generic_hash_speed_template);
  2018. if (mode > 400 && mode < 500) break;
  2019. /* fall through */
  2020. case 404:
  2021. test_ahash_speed("sha256", sec, generic_hash_speed_template);
  2022. if (mode > 400 && mode < 500) break;
  2023. /* fall through */
  2024. case 405:
  2025. test_ahash_speed("sha384", sec, generic_hash_speed_template);
  2026. if (mode > 400 && mode < 500) break;
  2027. /* fall through */
  2028. case 406:
  2029. test_ahash_speed("sha512", sec, generic_hash_speed_template);
  2030. if (mode > 400 && mode < 500) break;
  2031. /* fall through */
  2032. case 407:
  2033. test_ahash_speed("wp256", sec, generic_hash_speed_template);
  2034. if (mode > 400 && mode < 500) break;
  2035. /* fall through */
  2036. case 408:
  2037. test_ahash_speed("wp384", sec, generic_hash_speed_template);
  2038. if (mode > 400 && mode < 500) break;
  2039. /* fall through */
  2040. case 409:
  2041. test_ahash_speed("wp512", sec, generic_hash_speed_template);
  2042. if (mode > 400 && mode < 500) break;
  2043. /* fall through */
  2044. case 410:
  2045. test_ahash_speed("tgr128", sec, generic_hash_speed_template);
  2046. if (mode > 400 && mode < 500) break;
  2047. /* fall through */
  2048. case 411:
  2049. test_ahash_speed("tgr160", sec, generic_hash_speed_template);
  2050. if (mode > 400 && mode < 500) break;
  2051. /* fall through */
  2052. case 412:
  2053. test_ahash_speed("tgr192", sec, generic_hash_speed_template);
  2054. if (mode > 400 && mode < 500) break;
  2055. /* fall through */
  2056. case 413:
  2057. test_ahash_speed("sha224", sec, generic_hash_speed_template);
  2058. if (mode > 400 && mode < 500) break;
  2059. /* fall through */
  2060. case 414:
  2061. test_ahash_speed("rmd128", sec, generic_hash_speed_template);
  2062. if (mode > 400 && mode < 500) break;
  2063. /* fall through */
  2064. case 415:
  2065. test_ahash_speed("rmd160", sec, generic_hash_speed_template);
  2066. if (mode > 400 && mode < 500) break;
  2067. /* fall through */
  2068. case 416:
  2069. test_ahash_speed("rmd256", sec, generic_hash_speed_template);
  2070. if (mode > 400 && mode < 500) break;
  2071. /* fall through */
  2072. case 417:
  2073. test_ahash_speed("rmd320", sec, generic_hash_speed_template);
  2074. if (mode > 400 && mode < 500) break;
  2075. /* fall through */
  2076. case 418:
  2077. test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
  2078. if (mode > 400 && mode < 500) break;
  2079. /* fall through */
  2080. case 419:
  2081. test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
  2082. if (mode > 400 && mode < 500) break;
  2083. /* fall through */
  2084. case 420:
  2085. test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
  2086. if (mode > 400 && mode < 500) break;
  2087. /* fall through */
  2088. case 421:
  2089. test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
  2090. if (mode > 400 && mode < 500) break;
  2091. /* fall through */
  2092. case 422:
  2093. test_mb_ahash_speed("sha1", sec, generic_hash_speed_template,
  2094. num_mb);
  2095. if (mode > 400 && mode < 500) break;
  2096. /* fall through */
  2097. case 423:
  2098. test_mb_ahash_speed("sha256", sec, generic_hash_speed_template,
  2099. num_mb);
  2100. if (mode > 400 && mode < 500) break;
  2101. /* fall through */
  2102. case 424:
  2103. test_mb_ahash_speed("sha512", sec, generic_hash_speed_template,
  2104. num_mb);
  2105. if (mode > 400 && mode < 500) break;
  2106. /* fall through */
  2107. case 425:
  2108. test_mb_ahash_speed("sm3", sec, generic_hash_speed_template,
  2109. num_mb);
  2110. if (mode > 400 && mode < 500) break;
  2111. /* fall through */
  2112. case 499:
  2113. break;
  2114. case 500:
  2115. test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
  2116. speed_template_16_24_32);
  2117. test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
  2118. speed_template_16_24_32);
  2119. test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
  2120. speed_template_16_24_32);
  2121. test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
  2122. speed_template_16_24_32);
  2123. test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
  2124. speed_template_32_40_48);
  2125. test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
  2126. speed_template_32_40_48);
  2127. test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
  2128. speed_template_32_64);
  2129. test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
  2130. speed_template_32_64);
  2131. test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
  2132. speed_template_16_24_32);
  2133. test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
  2134. speed_template_16_24_32);
  2135. test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
  2136. speed_template_16_24_32);
  2137. test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
  2138. speed_template_16_24_32);
  2139. test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
  2140. speed_template_16_24_32);
  2141. test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
  2142. speed_template_16_24_32);
  2143. test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
  2144. speed_template_16_24_32);
  2145. test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
  2146. speed_template_16_24_32);
  2147. test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
  2148. speed_template_20_28_36);
  2149. test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
  2150. speed_template_20_28_36);
  2151. break;
  2152. case 501:
  2153. test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
  2154. des3_speed_template, DES3_SPEED_VECTORS,
  2155. speed_template_24);
  2156. test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
  2157. des3_speed_template, DES3_SPEED_VECTORS,
  2158. speed_template_24);
  2159. test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
  2160. des3_speed_template, DES3_SPEED_VECTORS,
  2161. speed_template_24);
  2162. test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
  2163. des3_speed_template, DES3_SPEED_VECTORS,
  2164. speed_template_24);
  2165. test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
  2166. des3_speed_template, DES3_SPEED_VECTORS,
  2167. speed_template_24);
  2168. test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
  2169. des3_speed_template, DES3_SPEED_VECTORS,
  2170. speed_template_24);
  2171. test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
  2172. des3_speed_template, DES3_SPEED_VECTORS,
  2173. speed_template_24);
  2174. test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
  2175. des3_speed_template, DES3_SPEED_VECTORS,
  2176. speed_template_24);
  2177. break;
  2178. case 502:
  2179. test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
  2180. speed_template_8);
  2181. test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
  2182. speed_template_8);
  2183. test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
  2184. speed_template_8);
  2185. test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
  2186. speed_template_8);
  2187. test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
  2188. speed_template_8);
  2189. test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
  2190. speed_template_8);
  2191. test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
  2192. speed_template_8);
  2193. test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
  2194. speed_template_8);
  2195. break;
  2196. case 503:
  2197. test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
  2198. speed_template_16_32);
  2199. test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
  2200. speed_template_16_32);
  2201. test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
  2202. speed_template_16_32);
  2203. test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
  2204. speed_template_16_32);
  2205. test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
  2206. speed_template_16_32);
  2207. test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
  2208. speed_template_16_32);
  2209. test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
  2210. speed_template_32_48);
  2211. test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
  2212. speed_template_32_48);
  2213. test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
  2214. speed_template_32_64);
  2215. test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
  2216. speed_template_32_64);
  2217. break;
  2218. case 504:
  2219. test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
  2220. speed_template_16_24_32);
  2221. test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
  2222. speed_template_16_24_32);
  2223. test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
  2224. speed_template_16_24_32);
  2225. test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
  2226. speed_template_16_24_32);
  2227. test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
  2228. speed_template_16_24_32);
  2229. test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
  2230. speed_template_16_24_32);
  2231. test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
  2232. speed_template_32_40_48);
  2233. test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
  2234. speed_template_32_40_48);
  2235. test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
  2236. speed_template_32_48_64);
  2237. test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
  2238. speed_template_32_48_64);
  2239. break;
  2240. case 505:
  2241. test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
  2242. speed_template_8);
  2243. break;
  2244. case 506:
  2245. test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
  2246. speed_template_8_16);
  2247. test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
  2248. speed_template_8_16);
  2249. test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
  2250. speed_template_8_16);
  2251. test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
  2252. speed_template_8_16);
  2253. test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
  2254. speed_template_8_16);
  2255. test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
  2256. speed_template_8_16);
  2257. break;
  2258. case 507:
  2259. test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
  2260. speed_template_16_32);
  2261. test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
  2262. speed_template_16_32);
  2263. test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
  2264. speed_template_16_32);
  2265. test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
  2266. speed_template_16_32);
  2267. test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
  2268. speed_template_16_32);
  2269. test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
  2270. speed_template_16_32);
  2271. test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
  2272. speed_template_32_48);
  2273. test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
  2274. speed_template_32_48);
  2275. test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
  2276. speed_template_32_64);
  2277. test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
  2278. speed_template_32_64);
  2279. break;
  2280. case 508:
  2281. test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
  2282. speed_template_16_32);
  2283. test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
  2284. speed_template_16_32);
  2285. test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
  2286. speed_template_16_32);
  2287. test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
  2288. speed_template_16_32);
  2289. test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
  2290. speed_template_16_32);
  2291. test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
  2292. speed_template_16_32);
  2293. test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
  2294. speed_template_32_48);
  2295. test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
  2296. speed_template_32_48);
  2297. test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
  2298. speed_template_32_64);
  2299. test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
  2300. speed_template_32_64);
  2301. break;
  2302. case 509:
  2303. test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
  2304. speed_template_8_32);
  2305. test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
  2306. speed_template_8_32);
  2307. test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
  2308. speed_template_8_32);
  2309. test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
  2310. speed_template_8_32);
  2311. test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
  2312. speed_template_8_32);
  2313. test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
  2314. speed_template_8_32);
  2315. break;
  2316. case 600:
  2317. test_mb_skcipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
  2318. speed_template_16_24_32, num_mb);
  2319. test_mb_skcipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
  2320. speed_template_16_24_32, num_mb);
  2321. test_mb_skcipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
  2322. speed_template_16_24_32, num_mb);
  2323. test_mb_skcipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
  2324. speed_template_16_24_32, num_mb);
  2325. test_mb_skcipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
  2326. speed_template_32_40_48, num_mb);
  2327. test_mb_skcipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
  2328. speed_template_32_40_48, num_mb);
  2329. test_mb_skcipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
  2330. speed_template_32_64, num_mb);
  2331. test_mb_skcipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
  2332. speed_template_32_64, num_mb);
  2333. test_mb_skcipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
  2334. speed_template_16_24_32, num_mb);
  2335. test_mb_skcipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
  2336. speed_template_16_24_32, num_mb);
  2337. test_mb_skcipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
  2338. speed_template_16_24_32, num_mb);
  2339. test_mb_skcipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
  2340. speed_template_16_24_32, num_mb);
  2341. test_mb_skcipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
  2342. speed_template_16_24_32, num_mb);
  2343. test_mb_skcipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
  2344. speed_template_16_24_32, num_mb);
  2345. test_mb_skcipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
  2346. speed_template_16_24_32, num_mb);
  2347. test_mb_skcipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
  2348. speed_template_16_24_32, num_mb);
  2349. test_mb_skcipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL,
  2350. 0, speed_template_20_28_36, num_mb);
  2351. test_mb_skcipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL,
  2352. 0, speed_template_20_28_36, num_mb);
  2353. break;
  2354. case 601:
  2355. test_mb_skcipher_speed("ecb(des3_ede)", ENCRYPT, sec,
  2356. des3_speed_template, DES3_SPEED_VECTORS,
  2357. speed_template_24, num_mb);
  2358. test_mb_skcipher_speed("ecb(des3_ede)", DECRYPT, sec,
  2359. des3_speed_template, DES3_SPEED_VECTORS,
  2360. speed_template_24, num_mb);
  2361. test_mb_skcipher_speed("cbc(des3_ede)", ENCRYPT, sec,
  2362. des3_speed_template, DES3_SPEED_VECTORS,
  2363. speed_template_24, num_mb);
  2364. test_mb_skcipher_speed("cbc(des3_ede)", DECRYPT, sec,
  2365. des3_speed_template, DES3_SPEED_VECTORS,
  2366. speed_template_24, num_mb);
  2367. test_mb_skcipher_speed("cfb(des3_ede)", ENCRYPT, sec,
  2368. des3_speed_template, DES3_SPEED_VECTORS,
  2369. speed_template_24, num_mb);
  2370. test_mb_skcipher_speed("cfb(des3_ede)", DECRYPT, sec,
  2371. des3_speed_template, DES3_SPEED_VECTORS,
  2372. speed_template_24, num_mb);
  2373. test_mb_skcipher_speed("ofb(des3_ede)", ENCRYPT, sec,
  2374. des3_speed_template, DES3_SPEED_VECTORS,
  2375. speed_template_24, num_mb);
  2376. test_mb_skcipher_speed("ofb(des3_ede)", DECRYPT, sec,
  2377. des3_speed_template, DES3_SPEED_VECTORS,
  2378. speed_template_24, num_mb);
  2379. break;
  2380. case 602:
  2381. test_mb_skcipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
  2382. speed_template_8, num_mb);
  2383. test_mb_skcipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
  2384. speed_template_8, num_mb);
  2385. test_mb_skcipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
  2386. speed_template_8, num_mb);
  2387. test_mb_skcipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
  2388. speed_template_8, num_mb);
  2389. test_mb_skcipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
  2390. speed_template_8, num_mb);
  2391. test_mb_skcipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
  2392. speed_template_8, num_mb);
  2393. test_mb_skcipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
  2394. speed_template_8, num_mb);
  2395. test_mb_skcipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
  2396. speed_template_8, num_mb);
  2397. break;
  2398. case 603:
  2399. test_mb_skcipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
  2400. speed_template_16_32, num_mb);
  2401. test_mb_skcipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
  2402. speed_template_16_32, num_mb);
  2403. test_mb_skcipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
  2404. speed_template_16_32, num_mb);
  2405. test_mb_skcipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
  2406. speed_template_16_32, num_mb);
  2407. test_mb_skcipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
  2408. speed_template_16_32, num_mb);
  2409. test_mb_skcipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
  2410. speed_template_16_32, num_mb);
  2411. test_mb_skcipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
  2412. speed_template_32_48, num_mb);
  2413. test_mb_skcipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
  2414. speed_template_32_48, num_mb);
  2415. test_mb_skcipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
  2416. speed_template_32_64, num_mb);
  2417. test_mb_skcipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
  2418. speed_template_32_64, num_mb);
  2419. break;
  2420. case 604:
  2421. test_mb_skcipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
  2422. speed_template_16_24_32, num_mb);
  2423. test_mb_skcipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
  2424. speed_template_16_24_32, num_mb);
  2425. test_mb_skcipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
  2426. speed_template_16_24_32, num_mb);
  2427. test_mb_skcipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
  2428. speed_template_16_24_32, num_mb);
  2429. test_mb_skcipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
  2430. speed_template_16_24_32, num_mb);
  2431. test_mb_skcipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
  2432. speed_template_16_24_32, num_mb);
  2433. test_mb_skcipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
  2434. speed_template_32_40_48, num_mb);
  2435. test_mb_skcipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
  2436. speed_template_32_40_48, num_mb);
  2437. test_mb_skcipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
  2438. speed_template_32_48_64, num_mb);
  2439. test_mb_skcipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
  2440. speed_template_32_48_64, num_mb);
  2441. break;
  2442. case 605:
  2443. test_mb_skcipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
  2444. speed_template_8, num_mb);
  2445. break;
  2446. case 606:
  2447. test_mb_skcipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
  2448. speed_template_8_16, num_mb);
  2449. test_mb_skcipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
  2450. speed_template_8_16, num_mb);
  2451. test_mb_skcipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
  2452. speed_template_8_16, num_mb);
  2453. test_mb_skcipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
  2454. speed_template_8_16, num_mb);
  2455. test_mb_skcipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
  2456. speed_template_8_16, num_mb);
  2457. test_mb_skcipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
  2458. speed_template_8_16, num_mb);
  2459. break;
  2460. case 607:
  2461. test_mb_skcipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
  2462. speed_template_16_32, num_mb);
  2463. test_mb_skcipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
  2464. speed_template_16_32, num_mb);
  2465. test_mb_skcipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
  2466. speed_template_16_32, num_mb);
  2467. test_mb_skcipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
  2468. speed_template_16_32, num_mb);
  2469. test_mb_skcipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
  2470. speed_template_16_32, num_mb);
  2471. test_mb_skcipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
  2472. speed_template_16_32, num_mb);
  2473. test_mb_skcipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
  2474. speed_template_32_48, num_mb);
  2475. test_mb_skcipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
  2476. speed_template_32_48, num_mb);
  2477. test_mb_skcipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
  2478. speed_template_32_64, num_mb);
  2479. test_mb_skcipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
  2480. speed_template_32_64, num_mb);
  2481. break;
  2482. case 608:
  2483. test_mb_skcipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
  2484. speed_template_16_32, num_mb);
  2485. test_mb_skcipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
  2486. speed_template_16_32, num_mb);
  2487. test_mb_skcipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
  2488. speed_template_16_32, num_mb);
  2489. test_mb_skcipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
  2490. speed_template_16_32, num_mb);
  2491. test_mb_skcipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
  2492. speed_template_16_32, num_mb);
  2493. test_mb_skcipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
  2494. speed_template_16_32, num_mb);
  2495. test_mb_skcipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
  2496. speed_template_32_48, num_mb);
  2497. test_mb_skcipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
  2498. speed_template_32_48, num_mb);
  2499. test_mb_skcipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
  2500. speed_template_32_64, num_mb);
  2501. test_mb_skcipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
  2502. speed_template_32_64, num_mb);
  2503. break;
  2504. case 609:
  2505. test_mb_skcipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
  2506. speed_template_8_32, num_mb);
  2507. test_mb_skcipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
  2508. speed_template_8_32, num_mb);
  2509. test_mb_skcipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
  2510. speed_template_8_32, num_mb);
  2511. test_mb_skcipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
  2512. speed_template_8_32, num_mb);
  2513. test_mb_skcipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
  2514. speed_template_8_32, num_mb);
  2515. test_mb_skcipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
  2516. speed_template_8_32, num_mb);
  2517. break;
  2518. case 1000:
  2519. test_available();
  2520. break;
  2521. }
  2522. return ret;
  2523. }
  2524. static int __init tcrypt_mod_init(void)
  2525. {
  2526. int err = -ENOMEM;
  2527. int i;
  2528. for (i = 0; i < TVMEMSIZE; i++) {
  2529. tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
  2530. if (!tvmem[i])
  2531. goto err_free_tv;
  2532. }
  2533. err = do_test(alg, type, mask, mode, num_mb);
  2534. if (err) {
  2535. printk(KERN_ERR "tcrypt: one or more tests failed!\n");
  2536. goto err_free_tv;
  2537. } else {
  2538. pr_debug("all tests passed\n");
  2539. }
  2540. /* We intentionaly return -EAGAIN to prevent keeping the module,
  2541. * unless we're running in fips mode. It does all its work from
  2542. * init() and doesn't offer any runtime functionality, but in
  2543. * the fips case, checking for a successful load is helpful.
  2544. * => we don't need it in the memory, do we?
  2545. * -- mludvig
  2546. */
  2547. if (!fips_enabled)
  2548. err = -EAGAIN;
  2549. err_free_tv:
  2550. for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
  2551. free_page((unsigned long)tvmem[i]);
  2552. return err;
  2553. }
  2554. /*
  2555. * If an init function is provided, an exit function must also be provided
  2556. * to allow module unload.
  2557. */
  2558. static void __exit tcrypt_mod_fini(void) { }
  2559. module_init(tcrypt_mod_init);
  2560. module_exit(tcrypt_mod_fini);
  2561. module_param(alg, charp, 0);
  2562. module_param(type, uint, 0);
  2563. module_param(mask, uint, 0);
  2564. module_param(mode, int, 0);
  2565. module_param(sec, uint, 0);
  2566. MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
  2567. "(defaults to zero which uses CPU cycles instead)");
  2568. module_param(num_mb, uint, 0000);
  2569. MODULE_PARM_DESC(num_mb, "Number of concurrent requests to be used in mb speed tests (defaults to 8)");
  2570. MODULE_LICENSE("GPL");
  2571. MODULE_DESCRIPTION("Quick & dirty crypto testing module");
  2572. MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");