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