Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2715420pxb; Thu, 3 Feb 2022 12:35:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJyXDekazW9UEOfx/7uy67rw/R/LwSSdHsMrk90uTpZb95hd244m7el099GJFur7vnFuYZO0 X-Received: by 2002:a17:902:6b06:: with SMTP id o6mr36589644plk.162.1643920523944; Thu, 03 Feb 2022 12:35:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643920523; cv=none; d=google.com; s=arc-20160816; b=G4+BFVp2/pPOgUX/zTG/xht4LEKrbcjU1PdNL8g97CbyWy0ybgpYVxgTu0pG1BTHJp NBfyPxedvl3OjrSwnhYe9oFG1BJQfG/wyXi6G5oQuyUru3EdkkqnNoeEV1ZXZXiccJmj TlbtWHIfxZYuFM2lCiq53tznnko2/glpa2kV07zuU+A4E0Rlpma3VH22Hvz9ER5OdXfB d6YK6U7fDhuzVrJEqWcjVOfwOyLcaTof9eqrSe1aUDUgb7CNl1gOvJduBhv/oUXd4qMJ nSqZ7Jt4cP5+8klZ1ACY4PSMdiGiXbbd/8U/tmm4qCuFiDq3z28+Aq8DX+psQR0WIZ9a ZCXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=umL7/7M8PKPS10nEN4wTl9xQHWEq8qbSqviM0UlZA8c=; b=IiXhAVsClKLqh6FYOcEhrAL1c6X924sQjXEdRxsgcgb9FNnfRCWHJaaoJ0oa73xLhs I3rVE9A1ldnkSdl56EnVT5KKuJF94Ke/gpZSNGfsBLF52mll4PxhRP92bRQuMzUdm+0n IqPbO2stedGeNIspek5j/Ya3OJXL87Dn6k/VFmX8JEI8meLCXXYKFZ2czaOzhOuibN0K nZIZLFrV2RoKDw8xoiRSdik6lpB1K1ceAGPyN503P3+n7f0Gtzmb+abtYJyI6EAUx3/Y /W9+eessgwf9x4cDpyCBfTVfK7ehLkyT/bw1YEt9CY+XpyYNJDgAk36UIDSPs40N8XB/ EQ1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chronox.de header.s=strato-dkim-0002 header.b=rC73LZRq; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x38si24324086pfh.310.2022.02.03.12.35.08; Thu, 03 Feb 2022 12:35:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chronox.de header.s=strato-dkim-0002 header.b=rC73LZRq; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235571AbiBAImP (ORCPT + 99 others); Tue, 1 Feb 2022 03:42:15 -0500 Received: from mo4-p00-ob.smtp.rzone.de ([85.215.255.24]:40445 "EHLO mo4-p00-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234940AbiBAImO (ORCPT ); Tue, 1 Feb 2022 03:42:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1643704925; s=strato-dkim-0002; d=chronox.de; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=umL7/7M8PKPS10nEN4wTl9xQHWEq8qbSqviM0UlZA8c=; b=rC73LZRq9nJmajhz5BTzdqch25MLgFVH/io6Q9wu/58BACxykm2mHGYIYcT2s3SiZn kn96GdgjGcwrfFsnot78qSa+TUG2XPLLCfawjxZ7Kn9ZPlJwnZ1ydE6WlVq8B3N+PAvF yvi6m26rEL4DdDYQeTI3oR1c5puXUnUbppGM8If0FgX+KB/LZ/GQiZdY3J1bmJecg7Wa uTC9VzHaoiI/EUcQL4nLiLzFRRyYHUl8S1mC6i1YJ/zTG1caMFJbzpY1PJiiplKzYlg4 1NRBIaFWOA+bDVVv2ODTzaq70R0S2lcAJXF2T2WBzshwL9QXC57hSYdWBluGs3frEQ0B tSbg== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2ERcEykfu11Y98lp/T7+hdri+uKZK8TKWEqNyiHySGSa9k9zW8BKRp5UFiyGZZ4jof7Xg==" X-RZG-CLASS-ID: mo00 Received: from positron.chronox.de by smtp.strato.de (RZmta 47.39.0 AUTH) with ESMTPSA id z28df7y118g43Jo (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Feb 2022 09:42:04 +0100 (CET) From: Stephan =?ISO-8859-1?Q?M=FCller?= To: Herbert Xu Cc: linux-crypto@vger.kernel.org, Niolai Stange , Simo Sorce Subject: [PATCH v2 2/2] crypto: HMAC - disallow keys < 112 bits in FIPS mode Date: Tue, 01 Feb 2022 09:41:32 +0100 Message-ID: <25394269.1r3eYUQgxm@positron.chronox.de> In-Reply-To: <4609802.vXUDI8C0e8@positron.chronox.de> References: <2075651.9o76ZdvQCi@positron.chronox.de> <4609802.vXUDI8C0e8@positron.chronox.de> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org FIPS 140 requires a minimum security strength of 112 bits. This implies that the HMAC key must not be smaller than 112 in FIPS mode. This restriction implies that the test vectors for HMAC that have a key that is smaller than 112 bits must be disabled when FIPS support is compiled. Signed-off-by: Stephan Mueller --- crypto/hmac.c | 4 ++++ crypto/testmgr.h | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/crypto/hmac.c b/crypto/hmac.c index 25856aa7ccbf..3610ff0b6739 100644 --- a/crypto/hmac.c +++ b/crypto/hmac.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -51,6 +52,9 @@ static int hmac_setkey(struct crypto_shash *parent, SHASH_DESC_ON_STACK(shash, hash); unsigned int i; + if (fips_enabled && (keylen < 112 / 8)) + return -EINVAL; + shash->tfm = hash; if (keylen > bs) { diff --git a/crypto/testmgr.h b/crypto/testmgr.h index 17b37525f289..85ccf811f5e7 100644 --- a/crypto/testmgr.h +++ b/crypto/testmgr.h @@ -5715,6 +5715,7 @@ static const struct hash_testvec hmac_sha1_tv_template[] = { .psize = 28, .digest = "\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74" "\x16\xd5\xf1\x84\xdf\x9c\x25\x9a\x7c\x79", + .fips_skip = 1, }, { .key = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", .ksize = 20, @@ -5804,6 +5805,7 @@ static const struct hash_testvec hmac_sha224_tv_template[] = { "\x45\x69\x0f\x3a\x7e\x9e\x6d\x0f" "\x8b\xbe\xa2\xa3\x9e\x61\x48\x00" "\x8f\xd0\x5e\x44", + .fips_skip = 1, }, { .key = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" @@ -5947,6 +5949,7 @@ static const struct hash_testvec hmac_sha256_tv_template[] = { "\x6a\x04\x24\x26\x08\x95\x75\xc7" "\x5a\x00\x3f\x08\x9d\x27\x39\x83" "\x9d\xec\x58\xb9\x64\xec\x38\x43", + .fips_skip = 1, }, { .key = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" @@ -6445,6 +6448,7 @@ static const struct hash_testvec hmac_sha384_tv_template[] = { "\xe4\x2e\xc3\x73\x63\x22\x44\x5e" "\x8e\x22\x40\xca\x5e\x69\xe2\xc7" "\x8b\x32\x39\xec\xfa\xb2\x16\x49", + .fips_skip = 1, }, { .key = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" @@ -6545,6 +6549,7 @@ static const struct hash_testvec hmac_sha512_tv_template[] = { "\x6d\x03\x4f\x65\xf8\xf0\xe6\xfd" "\xca\xea\xb1\xa3\x4d\x4a\x6b\x4b" "\x63\x6e\x07\x0a\x38\xbc\xe7\x37", + .fips_skip = 1, }, { .key = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" @@ -6640,6 +6645,7 @@ static const struct hash_testvec hmac_sha3_224_tv_template[] = { "\x1b\x79\x86\x34\xad\x38\x68\x11" "\xc2\xcf\xc8\x5b\xfa\xf5\xd5\x2b" "\xba\xce\x5e\x66", + .fips_skip = 1, }, { .key = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" @@ -6727,6 +6733,7 @@ static const struct hash_testvec hmac_sha3_256_tv_template[] = { "\x35\x96\xbb\xb0\xda\x73\xb8\x87" "\xc9\x17\x1f\x93\x09\x5b\x29\x4a" "\xe8\x57\xfb\xe2\x64\x5e\x1b\xa5", + .fips_skip = 1, }, { .key = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" @@ -6818,6 +6825,7 @@ static const struct hash_testvec hmac_sha3_384_tv_template[] = { "\x3c\xa1\x35\x08\xa9\x32\x43\xce" "\x48\xc0\x45\xdc\x00\x7f\x26\xa2" "\x1b\x3f\x5e\x0e\x9d\xf4\xc2\x0a", + .fips_skip = 1, }, { .key = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" @@ -6917,6 +6925,7 @@ static const struct hash_testvec hmac_sha3_512_tv_template[] = { "\xee\x7a\x0c\x31\xd0\x22\xa9\x5e" "\x1f\xc9\x2b\xa9\xd7\x7d\xf8\x83" "\x96\x02\x75\xbe\xb4\xe6\x20\x24", + .fips_skip = 1, }, { .key = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" -- 2.33.1