Alexei Fedorov | d686fa3 | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Lucian Paul-Trifu | 3519afe | 2022-03-08 15:02:31 +0000 | [diff] [blame^] | 7 | #ifndef TPM_LOG_PRIVATE_H |
| 8 | #define TPM_LOG_PRIVATE_H |
Alexei Fedorov | d686fa3 | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 9 | |
| 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 Fedorov | d686fa3 | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 19 | /* 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 Fedorov | d686fa3 | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 29 | #pragma pack(push, 1) |
| 30 | |
| 31 | /* |
| 32 | * PCR Event Header |
Lucian Paul-Trifu | 3519afe | 2022-03-08 15:02:31 +0000 | [diff] [blame^] | 33 | * TCG EFI Protocol Specification, |
| 34 | * Family "2.0", Level 00 Revision 00.13, March 30 2016. |
Alexei Fedorov | d686fa3 | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 35 | * 5.3 Event Log Header |
| 36 | */ |
| 37 | typedef 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 | */ |
| 63 | typedef 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-Trifu | 3519afe | 2022-03-08 15:02:31 +0000 | [diff] [blame^] | 69 | } id_event_alg_info_t; |
Alexei Fedorov | d686fa3 | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 70 | |
| 71 | /* |
| 72 | * TCG_EfiSpecIdEvent structure |
| 73 | * Ref. Table 15 TCG_EfiSpecIdEvent |
| 74 | * TCG PC Client Platform Firmware Profile 9.4.5.1 |
| 75 | */ |
| 76 | typedef 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-Trifu | 3519afe | 2022-03-08 15:02:31 +0000 | [diff] [blame^] | 131 | id_event_alg_info_t digest_sizes[]; /* number_of_algorithms */ |
| 132 | } id_event_misc_data_t; |
Alexei Fedorov | d686fa3 | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 133 | |
| 134 | typedef 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-Trifu | 3519afe | 2022-03-08 15:02:31 +0000 | [diff] [blame^] | 151 | } id_event_vendor_data_t; |
Alexei Fedorov | d686fa3 | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 152 | |
| 153 | typedef struct { |
Lucian Paul-Trifu | 3519afe | 2022-03-08 15:02:31 +0000 | [diff] [blame^] | 154 | id_event_misc_data_t id_event_misc_data; |
| 155 | id_event_vendor_data_t id_event_vendor_data; |
| 156 | } __id_event_t; |
Alexei Fedorov | d686fa3 | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 157 | |
| 158 | typedef struct { |
Lucian Paul-Trifu | 3519afe | 2022-03-08 15:02:31 +0000 | [diff] [blame^] | 159 | tcg_pcr_event_t container; |
| 160 | id_event_misc_data_t id_event_misc_data; |
| 161 | } id_event_container_t; |
Alexei Fedorov | d686fa3 | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 162 | |
| 163 | /* TPMT_HA Structure */ |
| 164 | typedef 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-Trifu | 3519afe | 2022-03-08 15:02:31 +0000 | [diff] [blame^] | 172 | } tpmt_ha_t; |
Alexei Fedorov | d686fa3 | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 173 | |
| 174 | /* |
| 175 | * TPML_DIGEST_VALUES Structure |
| 176 | */ |
| 177 | typedef 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-Trifu | 3519afe | 2022-03-08 15:02:31 +0000 | [diff] [blame^] | 184 | tpmt_ha_t digests[]; /* Digests[Count] */ |
| 185 | } tpml_digest_values_t; |
Alexei Fedorov | d686fa3 | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 186 | |
| 187 | /* |
| 188 | * TCG_PCR_EVENT2 header |
| 189 | */ |
| 190 | typedef 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-Trifu | 3519afe | 2022-03-08 15:02:31 +0000 | [diff] [blame^] | 201 | tpml_digest_values_t digests; /* Digests */ |
Alexei Fedorov | d686fa3 | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 202 | } event2_header_t; |
| 203 | |
| 204 | typedef 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 | */ |
| 216 | typedef 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-Trifu | 3519afe | 2022-03-08 15:02:31 +0000 | [diff] [blame^] | 226 | } startup_locality_event_data_t; |
| 227 | |
| 228 | typedef struct { |
| 229 | event2_data_t startup_event_header; |
| 230 | startup_locality_event_data_t startup_event_data; |
Alexei Fedorov | d686fa3 | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 231 | } startup_locality_event_t; |
| 232 | |
| 233 | #pragma pack(pop) |
| 234 | |
Lucian Paul-Trifu | 3519afe | 2022-03-08 15:02:31 +0000 | [diff] [blame^] | 235 | #endif /* TPM_LOG_PRIVATE_H */ |