Commit 3a338f20 authored by Jussi Kivilinna's avatar Jussi Kivilinna Committed by Herbert Xu

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: default avatarJussi Kivilinna <jussi.kivilinna@iki.fi>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 5714758b
...@@ -820,7 +820,7 @@ static int test_cipher(struct crypto_cipher *tfm, int enc, ...@@ -820,7 +820,7 @@ static int test_cipher(struct crypto_cipher *tfm, int enc,
static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc, static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
struct cipher_testvec *template, unsigned int tcount, struct cipher_testvec *template, unsigned int tcount,
const bool diff_dst) const bool diff_dst, const int align_offset)
{ {
const char *algo = const char *algo =
crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm)); crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
...@@ -876,10 +876,12 @@ static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc, ...@@ -876,10 +876,12 @@ static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
j++; j++;
ret = -EINVAL; ret = -EINVAL;
if (WARN_ON(template[i].ilen > PAGE_SIZE)) if (WARN_ON(align_offset + template[i].ilen >
PAGE_SIZE))
goto out; goto out;
data = xbuf[0]; data = xbuf[0];
data += align_offset;
memcpy(data, template[i].input, template[i].ilen); memcpy(data, template[i].input, template[i].ilen);
crypto_ablkcipher_clear_flags(tfm, ~0); crypto_ablkcipher_clear_flags(tfm, ~0);
...@@ -900,6 +902,7 @@ static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc, ...@@ -900,6 +902,7 @@ static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
sg_init_one(&sg[0], data, template[i].ilen); sg_init_one(&sg[0], data, template[i].ilen);
if (diff_dst) { if (diff_dst) {
data = xoutbuf[0]; data = xoutbuf[0];
data += align_offset;
sg_init_one(&sgout[0], data, template[i].ilen); sg_init_one(&sgout[0], data, template[i].ilen);
} }
...@@ -941,6 +944,9 @@ static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc, ...@@ -941,6 +944,9 @@ static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
j = 0; j = 0;
for (i = 0; i < tcount; i++) { for (i = 0; i < tcount; i++) {
/* alignment tests are only done with continuous buffers */
if (align_offset != 0)
break;
if (template[i].iv) if (template[i].iv)
memcpy(iv, template[i].iv, MAX_IVLEN); memcpy(iv, template[i].iv, MAX_IVLEN);
...@@ -1075,15 +1081,34 @@ static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc, ...@@ -1075,15 +1081,34 @@ static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
static int test_skcipher(struct crypto_ablkcipher *tfm, int enc, static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
struct cipher_testvec *template, unsigned int tcount) struct cipher_testvec *template, unsigned int tcount)
{ {
unsigned int alignmask;
int ret; int ret;
/* test 'dst == src' case */ /* test 'dst == src' case */
ret = __test_skcipher(tfm, enc, template, tcount, false); ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
if (ret) if (ret)
return ret; return ret;
/* test 'dst != src' case */ /* test 'dst != src' case */
return __test_skcipher(tfm, enc, template, tcount, true); ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
if (ret)
return ret;
/* test unaligned buffers, check with one byte offset */
ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
if (ret)
return ret;
alignmask = crypto_tfm_alg_alignmask(&tfm->base);
if (alignmask) {
/* Check if alignment mask for tfm is correctly set. */
ret = __test_skcipher(tfm, enc, template, tcount, true,
alignmask + 1);
if (ret)
return ret;
}
return 0;
} }
static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate, static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment