mirror of
https://github.com/team-infusion-developers/android_kernel_samsung_msm8976.git
synced 2024-09-21 03:43:03 +00:00
crypto: testmgr - make test_aead also test 'dst != src' code paths
Currrently test_aead uses same buffer for destination and source. However in any places, 'dst != src' take different path than 'dst == src' case. Therefore make test_aead 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>
This commit is contained in:
parent
08d6af8c16
commit
d8a32ac256
149
crypto/testmgr.c
149
crypto/testmgr.c
|
@ -358,8 +358,9 @@ out_nobuf:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 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;
|
||||||
|
@ -367,15 +368,18 @@ static int test_aead(struct crypto_aead *tfm, int enc,
|
||||||
char *q;
|
char *q;
|
||||||
char *key;
|
char *key;
|
||||||
struct aead_request *req;
|
struct aead_request *req;
|
||||||
struct scatterlist sg[8];
|
struct scatterlist *sg;
|
||||||
struct scatterlist asg[8];
|
struct scatterlist *asg;
|
||||||
const char *e;
|
struct scatterlist *sgout;
|
||||||
|
const char *e, *d;
|
||||||
struct tcrypt_result result;
|
struct tcrypt_result result;
|
||||||
unsigned int authsize;
|
unsigned int authsize;
|
||||||
void *input;
|
void *input;
|
||||||
|
void *output;
|
||||||
void *assoc;
|
void *assoc;
|
||||||
char iv[MAX_IVLEN];
|
char iv[MAX_IVLEN];
|
||||||
char *xbuf[XBUFSIZE];
|
char *xbuf[XBUFSIZE];
|
||||||
|
char *xoutbuf[XBUFSIZE];
|
||||||
char *axbuf[XBUFSIZE];
|
char *axbuf[XBUFSIZE];
|
||||||
|
|
||||||
if (testmgr_alloc_buf(xbuf))
|
if (testmgr_alloc_buf(xbuf))
|
||||||
|
@ -383,6 +387,21 @@ static int test_aead(struct crypto_aead *tfm, int enc,
|
||||||
if (testmgr_alloc_buf(axbuf))
|
if (testmgr_alloc_buf(axbuf))
|
||||||
goto out_noaxbuf;
|
goto out_noaxbuf;
|
||||||
|
|
||||||
|
if (diff_dst && testmgr_alloc_buf(xoutbuf))
|
||||||
|
goto out_nooutbuf;
|
||||||
|
|
||||||
|
/* avoid "the frame size is larger than 1024 bytes" compiler warning */
|
||||||
|
sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 3 : 2), GFP_KERNEL);
|
||||||
|
if (!sg)
|
||||||
|
goto out_nosg;
|
||||||
|
asg = &sg[8];
|
||||||
|
sgout = &asg[8];
|
||||||
|
|
||||||
|
if (diff_dst)
|
||||||
|
d = "-ddst";
|
||||||
|
else
|
||||||
|
d = "";
|
||||||
|
|
||||||
if (enc == ENCRYPT)
|
if (enc == ENCRYPT)
|
||||||
e = "encryption";
|
e = "encryption";
|
||||||
else
|
else
|
||||||
|
@ -392,8 +411,8 @@ static int test_aead(struct crypto_aead *tfm, int enc,
|
||||||
|
|
||||||
req = aead_request_alloc(tfm, GFP_KERNEL);
|
req = aead_request_alloc(tfm, GFP_KERNEL);
|
||||||
if (!req) {
|
if (!req) {
|
||||||
printk(KERN_ERR "alg: aead: Failed to allocate request for "
|
pr_err("alg: aead%s: Failed to allocate request for %s\n",
|
||||||
"%s\n", algo);
|
d, algo);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -432,9 +451,8 @@ static int test_aead(struct crypto_aead *tfm, int enc,
|
||||||
ret = crypto_aead_setkey(tfm, key,
|
ret = crypto_aead_setkey(tfm, key,
|
||||||
template[i].klen);
|
template[i].klen);
|
||||||
if (!ret == template[i].fail) {
|
if (!ret == template[i].fail) {
|
||||||
printk(KERN_ERR "alg: aead: setkey failed on "
|
pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
|
||||||
"test %d for %s: flags=%x\n", j, algo,
|
d, j, algo, crypto_aead_get_flags(tfm));
|
||||||
crypto_aead_get_flags(tfm));
|
|
||||||
goto out;
|
goto out;
|
||||||
} else if (ret)
|
} else if (ret)
|
||||||
continue;
|
continue;
|
||||||
|
@ -442,18 +460,26 @@ static int test_aead(struct crypto_aead *tfm, int enc,
|
||||||
authsize = abs(template[i].rlen - template[i].ilen);
|
authsize = abs(template[i].rlen - template[i].ilen);
|
||||||
ret = crypto_aead_setauthsize(tfm, authsize);
|
ret = crypto_aead_setauthsize(tfm, authsize);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printk(KERN_ERR "alg: aead: Failed to set "
|
pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
|
||||||
"authsize to %u on test %d for %s\n",
|
d, authsize, j, algo);
|
||||||
authsize, j, algo);
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
sg_init_one(&sg[0], input,
|
sg_init_one(&sg[0], input,
|
||||||
template[i].ilen + (enc ? authsize : 0));
|
template[i].ilen + (enc ? authsize : 0));
|
||||||
|
|
||||||
|
if (diff_dst) {
|
||||||
|
output = xoutbuf[0];
|
||||||
|
sg_init_one(&sgout[0], output,
|
||||||
|
template[i].ilen +
|
||||||
|
(enc ? authsize : 0));
|
||||||
|
} else {
|
||||||
|
output = input;
|
||||||
|
}
|
||||||
|
|
||||||
sg_init_one(&asg[0], assoc, template[i].alen);
|
sg_init_one(&asg[0], assoc, template[i].alen);
|
||||||
|
|
||||||
aead_request_set_crypt(req, sg, sg,
|
aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
|
||||||
template[i].ilen, iv);
|
template[i].ilen, iv);
|
||||||
|
|
||||||
aead_request_set_assoc(req, asg, template[i].alen);
|
aead_request_set_assoc(req, asg, template[i].alen);
|
||||||
|
@ -466,10 +492,8 @@ static int test_aead(struct crypto_aead *tfm, int enc,
|
||||||
case 0:
|
case 0:
|
||||||
if (template[i].novrfy) {
|
if (template[i].novrfy) {
|
||||||
/* verification was supposed to fail */
|
/* verification was supposed to fail */
|
||||||
printk(KERN_ERR "alg: aead: %s failed "
|
pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
|
||||||
"on test %d for %s: ret was 0, "
|
d, e, j, algo);
|
||||||
"expected -EBADMSG\n",
|
|
||||||
e, j, algo);
|
|
||||||
/* so really, we got a bad message */
|
/* so really, we got a bad message */
|
||||||
ret = -EBADMSG;
|
ret = -EBADMSG;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -489,15 +513,15 @@ static int test_aead(struct crypto_aead *tfm, int enc,
|
||||||
continue;
|
continue;
|
||||||
/* fall through */
|
/* fall through */
|
||||||
default:
|
default:
|
||||||
printk(KERN_ERR "alg: aead: %s failed on test "
|
pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
|
||||||
"%d for %s: ret=%d\n", e, j, algo, -ret);
|
d, e, j, algo, -ret);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
q = input;
|
q = output;
|
||||||
if (memcmp(q, template[i].result, template[i].rlen)) {
|
if (memcmp(q, template[i].result, template[i].rlen)) {
|
||||||
printk(KERN_ERR "alg: aead: Test %d failed on "
|
pr_err("alg: aead%s: Test %d failed on %s for %s\n",
|
||||||
"%s for %s\n", j, e, algo);
|
d, j, e, algo);
|
||||||
hexdump(q, template[i].rlen);
|
hexdump(q, template[i].rlen);
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -522,9 +546,8 @@ static int test_aead(struct crypto_aead *tfm, int enc,
|
||||||
|
|
||||||
ret = crypto_aead_setkey(tfm, key, template[i].klen);
|
ret = crypto_aead_setkey(tfm, key, template[i].klen);
|
||||||
if (!ret == template[i].fail) {
|
if (!ret == template[i].fail) {
|
||||||
printk(KERN_ERR "alg: aead: setkey failed on "
|
pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
|
||||||
"chunk test %d for %s: flags=%x\n", j,
|
d, j, algo, crypto_aead_get_flags(tfm));
|
||||||
algo, crypto_aead_get_flags(tfm));
|
|
||||||
goto out;
|
goto out;
|
||||||
} else if (ret)
|
} else if (ret)
|
||||||
continue;
|
continue;
|
||||||
|
@ -533,6 +556,8 @@ static int test_aead(struct crypto_aead *tfm, int enc,
|
||||||
|
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
sg_init_table(sg, template[i].np);
|
sg_init_table(sg, template[i].np);
|
||||||
|
if (diff_dst)
|
||||||
|
sg_init_table(sgout, template[i].np);
|
||||||
for (k = 0, temp = 0; k < template[i].np; k++) {
|
for (k = 0, temp = 0; k < template[i].np; k++) {
|
||||||
if (WARN_ON(offset_in_page(IDX[k]) +
|
if (WARN_ON(offset_in_page(IDX[k]) +
|
||||||
template[i].tap[k] > PAGE_SIZE))
|
template[i].tap[k] > PAGE_SIZE))
|
||||||
|
@ -551,14 +576,26 @@ static int test_aead(struct crypto_aead *tfm, int enc,
|
||||||
q[n] = 0;
|
q[n] = 0;
|
||||||
|
|
||||||
sg_set_buf(&sg[k], q, template[i].tap[k]);
|
sg_set_buf(&sg[k], q, template[i].tap[k]);
|
||||||
|
|
||||||
|
if (diff_dst) {
|
||||||
|
q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
|
||||||
|
offset_in_page(IDX[k]);
|
||||||
|
|
||||||
|
memset(q, 0, template[i].tap[k]);
|
||||||
|
if (offset_in_page(q) + n < PAGE_SIZE)
|
||||||
|
q[n] = 0;
|
||||||
|
|
||||||
|
sg_set_buf(&sgout[k], q,
|
||||||
|
template[i].tap[k]);
|
||||||
|
}
|
||||||
|
|
||||||
temp += template[i].tap[k];
|
temp += template[i].tap[k];
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = crypto_aead_setauthsize(tfm, authsize);
|
ret = crypto_aead_setauthsize(tfm, authsize);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printk(KERN_ERR "alg: aead: Failed to set "
|
pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
|
||||||
"authsize to %u on chunk test %d for "
|
d, authsize, j, algo);
|
||||||
"%s\n", authsize, j, algo);
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -571,6 +608,9 @@ static int test_aead(struct crypto_aead *tfm, int enc,
|
||||||
}
|
}
|
||||||
|
|
||||||
sg[k - 1].length += authsize;
|
sg[k - 1].length += authsize;
|
||||||
|
|
||||||
|
if (diff_dst)
|
||||||
|
sgout[k - 1].length += authsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
sg_init_table(asg, template[i].anp);
|
sg_init_table(asg, template[i].anp);
|
||||||
|
@ -588,7 +628,7 @@ static int test_aead(struct crypto_aead *tfm, int enc,
|
||||||
temp += template[i].atap[k];
|
temp += template[i].atap[k];
|
||||||
}
|
}
|
||||||
|
|
||||||
aead_request_set_crypt(req, sg, sg,
|
aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
|
||||||
template[i].ilen,
|
template[i].ilen,
|
||||||
iv);
|
iv);
|
||||||
|
|
||||||
|
@ -602,10 +642,8 @@ static int test_aead(struct crypto_aead *tfm, int enc,
|
||||||
case 0:
|
case 0:
|
||||||
if (template[i].novrfy) {
|
if (template[i].novrfy) {
|
||||||
/* verification was supposed to fail */
|
/* verification was supposed to fail */
|
||||||
printk(KERN_ERR "alg: aead: %s failed "
|
pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
|
||||||
"on chunk test %d for %s: ret "
|
d, e, j, algo);
|
||||||
"was 0, expected -EBADMSG\n",
|
|
||||||
e, j, algo);
|
|
||||||
/* so really, we got a bad message */
|
/* so really, we got a bad message */
|
||||||
ret = -EBADMSG;
|
ret = -EBADMSG;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -625,14 +663,17 @@ static int test_aead(struct crypto_aead *tfm, int enc,
|
||||||
continue;
|
continue;
|
||||||
/* fall through */
|
/* fall through */
|
||||||
default:
|
default:
|
||||||
printk(KERN_ERR "alg: aead: %s failed on "
|
pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
|
||||||
"chunk test %d for %s: ret=%d\n", e, j,
|
d, e, j, algo, -ret);
|
||||||
algo, -ret);
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
for (k = 0, temp = 0; k < template[i].np; k++) {
|
for (k = 0, temp = 0; k < template[i].np; k++) {
|
||||||
|
if (diff_dst)
|
||||||
|
q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
|
||||||
|
offset_in_page(IDX[k]);
|
||||||
|
else
|
||||||
q = xbuf[IDX[k] >> PAGE_SHIFT] +
|
q = xbuf[IDX[k] >> PAGE_SHIFT] +
|
||||||
offset_in_page(IDX[k]);
|
offset_in_page(IDX[k]);
|
||||||
|
|
||||||
|
@ -641,16 +682,16 @@ static int test_aead(struct crypto_aead *tfm, int enc,
|
||||||
n += enc ? authsize : -authsize;
|
n += enc ? authsize : -authsize;
|
||||||
|
|
||||||
if (memcmp(q, template[i].result + temp, n)) {
|
if (memcmp(q, template[i].result + temp, n)) {
|
||||||
printk(KERN_ERR "alg: aead: Chunk "
|
pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
|
||||||
"test %d failed on %s at page "
|
d, j, e, k, algo);
|
||||||
"%u for %s\n", j, e, k, algo);
|
|
||||||
hexdump(q, n);
|
hexdump(q, n);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
q += n;
|
q += n;
|
||||||
if (k == template[i].np - 1 && !enc) {
|
if (k == template[i].np - 1 && !enc) {
|
||||||
if (memcmp(q, template[i].input +
|
if (!diff_dst &&
|
||||||
|
memcmp(q, template[i].input +
|
||||||
temp + n, authsize))
|
temp + n, authsize))
|
||||||
n = authsize;
|
n = authsize;
|
||||||
else
|
else
|
||||||
|
@ -661,11 +702,8 @@ static int test_aead(struct crypto_aead *tfm, int enc,
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
if (n) {
|
if (n) {
|
||||||
printk(KERN_ERR "alg: aead: Result "
|
pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
|
||||||
"buffer corruption in chunk "
|
d, j, e, k, algo, n);
|
||||||
"test %d on %s at page %u for "
|
|
||||||
"%s: %u bytes:\n", j, e, k,
|
|
||||||
algo, n);
|
|
||||||
hexdump(q, n);
|
hexdump(q, n);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -679,6 +717,11 @@ static int test_aead(struct crypto_aead *tfm, int enc,
|
||||||
|
|
||||||
out:
|
out:
|
||||||
aead_request_free(req);
|
aead_request_free(req);
|
||||||
|
kfree(sg);
|
||||||
|
out_nosg:
|
||||||
|
if (diff_dst)
|
||||||
|
testmgr_free_buf(xoutbuf);
|
||||||
|
out_nooutbuf:
|
||||||
testmgr_free_buf(axbuf);
|
testmgr_free_buf(axbuf);
|
||||||
out_noaxbuf:
|
out_noaxbuf:
|
||||||
testmgr_free_buf(xbuf);
|
testmgr_free_buf(xbuf);
|
||||||
|
@ -686,6 +729,20 @@ out_noxbuf:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int test_aead(struct crypto_aead *tfm, int enc,
|
||||||
|
struct aead_testvec *template, unsigned int tcount)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* test 'dst == src' case */
|
||||||
|
ret = __test_aead(tfm, enc, template, tcount, false);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
/* test 'dst != src' case */
|
||||||
|
return __test_aead(tfm, enc, template, tcount, true);
|
||||||
|
}
|
||||||
|
|
||||||
static int test_cipher(struct crypto_cipher *tfm, int enc,
|
static int test_cipher(struct crypto_cipher *tfm, int enc,
|
||||||
struct cipher_testvec *template, unsigned int tcount)
|
struct cipher_testvec *template, unsigned int tcount)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue