Alexei Fedorov | 71d81dc | 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 | |
| 7 | #ifndef TCG_H |
| 8 | #define TCG_H |
| 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 | |
| 19 | /* |
| 20 | * Event types |
| 21 | * Ref. Table 9 Events |
| 22 | * TCG PC Client Platform Firmware Profile Specification. |
| 23 | */ |
| 24 | #define EV_PREBOOT_CERT U(0x00000000) |
| 25 | #define EV_POST_CODE U(0x00000001) |
| 26 | #define EV_UNUSED U(0x00000002) |
| 27 | #define EV_NO_ACTION U(0x00000003) |
| 28 | #define EV_SEPARATOR U(0x00000004) |
| 29 | #define EV_ACTION U(0x00000005) |
| 30 | #define EV_EVENT_TAG U(0x00000006) |
| 31 | #define EV_S_CRTM_CONTENTS U(0x00000007) |
| 32 | #define EV_S_CRTM_VERSION U(0x00000008) |
| 33 | #define EV_CPU_MICROCODE U(0x00000009) |
| 34 | #define EV_PLATFORM_CONFIG_FLAGS U(0x0000000A) |
| 35 | #define EV_TABLE_OF_DEVICES U(0x0000000B) |
| 36 | #define EV_COMPACT_HASH U(0x0000000C) |
| 37 | #define EV_IPL U(0x0000000D) |
| 38 | #define EV_IPL_PARTITION_DATA U(0x0000000E) |
| 39 | #define EV_NONHOST_CODE U(0x0000000F) |
| 40 | #define EV_NONHOST_CONFIG U(0x00000010) |
| 41 | #define EV_NONHOST_INFO U(0x00000011) |
| 42 | #define EV_OMIT_BOOT_DEVICE_EVENTS U(0x00000012) |
| 43 | #define EV_EFI_EVENT_BASE U(0x80000000) |
| 44 | #define EV_EFI_VARIABLE_DRIVER_CONFIG U(0x80000001) |
| 45 | #define EV_EFI_VARIABLE_BOOT U(0x80000002) |
| 46 | #define EV_EFI_BOOT_SERVICES_APPLICATION U(0x80000003) |
| 47 | #define EV_EFI_BOOT_SERVICES_DRIVER U(0x80000004) |
| 48 | #define EV_EFI_RUNTIME_SERVICES_DRIVER U(0x80000005) |
| 49 | #define EV_EFI_GPT_EVENT U(0x80000006) |
| 50 | #define EV_EFI_ACTION U(0x80000007) |
| 51 | #define EV_EFI_PLATFORM_FIRMWARE_BLOB U(0x80000008) |
| 52 | #define EV_EFI_HANDOFF_TABLES U(0x80000009) |
| 53 | #define EV_EFI_HCRTM_EVENT U(0x80000010) |
| 54 | #define EV_EFI_VARIABLE_AUTHORITY U(0x800000E0) |
| 55 | |
| 56 | /* |
| 57 | * TPM_ALG_ID constants. |
| 58 | * Ref. Table 9 - Definition of (UINT16) TPM_ALG_ID Constants |
| 59 | * Trusted Platform Module Library. Part 2: Structures |
| 60 | */ |
| 61 | #define TPM_ALG_SHA256 0x000B |
| 62 | #define TPM_ALG_SHA384 0x000C |
| 63 | #define TPM_ALG_SHA512 0x000D |
| 64 | |
| 65 | /* TCG Platform Type */ |
| 66 | #define PLATFORM_CLASS_CLIENT 0 |
| 67 | #define PLATFORM_CLASS_SERVER 1 |
| 68 | |
| 69 | /* SHA digest sizes in bytes */ |
| 70 | #define SHA1_DIGEST_SIZE 20 |
| 71 | #define SHA256_DIGEST_SIZE 32 |
| 72 | #define SHA384_DIGEST_SIZE 48 |
| 73 | #define SHA512_DIGEST_SIZE 64 |
| 74 | |
| 75 | enum { |
| 76 | /* |
| 77 | * SRTM, BIOS, Host Platform Extensions, Embedded |
| 78 | * Option ROMs and PI Drivers |
| 79 | */ |
| 80 | PCR_0 = 0, |
| 81 | /* Host Platform Configuration */ |
| 82 | PCR_1, |
| 83 | /* UEFI driver and application Code */ |
| 84 | PCR_2, |
| 85 | /* UEFI driver and application Configuration and Data */ |
| 86 | PCR_3, |
| 87 | /* UEFI Boot Manager Code (usually the MBR) and Boot Attempts */ |
| 88 | PCR_4, |
| 89 | /* |
| 90 | * Boot Manager Code Configuration and Data (for use |
| 91 | * by the Boot Manager Code) and GPT/Partition Table |
| 92 | */ |
| 93 | PCR_5, |
| 94 | /* Host Platform Manufacturer Specific */ |
| 95 | PCR_6, |
| 96 | /* Secure Boot Policy */ |
| 97 | PCR_7, |
| 98 | /* 8-15: Defined for use by the Static OS */ |
| 99 | PCR_8, |
| 100 | /* Debug */ |
| 101 | PCR_16 = 16 |
| 102 | }; |
| 103 | |
| 104 | #pragma pack(push, 1) |
| 105 | |
| 106 | /* |
| 107 | * PCR Event Header |
| 108 | * TCG EFI Protocol Specification |
| 109 | * 5.3 Event Log Header |
| 110 | */ |
| 111 | typedef struct { |
| 112 | /* PCRIndex: |
| 113 | * The PCR Index to which this event is extended |
| 114 | */ |
| 115 | uint32_t pcr_index; |
| 116 | |
| 117 | /* EventType: |
| 118 | * SHALL be an EV_NO_ACTION event |
| 119 | */ |
| 120 | uint32_t event_type; |
| 121 | |
| 122 | /* SHALL be 20 Bytes of 0x00 */ |
| 123 | uint8_t digest[SHA1_DIGEST_SIZE]; |
| 124 | |
| 125 | /* The size of the event */ |
| 126 | uint32_t event_size; |
| 127 | |
| 128 | /* SHALL be a TCG_EfiSpecIdEvent */ |
| 129 | uint8_t event[]; /* [event_data_size] */ |
| 130 | } tcg_pcr_event_t; |
| 131 | |
| 132 | /* |
| 133 | * Log Header Entry Data |
| 134 | * Ref. Table 14 TCG_EfiSpecIdEventAlgorithmSize |
| 135 | * TCG PC Client Platform Firmware Profile 9.4.5.1 |
| 136 | */ |
| 137 | typedef struct { |
| 138 | /* Algorithm ID (hashAlg) of the Hash used by BIOS */ |
| 139 | uint16_t algorithm_id; |
| 140 | |
| 141 | /* The size of the digest produced by the implemented Hash algorithm */ |
| 142 | uint16_t digest_size; |
| 143 | } id_event_algorithm_size_t; |
| 144 | |
| 145 | /* |
| 146 | * TCG_EfiSpecIdEvent structure |
| 147 | * Ref. Table 15 TCG_EfiSpecIdEvent |
| 148 | * TCG PC Client Platform Firmware Profile 9.4.5.1 |
| 149 | */ |
| 150 | typedef struct { |
| 151 | /* |
| 152 | * The NUL-terminated ASCII string "Spec ID Event03". |
| 153 | * SHALL be set to {0x53, 0x70, 0x65, 0x63, 0x20, 0x49, 0x44, |
| 154 | * 0x20, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x30, 0x33, 0x00}. |
| 155 | */ |
| 156 | uint8_t signature[16]; |
| 157 | |
| 158 | /* |
| 159 | * The value for the Platform Class. |
| 160 | * The enumeration is defined in the TCG ACPI Specification Client |
| 161 | * Common Header. |
| 162 | */ |
| 163 | uint32_t platform_class; |
| 164 | |
| 165 | /* |
| 166 | * The PC Client Platform Profile Specification minor version number |
| 167 | * this BIOS supports. |
| 168 | * Any BIOS supporting this version (2.0) MUST set this value to 0x00. |
| 169 | */ |
| 170 | uint8_t spec_version_minor; |
| 171 | |
| 172 | /* |
| 173 | * The PC Client Platform Profile Specification major version number |
| 174 | * this BIOS supports. |
| 175 | * Any BIOS supporting this version (2.0) MUST set this value to 0x02. |
| 176 | */ |
| 177 | uint8_t spec_version_major; |
| 178 | |
| 179 | /* |
| 180 | * The PC Client Platform Profile Specification errata version number |
| 181 | * this BIOS supports. |
| 182 | * Any BIOS supporting this version (2.0) MUST set this value to 0x02. |
| 183 | */ |
| 184 | uint8_t spec_errata; |
| 185 | |
| 186 | /* |
| 187 | * Specifies the size of the UINTN fields used in various data |
| 188 | * structures used in this specification. |
| 189 | * 0x01 indicates UINT32 and 0x02 indicates UINT64. |
| 190 | */ |
| 191 | uint8_t uintn_size; |
| 192 | |
| 193 | /* |
| 194 | * The number of Hash algorithms in the digestSizes field. |
| 195 | * This field MUST be set to a value of 0x01 or greater. |
| 196 | */ |
| 197 | uint32_t number_of_algorithms; |
| 198 | |
| 199 | /* |
| 200 | * Each TCG_EfiSpecIdEventAlgorithmSize SHALL contain an algorithmId |
| 201 | * and digestSize for each hash algorithm used in the TCG_PCR_EVENT2 |
| 202 | * structure, the first of which is a Hash algorithmID and the second |
| 203 | * is the size of the respective digest. |
| 204 | */ |
| 205 | id_event_algorithm_size_t digest_size[]; /* number_of_algorithms */ |
| 206 | } id_event_struct_header_t; |
| 207 | |
| 208 | typedef struct { |
| 209 | /* |
| 210 | * Size in bytes of the VendorInfo field. |
| 211 | * Maximum value MUST be FFh bytes. |
| 212 | */ |
| 213 | uint8_t vendor_info_size; |
| 214 | |
| 215 | /* |
| 216 | * Provided for use by Platform Firmware implementer. The value might |
| 217 | * be used, for example, to provide more detailed information about the |
| 218 | * specific BIOS such as BIOS revision numbers, etc. The values within |
| 219 | * this field are not standardized and are implementer-specific. |
| 220 | * Platform-specific or -unique information MUST NOT be provided in |
| 221 | * this field. |
| 222 | * |
| 223 | */ |
| 224 | uint8_t vendor_info[]; /* [vendorInfoSize] */ |
| 225 | } id_event_struct_data_t; |
| 226 | |
| 227 | typedef struct { |
| 228 | id_event_struct_header_t struct_header; |
| 229 | id_event_struct_data_t struct_data; |
| 230 | } id_event_struct_t; |
| 231 | |
| 232 | typedef struct { |
| 233 | tcg_pcr_event_t header; |
| 234 | id_event_struct_header_t struct_header; |
| 235 | } id_event_headers_t; |
| 236 | |
| 237 | /* TPMT_HA Structure */ |
| 238 | typedef struct { |
| 239 | /* Selector of the hash contained in the digest that implies |
| 240 | * the size of the digest |
| 241 | */ |
| 242 | uint16_t algorithm_id; /* AlgorithmId */ |
| 243 | |
| 244 | /* Digest, depends on AlgorithmId */ |
| 245 | uint8_t digest[]; /* Digest[] */ |
| 246 | } tpmt_ha; |
| 247 | |
| 248 | /* |
| 249 | * TPML_DIGEST_VALUES Structure |
| 250 | */ |
| 251 | typedef struct { |
| 252 | /* The number of digests in the list */ |
| 253 | uint32_t count; /* Count */ |
| 254 | |
| 255 | /* The list of tagged digests, as sent to the TPM as part of a |
| 256 | * TPM2_PCR_Extend or as received from a TPM2_PCR_Event command |
| 257 | */ |
| 258 | tpmt_ha digests[]; /* Digests[Count] */ |
| 259 | } tpml_digest_values; |
| 260 | |
| 261 | /* |
| 262 | * TCG_PCR_EVENT2 header |
| 263 | */ |
| 264 | typedef struct { |
| 265 | /* The PCR Index to which this event was extended */ |
| 266 | uint32_t pcr_index; /* PCRIndex */ |
| 267 | |
| 268 | /* Type of event */ |
| 269 | uint32_t event_type; /* EventType */ |
| 270 | |
| 271 | /* Digests: |
| 272 | * A counted list of tagged digests, which contain the digest of |
| 273 | * the event data (or external data) for all active PCR banks |
| 274 | */ |
| 275 | tpml_digest_values digests; /* Digests */ |
| 276 | } event2_header_t; |
| 277 | |
| 278 | typedef struct event2_data { |
| 279 | /* The size of the event data */ |
| 280 | uint32_t event_size; /* EventSize */ |
| 281 | |
| 282 | /* The data of the event */ |
| 283 | uint8_t event[]; /* Event[EventSize] */ |
| 284 | } event2_data_t; |
| 285 | |
| 286 | /* |
| 287 | * Startup Locality Event |
| 288 | * Ref. TCG PC Client Platform Firmware Profile 9.4.5.3 |
| 289 | */ |
| 290 | typedef struct { |
| 291 | /* |
| 292 | * The NUL-terminated ASCII string "StartupLocality" SHALL be |
| 293 | * set to {0x53 0x74 0x61 0x72 0x74 0x75 0x70 0x4C 0x6F 0x63 |
| 294 | * 0x61 0x6C 0x69 0x74 0x79 0x00} |
| 295 | */ |
| 296 | uint8_t signature[16]; |
| 297 | |
| 298 | /* The Locality Indicator which sent the TPM2_Startup command */ |
| 299 | uint8_t startup_locality; |
| 300 | } startup_locality_event_t; |
| 301 | |
| 302 | #pragma pack(pop) |
| 303 | |
| 304 | #endif /* TCG_H */ |