diff options
author | Jussi Kivilinna <jussi.kivilinna@mbnet.fi> | 2012-09-21 03:26:52 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2012-09-27 01:32:16 -0400 |
commit | d8a32ac25698cd60b02bed2100379803c7f964e3 (patch) | |
tree | 35894f4f788a9f57b245a48f85ca2a4bff3ff2d2 /crypto | |
parent | 08d6af8c160b6bd9b21a3177e2b1bebc72a21041 (diff) |
crypto: testmgr - make test_aead also test 'dst != src' code paths
Currrently test_aead uses same buffer for destination and source. However
in any places, 'dst != src' take different path than 'dst == src' case.
Therefore make test_aead also run tests with destination buffer being
different than source buffer.
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/testmgr.c | 153 |
1 files changed, 105 insertions, 48 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 00f54d54fc44..941d75cd1f7c 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c | |||
@@ -358,8 +358,9 @@ out_nobuf: | |||
358 | return ret; | 358 | return ret; |
359 | } | 359 | } |
360 | 360 | ||
361 | static int test_aead(struct crypto_aead *tfm, int enc, | 361 | static int __test_aead(struct crypto_aead *tfm, int enc, |
362 | struct aead_testvec *template, unsigned int tcount) | 362 | struct aead_testvec *template, unsigned int tcount, |
363 | const bool diff_dst) | ||
363 | { | 364 | { |
364 | const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm)); | 365 | const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm)); |
365 | unsigned int i, j, k, n, temp; | 366 | unsigned int i, j, k, n, temp; |
@@ -367,15 +368,18 @@ static int test_aead(struct crypto_aead *tfm, int enc, | |||
367 | char *q; | 368 | char *q; |
368 | char *key; | 369 | char *key; |
369 | struct aead_request *req; | 370 | struct aead_request *req; |
370 | struct scatterlist sg[8]; | 371 | struct scatterlist *sg; |
371 | struct scatterlist asg[8]; | 372 | struct scatterlist *asg; |
372 | const char *e; | 373 | struct scatterlist *sgout; |
374 | const char *e, *d; | ||
373 | struct tcrypt_result result; | 375 | struct tcrypt_result result; |
374 | unsigned int authsize; | 376 | unsigned int authsize; |
375 | void *input; | 377 | void *input; |
378 | void *output; | ||
376 | void *assoc; | 379 | void *assoc; |
377 | char iv[MAX_IVLEN]; | 380 | char iv[MAX_IVLEN]; |
378 | char *xbuf[XBUFSIZE]; | 381 | char *xbuf[XBUFSIZE]; |
382 | char *xoutbuf[XBUFSIZE]; | ||
379 | char *axbuf[XBUFSIZE]; | 383 | char *axbuf[XBUFSIZE]; |
380 | 384 | ||
381 | if (testmgr_alloc_buf(xbuf)) | 385 | if (testmgr_alloc_buf(xbuf)) |
@@ -383,6 +387,21 @@ static int test_aead(struct crypto_aead *tfm, int enc, | |||
383 | if (testmgr_alloc_buf(axbuf)) | 387 | if (testmgr_alloc_buf(axbuf)) |
384 | goto out_noaxbuf; | 388 | goto out_noaxbuf; |
385 | 389 | ||
390 | if (diff_dst && testmgr_alloc_buf(xoutbuf)) | ||
391 | goto out_nooutbuf; | ||
392 | |||
393 | /* avoid "the frame size is larger than 1024 bytes" compiler warning */ | ||
394 | sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 3 : 2), GFP_KERNEL); | ||
395 | if (!sg) | ||
396 | goto out_nosg; | ||
397 | asg = &sg[8]; | ||
398 | sgout = &asg[8]; | ||
399 | |||
400 | if (diff_dst) | ||
401 | d = "-ddst"; | ||
402 | else | ||
403 | d = ""; | ||
404 | |||
386 | if (enc == ENCRYPT) | 405 | if (enc == ENCRYPT) |
387 | e = "encryption"; | 406 | e = "encryption"; |
388 | else | 407 | else |
@@ -392,8 +411,8 @@ static int test_aead(struct crypto_aead *tfm, int enc, | |||
392 | 411 | ||
393 | req = aead_request_alloc(tfm, GFP_KERNEL); | 412 | req = aead_request_alloc(tfm, GFP_KERNEL); |
394 | if (!req) { | 413 | if (!req) { |
395 | printk(KERN_ERR "alg: aead: Failed to allocate request for " | 414 | pr_err("alg: aead%s: Failed to allocate request for %s\n", |
396 | "%s\n", algo); | 415 | d, algo); |
397 | goto out; | 416 | goto out; |
398 | } | 417 | } |
399 | 418 | ||
@@ -432,9 +451,8 @@ static int test_aead(struct crypto_aead *tfm, int enc, | |||
432 | ret = crypto_aead_setkey(tfm, key, | 451 | ret = crypto_aead_setkey(tfm, key, |
433 | template[i].klen); | 452 | template[i].klen); |
434 | if (!ret == template[i].fail) { | 453 | if (!ret == template[i].fail) { |
435 | printk(KERN_ERR "alg: aead: setkey failed on " | 454 | pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n", |
436 | "test %d for %s: flags=%x\n", j, algo, | 455 | d, j, algo, crypto_aead_get_flags(tfm)); |
437 | crypto_aead_get_flags(tfm)); | ||
438 | goto out; | 456 | goto out; |
439 | } else if (ret) | 457 | } else if (ret) |
440 | continue; | 458 | continue; |
@@ -442,18 +460,26 @@ static int test_aead(struct crypto_aead *tfm, int enc, | |||
442 | authsize = abs(template[i].rlen - template[i].ilen); | 460 | authsize = abs(template[i].rlen - template[i].ilen); |
443 | ret = crypto_aead_setauthsize(tfm, authsize); | 461 | ret = crypto_aead_setauthsize(tfm, authsize); |
444 | if (ret) { | 462 | if (ret) { |
445 | printk(KERN_ERR "alg: aead: Failed to set " | 463 | pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n", |
446 | "authsize to %u on test %d for %s\n", | 464 | d, authsize, j, algo); |
447 | authsize, j, algo); | ||
448 | goto out; | 465 | goto out; |
449 | } | 466 | } |
450 | 467 | ||
451 | sg_init_one(&sg[0], input, | 468 | sg_init_one(&sg[0], input, |
452 | template[i].ilen + (enc ? authsize : 0)); | 469 | template[i].ilen + (enc ? authsize : 0)); |
453 | 470 | ||
471 | if (diff_dst) { | ||
472 | output = xoutbuf[0]; | ||
473 | sg_init_one(&sgout[0], output, | ||
474 | template[i].ilen + | ||
475 | (enc ? authsize : 0)); | ||
476 | } else { | ||
477 | output = input; | ||
478 | } | ||
479 | |||
454 | sg_init_one(&asg[0], assoc, template[i].alen); | 480 | sg_init_one(&asg[0], assoc, template[i].alen); |
455 | 481 | ||
456 | aead_request_set_crypt(req, sg, sg, | 482 | aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, |
457 | template[i].ilen, iv); | 483 | template[i].ilen, iv); |
458 | 484 | ||
459 | aead_request_set_assoc(req, asg, template[i].alen); | 485 | aead_request_set_assoc(req, asg, template[i].alen); |
@@ -466,10 +492,8 @@ static int test_aead(struct crypto_aead *tfm, int enc, | |||
466 | case 0: | 492 | case 0: |
467 | if (template[i].novrfy) { | 493 | if (template[i].novrfy) { |
468 | /* verification was supposed to fail */ | 494 | /* verification was supposed to fail */ |
469 | printk(KERN_ERR "alg: aead: %s failed " | 495 | pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n", |
470 | "on test %d for %s: ret was 0, " | 496 | d, e, j, algo); |
471 | "expected -EBADMSG\n", | ||
472 | e, j, algo); | ||
473 | /* so really, we got a bad message */ | 497 | /* so really, we got a bad message */ |
474 | ret = -EBADMSG; | 498 | ret = -EBADMSG; |
475 | goto out; | 499 | goto out; |
@@ -489,15 +513,15 @@ static int test_aead(struct crypto_aead *tfm, int enc, | |||
489 | continue; | 513 | continue; |
490 | /* fall through */ | 514 | /* fall through */ |
491 | default: | 515 | default: |
492 | printk(KERN_ERR "alg: aead: %s failed on test " | 516 | pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n", |
493 | "%d for %s: ret=%d\n", e, j, algo, -ret); | 517 | d, e, j, algo, -ret); |
494 | goto out; | 518 | goto out; |
495 | } | 519 | } |
496 | 520 | ||
497 | q = input; | 521 | q = output; |
498 | if (memcmp(q, template[i].result, template[i].rlen)) { | 522 | if (memcmp(q, template[i].result, template[i].rlen)) { |
499 | printk(KERN_ERR "alg: aead: Test %d failed on " | 523 | pr_err("alg: aead%s: Test %d failed on %s for %s\n", |
500 | "%s for %s\n", j, e, algo); | 524 | d, j, e, algo); |
501 | hexdump(q, template[i].rlen); | 525 | hexdump(q, template[i].rlen); |
502 | ret = -EINVAL; | 526 | ret = -EINVAL; |
503 | goto out; | 527 | goto out; |
@@ -522,9 +546,8 @@ static int test_aead(struct crypto_aead *tfm, int enc, | |||
522 | 546 | ||
523 | ret = crypto_aead_setkey(tfm, key, template[i].klen); | 547 | ret = crypto_aead_setkey(tfm, key, template[i].klen); |
524 | if (!ret == template[i].fail) { | 548 | if (!ret == template[i].fail) { |
525 | printk(KERN_ERR "alg: aead: setkey failed on " | 549 | pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n", |
526 | "chunk test %d for %s: flags=%x\n", j, | 550 | d, j, algo, crypto_aead_get_flags(tfm)); |
527 | algo, crypto_aead_get_flags(tfm)); | ||
528 | goto out; | 551 | goto out; |
529 | } else if (ret) | 552 | } else if (ret) |
530 | continue; | 553 | continue; |
@@ -533,6 +556,8 @@ static int test_aead(struct crypto_aead *tfm, int enc, | |||
533 | 556 | ||
534 | ret = -EINVAL; | 557 | ret = -EINVAL; |
535 | sg_init_table(sg, template[i].np); | 558 | sg_init_table(sg, template[i].np); |
559 | if (diff_dst) | ||
560 | sg_init_table(sgout, template[i].np); | ||
536 | for (k = 0, temp = 0; k < template[i].np; k++) { | 561 | for (k = 0, temp = 0; k < template[i].np; k++) { |
537 | if (WARN_ON(offset_in_page(IDX[k]) + | 562 | if (WARN_ON(offset_in_page(IDX[k]) + |
538 | template[i].tap[k] > PAGE_SIZE)) | 563 | template[i].tap[k] > PAGE_SIZE)) |
@@ -551,14 +576,26 @@ static int test_aead(struct crypto_aead *tfm, int enc, | |||
551 | q[n] = 0; | 576 | q[n] = 0; |
552 | 577 | ||
553 | sg_set_buf(&sg[k], q, template[i].tap[k]); | 578 | sg_set_buf(&sg[k], q, template[i].tap[k]); |
579 | |||
580 | if (diff_dst) { | ||
581 | q = xoutbuf[IDX[k] >> PAGE_SHIFT] + | ||
582 | offset_in_page(IDX[k]); | ||
583 | |||
584 | memset(q, 0, template[i].tap[k]); | ||
585 | if (offset_in_page(q) + n < PAGE_SIZE) | ||
586 | q[n] = 0; | ||
587 | |||
588 | sg_set_buf(&sgout[k], q, | ||
589 | template[i].tap[k]); | ||
590 | } | ||
591 | |||
554 | temp += template[i].tap[k]; | 592 | temp += template[i].tap[k]; |
555 | } | 593 | } |
556 | 594 | ||
557 | ret = crypto_aead_setauthsize(tfm, authsize); | 595 | ret = crypto_aead_setauthsize(tfm, authsize); |
558 | if (ret) { | 596 | if (ret) { |
559 | printk(KERN_ERR "alg: aead: Failed to set " | 597 | pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n", |
560 | "authsize to %u on chunk test %d for " | 598 | d, authsize, j, algo); |
561 | "%s\n", authsize, j, algo); | ||
562 | goto out; | 599 | goto out; |
563 | } | 600 | } |
564 | 601 | ||
@@ -571,6 +608,9 @@ static int test_aead(struct crypto_aead *tfm, int enc, | |||
571 | } | 608 | } |
572 | 609 | ||
573 | sg[k - 1].length += authsize; | 610 | sg[k - 1].length += authsize; |
611 | |||
612 | if (diff_dst) | ||
613 | sgout[k - 1].length += authsize; | ||
574 | } | 614 | } |
575 | 615 | ||
576 | sg_init_table(asg, template[i].anp); | 616 | sg_init_table(asg, template[i].anp); |
@@ -588,7 +628,7 @@ static int test_aead(struct crypto_aead *tfm, int enc, | |||
588 | temp += template[i].atap[k]; | 628 | temp += template[i].atap[k]; |
589 | } | 629 | } |
590 | 630 | ||
591 | aead_request_set_crypt(req, sg, sg, | 631 | aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, |
592 | template[i].ilen, | 632 | template[i].ilen, |
593 | iv); | 633 | iv); |
594 | 634 | ||
@@ -602,10 +642,8 @@ static int test_aead(struct crypto_aead *tfm, int enc, | |||
602 | case 0: | 642 | case 0: |
603 | if (template[i].novrfy) { | 643 | if (template[i].novrfy) { |
604 | /* verification was supposed to fail */ | 644 | /* verification was supposed to fail */ |
605 | printk(KERN_ERR "alg: aead: %s failed " | 645 | pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n", |
606 | "on chunk test %d for %s: ret " | 646 | d, e, j, algo); |
607 | "was 0, expected -EBADMSG\n", | ||
608 | e, j, algo); | ||
609 | /* so really, we got a bad message */ | 647 | /* so really, we got a bad message */ |
610 | ret = -EBADMSG; | 648 | ret = -EBADMSG; |
611 | goto out; | 649 | goto out; |
@@ -625,32 +663,35 @@ static int test_aead(struct crypto_aead *tfm, int enc, | |||
625 | continue; | 663 | continue; |
626 | /* fall through */ | 664 | /* fall through */ |
627 | default: | 665 | default: |
628 | printk(KERN_ERR "alg: aead: %s failed on " | 666 | pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n", |
629 | "chunk test %d for %s: ret=%d\n", e, j, | 667 | d, e, j, algo, -ret); |
630 | algo, -ret); | ||
631 | goto out; | 668 | goto out; |
632 | } | 669 | } |
633 | 670 | ||
634 | ret = -EINVAL; | 671 | ret = -EINVAL; |
635 | for (k = 0, temp = 0; k < template[i].np; k++) { | 672 | for (k = 0, temp = 0; k < template[i].np; k++) { |
636 | q = xbuf[IDX[k] >> PAGE_SHIFT] + | 673 | if (diff_dst) |
637 | offset_in_page(IDX[k]); | 674 | q = xoutbuf[IDX[k] >> PAGE_SHIFT] + |
675 | offset_in_page(IDX[k]); | ||
676 | else | ||
677 | q = xbuf[IDX[k] >> PAGE_SHIFT] + | ||
678 | offset_in_page(IDX[k]); | ||
638 | 679 | ||
639 | n = template[i].tap[k]; | 680 | n = template[i].tap[k]; |
640 | if (k == template[i].np - 1) | 681 | if (k == template[i].np - 1) |
641 | n += enc ? authsize : -authsize; | 682 | n += enc ? authsize : -authsize; |
642 | 683 | ||
643 | if (memcmp(q, template[i].result + temp, n)) { | 684 | if (memcmp(q, template[i].result + temp, n)) { |
644 | printk(KERN_ERR "alg: aead: Chunk " | 685 | pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n", |
645 | "test %d failed on %s at page " | 686 | d, j, e, k, algo); |
646 | "%u for %s\n", j, e, k, algo); | ||
647 | hexdump(q, n); | 687 | hexdump(q, n); |
648 | goto out; | 688 | goto out; |
649 | } | 689 | } |
650 | 690 | ||
651 | q += n; | 691 | q += n; |
652 | if (k == template[i].np - 1 && !enc) { | 692 | if (k == template[i].np - 1 && !enc) { |
653 | if (memcmp(q, template[i].input + | 693 | if (!diff_dst && |
694 | memcmp(q, template[i].input + | ||
654 | temp + n, authsize)) | 695 | temp + n, authsize)) |
655 | n = authsize; | 696 | n = authsize; |
656 | else | 697 | else |
@@ -661,11 +702,8 @@ static int test_aead(struct crypto_aead *tfm, int enc, | |||
661 | ; | 702 | ; |
662 | } | 703 | } |
663 | if (n) { | 704 | if (n) { |
664 | printk(KERN_ERR "alg: aead: Result " | 705 | pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n", |
665 | "buffer corruption in chunk " | 706 | d, j, e, k, algo, n); |
666 | "test %d on %s at page %u for " | ||
667 | "%s: %u bytes:\n", j, e, k, | ||
668 | algo, n); | ||
669 | hexdump(q, n); | 707 | hexdump(q, n); |
670 | goto out; | 708 | goto out; |
671 | } | 709 | } |
@@ -679,6 +717,11 @@ static int test_aead(struct crypto_aead *tfm, int enc, | |||
679 | 717 | ||
680 | out: | 718 | out: |
681 | aead_request_free(req); | 719 | aead_request_free(req); |
720 | kfree(sg); | ||
721 | out_nosg: | ||
722 | if (diff_dst) | ||
723 | testmgr_free_buf(xoutbuf); | ||
724 | out_nooutbuf: | ||
682 | testmgr_free_buf(axbuf); | 725 | testmgr_free_buf(axbuf); |
683 | out_noaxbuf: | 726 | out_noaxbuf: |
684 | testmgr_free_buf(xbuf); | 727 | testmgr_free_buf(xbuf); |
@@ -686,6 +729,20 @@ out_noxbuf: | |||
686 | return ret; | 729 | return ret; |
687 | } | 730 | } |
688 | 731 | ||
732 | static int test_aead(struct crypto_aead *tfm, int enc, | ||
733 | struct aead_testvec *template, unsigned int tcount) | ||
734 | { | ||
735 | int ret; | ||
736 | |||
737 | /* test 'dst == src' case */ | ||
738 | ret = __test_aead(tfm, enc, template, tcount, false); | ||
739 | if (ret) | ||
740 | return ret; | ||
741 | |||
742 | /* test 'dst != src' case */ | ||
743 | return __test_aead(tfm, enc, template, tcount, true); | ||
744 | } | ||
745 | |||
689 | static int test_cipher(struct crypto_cipher *tfm, int enc, | 746 | static int test_cipher(struct crypto_cipher *tfm, int enc, |
690 | struct cipher_testvec *template, unsigned int tcount) | 747 | struct cipher_testvec *template, unsigned int tcount) |
691 | { | 748 | { |