From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796194005; b=Hx7D74aHxXKbQThlINlrn/1u4foq5+nu6CGG/5gaYk8aTGvNHhK6ozi8a+TY6O1FnkBg 23s5TVXGSsQAKVJ7vNWHnS5KWU3jJdAB4Lh7S8sZl7HrMIFoFBResqyRh62ZrvZ2tNFTV kKG523njizcfS9RYxWLpFvu0K7NUINGD7gy3kVYvMex8UblXMGuplVPOgNbq1NiobModZ l5W/NEzdYQ7N1ZkIkgS3E05ZiOHO6v3QdBCyqvg1WbZypEBM/EYTqOTYJvV9Jg+y5roHa FR/7ZGxqsVJDq+Ec+8bOQ7cADpYs7F4tkxh6HHePJrWlV7vpDhPQllPvkTUlxRuBSiw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796194005; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=XHd/rp/EjtIkx0yOjPC7bNcgaNFMqln0DzLqZ0exS0o=; b=qLVOQNDzF4unxx1+f32AtCPs69l7wfbggcA3YyZuvcdVFP7NWnVsC7cY4SPbiSZjjqhy m/X3avQ7WRVYLBWSBCpTCAWCXF+jJBlcHdYIzxWUTbSz7S38UyEAP0wB11K49vuH2F/Iw kokyz2KP51IvjonG1AJVzuDP67WhxGzlXYDSaZa7mPgG/NO1hV2UW7ky/oKOphMSNIUc3 xm27k3zCbdKNDyYPxVPgiKGn1Yhcp6QpDyrkrOTkveq5GZgUB58/4ka83UH3uZyp5IEgc CwgchyD0qKxj//cifFsDM07CJRQdpZ6wL42uLwEUuguPQpBb3XkFI3ep7sOp5JBXNjg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Poz7qSHr; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AC63606A322; Wed, 2 Dec 2026 06:46:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Poz7qSHr Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD9C51F0089B; Wed, 2 Dec 2026 06:46:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796194003; bh=XHd/rp/EjtIkx0yOjPC7bNcgaNFMqln0DzLqZ0exS0o=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=Poz7qSHr9a1ezc4frNRf5BRZOGmtbS1CywTFUhK3YnvmCfIRxBJMlDcu5Fm+yS4CQ VpDF1ZuI/Eryrs6bOHW4Urng8SR10raFhr3oKRNGQM2gGlRscT6XTIYm2NgQDZ+N6Y xkXv9Ua/Mvr9ExBbeNWVnhxUA8ztanreL406nSBQaLVpWjTVZr2eJ09Q3ohKJVUw8x mmhRFoF1DJVtvsmg+/yB4f9tP1OE5YupqGcL1hxVISduyVWbIhu6axSAOI/1Un1BSe y5ksZvWuGTUUskNgxqIicWPJyBBddgsFnlmwgBG4lVrmqwkj3f8ECqI1RJLSN3DKUq 4zfQDi6/kcrIQ== Date: Tue, 1 Dec 2026 22:46:42 -0800 From: Eric Biggers To: Thomas Huth Cc: Herbert Xu , linux-crypto@vger.kernel.org, "David S. Miller" , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/4] crypto: Add a wrapper function for checking the HMAC key length in FIPS mode Message-ID: <20261202064642.GA6603@sol> References: <20261201184722.887139-1-thuth@redhat.com> <20261201184722.887139-2-thuth@redhat.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261201184722.887139-2-thuth@redhat.com> On Tue, Dec 01, 2026 at 07:47:19PM +0100, Thomas Huth wrote: > We are going to need this check in multiple locations. To avoid that > we have to update each location in the future in case of changes in > the FIPS requirements, let's introduce a proper wrapper function for > this check first. > > Signed-off-by: Thomas Huth > --- > crypto/hmac.c | 2 +- > include/linux/fips.h | 9 +++++++++ > 2 files changed, 10 insertions(+), 1 deletion(-) > > diff --git a/crypto/hmac.c b/crypto/hmac.c > index 807e08b252c55..53ed48deb4b5a 100644 > --- a/crypto/hmac.c > +++ b/crypto/hmac.c > @@ -246,7 +246,7 @@ static int hmac_setkey_ahash(struct crypto_ahash *parent, > u8 *ipad = &tctx->pads[0]; > int err, i; > > - if (fips_enabled && (keylen < 112 / 8)) > + if (fips_hmac_keylen_disallowed(keylen)) > return -EINVAL; > > ahash_request_set_callback(req, 0, NULL, NULL); > diff --git a/include/linux/fips.h b/include/linux/fips.h > index c6961e932fef3..75b9ed6ec49be 100644 > --- a/include/linux/fips.h > +++ b/include/linux/fips.h > @@ -2,17 +2,26 @@ > #ifndef _FIPS_H > #define _FIPS_H > > +#include > + > #ifdef CONFIG_CRYPTO_FIPS > extern int fips_enabled; > extern struct atomic_notifier_head fips_fail_notif_chain; > > void fips_fail_notify(void); > > +static inline bool fips_hmac_keylen_disallowed(unsigned int keylen) > +{ > + return fips_enabled && keylen < 112 / 8; > +} > + > #else > #define fips_enabled 0 > > static inline void fips_fail_notify(void) {} > > +#define fips_hmac_keylen_disallowed(x) false > + > #endif The real definition can just go outside the #ifdef CONFIG_CRYPTO_FIPS section. It will get optimized out, since fips_enabled is defined to 0 when !defined(CONFIG_CRYPTO_FIPS). That would eliminate the stub macro (which does not have the same prototype as the real version). - Eric