From patchwork Tue Nov 8 14:20:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolai Stange X-Patchwork-Id: 17060 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2740701wru; Tue, 8 Nov 2022 06:27:56 -0800 (PST) X-Google-Smtp-Source: AMsMyM7meeP3OJdtm0V3J0sClNe5MkVP2hCLnYYLx+7XkV+ONlOReNbJKI4q+r4efpXdIVPsilq2 X-Received: by 2002:a17:90b:2246:b0:213:48f0:297f with SMTP id hk6-20020a17090b224600b0021348f0297fmr58314159pjb.236.1667917675948; Tue, 08 Nov 2022 06:27:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667917675; cv=none; d=google.com; s=arc-20160816; b=DGtLxeup1aIAlnrMGqomVk81qf2QFl/3dxgB5DKnchhYFggpMTf8GF9Ds+9pdVWniG qPbE58AWMA4fPi2yWdQtfqXRtTs2ehuLA9/Ulj4NGuzwllRB1Ogb35ifBPqk4JzqSc3b tZNsQYYFu2XKoe1zu2/P5uofHQ9nqoN8DqaUGFevLCq/lZo8EFQnWOh+glplJWgCrm0g YeujN6WAna18z9Bk+koeYZ3rAIfT9/wR4u7agKOcGhCoo8ZblkNGHeExJaPEM4YtPPr0 YCHZO+Ody6NXbhQ+TTdgHCQr+a4i0SEVkaoqx3xTxiAu+oAlVBXf9nsAYVmicEkIXfR1 4SAQ== 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:dkim-signature; bh=uG7bkbR8f1ErSbpnIswqV7scwgYtGlwKnO07NfMV1Ro=; b=0p8/QExrVSKMptJUjy9ATz397KJGqpnjtliCsyY6ZCbN0lZGIdXctwV7lWUn0W8eTp /mB4MkyRNbr70k5hPjunC3bgzhQ8DruGYHneQUHdqLIoUnE+4cK2oI6FN4aYKzAY1oIS pqb4/+ZTVvArRyJuw3XWPKd/fh0xSRbQO8n6eo5uuBpuixqoF65Dk28IxDR2B7FpIoTN UtTB6rwt9MacguPSO1+fA/5gHsSRcxPZ7A5ZYo91y45q7ReggBUTPuFjFMTThmU40pLa 2fDT1o48R4xqez9uowTNoB6hTHdVAdJel8OcSkKEfHu/uhzRuI2r3hU4hchSRAWQ6JaR 8LeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=S2tQIpOs; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=KlJyrsTf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b11-20020a17090a9bcb00b00216058fa03fsi15096185pjw.53.2022.11.08.06.27.36; Tue, 08 Nov 2022 06:27:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@suse.de header.s=susede2_rsa header.b=S2tQIpOs; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=KlJyrsTf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234737AbiKHOU5 (ORCPT + 99 others); Tue, 8 Nov 2022 09:20:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234651AbiKHOUt (ORCPT ); Tue, 8 Nov 2022 09:20:49 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72C36862D2; Tue, 8 Nov 2022 06:20:48 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2D9EC22A9E; Tue, 8 Nov 2022 14:20:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1667917247; h=from:from:reply-to: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=uG7bkbR8f1ErSbpnIswqV7scwgYtGlwKnO07NfMV1Ro=; b=S2tQIpOsR9mMrPkL1xyeJAXruYNrjsUZ6HF8BLdHGTnO80bnA4iQkodZli0rCTWp17IWc8 G6kffZIEF11rAdTdbELZu1ST4TdSTXfL63M0DMnRrH2pmqypMjsfkU+No7jDGUW6teZcNJ PWzOVo6S0JUb+DhSXB3gdpuJQuSP/vM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1667917247; h=from:from:reply-to: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=uG7bkbR8f1ErSbpnIswqV7scwgYtGlwKnO07NfMV1Ro=; b=KlJyrsTfyiJ5AaM/jlA9pToJSlXsFBVquwdB4l/WR9qI2U1mbUcggpwAbxZgZCNIAzPvsU DmdguqNlPjek2aAQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1F98E13398; Tue, 8 Nov 2022 14:20:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id kBtiB79lamMTKQAAMHmgww (envelope-from ); Tue, 08 Nov 2022 14:20:47 +0000 From: Nicolai Stange To: Herbert Xu , "David S. Miller" Cc: Vladis Dronov , Stephan Mueller , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolai Stange Subject: [PATCH 1/4] crypto: xts - restrict key lengths to approved values in FIPS mode Date: Tue, 8 Nov 2022 15:20:22 +0100 Message-Id: <20221108142025.13461-2-nstange@suse.de> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221108142025.13461-1-nstange@suse.de> References: <20221108142025.13461-1-nstange@suse.de> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748938445030610812?= X-GMAIL-MSGID: =?utf-8?q?1748938445030610812?= According to FIPS 140-3 IG C.I., only (total) key lengths of either 256 bits or 512 bits are allowed with xts(aes). Make xts_verify_key() to reject anything else in FIPS mode. As xts(aes) is the only approved xts() template instantiation in FIPS mode, the new restriction implemented in xts_verify_key() effectively only applies to this particular construction. Signed-off-by: Nicolai Stange --- include/crypto/xts.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/crypto/xts.h b/include/crypto/xts.h index 0f8dba69feb4..a233c1054df2 100644 --- a/include/crypto/xts.h +++ b/include/crypto/xts.h @@ -35,6 +35,13 @@ static inline int xts_verify_key(struct crypto_skcipher *tfm, if (keylen % 2) return -EINVAL; + /* + * In FIPS mode only a combined key length of either 256 or + * 512 bits is allowed, c.f. FIPS 140-3 IG C.I. + */ + if (fips_enabled && keylen != 32 && keylen != 64) + return -EINVAL; + /* ensure that the AES and tweak key are not identical */ if ((fips_enabled || (crypto_skcipher_get_flags(tfm) & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) &&