aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/testmgr.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/testmgr.c')
-rw-r--r--crypto/testmgr.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index a81c154e5d85..8bd185f068b6 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -820,7 +820,7 @@ out_nobuf:
820 820
821static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc, 821static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
822 struct cipher_testvec *template, unsigned int tcount, 822 struct cipher_testvec *template, unsigned int tcount,
823 const bool diff_dst) 823 const bool diff_dst, const int align_offset)
824{ 824{
825 const char *algo = 825 const char *algo =
826 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm)); 826 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
@@ -876,10 +876,12 @@ static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
876 j++; 876 j++;
877 877
878 ret = -EINVAL; 878 ret = -EINVAL;
879 if (WARN_ON(template[i].ilen > PAGE_SIZE)) 879 if (WARN_ON(align_offset + template[i].ilen >
880 PAGE_SIZE))
880 goto out; 881 goto out;
881 882
882 data = xbuf[0]; 883 data = xbuf[0];
884 data += align_offset;
883 memcpy(data, template[i].input, template[i].ilen); 885 memcpy(data, template[i].input, template[i].ilen);
884 886
885 crypto_ablkcipher_clear_flags(tfm, ~0); 887 crypto_ablkcipher_clear_flags(tfm, ~0);
@@ -900,6 +902,7 @@ static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
900 sg_init_one(&sg[0], data, template[i].ilen); 902 sg_init_one(&sg[0], data, template[i].ilen);
901 if (diff_dst) { 903 if (diff_dst) {
902 data = xoutbuf[0]; 904 data = xoutbuf[0];
905 data += align_offset;
903 sg_init_one(&sgout[0], data, template[i].ilen); 906 sg_init_one(&sgout[0], data, template[i].ilen);
904 } 907 }
905 908
@@ -941,6 +944,9 @@ static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
941 944
942 j = 0; 945 j = 0;
943 for (i = 0; i < tcount; i++) { 946 for (i = 0; i < tcount; i++) {
947 /* alignment tests are only done with continuous buffers */
948 if (align_offset != 0)
949 break;
944 950
945 if (template[i].iv) 951 if (template[i].iv)
946 memcpy(iv, template[i].iv, MAX_IVLEN); 952 memcpy(iv, template[i].iv, MAX_IVLEN);
@@ -1075,15 +1081,34 @@ out_nobuf:
1075static int test_skcipher(struct crypto_ablkcipher *tfm, int enc, 1081static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1076 struct cipher_testvec *template, unsigned int tcount) 1082 struct cipher_testvec *template, unsigned int tcount)
1077{ 1083{
1084 unsigned int alignmask;
1078 int ret; 1085 int ret;
1079 1086
1080 /* test 'dst == src' case */ 1087 /* test 'dst == src' case */
1081 ret = __test_skcipher(tfm, enc, template, tcount, false); 1088 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
1082 if (ret) 1089 if (ret)
1083 return ret; 1090 return ret;
1084 1091
1085 /* test 'dst != src' case */ 1092 /* test 'dst != src' case */
1086 return __test_skcipher(tfm, enc, template, tcount, true); 1093 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1094 if (ret)
1095 return ret;
1096
1097 /* test unaligned buffers, check with one byte offset */
1098 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1099 if (ret)
1100 return ret;
1101
1102 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1103 if (alignmask) {
1104 /* Check if alignment mask for tfm is correctly set. */
1105 ret = __test_skcipher(tfm, enc, template, tcount, true,
1106 alignmask + 1);
1107 if (ret)
1108 return ret;
1109 }
1110
1111 return 0;
1087} 1112}
1088 1113
1089static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate, 1114static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,