From patchwork Sun Oct 22 18:22:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dimitri John Ledkov X-Patchwork-Id: 13432039 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BAD19CDB474 for ; Sun, 22 Oct 2023 18:23:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=f4VY2QIQHex79Rw02I39OmSX7HDHgYTFoiVIDI9BLZI=; b=Bti2KzjcW0t0oH buQop7WlWz3i8tRGz7G41HCfj63fUAjb6dmzKjQoRsNGkKHiyJRamnR+VJz6se6xmcAhkwOUgCfKO nRLbDB2f74ccGxXQoBp4goAw0fPOl8aSyNrGBj9FxptieCB3GjjiVE8HiPqSI9pvDgHNLAaoxsEYL ck3c9NnybpzUreCsB6hYW21AeRUQsIZbL5KkymC1M/F5Sd81EsfW+hi2oIXch1TqFzfO/+q832HDd gg6fcw/3JHZtKMWtBEY8mNQvN25fnLGVg8xM+liMhI7iw0yxkXV0z6a6uTR/IAXwo9aKIikEM0q42 45rWX9S89HyOG/ewoG6g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qud67-005o48-1B; Sun, 22 Oct 2023 18:22:47 +0000 Received: from smtp-relay-internal-0.canonical.com ([185.125.188.122]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qud63-005o3E-0n for linux-arm-kernel@lists.infradead.org; Sun, 22 Oct 2023 18:22:45 +0000 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (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 smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 09CA63FA76 for ; Sun, 22 Oct 2023 18:22:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1697998959; bh=G21LvQrZs30vZixQb7qoXSrQRZ+ChOighJd9yL5njGg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XnLrftOr4IzrIg6cLChua4GUyA7wkyQ1FEcZY+2hgAW5v6y0g2Kqf42SABbfzQg+X rODK3UdeUNWirZhNFaPwrAt6J3GiyQROkocFTYFiR/Gt1jgApA3tmMSmE8kIK0m59A is3d7xugP6mupXvo7unbGvzrpnNquVy586RRc1Qx5tRDib2wb9CECVwh2vPnNSx9PH Q8QNi5sTP2AkdoUe9ixAqglbwxC4cOJwoJJ8zJIJWenGZkLjrvm3OXGL7fX/TiDmBb dlCIACGlj9q5MuNZp5kErnJVTSDyN5ozNKlSlnoRmd/jyzOtqDphwqrPZnuZMlz7RN y6A4xcCfEKsdg== Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-408695c377dso5951105e9.2 for ; Sun, 22 Oct 2023 11:22:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697998958; x=1698603758; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G21LvQrZs30vZixQb7qoXSrQRZ+ChOighJd9yL5njGg=; b=pEFZ66ah/BJFDb9g3JYsAW88wUBzpz0my/Ccx1yk5VC5cVZD/cHRt1T3WQJRQChvCV Z2aKR0Uv0qGcoeCdEAevqc04IXvFPjZOroO/3gfUnx5fvwQ3U+1J20OXenQjpMUfG1V1 eFLGjHNho4kCEnfNI3x+W+tYl+NNJ4I71bjQxbanVe2zuQ7iJdRFfy+xF48GUmwGOO6p TDqCPbJfGC10a0LIBoqUC/HlJA5VydQFuHwBo7JiMo1+1wLKe/Mgn+RzqRCM34OVi8Yl IJgAiS0oKLdzMKtDAO2soI0CuyTPo6ludDhIfODGvFeFdeDZXiClaswmDL/hDqP5GjOF AiKg== X-Gm-Message-State: AOJu0YyMFfSlEtPFKBr4Wpyh3zMl3GSfu8S9mfY9oBIEEJoCABsKxbZ7 5z4uDZaB49tOdqa7bCgM4RcbzY6uLSdsPY9X/H2Q1C5/E3KIjpa6sRBHr1JPoLLbd2GKgXi9odk D6gZR3BLFK9oVA9A1JtPEnUSdSznf80oh0Bm3ZR4bGHbEKqWcJM+6 X-Received: by 2002:adf:e387:0:b0:321:6779:944d with SMTP id e7-20020adfe387000000b003216779944dmr5166511wrm.47.1697998958655; Sun, 22 Oct 2023 11:22:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHAZvQT1bUdK5D86F47MwaUC8hGREbp8ZcoKdB+ACNOR56da1Ev4XH0crCuR05/TvtIF23FDw== X-Received: by 2002:adf:e387:0:b0:321:6779:944d with SMTP id e7-20020adfe387000000b003216779944dmr5166502wrm.47.1697998958286; Sun, 22 Oct 2023 11:22:38 -0700 (PDT) Received: from localhost ([2001:67c:1560:8007::aac:c15c]) by smtp.gmail.com with ESMTPSA id k17-20020a5d4291000000b0032da87e32e2sm6143324wrq.4.2023.10.22.11.22.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Oct 2023 11:22:38 -0700 (PDT) From: Dimitri John Ledkov To: herbert@gondor.apana.org.au, "David S. Miller" , Maxime Coquelin , Alexandre Torgue Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH 3/6] crypto: rsa-pkcs1pad - Add FIPS 202 SHA-3 support Date: Sun, 22 Oct 2023 19:22:05 +0100 Message-Id: <20231022182208.188714-4-dimitri.ledkov@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231022182208.188714-1-dimitri.ledkov@canonical.com> References: <20231022182208.188714-1-dimitri.ledkov@canonical.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231022_112243_536077_CE16DC7C X-CRM114-Status: GOOD ( 13.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add support in rsa-pkcs1pad for FIPS 202 SHA-3 hashes, sizes 256 and up. As 224 is too weak for any practical purposes. Signed-off-by: Dimitri John Ledkov --- crypto/rsa-pkcs1pad.c | 25 ++++++++++++++++++++++++- crypto/testmgr.c | 12 ++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/crypto/rsa-pkcs1pad.c b/crypto/rsa-pkcs1pad.c index d2e5e104f8..e32e497d29 100644 --- a/crypto/rsa-pkcs1pad.c +++ b/crypto/rsa-pkcs1pad.c @@ -61,6 +61,24 @@ static const u8 rsa_digest_info_sha512[] = { 0x05, 0x00, 0x04, 0x40 }; +static const u8 rsa_digest_info_sha3_256[] = { + 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, + 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x08, + 0x05, 0x00, 0x04, 0x20 +}; + +static const u8 rsa_digest_info_sha3_384[] = { + 0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, + 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x09, + 0x05, 0x00, 0x04, 0x30 +}; + +static const u8 rsa_digest_info_sha3_512[] = { + 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, + 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x0A, + 0x05, 0x00, 0x04, 0x40 +}; + static const struct rsa_asn1_template { const char *name; const u8 *data; @@ -74,8 +92,13 @@ static const struct rsa_asn1_template { _(sha384), _(sha512), _(sha224), - { NULL } #undef _ +#define _(X) { "sha3-" #X, rsa_digest_info_sha3_##X, sizeof(rsa_digest_info_sha3_##X) } + _(256), + _(384), + _(512), +#undef _ + { NULL } }; static const struct rsa_asn1_template *rsa_lookup_asn1(const char *name) diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 54135c7610..a074430223 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -5468,6 +5468,18 @@ static const struct alg_test_desc alg_test_descs[] = { .alg = "pkcs1pad(rsa,sha512)", .test = alg_test_null, .fips_allowed = 1, + }, { + .alg = "pkcs1pad(rsa,sha3-256)", + .test = alg_test_null, + .fips_allowed = 1, + }, { + .alg = "pkcs1pad(rsa,sha3-384)", + .test = alg_test_null, + .fips_allowed = 1, + }, { + .alg = "pkcs1pad(rsa,sha3-512)", + .test = alg_test_null, + .fips_allowed = 1, }, { .alg = "poly1305", .test = alg_test_hash,