aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristian Stoica <cristian.stoica@freescale.com>2014-07-28 06:11:23 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2014-08-25 08:27:17 -0400
commit05b1d3386f33ef09500db471e7a7b92ebd2f5d5f (patch)
tree6dba52dd11dd0920d29213f714f7a0b37cd42ce2
parent6d9529c586dbf0d356916d113f72f36397e71cdb (diff)
crypto: testmgr - white space fix-ups on test_aead
This patch inverts two if conditions and allows removal of one tab-stop in their code-blocks. Only white-space clean-up follows. Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--crypto/testmgr.c498
1 files changed, 242 insertions, 256 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index ac2b63105afc..68082d45573d 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -492,121 +492,116 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
492 tcrypt_complete, &result); 492 tcrypt_complete, &result);
493 493
494 for (i = 0, j = 0; i < tcount; i++) { 494 for (i = 0, j = 0; i < tcount; i++) {
495 if (!template[i].np) { 495 if (template[i].np)
496 j++; 496 continue;
497 497
498 /* some templates have no input data but they will 498 j++;
499 * touch input
500 */
501 input = xbuf[0];
502 input += align_offset;
503 assoc = axbuf[0];
504 499
505 ret = -EINVAL; 500 /* some templates have no input data but they will
506 if (WARN_ON(align_offset + template[i].ilen > 501 * touch input
507 PAGE_SIZE || template[i].alen > PAGE_SIZE)) 502 */
508 goto out; 503 input = xbuf[0];
504 input += align_offset;
505 assoc = axbuf[0];
509 506
510 memcpy(input, template[i].input, template[i].ilen); 507 ret = -EINVAL;
511 memcpy(assoc, template[i].assoc, template[i].alen); 508 if (WARN_ON(align_offset + template[i].ilen >
512 if (template[i].iv) 509 PAGE_SIZE || template[i].alen > PAGE_SIZE))
513 memcpy(iv, template[i].iv, MAX_IVLEN); 510 goto out;
514 else
515 memset(iv, 0, MAX_IVLEN);
516 511
517 crypto_aead_clear_flags(tfm, ~0); 512 memcpy(input, template[i].input, template[i].ilen);
518 if (template[i].wk) 513 memcpy(assoc, template[i].assoc, template[i].alen);
519 crypto_aead_set_flags( 514 if (template[i].iv)
520 tfm, CRYPTO_TFM_REQ_WEAK_KEY); 515 memcpy(iv, template[i].iv, MAX_IVLEN);
516 else
517 memset(iv, 0, MAX_IVLEN);
521 518
522 if (template[i].klen > MAX_KEYLEN) { 519 crypto_aead_clear_flags(tfm, ~0);
523 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n", 520 if (template[i].wk)
524 d, j, algo, template[i].klen, 521 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
525 MAX_KEYLEN);
526 ret = -EINVAL;
527 goto out;
528 }
529 memcpy(key, template[i].key, template[i].klen);
530 522
531 ret = crypto_aead_setkey(tfm, key, 523 if (template[i].klen > MAX_KEYLEN) {
532 template[i].klen); 524 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
533 if (!ret == template[i].fail) { 525 d, j, algo, template[i].klen,
534 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n", 526 MAX_KEYLEN);
535 d, j, algo, crypto_aead_get_flags(tfm)); 527 ret = -EINVAL;
536 goto out; 528 goto out;
537 } else if (ret) 529 }
538 continue; 530 memcpy(key, template[i].key, template[i].klen);
539 531
540 authsize = abs(template[i].rlen - template[i].ilen); 532 ret = crypto_aead_setkey(tfm, key, template[i].klen);
541 ret = crypto_aead_setauthsize(tfm, authsize); 533 if (!ret == template[i].fail) {
542 if (ret) { 534 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
543 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n", 535 d, j, algo, crypto_aead_get_flags(tfm));
544 d, authsize, j, algo); 536 goto out;
545 goto out; 537 } else if (ret)
546 } 538 continue;
547 539
548 if (diff_dst) { 540 authsize = abs(template[i].rlen - template[i].ilen);
549 output = xoutbuf[0]; 541 ret = crypto_aead_setauthsize(tfm, authsize);
550 output += align_offset; 542 if (ret) {
551 sg_init_one(&sg[0], input, template[i].ilen); 543 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
552 sg_init_one(&sgout[0], output, 544 d, authsize, j, algo);
553 template[i].rlen); 545 goto out;
554 } else { 546 }
555 sg_init_one(&sg[0], input,
556 template[i].ilen +
557 (enc ? authsize : 0));
558 output = input;
559 }
560 547
561 sg_init_one(&asg[0], assoc, template[i].alen); 548 if (diff_dst) {
549 output = xoutbuf[0];
550 output += align_offset;
551 sg_init_one(&sg[0], input, template[i].ilen);
552 sg_init_one(&sgout[0], output, template[i].rlen);
553 } else {
554 sg_init_one(&sg[0], input,
555 template[i].ilen + (enc ? authsize : 0));
556 output = input;
557 }
562 558
563 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, 559 sg_init_one(&asg[0], assoc, template[i].alen);
564 template[i].ilen, iv);
565 560
566 aead_request_set_assoc(req, asg, template[i].alen); 561 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
562 template[i].ilen, iv);
567 563
568 ret = enc ? 564 aead_request_set_assoc(req, asg, template[i].alen);
569 crypto_aead_encrypt(req) :
570 crypto_aead_decrypt(req);
571 565
572 switch (ret) { 566 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
573 case 0:
574 if (template[i].novrfy) {
575 /* verification was supposed to fail */
576 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
577 d, e, j, algo);
578 /* so really, we got a bad message */
579 ret = -EBADMSG;
580 goto out;
581 }
582 break;
583 case -EINPROGRESS:
584 case -EBUSY:
585 ret = wait_for_completion_interruptible(
586 &result.completion);
587 if (!ret && !(ret = result.err)) {
588 reinit_completion(&result.completion);
589 break;
590 }
591 case -EBADMSG:
592 if (template[i].novrfy)
593 /* verification failure was expected */
594 continue;
595 /* fall through */
596 default:
597 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
598 d, e, j, algo, -ret);
599 goto out;
600 }
601 567
602 q = output; 568 switch (ret) {
603 if (memcmp(q, template[i].result, template[i].rlen)) { 569 case 0:
604 pr_err("alg: aead%s: Test %d failed on %s for %s\n", 570 if (template[i].novrfy) {
605 d, j, e, algo); 571 /* verification was supposed to fail */
606 hexdump(q, template[i].rlen); 572 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
607 ret = -EINVAL; 573 d, e, j, algo);
574 /* so really, we got a bad message */
575 ret = -EBADMSG;
608 goto out; 576 goto out;
609 } 577 }
578 break;
579 case -EINPROGRESS:
580 case -EBUSY:
581 ret = wait_for_completion_interruptible(
582 &result.completion);
583 if (!ret && !(ret = result.err)) {
584 reinit_completion(&result.completion);
585 break;
586 }
587 case -EBADMSG:
588 if (template[i].novrfy)
589 /* verification failure was expected */
590 continue;
591 /* fall through */
592 default:
593 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
594 d, e, j, algo, -ret);
595 goto out;
596 }
597
598 q = output;
599 if (memcmp(q, template[i].result, template[i].rlen)) {
600 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
601 d, j, e, algo);
602 hexdump(q, template[i].rlen);
603 ret = -EINVAL;
604 goto out;
610 } 605 }
611 } 606 }
612 607
@@ -615,191 +610,182 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
615 if (align_offset != 0) 610 if (align_offset != 0)
616 break; 611 break;
617 612
618 if (template[i].np) { 613 if (!template[i].np)
619 j++; 614 continue;
620 615
621 if (template[i].iv) 616 j++;
622 memcpy(iv, template[i].iv, MAX_IVLEN);
623 else
624 memset(iv, 0, MAX_IVLEN);
625 617
626 crypto_aead_clear_flags(tfm, ~0); 618 if (template[i].iv)
627 if (template[i].wk) 619 memcpy(iv, template[i].iv, MAX_IVLEN);
628 crypto_aead_set_flags( 620 else
629 tfm, CRYPTO_TFM_REQ_WEAK_KEY); 621 memset(iv, 0, MAX_IVLEN);
630 if (template[i].klen > MAX_KEYLEN) {
631 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
632 d, j, algo, template[i].klen,
633 MAX_KEYLEN);
634 ret = -EINVAL;
635 goto out;
636 }
637 memcpy(key, template[i].key, template[i].klen);
638 622
639 ret = crypto_aead_setkey(tfm, key, template[i].klen); 623 crypto_aead_clear_flags(tfm, ~0);
640 if (!ret == template[i].fail) { 624 if (template[i].wk)
641 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n", 625 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
642 d, j, algo, crypto_aead_get_flags(tfm)); 626 if (template[i].klen > MAX_KEYLEN) {
643 goto out; 627 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
644 } else if (ret) 628 d, j, algo, template[i].klen, MAX_KEYLEN);
645 continue; 629 ret = -EINVAL;
630 goto out;
631 }
632 memcpy(key, template[i].key, template[i].klen);
646 633
647 authsize = abs(template[i].rlen - template[i].ilen); 634 ret = crypto_aead_setkey(tfm, key, template[i].klen);
635 if (!ret == template[i].fail) {
636 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
637 d, j, algo, crypto_aead_get_flags(tfm));
638 goto out;
639 } else if (ret)
640 continue;
648 641
649 ret = -EINVAL; 642 authsize = abs(template[i].rlen - template[i].ilen);
650 sg_init_table(sg, template[i].np);
651 if (diff_dst)
652 sg_init_table(sgout, template[i].np);
653 for (k = 0, temp = 0; k < template[i].np; k++) {
654 if (WARN_ON(offset_in_page(IDX[k]) +
655 template[i].tap[k] > PAGE_SIZE))
656 goto out;
657 643
658 q = xbuf[IDX[k] >> PAGE_SHIFT] + 644 ret = -EINVAL;
659 offset_in_page(IDX[k]); 645 sg_init_table(sg, template[i].np);
646 if (diff_dst)
647 sg_init_table(sgout, template[i].np);
648 for (k = 0, temp = 0; k < template[i].np; k++) {
649 if (WARN_ON(offset_in_page(IDX[k]) +
650 template[i].tap[k] > PAGE_SIZE))
651 goto out;
660 652
661 memcpy(q, template[i].input + temp, 653 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
662 template[i].tap[k]); 654 memcpy(q, template[i].input + temp, template[i].tap[k]);
655 sg_set_buf(&sg[k], q, template[i].tap[k]);
663 656
664 sg_set_buf(&sg[k], q, template[i].tap[k]); 657 if (diff_dst) {
658 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
659 offset_in_page(IDX[k]);
665 660
666 if (diff_dst) { 661 memset(q, 0, template[i].tap[k]);
667 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
668 offset_in_page(IDX[k]);
669 662
670 memset(q, 0, template[i].tap[k]); 663 sg_set_buf(&sgout[k], q, template[i].tap[k]);
664 }
671 665
672 sg_set_buf(&sgout[k], q, 666 n = template[i].tap[k];
673 template[i].tap[k]); 667 if (k == template[i].np - 1 && enc)
674 } 668 n += authsize;
669 if (offset_in_page(q) + n < PAGE_SIZE)
670 q[n] = 0;
675 671
676 n = template[i].tap[k]; 672 temp += template[i].tap[k];
677 if (k == template[i].np - 1 && enc) 673 }
678 n += authsize;
679 if (offset_in_page(q) + n < PAGE_SIZE)
680 q[n] = 0;
681 674
682 temp += template[i].tap[k]; 675 ret = crypto_aead_setauthsize(tfm, authsize);
683 } 676 if (ret) {
677 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
678 d, authsize, j, algo);
679 goto out;
680 }
684 681
685 ret = crypto_aead_setauthsize(tfm, authsize); 682 if (enc) {
686 if (ret) { 683 if (WARN_ON(sg[k - 1].offset +
687 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n", 684 sg[k - 1].length + authsize >
688 d, authsize, j, algo); 685 PAGE_SIZE)) {
686 ret = -EINVAL;
689 goto out; 687 goto out;
690 } 688 }
691 689
692 if (enc) { 690 if (diff_dst)
693 if (WARN_ON(sg[k - 1].offset + 691 sgout[k - 1].length += authsize;
694 sg[k - 1].length + authsize > 692 else
695 PAGE_SIZE)) { 693 sg[k - 1].length += authsize;
696 ret = -EINVAL; 694 }
697 goto out;
698 }
699 695
700 if (diff_dst) 696 sg_init_table(asg, template[i].anp);
701 sgout[k - 1].length += authsize; 697 ret = -EINVAL;
702 else 698 for (k = 0, temp = 0; k < template[i].anp; k++) {
703 sg[k - 1].length += authsize; 699 if (WARN_ON(offset_in_page(IDX[k]) +
700 template[i].atap[k] > PAGE_SIZE))
701 goto out;
702 sg_set_buf(&asg[k],
703 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
704 offset_in_page(IDX[k]),
705 template[i].assoc + temp,
706 template[i].atap[k]),
707 template[i].atap[k]);
708 temp += template[i].atap[k];
709 }
710
711 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
712 template[i].ilen,
713 iv);
714
715 aead_request_set_assoc(req, asg, template[i].alen);
716
717 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
718
719 switch (ret) {
720 case 0:
721 if (template[i].novrfy) {
722 /* verification was supposed to fail */
723 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
724 d, e, j, algo);
725 /* so really, we got a bad message */
726 ret = -EBADMSG;
727 goto out;
704 } 728 }
705 729 break;
706 sg_init_table(asg, template[i].anp); 730 case -EINPROGRESS:
707 ret = -EINVAL; 731 case -EBUSY:
708 for (k = 0, temp = 0; k < template[i].anp; k++) { 732 ret = wait_for_completion_interruptible(
709 if (WARN_ON(offset_in_page(IDX[k]) + 733 &result.completion);
710 template[i].atap[k] > PAGE_SIZE)) 734 if (!ret && !(ret = result.err)) {
711 goto out; 735 reinit_completion(&result.completion);
712 sg_set_buf(&asg[k], 736 break;
713 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
714 offset_in_page(IDX[k]),
715 template[i].assoc + temp,
716 template[i].atap[k]),
717 template[i].atap[k]);
718 temp += template[i].atap[k];
719 } 737 }
738 case -EBADMSG:
739 if (template[i].novrfy)
740 /* verification failure was expected */
741 continue;
742 /* fall through */
743 default:
744 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
745 d, e, j, algo, -ret);
746 goto out;
747 }
720 748
721 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, 749 ret = -EINVAL;
722 template[i].ilen, 750 for (k = 0, temp = 0; k < template[i].np; k++) {
723 iv); 751 if (diff_dst)
724 752 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
725 aead_request_set_assoc(req, asg, template[i].alen); 753 offset_in_page(IDX[k]);
754 else
755 q = xbuf[IDX[k] >> PAGE_SHIFT] +
756 offset_in_page(IDX[k]);
726 757
727 ret = enc ? 758 n = template[i].tap[k];
728 crypto_aead_encrypt(req) : 759 if (k == template[i].np - 1)
729 crypto_aead_decrypt(req); 760 n += enc ? authsize : -authsize;
730 761
731 switch (ret) { 762 if (memcmp(q, template[i].result + temp, n)) {
732 case 0: 763 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
733 if (template[i].novrfy) { 764 d, j, e, k, algo);
734 /* verification was supposed to fail */ 765 hexdump(q, n);
735 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
736 d, e, j, algo);
737 /* so really, we got a bad message */
738 ret = -EBADMSG;
739 goto out;
740 }
741 break;
742 case -EINPROGRESS:
743 case -EBUSY:
744 ret = wait_for_completion_interruptible(
745 &result.completion);
746 if (!ret && !(ret = result.err)) {
747 reinit_completion(&result.completion);
748 break;
749 }
750 case -EBADMSG:
751 if (template[i].novrfy)
752 /* verification failure was expected */
753 continue;
754 /* fall through */
755 default:
756 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
757 d, e, j, algo, -ret);
758 goto out; 766 goto out;
759 } 767 }
760 768
761 ret = -EINVAL; 769 q += n;
762 for (k = 0, temp = 0; k < template[i].np; k++) { 770 if (k == template[i].np - 1 && !enc) {
763 if (diff_dst) 771 if (!diff_dst &&
764 q = xoutbuf[IDX[k] >> PAGE_SHIFT] + 772 memcmp(q, template[i].input +
765 offset_in_page(IDX[k]); 773 temp + n, authsize))
774 n = authsize;
766 else 775 else
767 q = xbuf[IDX[k] >> PAGE_SHIFT] + 776 n = 0;
768 offset_in_page(IDX[k]); 777 } else {
769 778 for (n = 0; offset_in_page(q + n) && q[n]; n++)
770 n = template[i].tap[k]; 779 ;
771 if (k == template[i].np - 1)
772 n += enc ? authsize : -authsize;
773
774 if (memcmp(q, template[i].result + temp, n)) {
775 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
776 d, j, e, k, algo);
777 hexdump(q, n);
778 goto out;
779 }
780
781 q += n;
782 if (k == template[i].np - 1 && !enc) {
783 if (!diff_dst &&
784 memcmp(q, template[i].input +
785 temp + n, authsize))
786 n = authsize;
787 else
788 n = 0;
789 } else {
790 for (n = 0; offset_in_page(q + n) &&
791 q[n]; n++)
792 ;
793 }
794 if (n) {
795 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
796 d, j, e, k, algo, n);
797 hexdump(q, n);
798 goto out;
799 }
800
801 temp += template[i].tap[k];
802 } 780 }
781 if (n) {
782 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
783 d, j, e, k, algo, n);
784 hexdump(q, n);
785 goto out;
786 }
787
788 temp += template[i].tap[k];
803 } 789 }
804 } 790 }
805 791