summaryrefslogtreecommitdiffstats
path: root/crypto/testmgr.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2015-05-27 04:03:43 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2015-05-27 23:23:19 -0400
commit8a525fcd46751f8538c240baa4d37d55896c5a29 (patch)
tree7abc6cfaf2c841e0ad79770af61ce211862b35d6 /crypto/testmgr.c
parent056c04ba8bbad4c563c05306cc8a8c66e713f280 (diff)
crypto: testmgr - Switch to new AEAD interface
This patch makes use of the new AEAD interface which uses a single SG list instead of separate lists for the AD and plain text. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/testmgr.c')
-rw-r--r--crypto/testmgr.c87
1 files changed, 48 insertions, 39 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index 277b3ac0ca1a..717d6f2d8b0f 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -427,7 +427,6 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
427 char *key; 427 char *key;
428 struct aead_request *req; 428 struct aead_request *req;
429 struct scatterlist *sg; 429 struct scatterlist *sg;
430 struct scatterlist *asg;
431 struct scatterlist *sgout; 430 struct scatterlist *sgout;
432 const char *e, *d; 431 const char *e, *d;
433 struct tcrypt_result result; 432 struct tcrypt_result result;
@@ -454,11 +453,10 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
454 goto out_nooutbuf; 453 goto out_nooutbuf;
455 454
456 /* avoid "the frame size is larger than 1024 bytes" compiler warning */ 455 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
457 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 3 : 2), GFP_KERNEL); 456 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 4 : 2), GFP_KERNEL);
458 if (!sg) 457 if (!sg)
459 goto out_nosg; 458 goto out_nosg;
460 asg = &sg[8]; 459 sgout = &sg[16];
461 sgout = &asg[8];
462 460
463 if (diff_dst) 461 if (diff_dst)
464 d = "-ddst"; 462 d = "-ddst";
@@ -537,23 +535,27 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
537 goto out; 535 goto out;
538 } 536 }
539 537
538 k = !!template[i].alen;
539 sg_init_table(sg, k + 1);
540 sg_set_buf(&sg[0], assoc, template[i].alen);
541 sg_set_buf(&sg[k], input,
542 template[i].ilen + (enc ? authsize : 0));
543 output = input;
544
540 if (diff_dst) { 545 if (diff_dst) {
546 sg_init_table(sgout, k + 1);
547 sg_set_buf(&sgout[0], assoc, template[i].alen);
548
541 output = xoutbuf[0]; 549 output = xoutbuf[0];
542 output += align_offset; 550 output += align_offset;
543 sg_init_one(&sg[0], input, template[i].ilen); 551 sg_set_buf(&sgout[k], output,
544 sg_init_one(&sgout[0], output, template[i].rlen); 552 template[i].rlen + (enc ? 0 : authsize));
545 } else {
546 sg_init_one(&sg[0], input,
547 template[i].ilen + (enc ? authsize : 0));
548 output = input;
549 } 553 }
550 554
551 sg_init_one(&asg[0], assoc, template[i].alen);
552
553 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, 555 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
554 template[i].ilen, iv); 556 template[i].ilen, iv);
555 557
556 aead_request_set_assoc(req, asg, template[i].alen); 558 aead_request_set_ad(req, template[i].alen);
557 559
558 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req); 560 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
559 561
@@ -633,9 +635,29 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
633 authsize = abs(template[i].rlen - template[i].ilen); 635 authsize = abs(template[i].rlen - template[i].ilen);
634 636
635 ret = -EINVAL; 637 ret = -EINVAL;
636 sg_init_table(sg, template[i].np); 638 sg_init_table(sg, template[i].anp + template[i].np);
637 if (diff_dst) 639 if (diff_dst)
638 sg_init_table(sgout, template[i].np); 640 sg_init_table(sgout, template[i].anp + template[i].np);
641
642 ret = -EINVAL;
643 for (k = 0, temp = 0; k < template[i].anp; k++) {
644 if (WARN_ON(offset_in_page(IDX[k]) +
645 template[i].atap[k] > PAGE_SIZE))
646 goto out;
647 sg_set_buf(&sg[k],
648 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
649 offset_in_page(IDX[k]),
650 template[i].assoc + temp,
651 template[i].atap[k]),
652 template[i].atap[k]);
653 if (diff_dst)
654 sg_set_buf(&sgout[k],
655 axbuf[IDX[k] >> PAGE_SHIFT] +
656 offset_in_page(IDX[k]),
657 template[i].atap[k]);
658 temp += template[i].atap[k];
659 }
660
639 for (k = 0, temp = 0; k < template[i].np; k++) { 661 for (k = 0, temp = 0; k < template[i].np; k++) {
640 if (WARN_ON(offset_in_page(IDX[k]) + 662 if (WARN_ON(offset_in_page(IDX[k]) +
641 template[i].tap[k] > PAGE_SIZE)) 663 template[i].tap[k] > PAGE_SIZE))
@@ -643,7 +665,8 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
643 665
644 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]); 666 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
645 memcpy(q, template[i].input + temp, template[i].tap[k]); 667 memcpy(q, template[i].input + temp, template[i].tap[k]);
646 sg_set_buf(&sg[k], q, template[i].tap[k]); 668 sg_set_buf(&sg[template[i].anp + k],
669 q, template[i].tap[k]);
647 670
648 if (diff_dst) { 671 if (diff_dst) {
649 q = xoutbuf[IDX[k] >> PAGE_SHIFT] + 672 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
@@ -651,7 +674,8 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
651 674
652 memset(q, 0, template[i].tap[k]); 675 memset(q, 0, template[i].tap[k]);
653 676
654 sg_set_buf(&sgout[k], q, template[i].tap[k]); 677 sg_set_buf(&sgout[template[i].anp + k],
678 q, template[i].tap[k]);
655 } 679 }
656 680
657 n = template[i].tap[k]; 681 n = template[i].tap[k];
@@ -671,39 +695,24 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
671 } 695 }
672 696
673 if (enc) { 697 if (enc) {
674 if (WARN_ON(sg[k - 1].offset + 698 if (WARN_ON(sg[template[i].anp + k - 1].offset +
675 sg[k - 1].length + authsize > 699 sg[template[i].anp + k - 1].length +
676 PAGE_SIZE)) { 700 authsize > PAGE_SIZE)) {
677 ret = -EINVAL; 701 ret = -EINVAL;
678 goto out; 702 goto out;
679 } 703 }
680 704
681 if (diff_dst) 705 if (diff_dst)
682 sgout[k - 1].length += authsize; 706 sgout[template[i].anp + k - 1].length +=
683 else 707 authsize;
684 sg[k - 1].length += authsize; 708 sg[template[i].anp + k - 1].length += authsize;
685 }
686
687 sg_init_table(asg, template[i].anp);
688 ret = -EINVAL;
689 for (k = 0, temp = 0; k < template[i].anp; k++) {
690 if (WARN_ON(offset_in_page(IDX[k]) +
691 template[i].atap[k] > PAGE_SIZE))
692 goto out;
693 sg_set_buf(&asg[k],
694 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
695 offset_in_page(IDX[k]),
696 template[i].assoc + temp,
697 template[i].atap[k]),
698 template[i].atap[k]);
699 temp += template[i].atap[k];
700 } 709 }
701 710
702 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, 711 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
703 template[i].ilen, 712 template[i].ilen,
704 iv); 713 iv);
705 714
706 aead_request_set_assoc(req, asg, template[i].alen); 715 aead_request_set_ad(req, template[i].alen);
707 716
708 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req); 717 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
709 718