From patchwork Fri Jun 22 14:37:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Glauber X-Patchwork-Id: 10482281 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4047E60230 for ; Fri, 22 Jun 2018 14:37:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1231A28EC8 for ; Fri, 22 Jun 2018 14:37:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06AFD28F65; Fri, 22 Jun 2018 14:37:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B91428EC8 for ; Fri, 22 Jun 2018 14:37:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933465AbeFVOhx (ORCPT ); Fri, 22 Jun 2018 10:37:53 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:37871 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933583AbeFVOhv (ORCPT ); Fri, 22 Jun 2018 10:37:51 -0400 Received: by mail-wr0-f193.google.com with SMTP id k6-v6so6944622wrp.4 for ; Fri, 22 Jun 2018 07:37:50 -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:in-reply-to :references; bh=+9+nvNwZJoybcBPM0P+0OXG/yEl2+L41lfsFiTkBLUg=; b=dKMhhNGPqChlBe+jXqePCwOMAGoLwSbQ81IxFGKAYRe+QoVOGAdI6uwCVCNCMds28i i53KaNZgOPCMcRnON6caq49osfDvsZfNJj3Fb21CKGONFu2w61klBi1LY5Nr9sNKIrkG iJdKAeSYGhhydyQa6VEtG2SapK/IZdYVXcrnm3tx0ThNevK2SQG3cn222OQ00FlOo1iH 1rNLDChBDCqhKm9uPWaPvfkfKrNozU5d5U/kKO4q3VqibU+Hgq2rXvPezcwcemdnfIvz IjyitqqVC7dyfFPl+KKZyOb5/p+omml/FJ6NQkw7Ga0DA8tMoIr713prn5SPQjoXmcOP 7Vbg== X-Gm-Message-State: APt69E12s8GmKKMMTezolJogOMOp0SnHmDpUP+209ODPk+5qVTux0nLd QHuSKT8ZHr+xWz6zBXWVIpsIvOjU X-Google-Smtp-Source: AAOMgpekaBovW3DMWk2t+asY3PXmsdW+mwzIlBShjyUxmjaiEdzspYTKNdrfPQR9NJ85Xazjf5mibA== X-Received: by 2002:a5d:4141:: with SMTP id c1-v6mr1743204wrq.129.1529678270197; Fri, 22 Jun 2018 07:37:50 -0700 (PDT) Received: from hc.cavium.com (dslb-088-066-107-231.088.066.pools.vodafone-ip.de. [88.66.107.231]) by smtp.gmail.com with ESMTPSA id a5-v6sm6553033wro.12.2018.06.22.07.37.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 22 Jun 2018 07:37:49 -0700 (PDT) From: Jan Glauber To: Herbert Xu Cc: "David S . Miller" , linux-crypto@vger.kernel.org, Mahipal Challa , Jan Glauber Subject: [PATCH 3/5] crypto: testmgr - Improve compression/decompression test Date: Fri, 22 Jun 2018 16:37:20 +0200 Message-Id: <20180622143722.9406-4-jglauber@cavium.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180622143722.9406-1-jglauber@cavium.com> References: <20180622143722.9406-1-jglauber@cavium.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Signed-off-by: Jan Glauber --- 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",