aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/testmgr.c
diff options
context:
space:
mode:
authorJussi Kivilinna <jussi.kivilinna@mbnet.fi>2012-09-21 03:26:47 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2012-09-27 01:32:16 -0400
commit08d6af8c160b6bd9b21a3177e2b1bebc72a21041 (patch)
tree648d260d5961f85d6774362fd413da913a962c3e /crypto/testmgr.c
parent549595a0c782c1271cbcda51b6d07a95de1f894d (diff)
crypto: testmgr - make test_skcipher also test 'dst != src' code paths
Currrently test_skcipher uses same buffer for destination and source. However in any places, 'dst != src' take different path than 'dst == src' case. Therefore make test_skcipher 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/testmgr.c')
-rw-r--r--crypto/testmgr.c107
1 files changed, 76 insertions, 31 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index 8183777a49b6..00f54d54fc44 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -761,8 +761,9 @@ out_nobuf:
761 return ret; 761 return ret;
762} 762}
763 763
764static int test_skcipher(struct crypto_ablkcipher *tfm, int enc, 764static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
765 struct cipher_testvec *template, unsigned int tcount) 765 struct cipher_testvec *template, unsigned int tcount,
766 const bool diff_dst)
766{ 767{
767 const char *algo = 768 const char *algo =
768 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm)); 769 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
@@ -770,16 +771,26 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
770 char *q; 771 char *q;
771 struct ablkcipher_request *req; 772 struct ablkcipher_request *req;
772 struct scatterlist sg[8]; 773 struct scatterlist sg[8];
773 const char *e; 774 struct scatterlist sgout[8];
775 const char *e, *d;
774 struct tcrypt_result result; 776 struct tcrypt_result result;
775 void *data; 777 void *data;
776 char iv[MAX_IVLEN]; 778 char iv[MAX_IVLEN];
777 char *xbuf[XBUFSIZE]; 779 char *xbuf[XBUFSIZE];
780 char *xoutbuf[XBUFSIZE];
778 int ret = -ENOMEM; 781 int ret = -ENOMEM;
779 782
780 if (testmgr_alloc_buf(xbuf)) 783 if (testmgr_alloc_buf(xbuf))
781 goto out_nobuf; 784 goto out_nobuf;
782 785
786 if (diff_dst && testmgr_alloc_buf(xoutbuf))
787 goto out_nooutbuf;
788
789 if (diff_dst)
790 d = "-ddst";
791 else
792 d = "";
793
783 if (enc == ENCRYPT) 794 if (enc == ENCRYPT)
784 e = "encryption"; 795 e = "encryption";
785 else 796 else
@@ -789,8 +800,8 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
789 800
790 req = ablkcipher_request_alloc(tfm, GFP_KERNEL); 801 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
791 if (!req) { 802 if (!req) {
792 printk(KERN_ERR "alg: skcipher: Failed to allocate request " 803 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
793 "for %s\n", algo); 804 d, algo);
794 goto out; 805 goto out;
795 } 806 }
796 807
@@ -822,16 +833,21 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
822 ret = crypto_ablkcipher_setkey(tfm, template[i].key, 833 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
823 template[i].klen); 834 template[i].klen);
824 if (!ret == template[i].fail) { 835 if (!ret == template[i].fail) {
825 printk(KERN_ERR "alg: skcipher: setkey failed " 836 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, 837 d, j, algo,
827 algo, crypto_ablkcipher_get_flags(tfm)); 838 crypto_ablkcipher_get_flags(tfm));
828 goto out; 839 goto out;
829 } else if (ret) 840 } else if (ret)
830 continue; 841 continue;
831 842
832 sg_init_one(&sg[0], data, template[i].ilen); 843 sg_init_one(&sg[0], data, template[i].ilen);
844 if (diff_dst) {
845 data = xoutbuf[0];
846 sg_init_one(&sgout[0], data, template[i].ilen);
847 }
833 848
834 ablkcipher_request_set_crypt(req, sg, sg, 849 ablkcipher_request_set_crypt(req, sg,
850 (diff_dst) ? sgout : sg,
835 template[i].ilen, iv); 851 template[i].ilen, iv);
836 ret = enc ? 852 ret = enc ?
837 crypto_ablkcipher_encrypt(req) : 853 crypto_ablkcipher_encrypt(req) :
@@ -850,16 +866,15 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
850 } 866 }
851 /* fall through */ 867 /* fall through */
852 default: 868 default:
853 printk(KERN_ERR "alg: skcipher: %s failed on " 869 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, 870 d, e, j, algo, -ret);
855 -ret);
856 goto out; 871 goto out;
857 } 872 }
858 873
859 q = data; 874 q = data;
860 if (memcmp(q, template[i].result, template[i].rlen)) { 875 if (memcmp(q, template[i].result, template[i].rlen)) {
861 printk(KERN_ERR "alg: skcipher: Test %d " 876 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n",
862 "failed on %s for %s\n", j, e, algo); 877 d, j, e, algo);
863 hexdump(q, template[i].rlen); 878 hexdump(q, template[i].rlen);
864 ret = -EINVAL; 879 ret = -EINVAL;
865 goto out; 880 goto out;
@@ -886,9 +901,8 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
886 ret = crypto_ablkcipher_setkey(tfm, template[i].key, 901 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
887 template[i].klen); 902 template[i].klen);
888 if (!ret == template[i].fail) { 903 if (!ret == template[i].fail) {
889 printk(KERN_ERR "alg: skcipher: setkey failed " 904 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", 905 d, j, algo,
891 j, algo,
892 crypto_ablkcipher_get_flags(tfm)); 906 crypto_ablkcipher_get_flags(tfm));
893 goto out; 907 goto out;
894 } else if (ret) 908 } else if (ret)
@@ -897,6 +911,8 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
897 temp = 0; 911 temp = 0;
898 ret = -EINVAL; 912 ret = -EINVAL;
899 sg_init_table(sg, template[i].np); 913 sg_init_table(sg, template[i].np);
914 if (diff_dst)
915 sg_init_table(sgout, template[i].np);
900 for (k = 0; k < template[i].np; k++) { 916 for (k = 0; k < template[i].np; k++) {
901 if (WARN_ON(offset_in_page(IDX[k]) + 917 if (WARN_ON(offset_in_page(IDX[k]) +
902 template[i].tap[k] > PAGE_SIZE)) 918 template[i].tap[k] > PAGE_SIZE))
@@ -913,11 +929,24 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
913 q[template[i].tap[k]] = 0; 929 q[template[i].tap[k]] = 0;
914 930
915 sg_set_buf(&sg[k], q, template[i].tap[k]); 931 sg_set_buf(&sg[k], q, template[i].tap[k]);
932 if (diff_dst) {
933 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
934 offset_in_page(IDX[k]);
935
936 sg_set_buf(&sgout[k], q,
937 template[i].tap[k]);
938
939 memset(q, 0, template[i].tap[k]);
940 if (offset_in_page(q) +
941 template[i].tap[k] < PAGE_SIZE)
942 q[template[i].tap[k]] = 0;
943 }
916 944
917 temp += template[i].tap[k]; 945 temp += template[i].tap[k];
918 } 946 }
919 947
920 ablkcipher_request_set_crypt(req, sg, sg, 948 ablkcipher_request_set_crypt(req, sg,
949 (diff_dst) ? sgout : sg,
921 template[i].ilen, iv); 950 template[i].ilen, iv);
922 951
923 ret = enc ? 952 ret = enc ?
@@ -937,23 +966,25 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
937 } 966 }
938 /* fall through */ 967 /* fall through */
939 default: 968 default:
940 printk(KERN_ERR "alg: skcipher: %s failed on " 969 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, 970 d, e, j, algo, -ret);
942 algo, -ret);
943 goto out; 971 goto out;
944 } 972 }
945 973
946 temp = 0; 974 temp = 0;
947 ret = -EINVAL; 975 ret = -EINVAL;
948 for (k = 0; k < template[i].np; k++) { 976 for (k = 0; k < template[i].np; k++) {
949 q = xbuf[IDX[k] >> PAGE_SHIFT] + 977 if (diff_dst)
950 offset_in_page(IDX[k]); 978 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
979 offset_in_page(IDX[k]);
980 else
981 q = xbuf[IDX[k] >> PAGE_SHIFT] +
982 offset_in_page(IDX[k]);
951 983
952 if (memcmp(q, template[i].result + temp, 984 if (memcmp(q, template[i].result + temp,
953 template[i].tap[k])) { 985 template[i].tap[k])) {
954 printk(KERN_ERR "alg: skcipher: Chunk " 986 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 " 987 d, j, e, k, algo);
956 "%u for %s\n", j, e, k, algo);
957 hexdump(q, template[i].tap[k]); 988 hexdump(q, template[i].tap[k]);
958 goto out; 989 goto out;
959 } 990 }
@@ -962,11 +993,8 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
962 for (n = 0; offset_in_page(q + n) && q[n]; n++) 993 for (n = 0; offset_in_page(q + n) && q[n]; n++)
963 ; 994 ;
964 if (n) { 995 if (n) {
965 printk(KERN_ERR "alg: skcipher: " 996 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 " 997 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); 998 hexdump(q, n);
971 goto out; 999 goto out;
972 } 1000 }
@@ -979,11 +1007,28 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
979 1007
980out: 1008out:
981 ablkcipher_request_free(req); 1009 ablkcipher_request_free(req);
1010 if (diff_dst)
1011 testmgr_free_buf(xoutbuf);
1012out_nooutbuf:
982 testmgr_free_buf(xbuf); 1013 testmgr_free_buf(xbuf);
983out_nobuf: 1014out_nobuf:
984 return ret; 1015 return ret;
985} 1016}
986 1017
1018static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1019 struct cipher_testvec *template, unsigned int tcount)
1020{
1021 int ret;
1022
1023 /* test 'dst == src' case */
1024 ret = __test_skcipher(tfm, enc, template, tcount, false);
1025 if (ret)
1026 return ret;
1027
1028 /* test 'dst != src' case */
1029 return __test_skcipher(tfm, enc, template, tcount, true);
1030}
1031
987static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate, 1032static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
988 struct comp_testvec *dtemplate, int ctcount, int dtcount) 1033 struct comp_testvec *dtemplate, int ctcount, int dtcount)
989{ 1034{