tcg.h 8.1 KB

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