diff options
author | Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> | 2012-10-19 15:19:19 -0400 |
---|---|---|
committer | Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> | 2012-10-19 15:19:19 -0400 |
commit | e05dacd71db0a5da7c1a44bcaab2a8a240b9c233 (patch) | |
tree | 31382cf1c7d62c03126448affb2fc86e8c4aaa8b /crypto/testmgr.c | |
parent | 3ab0b83bf6a1e834f4b884150d8012990c75d25d (diff) | |
parent | ddffeb8c4d0331609ef2581d84de4d763607bd37 (diff) |
Merge commit 'v3.7-rc1' into stable/for-linus-3.7
* commit 'v3.7-rc1': (10892 commits)
Linux 3.7-rc1
x86, boot: Explicitly include autoconf.h for hostprogs
perf: Fix UAPI fallout
ARM: config: make sure that platforms are ordered by option string
ARM: config: sort select statements alphanumerically
UAPI: (Scripted) Disintegrate include/linux/byteorder
UAPI: (Scripted) Disintegrate include/linux
UAPI: Unexport linux/blk_types.h
UAPI: Unexport part of linux/ppp-comp.h
perf: Handle new rbtree implementation
procfs: don't need a PATH_MAX allocation to hold a string representation of an int
vfs: embed struct filename inside of names_cache allocation if possible
audit: make audit_inode take struct filename
vfs: make path_openat take a struct filename pointer
vfs: turn do_path_lookup into wrapper around struct filename variant
audit: allow audit code to satisfy getname requests from its names_list
vfs: define struct filename and have getname() return it
btrfs: Fix compilation with user namespace support enabled
userns: Fix posix_acl_file_xattr_userns gid conversion
userns: Properly print bluetooth socket uids
...
Diffstat (limited to 'crypto/testmgr.c')
-rw-r--r-- | crypto/testmgr.c | 472 |
1 files changed, 392 insertions, 80 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c index a2ca7431760a..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 | { |
@@ -761,8 +818,9 @@ out_nobuf: | |||
761 | return ret; | 818 | return ret; |
762 | } | 819 | } |
763 | 820 | ||
764 | static int test_skcipher(struct crypto_ablkcipher *tfm, int enc, | 821 | static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc, |
765 | struct cipher_testvec *template, unsigned int tcount) | 822 | struct cipher_testvec *template, unsigned int tcount, |
823 | const bool diff_dst) | ||
766 | { | 824 | { |
767 | const char *algo = | 825 | const char *algo = |
768 | crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm)); | 826 | crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm)); |
@@ -770,16 +828,26 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc, | |||
770 | char *q; | 828 | char *q; |
771 | struct ablkcipher_request *req; | 829 | struct ablkcipher_request *req; |
772 | struct scatterlist sg[8]; | 830 | struct scatterlist sg[8]; |
773 | const char *e; | 831 | struct scatterlist sgout[8]; |
832 | const char *e, *d; | ||
774 | struct tcrypt_result result; | 833 | struct tcrypt_result result; |
775 | void *data; | 834 | void *data; |
776 | char iv[MAX_IVLEN]; | 835 | char iv[MAX_IVLEN]; |
777 | char *xbuf[XBUFSIZE]; | 836 | char *xbuf[XBUFSIZE]; |
837 | char *xoutbuf[XBUFSIZE]; | ||
778 | int ret = -ENOMEM; | 838 | int ret = -ENOMEM; |
779 | 839 | ||
780 | if (testmgr_alloc_buf(xbuf)) | 840 | if (testmgr_alloc_buf(xbuf)) |
781 | goto out_nobuf; | 841 | goto out_nobuf; |
782 | 842 | ||
843 | if (diff_dst && testmgr_alloc_buf(xoutbuf)) | ||
844 | goto out_nooutbuf; | ||
845 | |||
846 | if (diff_dst) | ||
847 | d = "-ddst"; | ||
848 | else | ||
849 | d = ""; | ||
850 | |||
783 | if (enc == ENCRYPT) | 851 | if (enc == ENCRYPT) |
784 | e = "encryption"; | 852 | e = "encryption"; |
785 | else | 853 | else |
@@ -789,8 +857,8 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc, | |||
789 | 857 | ||
790 | req = ablkcipher_request_alloc(tfm, GFP_KERNEL); | 858 | req = ablkcipher_request_alloc(tfm, GFP_KERNEL); |
791 | if (!req) { | 859 | if (!req) { |
792 | printk(KERN_ERR "alg: skcipher: Failed to allocate request " | 860 | pr_err("alg: skcipher%s: Failed to allocate request for %s\n", |
793 | "for %s\n", algo); | 861 | d, algo); |
794 | goto out; | 862 | goto out; |
795 | } | 863 | } |
796 | 864 | ||
@@ -804,7 +872,7 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc, | |||
804 | else | 872 | else |
805 | memset(iv, 0, MAX_IVLEN); | 873 | memset(iv, 0, MAX_IVLEN); |
806 | 874 | ||
807 | if (!(template[i].np)) { | 875 | if (!(template[i].np) || (template[i].also_non_np)) { |
808 | j++; | 876 | j++; |
809 | 877 | ||
810 | ret = -EINVAL; | 878 | ret = -EINVAL; |
@@ -822,16 +890,21 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc, | |||
822 | ret = crypto_ablkcipher_setkey(tfm, template[i].key, | 890 | ret = crypto_ablkcipher_setkey(tfm, template[i].key, |
823 | template[i].klen); | 891 | template[i].klen); |
824 | if (!ret == template[i].fail) { | 892 | if (!ret == template[i].fail) { |
825 | printk(KERN_ERR "alg: skcipher: setkey failed " | 893 | pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n", |
826 | "on test %d for %s: flags=%x\n", j, | 894 | d, j, algo, |
827 | algo, crypto_ablkcipher_get_flags(tfm)); | 895 | crypto_ablkcipher_get_flags(tfm)); |
828 | goto out; | 896 | goto out; |
829 | } else if (ret) | 897 | } else if (ret) |
830 | continue; | 898 | continue; |
831 | 899 | ||
832 | sg_init_one(&sg[0], data, template[i].ilen); | 900 | sg_init_one(&sg[0], data, template[i].ilen); |
901 | if (diff_dst) { | ||
902 | data = xoutbuf[0]; | ||
903 | sg_init_one(&sgout[0], data, template[i].ilen); | ||
904 | } | ||
833 | 905 | ||
834 | ablkcipher_request_set_crypt(req, sg, sg, | 906 | ablkcipher_request_set_crypt(req, sg, |
907 | (diff_dst) ? sgout : sg, | ||
835 | template[i].ilen, iv); | 908 | template[i].ilen, iv); |
836 | ret = enc ? | 909 | ret = enc ? |
837 | crypto_ablkcipher_encrypt(req) : | 910 | crypto_ablkcipher_encrypt(req) : |
@@ -850,16 +923,15 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc, | |||
850 | } | 923 | } |
851 | /* fall through */ | 924 | /* fall through */ |
852 | default: | 925 | default: |
853 | printk(KERN_ERR "alg: skcipher: %s failed on " | 926 | pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n", |
854 | "test %d for %s: ret=%d\n", e, j, algo, | 927 | d, e, j, algo, -ret); |
855 | -ret); | ||
856 | goto out; | 928 | goto out; |
857 | } | 929 | } |
858 | 930 | ||
859 | q = data; | 931 | q = data; |
860 | if (memcmp(q, template[i].result, template[i].rlen)) { | 932 | if (memcmp(q, template[i].result, template[i].rlen)) { |
861 | printk(KERN_ERR "alg: skcipher: Test %d " | 933 | pr_err("alg: skcipher%s: Test %d failed on %s for %s\n", |
862 | "failed on %s for %s\n", j, e, algo); | 934 | d, j, e, algo); |
863 | hexdump(q, template[i].rlen); | 935 | hexdump(q, template[i].rlen); |
864 | ret = -EINVAL; | 936 | ret = -EINVAL; |
865 | goto out; | 937 | goto out; |
@@ -886,9 +958,8 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc, | |||
886 | ret = crypto_ablkcipher_setkey(tfm, template[i].key, | 958 | ret = crypto_ablkcipher_setkey(tfm, template[i].key, |
887 | template[i].klen); | 959 | template[i].klen); |
888 | if (!ret == template[i].fail) { | 960 | if (!ret == template[i].fail) { |
889 | printk(KERN_ERR "alg: skcipher: setkey failed " | 961 | pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n", |
890 | "on chunk test %d for %s: flags=%x\n", | 962 | d, j, algo, |
891 | j, algo, | ||
892 | crypto_ablkcipher_get_flags(tfm)); | 963 | crypto_ablkcipher_get_flags(tfm)); |
893 | goto out; | 964 | goto out; |
894 | } else if (ret) | 965 | } else if (ret) |
@@ -897,6 +968,8 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc, | |||
897 | temp = 0; | 968 | temp = 0; |
898 | ret = -EINVAL; | 969 | ret = -EINVAL; |
899 | sg_init_table(sg, template[i].np); | 970 | sg_init_table(sg, template[i].np); |
971 | if (diff_dst) | ||
972 | sg_init_table(sgout, template[i].np); | ||
900 | for (k = 0; k < template[i].np; k++) { | 973 | for (k = 0; k < template[i].np; k++) { |
901 | if (WARN_ON(offset_in_page(IDX[k]) + | 974 | if (WARN_ON(offset_in_page(IDX[k]) + |
902 | template[i].tap[k] > PAGE_SIZE)) | 975 | template[i].tap[k] > PAGE_SIZE)) |
@@ -913,11 +986,24 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc, | |||
913 | q[template[i].tap[k]] = 0; | 986 | q[template[i].tap[k]] = 0; |
914 | 987 | ||
915 | sg_set_buf(&sg[k], q, template[i].tap[k]); | 988 | sg_set_buf(&sg[k], q, template[i].tap[k]); |
989 | if (diff_dst) { | ||
990 | q = xoutbuf[IDX[k] >> PAGE_SHIFT] + | ||
991 | offset_in_page(IDX[k]); | ||
992 | |||
993 | sg_set_buf(&sgout[k], q, | ||
994 | template[i].tap[k]); | ||
995 | |||
996 | memset(q, 0, template[i].tap[k]); | ||
997 | if (offset_in_page(q) + | ||
998 | template[i].tap[k] < PAGE_SIZE) | ||
999 | q[template[i].tap[k]] = 0; | ||
1000 | } | ||
916 | 1001 | ||
917 | temp += template[i].tap[k]; | 1002 | temp += template[i].tap[k]; |
918 | } | 1003 | } |
919 | 1004 | ||
920 | ablkcipher_request_set_crypt(req, sg, sg, | 1005 | ablkcipher_request_set_crypt(req, sg, |
1006 | (diff_dst) ? sgout : sg, | ||
921 | template[i].ilen, iv); | 1007 | template[i].ilen, iv); |
922 | 1008 | ||
923 | ret = enc ? | 1009 | ret = enc ? |
@@ -937,23 +1023,25 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc, | |||
937 | } | 1023 | } |
938 | /* fall through */ | 1024 | /* fall through */ |
939 | default: | 1025 | default: |
940 | printk(KERN_ERR "alg: skcipher: %s failed on " | 1026 | pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n", |
941 | "chunk test %d for %s: ret=%d\n", e, j, | 1027 | d, e, j, algo, -ret); |
942 | algo, -ret); | ||
943 | goto out; | 1028 | goto out; |
944 | } | 1029 | } |
945 | 1030 | ||
946 | temp = 0; | 1031 | temp = 0; |
947 | ret = -EINVAL; | 1032 | ret = -EINVAL; |
948 | for (k = 0; k < template[i].np; k++) { | 1033 | for (k = 0; k < template[i].np; k++) { |
949 | q = xbuf[IDX[k] >> PAGE_SHIFT] + | 1034 | if (diff_dst) |
950 | offset_in_page(IDX[k]); | 1035 | q = xoutbuf[IDX[k] >> PAGE_SHIFT] + |
1036 | offset_in_page(IDX[k]); | ||
1037 | else | ||
1038 | q = xbuf[IDX[k] >> PAGE_SHIFT] + | ||
1039 | offset_in_page(IDX[k]); | ||
951 | 1040 | ||
952 | if (memcmp(q, template[i].result + temp, | 1041 | if (memcmp(q, template[i].result + temp, |
953 | template[i].tap[k])) { | 1042 | template[i].tap[k])) { |
954 | printk(KERN_ERR "alg: skcipher: Chunk " | 1043 | pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n", |
955 | "test %d failed on %s at page " | 1044 | d, j, e, k, algo); |
956 | "%u for %s\n", j, e, k, algo); | ||
957 | hexdump(q, template[i].tap[k]); | 1045 | hexdump(q, template[i].tap[k]); |
958 | goto out; | 1046 | goto out; |
959 | } | 1047 | } |
@@ -962,11 +1050,8 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc, | |||
962 | for (n = 0; offset_in_page(q + n) && q[n]; n++) | 1050 | for (n = 0; offset_in_page(q + n) && q[n]; n++) |
963 | ; | 1051 | ; |
964 | if (n) { | 1052 | if (n) { |
965 | printk(KERN_ERR "alg: skcipher: " | 1053 | pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n", |
966 | "Result buffer corruption in " | 1054 | d, j, e, k, algo, n); |
967 | "chunk test %d on %s at page " | ||
968 | "%u for %s: %u bytes:\n", j, e, | ||
969 | k, algo, n); | ||
970 | hexdump(q, n); | 1055 | hexdump(q, n); |
971 | goto out; | 1056 | goto out; |
972 | } | 1057 | } |
@@ -979,11 +1064,28 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc, | |||
979 | 1064 | ||
980 | out: | 1065 | out: |
981 | ablkcipher_request_free(req); | 1066 | ablkcipher_request_free(req); |
1067 | if (diff_dst) | ||
1068 | testmgr_free_buf(xoutbuf); | ||
1069 | out_nooutbuf: | ||
982 | testmgr_free_buf(xbuf); | 1070 | testmgr_free_buf(xbuf); |
983 | out_nobuf: | 1071 | out_nobuf: |
984 | return ret; | 1072 | return ret; |
985 | } | 1073 | } |
986 | 1074 | ||
1075 | static int test_skcipher(struct crypto_ablkcipher *tfm, int enc, | ||
1076 | struct cipher_testvec *template, unsigned int tcount) | ||
1077 | { | ||
1078 | int ret; | ||
1079 | |||
1080 | /* test 'dst == src' case */ | ||
1081 | ret = __test_skcipher(tfm, enc, template, tcount, false); | ||
1082 | if (ret) | ||
1083 | return ret; | ||
1084 | |||
1085 | /* test 'dst != src' case */ | ||
1086 | return __test_skcipher(tfm, enc, template, tcount, true); | ||
1087 | } | ||
1088 | |||
987 | static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate, | 1089 | static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate, |
988 | struct comp_testvec *dtemplate, int ctcount, int dtcount) | 1090 | struct comp_testvec *dtemplate, int ctcount, int dtcount) |
989 | { | 1091 | { |
@@ -1534,6 +1636,36 @@ static int alg_test_null(const struct alg_test_desc *desc, | |||
1534 | /* Please keep this list sorted by algorithm name. */ | 1636 | /* Please keep this list sorted by algorithm name. */ |
1535 | static const struct alg_test_desc alg_test_descs[] = { | 1637 | static const struct alg_test_desc alg_test_descs[] = { |
1536 | { | 1638 | { |
1639 | .alg = "__cbc-cast5-avx", | ||
1640 | .test = alg_test_null, | ||
1641 | .suite = { | ||
1642 | .cipher = { | ||
1643 | .enc = { | ||
1644 | .vecs = NULL, | ||
1645 | .count = 0 | ||
1646 | }, | ||
1647 | .dec = { | ||
1648 | .vecs = NULL, | ||
1649 | .count = 0 | ||
1650 | } | ||
1651 | } | ||
1652 | } | ||
1653 | }, { | ||
1654 | .alg = "__cbc-cast6-avx", | ||
1655 | .test = alg_test_null, | ||
1656 | .suite = { | ||
1657 | .cipher = { | ||
1658 | .enc = { | ||
1659 | .vecs = NULL, | ||
1660 | .count = 0 | ||
1661 | }, | ||
1662 | .dec = { | ||
1663 | .vecs = NULL, | ||
1664 | .count = 0 | ||
1665 | } | ||
1666 | } | ||
1667 | } | ||
1668 | }, { | ||
1537 | .alg = "__cbc-serpent-avx", | 1669 | .alg = "__cbc-serpent-avx", |
1538 | .test = alg_test_null, | 1670 | .test = alg_test_null, |
1539 | .suite = { | 1671 | .suite = { |
@@ -1595,6 +1727,36 @@ static const struct alg_test_desc alg_test_descs[] = { | |||
1595 | } | 1727 | } |
1596 | } | 1728 | } |
1597 | }, { | 1729 | }, { |
1730 | .alg = "__driver-cbc-cast5-avx", | ||
1731 | .test = alg_test_null, | ||
1732 | .suite = { | ||
1733 | .cipher = { | ||
1734 | .enc = { | ||
1735 | .vecs = NULL, | ||
1736 | .count = 0 | ||
1737 | }, | ||
1738 | .dec = { | ||
1739 | .vecs = NULL, | ||
1740 | .count = 0 | ||
1741 | } | ||
1742 | } | ||
1743 | } | ||
1744 | }, { | ||
1745 | .alg = "__driver-cbc-cast6-avx", | ||
1746 | .test = alg_test_null, | ||
1747 | .suite = { | ||
1748 | .cipher = { | ||
1749 | .enc = { | ||
1750 | .vecs = NULL, | ||
1751 | .count = 0 | ||
1752 | }, | ||
1753 | .dec = { | ||
1754 | .vecs = NULL, | ||
1755 | .count = 0 | ||
1756 | } | ||
1757 | } | ||
1758 | } | ||
1759 | }, { | ||
1598 | .alg = "__driver-cbc-serpent-avx", | 1760 | .alg = "__driver-cbc-serpent-avx", |
1599 | .test = alg_test_null, | 1761 | .test = alg_test_null, |
1600 | .suite = { | 1762 | .suite = { |
@@ -1656,6 +1818,36 @@ static const struct alg_test_desc alg_test_descs[] = { | |||
1656 | } | 1818 | } |
1657 | } | 1819 | } |
1658 | }, { | 1820 | }, { |
1821 | .alg = "__driver-ecb-cast5-avx", | ||
1822 | .test = alg_test_null, | ||
1823 | .suite = { | ||
1824 | .cipher = { | ||
1825 | .enc = { | ||
1826 | .vecs = NULL, | ||
1827 | .count = 0 | ||
1828 | }, | ||
1829 | .dec = { | ||
1830 | .vecs = NULL, | ||
1831 | .count = 0 | ||
1832 | } | ||
1833 | } | ||
1834 | } | ||
1835 | }, { | ||
1836 | .alg = "__driver-ecb-cast6-avx", | ||
1837 | .test = alg_test_null, | ||
1838 | .suite = { | ||
1839 | .cipher = { | ||
1840 | .enc = { | ||
1841 | .vecs = NULL, | ||
1842 | .count = 0 | ||
1843 | }, | ||
1844 | .dec = { | ||
1845 | .vecs = NULL, | ||
1846 | .count = 0 | ||
1847 | } | ||
1848 | } | ||
1849 | } | ||
1850 | }, { | ||
1659 | .alg = "__driver-ecb-serpent-avx", | 1851 | .alg = "__driver-ecb-serpent-avx", |
1660 | .test = alg_test_null, | 1852 | .test = alg_test_null, |
1661 | .suite = { | 1853 | .suite = { |
@@ -1818,6 +2010,36 @@ static const struct alg_test_desc alg_test_descs[] = { | |||
1818 | } | 2010 | } |
1819 | } | 2011 | } |
1820 | }, { | 2012 | }, { |
2013 | .alg = "cbc(cast5)", | ||
2014 | .test = alg_test_skcipher, | ||
2015 | .suite = { | ||
2016 | .cipher = { | ||
2017 | .enc = { | ||
2018 | .vecs = cast5_cbc_enc_tv_template, | ||
2019 | .count = CAST5_CBC_ENC_TEST_VECTORS | ||
2020 | }, | ||
2021 | .dec = { | ||
2022 | .vecs = cast5_cbc_dec_tv_template, | ||
2023 | .count = CAST5_CBC_DEC_TEST_VECTORS | ||
2024 | } | ||
2025 | } | ||
2026 | } | ||
2027 | }, { | ||
2028 | .alg = "cbc(cast6)", | ||
2029 | .test = alg_test_skcipher, | ||
2030 | .suite = { | ||
2031 | .cipher = { | ||
2032 | .enc = { | ||
2033 | .vecs = cast6_cbc_enc_tv_template, | ||
2034 | .count = CAST6_CBC_ENC_TEST_VECTORS | ||
2035 | }, | ||
2036 | .dec = { | ||
2037 | .vecs = cast6_cbc_dec_tv_template, | ||
2038 | .count = CAST6_CBC_DEC_TEST_VECTORS | ||
2039 | } | ||
2040 | } | ||
2041 | } | ||
2042 | }, { | ||
1821 | .alg = "cbc(des)", | 2043 | .alg = "cbc(des)", |
1822 | .test = alg_test_skcipher, | 2044 | .test = alg_test_skcipher, |
1823 | .suite = { | 2045 | .suite = { |
@@ -1937,6 +2159,36 @@ static const struct alg_test_desc alg_test_descs[] = { | |||
1937 | } | 2159 | } |
1938 | } | 2160 | } |
1939 | }, { | 2161 | }, { |
2162 | .alg = "cryptd(__driver-ecb-cast5-avx)", | ||
2163 | .test = alg_test_null, | ||
2164 | .suite = { | ||
2165 | .cipher = { | ||
2166 | .enc = { | ||
2167 | .vecs = NULL, | ||
2168 | .count = 0 | ||
2169 | }, | ||
2170 | .dec = { | ||
2171 | .vecs = NULL, | ||
2172 | .count = 0 | ||
2173 | } | ||
2174 | } | ||
2175 | } | ||
2176 | }, { | ||
2177 | .alg = "cryptd(__driver-ecb-cast6-avx)", | ||
2178 | .test = alg_test_null, | ||
2179 | .suite = { | ||
2180 | .cipher = { | ||
2181 | .enc = { | ||
2182 | .vecs = NULL, | ||
2183 | .count = 0 | ||
2184 | }, | ||
2185 | .dec = { | ||
2186 | .vecs = NULL, | ||
2187 | .count = 0 | ||
2188 | } | ||
2189 | } | ||
2190 | } | ||
2191 | }, { | ||
1940 | .alg = "cryptd(__driver-ecb-serpent-avx)", | 2192 | .alg = "cryptd(__driver-ecb-serpent-avx)", |
1941 | .test = alg_test_null, | 2193 | .test = alg_test_null, |
1942 | .suite = { | 2194 | .suite = { |
@@ -2054,6 +2306,36 @@ static const struct alg_test_desc alg_test_descs[] = { | |||
2054 | } | 2306 | } |
2055 | } | 2307 | } |
2056 | }, { | 2308 | }, { |
2309 | .alg = "ctr(cast5)", | ||
2310 | .test = alg_test_skcipher, | ||
2311 | .suite = { | ||
2312 | .cipher = { | ||
2313 | .enc = { | ||
2314 | .vecs = cast5_ctr_enc_tv_template, | ||
2315 | .count = CAST5_CTR_ENC_TEST_VECTORS | ||
2316 | }, | ||
2317 | .dec = { | ||
2318 | .vecs = cast5_ctr_dec_tv_template, | ||
2319 | .count = CAST5_CTR_DEC_TEST_VECTORS | ||
2320 | } | ||
2321 | } | ||
2322 | } | ||
2323 | }, { | ||
2324 | .alg = "ctr(cast6)", | ||
2325 | .test = alg_test_skcipher, | ||
2326 | .suite = { | ||
2327 | .cipher = { | ||
2328 | .enc = { | ||
2329 | .vecs = cast6_ctr_enc_tv_template, | ||
2330 | .count = CAST6_CTR_ENC_TEST_VECTORS | ||
2331 | }, | ||
2332 | .dec = { | ||
2333 | .vecs = cast6_ctr_dec_tv_template, | ||
2334 | .count = CAST6_CTR_DEC_TEST_VECTORS | ||
2335 | } | ||
2336 | } | ||
2337 | } | ||
2338 | }, { | ||
2057 | .alg = "ctr(serpent)", | 2339 | .alg = "ctr(serpent)", |
2058 | .test = alg_test_skcipher, | 2340 | .test = alg_test_skcipher, |
2059 | .suite = { | 2341 | .suite = { |
@@ -2530,6 +2812,21 @@ static const struct alg_test_desc alg_test_descs[] = { | |||
2530 | } | 2812 | } |
2531 | } | 2813 | } |
2532 | }, { | 2814 | }, { |
2815 | .alg = "lrw(cast6)", | ||
2816 | .test = alg_test_skcipher, | ||
2817 | .suite = { | ||
2818 | .cipher = { | ||
2819 | .enc = { | ||
2820 | .vecs = cast6_lrw_enc_tv_template, | ||
2821 | .count = CAST6_LRW_ENC_TEST_VECTORS | ||
2822 | }, | ||
2823 | .dec = { | ||
2824 | .vecs = cast6_lrw_dec_tv_template, | ||
2825 | .count = CAST6_LRW_DEC_TEST_VECTORS | ||
2826 | } | ||
2827 | } | ||
2828 | } | ||
2829 | }, { | ||
2533 | .alg = "lrw(serpent)", | 2830 | .alg = "lrw(serpent)", |
2534 | .test = alg_test_skcipher, | 2831 | .test = alg_test_skcipher, |
2535 | .suite = { | 2832 | .suite = { |
@@ -2882,6 +3179,21 @@ static const struct alg_test_desc alg_test_descs[] = { | |||
2882 | } | 3179 | } |
2883 | } | 3180 | } |
2884 | }, { | 3181 | }, { |
3182 | .alg = "xts(cast6)", | ||
3183 | .test = alg_test_skcipher, | ||
3184 | .suite = { | ||
3185 | .cipher = { | ||
3186 | .enc = { | ||
3187 | .vecs = cast6_xts_enc_tv_template, | ||
3188 | .count = CAST6_XTS_ENC_TEST_VECTORS | ||
3189 | }, | ||
3190 | .dec = { | ||
3191 | .vecs = cast6_xts_dec_tv_template, | ||
3192 | .count = CAST6_XTS_DEC_TEST_VECTORS | ||
3193 | } | ||
3194 | } | ||
3195 | } | ||
3196 | }, { | ||
2885 | .alg = "xts(serpent)", | 3197 | .alg = "xts(serpent)", |
2886 | .test = alg_test_skcipher, | 3198 | .test = alg_test_skcipher, |
2887 | .suite = { | 3199 | .suite = { |