Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp217732lqh; Mon, 6 May 2024 17:25:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVOTci1HGZH/o8CY758pSRfRKTxRqtH79cgVzq5TWDMadKK8osPd0p0YV1ACC+zg5DYmS9k4igSTdT5ohbUcE3Y3SxBDdkyvwNgBawZ9g== X-Google-Smtp-Source: AGHT+IHsg2g9x3XAV1psWBF+FEnirlYDZ6X3tZZn09jcj5YIgt16jGYPuYTx9JiyCVqMYoCGzj4U X-Received: by 2002:a17:906:2354:b0:a59:9ed5:eefc with SMTP id m20-20020a170906235400b00a599ed5eefcmr796643eja.32.1715041531145; Mon, 06 May 2024 17:25:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715041531; cv=pass; d=google.com; s=arc-20160816; b=m4L27D6uYodMksnw2+VzmV8D4hJHS/jJWTAcJxx2d2DcTfm9IGp1IFlq83AGM57j5B 8UaRbOXKOGRO1ZvvVIOHh7kZ55X05CV6WCEdUL88EArjcxSpeufw+v33aQmFEW2BkHam YCcgn38Gdlz7XpUkKqaI3Sg45FNj/bhg6h0UZkgce2F+tg9lm8PpOmVWKDCBmv8ULC+8 HpabWv6Ffust5ZnGHMGN4AXQZbKhddeNd8mIjPx4CnJ80e+E6NNLGR0V3KWDY0Tq9nll pJ7ZXFPFnuYU6putzUbjY4GPVXEAjYOR/JUVewEI1j4UBCARNVd4fraPOiaYucZeN0BG Ly4Q== 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=pAEtVhoD/k8Bi51UyFW3CzVeV8dd86khoHc9VZi2MWQ=; fh=Oc4UeL7Acx0XOi4VhIHpcDb9W4i3PZetSD9m7YBP3X4=; b=i2y85q/XYNTdv7XQWXa7XI5aH1g4PcaJWXdAarbpOjKcAd6nNvjTnOdTX/Mpn0NSH5 o2dCrdujElTDFO2KcSdkUZD2/MBZOc/n8jzOqdkkQKLWBVfXN2Dw84wzpTjDvXylIeUr M3KAEEks1ycjKdl9FgW3sDHN9/j/GatlpTmbEdwj8yUczhyjOjZEdtIOtYRBnGcwbUAh qtzE2M74dkXjPIo/QD4o1drR0dSLERm3jcTyqtzvaeefvr9euQrLZQDaHN1OSLjwUkO1 ijJtXETW95UO5EZvYWgWR1tYRqeDB9a+pegTPcIKkysHX6UZOOKUrq/9Hl6FCoXdtANY AEcw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fdoVgErU; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4047-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4047-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id dv13-20020a170906b80d00b00a59a4370e92si3656716ejb.479.2024.05.06.17.25.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 17:25:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-4047-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fdoVgErU; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4047-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4047-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 DD32E1F233B3 for ; Tue, 7 May 2024 00:25:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6B09315C3; Tue, 7 May 2024 00:25:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fdoVgErU" 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 23DB8EDE; Tue, 7 May 2024 00:25:16 +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=1715041517; cv=none; b=Zl07JVnNGXXb6rKBJrsVNDEjoQ7fMxrQhYmAKzTf8G4lMxFl1IIZOhPGPHxC7eAIbO4BNuZo27bkGjyFkeWV5xBrldiiw56lzQlXP28z+PJIr7xLFT51tVHUV0xj77QEek2TJiqgBcJ3TTw/2+YqmzOjTdXqRbYE1nD+x3d+62U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715041517; c=relaxed/simple; bh=Uz9jUnVkeFhGTzlbzEDSdQYkq7NwLZLlyFt/EXJFwgU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ub8kRpAD+bbYa3fyv0tkLOUic9U8Nvm8OwLtUSh3ua5T+xkKoy7048nAxk4L2Tu0aN+1MlpTxymJcWcHzV3dJcdBmd712B5XDNep3W9uM8U4jCPzqNqa2Z734blpoADwP6pCSq95Bgys0rAKXx4cXjPUX0RfnEWth3+aWuLwWEI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fdoVgErU; arc=none smtp.client-ip=10.30.226.201 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> 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.45.0