From nobody Mon Apr 6 23:36:06 2026 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (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 C6E0026F293; Tue, 17 Mar 2026 16:06:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.165.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773763617; cv=none; b=FVpQotqeGYK2cL/x8vNaJ93466UGR4yGwVIu4y6pZFcssZqQL3fchEZiwIZ0mwHk86RFaDXR7Fjj6lT/wQFp+jPXPeVQ/41O6U03hBaF5shSO+cxik5ncz+ihWYDtty7Vp/j8ovBuN8LkmGK4yDJ7iZ1a5N+W5YlgsXOxd1Txo4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773763617; c=relaxed/simple; bh=wrzci2Meegi1bKuXCl6+mRdzgZT0jW/C1Kb+skqurLs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZQCmUMa7I614szBZB9pnC7+snbvg6V7j2SjHrzB30vZ8ZYaOisjA5DPh+1gMJFkrAD8w+UVPdapBaN5RuDygGzw600q2q/4AbW7EdQYfH2WYVWzcRF3Xp+nwG92BRcZboTxYS4thqU/QgbminUXcO13TzZSFzpFLnKJheg/vZY4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=X8q65HHz; arc=none smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="X8q65HHz" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 62HE4BRs104304; Tue, 17 Mar 2026 16:06:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=vy8KW SDHCCeTGCwkFTZCGK5NcEj8xZNfPUiYETykNRo=; b=X8q65HHzQaQ2csvKn2Yxw hFieQfnKUZcxNkCE38XkCAaCP2H6D4sKwM1aQ3pyhLFh30WIpVtAxeFHycCz3Q8u XmVx/gklIXRFwlS/+ohSXPJac9WT0uAPZWYHYDySSyvjX2SQampRBgP177p3h+hF rn/lnRUKMIb5zPguz89u/W5qlcDKmWwgaR2OcZdJOSnno9EEnKo8QwyfE1HQuCmq OZK+mwSw6PayVtNxlWmESNN7spFbXizpeI6XELseQGcDA3HINN8je740Tla6yEw3 hWBMGcXLXF3IzU9bRVuH/L/aB9aDtDWds1+zqbICsQW7txYluDs22s847xbXJ0hP Q== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4cvx8x4fet-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Mar 2026 16:06:42 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 62HEcgmW014108; Tue, 17 Mar 2026 16:06:41 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4cvx4aag40-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Mar 2026 16:06:41 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 62HG6Pvk031124; Tue, 17 Mar 2026 16:06:41 GMT Received: from localhost (alecbro-ol9.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.255.11]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4cvx4aag0r-1; Tue, 17 Mar 2026 16:06:40 +0000 From: Alec Brown To: linux-kernel@vger.kernel.org, linux-integrity@vger.kernel.org, jarkko@kernel.org Cc: peterhuewe@gmx.de, jarkko.sakkinen@iki.fi, jgg@ziepe.ca, ross.philipson@oracle.com, dpsmith@apertussolutions.com, daniel.kiper@oracle.com, kanth.ghatraju@oracle.com, trenchboot-devel@googlegroups.com, ardb@kernel.org, alec.r.brown@oracle.com Subject: [PATCH 4/4] tpm: Move TPM common base definitions to the command header Date: Tue, 17 Mar 2026 16:03:35 +0000 Message-ID: <20260317160613.2899129-5-alec.r.brown@oracle.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260317160613.2899129-1-alec.r.brown@oracle.com> References: <20260317160613.2899129-1-alec.r.brown@oracle.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-03-17_03,2026-03-17_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 bulkscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2603050001 definitions=main-2603170142 X-Proofpoint-GUID: E6JBUFNjpcHBobTqDCDcu7BsSoQxqWL8 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzE3MDE0MiBTYWx0ZWRfX7tZXo5RrF0xl K/jYP9r+k1QNl3rRfTi/pnTsmTgtWZXWBAKge8XFMiTQZTdtXZeE8Uqw0OkEFCn/eVGuiM7vTG7 ycuwgLDjJ4iNJwX/VTtwSuPLMEo/I+P6TDjWN9Vfs9mHqBwe9JYaDf39X6wSPDiEwMcwPl8PZne tohI/dkMJnWzsa1VsXV8gMiPDc8PGLxnBhrLQryp43KdoqXDLfIscFf2QVU1T7BTGLJzySEEAbZ iVVtIfNYe8Rxzy79Ac1wUsdlzJQYkhra7O7JXXV2fumU0lqGJZvTAHyqi9o51GoEkgGJ8jPo97N eycSE7/SiI26eFok4Belvtkoj9RCVJF3mxiay9cTlUEJlskcNTwH+x1MdYe4PBlYUTmR1o+6JJG 7qzjPaMNRRx7zJOzpuOJ77fuv3WuSK5IB+Oqf4y3FbNLT4Z29/gLgKRlRcSz2JDG9O5D5HKscLA Ygba7dz/AcfhU/hiy9g== X-Authority-Analysis: v=2.4 cv=dJmrWeZb c=1 sm=1 tr=0 ts=69b97c12 cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=Yq5XynenixoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=jiCTI4zE5U7BLdzWsZGv:22 a=RD47p0oAkeU5bO7t-o6f:22 a=yPCof4ZbAAAA:8 a=UN5060LkAAAA:8 a=9u39xqQJ7Ymw5X7hPw4A:9 a=E6eXv-vVeS7VqOnxGRGn:22 X-Proofpoint-ORIG-GUID: E6JBUFNjpcHBobTqDCDcu7BsSoQxqWL8 Content-Type: text/plain; charset="utf-8" From: Ross Philipson From: Ross Philipson These are top level definitions shared by both TPM 1 and 2 family chips. This includes core definitions like TPM localities, common crypto algorithm IDs, and the base TPM command header. Signed-off-by: Daniel P. Smith Signed-off-by: Ross Philipson Signed-off-by: Alec Brown --- include/linux/tpm.h | 50 +-------------------- include/linux/tpm_command.h | 89 +++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 49 deletions(-) diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 92957452f7a7..a282b7045a24 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -27,49 +27,12 @@ =20 #include "tpm_command.h" =20 -#define TPM_DIGEST_SIZE 20 /* Max TPM v1.2 PCR size */ - -#define TPM2_MAX_DIGEST_SIZE SHA512_DIGEST_SIZE -#define TPM2_MAX_PCR_BANKS 8 - struct tpm_chip; struct trusted_key_payload; struct trusted_key_options; /* opaque structure, holds auth session parameters like the session key */ struct tpm2_auth; =20 -/* if you add a new hash to this, increment TPM_MAX_HASHES below */ -enum tpm_algorithms { - TPM_ALG_ERROR =3D 0x0000, - TPM_ALG_SHA1 =3D 0x0004, - TPM_ALG_AES =3D 0x0006, - TPM_ALG_KEYEDHASH =3D 0x0008, - TPM_ALG_SHA256 =3D 0x000B, - TPM_ALG_SHA384 =3D 0x000C, - TPM_ALG_SHA512 =3D 0x000D, - TPM_ALG_NULL =3D 0x0010, - TPM_ALG_SM3_256 =3D 0x0012, - TPM_ALG_ECC =3D 0x0023, - TPM_ALG_CFB =3D 0x0043, -}; - -/* - * maximum number of hashing algorithms a TPM can have. This is - * basically a count of every hash in tpm_algorithms above - */ -#define TPM_MAX_HASHES 5 - -struct tpm_digest { - u16 alg_id; - u8 digest[TPM2_MAX_DIGEST_SIZE]; -} __packed; - -struct tpm_bank_info { - u16 alg_id; - u16 digest_size; - u16 crypto_id; -}; - enum TPM_OPS_FLAGS { TPM_OPS_AUTO_STARTUP =3D BIT(0), }; @@ -127,7 +90,7 @@ struct tpm_chip_seqops { const struct seq_operations *seqops; }; =20 -/* fixed define for the curve we use which is NIST_P256 */ +/* Fixed define for the curve we use which is NIST_P256 */ #define EC_PT_SZ 32 =20 /* @@ -209,8 +172,6 @@ struct tpm_chip { #endif }; =20 -#define TPM_HEADER_SIZE 10 - static inline enum tpm2_mso_type tpm2_handle_mso(u32 handle) { return handle >> 24; @@ -239,15 +200,6 @@ enum tpm_chip_flags { =20 #define to_tpm_chip(d) container_of(d, struct tpm_chip, dev) =20 -struct tpm_header { - __be16 tag; - __be32 length; - union { - __be32 ordinal; - __be32 return_code; - }; -} __packed; - enum tpm_buf_flags { /* the capacity exceeded: */ TPM_BUF_OVERFLOW =3D BIT(0), diff --git a/include/linux/tpm_command.h b/include/linux/tpm_command.h index ee76fcd5ecef..25a247254140 100644 --- a/include/linux/tpm_command.h +++ b/include/linux/tpm_command.h @@ -431,4 +431,93 @@ struct tpm2_context { __be16 blob_size; } __packed; =20 +/************************************************/ +/* TPM Common Defs */ +/************************************************/ + +#define TPM_DIGEST_SIZE 20 /* Max TPM v1.2 PCR size */ +#define TPM_BUFSIZE 4096 + +/* + * SHA-512 is, as of today, the largest digest in the TCG algorithm reposi= tory. + */ +#define TPM2_MAX_DIGEST_SIZE SHA512_DIGEST_SIZE + +/* + * A TPM name digest i.e., TPMT_HA, is a concatenation of TPM_ALG_ID of the + * name algorithm and hash of TPMT_PUBLIC. + */ +#define TPM2_MAX_NAME_SIZE (TPM2_MAX_DIGEST_SIZE + 2) + +/* + * Fixed define for the size of a name. This is actually HASHALG size + * plus 2, so 32 for SHA256 + */ +#define TPM2_NULL_NAME_SIZE 34 + +/* + * The maximum number of PCR banks. + */ +#define TPM2_MAX_PCR_BANKS 8 + +/* If you add a new hash to this, increment TPM_MAX_HASHES below */ +enum tpm_algorithms { + TPM_ALG_ERROR =3D 0x0000, + TPM_ALG_SHA1 =3D 0x0004, + TPM_ALG_AES =3D 0x0006, + TPM_ALG_KEYEDHASH =3D 0x0008, + TPM_ALG_SHA256 =3D 0x000B, + TPM_ALG_SHA384 =3D 0x000C, + TPM_ALG_SHA512 =3D 0x000D, + TPM_ALG_NULL =3D 0x0010, + TPM_ALG_SM3_256 =3D 0x0012, + TPM_ALG_ECC =3D 0x0023, + TPM_ALG_CFB =3D 0x0043, +}; + +/* + * The locality (0 - 4) for a TPM, as defined in section 3.2 of the + * Client Platform Profile Specification. + */ +enum tpm_localities { + TPM_LOCALITY_0 =3D 0, /* Static RTM */ + TPM_LOCALITY_1 =3D 1, /* Dynamic OS */ + TPM_LOCALITY_2 =3D 2, /* DRTM Environment */ + TPM_LOCALITY_3 =3D 3, /* Aux Components */ + TPM_LOCALITY_4 =3D 4, /* CPU DRTM Establishment */ + TPM_MAX_LOCALITY =3D TPM_LOCALITY_4 +}; + +/* + * Structure to represent active PCR algorithm banks usable by the + * TPM chip. + */ +struct tpm_bank_info { + u16 alg_id; + u16 digest_size; + u16 crypto_id; +}; + +/* + * Maximum number of hashing algorithms a TPM can have. This is + * basically a count of every hash in tpm_algorithms above + */ +#define TPM_MAX_HASHES 5 + +struct tpm_digest { + u16 alg_id; + u8 digest[TPM2_MAX_DIGEST_SIZE]; +} __packed; + +#define TPM_HEADER_SIZE 10 + +struct tpm_header { + __be16 tag; + __be32 length; + union { + __be32 ordinal; + __be32 return_code; + }; +} __packed; + #endif --=20 2.47.3