From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796290408; b=1NGz+p/7GFuplpqlFAMApnTOo/DdPw2SdleLGzsAaNzCV5WYQIlgfK99gRfiwAi7Qaa6 H0oAiERwcoQhBIpO0xEWVAQ4PZOE6UeZ2DXjbxuKxbI0FQCIdof1stuFFihrobkQx/AgY aPq5qOykG/XuzduwP9hLsLXjzFSshdH/Yc1NS/br2aZWx+76ZNdBil8HbvomoAagWva98 KWWqc+mLvLx8Vr8G6IAGqa0UucK5kMUCIOp7vYdnTFlCZS3sVetwOvGjbxtDLy35XQ/LA flYbcw6UahnB/3Dt1b8RBieHW0Q2UCxpno2/xnDLLj5MOfbPZy/NkKuxL4RxhbXVmuQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796290408; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Scanned-By; bh=VwYn/TP4OukeYrF0xrEZQMVa75JEcezyDyKxH1ZnCyM=; b=DBsnG8ub0KvYlu7ShZDXCO8Qt8ELpOzVPeGtRJfHSU/je7SNYdQQmHX7sYdVuBxsGza5 lsTIvtyWifKldp6jSKaH5CBrIVdiyPHtXGLw9psACEBbhWwaS2O3dHB/iZmeRz+9K/8Hf RlQXbwqaU6oZOGnX8De/ytbV7AqDbPCpvvrYCH0cM8pJFQ3VlFNczyg++bogOd1C+vZDi 1JfSQg9IdiUHy0dW7jijh/kxf8npAuSrAVXoK5GIpDfA6naqBP3VLDw6HanvvvEttxqrc 2+9CvY455A1eemBEWvEUc4uPwsuzPF2JfixKvc6NfIDzCW6JmOLbep2G09gZx9ZUNcA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TTbYQ691; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 331C7606A332 for ; Thu, 3 Dec 2026 09:33:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 331C7606A332 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TTbYQ691 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796290407; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VwYn/TP4OukeYrF0xrEZQMVa75JEcezyDyKxH1ZnCyM=; b=TTbYQ691RqAejG58vMrrkq7omOrNtONOmdYS7axXjQMrrW4NOZwVi4Ukkxsi/QQRsrugXk 886Je77uH+6O/SmJkx7ZyeqNcs3uEBPo1P3vPAGEnFiwzmCLeOQDNmrlS56h2JDsKUTfxz rhiLkghEzQFsnyW9vr4B+8l+WjNZgzk= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-281-XZ0-FzfKOr6EWsNvwh9lQQ-1; Thu, 3 Dec 2026 09:33:24 +0000 X-MC-Unique: XZ0-FzfKOr6EWsNvwh9lQQ-1 X-Mimecast-MFC-AGG-ID: XZ0-FzfKOr6EWsNvwh9lQQ_1796290402 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 72CEC1918EAC; Thu, 3 Dec 2026 09:33:22 +0000 (UTC) Received: from thuth-p1g4.redhat.corp (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 63D34B82; Thu, 3 Dec 2026 09:33:20 +0000 (UTC) From: Thomas Huth To: Herbert Xu , linux-crypto@vger.kernel.org Cc: "David S. Miller" , Eric Biggers , linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2 1/4] crypto: fips - Add a wrapper function for checking the HMAC key length Date: Thu, 3 Dec 2026 10:33:13 +0100 Message-ID: <20261203093316.97847-2-thuth@redhat.com> In-Reply-To: <20261203093316.97847-1-thuth@redhat.com> References: <20261203093316.97847-1-thuth@redhat.com> X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 We are going to need this check in multiple locations. To avoid having to update each location separately if the FIPS requirements change, introduce a common helper function first.. Cc: stable@vger.kernel.org # 6.19+, prerequisite for the following patches Signed-off-by: Thomas Huth --- Note: Please don't backport this patch to any kernel before 6.19, see: https://lore.kernel.org/linux-crypto/20261201202148.GA501764@google.com/ crypto/hmac.c | 4 ++-- include/linux/fips.h | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/crypto/hmac.c b/crypto/hmac.c index 807e08b252c55..bfa5225a79990 100644 --- a/crypto/hmac.c +++ b/crypto/hmac.c @@ -45,7 +45,7 @@ static int hmac_setkey(struct crypto_shash *parent, SHASH_DESC_ON_STACK(shash, hash); int err, i; - if (fips_enabled && (keylen < 112 / 8)) + if (fips_hmac_keylen_disallowed(keylen)) return -EINVAL; shash->tfm = hash; @@ -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..17e7ae747c485 100644 --- a/include/linux/fips.h +++ b/include/linux/fips.h @@ -2,6 +2,8 @@ #ifndef _FIPS_H #define _FIPS_H +#include + #ifdef CONFIG_CRYPTO_FIPS extern int fips_enabled; extern struct atomic_notifier_head fips_fail_notif_chain; @@ -15,4 +17,9 @@ static inline void fips_fail_notify(void) {} #endif +static inline bool fips_hmac_keylen_disallowed(unsigned int keylen) +{ + return fips_enabled && keylen < 112 / 8; +} + #endif -- 2.56.1