diff options
Diffstat (limited to 'crypto/tcrypt.c')
-rw-r--r-- | crypto/tcrypt.c | 449 |
1 files changed, 384 insertions, 65 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index 24141fb6f5cb..1ab8c017a011 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c | |||
@@ -6,12 +6,16 @@ | |||
6 | * | 6 | * |
7 | * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> | 7 | * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> |
8 | * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org> | 8 | * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org> |
9 | * Copyright (c) 2007 Nokia Siemens Networks | ||
9 | * | 10 | * |
10 | * This program is free software; you can redistribute it and/or modify it | 11 | * 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 | * 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 | * Software Foundation; either version 2 of the License, or (at your option) |
13 | * any later version. | 14 | * any later version. |
14 | * | 15 | * |
16 | * 2007-11-13 Added GCM tests | ||
17 | * 2007-11-13 Added AEAD support | ||
18 | * 2007-11-06 Added SHA-224 and SHA-224-HMAC tests | ||
15 | * 2006-12-07 Added SHA384 HMAC and SHA512 HMAC tests | 19 | * 2006-12-07 Added SHA384 HMAC and SHA512 HMAC tests |
16 | * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>) | 20 | * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>) |
17 | * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt | 21 | * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt |
@@ -71,22 +75,23 @@ static unsigned int sec; | |||
71 | 75 | ||
72 | static int mode; | 76 | static int mode; |
73 | static char *xbuf; | 77 | static char *xbuf; |
78 | static char *axbuf; | ||
74 | static char *tvmem; | 79 | static char *tvmem; |
75 | 80 | ||
76 | static char *check[] = { | 81 | static char *check[] = { |
77 | "des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish", | 82 | "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", |
78 | "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6", | 83 | "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes", |
84 | "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", | ||
79 | "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", | 85 | "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", |
80 | "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", | 86 | "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", |
81 | "camellia", "seed", NULL | 87 | "camellia", "seed", "salsa20", "lzo", NULL |
82 | }; | 88 | }; |
83 | 89 | ||
84 | static void hexdump(unsigned char *buf, unsigned int len) | 90 | static void hexdump(unsigned char *buf, unsigned int len) |
85 | { | 91 | { |
86 | while (len--) | 92 | print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET, |
87 | printk("%02x", *buf++); | 93 | 16, 1, |
88 | 94 | buf, len, false); | |
89 | printk("\n"); | ||
90 | } | 95 | } |
91 | 96 | ||
92 | static void tcrypt_complete(struct crypto_async_request *req, int err) | 97 | static void tcrypt_complete(struct crypto_async_request *req, int err) |
@@ -215,6 +220,238 @@ out: | |||
215 | crypto_free_hash(tfm); | 220 | crypto_free_hash(tfm); |
216 | } | 221 | } |
217 | 222 | ||
223 | static void test_aead(char *algo, int enc, struct aead_testvec *template, | ||
224 | unsigned int tcount) | ||
225 | { | ||
226 | unsigned int ret, i, j, k, temp; | ||
227 | unsigned int tsize; | ||
228 | char *q; | ||
229 | struct crypto_aead *tfm; | ||
230 | char *key; | ||
231 | struct aead_testvec *aead_tv; | ||
232 | struct aead_request *req; | ||
233 | struct scatterlist sg[8]; | ||
234 | struct scatterlist asg[8]; | ||
235 | const char *e; | ||
236 | struct tcrypt_result result; | ||
237 | unsigned int authsize; | ||
238 | |||
239 | if (enc == ENCRYPT) | ||
240 | e = "encryption"; | ||
241 | else | ||
242 | e = "decryption"; | ||
243 | |||
244 | printk(KERN_INFO "\ntesting %s %s\n", algo, e); | ||
245 | |||
246 | tsize = sizeof(struct aead_testvec); | ||
247 | tsize *= tcount; | ||
248 | |||
249 | if (tsize > TVMEMSIZE) { | ||
250 | printk(KERN_INFO "template (%u) too big for tvmem (%u)\n", | ||
251 | tsize, TVMEMSIZE); | ||
252 | return; | ||
253 | } | ||
254 | |||
255 | memcpy(tvmem, template, tsize); | ||
256 | aead_tv = (void *)tvmem; | ||
257 | |||
258 | init_completion(&result.completion); | ||
259 | |||
260 | tfm = crypto_alloc_aead(algo, 0, 0); | ||
261 | |||
262 | if (IS_ERR(tfm)) { | ||
263 | printk(KERN_INFO "failed to load transform for %s: %ld\n", | ||
264 | algo, PTR_ERR(tfm)); | ||
265 | return; | ||
266 | } | ||
267 | |||
268 | req = aead_request_alloc(tfm, GFP_KERNEL); | ||
269 | if (!req) { | ||
270 | printk(KERN_INFO "failed to allocate request for %s\n", algo); | ||
271 | goto out; | ||
272 | } | ||
273 | |||
274 | aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, | ||
275 | tcrypt_complete, &result); | ||
276 | |||
277 | for (i = 0, j = 0; i < tcount; i++) { | ||
278 | if (!aead_tv[i].np) { | ||
279 | printk(KERN_INFO "test %u (%d bit key):\n", | ||
280 | ++j, aead_tv[i].klen * 8); | ||
281 | |||
282 | crypto_aead_clear_flags(tfm, ~0); | ||
283 | if (aead_tv[i].wk) | ||
284 | crypto_aead_set_flags( | ||
285 | tfm, CRYPTO_TFM_REQ_WEAK_KEY); | ||
286 | key = aead_tv[i].key; | ||
287 | |||
288 | ret = crypto_aead_setkey(tfm, key, | ||
289 | aead_tv[i].klen); | ||
290 | if (ret) { | ||
291 | printk(KERN_INFO "setkey() failed flags=%x\n", | ||
292 | crypto_aead_get_flags(tfm)); | ||
293 | |||
294 | if (!aead_tv[i].fail) | ||
295 | goto out; | ||
296 | } | ||
297 | |||
298 | authsize = abs(aead_tv[i].rlen - aead_tv[i].ilen); | ||
299 | ret = crypto_aead_setauthsize(tfm, authsize); | ||
300 | if (ret) { | ||
301 | printk(KERN_INFO | ||
302 | "failed to set authsize = %u\n", | ||
303 | authsize); | ||
304 | goto out; | ||
305 | } | ||
306 | |||
307 | sg_init_one(&sg[0], aead_tv[i].input, | ||
308 | aead_tv[i].ilen + (enc ? authsize : 0)); | ||
309 | |||
310 | sg_init_one(&asg[0], aead_tv[i].assoc, | ||
311 | aead_tv[i].alen); | ||
312 | |||
313 | aead_request_set_crypt(req, sg, sg, | ||
314 | aead_tv[i].ilen, | ||
315 | aead_tv[i].iv); | ||
316 | |||
317 | aead_request_set_assoc(req, asg, aead_tv[i].alen); | ||
318 | |||
319 | ret = enc ? | ||
320 | crypto_aead_encrypt(req) : | ||
321 | crypto_aead_decrypt(req); | ||
322 | |||
323 | switch (ret) { | ||
324 | case 0: | ||
325 | break; | ||
326 | case -EINPROGRESS: | ||
327 | case -EBUSY: | ||
328 | ret = wait_for_completion_interruptible( | ||
329 | &result.completion); | ||
330 | if (!ret && !(ret = result.err)) { | ||
331 | INIT_COMPLETION(result.completion); | ||
332 | break; | ||
333 | } | ||
334 | /* fall through */ | ||
335 | default: | ||
336 | printk(KERN_INFO "%s () failed err=%d\n", | ||
337 | e, -ret); | ||
338 | goto out; | ||
339 | } | ||
340 | |||
341 | q = kmap(sg_page(&sg[0])) + sg[0].offset; | ||
342 | hexdump(q, aead_tv[i].rlen); | ||
343 | |||
344 | printk(KERN_INFO "enc/dec: %s\n", | ||
345 | memcmp(q, aead_tv[i].result, | ||
346 | aead_tv[i].rlen) ? "fail" : "pass"); | ||
347 | } | ||
348 | } | ||
349 | |||
350 | printk(KERN_INFO "\ntesting %s %s across pages (chunking)\n", algo, e); | ||
351 | memset(xbuf, 0, XBUFSIZE); | ||
352 | memset(axbuf, 0, XBUFSIZE); | ||
353 | |||
354 | for (i = 0, j = 0; i < tcount; i++) { | ||
355 | if (aead_tv[i].np) { | ||
356 | printk(KERN_INFO "test %u (%d bit key):\n", | ||
357 | ++j, aead_tv[i].klen * 8); | ||
358 | |||
359 | crypto_aead_clear_flags(tfm, ~0); | ||
360 | if (aead_tv[i].wk) | ||
361 | crypto_aead_set_flags( | ||
362 | tfm, CRYPTO_TFM_REQ_WEAK_KEY); | ||
363 | key = aead_tv[i].key; | ||
364 | |||
365 | ret = crypto_aead_setkey(tfm, key, aead_tv[i].klen); | ||
366 | if (ret) { | ||
367 | printk(KERN_INFO "setkey() failed flags=%x\n", | ||
368 | crypto_aead_get_flags(tfm)); | ||
369 | |||
370 | if (!aead_tv[i].fail) | ||
371 | goto out; | ||
372 | } | ||
373 | |||
374 | sg_init_table(sg, aead_tv[i].np); | ||
375 | for (k = 0, temp = 0; k < aead_tv[i].np; k++) { | ||
376 | memcpy(&xbuf[IDX[k]], | ||
377 | aead_tv[i].input + temp, | ||
378 | aead_tv[i].tap[k]); | ||
379 | temp += aead_tv[i].tap[k]; | ||
380 | sg_set_buf(&sg[k], &xbuf[IDX[k]], | ||
381 | aead_tv[i].tap[k]); | ||
382 | } | ||
383 | |||
384 | authsize = abs(aead_tv[i].rlen - aead_tv[i].ilen); | ||
385 | ret = crypto_aead_setauthsize(tfm, authsize); | ||
386 | if (ret) { | ||
387 | printk(KERN_INFO | ||
388 | "failed to set authsize = %u\n", | ||
389 | authsize); | ||
390 | goto out; | ||
391 | } | ||
392 | |||
393 | if (enc) | ||
394 | sg[k - 1].length += authsize; | ||
395 | |||
396 | sg_init_table(asg, aead_tv[i].anp); | ||
397 | for (k = 0, temp = 0; k < aead_tv[i].anp; k++) { | ||
398 | memcpy(&axbuf[IDX[k]], | ||
399 | aead_tv[i].assoc + temp, | ||
400 | aead_tv[i].atap[k]); | ||
401 | temp += aead_tv[i].atap[k]; | ||
402 | sg_set_buf(&asg[k], &axbuf[IDX[k]], | ||
403 | aead_tv[i].atap[k]); | ||
404 | } | ||
405 | |||
406 | aead_request_set_crypt(req, sg, sg, | ||
407 | aead_tv[i].ilen, | ||
408 | aead_tv[i].iv); | ||
409 | |||
410 | aead_request_set_assoc(req, asg, aead_tv[i].alen); | ||
411 | |||
412 | ret = enc ? | ||
413 | crypto_aead_encrypt(req) : | ||
414 | crypto_aead_decrypt(req); | ||
415 | |||
416 | switch (ret) { | ||
417 | case 0: | ||
418 | break; | ||
419 | case -EINPROGRESS: | ||
420 | case -EBUSY: | ||
421 | ret = wait_for_completion_interruptible( | ||
422 | &result.completion); | ||
423 | if (!ret && !(ret = result.err)) { | ||
424 | INIT_COMPLETION(result.completion); | ||
425 | break; | ||
426 | } | ||
427 | /* fall through */ | ||
428 | default: | ||
429 | printk(KERN_INFO "%s () failed err=%d\n", | ||
430 | e, -ret); | ||
431 | goto out; | ||
432 | } | ||
433 | |||
434 | for (k = 0, temp = 0; k < aead_tv[i].np; k++) { | ||
435 | printk(KERN_INFO "page %u\n", k); | ||
436 | q = kmap(sg_page(&sg[k])) + sg[k].offset; | ||
437 | hexdump(q, aead_tv[i].tap[k]); | ||
438 | printk(KERN_INFO "%s\n", | ||
439 | memcmp(q, aead_tv[i].result + temp, | ||
440 | aead_tv[i].tap[k] - | ||
441 | (k < aead_tv[i].np - 1 || enc ? | ||
442 | 0 : authsize)) ? | ||
443 | "fail" : "pass"); | ||
444 | |||
445 | temp += aead_tv[i].tap[k]; | ||
446 | } | ||
447 | } | ||
448 | } | ||
449 | |||
450 | out: | ||
451 | crypto_free_aead(tfm); | ||
452 | aead_request_free(req); | ||
453 | } | ||
454 | |||
218 | static void test_cipher(char *algo, int enc, | 455 | static void test_cipher(char *algo, int enc, |
219 | struct cipher_testvec *template, unsigned int tcount) | 456 | struct cipher_testvec *template, unsigned int tcount) |
220 | { | 457 | { |
@@ -237,15 +474,11 @@ static void test_cipher(char *algo, int enc, | |||
237 | printk("\ntesting %s %s\n", algo, e); | 474 | printk("\ntesting %s %s\n", algo, e); |
238 | 475 | ||
239 | tsize = sizeof (struct cipher_testvec); | 476 | tsize = sizeof (struct cipher_testvec); |
240 | tsize *= tcount; | ||
241 | |||
242 | if (tsize > TVMEMSIZE) { | 477 | if (tsize > TVMEMSIZE) { |
243 | printk("template (%u) too big for tvmem (%u)\n", tsize, | 478 | printk("template (%u) too big for tvmem (%u)\n", tsize, |
244 | TVMEMSIZE); | 479 | TVMEMSIZE); |
245 | return; | 480 | return; |
246 | } | 481 | } |
247 | |||
248 | memcpy(tvmem, template, tsize); | ||
249 | cipher_tv = (void *)tvmem; | 482 | cipher_tv = (void *)tvmem; |
250 | 483 | ||
251 | init_completion(&result.completion); | 484 | init_completion(&result.completion); |
@@ -269,33 +502,34 @@ static void test_cipher(char *algo, int enc, | |||
269 | 502 | ||
270 | j = 0; | 503 | j = 0; |
271 | for (i = 0; i < tcount; i++) { | 504 | for (i = 0; i < tcount; i++) { |
272 | if (!(cipher_tv[i].np)) { | 505 | memcpy(cipher_tv, &template[i], tsize); |
506 | if (!(cipher_tv->np)) { | ||
273 | j++; | 507 | j++; |
274 | printk("test %u (%d bit key):\n", | 508 | printk("test %u (%d bit key):\n", |
275 | j, cipher_tv[i].klen * 8); | 509 | j, cipher_tv->klen * 8); |
276 | 510 | ||
277 | crypto_ablkcipher_clear_flags(tfm, ~0); | 511 | crypto_ablkcipher_clear_flags(tfm, ~0); |
278 | if (cipher_tv[i].wk) | 512 | if (cipher_tv->wk) |
279 | crypto_ablkcipher_set_flags( | 513 | crypto_ablkcipher_set_flags( |
280 | tfm, CRYPTO_TFM_REQ_WEAK_KEY); | 514 | tfm, CRYPTO_TFM_REQ_WEAK_KEY); |
281 | key = cipher_tv[i].key; | 515 | key = cipher_tv->key; |
282 | 516 | ||
283 | ret = crypto_ablkcipher_setkey(tfm, key, | 517 | ret = crypto_ablkcipher_setkey(tfm, key, |
284 | cipher_tv[i].klen); | 518 | cipher_tv->klen); |
285 | if (ret) { | 519 | if (ret) { |
286 | printk("setkey() failed flags=%x\n", | 520 | printk("setkey() failed flags=%x\n", |
287 | crypto_ablkcipher_get_flags(tfm)); | 521 | crypto_ablkcipher_get_flags(tfm)); |
288 | 522 | ||
289 | if (!cipher_tv[i].fail) | 523 | if (!cipher_tv->fail) |
290 | goto out; | 524 | goto out; |
291 | } | 525 | } |
292 | 526 | ||
293 | sg_init_one(&sg[0], cipher_tv[i].input, | 527 | sg_init_one(&sg[0], cipher_tv->input, |
294 | cipher_tv[i].ilen); | 528 | cipher_tv->ilen); |
295 | 529 | ||
296 | ablkcipher_request_set_crypt(req, sg, sg, | 530 | ablkcipher_request_set_crypt(req, sg, sg, |
297 | cipher_tv[i].ilen, | 531 | cipher_tv->ilen, |
298 | cipher_tv[i].iv); | 532 | cipher_tv->iv); |
299 | 533 | ||
300 | ret = enc ? | 534 | ret = enc ? |
301 | crypto_ablkcipher_encrypt(req) : | 535 | crypto_ablkcipher_encrypt(req) : |
@@ -319,11 +553,11 @@ static void test_cipher(char *algo, int enc, | |||
319 | } | 553 | } |
320 | 554 | ||
321 | q = kmap(sg_page(&sg[0])) + sg[0].offset; | 555 | q = kmap(sg_page(&sg[0])) + sg[0].offset; |
322 | hexdump(q, cipher_tv[i].rlen); | 556 | hexdump(q, cipher_tv->rlen); |
323 | 557 | ||
324 | printk("%s\n", | 558 | printk("%s\n", |
325 | memcmp(q, cipher_tv[i].result, | 559 | memcmp(q, cipher_tv->result, |
326 | cipher_tv[i].rlen) ? "fail" : "pass"); | 560 | cipher_tv->rlen) ? "fail" : "pass"); |
327 | } | 561 | } |
328 | } | 562 | } |
329 | 563 | ||
@@ -332,41 +566,42 @@ static void test_cipher(char *algo, int enc, | |||
332 | 566 | ||
333 | j = 0; | 567 | j = 0; |
334 | for (i = 0; i < tcount; i++) { | 568 | for (i = 0; i < tcount; i++) { |
335 | if (cipher_tv[i].np) { | 569 | memcpy(cipher_tv, &template[i], tsize); |
570 | if (cipher_tv->np) { | ||
336 | j++; | 571 | j++; |
337 | printk("test %u (%d bit key):\n", | 572 | printk("test %u (%d bit key):\n", |
338 | j, cipher_tv[i].klen * 8); | 573 | j, cipher_tv->klen * 8); |
339 | 574 | ||
340 | crypto_ablkcipher_clear_flags(tfm, ~0); | 575 | crypto_ablkcipher_clear_flags(tfm, ~0); |
341 | if (cipher_tv[i].wk) | 576 | if (cipher_tv->wk) |
342 | crypto_ablkcipher_set_flags( | 577 | crypto_ablkcipher_set_flags( |
343 | tfm, CRYPTO_TFM_REQ_WEAK_KEY); | 578 | tfm, CRYPTO_TFM_REQ_WEAK_KEY); |
344 | key = cipher_tv[i].key; | 579 | key = cipher_tv->key; |
345 | 580 | ||
346 | ret = crypto_ablkcipher_setkey(tfm, key, | 581 | ret = crypto_ablkcipher_setkey(tfm, key, |
347 | cipher_tv[i].klen); | 582 | cipher_tv->klen); |
348 | if (ret) { | 583 | if (ret) { |
349 | printk("setkey() failed flags=%x\n", | 584 | printk("setkey() failed flags=%x\n", |
350 | crypto_ablkcipher_get_flags(tfm)); | 585 | crypto_ablkcipher_get_flags(tfm)); |
351 | 586 | ||
352 | if (!cipher_tv[i].fail) | 587 | if (!cipher_tv->fail) |
353 | goto out; | 588 | goto out; |
354 | } | 589 | } |
355 | 590 | ||
356 | temp = 0; | 591 | temp = 0; |
357 | sg_init_table(sg, cipher_tv[i].np); | 592 | sg_init_table(sg, cipher_tv->np); |
358 | for (k = 0; k < cipher_tv[i].np; k++) { | 593 | for (k = 0; k < cipher_tv->np; k++) { |
359 | memcpy(&xbuf[IDX[k]], | 594 | memcpy(&xbuf[IDX[k]], |
360 | cipher_tv[i].input + temp, | 595 | cipher_tv->input + temp, |
361 | cipher_tv[i].tap[k]); | 596 | cipher_tv->tap[k]); |
362 | temp += cipher_tv[i].tap[k]; | 597 | temp += cipher_tv->tap[k]; |
363 | sg_set_buf(&sg[k], &xbuf[IDX[k]], | 598 | sg_set_buf(&sg[k], &xbuf[IDX[k]], |
364 | cipher_tv[i].tap[k]); | 599 | cipher_tv->tap[k]); |
365 | } | 600 | } |
366 | 601 | ||
367 | ablkcipher_request_set_crypt(req, sg, sg, | 602 | ablkcipher_request_set_crypt(req, sg, sg, |
368 | cipher_tv[i].ilen, | 603 | cipher_tv->ilen, |
369 | cipher_tv[i].iv); | 604 | cipher_tv->iv); |
370 | 605 | ||
371 | ret = enc ? | 606 | ret = enc ? |
372 | crypto_ablkcipher_encrypt(req) : | 607 | crypto_ablkcipher_encrypt(req) : |
@@ -390,15 +625,15 @@ static void test_cipher(char *algo, int enc, | |||
390 | } | 625 | } |
391 | 626 | ||
392 | temp = 0; | 627 | temp = 0; |
393 | for (k = 0; k < cipher_tv[i].np; k++) { | 628 | for (k = 0; k < cipher_tv->np; k++) { |
394 | printk("page %u\n", k); | 629 | printk("page %u\n", k); |
395 | q = kmap(sg_page(&sg[k])) + sg[k].offset; | 630 | q = kmap(sg_page(&sg[k])) + sg[k].offset; |
396 | hexdump(q, cipher_tv[i].tap[k]); | 631 | hexdump(q, cipher_tv->tap[k]); |
397 | printk("%s\n", | 632 | printk("%s\n", |
398 | memcmp(q, cipher_tv[i].result + temp, | 633 | memcmp(q, cipher_tv->result + temp, |
399 | cipher_tv[i].tap[k]) ? "fail" : | 634 | cipher_tv->tap[k]) ? "fail" : |
400 | "pass"); | 635 | "pass"); |
401 | temp += cipher_tv[i].tap[k]; | 636 | temp += cipher_tv->tap[k]; |
402 | } | 637 | } |
403 | } | 638 | } |
404 | } | 639 | } |
@@ -800,7 +1035,8 @@ out: | |||
800 | crypto_free_hash(tfm); | 1035 | crypto_free_hash(tfm); |
801 | } | 1036 | } |
802 | 1037 | ||
803 | static void test_deflate(void) | 1038 | static void test_comp(char *algo, struct comp_testvec *ctemplate, |
1039 | struct comp_testvec *dtemplate, int ctcount, int dtcount) | ||
804 | { | 1040 | { |
805 | unsigned int i; | 1041 | unsigned int i; |
806 | char result[COMP_BUF_SIZE]; | 1042 | char result[COMP_BUF_SIZE]; |
@@ -808,25 +1044,26 @@ static void test_deflate(void) | |||
808 | struct comp_testvec *tv; | 1044 | struct comp_testvec *tv; |
809 | unsigned int tsize; | 1045 | unsigned int tsize; |
810 | 1046 | ||
811 | printk("\ntesting deflate compression\n"); | 1047 | printk("\ntesting %s compression\n", algo); |
812 | 1048 | ||
813 | tsize = sizeof (deflate_comp_tv_template); | 1049 | tsize = sizeof(struct comp_testvec); |
1050 | tsize *= ctcount; | ||
814 | if (tsize > TVMEMSIZE) { | 1051 | if (tsize > TVMEMSIZE) { |
815 | printk("template (%u) too big for tvmem (%u)\n", tsize, | 1052 | printk("template (%u) too big for tvmem (%u)\n", tsize, |
816 | TVMEMSIZE); | 1053 | TVMEMSIZE); |
817 | return; | 1054 | return; |
818 | } | 1055 | } |
819 | 1056 | ||
820 | memcpy(tvmem, deflate_comp_tv_template, tsize); | 1057 | memcpy(tvmem, ctemplate, tsize); |
821 | tv = (void *)tvmem; | 1058 | tv = (void *)tvmem; |
822 | 1059 | ||
823 | tfm = crypto_alloc_comp("deflate", 0, CRYPTO_ALG_ASYNC); | 1060 | tfm = crypto_alloc_comp(algo, 0, CRYPTO_ALG_ASYNC); |
824 | if (IS_ERR(tfm)) { | 1061 | if (IS_ERR(tfm)) { |
825 | printk("failed to load transform for deflate\n"); | 1062 | printk("failed to load transform for %s\n", algo); |
826 | return; | 1063 | return; |
827 | } | 1064 | } |
828 | 1065 | ||
829 | for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) { | 1066 | for (i = 0; i < ctcount; i++) { |
830 | int ilen, ret, dlen = COMP_BUF_SIZE; | 1067 | int ilen, ret, dlen = COMP_BUF_SIZE; |
831 | 1068 | ||
832 | printk("test %u:\n", i + 1); | 1069 | printk("test %u:\n", i + 1); |
@@ -845,19 +1082,20 @@ static void test_deflate(void) | |||
845 | ilen, dlen); | 1082 | ilen, dlen); |
846 | } | 1083 | } |
847 | 1084 | ||
848 | printk("\ntesting deflate decompression\n"); | 1085 | printk("\ntesting %s decompression\n", algo); |
849 | 1086 | ||
850 | tsize = sizeof (deflate_decomp_tv_template); | 1087 | tsize = sizeof(struct comp_testvec); |
1088 | tsize *= dtcount; | ||
851 | if (tsize > TVMEMSIZE) { | 1089 | if (tsize > TVMEMSIZE) { |
852 | printk("template (%u) too big for tvmem (%u)\n", tsize, | 1090 | printk("template (%u) too big for tvmem (%u)\n", tsize, |
853 | TVMEMSIZE); | 1091 | TVMEMSIZE); |
854 | goto out; | 1092 | goto out; |
855 | } | 1093 | } |
856 | 1094 | ||
857 | memcpy(tvmem, deflate_decomp_tv_template, tsize); | 1095 | memcpy(tvmem, dtemplate, tsize); |
858 | tv = (void *)tvmem; | 1096 | tv = (void *)tvmem; |
859 | 1097 | ||
860 | for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) { | 1098 | for (i = 0; i < dtcount; i++) { |
861 | int ilen, ret, dlen = COMP_BUF_SIZE; | 1099 | int ilen, ret, dlen = COMP_BUF_SIZE; |
862 | 1100 | ||
863 | printk("test %u:\n", i + 1); | 1101 | printk("test %u:\n", i + 1); |
@@ -918,6 +1156,8 @@ static void do_test(void) | |||
918 | 1156 | ||
919 | test_hash("md4", md4_tv_template, MD4_TEST_VECTORS); | 1157 | test_hash("md4", md4_tv_template, MD4_TEST_VECTORS); |
920 | 1158 | ||
1159 | test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS); | ||
1160 | |||
921 | test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS); | 1161 | test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS); |
922 | 1162 | ||
923 | //BLOWFISH | 1163 | //BLOWFISH |
@@ -969,6 +1209,18 @@ static void do_test(void) | |||
969 | AES_XTS_ENC_TEST_VECTORS); | 1209 | AES_XTS_ENC_TEST_VECTORS); |
970 | test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template, | 1210 | test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template, |
971 | AES_XTS_DEC_TEST_VECTORS); | 1211 | AES_XTS_DEC_TEST_VECTORS); |
1212 | test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template, | ||
1213 | AES_CTR_ENC_TEST_VECTORS); | ||
1214 | test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template, | ||
1215 | AES_CTR_DEC_TEST_VECTORS); | ||
1216 | test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template, | ||
1217 | AES_GCM_ENC_TEST_VECTORS); | ||
1218 | test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template, | ||
1219 | AES_GCM_DEC_TEST_VECTORS); | ||
1220 | test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template, | ||
1221 | AES_CCM_ENC_TEST_VECTORS); | ||
1222 | test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template, | ||
1223 | AES_CCM_DEC_TEST_VECTORS); | ||
972 | 1224 | ||
973 | //CAST5 | 1225 | //CAST5 |
974 | test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template, | 1226 | test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template, |
@@ -1057,12 +1309,18 @@ static void do_test(void) | |||
1057 | test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS); | 1309 | test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS); |
1058 | test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS); | 1310 | test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS); |
1059 | test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS); | 1311 | test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS); |
1060 | test_deflate(); | 1312 | test_comp("deflate", deflate_comp_tv_template, |
1313 | deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS, | ||
1314 | DEFLATE_DECOMP_TEST_VECTORS); | ||
1315 | test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template, | ||
1316 | LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS); | ||
1061 | test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS); | 1317 | test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS); |
1062 | test_hash("hmac(md5)", hmac_md5_tv_template, | 1318 | test_hash("hmac(md5)", hmac_md5_tv_template, |
1063 | HMAC_MD5_TEST_VECTORS); | 1319 | HMAC_MD5_TEST_VECTORS); |
1064 | test_hash("hmac(sha1)", hmac_sha1_tv_template, | 1320 | test_hash("hmac(sha1)", hmac_sha1_tv_template, |
1065 | HMAC_SHA1_TEST_VECTORS); | 1321 | HMAC_SHA1_TEST_VECTORS); |
1322 | test_hash("hmac(sha224)", hmac_sha224_tv_template, | ||
1323 | HMAC_SHA224_TEST_VECTORS); | ||
1066 | test_hash("hmac(sha256)", hmac_sha256_tv_template, | 1324 | test_hash("hmac(sha256)", hmac_sha256_tv_template, |
1067 | HMAC_SHA256_TEST_VECTORS); | 1325 | HMAC_SHA256_TEST_VECTORS); |
1068 | test_hash("hmac(sha384)", hmac_sha384_tv_template, | 1326 | test_hash("hmac(sha384)", hmac_sha384_tv_template, |
@@ -1156,6 +1414,10 @@ static void do_test(void) | |||
1156 | AES_XTS_ENC_TEST_VECTORS); | 1414 | AES_XTS_ENC_TEST_VECTORS); |
1157 | test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template, | 1415 | test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template, |
1158 | AES_XTS_DEC_TEST_VECTORS); | 1416 | AES_XTS_DEC_TEST_VECTORS); |
1417 | test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template, | ||
1418 | AES_CTR_ENC_TEST_VECTORS); | ||
1419 | test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template, | ||
1420 | AES_CTR_DEC_TEST_VECTORS); | ||
1159 | break; | 1421 | break; |
1160 | 1422 | ||
1161 | case 11: | 1423 | case 11: |
@@ -1167,7 +1429,9 @@ static void do_test(void) | |||
1167 | break; | 1429 | break; |
1168 | 1430 | ||
1169 | case 13: | 1431 | case 13: |
1170 | test_deflate(); | 1432 | test_comp("deflate", deflate_comp_tv_template, |
1433 | deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS, | ||
1434 | DEFLATE_DECOMP_TEST_VECTORS); | ||
1171 | break; | 1435 | break; |
1172 | 1436 | ||
1173 | case 14: | 1437 | case 14: |
@@ -1291,6 +1555,34 @@ static void do_test(void) | |||
1291 | camellia_cbc_dec_tv_template, | 1555 | camellia_cbc_dec_tv_template, |
1292 | CAMELLIA_CBC_DEC_TEST_VECTORS); | 1556 | CAMELLIA_CBC_DEC_TEST_VECTORS); |
1293 | break; | 1557 | break; |
1558 | case 33: | ||
1559 | test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS); | ||
1560 | break; | ||
1561 | |||
1562 | case 34: | ||
1563 | test_cipher("salsa20", ENCRYPT, | ||
1564 | salsa20_stream_enc_tv_template, | ||
1565 | SALSA20_STREAM_ENC_TEST_VECTORS); | ||
1566 | break; | ||
1567 | |||
1568 | case 35: | ||
1569 | test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template, | ||
1570 | AES_GCM_ENC_TEST_VECTORS); | ||
1571 | test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template, | ||
1572 | AES_GCM_DEC_TEST_VECTORS); | ||
1573 | break; | ||
1574 | |||
1575 | case 36: | ||
1576 | test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template, | ||
1577 | LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS); | ||
1578 | break; | ||
1579 | |||
1580 | case 37: | ||
1581 | test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template, | ||
1582 | AES_CCM_ENC_TEST_VECTORS); | ||
1583 | test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template, | ||
1584 | AES_CCM_DEC_TEST_VECTORS); | ||
1585 | break; | ||
1294 | 1586 | ||
1295 | case 100: | 1587 | case 100: |
1296 | test_hash("hmac(md5)", hmac_md5_tv_template, | 1588 | test_hash("hmac(md5)", hmac_md5_tv_template, |
@@ -1317,6 +1609,15 @@ static void do_test(void) | |||
1317 | HMAC_SHA512_TEST_VECTORS); | 1609 | HMAC_SHA512_TEST_VECTORS); |
1318 | break; | 1610 | break; |
1319 | 1611 | ||
1612 | case 105: | ||
1613 | test_hash("hmac(sha224)", hmac_sha224_tv_template, | ||
1614 | HMAC_SHA224_TEST_VECTORS); | ||
1615 | break; | ||
1616 | |||
1617 | case 106: | ||
1618 | test_hash("xcbc(aes)", aes_xcbc128_tv_template, | ||
1619 | XCBC_AES_TEST_VECTORS); | ||
1620 | break; | ||
1320 | 1621 | ||
1321 | case 200: | 1622 | case 200: |
1322 | test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, | 1623 | test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, |
@@ -1400,6 +1701,11 @@ static void do_test(void) | |||
1400 | camellia_speed_template); | 1701 | camellia_speed_template); |
1401 | break; | 1702 | break; |
1402 | 1703 | ||
1704 | case 206: | ||
1705 | test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0, | ||
1706 | salsa20_speed_template); | ||
1707 | break; | ||
1708 | |||
1403 | case 300: | 1709 | case 300: |
1404 | /* fall through */ | 1710 | /* fall through */ |
1405 | 1711 | ||
@@ -1451,6 +1757,10 @@ static void do_test(void) | |||
1451 | test_hash_speed("tgr192", sec, generic_hash_speed_template); | 1757 | test_hash_speed("tgr192", sec, generic_hash_speed_template); |
1452 | if (mode > 300 && mode < 400) break; | 1758 | if (mode > 300 && mode < 400) break; |
1453 | 1759 | ||
1760 | case 313: | ||
1761 | test_hash_speed("sha224", sec, generic_hash_speed_template); | ||
1762 | if (mode > 300 && mode < 400) break; | ||
1763 | |||
1454 | case 399: | 1764 | case 399: |
1455 | break; | 1765 | break; |
1456 | 1766 | ||
@@ -1467,20 +1777,21 @@ static void do_test(void) | |||
1467 | 1777 | ||
1468 | static int __init init(void) | 1778 | static int __init init(void) |
1469 | { | 1779 | { |
1780 | int err = -ENOMEM; | ||
1781 | |||
1470 | tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL); | 1782 | tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL); |
1471 | if (tvmem == NULL) | 1783 | if (tvmem == NULL) |
1472 | return -ENOMEM; | 1784 | return err; |
1473 | 1785 | ||
1474 | xbuf = kmalloc(XBUFSIZE, GFP_KERNEL); | 1786 | xbuf = kmalloc(XBUFSIZE, GFP_KERNEL); |
1475 | if (xbuf == NULL) { | 1787 | if (xbuf == NULL) |
1476 | kfree(tvmem); | 1788 | goto err_free_tv; |
1477 | return -ENOMEM; | ||
1478 | } | ||
1479 | 1789 | ||
1480 | do_test(); | 1790 | axbuf = kmalloc(XBUFSIZE, GFP_KERNEL); |
1791 | if (axbuf == NULL) | ||
1792 | goto err_free_xbuf; | ||
1481 | 1793 | ||
1482 | kfree(xbuf); | 1794 | do_test(); |
1483 | kfree(tvmem); | ||
1484 | 1795 | ||
1485 | /* We intentionaly return -EAGAIN to prevent keeping | 1796 | /* We intentionaly return -EAGAIN to prevent keeping |
1486 | * the module. It does all its work from init() | 1797 | * the module. It does all its work from init() |
@@ -1488,7 +1799,15 @@ static int __init init(void) | |||
1488 | * => we don't need it in the memory, do we? | 1799 | * => we don't need it in the memory, do we? |
1489 | * -- mludvig | 1800 | * -- mludvig |
1490 | */ | 1801 | */ |
1491 | return -EAGAIN; | 1802 | err = -EAGAIN; |
1803 | |||
1804 | kfree(axbuf); | ||
1805 | err_free_xbuf: | ||
1806 | kfree(xbuf); | ||
1807 | err_free_tv: | ||
1808 | kfree(tvmem); | ||
1809 | |||
1810 | return err; | ||
1492 | } | 1811 | } |
1493 | 1812 | ||
1494 | /* | 1813 | /* |