Commit 3a338f20c3c5c33c45ab1c36c8eccd62289c6401

Authored by Jussi Kivilinna
Committed by Herbert Xu
1 parent 5714758b5c

crypto: testmgr - test skciphers with unaligned buffers

This patch adds unaligned buffer tests for blkciphers.

The first new test is with one byte offset and the second test checks if
cra_alignmask for driver is big enough; for example, for testing a case
where cra_alignmask is set to 7, but driver really needs buffers to be
aligned to 16 bytes.

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Showing 1 changed file with 29 additions and 4 deletions Side-by-side Diff

... ... @@ -820,7 +820,7 @@
820 820  
821 821 static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
822 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 825 const char *algo =
826 826 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
827 827  
... ... @@ -876,10 +876,12 @@
876 876 j++;
877 877  
878 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 881 goto out;
881 882  
882 883 data = xbuf[0];
  884 + data += align_offset;
883 885 memcpy(data, template[i].input, template[i].ilen);
884 886  
885 887 crypto_ablkcipher_clear_flags(tfm, ~0);
... ... @@ -900,6 +902,7 @@
900 902 sg_init_one(&sg[0], data, template[i].ilen);
901 903 if (diff_dst) {
902 904 data = xoutbuf[0];
  905 + data += align_offset;
903 906 sg_init_one(&sgout[0], data, template[i].ilen);
904 907 }
905 908  
... ... @@ -941,6 +944,9 @@
941 944  
942 945 j = 0;
943 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 951 if (template[i].iv)
946 952 memcpy(iv, template[i].iv, MAX_IVLEN);
947 953  
948 954  
... ... @@ -1075,15 +1081,34 @@
1075 1081 static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1076 1082 struct cipher_testvec *template, unsigned int tcount)
1077 1083 {
  1084 + unsigned int alignmask;
1078 1085 int ret;
1079 1086  
1080 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 1089 if (ret)
1083 1090 return ret;
1084 1091  
1085 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  
1089 1114 static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,