From patchwork Mon Jun 3 18:37:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13684071 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 CB6EFC25B75 for ; Mon, 3 Jun 2024 18:39:23 +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=4PexGn6cNTX4GmBMvCLgP/hZivktBBDUkaa2g9tPThk=; b=kupG1FkffFRQyb hvoy/ceRJIrkDWkcsqDCuxQEQVs1i1Wk9SiXGwSm8jZidHIUsXuMpLs/5yI9I0JkCsL5k/IDCOuJM iFPfuhRWqsLtp+SRN4DM6uFQ1u1N747YlHl0D0PDJea1CEEPLdz9KTIBpUCKQ0swlXzEhd5WWCmgZ yAu/R6qtQSiXkfRGd7Hyvn69OrXViuEEwKCdnCFTMlM81WGhWvJwSlfBMSN9NwOx/+MTlRt6XCEEl 4hfVWjcxe5VIOH5Aiz/ldWIDJfQwNrs5LASVSp+OI9xUryEUJiedW5IAGjPHhvXI0jpPJsqUsXLiA qe0LAUle54jCwdbTQ3Jg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sECaO-000000002jk-3j8N; Mon, 03 Jun 2024 18:39:12 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sECaH-000000002cX-07Dj for linux-arm-kernel@lists.infradead.org; Mon, 03 Jun 2024 18:39:08 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 4194D60F56; Mon, 3 Jun 2024 18:39:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ABA08C4AF0C; Mon, 3 Jun 2024 18:39:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717439944; bh=x6BpOkZDth1TELblCpsyj+k4HXeki2UgF3oymt00wPQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bjygecmDtViAWcFTVGQqDXqZqubTgs2At4eNDnwjZX8B2LaBrW6cMtNEjPf65Hl4Q ISdjeHXuF0nci26Q0PAlY8/Wh0A9VV1tr9MjlptBoxoqllTJ0+/vpJLB6BZ5pJrf3w QhfE0m0F/W1P8eMP+TrldFQ7XMw9fJbFfWQ46tRN8XRMD5KUQZ1fgcyzaCTNRAqNXo HfnRvkS3NY86oLpmB7TMWPpFCFtHQkrcH4OSNYqDQn3NTBUvsS1ogYMMMJ8pK3zZMx iKhelu60NcvKydJaJoPs0S/c6HE+iZrlSWaDrW/PfhkrVmQNN5OItJ+JO6k5apuK0n XjSN4bVSoqPAg== From: Eric Biggers To: linux-crypto@vger.kernel.org, fsverity@lists.linux.dev, dm-devel@lists.linux.dev, Herbert Xu Cc: x86@kernel.org, linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Sami Tolvanen , Bart Van Assche Subject: [PATCH v4 2/8] crypto: testmgr - generate power-of-2 lengths more often Date: Mon, 3 Jun 2024 11:37:25 -0700 Message-ID: <20240603183731.108986-3-ebiggers@kernel.org> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240603183731.108986-1-ebiggers@kernel.org> References: <20240603183731.108986-1-ebiggers@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_113905_154791_D0F79B9C X-CRM114-Status: GOOD ( 12.83 ) 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 | 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)