From patchwork Tue May 7 00:23:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13656143 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 4E208C25B74 for ; Tue, 7 May 2024 00:25:39 +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=1yVNOge9Kq/Dc41mzvU8tV/tYhTfqN8pin6yH1W8IY8=; b=lN9Dc6o+ViW0rg PuE7zQ4V8WN5ZPW4kjCK35TqYuCJWoH9nwveY/7+4laNalJ0gi/VchvtcNiNN0WkI6SK/Oz33SnZI 4vJT2SDQtK9oOmfPHlmdu3Jf+xb9DwLBTXp/GXXAIXovkaZT9SGQfLGGD8WEmPtJXl3E8HINsJeBO PmbqHClzP4pycQcreAUim7/bb9aIaGxrfRGa1JVlEtcY3FOP59Mo/sZGpRJaH9TUg6ba1Bj+sFFZW r0w/FxgzNq0VM7wFlBhgVkuGy9HfneR/nkCvfrc/aynbXVbu34x1oXF/lNuEd66YxIsJ7OWd3fchR sXP2XsT21/52eyNEBOxw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s48e0-000000098va-29oa; Tue, 07 May 2024 00:25:20 +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 1s48dy-000000098t2-1evI for linux-arm-kernel@lists.infradead.org; Tue, 07 May 2024 00:25:19 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 0312A614C3; Tue, 7 May 2024 00:25:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74AEBC4AF68; Tue, 7 May 2024 00:25:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715041516; bh=Uz9jUnVkeFhGTzlbzEDSdQYkq7NwLZLlyFt/EXJFwgU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fdoVgErUHlFaNHNPh7L2HqNT2WhznXXZhVrDA03ETRpynG1rucaSJefVdt2C+j4Dg pByuM9zrY3/oKGhLDINRgqHVGjPoU6hPpffQnAsgTPBJO8WmuwAeehgVemsROA0O35 LGulunY6Bce+vgQqqhKRnCdScqv2Px2OYsSLst/Ei+5/ko7Fa9QPG/WUAabYP6KybP tGCMblilUdPk+SI7OsBRZYKJb9uEKHZ7ybTYF4XqtWww0jXcVUM4/S5juxhzlouGx1 CFGaSIC74zn60cHGQoYvGsAoAw+x4S2kEWBwZFxbSpL/RVotxMl4bkzZsZ0TzigmzZ SOCmbWoyvaPig== 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 v3 2/8] crypto: testmgr - generate power-of-2 lengths more often Date: Mon, 6 May 2024 17:23:37 -0700 Message-ID: <20240507002343.239552-3-ebiggers@kernel.org> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240507002343.239552-1-ebiggers@kernel.org> References: <20240507002343.239552-1-ebiggers@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240506_172518_513712_32740A76 X-CRM114-Status: GOOD ( 13.00 ) 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)