tpm.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2018 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef GRUB_EFI_TPM_HEADER
  19. #define GRUB_EFI_TPM_HEADER 1
  20. #define EFI_TPM_GUID {0xf541796d, 0xa62e, 0x4954, {0xa7, 0x75, 0x95, 0x84, 0xf6, 0x1b, 0x9c, 0xdd }};
  21. #define EFI_TPM2_GUID {0x607f766c, 0x7455, 0x42be, {0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f }};
  22. #define TCG_ALG_SHA 0x00000004
  23. /* These structs are as defined in the TCG EFI Protocol Specification, family 2.0. */
  24. struct __TCG_VERSION
  25. {
  26. grub_efi_uint8_t Major;
  27. grub_efi_uint8_t Minor;
  28. grub_efi_uint8_t RevMajor;
  29. grub_efi_uint8_t RevMinor;
  30. };
  31. typedef struct __TCG_VERSION TCG_VERSION;
  32. struct __TCG_EFI_BOOT_SERVICE_CAPABILITY
  33. {
  34. /* Size of this structure. */
  35. grub_efi_uint8_t Size;
  36. TCG_VERSION StructureVersion;
  37. TCG_VERSION ProtocolSpecVersion;
  38. /* Hash algorithms supported by this TPM. */
  39. grub_efi_uint8_t HashAlgorithmBitmap;
  40. /* 1 if TPM present. */
  41. char TPMPresentFlag;
  42. /* 1 if TPM deactivated. */
  43. char TPMDeactivatedFlag;
  44. };
  45. typedef struct __TCG_EFI_BOOT_SERVICE_CAPABILITY TCG_EFI_BOOT_SERVICE_CAPABILITY;
  46. struct tdTCG_PCR_EVENT
  47. {
  48. grub_efi_uint32_t PCRIndex;
  49. grub_efi_uint32_t EventType;
  50. grub_efi_uint8_t digest[20];
  51. grub_efi_uint32_t EventSize;
  52. grub_efi_uint8_t Event[1];
  53. };
  54. typedef struct tdTCG_PCR_EVENT TCG_PCR_EVENT;
  55. struct grub_efi_tpm_protocol
  56. {
  57. grub_efi_status_t
  58. (__grub_efi_api *status_check) (struct grub_efi_tpm_protocol *this,
  59. TCG_EFI_BOOT_SERVICE_CAPABILITY *ProtocolCapability,
  60. grub_efi_uint32_t *TCGFeatureFlags,
  61. grub_efi_physical_address_t *EventLogLocation,
  62. grub_efi_physical_address_t *EventLogLastEntry);
  63. grub_efi_status_t
  64. (__grub_efi_api *hash_all) (struct grub_efi_tpm_protocol *this,
  65. grub_efi_uint8_t *HashData,
  66. grub_efi_uint64_t HashLen,
  67. grub_efi_uint32_t AlgorithmId,
  68. grub_efi_uint64_t *HashedDataLen,
  69. grub_efi_uint8_t **HashedDataResult);
  70. grub_efi_status_t
  71. (__grub_efi_api *log_event) (struct grub_efi_tpm_protocol *this,
  72. TCG_PCR_EVENT *TCGLogData,
  73. grub_efi_uint32_t *EventNumber,
  74. grub_efi_uint32_t Flags);
  75. grub_efi_status_t
  76. (__grub_efi_api *pass_through_to_tpm) (struct grub_efi_tpm_protocol *this,
  77. grub_efi_uint32_t TpmInputParameterBlockSize,
  78. grub_efi_uint8_t *TpmInputParameterBlock,
  79. grub_efi_uint32_t TpmOutputParameterBlockSize,
  80. grub_efi_uint8_t *TpmOutputParameterBlock);
  81. grub_efi_status_t
  82. (__grub_efi_api *log_extend_event) (struct grub_efi_tpm_protocol *this,
  83. grub_efi_physical_address_t HashData,
  84. grub_efi_uint64_t HashDataLen,
  85. grub_efi_uint32_t AlgorithmId,
  86. TCG_PCR_EVENT *TCGLogData,
  87. grub_efi_uint32_t *EventNumber,
  88. grub_efi_physical_address_t *EventLogLastEntry);
  89. };
  90. typedef struct grub_efi_tpm_protocol grub_efi_tpm_protocol_t;
  91. typedef grub_efi_uint32_t EFI_TCG2_EVENT_LOG_BITMAP;
  92. typedef grub_efi_uint32_t EFI_TCG2_EVENT_LOG_FORMAT;
  93. typedef grub_efi_uint32_t EFI_TCG2_EVENT_ALGORITHM_BITMAP;
  94. struct tdEFI_TCG2_VERSION
  95. {
  96. grub_efi_uint8_t Major;
  97. grub_efi_uint8_t Minor;
  98. } GRUB_PACKED;
  99. typedef struct tdEFI_TCG2_VERSION EFI_TCG2_VERSION;
  100. struct tdEFI_TCG2_BOOT_SERVICE_CAPABILITY
  101. {
  102. grub_efi_uint8_t Size;
  103. EFI_TCG2_VERSION StructureVersion;
  104. EFI_TCG2_VERSION ProtocolVersion;
  105. EFI_TCG2_EVENT_ALGORITHM_BITMAP HashAlgorithmBitmap;
  106. EFI_TCG2_EVENT_LOG_BITMAP SupportedEventLogs;
  107. grub_efi_boolean_t TPMPresentFlag;
  108. grub_efi_uint16_t MaxCommandSize;
  109. grub_efi_uint16_t MaxResponseSize;
  110. grub_efi_uint32_t ManufacturerID;
  111. grub_efi_uint32_t NumberOfPcrBanks;
  112. EFI_TCG2_EVENT_ALGORITHM_BITMAP ActivePcrBanks;
  113. };
  114. typedef struct tdEFI_TCG2_BOOT_SERVICE_CAPABILITY EFI_TCG2_BOOT_SERVICE_CAPABILITY;
  115. typedef grub_efi_uint32_t TCG_PCRINDEX;
  116. typedef grub_efi_uint32_t TCG_EVENTTYPE;
  117. struct tdEFI_TCG2_EVENT_HEADER
  118. {
  119. grub_efi_uint32_t HeaderSize;
  120. grub_efi_uint16_t HeaderVersion;
  121. TCG_PCRINDEX PCRIndex;
  122. TCG_EVENTTYPE EventType;
  123. } GRUB_PACKED;
  124. typedef struct tdEFI_TCG2_EVENT_HEADER EFI_TCG2_EVENT_HEADER;
  125. struct tdEFI_TCG2_EVENT
  126. {
  127. grub_efi_uint32_t Size;
  128. EFI_TCG2_EVENT_HEADER Header;
  129. grub_efi_uint8_t Event[1];
  130. } GRUB_PACKED;
  131. typedef struct tdEFI_TCG2_EVENT EFI_TCG2_EVENT;
  132. struct grub_efi_tpm2_protocol
  133. {
  134. grub_efi_status_t
  135. (__grub_efi_api *get_capability) (struct grub_efi_tpm2_protocol *this,
  136. EFI_TCG2_BOOT_SERVICE_CAPABILITY *ProtocolCapability);
  137. grub_efi_status_t
  138. (__grub_efi_api *get_event_log) (struct grub_efi_tpm2_protocol *this,
  139. EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat,
  140. grub_efi_physical_address_t *EventLogLocation,
  141. grub_efi_physical_address_t *EventLogLastEntry,
  142. grub_efi_boolean_t *EventLogTruncated);
  143. grub_efi_status_t
  144. (__grub_efi_api *hash_log_extend_event) (struct grub_efi_tpm2_protocol *this,
  145. grub_efi_uint64_t Flags,
  146. grub_efi_physical_address_t DataToHash,
  147. grub_efi_uint64_t DataToHashLen,
  148. EFI_TCG2_EVENT *EfiTcgEvent);
  149. grub_efi_status_t
  150. (__grub_efi_api *submit_command) (struct grub_efi_tpm2_protocol *this,
  151. grub_efi_uint32_t InputParameterBlockSize,
  152. grub_efi_uint8_t *InputParameterBlock,
  153. grub_efi_uint32_t OutputParameterBlockSize,
  154. grub_efi_uint8_t *OutputParameterBlock);
  155. grub_efi_status_t
  156. (__grub_efi_api *get_active_pcr_banks) (struct grub_efi_tpm2_protocol *this,
  157. grub_efi_uint32_t *ActivePcrBanks);
  158. grub_efi_status_t
  159. (__grub_efi_api *set_active_pcr_banks) (struct grub_efi_tpm2_protocol *this,
  160. grub_efi_uint32_t ActivePcrBanks);
  161. grub_efi_status_t
  162. (__grub_efi_api *get_result_of_set_active_pcr_banks) (struct grub_efi_tpm2_protocol *this,
  163. grub_efi_uint32_t *OperationPresent,
  164. grub_efi_uint32_t *Response);
  165. };
  166. typedef struct grub_efi_tpm2_protocol grub_efi_tpm2_protocol_t;
  167. #endif