4076632
From patchwork Wed Apr 11 18:28:32 2018
4076632
Content-Type: text/plain; charset="utf-8"
4076632
MIME-Version: 1.0
4076632
Content-Transfer-Encoding: 7bit
4076632
Subject: crypto: testmgr: Allow different compression results
4076632
From: Jan Glauber <jglauber@cavium.com>
4076632
X-Patchwork-Id: 10336001
4076632
Message-Id: <20180411182832.27761-1-jglauber@cavium.com>
4076632
To: Herbert Xu <herbert@gondor.apana.org.au>
4076632
Cc: "David S . Miller" <davem@davemloft.net>,
4076632
 linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
4076632
 Mahipal Challa <mchalla@cavium.com>,
4076632
 Balakrishna Bhamidipati <bbhamidipati@cavium.com>,
4076632
 Jan Glauber <jglauber@cavium.com>
4076632
Date: Wed, 11 Apr 2018 20:28:32 +0200
4076632
4076632
From: Mahipal Challa <mchalla@cavium.com>
4076632
4076632
The following error is triggered by the ThunderX ZIP driver
4076632
if the testmanager is enabled:
4076632
4076632
[  199.069437] ThunderX-ZIP 0000:03:00.0: Found ZIP device 0 177d:a01a on Node 0
4076632
[  199.073573] alg: comp: Compression test 1 failed for deflate-generic: output len = 37
4076632
4076632
The reason for this error is the verification of the compression
4076632
results. Verifying the compression result only works if all
4076632
algorithm parameters are identical, in this case to the software
4076632
implementation.
4076632
4076632
Different compression engines like the ThunderX ZIP coprocessor
4076632
might yield different compression results by tuning the
4076632
algorithm parameters. In our case the compressed result is
4076632
shorter than the test vector.
4076632
4076632
We should not forbid different compression results but only
4076632
check that compression -> decompression yields the same
4076632
result. This is done already in the acomp test. Do something
4076632
similar for test_comp().
4076632
4076632
Signed-off-by: Mahipal Challa <mchalla@cavium.com>
4076632
Signed-off-by: Balakrishna Bhamidipati <bbhamidipati@cavium.com>
4076632
[jglauber@cavium.com: removed unrelated printk changes, rewrote commit msg,
4076632
 fixed whitespace and unneeded initialization]
4076632
Signed-off-by: Jan Glauber <jglauber@cavium.com>
4076632
---
4076632
 crypto/testmgr.c | 50 +++++++++++++++++++++++++++++++++++++-------------
4076632
 1 file changed, 37 insertions(+), 13 deletions(-)
4076632
4076632
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
4076632
index af4a01c..627e82e 100644
4076632
--- a/crypto/testmgr.c
4076632
+++ b/crypto/testmgr.c
4076632
@@ -1342,19 +1342,30 @@ static int test_comp(struct crypto_comp *tfm,
4076632
 		     int ctcount, int dtcount)
4076632
 {
4076632
 	const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
4076632
+	char *output, *decomp_output;
4076632
 	unsigned int i;
4076632
-	char result[COMP_BUF_SIZE];
4076632
 	int ret;
4076632
 
4076632
+	output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
4076632
+	if (!output)
4076632
+		return -ENOMEM;
4076632
+
4076632
+	decomp_output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
4076632
+	if (!decomp_output) {
4076632
+		kfree(output);
4076632
+		return -ENOMEM;
4076632
+	}
4076632
+
4076632
 	for (i = 0; i < ctcount; i++) {
4076632
 		int ilen;
4076632
 		unsigned int dlen = COMP_BUF_SIZE;
4076632
 
4076632
-		memset(result, 0, sizeof (result));
4076632
+		memset(output, 0, sizeof(COMP_BUF_SIZE));
4076632
+		memset(decomp_output, 0, sizeof(COMP_BUF_SIZE));
4076632
 
4076632
 		ilen = ctemplate[i].inlen;
4076632
 		ret = crypto_comp_compress(tfm, ctemplate[i].input,
4076632
-		                           ilen, result, &dlen);
4076632
+					   ilen, output, &dlen);
4076632
 		if (ret) {
4076632
 			printk(KERN_ERR "alg: comp: compression failed "
4076632
 			       "on test %d for %s: ret=%d\n", i + 1, algo,
4076632
@@ -1362,7 +1373,17 @@ static int test_comp(struct crypto_comp *tfm,
4076632
 			goto out;
4076632
 		}
4076632
 
4076632
-		if (dlen != ctemplate[i].outlen) {
4076632
+		ilen = dlen;
4076632
+		dlen = COMP_BUF_SIZE;
4076632
+		ret = crypto_comp_decompress(tfm, output,
4076632
+					     ilen, decomp_output, &dlen);
4076632
+		if (ret) {
4076632
+			pr_err("alg: comp: compression failed: decompress: on test %d for %s failed: ret=%d\n",
4076632
+			       i + 1, algo, -ret);
4076632
+			goto out;
4076632
+		}
4076632
+
4076632
+		if (dlen != ctemplate[i].inlen) {
4076632
 			printk(KERN_ERR "alg: comp: Compression test %d "
4076632
 			       "failed for %s: output len = %d\n", i + 1, algo,
4076632
 			       dlen);
4076632
@@ -1370,10 +1391,11 @@ static int test_comp(struct crypto_comp *tfm,
4076632
 			goto out;
4076632
 		}
4076632
 
4076632
-		if (memcmp(result, ctemplate[i].output, dlen)) {
4076632
-			printk(KERN_ERR "alg: comp: Compression test %d "
4076632
-			       "failed for %s\n", i + 1, algo);
4076632
-			hexdump(result, dlen);
4076632
+		if (memcmp(decomp_output, ctemplate[i].input,
4076632
+			   ctemplate[i].inlen)) {
4076632
+			pr_err("alg: comp: compression failed: output differs: on test %d for %s\n",
4076632
+			       i + 1, algo);
4076632
+			hexdump(decomp_output, dlen);
4076632
 			ret = -EINVAL;
4076632
 			goto out;
4076632
 		}
4076632
@@ -1383,11 +1405,11 @@ static int test_comp(struct crypto_comp *tfm,
4076632
 		int ilen;
4076632
 		unsigned int dlen = COMP_BUF_SIZE;
4076632
 
4076632
-		memset(result, 0, sizeof (result));
4076632
+		memset(decomp_output, 0, sizeof(COMP_BUF_SIZE));
4076632
 
4076632
 		ilen = dtemplate[i].inlen;
4076632
 		ret = crypto_comp_decompress(tfm, dtemplate[i].input,
4076632
-		                             ilen, result, &dlen);
4076632
+					     ilen, decomp_output, &dlen);
4076632
 		if (ret) {
4076632
 			printk(KERN_ERR "alg: comp: decompression failed "
4076632
 			       "on test %d for %s: ret=%d\n", i + 1, algo,
4076632
@@ -1403,10 +1425,10 @@ static int test_comp(struct crypto_comp *tfm,
4076632
 			goto out;
4076632
 		}
4076632
 
4076632
-		if (memcmp(result, dtemplate[i].output, dlen)) {
4076632
+		if (memcmp(decomp_output, dtemplate[i].output, dlen)) {
4076632
 			printk(KERN_ERR "alg: comp: Decompression test %d "
4076632
 			       "failed for %s\n", i + 1, algo);
4076632
-			hexdump(result, dlen);
4076632
+			hexdump(decomp_output, dlen);
4076632
 			ret = -EINVAL;
4076632
 			goto out;
4076632
 		}
4076632
@@ -1415,11 +1437,13 @@ static int test_comp(struct crypto_comp *tfm,
4076632
 	ret = 0;
4076632
 
4076632
 out:
4076632
+	kfree(decomp_output);
4076632
+	kfree(output);
4076632
 	return ret;
4076632
 }
4076632
 
4076632
 static int test_acomp(struct crypto_acomp *tfm,
4076632
-		      const struct comp_testvec *ctemplate,
4076632
+			      const struct comp_testvec *ctemplate,
4076632
 		      const struct comp_testvec *dtemplate,
4076632
 		      int ctcount, int dtcount)
4076632
 {