Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Thomas Huth <thuth@redhat.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
	linux-crypto@vger.kernel.org,
	"David S. Miller" <davem@davemloft.net>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/4] crypto: Add a wrapper function for checking the HMAC key length in FIPS mode
Date: Tue, 1 Dec 2026 22:46:42 -0800	[thread overview]
Message-ID: <20261202064642.GA6603@sol> (raw)
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 <thuth@redhat.com>
> ---
>  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 <linux/types.h>
> +
>  #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

  parent reply	other threads:[~2026-12-02  6:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 18:47 [PATCH 0/4] crypto: Add back the lost FIPS key length checks to the hmac(sha*) algorithms Thomas Huth
2026-12-01 18:47 ` [PATCH 1/4] crypto: Add a wrapper function for checking the HMAC key length in FIPS mode Thomas Huth
2026-12-01 18:52   ` sashiko-bot
2026-12-01 19:07     ` Thomas Huth
2026-12-02  6:46   ` Eric Biggers [this message]
2026-12-01 18:47 ` [PATCH 2/4] crypto: Add back the lost FIPS key length check to the hmac(sha1) algorithm Thomas Huth
2026-12-01 18:47 ` [PATCH 3/4] crypto: Add back the lost FIPS key length check to the hmac(sha256) algorithm Thomas Huth
2026-12-01 18:47 ` [PATCH 4/4] crypto: Add back the lost FIPS key length check to the hmac(sha512) algorithm Thomas Huth
2026-12-01 20:21 ` [PATCH 0/4] crypto: Add back the lost FIPS key length checks to the hmac(sha*) algorithms Eric Biggers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202064642.GA6603@sol \
    --to=ebiggers@kernel.org \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox