Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2409235lqb; Mon, 27 May 2024 20:52:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWObbEMAqpMDfpfziEizQy9yfpEG1q9nY+q2G1GecDwiOupwO35unaef0erA/NZbB21YIPMzBKovrFx6olDsmm0pAGUH+Rvrzew92q14A== X-Google-Smtp-Source: AGHT+IEqi+zEDWv3NjzZkuVwDrMV7WIw0S2g6zkCb9xykmvXRFYOkzvaB9R8XEJpLRrckws4Mf/e X-Received: by 2002:a17:903:1d1:b0:1f4:befa:7a72 with SMTP id d9443c01a7336-1f4befa8a21mr18976025ad.2.1716868341259; Mon, 27 May 2024 20:52:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716868341; cv=pass; d=google.com; s=arc-20160816; b=itQ3jwICQKbrslFzHtpV1TDTwfJa3bqf+GfxG97MiP+XtU36/QHY0eHTy8wJEuSmYr bB4lVj5w+2c/Q2tTCe/XU7Gl2kVKM2ekWhrX9U/ednIpNok8DMrz0NlIPaMtPcZ/D2hW 0uyFj5vH0ddgxqNFHaAYvMEKg/KECsFEsQMXEO0fPgTdD6jlVdDn0/znRyldq9KS10QC 2JHAOAXg5OSn2FM+y5Lll4dkEH6shDVEZ1vIh5XAm6xM1yVKG+wDj0ca5i5DewJKBDCO +EvMe8v7ywTuWJsxH/gSu/GD6kndUKqNg99V6XbObV7hf3fg6RaWzgbse1J7/1JKdq7V qzjA== 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=KFwIYojOnDNIufnnlXFKQTGNfalXnhK/xy0KsKaoQ2E=; b=OIOQcb40R6YcT6WoXkr1mbyDJESRivJoricvmRKbekhVoAXYFRV6aHQ4CMs9DFbasv gnTy8JqIbrcOju8s9PO7SknEhcZtwoIk0O1xO2g8NnuskDhS+TfoPovyAqGwCQyyh6O0 xBp5MWB0GQaCPljAgdIQwvRyI3Qs97qv1+PEEl6jt8ULv1c6zGsKOPguyZy9Y4gcogKD FyGaqAPYGSFINpXckrLkZajNQ/HxAyjXumkJH1kKGpPHoJ2vnl9UlVcptRLDtjwo7bhP 88VUbiCG3a0nuj10cuGgkE0CGbJL0M8lukAjUMV8CPjSMXK60S2ARuErjzMn42mPUICT 4j2A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mFJGocpV; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4434-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4434-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f44c7c2600si74532265ad.139.2024.05.27.20.52.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 20:52:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-4434-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mFJGocpV; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4434-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4434-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E07AD28464D for ; Tue, 28 May 2024 03:52:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0AAF428DD5; Tue, 28 May 2024 03:51:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mFJGocpV" 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 AB904241E7; Tue, 28 May 2024 03:51:57 +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=1716868317; cv=none; b=UpBGA6iST6LV9a7BARR/cc4JFJJDJ2BQHL8Oiu3iSjGfFdbhVO4YJzXL3xcZu5EsVIVkotx/MmaM1715lklAyJ0r8dt3Y4uQ6Wt7Z4VYK7xZpEtCtRmqZaPg3KsxM4HAf+E0/usEsgyre3PJMZG7GVTKkTofEdYUBWAlkbkZrP8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716868317; c=relaxed/simple; bh=rQTPLrmfpCPpQ7Zz53PlLkcw1m7mUahOVVqZUGpxmKU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pXRcuhK4RkPvNrurY6LIWnuqENuAeRxK6PyNxC/m58bkJOOVeUK140igZWEeX9cYNDEayLtILFhl17LM6U5zGEYrWlxwEEMoh5FgoAZ0mnBJ+9FkW0Y/m7TjzaKh51gFNlK7aCNqrH04+9002XNFkHCsBr7QaJ0bWOJptA6TI4g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mFJGocpV; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB1A0C3277B; Tue, 28 May 2024 03:51:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716868317; bh=rQTPLrmfpCPpQ7Zz53PlLkcw1m7mUahOVVqZUGpxmKU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mFJGocpV6xt6VzaDwEswX4GBU1Uo5NqO2zz6v9xQkJ0Hm+AGkuL/h65yRlRVkxQ5A Ykzd7tkUMMlUbyIiyAgF+TuoctQpMaIW7+Q9fUOrB/1gWl5cWBPoXHe3S9i7RV6hPU 6oTNd3b7GkG5n1vwHLjZJvfnk6cImEd7uvuEnCTQcTCub/dfsxWkhDBNv5EprmoE6G N9WP17eZoWZmlmBy4QecAjM2QK+VBEGVrAe1c/DV0t3JPGSEbwmSwIdAcZNgs6KAv8 hBv3SMTMzW6t1IDR42bR42If+YfLqCdcuSdlS4ljvWehBmYXNkOJridfL8YOmZZ2nF p3oKyNm8QJpSQ== 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, Stefan Berger , Jarkko Sakkinen , "David S. Miller" , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v6 2/6] crypto: rsa-pkcs1pad: export rsa1_asn_lookup() Date: Tue, 28 May 2024 06:51:17 +0300 Message-ID: <20240528035136.11464-3-jarkko@kernel.org> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240528035136.11464-1-jarkko@kernel.org> References: <20240528035136.11464-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