While commit 336073840a87 ("crypto: testmgr - Allow different compression results") allowed to test non-generic compression algorithms there are some corner cases that would not be detected in test_comp(). For example if input -> compression -> decompression would all yield the same bytes the test would still pass. Improve the compression test by using the generic variant (if available) to decompress the compressed test vector from the non-generic algorithm. Suggested-by: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx> Signed-off-by: Jan Glauber <jglauber@xxxxxxxxxx> --- crypto/testmgr.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/crypto/testmgr.c b/crypto/testmgr.c index d1d99843cce4..cfb5fe4c5ccf 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -1346,6 +1346,7 @@ static int test_comp(struct crypto_comp *tfm, int ctcount, int dtcount) { const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm)); + const char *name = crypto_tfm_alg_name(crypto_comp_tfm(tfm)); char *output, *decomp_output; unsigned int i; int ret; @@ -1363,6 +1364,8 @@ static int test_comp(struct crypto_comp *tfm, for (i = 0; i < ctcount; i++) { int ilen; unsigned int dlen = COMP_BUF_SIZE; + struct crypto_comp *tfm_decomp = NULL; + char *gname; memset(output, 0, sizeof(COMP_BUF_SIZE)); memset(decomp_output, 0, sizeof(COMP_BUF_SIZE)); @@ -1377,9 +1380,27 @@ static int test_comp(struct crypto_comp *tfm, goto out; } + /* + * If compression of a non-generic algorithm was tested try to + * decompress using the generic variant. + */ + if (!strstr(algo, "generic")) { + /* Construct name from cra_name + "-generic" */ + gname = kmalloc(strlen(name) + 9, GFP_KERNEL); + strncpy(gname, name, strlen(name)); + strncpy(gname + strlen(name), "-generic", 9); + + tfm_decomp = crypto_alloc_comp(gname, 0, 0); + kfree(gname); + } + + /* If there is no generic variant use the same tfm as before. */ + if (!tfm_decomp || IS_ERR(tfm_decomp)) + tfm_decomp = tfm; + ilen = dlen; dlen = COMP_BUF_SIZE; - ret = crypto_comp_decompress(tfm, output, + ret = crypto_comp_decompress(tfm_decomp, output, ilen, decomp_output, &dlen); if (ret) { pr_err("alg: comp: compression failed: decompress: on test %d for %s failed: ret=%d\n", -- 2.17.1