Commit 58dcf548 authored by Jussi Kivilinna's avatar Jussi Kivilinna Committed by Herbert Xu

crypto: testmgr - test AEADs with unaligned buffers

This patch adds unaligned buffer tests for AEADs.

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 3a338f20
...@@ -360,7 +360,7 @@ static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, ...@@ -360,7 +360,7 @@ static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
static int __test_aead(struct crypto_aead *tfm, int enc, static int __test_aead(struct crypto_aead *tfm, int enc,
struct aead_testvec *template, unsigned int tcount, struct aead_testvec *template, unsigned int tcount,
const bool diff_dst) const bool diff_dst, const int align_offset)
{ {
const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm)); const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
unsigned int i, j, k, n, temp; unsigned int i, j, k, n, temp;
...@@ -423,15 +423,16 @@ static int __test_aead(struct crypto_aead *tfm, int enc, ...@@ -423,15 +423,16 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
if (!template[i].np) { if (!template[i].np) {
j++; j++;
/* some tepmplates have no input data but they will /* some templates have no input data but they will
* touch input * touch input
*/ */
input = xbuf[0]; input = xbuf[0];
input += align_offset;
assoc = axbuf[0]; assoc = axbuf[0];
ret = -EINVAL; ret = -EINVAL;
if (WARN_ON(template[i].ilen > PAGE_SIZE || if (WARN_ON(align_offset + template[i].ilen >
template[i].alen > PAGE_SIZE)) PAGE_SIZE || template[i].alen > PAGE_SIZE))
goto out; goto out;
memcpy(input, template[i].input, template[i].ilen); memcpy(input, template[i].input, template[i].ilen);
...@@ -470,6 +471,7 @@ static int __test_aead(struct crypto_aead *tfm, int enc, ...@@ -470,6 +471,7 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
if (diff_dst) { if (diff_dst) {
output = xoutbuf[0]; output = xoutbuf[0];
output += align_offset;
sg_init_one(&sgout[0], output, sg_init_one(&sgout[0], output,
template[i].ilen + template[i].ilen +
(enc ? authsize : 0)); (enc ? authsize : 0));
...@@ -530,6 +532,10 @@ static int __test_aead(struct crypto_aead *tfm, int enc, ...@@ -530,6 +532,10 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
} }
for (i = 0, j = 0; i < tcount; i++) { for (i = 0, j = 0; i < tcount; i++) {
/* alignment tests are only done with continuous buffers */
if (align_offset != 0)
break;
if (template[i].np) { if (template[i].np) {
j++; j++;
...@@ -732,15 +738,34 @@ static int __test_aead(struct crypto_aead *tfm, int enc, ...@@ -732,15 +738,34 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
static int test_aead(struct crypto_aead *tfm, int enc, static int test_aead(struct crypto_aead *tfm, int enc,
struct aead_testvec *template, unsigned int tcount) struct aead_testvec *template, unsigned int tcount)
{ {
unsigned int alignmask;
int ret; int ret;
/* test 'dst == src' case */ /* test 'dst == src' case */
ret = __test_aead(tfm, enc, template, tcount, false); ret = __test_aead(tfm, enc, template, tcount, false, 0);
if (ret) if (ret)
return ret; return ret;
/* test 'dst != src' case */ /* test 'dst != src' case */
return __test_aead(tfm, enc, template, tcount, true); ret = __test_aead(tfm, enc, template, tcount, true, 0);
if (ret)
return ret;
/* test unaligned buffers, check with one byte offset */
ret = __test_aead(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_aead(tfm, enc, template, tcount, true,
alignmask + 1);
if (ret)
return ret;
}
return 0;
} }
static int test_cipher(struct crypto_cipher *tfm, int enc, static int test_cipher(struct crypto_cipher *tfm, int enc,
......
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