From 53db677586e3e7c4a874f1ef16f34a6d01c269a0 Mon Sep 17 00:00:00 2001
From: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Date: Sun, 23 Oct 2022 00:47:55 +0300
Subject: security/tpm: add TPM log format as per 2.0 spec
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Used by default for all boards with TPM2 which don't specify log
format explicitly.

Change-Id: I0fac386bebab1b7104378ae3424957c6497e84e1
Ticket: https://ticket.coreboot.org/issues/422
Ticket: https://ticket.coreboot.org/issues/423
Signed-off-by: Michał Żygowski <michal.zygowski@3mdeb.com>
Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/68748
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
---
 .../bsd/include/commonlib/bsd/tpm_log_defs.h       | 37 ++++++++++++++++++++++
 1 file changed, 37 insertions(+)

(limited to 'src/commonlib')

diff --git a/src/commonlib/bsd/include/commonlib/bsd/tpm_log_defs.h b/src/commonlib/bsd/include/commonlib/bsd/tpm_log_defs.h
index a45a212746..144d55a331 100644
--- a/src/commonlib/bsd/include/commonlib/bsd/tpm_log_defs.h
+++ b/src/commonlib/bsd/include/commonlib/bsd/tpm_log_defs.h
@@ -9,6 +9,21 @@
 #define TCPA_SPEC_ID_EVENT_SIGNATURE    "Spec ID Event00"
 #define TCG_EFI_SPEC_ID_EVENT_SIGNATURE "Spec ID Event03"
 
+#define TPM2_ALG_ERROR   0x0000
+#define TPM2_ALG_HMAC    0x0005
+#define TPM2_ALG_NULL    0x0010
+#define TPM2_ALG_SHA1    0x0004
+#define TPM2_ALG_SHA256  0x000B
+#define TPM2_ALG_SHA384  0x000C
+#define TPM2_ALG_SHA512  0x000D
+#define TPM2_ALG_SM3_256 0x0012
+
+#define SHA1_DIGEST_SIZE    20
+#define SHA256_DIGEST_SIZE  32
+#define SHA384_DIGEST_SIZE  48
+#define SHA512_DIGEST_SIZE  64
+#define SM3_256_DIGEST_SIZE 32
+
 #define EV_PREBOOT_CERT			0x00000000
 #define EV_POST_CODE			0x00000001
 #define EV_UNUSED			0x00000002
@@ -39,4 +54,26 @@ struct spec_id_event_data {
 	uint8_t vendor_info_size;
 } __packed;
 
+struct tpm_digest_sizes {
+	uint16_t alg_id;
+	uint16_t digest_size;
+} __packed;
+
+struct tcg_efi_spec_id_event {
+	uint32_t pcr_index;
+	uint32_t event_type;
+	uint8_t digest[20];
+	uint32_t event_size;
+	uint8_t signature[16];
+	uint32_t platform_class;
+	uint8_t spec_version_minor;
+	uint8_t spec_version_major;
+	uint8_t spec_errata;
+	uint8_t uintn_size;
+	uint32_t num_of_algorithms;
+	struct tpm_digest_sizes digest_sizes[0]; /* variable number of members */
+	/* uint8_t vendor_info_size; */
+	/* uint8_t vendor_info[vendor_info_size]; */
+} __packed;
+
 #endif
-- 
cgit v1.2.3