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=1796290409; b=Pdvdw8U6vUng334EMg1eFwAPXc0SRENGS0gpX0fjgN2Twb2Yia9dRNZDe7BBXV+fYOlx Y+HSBRWL50wnTboBuhdHba9muNFQhQaC1hiG989ntVQiWH0xmy7XCVMn0+6BeVvbJLzc4 AXtgoZJuvBEWacvWRLzviBOXyY0p8gWcI0XBB+cUmJgNNRgM+MUQeRe6Xxfc+hVUoeQQp uxDsohN4+v/P20vkKEixs5zQnPFKVHDL6P6XTHV7sI9FAQTUGe1xPtx6/2wdvg5iHT+yU 1rg3PWxsa1nV0wwl8eDlhM2sTfOEppNPUGowCUNe2mENw4h/kAC9u6r5/Llm/jei8bg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796290409; 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=PsDBGKNFkmxivl44qWMiB7OBFrkcvzqU0S3BiKJoVY1wuX3a6iWnZ+cG4LHnYeDhia4F FpnMPjgZjkdJwCStOYz+W5oMU2oo/u19j3oGXgk1RQ2fL4rJoLIvb6oH+Pb096w1nXLfS e9HjuWcAccNglZNZB/pKb63ue15OsoIWDRaTRoLfMPus7ssHnBo+NMy8b+vgTz/ZO/eOh WYIUoBGTMI14HnMGzVLZgDM43BcudcSe+h9L7fniePY2HsC65gpp89qJBRtmI34tOSz65 gF8qsgQMBCeBdhHiAbXsP1FdNbtHKkNbEHiKrEh/2vNmTh/n1x8qJ1288X1SAK22b/w== 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=itAxaCdt; 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 DC762606A686 for ; Thu, 3 Dec 2026 09:33:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DC762606A686 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=itAxaCdt DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796290409; 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=itAxaCdtUiEGiSTth10ky3K6uWC+SMmQN19EIWLyoIqRCzjkSUbvjkLgHBF+IAfXPhMKuL 81Za87darS4x+6SumEa3NuYSO9nl5Y764A+vOjlD5ncKSHHqNORagGWEHv6CM384VgD6/s 2d/GwbCIRNgogFrvtDVEj9hnHR5p/eo= 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-kernel@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