aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiovanni Cabiddu <giovanni.cabiddu@intel.com>2017-04-19 09:27:18 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2017-04-21 08:30:50 -0400
commita9943a0ad19f4a23bb5c4217df0fb37feb7ac339 (patch)
tree5cfeb0799e11fc111c0c85ba89ecbd14b16ac65f
parent3ce5bc72eb88c02b23374c0e4f619ada27e47552 (diff)
crypto: testmgr - replace compression known answer test
Compression implementations might return valid outputs that do not match what specified in the test vectors. For this reason, the testmgr might report that a compression implementation failed the test even if the data produced by the compressor is correct. This implements a decompress-and-verify test for acomp compression tests rather than a known answer test. Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--crypto/testmgr.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index cd075c7d8ee1..8373c727752a 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -1458,7 +1458,7 @@ static int test_acomp(struct crypto_acomp *tfm,
1458{ 1458{
1459 const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm)); 1459 const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm));
1460 unsigned int i; 1460 unsigned int i;
1461 char *output; 1461 char *output, *decomp_out;
1462 int ret; 1462 int ret;
1463 struct scatterlist src, dst; 1463 struct scatterlist src, dst;
1464 struct acomp_req *req; 1464 struct acomp_req *req;
@@ -1468,6 +1468,12 @@ static int test_acomp(struct crypto_acomp *tfm,
1468 if (!output) 1468 if (!output)
1469 return -ENOMEM; 1469 return -ENOMEM;
1470 1470
1471 decomp_out = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1472 if (!decomp_out) {
1473 kfree(output);
1474 return -ENOMEM;
1475 }
1476
1471 for (i = 0; i < ctcount; i++) { 1477 for (i = 0; i < ctcount; i++) {
1472 unsigned int dlen = COMP_BUF_SIZE; 1478 unsigned int dlen = COMP_BUF_SIZE;
1473 int ilen = ctemplate[i].inlen; 1479 int ilen = ctemplate[i].inlen;
@@ -1506,7 +1512,23 @@ static int test_acomp(struct crypto_acomp *tfm,
1506 goto out; 1512 goto out;
1507 } 1513 }
1508 1514
1509 if (req->dlen != ctemplate[i].outlen) { 1515 ilen = req->dlen;
1516 dlen = COMP_BUF_SIZE;
1517 sg_init_one(&src, output, ilen);
1518 sg_init_one(&dst, decomp_out, dlen);
1519 init_completion(&result.completion);
1520 acomp_request_set_params(req, &src, &dst, ilen, dlen);
1521
1522 ret = wait_async_op(&result, crypto_acomp_decompress(req));
1523 if (ret) {
1524 pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
1525 i + 1, algo, -ret);
1526 kfree(input_vec);
1527 acomp_request_free(req);
1528 goto out;
1529 }
1530
1531 if (req->dlen != ctemplate[i].inlen) {
1510 pr_err("alg: acomp: Compression test %d failed for %s: output len = %d\n", 1532 pr_err("alg: acomp: Compression test %d failed for %s: output len = %d\n",
1511 i + 1, algo, req->dlen); 1533 i + 1, algo, req->dlen);
1512 ret = -EINVAL; 1534 ret = -EINVAL;
@@ -1515,7 +1537,7 @@ static int test_acomp(struct crypto_acomp *tfm,
1515 goto out; 1537 goto out;
1516 } 1538 }
1517 1539
1518 if (memcmp(output, ctemplate[i].output, req->dlen)) { 1540 if (memcmp(input_vec, decomp_out, req->dlen)) {
1519 pr_err("alg: acomp: Compression test %d failed for %s\n", 1541 pr_err("alg: acomp: Compression test %d failed for %s\n",
1520 i + 1, algo); 1542 i + 1, algo);
1521 hexdump(output, req->dlen); 1543 hexdump(output, req->dlen);
@@ -1593,6 +1615,7 @@ static int test_acomp(struct crypto_acomp *tfm,
1593 ret = 0; 1615 ret = 0;
1594 1616
1595out: 1617out:
1618 kfree(decomp_out);
1596 kfree(output); 1619 kfree(output);
1597 return ret; 1620 return ret;
1598} 1621}