Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2534233lqt; Mon, 22 Apr 2024 13:36:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVAaKtirhTa6RNh1SSTvV9pP2f8kORGe6/im2Oavz55DJW0LQ0PRh8rdNKcqyzXqHaFeMGoQFj/ZgFR9qrrm3fs5OppdhSZsL/ZCQSiJA== X-Google-Smtp-Source: AGHT+IEJoeb3fFsrqEU3G06Ek1OT4R+lgmdsyo41YqlkOi0FIOaOOVJ58PFYbHaYO8LpzRqxuwdU X-Received: by 2002:a50:d4c9:0:b0:56e:2464:7c4b with SMTP id e9-20020a50d4c9000000b0056e24647c4bmr7354367edj.10.1713818174555; Mon, 22 Apr 2024 13:36:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713818174; cv=pass; d=google.com; s=arc-20160816; b=PWMCaHMAhwxX0KNGDOI30HVIUWkGDvLUEZmh4Bv8bM6C6WWtmAfEb6NbnxYZq0lOTi lF0B3GeMiAiIbdTDVN9Lg9W4tu/CNks1Yxt0mchBgANTM5orMazP35XKNri+AQHCoszh dLDvZEaTFv1ZOQB12Scnu8pj2OQuNFd8bdYmVNUrNPQH8kOOvjpJs6umkAHppaHPkOTm CGngM3xServ5KgMrDN9DQWxDWRE3iATcAoSRuakcEaUS0IDswOdjwoRpGXrjDqRj1SKY PrZZdRJOjdQJZFyZnLnAITcBj5I6etYGsw3HANe6rGpJ64dHU7pSe2/WC+JbSuaSDHRp Kv+A== 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=4mpwSuCWssh5tJZGaIGmCkomzVXcGu0csFDPw16eWxc=; fh=Oc4UeL7Acx0XOi4VhIHpcDb9W4i3PZetSD9m7YBP3X4=; b=Btf4WfZkR7WzCg+AJOky/WuXEfyKhEkgfOrQPZxe/M8dnDoD8yPx5nToAu1nPwPtPV UBLAIPnjto4ujB95eUj6ERHP2k87e0q0j3Icys8DaE6AS5zdEG8reoqh+nZyxHyJQ7F2 a8jiN5Xplsq1aDzRGWmEfSutBcjBdhMf6dYTEgEYr+th1jRJZ1JsZplLR3un6e3Afy2D er/SegdHnWCSuvTAPdTTvOENVDtKjPFh8OyA5O2TIslxX8ETtAxTp6VNEIdhQAtmE9n7 UqAt/18/yMsFRFmKBve/D+eTRqSHLXuJiLRF2wfLeuuEE+7w9VsIEPHMZGCmvOiCAY8H oH3A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Xk/q0l0D"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-3766-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-crypto+bounces-3766-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id e10-20020a50d4ca000000b0057210a7f085si1282092edj.605.2024.04.22.13.36.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 13:36:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-3766-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Xk/q0l0D"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-3766-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-crypto+bounces-3766-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 4EB0F1F21914 for ; Mon, 22 Apr 2024 20:36:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CD9DD1BC57; Mon, 22 Apr 2024 20:36:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Xk/q0l0D" 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 875041BC30; 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=1713818162; cv=none; b=YRtduT8M+cwx4nwaXkpMqh1BmI5Y/2bhBqlIEl0jSOnmvCb6jajl6r0rueIAZOnvGp6h0OwbQijEpzLBD0gVM4pIw6MFSv6titqk5eecp0E1sCVpoWNNSVrJj2IMU/9W2P57nhNLVT6jAEuiz+rk7C7pX2kMcjWYvSeiLcwJTx0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713818162; c=relaxed/simple; bh=GMvvTyTptY381bus5AKP9+Zcbl57z9O5+351qZUIEJg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a04tzGqs/g736XmBXE+1YuBLxv1DCr6/cKkJBIWwB8fzCd8m6O1vk/hIUhthPX9nyMmWaPN4TPXHdLEjfnrRsCQ2sgPWujX8sC/wUPW5HNoYA2pF2n2aN3dQRkV3AE5jb7aE7n5BwcWmfZUJFckX2XRh45GFclUETo05x+BWEME= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Xk/q0l0D; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3D41C3277B; Mon, 22 Apr 2024 20:36:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713818162; bh=GMvvTyTptY381bus5AKP9+Zcbl57z9O5+351qZUIEJg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xk/q0l0DX6W6+f1glrMirEixqabVzY39wigVDaGL0vXnkZx7JNiukS+/5qEl77Yq4 EUZM+dwyxnSryPavreuMfpWsW3NIvqOHmuGkxYBos+i2YntMk8HfjxNTLC8nhDOnUM DZ5fVAUOsP/894g2ARQVFP/K7FOADtHtJZpKp7Sp+olrClhESgYTpbF7iYh84tmuAj 2tDetLehMqV2vtvqQmahH50ohHzZvzFa1vU5cvUDmtoDHa83mO1SYKZnxkvwajlXnJ Qy4zy0o94iZCcBtqTx2qqa95mCIFxLJBsVBeQFX/WU4+alH3XYuVO/H8YB5rc+oLiV fzK3AIKALgH4w== 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 2/8] crypto: testmgr - generate power-of-2 lengths more often Date: Mon, 22 Apr 2024 13:35:38 -0700 Message-ID: <20240422203544.195390-3-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 Implementations of hash functions often have special cases when lengths are a multiple of the hash function's internal block size (e.g. 64 for SHA-256, 128 for SHA-512). Currently, when the fuzz testing code generates lengths, it doesn't prefer any length mod 64 over any other. This limits the coverage of these special cases. Therefore, this patch updates the fuzz testing code to generate power-of-2 lengths and divide messages exactly in half a bit more often. Signed-off-by: Eric Biggers --- crypto/testmgr.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 00f5a6cf341a..2c57ebcaf368 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -901,18 +901,24 @@ static unsigned int generate_random_length(struct rnd_state *rng, { unsigned int len = prandom_u32_below(rng, max_len + 1); switch (prandom_u32_below(rng, 4)) { case 0: - return len % 64; + len %= 64; + break; case 1: - return len % 256; + len %= 256; + break; case 2: - return len % 1024; + len %= 1024; + break; default: - return len; + break; } + if (prandom_u32_below(rng, 4) == 0) + len = rounddown_pow_of_two(len); + return len; } /* Flip a random bit in the given nonempty data buffer */ static void flip_random_bit(struct rnd_state *rng, u8 *buf, size_t size) { @@ -1004,10 +1010,12 @@ static char *generate_random_sgl_divisions(struct rnd_state *rng, unsigned int this_len; const char *flushtype_str; if (div == &divs[max_divs - 1] || prandom_bool(rng)) this_len = remaining; + else if (prandom_u32_below(rng, 4) == 0) + this_len = (remaining + 1) / 2; else this_len = prandom_u32_inclusive(rng, 1, remaining); div->proportion_of_total = this_len; if (prandom_u32_below(rng, 4) == 0) -- 2.44.0