blob: 8be21fd3af2b9d0b629b83724d0d6b39f2c2c897 [file] [log] [blame]
Alexei Fedorovd686fa32020-07-13 13:58:06 +01001/*
2 * Copyright (c) 2020, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Lucian Paul-Trifu3519afe2022-03-08 15:02:31 +00007#ifndef TPM_LOG_PRIVATE_H
8#define TPM_LOG_PRIVATE_H
Alexei Fedorovd686fa32020-07-13 13:58:06 +01009
10#include <stdint.h>
11
12#define TCG_ID_EVENT_SIGNATURE_03 "Spec ID Event03"
13#define TCG_STARTUP_LOCALITY_SIGNATURE "StartupLocality"
14
15#define TCG_SPEC_VERSION_MAJOR_TPM2 2
16#define TCG_SPEC_VERSION_MINOR_TPM2 0
17#define TCG_SPEC_ERRATA_TPM2 2
18
Alexei Fedorovd686fa32020-07-13 13:58:06 +010019/* TCG Platform Type */
20#define PLATFORM_CLASS_CLIENT 0
21#define PLATFORM_CLASS_SERVER 1
22
23/* SHA digest sizes in bytes */
24#define SHA1_DIGEST_SIZE 20
25#define SHA256_DIGEST_SIZE 32
26#define SHA384_DIGEST_SIZE 48
27#define SHA512_DIGEST_SIZE 64
28
Alexei Fedorovd686fa32020-07-13 13:58:06 +010029#pragma pack(push, 1)
30
31/*
32 * PCR Event Header
Lucian Paul-Trifu3519afe2022-03-08 15:02:31 +000033 * TCG EFI Protocol Specification,
34 * Family "2.0", Level 00 Revision 00.13, March 30 2016.
Alexei Fedorovd686fa32020-07-13 13:58:06 +010035 * 5.3 Event Log Header
36 */
37typedef struct {
38 /* PCRIndex:
39 * The PCR Index to which this event is extended
40 */
41 uint32_t pcr_index;
42
43 /* EventType:
44 * SHALL be an EV_NO_ACTION event
45 */
46 uint32_t event_type;
47
48 /* SHALL be 20 Bytes of 0x00 */
49 uint8_t digest[SHA1_DIGEST_SIZE];
50
51 /* The size of the event */
52 uint32_t event_size;
53
54 /* SHALL be a TCG_EfiSpecIdEvent */
55 uint8_t event[]; /* [event_data_size] */
56} tcg_pcr_event_t;
57
58/*
59 * Log Header Entry Data
60 * Ref. Table 14 TCG_EfiSpecIdEventAlgorithmSize
61 * TCG PC Client Platform Firmware Profile 9.4.5.1
62 */
63typedef struct {
64 /* Algorithm ID (hashAlg) of the Hash used by BIOS */
65 uint16_t algorithm_id;
66
67 /* The size of the digest produced by the implemented Hash algorithm */
68 uint16_t digest_size;
Lucian Paul-Trifu3519afe2022-03-08 15:02:31 +000069} id_event_alg_info_t;
Alexei Fedorovd686fa32020-07-13 13:58:06 +010070
71/*
72 * TCG_EfiSpecIdEvent structure
73 * Ref. Table 15 TCG_EfiSpecIdEvent
74 * TCG PC Client Platform Firmware Profile 9.4.5.1
75 */
76typedef struct {
77 /*
78 * The NUL-terminated ASCII string "Spec ID Event03".
79 * SHALL be set to {0x53, 0x70, 0x65, 0x63, 0x20, 0x49, 0x44,
80 * 0x20, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x30, 0x33, 0x00}.
81 */
82 uint8_t signature[16];
83
84 /*
85 * The value for the Platform Class.
86 * The enumeration is defined in the TCG ACPI Specification Client
87 * Common Header.
88 */
89 uint32_t platform_class;
90
91 /*
92 * The PC Client Platform Profile Specification minor version number
93 * this BIOS supports.
94 * Any BIOS supporting this version (2.0) MUST set this value to 0x00.
95 */
96 uint8_t spec_version_minor;
97
98 /*
99 * The PC Client Platform Profile Specification major version number
100 * this BIOS supports.
101 * Any BIOS supporting this version (2.0) MUST set this value to 0x02.
102 */
103 uint8_t spec_version_major;
104
105 /*
106 * The PC Client Platform Profile Specification errata version number
107 * this BIOS supports.
108 * Any BIOS supporting this version (2.0) MUST set this value to 0x02.
109 */
110 uint8_t spec_errata;
111
112 /*
113 * Specifies the size of the UINTN fields used in various data
114 * structures used in this specification.
115 * 0x01 indicates UINT32 and 0x02 indicates UINT64.
116 */
117 uint8_t uintn_size;
118
119 /*
120 * The number of Hash algorithms in the digestSizes field.
121 * This field MUST be set to a value of 0x01 or greater.
122 */
123 uint32_t number_of_algorithms;
124
125 /*
126 * Each TCG_EfiSpecIdEventAlgorithmSize SHALL contain an algorithmId
127 * and digestSize for each hash algorithm used in the TCG_PCR_EVENT2
128 * structure, the first of which is a Hash algorithmID and the second
129 * is the size of the respective digest.
130 */
Lucian Paul-Trifu3519afe2022-03-08 15:02:31 +0000131 id_event_alg_info_t digest_sizes[]; /* number_of_algorithms */
132} id_event_misc_data_t;
Alexei Fedorovd686fa32020-07-13 13:58:06 +0100133
134typedef struct {
135 /*
136 * Size in bytes of the VendorInfo field.
137 * Maximum value MUST be FFh bytes.
138 */
139 uint8_t vendor_info_size;
140
141 /*
142 * Provided for use by Platform Firmware implementer. The value might
143 * be used, for example, to provide more detailed information about the
144 * specific BIOS such as BIOS revision numbers, etc. The values within
145 * this field are not standardized and are implementer-specific.
146 * Platform-specific or -unique information MUST NOT be provided in
147 * this field.
148 *
149 */
150 uint8_t vendor_info[]; /* [vendorInfoSize] */
Lucian Paul-Trifu3519afe2022-03-08 15:02:31 +0000151} id_event_vendor_data_t;
Alexei Fedorovd686fa32020-07-13 13:58:06 +0100152
153typedef struct {
Lucian Paul-Trifu3519afe2022-03-08 15:02:31 +0000154 id_event_misc_data_t id_event_misc_data;
155 id_event_vendor_data_t id_event_vendor_data;
156} __id_event_t;
Alexei Fedorovd686fa32020-07-13 13:58:06 +0100157
158typedef struct {
Lucian Paul-Trifu3519afe2022-03-08 15:02:31 +0000159 tcg_pcr_event_t container;
160 id_event_misc_data_t id_event_misc_data;
161} id_event_container_t;
Alexei Fedorovd686fa32020-07-13 13:58:06 +0100162
163/* TPMT_HA Structure */
164typedef struct {
165 /* Selector of the hash contained in the digest that implies
166 * the size of the digest
167 */
168 uint16_t algorithm_id; /* AlgorithmId */
169
170 /* Digest, depends on AlgorithmId */
171 uint8_t digest[]; /* Digest[] */
Lucian Paul-Trifu3519afe2022-03-08 15:02:31 +0000172} tpmt_ha_t;
Alexei Fedorovd686fa32020-07-13 13:58:06 +0100173
174/*
175 * TPML_DIGEST_VALUES Structure
176 */
177typedef struct {
178 /* The number of digests in the list */
179 uint32_t count; /* Count */
180
181 /* The list of tagged digests, as sent to the TPM as part of a
182 * TPM2_PCR_Extend or as received from a TPM2_PCR_Event command
183 */
Lucian Paul-Trifu3519afe2022-03-08 15:02:31 +0000184 tpmt_ha_t digests[]; /* Digests[Count] */
185} tpml_digest_values_t;
Alexei Fedorovd686fa32020-07-13 13:58:06 +0100186
187/*
188 * TCG_PCR_EVENT2 header
189 */
190typedef struct {
191 /* The PCR Index to which this event was extended */
192 uint32_t pcr_index; /* PCRIndex */
193
194 /* Type of event */
195 uint32_t event_type; /* EventType */
196
197 /* Digests:
198 * A counted list of tagged digests, which contain the digest of
199 * the event data (or external data) for all active PCR banks
200 */
Lucian Paul-Trifu3519afe2022-03-08 15:02:31 +0000201 tpml_digest_values_t digests; /* Digests */
Alexei Fedorovd686fa32020-07-13 13:58:06 +0100202} event2_header_t;
203
204typedef struct event2_data {
205 /* The size of the event data */
206 uint32_t event_size; /* EventSize */
207
208 /* The data of the event */
209 uint8_t event[]; /* Event[EventSize] */
210} event2_data_t;
211
212/*
213 * Startup Locality Event
214 * Ref. TCG PC Client Platform Firmware Profile 9.4.5.3
215 */
216typedef struct {
217 /*
218 * The NUL-terminated ASCII string "StartupLocality" SHALL be
219 * set to {0x53 0x74 0x61 0x72 0x74 0x75 0x70 0x4C 0x6F 0x63
220 * 0x61 0x6C 0x69 0x74 0x79 0x00}
221 */
222 uint8_t signature[16];
223
224 /* The Locality Indicator which sent the TPM2_Startup command */
225 uint8_t startup_locality;
Lucian Paul-Trifu3519afe2022-03-08 15:02:31 +0000226} startup_locality_event_data_t;
227
228typedef struct {
229 event2_data_t startup_event_header;
230 startup_locality_event_data_t startup_event_data;
Alexei Fedorovd686fa32020-07-13 13:58:06 +0100231} startup_locality_event_t;
232
233#pragma pack(pop)
234
Lucian Paul-Trifu3519afe2022-03-08 15:02:31 +0000235#endif /* TPM_LOG_PRIVATE_H */