From patchwork Thu Jun 28 07:32:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 140424 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1853950ljj; Thu, 28 Jun 2018 00:33:49 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKPsxx2rUk7HAmAyTYpo2GkcdlUBJpyS1r6vn6fx5IbCpIwVPrBV3/qoXckTrylk75patFf X-Received: by 2002:a65:5307:: with SMTP id m7-v6mr8101907pgq.431.1530171229006; Thu, 28 Jun 2018 00:33:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530171228; cv=none; d=google.com; s=arc-20160816; b=VGDm5aR2G2Kuu3kP5w9hpkSL1MvP8zGlNCyg0SzUlVvsFrXsg7Ykx4eMQ30l6F1FHJ 5X5vD6h7xk22M2rS2LnJZLxuo6FBf8LcAF95ocyqNxqtC4600YAePJcQ6PHYpgciuPqg edOQkeCCsaZ/ia74Az0osJUXGl6X4+e6gFMp1G2M/XNfavd6Z5+h7I2N+pb5ZWF+dSiV +1LSCQvG5VxJkcmW70sDsrg/p+tbQBsxuSoLvK5hHhShiomrbSkTYeV5GkDkrVKR0DJk vug9oIMsJhIex+b9sKjvnYtUMBIbFMCeqADq7z1hGdiBqzZq46IMY8hsauKT/YP3LUQN qV0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=3mCkkKilz3I18/23SY7kQZ8PEWIUbvmkGGzxlUN3O58=; b=s2KQuI2NmZpD5pkY2ukzai1zpY7/c9H9aSqzkLkJQQpUzRmV8xXBRvNeLzprzhu7rN UoEo3MWaXB5n5vjFST/Hv1ge6U2DtgqRyqNM7cdSl/g7+ZI1+KL8xKO4HoAqVYoAUza9 Hgtc+SZZFEPWm8xxs+Jp07DFlodYKqomoPhA2aFJaP/eHdBo+ZaKtHZL4IAOhO81+MAx JbyiKAxWtPRLdPrV4XAB8imBmc/rQvw32o2pMArOfnaYeNqnt3mrACLg0gknPUGeyquV etoJnuLRFuM0zW6bJ/fM4MBnXYhLJecdqVUlf0jAiK+N1p3nF+6IRbHuIqhRfL0XxydM oNWw== 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 21-v6si5961413pfj.6.2018.06.28.00.33.48; Thu, 28 Jun 2018 00:33:48 -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 S964936AbeF1Hdr (ORCPT + 31 others); Thu, 28 Jun 2018 03:33:47 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:42222 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934133AbeF1HdF (ORCPT ); Thu, 28 Jun 2018 03:33:05 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4F25F18A; Thu, 28 Jun 2018 00:33:05 -0700 (PDT) Received: from sugar.kfn.arm.com (unknown [10.45.48.147]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A0EF63F5C0; Thu, 28 Jun 2018 00:33:03 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" Cc: Ofir Drang , Hadar Gat , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] crypto: testmgr: add hash finup tests Date: Thu, 28 Jun 2018 08:32:52 +0100 Message-Id: <1530171175-31960-3-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530171175-31960-1-git-send-email-gilad@benyossef.com> References: <1530171175-31960-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The testmgr hash tests were testing init, digest, update and final methods but not the finup method. Add a test for this one too. While doing this, make sure we only run the partial tests once with the digest tests and skip them with the final and finup tests since they are the same. Signed-off-by: Gilad Ben-Yossef --- crypto/testmgr.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 9 deletions(-) -- 2.7.4 diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 11e4535..ca475f6 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -259,9 +259,15 @@ static int ahash_partial_update(struct ahash_request **preq, return ret; } +enum hash_test { + HASH_TEST_DIGEST, + HASH_TEST_FINAL, + HASH_TEST_FINUP +}; + static int __test_hash(struct crypto_ahash *tfm, const struct hash_testvec *template, unsigned int tcount, - bool use_digest, const int align_offset) + enum hash_test test_type, const int align_offset) { const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm)); size_t digest_size = crypto_ahash_digestsize(tfm); @@ -332,14 +338,17 @@ static int __test_hash(struct crypto_ahash *tfm, } ahash_request_set_crypt(req, sg, result, template[i].psize); - if (use_digest) { + switch (test_type) { + case HASH_TEST_DIGEST: ret = crypto_wait_req(crypto_ahash_digest(req), &wait); if (ret) { pr_err("alg: hash: digest failed on test %d " "for %s: ret=%d\n", j, algo, -ret); goto out; } - } else { + break; + + case HASH_TEST_FINAL: memset(result, 1, digest_size); ret = crypto_wait_req(crypto_ahash_init(req), &wait); if (ret) { @@ -371,6 +380,29 @@ static int __test_hash(struct crypto_ahash *tfm, "for %s: ret=%d\n", j, algo, -ret); goto out; } + break; + + case HASH_TEST_FINUP: + memset(result, 1, digest_size); + ret = crypto_wait_req(crypto_ahash_init(req), &wait); + if (ret) { + pr_err("alg: hash: init failed on test %d " + "for %s: ret=%d\n", j, algo, -ret); + goto out; + } + ret = ahash_guard_result(result, 1, digest_size); + if (ret) { + pr_err("alg: hash: init failed on test %d " + "for %s: used req->result\n", j, algo); + goto out; + } + ret = crypto_wait_req(crypto_ahash_finup(req), &wait); + if (ret) { + pr_err("alg: hash: final failed on test %d " + "for %s: ret=%d\n", j, algo, -ret); + goto out; + } + break; } if (memcmp(result, template[i].digest, @@ -383,6 +415,9 @@ static int __test_hash(struct crypto_ahash *tfm, } } + if (test_type) + goto out; + j = 0; for (i = 0; i < tcount; i++) { /* alignment tests are only done with continuous buffers */ @@ -540,24 +575,24 @@ static int __test_hash(struct crypto_ahash *tfm, static int test_hash(struct crypto_ahash *tfm, const struct hash_testvec *template, - unsigned int tcount, bool use_digest) + unsigned int tcount, enum hash_test test_type) { unsigned int alignmask; int ret; - ret = __test_hash(tfm, template, tcount, use_digest, 0); + ret = __test_hash(tfm, template, tcount, test_type, 0); if (ret) return ret; /* test unaligned buffers, check with one byte offset */ - ret = __test_hash(tfm, template, tcount, use_digest, 1); + ret = __test_hash(tfm, template, tcount, test_type, 1); if (ret) return ret; alignmask = crypto_tfm_alg_alignmask(&tfm->base); if (alignmask) { /* Check if alignment mask for tfm is correctly set. */ - ret = __test_hash(tfm, template, tcount, use_digest, + ret = __test_hash(tfm, template, tcount, test_type, alignmask + 1); if (ret) return ret; @@ -1803,9 +1838,11 @@ static int __alg_test_hash(const struct hash_testvec *template, return PTR_ERR(tfm); } - err = test_hash(tfm, template, tcount, true); + err = test_hash(tfm, template, tcount, HASH_TEST_DIGEST); + if (!err) + err = test_hash(tfm, template, tcount, HASH_TEST_FINAL); if (!err) - err = test_hash(tfm, template, tcount, false); + err = test_hash(tfm, template, tcount, HASH_TEST_FINUP); crypto_free_ahash(tfm); return err; }