tcrypt.c 47 KB

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