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