Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp7275734imm; Thu, 28 Jun 2018 00:35:36 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLROMilKamQrqQUy8Q86ipGw3MAXCRK+evNJZ5lC0txOebp1OI5Kz6eNqb5Cj/ejXQ1vVlt X-Received: by 2002:a63:735d:: with SMTP id d29-v6mr7985652pgn.156.1530171335951; Thu, 28 Jun 2018 00:35:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530171335; cv=none; d=google.com; s=arc-20160816; b=zbZm4SOlKiPcCWUp9Hf1dDv0dKdasIcLtpHa99MzwrDjgOdet6ofgxmZdC8EittVXe pCF7y1Zm965u26XnLLY7BZ/kDzwxE0fAGM6kyg4XfF/+1q6ssBGTve8XNJYrZBf1Iq+/ MvULKC2sJOBqaXy2HGwv+CX/r0E3482rY4GIUbyBf7BHNN0qYEwXT+pniJnLDisgas7r pOU9KUPfF11pQ2vv+wwZt5DZILa0Bp0fQp3PFS6MXueH3Js+qFI5pesRGPt6lgZ52Ax7 8eI7u79w8rsplOrTDf29RHHn0c111Ev57qaQg0PARKA4JbmdCBDlAux/tQubgKbE0rUa ud9Q== 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 n13-v6si2607822pfd.50.2018.06.28.00.35.21; Thu, 28 Jun 2018 00:35:35 -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 S964889AbeF1Hdq (ORCPT + 99 others); Thu, 28 Jun 2018 03:33:46 -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(-) 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; } -- 2.7.4