From patchwork Mon Apr 15 21:37:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13630755 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DB446C4345F for ; Mon, 15 Apr 2024 21:39:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ZoyPxSQ6HpCr6GdTUveQRnKrx/L6FYzJmbqT53cxXqg=; b=oW8A2ycTNjdUoq sqYYSLasOzwr7MecHmjEFWhzr7Bh8BfHKuqNGwkmk4jSwR+rROOsffizqAXjXiRuzphuPLUojvyaF JbsrCKb1nK1D5OztJBNPMkbcq78Vcw8GOVdYf1F50UbGHSphw+WmXDkb0HkjB/pJSwleytweQWvTE +3DyloVW07dL/N9GUHXIDjGQjPBpd3il3hFPwc2Nx1cc5lhidCZxAHnqZxzeMJE1TT7l93up3A/4a 6sZbEtzGGbkc8SccTVEI5VI611vLxjgbspMBHajgJksCLIrAbHluZYTNxN7EwjDZZV8biy7LobM5K MUOTgOhpfxmLueg2YBKg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwU2b-00000009zBR-2WiA; Mon, 15 Apr 2024 21:39:05 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwU2N-00000009z2c-3tQn for linux-arm-kernel@lists.infradead.org; Mon, 15 Apr 2024 21:38:55 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 17816CE0BA1; Mon, 15 Apr 2024 21:38:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B7A9C4AF07; Mon, 15 Apr 2024 21:38:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713217129; bh=7EeMhSwgfXHIxMBvok4WynVvjspAaaT/x9LSuah1mWA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=apE+WaJBVTRpZ06MLaJm1+uhetGmGUYYcBMHvgLZhO/1pHcokq4mrSb2AvKhTeRwf xgQHbuWmNISyO2WTgLlgnyaC/I9K5EKor3mU1h9hb5332peW7y0H3rrDe67N7WjlDt +OzW4TS+DpYD457BwLOg1/uSGFPtc6Vjv4mtI5sj01Bihh/ZF20hn5t6WwdT4n2nxF NkPOvElsVJc6/AuVe2U5jUNgbV0ZvHt1pSmB5op9tfZAi7dJPtzWjCz1JcleaA7MkK 8CbhbEdXhWaW0PjNxvfXhtkr8JwOBZlTLXXLD55DvPoSfLNaEaaXaGiC7PneW8s5MG FswQ1M7NTA0xQ== 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: [RFC PATCH 2/8] crypto: testmgr - generate power-of-2 lengths more often Date: Mon, 15 Apr 2024 14:37:13 -0700 Message-ID: <20240415213719.120673-3-ebiggers@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240415213719.120673-1-ebiggers@kernel.org> References: <20240415213719.120673-1-ebiggers@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240415_143852_320215_122858F4 X-CRM114-Status: GOOD ( 12.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 3dddd288ca02c..2200d70e2aa9d 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -899,16 +899,18 @@ static inline u32 prandom_u32_inclusive(struct rnd_state *rng, static unsigned int generate_random_length(struct rnd_state *rng, unsigned int max_len) { unsigned int len = prandom_u32_below(rng, max_len + 1); - switch (prandom_u32_below(rng, 4)) { + switch (prandom_u32_below(rng, 5)) { case 0: return len % 64; case 1: return len % 256; case 2: + return min(1U << (len % 10), max_len); + case 3: return len % 1024; default: return len; } } @@ -1004,10 +1006,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)