tcrypt.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908
  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. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the Free
  13. * Software Foundation; either version 2 of the License, or (at your option)
  14. * any later version.
  15. *
  16. */
  17. #include <linux/err.h>
  18. #include <linux/init.h>
  19. #include <linux/module.h>
  20. #include <linux/mm.h>
  21. #include <linux/slab.h>
  22. #include <linux/scatterlist.h>
  23. #include <linux/string.h>
  24. #include <linux/crypto.h>
  25. #include <linux/highmem.h>
  26. #include <linux/moduleparam.h>
  27. #include <linux/jiffies.h>
  28. #include <linux/timex.h>
  29. #include <linux/interrupt.h>
  30. #include "tcrypt.h"
  31. /*
  32. * Need to kmalloc() memory for testing kmap().
  33. */
  34. #define TVMEMSIZE 16384
  35. #define XBUFSIZE 32768
  36. /*
  37. * Indexes into the xbuf to simulate cross-page access.
  38. */
  39. #define IDX1 32
  40. #define IDX2 32400
  41. #define IDX3 1
  42. #define IDX4 8193
  43. #define IDX5 22222
  44. #define IDX6 17101
  45. #define IDX7 27333
  46. #define IDX8 3000
  47. /*
  48. * Used by test_cipher()
  49. */
  50. #define ENCRYPT 1
  51. #define DECRYPT 0
  52. struct tcrypt_result {
  53. struct completion completion;
  54. int err;
  55. };
  56. static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
  57. /*
  58. * Used by test_cipher_speed()
  59. */
  60. static unsigned int sec;
  61. static int mode;
  62. static char *xbuf;
  63. static char *axbuf;
  64. static char *tvmem;
  65. static char *check[] = {
  66. "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
  67. "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
  68. "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
  69. "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
  70. "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
  71. "lzo", "cts", NULL
  72. };
  73. static void hexdump(unsigned char *buf, unsigned int len)
  74. {
  75. print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
  76. 16, 1,
  77. buf, len, false);
  78. }
  79. static void tcrypt_complete(struct crypto_async_request *req, int err)
  80. {
  81. struct tcrypt_result *res = req->data;
  82. if (err == -EINPROGRESS)
  83. return;
  84. res->err = err;
  85. complete(&res->completion);
  86. }
  87. static void test_hash(char *algo, struct hash_testvec *template,
  88. unsigned int tcount)
  89. {
  90. unsigned int i, j, k, temp;
  91. struct scatterlist sg[8];
  92. char result[64];
  93. struct crypto_hash *tfm;
  94. struct hash_desc desc;
  95. int ret;
  96. void *hash_buff;
  97. printk("\ntesting %s\n", algo);
  98. tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
  99. if (IS_ERR(tfm)) {
  100. printk("failed to load transform for %s: %ld\n", algo,
  101. PTR_ERR(tfm));
  102. return;
  103. }
  104. desc.tfm = tfm;
  105. desc.flags = 0;
  106. for (i = 0; i < tcount; i++) {
  107. printk("test %u:\n", i + 1);
  108. memset(result, 0, 64);
  109. hash_buff = kzalloc(template[i].psize, GFP_KERNEL);
  110. if (!hash_buff)
  111. continue;
  112. memcpy(hash_buff, template[i].plaintext, template[i].psize);
  113. sg_init_one(&sg[0], hash_buff, template[i].psize);
  114. if (template[i].ksize) {
  115. ret = crypto_hash_setkey(tfm, template[i].key,
  116. template[i].ksize);
  117. if (ret) {
  118. printk("setkey() failed ret=%d\n", ret);
  119. kfree(hash_buff);
  120. goto out;
  121. }
  122. }
  123. ret = crypto_hash_digest(&desc, sg, template[i].psize, result);
  124. if (ret) {
  125. printk("digest () failed ret=%d\n", ret);
  126. kfree(hash_buff);
  127. goto out;
  128. }
  129. hexdump(result, crypto_hash_digestsize(tfm));
  130. printk("%s\n",
  131. memcmp(result, template[i].digest,
  132. crypto_hash_digestsize(tfm)) ?
  133. "fail" : "pass");
  134. kfree(hash_buff);
  135. }
  136. printk("testing %s across pages\n", algo);
  137. /* setup the dummy buffer first */
  138. memset(xbuf, 0, XBUFSIZE);
  139. j = 0;
  140. for (i = 0; i < tcount; i++) {
  141. if (template[i].np) {
  142. j++;
  143. printk("test %u:\n", j);
  144. memset(result, 0, 64);
  145. temp = 0;
  146. sg_init_table(sg, template[i].np);
  147. for (k = 0; k < template[i].np; k++) {
  148. memcpy(&xbuf[IDX[k]],
  149. template[i].plaintext + temp,
  150. template[i].tap[k]);
  151. temp += template[i].tap[k];
  152. sg_set_buf(&sg[k], &xbuf[IDX[k]],
  153. template[i].tap[k]);
  154. }
  155. if (template[i].ksize) {
  156. ret = crypto_hash_setkey(tfm, template[i].key,
  157. template[i].ksize);
  158. if (ret) {
  159. printk("setkey() failed ret=%d\n", ret);
  160. goto out;
  161. }
  162. }
  163. ret = crypto_hash_digest(&desc, sg, template[i].psize,
  164. result);
  165. if (ret) {
  166. printk("digest () failed ret=%d\n", ret);
  167. goto out;
  168. }
  169. hexdump(result, crypto_hash_digestsize(tfm));
  170. printk("%s\n",
  171. memcmp(result, template[i].digest,
  172. crypto_hash_digestsize(tfm)) ?
  173. "fail" : "pass");
  174. }
  175. }
  176. out:
  177. crypto_free_hash(tfm);
  178. }
  179. static void test_aead(char *algo, int enc, struct aead_testvec *template,
  180. unsigned int tcount)
  181. {
  182. unsigned int ret, i, j, k, n, temp;
  183. char *q;
  184. struct crypto_aead *tfm;
  185. char *key;
  186. struct aead_request *req;
  187. struct scatterlist sg[8];
  188. struct scatterlist asg[8];
  189. const char *e;
  190. struct tcrypt_result result;
  191. unsigned int authsize;
  192. void *input;
  193. void *assoc;
  194. char iv[MAX_IVLEN];
  195. if (enc == ENCRYPT)
  196. e = "encryption";
  197. else
  198. e = "decryption";
  199. printk(KERN_INFO "\ntesting %s %s\n", algo, e);
  200. init_completion(&result.completion);
  201. tfm = crypto_alloc_aead(algo, 0, 0);
  202. if (IS_ERR(tfm)) {
  203. printk(KERN_INFO "failed to load transform for %s: %ld\n",
  204. algo, PTR_ERR(tfm));
  205. return;
  206. }
  207. req = aead_request_alloc(tfm, GFP_KERNEL);
  208. if (!req) {
  209. printk(KERN_INFO "failed to allocate request for %s\n", algo);
  210. goto out;
  211. }
  212. aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  213. tcrypt_complete, &result);
  214. for (i = 0, j = 0; i < tcount; i++) {
  215. if (!template[i].np) {
  216. printk(KERN_INFO "test %u (%d bit key):\n",
  217. ++j, template[i].klen * 8);
  218. /* some tepmplates have no input data but they will
  219. * touch input
  220. */
  221. input = kzalloc(template[i].ilen + template[i].rlen, GFP_KERNEL);
  222. if (!input)
  223. continue;
  224. assoc = kzalloc(template[i].alen, GFP_KERNEL);
  225. if (!assoc) {
  226. kfree(input);
  227. continue;
  228. }
  229. memcpy(input, template[i].input, template[i].ilen);
  230. memcpy(assoc, template[i].assoc, template[i].alen);
  231. if (template[i].iv)
  232. memcpy(iv, template[i].iv, MAX_IVLEN);
  233. else
  234. memset(iv, 0, MAX_IVLEN);
  235. crypto_aead_clear_flags(tfm, ~0);
  236. if (template[i].wk)
  237. crypto_aead_set_flags(
  238. tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  239. if (template[i].key)
  240. key = template[i].key;
  241. else
  242. key = kzalloc(template[i].klen, GFP_KERNEL);
  243. ret = crypto_aead_setkey(tfm, key,
  244. template[i].klen);
  245. if (ret) {
  246. printk(KERN_INFO "setkey() failed flags=%x\n",
  247. crypto_aead_get_flags(tfm));
  248. if (!template[i].fail)
  249. goto next_one;
  250. }
  251. authsize = abs(template[i].rlen - template[i].ilen);
  252. ret = crypto_aead_setauthsize(tfm, authsize);
  253. if (ret) {
  254. printk(KERN_INFO
  255. "failed to set authsize = %u\n",
  256. authsize);
  257. goto next_one;
  258. }
  259. sg_init_one(&sg[0], input,
  260. template[i].ilen + (enc ? authsize : 0));
  261. sg_init_one(&asg[0], assoc, template[i].alen);
  262. aead_request_set_crypt(req, sg, sg,
  263. template[i].ilen, iv);
  264. aead_request_set_assoc(req, asg, template[i].alen);
  265. ret = enc ?
  266. crypto_aead_encrypt(req) :
  267. crypto_aead_decrypt(req);
  268. switch (ret) {
  269. case 0:
  270. break;
  271. case -EINPROGRESS:
  272. case -EBUSY:
  273. ret = wait_for_completion_interruptible(
  274. &result.completion);
  275. if (!ret && !(ret = result.err)) {
  276. INIT_COMPLETION(result.completion);
  277. break;
  278. }
  279. /* fall through */
  280. default:
  281. printk(KERN_INFO "%s () failed err=%d\n",
  282. e, -ret);
  283. goto next_one;
  284. }
  285. q = kmap(sg_page(&sg[0])) + sg[0].offset;
  286. hexdump(q, template[i].rlen);
  287. printk(KERN_INFO "enc/dec: %s\n",
  288. memcmp(q, template[i].result,
  289. template[i].rlen) ? "fail" : "pass");
  290. kunmap(sg_page(&sg[0]));
  291. next_one:
  292. if (!template[i].key)
  293. kfree(key);
  294. kfree(assoc);
  295. kfree(input);
  296. }
  297. }
  298. printk(KERN_INFO "\ntesting %s %s across pages (chunking)\n", algo, e);
  299. memset(axbuf, 0, XBUFSIZE);
  300. for (i = 0, j = 0; i < tcount; i++) {
  301. if (template[i].np) {
  302. printk(KERN_INFO "test %u (%d bit key):\n",
  303. ++j, template[i].klen * 8);
  304. if (template[i].iv)
  305. memcpy(iv, template[i].iv, MAX_IVLEN);
  306. else
  307. memset(iv, 0, MAX_IVLEN);
  308. crypto_aead_clear_flags(tfm, ~0);
  309. if (template[i].wk)
  310. crypto_aead_set_flags(
  311. tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  312. key = template[i].key;
  313. ret = crypto_aead_setkey(tfm, key, template[i].klen);
  314. if (ret) {
  315. printk(KERN_INFO "setkey() failed flags=%x\n",
  316. crypto_aead_get_flags(tfm));
  317. if (!template[i].fail)
  318. goto out;
  319. }
  320. memset(xbuf, 0, XBUFSIZE);
  321. sg_init_table(sg, template[i].np);
  322. for (k = 0, temp = 0; k < template[i].np; k++) {
  323. memcpy(&xbuf[IDX[k]],
  324. template[i].input + temp,
  325. template[i].tap[k]);
  326. temp += template[i].tap[k];
  327. sg_set_buf(&sg[k], &xbuf[IDX[k]],
  328. template[i].tap[k]);
  329. }
  330. authsize = abs(template[i].rlen - template[i].ilen);
  331. ret = crypto_aead_setauthsize(tfm, authsize);
  332. if (ret) {
  333. printk(KERN_INFO
  334. "failed to set authsize = %u\n",
  335. authsize);
  336. goto out;
  337. }
  338. if (enc)
  339. sg[k - 1].length += authsize;
  340. sg_init_table(asg, template[i].anp);
  341. for (k = 0, temp = 0; k < template[i].anp; k++) {
  342. memcpy(&axbuf[IDX[k]],
  343. template[i].assoc + temp,
  344. template[i].atap[k]);
  345. temp += template[i].atap[k];
  346. sg_set_buf(&asg[k], &axbuf[IDX[k]],
  347. template[i].atap[k]);
  348. }
  349. aead_request_set_crypt(req, sg, sg,
  350. template[i].ilen,
  351. iv);
  352. aead_request_set_assoc(req, asg, template[i].alen);
  353. ret = enc ?
  354. crypto_aead_encrypt(req) :
  355. crypto_aead_decrypt(req);
  356. switch (ret) {
  357. case 0:
  358. break;
  359. case -EINPROGRESS:
  360. case -EBUSY:
  361. ret = wait_for_completion_interruptible(
  362. &result.completion);
  363. if (!ret && !(ret = result.err)) {
  364. INIT_COMPLETION(result.completion);
  365. break;
  366. }
  367. /* fall through */
  368. default:
  369. printk(KERN_INFO "%s () failed err=%d\n",
  370. e, -ret);
  371. goto out;
  372. }
  373. for (k = 0, temp = 0; k < template[i].np; k++) {
  374. printk(KERN_INFO "page %u\n", k);
  375. q = kmap(sg_page(&sg[k])) + sg[k].offset;
  376. hexdump(q, template[i].tap[k]);
  377. printk(KERN_INFO "%s\n",
  378. memcmp(q, template[i].result + temp,
  379. template[i].tap[k] -
  380. (k < template[i].np - 1 || enc ?
  381. 0 : authsize)) ?
  382. "fail" : "pass");
  383. for (n = 0; q[template[i].tap[k] + n]; n++)
  384. ;
  385. if (n) {
  386. printk("Result buffer corruption %u "
  387. "bytes:\n", n);
  388. hexdump(&q[template[i].tap[k]], n);
  389. }
  390. temp += template[i].tap[k];
  391. kunmap(sg_page(&sg[k]));
  392. }
  393. }
  394. }
  395. out:
  396. crypto_free_aead(tfm);
  397. aead_request_free(req);
  398. }
  399. static void test_cipher(char *algo, int enc,
  400. struct cipher_testvec *template, unsigned int tcount)
  401. {
  402. unsigned int ret, i, j, k, n, temp;
  403. char *q;
  404. struct crypto_ablkcipher *tfm;
  405. struct ablkcipher_request *req;
  406. struct scatterlist sg[8];
  407. const char *e;
  408. struct tcrypt_result result;
  409. void *data;
  410. char iv[MAX_IVLEN];
  411. if (enc == ENCRYPT)
  412. e = "encryption";
  413. else
  414. e = "decryption";
  415. printk("\ntesting %s %s\n", algo, e);
  416. init_completion(&result.completion);
  417. tfm = crypto_alloc_ablkcipher(algo, 0, 0);
  418. if (IS_ERR(tfm)) {
  419. printk("failed to load transform for %s: %ld\n", algo,
  420. PTR_ERR(tfm));
  421. return;
  422. }
  423. req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
  424. if (!req) {
  425. printk("failed to allocate request for %s\n", algo);
  426. goto out;
  427. }
  428. ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  429. tcrypt_complete, &result);
  430. j = 0;
  431. for (i = 0; i < tcount; i++) {
  432. data = kzalloc(template[i].ilen, GFP_KERNEL);
  433. if (!data)
  434. continue;
  435. memcpy(data, template[i].input, template[i].ilen);
  436. if (template[i].iv)
  437. memcpy(iv, template[i].iv, MAX_IVLEN);
  438. else
  439. memset(iv, 0, MAX_IVLEN);
  440. if (!(template[i].np)) {
  441. j++;
  442. printk("test %u (%d bit key):\n",
  443. j, template[i].klen * 8);
  444. crypto_ablkcipher_clear_flags(tfm, ~0);
  445. if (template[i].wk)
  446. crypto_ablkcipher_set_flags(
  447. tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  448. ret = crypto_ablkcipher_setkey(tfm, template[i].key,
  449. template[i].klen);
  450. if (ret) {
  451. printk("setkey() failed flags=%x\n",
  452. crypto_ablkcipher_get_flags(tfm));
  453. if (!template[i].fail) {
  454. kfree(data);
  455. goto out;
  456. }
  457. }
  458. sg_init_one(&sg[0], data, template[i].ilen);
  459. ablkcipher_request_set_crypt(req, sg, sg,
  460. template[i].ilen, iv);
  461. ret = enc ?
  462. crypto_ablkcipher_encrypt(req) :
  463. crypto_ablkcipher_decrypt(req);
  464. switch (ret) {
  465. case 0:
  466. break;
  467. case -EINPROGRESS:
  468. case -EBUSY:
  469. ret = wait_for_completion_interruptible(
  470. &result.completion);
  471. if (!ret && !((ret = result.err))) {
  472. INIT_COMPLETION(result.completion);
  473. break;
  474. }
  475. /* fall through */
  476. default:
  477. printk("%s () failed err=%d\n", e, -ret);
  478. kfree(data);
  479. goto out;
  480. }
  481. q = kmap(sg_page(&sg[0])) + sg[0].offset;
  482. hexdump(q, template[i].rlen);
  483. printk("%s\n",
  484. memcmp(q, template[i].result,
  485. template[i].rlen) ? "fail" : "pass");
  486. kunmap(sg_page(&sg[0]));
  487. }
  488. kfree(data);
  489. }
  490. printk("\ntesting %s %s across pages (chunking)\n", algo, e);
  491. j = 0;
  492. for (i = 0; i < tcount; i++) {
  493. if (template[i].iv)
  494. memcpy(iv, template[i].iv, MAX_IVLEN);
  495. else
  496. memset(iv, 0, MAX_IVLEN);
  497. if (template[i].np) {
  498. j++;
  499. printk("test %u (%d bit key):\n",
  500. j, template[i].klen * 8);
  501. memset(xbuf, 0, XBUFSIZE);
  502. crypto_ablkcipher_clear_flags(tfm, ~0);
  503. if (template[i].wk)
  504. crypto_ablkcipher_set_flags(
  505. tfm, CRYPTO_TFM_REQ_WEAK_KEY);
  506. ret = crypto_ablkcipher_setkey(tfm, template[i].key,
  507. template[i].klen);
  508. if (ret) {
  509. printk("setkey() failed flags=%x\n",
  510. crypto_ablkcipher_get_flags(tfm));
  511. if (!template[i].fail)
  512. goto out;
  513. }
  514. temp = 0;
  515. sg_init_table(sg, template[i].np);
  516. for (k = 0; k < template[i].np; k++) {
  517. memcpy(&xbuf[IDX[k]],
  518. template[i].input + temp,
  519. template[i].tap[k]);
  520. temp += template[i].tap[k];
  521. sg_set_buf(&sg[k], &xbuf[IDX[k]],
  522. template[i].tap[k]);
  523. }
  524. ablkcipher_request_set_crypt(req, sg, sg,
  525. template[i].ilen, iv);
  526. ret = enc ?
  527. crypto_ablkcipher_encrypt(req) :
  528. crypto_ablkcipher_decrypt(req);
  529. switch (ret) {
  530. case 0:
  531. break;
  532. case -EINPROGRESS:
  533. case -EBUSY:
  534. ret = wait_for_completion_interruptible(
  535. &result.completion);
  536. if (!ret && !((ret = result.err))) {
  537. INIT_COMPLETION(result.completion);
  538. break;
  539. }
  540. /* fall through */
  541. default:
  542. printk("%s () failed err=%d\n", e, -ret);
  543. goto out;
  544. }
  545. temp = 0;
  546. for (k = 0; k < template[i].np; k++) {
  547. printk("page %u\n", k);
  548. q = kmap(sg_page(&sg[k])) + sg[k].offset;
  549. hexdump(q, template[i].tap[k]);
  550. printk("%s\n",
  551. memcmp(q, template[i].result + temp,
  552. template[i].tap[k]) ? "fail" :
  553. "pass");
  554. for (n = 0; q[template[i].tap[k] + n]; n++)
  555. ;
  556. if (n) {
  557. printk("Result buffer corruption %u "
  558. "bytes:\n", n);
  559. hexdump(&q[template[i].tap[k]], n);
  560. }
  561. temp += template[i].tap[k];
  562. kunmap(sg_page(&sg[k]));
  563. }
  564. }
  565. }
  566. out:
  567. crypto_free_ablkcipher(tfm);
  568. ablkcipher_request_free(req);
  569. }
  570. static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
  571. int blen, int sec)
  572. {
  573. struct scatterlist sg[1];
  574. unsigned long start, end;
  575. int bcount;
  576. int ret;
  577. sg_init_one(sg, p, blen);
  578. for (start = jiffies, end = start + sec * HZ, bcount = 0;
  579. time_before(jiffies, end); bcount++) {
  580. if (enc)
  581. ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
  582. else
  583. ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
  584. if (ret)
  585. return ret;
  586. }
  587. printk("%d operations in %d seconds (%ld bytes)\n",
  588. bcount, sec, (long)bcount * blen);
  589. return 0;
  590. }
  591. static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p,
  592. int blen)
  593. {
  594. struct scatterlist sg[1];
  595. unsigned long cycles = 0;
  596. int ret = 0;
  597. int i;
  598. sg_init_one(sg, p, blen);
  599. local_bh_disable();
  600. local_irq_disable();
  601. /* Warm-up run. */
  602. for (i = 0; i < 4; i++) {
  603. if (enc)
  604. ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
  605. else
  606. ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
  607. if (ret)
  608. goto out;
  609. }
  610. /* The real thing. */
  611. for (i = 0; i < 8; i++) {
  612. cycles_t start, end;
  613. start = get_cycles();
  614. if (enc)
  615. ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
  616. else
  617. ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
  618. end = get_cycles();
  619. if (ret)
  620. goto out;
  621. cycles += end - start;
  622. }
  623. out:
  624. local_irq_enable();
  625. local_bh_enable();
  626. if (ret == 0)
  627. printk("1 operation in %lu cycles (%d bytes)\n",
  628. (cycles + 4) / 8, blen);
  629. return ret;
  630. }
  631. static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
  632. static void test_cipher_speed(char *algo, int enc, unsigned int sec,
  633. struct cipher_testvec *template,
  634. unsigned int tcount, u8 *keysize)
  635. {
  636. unsigned int ret, i, j, iv_len;
  637. unsigned char *key, *p, iv[128];
  638. struct crypto_blkcipher *tfm;
  639. struct blkcipher_desc desc;
  640. const char *e;
  641. u32 *b_size;
  642. if (enc == ENCRYPT)
  643. e = "encryption";
  644. else
  645. e = "decryption";
  646. printk("\ntesting speed of %s %s\n", algo, e);
  647. tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
  648. if (IS_ERR(tfm)) {
  649. printk("failed to load transform for %s: %ld\n", algo,
  650. PTR_ERR(tfm));
  651. return;
  652. }
  653. desc.tfm = tfm;
  654. desc.flags = 0;
  655. i = 0;
  656. do {
  657. b_size = block_sizes;
  658. do {
  659. if ((*keysize + *b_size) > TVMEMSIZE) {
  660. printk("template (%u) too big for tvmem (%u)\n",
  661. *keysize + *b_size, TVMEMSIZE);
  662. goto out;
  663. }
  664. printk("test %u (%d bit key, %d byte blocks): ", i,
  665. *keysize * 8, *b_size);
  666. memset(tvmem, 0xff, *keysize + *b_size);
  667. /* set key, plain text and IV */
  668. key = (unsigned char *)tvmem;
  669. for (j = 0; j < tcount; j++) {
  670. if (template[j].klen == *keysize) {
  671. key = template[j].key;
  672. break;
  673. }
  674. }
  675. p = (unsigned char *)tvmem + *keysize;
  676. ret = crypto_blkcipher_setkey(tfm, key, *keysize);
  677. if (ret) {
  678. printk("setkey() failed flags=%x\n",
  679. crypto_blkcipher_get_flags(tfm));
  680. goto out;
  681. }
  682. iv_len = crypto_blkcipher_ivsize(tfm);
  683. if (iv_len) {
  684. memset(&iv, 0xff, iv_len);
  685. crypto_blkcipher_set_iv(tfm, iv, iv_len);
  686. }
  687. if (sec)
  688. ret = test_cipher_jiffies(&desc, enc, p, *b_size, sec);
  689. else
  690. ret = test_cipher_cycles(&desc, enc, p, *b_size);
  691. if (ret) {
  692. printk("%s() failed flags=%x\n", e, desc.flags);
  693. break;
  694. }
  695. b_size++;
  696. i++;
  697. } while (*b_size);
  698. keysize++;
  699. } while (*keysize);
  700. out:
  701. crypto_free_blkcipher(tfm);
  702. }
  703. static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen,
  704. char *out, int sec)
  705. {
  706. struct scatterlist sg[1];
  707. unsigned long start, end;
  708. int bcount;
  709. int ret;
  710. sg_init_table(sg, 1);
  711. for (start = jiffies, end = start + sec * HZ, bcount = 0;
  712. time_before(jiffies, end); bcount++) {
  713. sg_set_buf(sg, p, blen);
  714. ret = crypto_hash_digest(desc, sg, blen, out);
  715. if (ret)
  716. return ret;
  717. }
  718. printk("%6u opers/sec, %9lu bytes/sec\n",
  719. bcount / sec, ((long)bcount * blen) / sec);
  720. return 0;
  721. }
  722. static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen,
  723. int plen, char *out, int sec)
  724. {
  725. struct scatterlist sg[1];
  726. unsigned long start, end;
  727. int bcount, pcount;
  728. int ret;
  729. if (plen == blen)
  730. return test_hash_jiffies_digest(desc, p, blen, out, sec);
  731. sg_init_table(sg, 1);
  732. for (start = jiffies, end = start + sec * HZ, bcount = 0;
  733. time_before(jiffies, end); bcount++) {
  734. ret = crypto_hash_init(desc);
  735. if (ret)
  736. return ret;
  737. for (pcount = 0; pcount < blen; pcount += plen) {
  738. sg_set_buf(sg, p + pcount, plen);
  739. ret = crypto_hash_update(desc, sg, plen);
  740. if (ret)
  741. return ret;
  742. }
  743. /* we assume there is enough space in 'out' for the result */
  744. ret = crypto_hash_final(desc, out);
  745. if (ret)
  746. return ret;
  747. }
  748. printk("%6u opers/sec, %9lu bytes/sec\n",
  749. bcount / sec, ((long)bcount * blen) / sec);
  750. return 0;
  751. }
  752. static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen,
  753. char *out)
  754. {
  755. struct scatterlist sg[1];
  756. unsigned long cycles = 0;
  757. int i;
  758. int ret;
  759. sg_init_table(sg, 1);
  760. local_bh_disable();
  761. local_irq_disable();
  762. /* Warm-up run. */
  763. for (i = 0; i < 4; i++) {
  764. sg_set_buf(sg, p, blen);
  765. ret = crypto_hash_digest(desc, sg, blen, out);
  766. if (ret)
  767. goto out;
  768. }
  769. /* The real thing. */
  770. for (i = 0; i < 8; i++) {
  771. cycles_t start, end;
  772. start = get_cycles();
  773. sg_set_buf(sg, p, blen);
  774. ret = crypto_hash_digest(desc, sg, blen, out);
  775. if (ret)
  776. goto out;
  777. end = get_cycles();
  778. cycles += end - start;
  779. }
  780. out:
  781. local_irq_enable();
  782. local_bh_enable();
  783. if (ret)
  784. return ret;
  785. printk("%6lu cycles/operation, %4lu cycles/byte\n",
  786. cycles / 8, cycles / (8 * blen));
  787. return 0;
  788. }
  789. static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
  790. int plen, char *out)
  791. {
  792. struct scatterlist sg[1];
  793. unsigned long cycles = 0;
  794. int i, pcount;
  795. int ret;
  796. if (plen == blen)
  797. return test_hash_cycles_digest(desc, p, blen, out);
  798. sg_init_table(sg, 1);
  799. local_bh_disable();
  800. local_irq_disable();
  801. /* Warm-up run. */
  802. for (i = 0; i < 4; i++) {
  803. ret = crypto_hash_init(desc);
  804. if (ret)
  805. goto out;
  806. for (pcount = 0; pcount < blen; pcount += plen) {
  807. sg_set_buf(sg, p + pcount, plen);
  808. ret = crypto_hash_update(desc, sg, plen);
  809. if (ret)
  810. goto out;
  811. }
  812. ret = crypto_hash_final(desc, out);
  813. if (ret)
  814. goto out;
  815. }
  816. /* The real thing. */
  817. for (i = 0; i < 8; i++) {
  818. cycles_t start, end;
  819. start = get_cycles();
  820. ret = crypto_hash_init(desc);
  821. if (ret)
  822. goto out;
  823. for (pcount = 0; pcount < blen; pcount += plen) {
  824. sg_set_buf(sg, p + pcount, plen);
  825. ret = crypto_hash_update(desc, sg, plen);
  826. if (ret)
  827. goto out;
  828. }
  829. ret = crypto_hash_final(desc, out);
  830. if (ret)
  831. goto out;
  832. end = get_cycles();
  833. cycles += end - start;
  834. }
  835. out:
  836. local_irq_enable();
  837. local_bh_enable();
  838. if (ret)
  839. return ret;
  840. printk("%6lu cycles/operation, %4lu cycles/byte\n",
  841. cycles / 8, cycles / (8 * blen));
  842. return 0;
  843. }
  844. static void test_hash_speed(char *algo, unsigned int sec,
  845. struct hash_speed *speed)
  846. {
  847. struct crypto_hash *tfm;
  848. struct hash_desc desc;
  849. char output[1024];
  850. int i;
  851. int ret;
  852. printk("\ntesting speed of %s\n", algo);
  853. tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
  854. if (IS_ERR(tfm)) {
  855. printk("failed to load transform for %s: %ld\n", algo,
  856. PTR_ERR(tfm));
  857. return;
  858. }
  859. desc.tfm = tfm;
  860. desc.flags = 0;
  861. if (crypto_hash_digestsize(tfm) > sizeof(output)) {
  862. printk("digestsize(%u) > outputbuffer(%zu)\n",
  863. crypto_hash_digestsize(tfm), sizeof(output));
  864. goto out;
  865. }
  866. for (i = 0; speed[i].blen != 0; i++) {
  867. if (speed[i].blen > TVMEMSIZE) {
  868. printk("template (%u) too big for tvmem (%u)\n",
  869. speed[i].blen, TVMEMSIZE);
  870. goto out;
  871. }
  872. printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
  873. i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
  874. memset(tvmem, 0xff, speed[i].blen);
  875. if (sec)
  876. ret = test_hash_jiffies(&desc, tvmem, speed[i].blen,
  877. speed[i].plen, output, sec);
  878. else
  879. ret = test_hash_cycles(&desc, tvmem, speed[i].blen,
  880. speed[i].plen, output);
  881. if (ret) {
  882. printk("hashing failed ret=%d\n", ret);
  883. break;
  884. }
  885. }
  886. out:
  887. crypto_free_hash(tfm);
  888. }
  889. static void test_comp(char *algo, struct comp_testvec *ctemplate,
  890. struct comp_testvec *dtemplate, int ctcount, int dtcount)
  891. {
  892. unsigned int i;
  893. char result[COMP_BUF_SIZE];
  894. struct crypto_comp *tfm;
  895. unsigned int tsize;
  896. printk("\ntesting %s compression\n", algo);
  897. tfm = crypto_alloc_comp(algo, 0, CRYPTO_ALG_ASYNC);
  898. if (IS_ERR(tfm)) {
  899. printk("failed to load transform for %s\n", algo);
  900. return;
  901. }
  902. for (i = 0; i < ctcount; i++) {
  903. int ilen, ret, dlen = COMP_BUF_SIZE;
  904. printk("test %u:\n", i + 1);
  905. memset(result, 0, sizeof (result));
  906. ilen = ctemplate[i].inlen;
  907. ret = crypto_comp_compress(tfm, ctemplate[i].input,
  908. ilen, result, &dlen);
  909. if (ret) {
  910. printk("fail: ret=%d\n", ret);
  911. continue;
  912. }
  913. hexdump(result, dlen);
  914. printk("%s (ratio %d:%d)\n",
  915. memcmp(result, ctemplate[i].output, dlen) ? "fail" : "pass",
  916. ilen, dlen);
  917. }
  918. printk("\ntesting %s decompression\n", algo);
  919. tsize = sizeof(struct comp_testvec);
  920. tsize *= dtcount;
  921. if (tsize > TVMEMSIZE) {
  922. printk("template (%u) too big for tvmem (%u)\n", tsize,
  923. TVMEMSIZE);
  924. goto out;
  925. }
  926. for (i = 0; i < dtcount; i++) {
  927. int ilen, ret, dlen = COMP_BUF_SIZE;
  928. printk("test %u:\n", i + 1);
  929. memset(result, 0, sizeof (result));
  930. ilen = dtemplate[i].inlen;
  931. ret = crypto_comp_decompress(tfm, dtemplate[i].input,
  932. ilen, result, &dlen);
  933. if (ret) {
  934. printk("fail: ret=%d\n", ret);
  935. continue;
  936. }
  937. hexdump(result, dlen);
  938. printk("%s (ratio %d:%d)\n",
  939. memcmp(result, dtemplate[i].output, dlen) ? "fail" : "pass",
  940. ilen, dlen);
  941. }
  942. out:
  943. crypto_free_comp(tfm);
  944. }
  945. static void test_available(void)
  946. {
  947. char **name = check;
  948. while (*name) {
  949. printk("alg %s ", *name);
  950. printk(crypto_has_alg(*name, 0, 0) ?
  951. "found\n" : "not found\n");
  952. name++;
  953. }
  954. }
  955. static void do_test(void)
  956. {
  957. switch (mode) {
  958. case 0:
  959. test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
  960. test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
  961. //DES
  962. test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
  963. DES_ENC_TEST_VECTORS);
  964. test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
  965. DES_DEC_TEST_VECTORS);
  966. test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
  967. DES_CBC_ENC_TEST_VECTORS);
  968. test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
  969. DES_CBC_DEC_TEST_VECTORS);
  970. //DES3_EDE
  971. test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
  972. DES3_EDE_ENC_TEST_VECTORS);
  973. test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
  974. DES3_EDE_DEC_TEST_VECTORS);
  975. test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
  976. test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
  977. test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
  978. //BLOWFISH
  979. test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
  980. BF_ENC_TEST_VECTORS);
  981. test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
  982. BF_DEC_TEST_VECTORS);
  983. test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
  984. BF_CBC_ENC_TEST_VECTORS);
  985. test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
  986. BF_CBC_DEC_TEST_VECTORS);
  987. //TWOFISH
  988. test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
  989. TF_ENC_TEST_VECTORS);
  990. test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
  991. TF_DEC_TEST_VECTORS);
  992. test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
  993. TF_CBC_ENC_TEST_VECTORS);
  994. test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
  995. TF_CBC_DEC_TEST_VECTORS);
  996. //SERPENT
  997. test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
  998. SERPENT_ENC_TEST_VECTORS);
  999. test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
  1000. SERPENT_DEC_TEST_VECTORS);
  1001. //TNEPRES
  1002. test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
  1003. TNEPRES_ENC_TEST_VECTORS);
  1004. test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
  1005. TNEPRES_DEC_TEST_VECTORS);
  1006. //AES
  1007. test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
  1008. AES_ENC_TEST_VECTORS);
  1009. test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
  1010. AES_DEC_TEST_VECTORS);
  1011. test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
  1012. AES_CBC_ENC_TEST_VECTORS);
  1013. test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
  1014. AES_CBC_DEC_TEST_VECTORS);
  1015. test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
  1016. AES_LRW_ENC_TEST_VECTORS);
  1017. test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
  1018. AES_LRW_DEC_TEST_VECTORS);
  1019. test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
  1020. AES_XTS_ENC_TEST_VECTORS);
  1021. test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
  1022. AES_XTS_DEC_TEST_VECTORS);
  1023. test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
  1024. AES_CTR_ENC_TEST_VECTORS);
  1025. test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
  1026. AES_CTR_DEC_TEST_VECTORS);
  1027. test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
  1028. AES_GCM_ENC_TEST_VECTORS);
  1029. test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
  1030. AES_GCM_DEC_TEST_VECTORS);
  1031. test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template,
  1032. AES_CCM_ENC_TEST_VECTORS);
  1033. test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template,
  1034. AES_CCM_DEC_TEST_VECTORS);
  1035. //CAST5
  1036. test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
  1037. CAST5_ENC_TEST_VECTORS);
  1038. test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
  1039. CAST5_DEC_TEST_VECTORS);
  1040. //CAST6
  1041. test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
  1042. CAST6_ENC_TEST_VECTORS);
  1043. test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
  1044. CAST6_DEC_TEST_VECTORS);
  1045. //ARC4
  1046. test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
  1047. ARC4_ENC_TEST_VECTORS);
  1048. test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
  1049. ARC4_DEC_TEST_VECTORS);
  1050. //TEA
  1051. test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
  1052. TEA_ENC_TEST_VECTORS);
  1053. test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
  1054. TEA_DEC_TEST_VECTORS);
  1055. //XTEA
  1056. test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
  1057. XTEA_ENC_TEST_VECTORS);
  1058. test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
  1059. XTEA_DEC_TEST_VECTORS);
  1060. //KHAZAD
  1061. test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
  1062. KHAZAD_ENC_TEST_VECTORS);
  1063. test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
  1064. KHAZAD_DEC_TEST_VECTORS);
  1065. //ANUBIS
  1066. test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
  1067. ANUBIS_ENC_TEST_VECTORS);
  1068. test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
  1069. ANUBIS_DEC_TEST_VECTORS);
  1070. test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
  1071. ANUBIS_CBC_ENC_TEST_VECTORS);
  1072. test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
  1073. ANUBIS_CBC_ENC_TEST_VECTORS);
  1074. //XETA
  1075. test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
  1076. XETA_ENC_TEST_VECTORS);
  1077. test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
  1078. XETA_DEC_TEST_VECTORS);
  1079. //FCrypt
  1080. test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
  1081. FCRYPT_ENC_TEST_VECTORS);
  1082. test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
  1083. FCRYPT_DEC_TEST_VECTORS);
  1084. //CAMELLIA
  1085. test_cipher("ecb(camellia)", ENCRYPT,
  1086. camellia_enc_tv_template,
  1087. CAMELLIA_ENC_TEST_VECTORS);
  1088. test_cipher("ecb(camellia)", DECRYPT,
  1089. camellia_dec_tv_template,
  1090. CAMELLIA_DEC_TEST_VECTORS);
  1091. test_cipher("cbc(camellia)", ENCRYPT,
  1092. camellia_cbc_enc_tv_template,
  1093. CAMELLIA_CBC_ENC_TEST_VECTORS);
  1094. test_cipher("cbc(camellia)", DECRYPT,
  1095. camellia_cbc_dec_tv_template,
  1096. CAMELLIA_CBC_DEC_TEST_VECTORS);
  1097. //SEED
  1098. test_cipher("ecb(seed)", ENCRYPT, seed_enc_tv_template,
  1099. SEED_ENC_TEST_VECTORS);
  1100. test_cipher("ecb(seed)", DECRYPT, seed_dec_tv_template,
  1101. SEED_DEC_TEST_VECTORS);
  1102. //CTS
  1103. test_cipher("cts(cbc(aes))", ENCRYPT, cts_mode_enc_tv_template,
  1104. CTS_MODE_ENC_TEST_VECTORS);
  1105. test_cipher("cts(cbc(aes))", DECRYPT, cts_mode_dec_tv_template,
  1106. CTS_MODE_DEC_TEST_VECTORS);
  1107. test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
  1108. test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
  1109. test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
  1110. test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
  1111. test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
  1112. test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
  1113. test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
  1114. test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
  1115. test_comp("deflate", deflate_comp_tv_template,
  1116. deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
  1117. DEFLATE_DECOMP_TEST_VECTORS);
  1118. test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template,
  1119. LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
  1120. test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
  1121. test_hash("hmac(md5)", hmac_md5_tv_template,
  1122. HMAC_MD5_TEST_VECTORS);
  1123. test_hash("hmac(sha1)", hmac_sha1_tv_template,
  1124. HMAC_SHA1_TEST_VECTORS);
  1125. test_hash("hmac(sha224)", hmac_sha224_tv_template,
  1126. HMAC_SHA224_TEST_VECTORS);
  1127. test_hash("hmac(sha256)", hmac_sha256_tv_template,
  1128. HMAC_SHA256_TEST_VECTORS);
  1129. test_hash("hmac(sha384)", hmac_sha384_tv_template,
  1130. HMAC_SHA384_TEST_VECTORS);
  1131. test_hash("hmac(sha512)", hmac_sha512_tv_template,
  1132. HMAC_SHA512_TEST_VECTORS);
  1133. test_hash("xcbc(aes)", aes_xcbc128_tv_template,
  1134. XCBC_AES_TEST_VECTORS);
  1135. test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
  1136. break;
  1137. case 1:
  1138. test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
  1139. break;
  1140. case 2:
  1141. test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
  1142. break;
  1143. case 3:
  1144. test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
  1145. DES_ENC_TEST_VECTORS);
  1146. test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
  1147. DES_DEC_TEST_VECTORS);
  1148. test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
  1149. DES_CBC_ENC_TEST_VECTORS);
  1150. test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
  1151. DES_CBC_DEC_TEST_VECTORS);
  1152. break;
  1153. case 4:
  1154. test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
  1155. DES3_EDE_ENC_TEST_VECTORS);
  1156. test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
  1157. DES3_EDE_DEC_TEST_VECTORS);
  1158. break;
  1159. case 5:
  1160. test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
  1161. break;
  1162. case 6:
  1163. test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
  1164. break;
  1165. case 7:
  1166. test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
  1167. BF_ENC_TEST_VECTORS);
  1168. test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
  1169. BF_DEC_TEST_VECTORS);
  1170. test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
  1171. BF_CBC_ENC_TEST_VECTORS);
  1172. test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
  1173. BF_CBC_DEC_TEST_VECTORS);
  1174. break;
  1175. case 8:
  1176. test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
  1177. TF_ENC_TEST_VECTORS);
  1178. test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
  1179. TF_DEC_TEST_VECTORS);
  1180. test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
  1181. TF_CBC_ENC_TEST_VECTORS);
  1182. test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
  1183. TF_CBC_DEC_TEST_VECTORS);
  1184. break;
  1185. case 9:
  1186. test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
  1187. SERPENT_ENC_TEST_VECTORS);
  1188. test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
  1189. SERPENT_DEC_TEST_VECTORS);
  1190. break;
  1191. case 10:
  1192. test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
  1193. AES_ENC_TEST_VECTORS);
  1194. test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
  1195. AES_DEC_TEST_VECTORS);
  1196. test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
  1197. AES_CBC_ENC_TEST_VECTORS);
  1198. test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
  1199. AES_CBC_DEC_TEST_VECTORS);
  1200. test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
  1201. AES_LRW_ENC_TEST_VECTORS);
  1202. test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
  1203. AES_LRW_DEC_TEST_VECTORS);
  1204. test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
  1205. AES_XTS_ENC_TEST_VECTORS);
  1206. test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
  1207. AES_XTS_DEC_TEST_VECTORS);
  1208. test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
  1209. AES_CTR_ENC_TEST_VECTORS);
  1210. test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
  1211. AES_CTR_DEC_TEST_VECTORS);
  1212. break;
  1213. case 11:
  1214. test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
  1215. break;
  1216. case 12:
  1217. test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
  1218. break;
  1219. case 13:
  1220. test_comp("deflate", deflate_comp_tv_template,
  1221. deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
  1222. DEFLATE_DECOMP_TEST_VECTORS);
  1223. break;
  1224. case 14:
  1225. test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
  1226. CAST5_ENC_TEST_VECTORS);
  1227. test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
  1228. CAST5_DEC_TEST_VECTORS);
  1229. break;
  1230. case 15:
  1231. test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
  1232. CAST6_ENC_TEST_VECTORS);
  1233. test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
  1234. CAST6_DEC_TEST_VECTORS);
  1235. break;
  1236. case 16:
  1237. test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
  1238. ARC4_ENC_TEST_VECTORS);
  1239. test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
  1240. ARC4_DEC_TEST_VECTORS);
  1241. break;
  1242. case 17:
  1243. test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
  1244. break;
  1245. case 18:
  1246. test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
  1247. break;
  1248. case 19:
  1249. test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
  1250. TEA_ENC_TEST_VECTORS);
  1251. test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
  1252. TEA_DEC_TEST_VECTORS);
  1253. break;
  1254. case 20:
  1255. test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
  1256. XTEA_ENC_TEST_VECTORS);
  1257. test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
  1258. XTEA_DEC_TEST_VECTORS);
  1259. break;
  1260. case 21:
  1261. test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
  1262. KHAZAD_ENC_TEST_VECTORS);
  1263. test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
  1264. KHAZAD_DEC_TEST_VECTORS);
  1265. break;
  1266. case 22:
  1267. test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
  1268. break;
  1269. case 23:
  1270. test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
  1271. break;
  1272. case 24:
  1273. test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
  1274. break;
  1275. case 25:
  1276. test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
  1277. TNEPRES_ENC_TEST_VECTORS);
  1278. test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
  1279. TNEPRES_DEC_TEST_VECTORS);
  1280. break;
  1281. case 26:
  1282. test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
  1283. ANUBIS_ENC_TEST_VECTORS);
  1284. test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
  1285. ANUBIS_DEC_TEST_VECTORS);
  1286. test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
  1287. ANUBIS_CBC_ENC_TEST_VECTORS);
  1288. test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
  1289. ANUBIS_CBC_ENC_TEST_VECTORS);
  1290. break;
  1291. case 27:
  1292. test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
  1293. break;
  1294. case 28:
  1295. test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
  1296. break;
  1297. case 29:
  1298. test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
  1299. break;
  1300. case 30:
  1301. test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
  1302. XETA_ENC_TEST_VECTORS);
  1303. test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
  1304. XETA_DEC_TEST_VECTORS);
  1305. break;
  1306. case 31:
  1307. test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
  1308. FCRYPT_ENC_TEST_VECTORS);
  1309. test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
  1310. FCRYPT_DEC_TEST_VECTORS);
  1311. break;
  1312. case 32:
  1313. test_cipher("ecb(camellia)", ENCRYPT,
  1314. camellia_enc_tv_template,
  1315. CAMELLIA_ENC_TEST_VECTORS);
  1316. test_cipher("ecb(camellia)", DECRYPT,
  1317. camellia_dec_tv_template,
  1318. CAMELLIA_DEC_TEST_VECTORS);
  1319. test_cipher("cbc(camellia)", ENCRYPT,
  1320. camellia_cbc_enc_tv_template,
  1321. CAMELLIA_CBC_ENC_TEST_VECTORS);
  1322. test_cipher("cbc(camellia)", DECRYPT,
  1323. camellia_cbc_dec_tv_template,
  1324. CAMELLIA_CBC_DEC_TEST_VECTORS);
  1325. break;
  1326. case 33:
  1327. test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
  1328. break;
  1329. case 34:
  1330. test_cipher("salsa20", ENCRYPT,
  1331. salsa20_stream_enc_tv_template,
  1332. SALSA20_STREAM_ENC_TEST_VECTORS);
  1333. break;
  1334. case 35:
  1335. test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
  1336. AES_GCM_ENC_TEST_VECTORS);
  1337. test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
  1338. AES_GCM_DEC_TEST_VECTORS);
  1339. break;
  1340. case 36:
  1341. test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template,
  1342. LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
  1343. break;
  1344. case 37:
  1345. test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template,
  1346. AES_CCM_ENC_TEST_VECTORS);
  1347. test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template,
  1348. AES_CCM_DEC_TEST_VECTORS);
  1349. break;
  1350. case 38:
  1351. test_cipher("cts(cbc(aes))", ENCRYPT, cts_mode_enc_tv_template,
  1352. CTS_MODE_ENC_TEST_VECTORS);
  1353. test_cipher("cts(cbc(aes))", DECRYPT, cts_mode_dec_tv_template,
  1354. CTS_MODE_DEC_TEST_VECTORS);
  1355. break;
  1356. case 39:
  1357. test_hash("rmd128", rmd128_tv_template, RMD128_TEST_VECTORS);
  1358. break;
  1359. case 40:
  1360. test_hash("rmd160", rmd160_tv_template, RMD160_TEST_VECTORS);
  1361. break;
  1362. case 41:
  1363. test_hash("rmd256", rmd256_tv_template, RMD256_TEST_VECTORS);
  1364. break;
  1365. case 42:
  1366. test_hash("rmd320", rmd320_tv_template, RMD320_TEST_VECTORS);
  1367. break;
  1368. case 100:
  1369. test_hash("hmac(md5)", hmac_md5_tv_template,
  1370. HMAC_MD5_TEST_VECTORS);
  1371. break;
  1372. case 101:
  1373. test_hash("hmac(sha1)", hmac_sha1_tv_template,
  1374. HMAC_SHA1_TEST_VECTORS);
  1375. break;
  1376. case 102:
  1377. test_hash("hmac(sha256)", hmac_sha256_tv_template,
  1378. HMAC_SHA256_TEST_VECTORS);
  1379. break;
  1380. case 103:
  1381. test_hash("hmac(sha384)", hmac_sha384_tv_template,
  1382. HMAC_SHA384_TEST_VECTORS);
  1383. break;
  1384. case 104:
  1385. test_hash("hmac(sha512)", hmac_sha512_tv_template,
  1386. HMAC_SHA512_TEST_VECTORS);
  1387. break;
  1388. case 105:
  1389. test_hash("hmac(sha224)", hmac_sha224_tv_template,
  1390. HMAC_SHA224_TEST_VECTORS);
  1391. break;
  1392. case 106:
  1393. test_hash("xcbc(aes)", aes_xcbc128_tv_template,
  1394. XCBC_AES_TEST_VECTORS);
  1395. break;
  1396. case 107:
  1397. test_hash("hmac(rmd128)", hmac_rmd128_tv_template,
  1398. HMAC_RMD128_TEST_VECTORS);
  1399. break;
  1400. case 108:
  1401. test_hash("hmac(rmd160)", hmac_rmd160_tv_template,
  1402. HMAC_RMD160_TEST_VECTORS);
  1403. break;
  1404. case 200:
  1405. test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
  1406. speed_template_16_24_32);
  1407. test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
  1408. speed_template_16_24_32);
  1409. test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
  1410. speed_template_16_24_32);
  1411. test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
  1412. speed_template_16_24_32);
  1413. test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
  1414. speed_template_32_40_48);
  1415. test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
  1416. speed_template_32_40_48);
  1417. test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
  1418. speed_template_32_48_64);
  1419. test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
  1420. speed_template_32_48_64);
  1421. break;
  1422. case 201:
  1423. test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
  1424. des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
  1425. speed_template_24);
  1426. test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
  1427. des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
  1428. speed_template_24);
  1429. test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
  1430. des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
  1431. speed_template_24);
  1432. test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
  1433. des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
  1434. speed_template_24);
  1435. break;
  1436. case 202:
  1437. test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
  1438. speed_template_16_24_32);
  1439. test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
  1440. speed_template_16_24_32);
  1441. test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
  1442. speed_template_16_24_32);
  1443. test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
  1444. speed_template_16_24_32);
  1445. break;
  1446. case 203:
  1447. test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
  1448. speed_template_8_32);
  1449. test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
  1450. speed_template_8_32);
  1451. test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
  1452. speed_template_8_32);
  1453. test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
  1454. speed_template_8_32);
  1455. break;
  1456. case 204:
  1457. test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
  1458. speed_template_8);
  1459. test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
  1460. speed_template_8);
  1461. test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
  1462. speed_template_8);
  1463. test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
  1464. speed_template_8);
  1465. break;
  1466. case 205:
  1467. test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
  1468. speed_template_16_24_32);
  1469. test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
  1470. speed_template_16_24_32);
  1471. test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
  1472. speed_template_16_24_32);
  1473. test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
  1474. speed_template_16_24_32);
  1475. break;
  1476. case 206:
  1477. test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
  1478. speed_template_16_32);
  1479. break;
  1480. case 300:
  1481. /* fall through */
  1482. case 301:
  1483. test_hash_speed("md4", sec, generic_hash_speed_template);
  1484. if (mode > 300 && mode < 400) break;
  1485. case 302:
  1486. test_hash_speed("md5", sec, generic_hash_speed_template);
  1487. if (mode > 300 && mode < 400) break;
  1488. case 303:
  1489. test_hash_speed("sha1", sec, generic_hash_speed_template);
  1490. if (mode > 300 && mode < 400) break;
  1491. case 304:
  1492. test_hash_speed("sha256", sec, generic_hash_speed_template);
  1493. if (mode > 300 && mode < 400) break;
  1494. case 305:
  1495. test_hash_speed("sha384", sec, generic_hash_speed_template);
  1496. if (mode > 300 && mode < 400) break;
  1497. case 306:
  1498. test_hash_speed("sha512", sec, generic_hash_speed_template);
  1499. if (mode > 300 && mode < 400) break;
  1500. case 307:
  1501. test_hash_speed("wp256", sec, generic_hash_speed_template);
  1502. if (mode > 300 && mode < 400) break;
  1503. case 308:
  1504. test_hash_speed("wp384", sec, generic_hash_speed_template);
  1505. if (mode > 300 && mode < 400) break;
  1506. case 309:
  1507. test_hash_speed("wp512", sec, generic_hash_speed_template);
  1508. if (mode > 300 && mode < 400) break;
  1509. case 310:
  1510. test_hash_speed("tgr128", sec, generic_hash_speed_template);
  1511. if (mode > 300 && mode < 400) break;
  1512. case 311:
  1513. test_hash_speed("tgr160", sec, generic_hash_speed_template);
  1514. if (mode > 300 && mode < 400) break;
  1515. case 312:
  1516. test_hash_speed("tgr192", sec, generic_hash_speed_template);
  1517. if (mode > 300 && mode < 400) break;
  1518. case 313:
  1519. test_hash_speed("sha224", sec, generic_hash_speed_template);
  1520. if (mode > 300 && mode < 400) break;
  1521. case 314:
  1522. test_hash_speed("rmd128", sec, generic_hash_speed_template);
  1523. if (mode > 300 && mode < 400) break;
  1524. case 315:
  1525. test_hash_speed("rmd160", sec, generic_hash_speed_template);
  1526. if (mode > 300 && mode < 400) break;
  1527. case 316:
  1528. test_hash_speed("rmd256", sec, generic_hash_speed_template);
  1529. if (mode > 300 && mode < 400) break;
  1530. case 317:
  1531. test_hash_speed("rmd320", sec, generic_hash_speed_template);
  1532. if (mode > 300 && mode < 400) break;
  1533. case 399:
  1534. break;
  1535. case 1000:
  1536. test_available();
  1537. break;
  1538. default:
  1539. /* useful for debugging */
  1540. printk("not testing anything\n");
  1541. break;
  1542. }
  1543. }
  1544. static int __init tcrypt_mod_init(void)
  1545. {
  1546. int err = -ENOMEM;
  1547. tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
  1548. if (tvmem == NULL)
  1549. return err;
  1550. xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
  1551. if (xbuf == NULL)
  1552. goto err_free_tv;
  1553. axbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
  1554. if (axbuf == NULL)
  1555. goto err_free_xbuf;
  1556. do_test();
  1557. /* We intentionaly return -EAGAIN to prevent keeping
  1558. * the module. It does all its work from init()
  1559. * and doesn't offer any runtime functionality
  1560. * => we don't need it in the memory, do we?
  1561. * -- mludvig
  1562. */
  1563. err = -EAGAIN;
  1564. kfree(axbuf);
  1565. err_free_xbuf:
  1566. kfree(xbuf);
  1567. err_free_tv:
  1568. kfree(tvmem);
  1569. return err;
  1570. }
  1571. /*
  1572. * If an init function is provided, an exit function must also be provided
  1573. * to allow module unload.
  1574. */
  1575. static void __exit tcrypt_mod_fini(void) { }
  1576. module_init(tcrypt_mod_init);
  1577. module_exit(tcrypt_mod_fini);
  1578. module_param(mode, int, 0);
  1579. module_param(sec, uint, 0);
  1580. MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
  1581. "(defaults to zero which uses CPU cycles instead)");
  1582. MODULE_LICENSE("GPL");
  1583. MODULE_DESCRIPTION("Quick & dirty crypto testing module");
  1584. MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");