summaryrefslogtreecommitdiffstats
path: root/crypto/testmgr.c
diff options
context:
space:
mode:
authorMahipal Challa <mchalla@cavium.com>2018-04-11 14:28:32 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2018-04-20 12:58:37 -0400
commit336073840a8723f993511a3f357df42fc4a20930 (patch)
tree745a4361c0edb45da183415e10a0701245ded61c /crypto/testmgr.c
parent654f2b937b389295581bcb4aa26011a63db7bc8f (diff)
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>
Diffstat (limited to 'crypto/testmgr.c')
-rw-r--r--crypto/testmgr.c50
1 files changed, 37 insertions, 13 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index e2ed79dec2c7..397b117309f1 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -1342,19 +1342,30 @@ static int test_comp(struct crypto_comp *tfm,
1342 int ctcount, int dtcount) 1342 int ctcount, int dtcount)
1343{ 1343{
1344 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm)); 1344 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1345 char *output, *decomp_output;
1345 unsigned int i; 1346 unsigned int i;
1346 char result[COMP_BUF_SIZE];
1347 int ret; 1347 int ret;
1348 1348
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
1349 for (i = 0; i < ctcount; i++) { 1359 for (i = 0; i < ctcount; i++) {
1350 int ilen; 1360 int ilen;
1351 unsigned int dlen = COMP_BUF_SIZE; 1361 unsigned int dlen = COMP_BUF_SIZE;
1352 1362
1353 memset(result, 0, sizeof (result)); 1363 memset(output, 0, sizeof(COMP_BUF_SIZE));
1364 memset(decomp_output, 0, sizeof(COMP_BUF_SIZE));
1354 1365
1355 ilen = ctemplate[i].inlen; 1366 ilen = ctemplate[i].inlen;
1356 ret = crypto_comp_compress(tfm, ctemplate[i].input, 1367 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1357 ilen, result, &dlen); 1368 ilen, output, &dlen);
1358 if (ret) { 1369 if (ret) {
1359 printk(KERN_ERR "alg: comp: compression failed " 1370 printk(KERN_ERR "alg: comp: compression failed "
1360 "on test %d for %s: ret=%d\n", i + 1, algo, 1371 "on test %d for %s: ret=%d\n", i + 1, algo,
@@ -1362,7 +1373,17 @@ static int test_comp(struct crypto_comp *tfm,
1362 goto out; 1373 goto out;
1363 } 1374 }
1364 1375
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) {
1366 printk(KERN_ERR "alg: comp: Compression test %d " 1387 printk(KERN_ERR "alg: comp: Compression test %d "
1367 "failed for %s: output len = %d\n", i + 1, algo, 1388 "failed for %s: output len = %d\n", i + 1, algo,
1368 dlen); 1389 dlen);
@@ -1370,10 +1391,11 @@ static int test_comp(struct crypto_comp *tfm,
1370 goto out; 1391 goto out;
1371 } 1392 }
1372 1393
1373 if (memcmp(result, ctemplate[i].output, dlen)) { 1394 if (memcmp(decomp_output, ctemplate[i].input,
1374 printk(KERN_ERR "alg: comp: Compression test %d " 1395 ctemplate[i].inlen)) {
1375 "failed for %s\n", i + 1, algo); 1396 pr_err("alg: comp: compression failed: output differs: on test %d for %s\n",
1376 hexdump(result, dlen); 1397 i + 1, algo);
1398 hexdump(decomp_output, dlen);
1377 ret = -EINVAL; 1399 ret = -EINVAL;
1378 goto out; 1400 goto out;
1379 } 1401 }
@@ -1383,11 +1405,11 @@ static int test_comp(struct crypto_comp *tfm,
1383 int ilen; 1405 int ilen;
1384 unsigned int dlen = COMP_BUF_SIZE; 1406 unsigned int dlen = COMP_BUF_SIZE;
1385 1407
1386 memset(result, 0, sizeof (result)); 1408 memset(decomp_output, 0, sizeof(COMP_BUF_SIZE));
1387 1409
1388 ilen = dtemplate[i].inlen; 1410 ilen = dtemplate[i].inlen;
1389 ret = crypto_comp_decompress(tfm, dtemplate[i].input, 1411 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1390 ilen, result, &dlen); 1412 ilen, decomp_output, &dlen);
1391 if (ret) { 1413 if (ret) {
1392 printk(KERN_ERR "alg: comp: decompression failed " 1414 printk(KERN_ERR "alg: comp: decompression failed "
1393 "on test %d for %s: ret=%d\n", i + 1, algo, 1415 "on test %d for %s: ret=%d\n", i + 1, algo,
@@ -1403,10 +1425,10 @@ static int test_comp(struct crypto_comp *tfm,
1403 goto out; 1425 goto out;
1404 } 1426 }
1405 1427
1406 if (memcmp(result, dtemplate[i].output, dlen)) { 1428 if (memcmp(decomp_output, dtemplate[i].output, dlen)) {
1407 printk(KERN_ERR "alg: comp: Decompression test %d " 1429 printk(KERN_ERR "alg: comp: Decompression test %d "
1408 "failed for %s\n", i + 1, algo); 1430 "failed for %s\n", i + 1, algo);
1409 hexdump(result, dlen); 1431 hexdump(decomp_output, dlen);
1410 ret = -EINVAL; 1432 ret = -EINVAL;
1411 goto out; 1433 goto out;
1412 } 1434 }
@@ -1415,11 +1437,13 @@ static int test_comp(struct crypto_comp *tfm,
1415 ret = 0; 1437 ret = 0;
1416 1438
1417out: 1439out:
1440 kfree(decomp_output);
1441 kfree(output);
1418 return ret; 1442 return ret;
1419} 1443}
1420 1444
1421static int test_acomp(struct crypto_acomp *tfm, 1445static int test_acomp(struct crypto_acomp *tfm,
1422 const struct comp_testvec *ctemplate, 1446 const struct comp_testvec *ctemplate,
1423 const struct comp_testvec *dtemplate, 1447 const struct comp_testvec *dtemplate,
1424 int ctcount, int dtcount) 1448 int ctcount, int dtcount)
1425{ 1449{