Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2534254lqt; Mon, 22 Apr 2024 13:36:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXUrW4R0JGRIGbArRCRZ7wfFy89fSta9Y1F8UDxpu+ZhR1EngnUVA5s50RVbJZeARyakH9UIyGm0ekfRkMZT6UduqxAzWPjzG3rfvbKgQ== X-Google-Smtp-Source: AGHT+IFI/M2FRBcRi4uYdu1CYq6FLpc3nsA/q4EeSOeIfgpLx9hxq3UrAYz6NwznPZVj0kBzs8hh X-Received: by 2002:a05:6808:6291:b0:3c6:92c:ff2b with SMTP id du17-20020a056808629100b003c6092cff2bmr12438782oib.12.1713818177083; Mon, 22 Apr 2024 13:36:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713818177; cv=pass; d=google.com; s=arc-20160816; b=eGIxhfIOw690uBmGKgAQTXbGadGTjfGDFlxsEXdqyu/xca7rVVhf0NToFchAIwkGYQ fhGLkB7aGf+2+PJ7ozlov8vnZ453EDOk/85PEWJMi0T5u7qXBrzou4jLomC1E5oIw1Oa UdeoOB5BR5v4VohWQE4rMNvIDr0kR4KUuq6M9N2MzBrrI/O67/8ISl7b5Cx+wTB+croy jatkGxMwRV4Grk1n49cW1PwkfKnT6bUZKAJam2K4KvavOqWcdU3XHd7GLpDwhMY7BlFN FxMkAW0e0FUO80OJAuDiDQ5bnUWP9Q3/++iQ9nba9J3A+WvsSoc2TvSRofHIRM46Gw5h VO7A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=d++R28FMaLykLDmAIxym8q4BHwvaS3JgTQKeQLb5VGs=; fh=Oc4UeL7Acx0XOi4VhIHpcDb9W4i3PZetSD9m7YBP3X4=; b=rZuCbxVR6JtMLqVoxDTzWwQMqkbbCxUyAPOVjLx5OilTmU5MZJQkPf0jwoj9Iyt7j7 h0+jbsTO+hUq9ISFUC6RGE0QWU73OqOAAT6jVwoHYe0N1xhIFYpU9ObqxStss8W3iJhN Enl4uZq4P8WNA+TpTzpb8MsnQdR+dV7qQpYaQs179EahVhKkGo3u41gj83LeZUH/3v8O FoJvuIO728dv/Rn3Y9IRsu9cVtEsmBPqRrAS/eB8Sy1GpySikyddP5xRVHY/0WLV74YM 7pu7l1d7UM0UioMFBbIuyt6hcB8fYEugPAb9jKLWO8FZuueoBi75WvrPIp+dudcxIA6x S3ZA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=guEFiQ7a; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-3767-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-crypto+bounces-3767-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id r6-20020a05622a034600b00434fcdcaa93si11178402qtw.758.2024.04.22.13.36.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 13:36:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-3767-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=guEFiQ7a; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-3767-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-crypto+bounces-3767-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B822F1C21064 for ; Mon, 22 Apr 2024 20:36:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 33ECF1C2A5; Mon, 22 Apr 2024 20:36:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="guEFiQ7a" X-Original-To: linux-crypto@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DFC1A1BDC4; Mon, 22 Apr 2024 20:36:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713818163; cv=none; b=AZV8dWpj0k4eTq0St9nNVSwGQJn/rPaEAEWZj0mn+0L3bluSTDI2sr6RyW/PwBbrOnQMgxkEIUVEJHVIZGf5FC0vkizaGPv2vcQ1Pq/D03k3Yg0dbT5X2L2X+BtvryI30GO/gxRGZAdryIEYXvWsKg8/WkVyG2J3hvOCv8FWNcg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713818163; c=relaxed/simple; bh=g2lxiYMhd7JfTooN9yvW8o7SK6LFd1hw8m3EZ1YtqW0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Sxdifbik1MThsDQCBPf3adhkEorQje+aVYCSYGhqUzJhaqT6OYRXdk0pvyXyI31skN0b97deCkIIKmF4MSCQWiKSzAVFiIfpCk9rUC4Y0YokuxUku3lb8WnAMKTe0pvtPH5x6nkB327XIThmcUSg72TtAriK4Kq/lwh0xWHQdTs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=guEFiQ7a; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52EB7C4AF08; Mon, 22 Apr 2024 20:36:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713818162; bh=g2lxiYMhd7JfTooN9yvW8o7SK6LFd1hw8m3EZ1YtqW0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=guEFiQ7agdb4PW66xa0AifMHOKe0fsNK9s0Au1C096IMK8Z68EDRGPQJ1MaOrs8pN oBRaxxP6C7oPWC7GRH3V12xiAKS24uN6vO8sh8RkZA4GhzeaHKDqWB9z1Rfng5eahi 5q0zNeWecb9r+ogAvQ6XqJLzPI6zs5FQ5BLOtoGjupsrnQMZmXEDPw5BmX8ZTQHFMK Pa57FVRwSZv+y5V130P/rFHEZZZ9MMYEFNOgwbgEMWWSmBE7GQy797opqxh6AuhwRd aw+XmZjmkNPNA5p618grKeuz+sjaiFSdxPTYuSWY0+vVvTvWlrJMXkUyC1Wdce2f7p nXWpDY4HXHTOg== From: Eric Biggers To: linux-crypto@vger.kernel.org, fsverity@lists.linux.dev, dm-devel@lists.linux.dev Cc: x86@kernel.org, linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Sami Tolvanen , Bart Van Assche Subject: [PATCH v2 3/8] crypto: testmgr - add tests for finup2x Date: Mon, 22 Apr 2024 13:35:39 -0700 Message-ID: <20240422203544.195390-4-ebiggers@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422203544.195390-1-ebiggers@kernel.org> References: <20240422203544.195390-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Eric Biggers Update the shash self-tests to test the new finup2x method when CONFIG_CRYPTO_MANAGER_EXTRA_TESTS=y. Signed-off-by: Eric Biggers --- crypto/testmgr.c | 56 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 2c57ebcaf368..b49fa88c95e1 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -227,10 +227,12 @@ enum flush_type { /* finalization function for hash algorithms */ enum finalization_type { FINALIZATION_TYPE_FINAL, /* use final() */ FINALIZATION_TYPE_FINUP, /* use finup() */ + FINALIZATION_TYPE_FINUP2X_BUF1, /* use 1st buffer of finup2x() */ + FINALIZATION_TYPE_FINUP2X_BUF2, /* use 2nd buffer of finup2x() */ FINALIZATION_TYPE_DIGEST, /* use digest() */ }; /* * Whether the crypto operation will occur in-place, and if so whether the @@ -1109,19 +1111,28 @@ static void generate_random_testvec_config(struct rnd_state *rng, if (prandom_bool(rng)) { cfg->req_flags |= CRYPTO_TFM_REQ_MAY_SLEEP; p += scnprintf(p, end - p, " may_sleep"); } - switch (prandom_u32_below(rng, 4)) { + switch (prandom_u32_below(rng, 8)) { case 0: + case 1: cfg->finalization_type = FINALIZATION_TYPE_FINAL; p += scnprintf(p, end - p, " use_final"); break; - case 1: + case 2: cfg->finalization_type = FINALIZATION_TYPE_FINUP; p += scnprintf(p, end - p, " use_finup"); break; + case 3: + cfg->finalization_type = FINALIZATION_TYPE_FINUP2X_BUF1; + p += scnprintf(p, end - p, " use_finup2x_buf1"); + break; + case 4: + cfg->finalization_type = FINALIZATION_TYPE_FINUP2X_BUF2; + p += scnprintf(p, end - p, " use_finup2x_buf2"); + break; default: cfg->finalization_type = FINALIZATION_TYPE_DIGEST; p += scnprintf(p, end - p, " use_digest"); break; } @@ -1346,11 +1357,14 @@ static int test_shash_vec_cfg(const struct hash_testvec *vec, return -EINVAL; } goto result_ready; } - /* Using init(), zero or more update(), then final() or finup() */ + /* + * Using init(), zero or more update(), then either final(), finup(), or + * finup2x(). + */ if (cfg->nosimd) crypto_disable_simd_for_test(); err = crypto_shash_init(desc); if (cfg->nosimd) @@ -1358,28 +1372,50 @@ static int test_shash_vec_cfg(const struct hash_testvec *vec, err = check_shash_op("init", err, driver, vec_name, cfg); if (err) return err; for (i = 0; i < tsgl->nents; i++) { + const u8 *data = sg_virt(&tsgl->sgl[i]); + unsigned int len = tsgl->sgl[i].length; + if (i + 1 == tsgl->nents && - cfg->finalization_type == FINALIZATION_TYPE_FINUP) { + (cfg->finalization_type == FINALIZATION_TYPE_FINUP || + cfg->finalization_type == FINALIZATION_TYPE_FINUP2X_BUF1 || + cfg->finalization_type == FINALIZATION_TYPE_FINUP2X_BUF2)) { + const u8 *unused_data = tsgl->bufs[XBUFSIZE - 1]; + u8 unused_result[HASH_MAX_DIGESTSIZE]; + const char *op; + if (divs[i]->nosimd) crypto_disable_simd_for_test(); - err = crypto_shash_finup(desc, sg_virt(&tsgl->sgl[i]), - tsgl->sgl[i].length, result); + if (cfg->finalization_type == FINALIZATION_TYPE_FINUP || + !crypto_shash_supports_finup2x(tfm)) { + err = crypto_shash_finup(desc, data, len, + result); + op = "finup"; + } else if (cfg->finalization_type == + FINALIZATION_TYPE_FINUP2X_BUF1) { + err = crypto_shash_finup2x( + desc, data, unused_data, len, + result, unused_result); + op = "finup2x_buf1"; + } else { /* FINALIZATION_TYPE_FINUP2X_BUF2 */ + err = crypto_shash_finup2x( + desc, unused_data, data, len, + unused_result, result); + op = "finup2x_buf2"; + } if (divs[i]->nosimd) crypto_reenable_simd_for_test(); - err = check_shash_op("finup", err, driver, vec_name, - cfg); + err = check_shash_op(op, err, driver, vec_name, cfg); if (err) return err; goto result_ready; } if (divs[i]->nosimd) crypto_disable_simd_for_test(); - err = crypto_shash_update(desc, sg_virt(&tsgl->sgl[i]), - tsgl->sgl[i].length); + err = crypto_shash_update(desc, data, len); if (divs[i]->nosimd) crypto_reenable_simd_for_test(); err = check_shash_op("update", err, driver, vec_name, cfg); if (err) return err; -- 2.44.0