Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp171262lqb; Thu, 23 May 2024 14:26:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVBovfJ3EiYZHaitrA1DxIn1CzYjPT8JTsRcX8Truh4ckeKZ9A7qBM9DTfvnIhcNQgjbBVfs0HWLmPsfNHNVv9GP35wjQoXC9TtGs9I+w== X-Google-Smtp-Source: AGHT+IGsppAnBlY4lhBLFjSbNluLUVsz4eogHd+4XAQVq6P3g65+3wW1/L2Ao0deugWlL/ozP6d3 X-Received: by 2002:a05:622a:1304:b0:43a:712c:f985 with SMTP id d75a77b69052e-43fb0e88d26mr3824581cf.56.1716499583153; Thu, 23 May 2024 14:26:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716499583; cv=pass; d=google.com; s=arc-20160816; b=u+mrj92SMFYOJ7Vflnt9DZ6LhIriXeAcqNW0P9a8EuVQJWq6Boy2LVyVqyj6wvwr4R bD7sMb77OYFgC3K5pDftw5BugRY9zUVZE9Sa7zjKj0Vxw0NaVUYuFO3IZc/AZbrJvrkI hWzFN5ixgCisvPw/YTIJIl0FqOAXz6xhH2QFqbCTgR4B44LXLK+mvyDleJ2x8Gmqm2Ls AUBRKvj2B0S9MIcQGn0sFK7CDKphqUN78dLlaFkmhwLp59hP8iubcrErd9ll3LHEL7Ot Yux9LJB+Q+asE359a1t4G7Ne9XBwlfo0kbJw0UGhf0HtsY6GJspN037fotX5sR3VQ/tL 1fPg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=43Sb18VKUhg0R2Kq+8TU0oUqFnZm/9MPZAGvJnbIyCs=; fh=HJ8tKstv3+1Dycb4MUp5bfy1ynJ/4UeuXZQo2M3TLOM=; b=AGzxgv+sOkI0aDGVw4orWZz8jey63XE9zTrnV7zLrNpgRhgfq0xwgIafFgpNBZi4PY 6w8EkCVjthPOx9BRXRxLn5hOpC+W57nAltMNkGbjkn5r3pULvOfuGe9tswvp80G15BQ9 T21klFrUdKoiLJ3AEsnZwAH6VYcOMNZ34Px73fkrPLEW0J+SBJhOFSW7z6ZBIg4hjw7m qYD/UHQJI17WqkLXvh5S+hW57Gpb+klv/DE2NDsyj0CotyRsnci0rmsjxO6sobmWZAvK Kd/lBzPhCUHP16ALU311XSxaYlT/X+K6pxexrY7E6/wETiPHdVgFLgborQCR9v5aj1dU FvFw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=otBxOit5; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4373-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4373-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43fb18eac16si1611701cf.735.2024.05.23.14.26.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 14:26:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-4373-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=otBxOit5; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4373-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4373-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DE77B1C23018 for ; Thu, 23 May 2024 21:26:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E1FA11292F8; Thu, 23 May 2024 21:25:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="otBxOit5" X-Original-To: linux-crypto@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97D1B127E28; Thu, 23 May 2024 21:25:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716499527; cv=none; b=pRsvw3EODAhpVLHDV/LPo7oLPFKi6TGQOi9OubstGP9AwKzg9T9K5hViBcmOYCVBz6M9+d6VtuCtwezElNQqIy6ujMVJd5nMy5vDFH37VSKkwwhJUmSvVQ92i8RD1XK31MvuRJH7bDP9apqS7yMxEok8aEglqqnP9q+AIo1adDA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716499527; c=relaxed/simple; bh=rQTPLrmfpCPpQ7Zz53PlLkcw1m7mUahOVVqZUGpxmKU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Nt2G/AqzpImT7uiZ0K5+71v82XkcVlSS5V2uod84nkgtK29A8DtnzCczYcOdb+POTVXZ49lTiL7ZR4aUY6kK2rtHrn+9X9wdbwI2tmHB6pfl7T/qkCSVwK3rsHY5o2RDdR2puxNOt08oqIcs/B7aTDNgqKSwZ37RrzzemqyX0Ps= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=otBxOit5; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBE63C2BD10; Thu, 23 May 2024 21:25:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716499527; bh=rQTPLrmfpCPpQ7Zz53PlLkcw1m7mUahOVVqZUGpxmKU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=otBxOit5RUgQ1nmFtsG5q625SvOf8fm5OrjyoDr5Vy79x3Tu9G8KxwuzBwao/lrQF yNhotRGFJRdE9uf6NElkPOubnPL3evT7+TdsJa6RYkssatcwU7kJyvsotcNiI28cHm bSBtzJ5o25AdzMl1YKaNj/+p5H4X4MA/LXb1KRZYmzmdRtBmQbBp9PRgRn7ZQSLZB3 toSURmpaf+IEG5LUHhsu22dxAlyIayJlC0EGWDtqveubUr8ApTc9RENRCryDbwMFJQ RapqtHXOuiCpJGg/50BkyqacatIPNuD3rUN1u65f41sg8kNOQn4cTkqHOxV/XvXYmk s+Sxk+WY2rijQ== From: Jarkko Sakkinen To: Herbert Xu Cc: linux-integrity@vger.kernel.org, keyrings@vger.kernel.org, Andreas.Fuchs@infineon.com, James Prestwood , David Woodhouse , Eric Biggers , James Bottomley , linux-crypto@vger.kernel.org, Jarkko Sakkinen , "David S. Miller" , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v5 1/5] crypto: rsa-pkcs1pad: export rsa1_asn_lookup() Date: Fri, 24 May 2024 00:25:02 +0300 Message-ID: <20240523212515.4875-2-jarkko@kernel.org> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523212515.4875-1-jarkko@kernel.org> References: <20240523212515.4875-1-jarkko@kernel.org> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ASN.1 template is required for TPM2 asymmetric keys, as it needs to be piggy-packed with the input data before applying TPM2_RSA_Decrypt. This patch prepares crypto subsystem for the addition of those keys. Signed-off-by: Jarkko Sakkinen --- crypto/rsa-pkcs1pad.c | 16 ++++++++++------ include/crypto/rsa-pkcs1pad.h | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 include/crypto/rsa-pkcs1pad.h diff --git a/crypto/rsa-pkcs1pad.c b/crypto/rsa-pkcs1pad.c index cd501195f34a..00b6c14f861c 100644 --- a/crypto/rsa-pkcs1pad.c +++ b/crypto/rsa-pkcs1pad.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -79,11 +80,7 @@ static const u8 rsa_digest_info_sha3_512[] = { 0x05, 0x00, 0x04, 0x40 }; -static const struct rsa_asn1_template { - const char *name; - const u8 *data; - size_t size; -} rsa_asn1_templates[] = { +static const struct rsa_asn1_template rsa_asn1_templates[] = { #define _(X) { #X, rsa_digest_info_##X, sizeof(rsa_digest_info_##X) } _(md5), _(sha1), @@ -101,7 +98,13 @@ static const struct rsa_asn1_template { { NULL } }; -static const struct rsa_asn1_template *rsa_lookup_asn1(const char *name) +/** + * rsa_lookup_asn1() - Lookup the ASN.1 digest info given the hash + * name: hash algorithm name + * + * Returns the ASN.1 digest info on success, and NULL on failure. + */ +const struct rsa_asn1_template *rsa_lookup_asn1(const char *name) { const struct rsa_asn1_template *p; @@ -110,6 +113,7 @@ static const struct rsa_asn1_template *rsa_lookup_asn1(const char *name) return p; return NULL; } +EXPORT_SYMBOL_GPL(rsa_lookup_asn1); struct pkcs1pad_ctx { struct crypto_akcipher *child; diff --git a/include/crypto/rsa-pkcs1pad.h b/include/crypto/rsa-pkcs1pad.h new file mode 100644 index 000000000000..32c7453ff644 --- /dev/null +++ b/include/crypto/rsa-pkcs1pad.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * RSA padding templates. + */ + +#ifndef _CRYPTO_RSA_PKCS1PAD_H +#define _CRYPTO_RSA_PKCS1PAD_H + +/* + * Hash algorithm name to ASN.1 template mapping. + */ +struct rsa_asn1_template { + const char *name; + const u8 *data; + size_t size; +}; + +const struct rsa_asn1_template *rsa_lookup_asn1(const char *name); + +#endif /* _CRYPTO_RSA_PKCS1PAD_H */ -- 2.45.1