Received: by 10.192.165.156 with SMTP id m28csp1052877imm; Wed, 11 Apr 2018 11:32:12 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+G0xLdpLo8j03cvtZaIfE+Bo006DfQtM5RI4VURpPnDcej+cyVH93ewvdZE1XX2TqStWOh X-Received: by 10.167.133.85 with SMTP id y21mr4908047pfn.139.1523471532703; Wed, 11 Apr 2018 11:32:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523471532; cv=none; d=google.com; s=arc-20160816; b=1Lo3reWMuG3VtWqXwUuaYHWR/yMZsAeD7qHzTV68HPPp1li/HHVPdVe2b/JB1vtWjB 4/pRqhBV8LGLaRoY8Ot+G/Rn9D3jlQZlAYLTjzJ+at4c0TVyznhb2M2SNLUtzRAO/XIC x66XsSIjApKYuyHftTNve5Br1IDzareooMmWMlw7vFopFg72VQRUpZJQJOjSECFO2XYz VBo+2pHHs0IqMpRzC50O4//sMeo7B1QqPEgh1fsLspZIACJjhrk5JjdxEWzkeBfcjPYZ 4uV3oJSFccVArLkJwQgTXTVyY3hMH23hBpTeZ012UXlUyxgNe591xPFzXoQ4VMNiqquw XXNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=SctSAI3sC8tg2iohQb13HlAELeNb8dcAYnNP1HF8D9M=; b=0jHx2GyacfPDEtz7eizywfKliwg0KTkVa0k63UPb3UaLW1I8HtbIaVQ5S+oh7xEE9+ 26hFOFNTAY3+yeZLs5PDSHCYerk6lKODyUdziDalxTmpws/rSgzHlCCLyfOwBpIP3GiV PzHQh+Po2pIJ5olUfqEbgaRvESbG10QgOlPDqG8sj+PfYUqWOlQbcIbCc0AZDSS76+Fr a7DlYGOnTxGRrpCuytJTQgZppQcAVWZqo+RYFYH0Saw7Ycd5VWrvCtb8SJbDx8lBgIzy y1f+kfq2nOzgRE3kmEawvF3ektgwBoG2rX1sBhDv5PXY5DhMddzLTF/fwm5vgYofW10V yzOw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u20si1077069pgv.12.2018.04.11.11.31.35; Wed, 11 Apr 2018 11:32:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752915AbeDKS2x (ORCPT + 99 others); Wed, 11 Apr 2018 14:28:53 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:56253 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751798AbeDKS2w (ORCPT ); Wed, 11 Apr 2018 14:28:52 -0400 Received: by mail-wm0-f66.google.com with SMTP id b127so6143139wmf.5; Wed, 11 Apr 2018 11:28:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=SctSAI3sC8tg2iohQb13HlAELeNb8dcAYnNP1HF8D9M=; b=haOz2TSBAXbXLF8QiVN0HvYL/1c42SXVyCZcKDGhs8X0IB11ns5Ket2O4PKfoN64d1 01POU3PMItsM88QQAt5LXPIYtoGDnoeF0onlFu5izmkwShtIGo6+oxQte9Uxlnf+gnas L/wpabFbKdUt1Z9zgE5FIrcjGambf4aifst+FgpYyAQv0bWJo/tVMhkA4QnOqvknTChm rF+rys5Mtvxuu6GttlfVF7SgPzZaVHE26eFrBxzROzFkf7AVo9vftQBsMLQZ29rhquoW NJq9yf24lieFNID0tbs4HIn4BxBL62mymIlFx3ZqdKFC7s9u+d3T9otnP2kVfWR8VXmN /JOw== X-Gm-Message-State: ALQs6tCwTg2xAEbS82zX6SEQlL1TVldu8iP5hLYQ13halihUD9o+F9Si LtN8IAGsT6njMgP+lSbhXi/1CZbV X-Received: by 10.28.158.10 with SMTP id h10mr3152584wme.105.1523471330501; Wed, 11 Apr 2018 11:28:50 -0700 (PDT) Received: from hc.fritz.box (HSI-KBW-37-49-17-1.hsi14.kabel-badenwuerttemberg.de. [37.49.17.1]) by smtp.gmail.com with ESMTPSA id r196sm1776879wmf.9.2018.04.11.11.28.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Apr 2018 11:28:49 -0700 (PDT) From: Jan Glauber To: Herbert Xu Cc: "David S . Miller" , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Mahipal Challa , Balakrishna Bhamidipati , Jan Glauber Subject: [PATCH] crypto: testmgr: Allow different compression results Date: Wed, 11 Apr 2018 20:28:32 +0200 Message-Id: <20180411182832.27761-1-jglauber@cavium.com> X-Mailer: git-send-email 2.16.2 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mahipal Challa 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 Signed-off-by: Balakrishna Bhamidipati [jglauber@cavium.com: removed unrelated printk changes, rewrote commit msg, fixed whitespace and unneeded initialization] Signed-off-by: Jan Glauber --- crypto/testmgr.c | 50 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/crypto/testmgr.c b/crypto/testmgr.c index af4a01c..627e82e 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -1342,19 +1342,30 @@ static int test_comp(struct crypto_comp *tfm, int ctcount, int dtcount) { const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm)); + char *output, *decomp_output; unsigned int i; - char result[COMP_BUF_SIZE]; int ret; + output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL); + if (!output) + return -ENOMEM; + + decomp_output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL); + if (!decomp_output) { + kfree(output); + return -ENOMEM; + } + for (i = 0; i < ctcount; i++) { int ilen; unsigned int dlen = COMP_BUF_SIZE; - memset(result, 0, sizeof (result)); + memset(output, 0, sizeof(COMP_BUF_SIZE)); + memset(decomp_output, 0, sizeof(COMP_BUF_SIZE)); ilen = ctemplate[i].inlen; ret = crypto_comp_compress(tfm, ctemplate[i].input, - ilen, result, &dlen); + ilen, output, &dlen); if (ret) { printk(KERN_ERR "alg: comp: compression failed " "on test %d for %s: ret=%d\n", i + 1, algo, @@ -1362,7 +1373,17 @@ static int test_comp(struct crypto_comp *tfm, goto out; } - if (dlen != ctemplate[i].outlen) { + ilen = dlen; + dlen = COMP_BUF_SIZE; + ret = crypto_comp_decompress(tfm, output, + ilen, decomp_output, &dlen); + if (ret) { + pr_err("alg: comp: compression failed: decompress: on test %d for %s failed: ret=%d\n", + i + 1, algo, -ret); + goto out; + } + + if (dlen != ctemplate[i].inlen) { printk(KERN_ERR "alg: comp: Compression test %d " "failed for %s: output len = %d\n", i + 1, algo, dlen); @@ -1370,10 +1391,11 @@ static int test_comp(struct crypto_comp *tfm, goto out; } - if (memcmp(result, ctemplate[i].output, dlen)) { - printk(KERN_ERR "alg: comp: Compression test %d " - "failed for %s\n", i + 1, algo); - hexdump(result, dlen); + if (memcmp(decomp_output, ctemplate[i].input, + ctemplate[i].inlen)) { + pr_err("alg: comp: compression failed: output differs: on test %d for %s\n", + i + 1, algo); + hexdump(decomp_output, dlen); ret = -EINVAL; goto out; } @@ -1383,11 +1405,11 @@ static int test_comp(struct crypto_comp *tfm, int ilen; unsigned int dlen = COMP_BUF_SIZE; - memset(result, 0, sizeof (result)); + memset(decomp_output, 0, sizeof(COMP_BUF_SIZE)); ilen = dtemplate[i].inlen; ret = crypto_comp_decompress(tfm, dtemplate[i].input, - ilen, result, &dlen); + ilen, decomp_output, &dlen); if (ret) { printk(KERN_ERR "alg: comp: decompression failed " "on test %d for %s: ret=%d\n", i + 1, algo, @@ -1403,10 +1425,10 @@ static int test_comp(struct crypto_comp *tfm, goto out; } - if (memcmp(result, dtemplate[i].output, dlen)) { + if (memcmp(decomp_output, dtemplate[i].output, dlen)) { printk(KERN_ERR "alg: comp: Decompression test %d " "failed for %s\n", i + 1, algo); - hexdump(result, dlen); + hexdump(decomp_output, dlen); ret = -EINVAL; goto out; } @@ -1415,11 +1437,13 @@ static int test_comp(struct crypto_comp *tfm, ret = 0; out: + kfree(decomp_output); + kfree(output); return ret; } static int test_acomp(struct crypto_acomp *tfm, - const struct comp_testvec *ctemplate, + const struct comp_testvec *ctemplate, const struct comp_testvec *dtemplate, int ctcount, int dtcount) { -- 2.7.4