xref: /aosp_15_r20/external/coreboot/src/commonlib/bsd/include/commonlib/bsd/tpm_log_defs.h (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 
3 #ifndef COMMONLIB_BSD_TPM_LOG_DEFS_H
4 #define COMMONLIB_BSD_TPM_LOG_DEFS_H
5 
6 #include <commonlib/helpers.h>
7 #include <stdint.h>
8 
9 #define TCPA_SPEC_ID_EVENT_SIGNATURE    "Spec ID Event00"
10 #define TCG_EFI_SPEC_ID_EVENT_SIGNATURE "Spec ID Event03"
11 
12 struct tcpa_log_entry {
13 	uint32_t pcr;
14 	uint32_t event_type;
15 	uint8_t digest[20];
16 	uint32_t event_data_size;
17 	uint8_t event[0];
18 } __packed;
19 
20 struct tcpa_spec_entry {
21 	struct tcpa_log_entry entry;
22 	uint8_t signature[16];
23 	uint32_t platform_class;
24 	uint8_t spec_version_minor;
25 	uint8_t spec_version_major;
26 	uint8_t spec_errata;
27 	uint8_t reserved;
28 	uint8_t vendor_info_size;
29 	uint8_t vendor_info[0];
30 } __packed;
31 
32 #define TPM2_ALG_ERROR   0x0000
33 #define TPM2_ALG_HMAC    0x0005
34 #define TPM2_ALG_NULL    0x0010
35 #define TPM2_ALG_SHA1    0x0004
36 #define TPM2_ALG_SHA256  0x000B
37 #define TPM2_ALG_SHA384  0x000C
38 #define TPM2_ALG_SHA512  0x000D
39 #define TPM2_ALG_SM3_256 0x0012
40 
41 #define SHA1_DIGEST_SIZE    20
42 #define SHA256_DIGEST_SIZE  32
43 #define SHA384_DIGEST_SIZE  48
44 #define SHA512_DIGEST_SIZE  64
45 #define SM3_256_DIGEST_SIZE 32
46 
47 enum ev_enum {
48 	EV_PREBOOT_CERT,
49 	EV_POST_CODE,
50 	EV_UNUSED,
51 	EV_NO_ACTION,
52 	EV_SEPARATOR,
53 	EV_ACTION,
54 	EV_EVENT_TAG,
55 	EV_S_CRTM_CONTENTS,
56 	EV_S_CRTM_VERSION,
57 	EV_CPU_MICROCODE,
58 	EV_PLATFORM_CONFIG_FLAGS,
59 	EV_TABLE_OF_DEVICES,
60 	EV_COMPACT_HASH,
61 	EV_IPL,
62 	EV_IPL_PARTITION_DATA,
63 	EV_NONHOST_CODE,
64 	EV_NONHOST_CONFIG,
65 	EV_NONHOST_INFO,
66 	EV_OMIT_BOOT_DEVICE_EVENTS
67 };
68 
69 struct spec_id_event_data {
70 	char signature[16];
71 	uint32_t platform_class;
72 	uint8_t spec_version_minor;
73 	uint8_t spec_version_major;
74 	uint8_t spec_errata;
75 	uint8_t reserved;
76 	uint8_t vendor_info_size;
77 } __packed;
78 
79 union tpm_hash_digest {
80 	uint8_t sha1[SHA1_DIGEST_SIZE];
81 	uint8_t sha256[SHA256_DIGEST_SIZE];
82 	uint8_t sm3_256[SM3_256_DIGEST_SIZE];
83 	uint8_t sha384[SHA384_DIGEST_SIZE];
84 	uint8_t sha512[SHA512_DIGEST_SIZE];
85 };
86 
87 struct tpm_hash_algorithm {
88 	uint16_t hashAlg;
89 	union tpm_hash_digest digest;
90 } __packed;
91 
92 struct tcg_pcr_event2_header {
93 	uint32_t pcr_index;
94 	uint32_t event_type;
95 	uint32_t digest_count;
96 	uint8_t digests[0];
97 	/* uint32_t event_size; */
98 	/* uint8_t event[0]; */
99 } __packed;
100 
101 struct tpm_digest_sizes {
102 	uint16_t alg_id;
103 	uint16_t digest_size;
104 } __packed;
105 
106 struct tcg_efi_spec_id_event {
107 	uint32_t pcr_index;
108 	uint32_t event_type;
109 	uint8_t digest[20];
110 	uint32_t event_size;
111 	uint8_t signature[16];
112 	uint32_t platform_class;
113 	uint8_t spec_version_minor;
114 	uint8_t spec_version_major;
115 	uint8_t spec_errata;
116 	uint8_t uintn_size;
117 	uint32_t num_of_algorithms;
118 	struct tpm_digest_sizes digest_sizes[0]; /* variable number of members */
119 	/* uint8_t vendor_info_size; */
120 	/* uint8_t vendor_info[vendor_info_size]; */
121 } __packed;
122 
123 static const char *tpm_event_types[] __maybe_unused = {
124 	[EV_PREBOOT_CERT]		= "Reserved",
125 	[EV_POST_CODE]			= "POST code",
126 	[EV_UNUSED]			= "Unused",
127 	[EV_NO_ACTION]			= "No action",
128 	[EV_SEPARATOR]			= "Separator",
129 	[EV_ACTION]			= "Action",
130 	[EV_EVENT_TAG]			= "Event tag",
131 	[EV_S_CRTM_CONTENTS]		= "S-CRTM contents",
132 	[EV_S_CRTM_VERSION]		= "S-CRTM version",
133 	[EV_CPU_MICROCODE]		= "CPU microcode",
134 	[EV_PLATFORM_CONFIG_FLAGS]	= "Platform configuration flags",
135 	[EV_TABLE_OF_DEVICES]		= "Table of devices",
136 	[EV_COMPACT_HASH]		= "Compact hash",
137 	[EV_IPL]			= "IPL",
138 	[EV_IPL_PARTITION_DATA]		= "IPL partition data",
139 	[EV_NONHOST_CODE]		= "Non-host code",
140 	[EV_NONHOST_CONFIG]		= "Non-host configuration",
141 	[EV_NONHOST_INFO]		= "Non-host information",
142 	[EV_OMIT_BOOT_DEVICE_EVENTS]	= "Omit boot device events",
143 };
144 
145 #endif
146