tpm2-tss 4.2.0
TPM Software stack 2.0 TCG spec compliant implementation
efi_event.h
1/* SPDX-FileCopyrightText: 2021, Fraunhofer SIT sponsored by Infineon */
2/* SPDX-FileCopyrightText: 2023, Juergen Repp */
3/* SPDX-License-Identifier: BSD-2-Clause */
4#ifndef TCG_EFI_EVENT_H
5#define TCG_EFI_EVENT_H 1
6
7#include <uchar.h> // for char16_t
8#include <uuid/uuid.h> // for uuid_t
9
10#include "tss2_common.h" // for UINT32, BYTE, UINT64, UINT8, UINT16
11
12/*
13 * Log event types. These are spread out over 2 specs:
14 * "TCG EFI Protocol Specification For TPM Family 1.1 or 1.2" and
15 * "TCG PC Client Specific Implementation Specification for Conventional BIOS"
16 */
17#define EV_PREBOOT_CERT 0x0
18#define EV_POST_CODE 0x1
19#define EV_UNUSED 0x2
20#define EV_NO_ACTION 0x3
21#define EV_SEPARATOR 0x4
22#define EV_ACTION 0x5
23#define EV_EVENT_TAG 0x6
24#define EV_S_CRTM_CONTENTS 0x7
25#define EV_S_CRTM_VERSION 0x8
26#define EV_CPU_MICROCODE 0x9
27#define EV_PLATFORM_CONFIG_FLAGS 0xa
28#define EV_TABLE_OF_DEVICES 0xb
29#define EV_COMPACT_HASH 0xc
30#define EV_IPL 0xd
31#define EV_IPL_PARTITION_DATA 0xe
32#define EV_NONHOST_CODE 0xf
33#define EV_NONHOST_CONFIG 0x10
34#define EV_NONHOST_INFO 0x11
35#define EV_OMIT_BOOT_DEVICE_EVENTS 0x12
36
37/* TCG EFI Platform Specification For TPM Family 1.1 or 1.2 */
38#define EV_EFI_EVENT_BASE 0x80000000
39#define EV_EFI_VARIABLE_DRIVER_CONFIG (EV_EFI_EVENT_BASE + 0x1)
40#define EV_EFI_VARIABLE_BOOT (EV_EFI_EVENT_BASE + 0x2)
41#define EV_EFI_BOOT_SERVICES_APPLICATION (EV_EFI_EVENT_BASE + 0x3)
42#define EV_EFI_BOOT_SERVICES_DRIVER (EV_EFI_EVENT_BASE + 0x4)
43#define EV_EFI_RUNTIME_SERVICES_DRIVER (EV_EFI_EVENT_BASE + 0x5)
44#define EV_EFI_GPT_EVENT (EV_EFI_EVENT_BASE + 0x6)
45#define EV_EFI_ACTION (EV_EFI_EVENT_BASE + 0x7)
46#define EV_EFI_PLATFORM_FIRMWARE_BLOB (EV_EFI_EVENT_BASE + 0x8)
47#define EV_EFI_HANDOFF_TABLES (EV_EFI_EVENT_BASE + 0x9)
48#define EV_EFI_PLATFORM_FIRMWARE_BLOB2 (EV_EFI_EVENT_BASE + 0xa)
49#define EV_EFI_HANDOFF_TABLES2 (EV_EFI_EVENT_BASE + 0xb)
50#define EV_EFI_VARIABLE_BOOT2 (EV_EFI_EVENT_BASE + 0xc)
51#define EV_EFI_HCRTM_EVENT (EV_EFI_EVENT_BASE + 0x10)
52#define EV_EFI_VARIABLE_AUTHORITY (EV_EFI_EVENT_BASE + 0xe0)
53
54#ifndef PACKED
55#define PACKED __attribute__((__packed__))
56#endif
57
58typedef struct {
59 UINT16 AlgorithmId;
60 UINT8 Digest[];
61} PACKED TCG_DIGEST2;
62
63typedef struct {
64 UINT32 EventSize;
65 UINT8 Event[];
66} PACKED TCG_EVENT2;
67
68typedef struct {
69 UINT32 PCRIndex;
70 UINT32 EventType;
71 UINT32 DigestCount;
72 TCG_DIGEST2 Digests[];
73 /* TCG_EVENT2 comes next */
74} PACKED TCG_EVENT_HEADER2;
75
76/* Helper structure for dealing with unaligned char16_t */
77typedef struct {
78 char16_t c;
79} PACKED UTF16_CHAR;
80
81typedef struct {
82 uuid_t VariableName;
83 UINT64 UnicodeNameLength;
84 UINT64 VariableDataLength;
85 char16_t UnicodeName[];
86 /* INT8 VariableData[] comes next */
87} PACKED UEFI_VARIABLE_DATA;
88
89typedef UINT64 UEFI_PHYSICAL_ADDRESS;
90typedef struct {
91 UEFI_PHYSICAL_ADDRESS BlobBase;
92 UINT64 BlobLength;
93} PACKED UEFI_PLATFORM_FIRMWARE_BLOB;
94
95typedef struct {
96 UINT32 pcrIndex;
97 UINT32 eventType;
98 BYTE digest[20];
99 UINT32 eventDataSize;
100 BYTE event[];
101} PACKED TCG_EVENT;
102
103typedef struct {
104 UINT16 algorithmId;
105 UINT16 digestSize;
106} PACKED TCG_SPECID_ALG;
107
108typedef struct {
109 UINT8 vendorInfoSize;
110 BYTE vendorInfo[];
111} PACKED TCG_VENDOR_INFO;
112
113typedef struct {
114 BYTE Signature[16];
115 UINT32 platformClass;
116 UINT8 specVersionMinor;
117 UINT8 specVersionMajor;
118 UINT8 specErrata;
119 UINT8 uintnSize;
120 UINT32 numberOfAlgorithms;
121 TCG_SPECID_ALG digestSizes[];
122 /* then TCG_VendorStuff */
123} PACKED TCG_SPECID_EVENT;
124
125typedef struct {
126 UEFI_PHYSICAL_ADDRESS ImageLocationInMemory;
127 UINT64 ImageLengthInMemory;
128 UINT64 ImageLinkTimeAddress;
129 UINT64 LengthOfDevicePath;
130 BYTE DevicePath[];
131} PACKED UEFI_IMAGE_LOAD_EVENT;
132
133/*
134 * EV_NO_ACTION_STRUCT is the structure of an EV_NO_ACTION event.
135 * Described in TCG PCClient PFP section 9.4.5.
136 * The Signature identifies which arm of the union applies.
137 */
138typedef struct {
139 BYTE Signature[16];
140 union {
141 BYTE StartupLocality;
142 } Cases;
143} PACKED EV_NO_ACTION_STRUCT;
144
145static const BYTE STARTUP_LOCALITY_SIGNATURE[16] = { 0x53, 0x74, 0x61, 0x72, 0x74, 0x75, 0x70, 0x4C,
146 0x6F, 0x63, 0x61, 0x6C, 0x69, 0x74, 0x79, 0 };
147
148#endif