Skip to content

Commit d7db7a8

Browse files
gcabidduherbertx
authored andcommitted
crypto: acomp - update testmgr with support for acomp
Add tests to the test manager for algorithms exposed through acomp. Signed-off-by: Giovanni Cabiddu <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent f6ded09 commit d7db7a8

File tree

1 file changed

+145
-13
lines changed

1 file changed

+145
-13
lines changed

crypto/testmgr.c

Lines changed: 145 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <crypto/drbg.h>
3434
#include <crypto/akcipher.h>
3535
#include <crypto/kpp.h>
36+
#include <crypto/acompress.h>
3637

3738
#include "internal.h"
3839

@@ -1442,6 +1443,121 @@ static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
14421443
return ret;
14431444
}
14441445

1446+
static int test_acomp(struct crypto_acomp *tfm, struct comp_testvec *ctemplate,
1447+
struct comp_testvec *dtemplate, int ctcount, int dtcount)
1448+
{
1449+
const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm));
1450+
unsigned int i;
1451+
char output[COMP_BUF_SIZE];
1452+
int ret;
1453+
struct scatterlist src, dst;
1454+
struct acomp_req *req;
1455+
struct tcrypt_result result;
1456+
1457+
for (i = 0; i < ctcount; i++) {
1458+
unsigned int dlen = COMP_BUF_SIZE;
1459+
int ilen = ctemplate[i].inlen;
1460+
1461+
memset(output, 0, sizeof(output));
1462+
init_completion(&result.completion);
1463+
sg_init_one(&src, ctemplate[i].input, ilen);
1464+
sg_init_one(&dst, output, dlen);
1465+
1466+
req = acomp_request_alloc(tfm);
1467+
if (!req) {
1468+
pr_err("alg: acomp: request alloc failed for %s\n",
1469+
algo);
1470+
ret = -ENOMEM;
1471+
goto out;
1472+
}
1473+
1474+
acomp_request_set_params(req, &src, &dst, ilen, dlen);
1475+
acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1476+
tcrypt_complete, &result);
1477+
1478+
ret = wait_async_op(&result, crypto_acomp_compress(req));
1479+
if (ret) {
1480+
pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
1481+
i + 1, algo, -ret);
1482+
acomp_request_free(req);
1483+
goto out;
1484+
}
1485+
1486+
if (req->dlen != ctemplate[i].outlen) {
1487+
pr_err("alg: acomp: Compression test %d failed for %s: output len = %d\n",
1488+
i + 1, algo, req->dlen);
1489+
ret = -EINVAL;
1490+
acomp_request_free(req);
1491+
goto out;
1492+
}
1493+
1494+
if (memcmp(output, ctemplate[i].output, req->dlen)) {
1495+
pr_err("alg: acomp: Compression test %d failed for %s\n",
1496+
i + 1, algo);
1497+
hexdump(output, req->dlen);
1498+
ret = -EINVAL;
1499+
acomp_request_free(req);
1500+
goto out;
1501+
}
1502+
1503+
acomp_request_free(req);
1504+
}
1505+
1506+
for (i = 0; i < dtcount; i++) {
1507+
unsigned int dlen = COMP_BUF_SIZE;
1508+
int ilen = dtemplate[i].inlen;
1509+
1510+
memset(output, 0, sizeof(output));
1511+
init_completion(&result.completion);
1512+
sg_init_one(&src, dtemplate[i].input, ilen);
1513+
sg_init_one(&dst, output, dlen);
1514+
1515+
req = acomp_request_alloc(tfm);
1516+
if (!req) {
1517+
pr_err("alg: acomp: request alloc failed for %s\n",
1518+
algo);
1519+
ret = -ENOMEM;
1520+
goto out;
1521+
}
1522+
1523+
acomp_request_set_params(req, &src, &dst, ilen, dlen);
1524+
acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1525+
tcrypt_complete, &result);
1526+
1527+
ret = wait_async_op(&result, crypto_acomp_decompress(req));
1528+
if (ret) {
1529+
pr_err("alg: acomp: decompression failed on test %d for %s: ret=%d\n",
1530+
i + 1, algo, -ret);
1531+
acomp_request_free(req);
1532+
goto out;
1533+
}
1534+
1535+
if (req->dlen != dtemplate[i].outlen) {
1536+
pr_err("alg: acomp: Decompression test %d failed for %s: output len = %d\n",
1537+
i + 1, algo, req->dlen);
1538+
ret = -EINVAL;
1539+
acomp_request_free(req);
1540+
goto out;
1541+
}
1542+
1543+
if (memcmp(output, dtemplate[i].output, req->dlen)) {
1544+
pr_err("alg: acomp: Decompression test %d failed for %s\n",
1545+
i + 1, algo);
1546+
hexdump(output, req->dlen);
1547+
ret = -EINVAL;
1548+
acomp_request_free(req);
1549+
goto out;
1550+
}
1551+
1552+
acomp_request_free(req);
1553+
}
1554+
1555+
ret = 0;
1556+
1557+
out:
1558+
return ret;
1559+
}
1560+
14451561
static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
14461562
unsigned int tcount)
14471563
{
@@ -1593,22 +1709,38 @@ static int alg_test_skcipher(const struct alg_test_desc *desc,
15931709
static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
15941710
u32 type, u32 mask)
15951711
{
1596-
struct crypto_comp *tfm;
1712+
struct crypto_comp *comp;
1713+
struct crypto_acomp *acomp;
15971714
int err;
1715+
u32 algo_type = type & CRYPTO_ALG_TYPE_ACOMPRESS_MASK;
1716+
1717+
if (algo_type == CRYPTO_ALG_TYPE_ACOMPRESS) {
1718+
acomp = crypto_alloc_acomp(driver, type, mask);
1719+
if (IS_ERR(acomp)) {
1720+
pr_err("alg: acomp: Failed to load transform for %s: %ld\n",
1721+
driver, PTR_ERR(acomp));
1722+
return PTR_ERR(acomp);
1723+
}
1724+
err = test_acomp(acomp, desc->suite.comp.comp.vecs,
1725+
desc->suite.comp.decomp.vecs,
1726+
desc->suite.comp.comp.count,
1727+
desc->suite.comp.decomp.count);
1728+
crypto_free_acomp(acomp);
1729+
} else {
1730+
comp = crypto_alloc_comp(driver, type, mask);
1731+
if (IS_ERR(comp)) {
1732+
pr_err("alg: comp: Failed to load transform for %s: %ld\n",
1733+
driver, PTR_ERR(comp));
1734+
return PTR_ERR(comp);
1735+
}
15981736

1599-
tfm = crypto_alloc_comp(driver, type, mask);
1600-
if (IS_ERR(tfm)) {
1601-
printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1602-
"%ld\n", driver, PTR_ERR(tfm));
1603-
return PTR_ERR(tfm);
1604-
}
1605-
1606-
err = test_comp(tfm, desc->suite.comp.comp.vecs,
1607-
desc->suite.comp.decomp.vecs,
1608-
desc->suite.comp.comp.count,
1609-
desc->suite.comp.decomp.count);
1737+
err = test_comp(comp, desc->suite.comp.comp.vecs,
1738+
desc->suite.comp.decomp.vecs,
1739+
desc->suite.comp.comp.count,
1740+
desc->suite.comp.decomp.count);
16101741

1611-
crypto_free_comp(tfm);
1742+
crypto_free_comp(comp);
1743+
}
16121744
return err;
16131745
}
16141746

0 commit comments

Comments
 (0)