Skip to content

Commit 3360738

Browse files
mchallacaviumherbertx
authored andcommitted
crypto: testmgr - Allow different compression results
The following error is triggered by the ThunderX ZIP driver if the testmanager is enabled: [ 199.069437] ThunderX-ZIP 0000:03:00.0: Found ZIP device 0 177d:a01a on Node 0 [ 199.073573] alg: comp: Compression test 1 failed for deflate-generic: output len = 37 The reason for this error is the verification of the compression results. Verifying the compression result only works if all algorithm parameters are identical, in this case to the software implementation. Different compression engines like the ThunderX ZIP coprocessor might yield different compression results by tuning the algorithm parameters. In our case the compressed result is shorter than the test vector. We should not forbid different compression results but only check that compression -> decompression yields the same result. This is done already in the acomp test. Do something similar for test_comp(). Signed-off-by: Mahipal Challa <mchalla@cavium.com> Signed-off-by: Balakrishna Bhamidipati <bbhamidipati@cavium.com> [jglauber@cavium.com: removed unrelated printk changes, rewrote commit msg, fixed whitespace and unneeded initialization] Signed-off-by: Jan Glauber <jglauber@cavium.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 654f2b9 commit 3360738

File tree

1 file changed

+37
-13
lines changed

1 file changed

+37
-13
lines changed

crypto/testmgr.c

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,38 +1342,60 @@ static int test_comp(struct crypto_comp *tfm,
13421342
int ctcount, int dtcount)
13431343
{
13441344
const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1345+
char *output, *decomp_output;
13451346
unsigned int i;
1346-
char result[COMP_BUF_SIZE];
13471347
int ret;
13481348

1349+
output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1350+
if (!output)
1351+
return -ENOMEM;
1352+
1353+
decomp_output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1354+
if (!decomp_output) {
1355+
kfree(output);
1356+
return -ENOMEM;
1357+
}
1358+
13491359
for (i = 0; i < ctcount; i++) {
13501360
int ilen;
13511361
unsigned int dlen = COMP_BUF_SIZE;
13521362

1353-
memset(result, 0, sizeof (result));
1363+
memset(output, 0, sizeof(COMP_BUF_SIZE));
1364+
memset(decomp_output, 0, sizeof(COMP_BUF_SIZE));
13541365

13551366
ilen = ctemplate[i].inlen;
13561367
ret = crypto_comp_compress(tfm, ctemplate[i].input,
1357-
ilen, result, &dlen);
1368+
ilen, output, &dlen);
13581369
if (ret) {
13591370
printk(KERN_ERR "alg: comp: compression failed "
13601371
"on test %d for %s: ret=%d\n", i + 1, algo,
13611372
-ret);
13621373
goto out;
13631374
}
13641375

1365-
if (dlen != ctemplate[i].outlen) {
1376+
ilen = dlen;
1377+
dlen = COMP_BUF_SIZE;
1378+
ret = crypto_comp_decompress(tfm, output,
1379+
ilen, decomp_output, &dlen);
1380+
if (ret) {
1381+
pr_err("alg: comp: compression failed: decompress: on test %d for %s failed: ret=%d\n",
1382+
i + 1, algo, -ret);
1383+
goto out;
1384+
}
1385+
1386+
if (dlen != ctemplate[i].inlen) {
13661387
printk(KERN_ERR "alg: comp: Compression test %d "
13671388
"failed for %s: output len = %d\n", i + 1, algo,
13681389
dlen);
13691390
ret = -EINVAL;
13701391
goto out;
13711392
}
13721393

1373-
if (memcmp(result, ctemplate[i].output, dlen)) {
1374-
printk(KERN_ERR "alg: comp: Compression test %d "
1375-
"failed for %s\n", i + 1, algo);
1376-
hexdump(result, dlen);
1394+
if (memcmp(decomp_output, ctemplate[i].input,
1395+
ctemplate[i].inlen)) {
1396+
pr_err("alg: comp: compression failed: output differs: on test %d for %s\n",
1397+
i + 1, algo);
1398+
hexdump(decomp_output, dlen);
13771399
ret = -EINVAL;
13781400
goto out;
13791401
}
@@ -1383,11 +1405,11 @@ static int test_comp(struct crypto_comp *tfm,
13831405
int ilen;
13841406
unsigned int dlen = COMP_BUF_SIZE;
13851407

1386-
memset(result, 0, sizeof (result));
1408+
memset(decomp_output, 0, sizeof(COMP_BUF_SIZE));
13871409

13881410
ilen = dtemplate[i].inlen;
13891411
ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1390-
ilen, result, &dlen);
1412+
ilen, decomp_output, &dlen);
13911413
if (ret) {
13921414
printk(KERN_ERR "alg: comp: decompression failed "
13931415
"on test %d for %s: ret=%d\n", i + 1, algo,
@@ -1403,10 +1425,10 @@ static int test_comp(struct crypto_comp *tfm,
14031425
goto out;
14041426
}
14051427

1406-
if (memcmp(result, dtemplate[i].output, dlen)) {
1428+
if (memcmp(decomp_output, dtemplate[i].output, dlen)) {
14071429
printk(KERN_ERR "alg: comp: Decompression test %d "
14081430
"failed for %s\n", i + 1, algo);
1409-
hexdump(result, dlen);
1431+
hexdump(decomp_output, dlen);
14101432
ret = -EINVAL;
14111433
goto out;
14121434
}
@@ -1415,11 +1437,13 @@ static int test_comp(struct crypto_comp *tfm,
14151437
ret = 0;
14161438

14171439
out:
1440+
kfree(decomp_output);
1441+
kfree(output);
14181442
return ret;
14191443
}
14201444

14211445
static int test_acomp(struct crypto_acomp *tfm,
1422-
const struct comp_testvec *ctemplate,
1446+
const struct comp_testvec *ctemplate,
14231447
const struct comp_testvec *dtemplate,
14241448
int ctcount, int dtcount)
14251449
{

0 commit comments

Comments
 (0)