tpm1_tss_constants.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * Copyright 2016 The Chromium OS Authors. All rights reserved.
  3. * Use of this source code is governed by a BSD-style license that can be
  4. * found in the LICENSE file.
  5. *
  6. * Some TPM constants and type definitions for standalone compilation for use
  7. * in the firmware
  8. */
  9. #ifndef __VBOOT_REFERENCE_FIRMWARE_INCLUDE_TPM1_TSS_CONSTANTS_H
  10. #define __VBOOT_REFERENCE_FIRMWARE_INCLUDE_TPM1_TSS_CONSTANTS_H
  11. #include <stdint.h>
  12. #define TPM_MAX_COMMAND_SIZE 4096
  13. #define TPM_LARGE_ENOUGH_COMMAND_SIZE 256 /* saves space in the firmware */
  14. #define TPM_PUBEK_SIZE 256
  15. #define TPM_PCR_DIGEST 20
  16. #define TPM_E_NON_FATAL 0x800
  17. #define TPM_E_AREA_LOCKED ((uint32_t) 0x0000003c)
  18. #define TPM_E_BADINDEX ((uint32_t) 0x00000002)
  19. #define TPM_E_BAD_PRESENCE ((uint32_t) 0x0000002d)
  20. #define TPM_E_IOERROR ((uint32_t) 0x0000001f)
  21. #define TPM_E_INVALID_POSTINIT ((uint32_t) 0x00000026)
  22. #define TPM_E_MAXNVWRITES ((uint32_t) 0x00000048)
  23. #define TPM_E_OWNER_SET ((uint32_t) 0x00000014)
  24. #define TPM_E_NEEDS_SELFTEST ((uint32_t) (TPM_E_NON_FATAL + 1))
  25. #define TPM_E_DOING_SELFTEST ((uint32_t) (TPM_E_NON_FATAL + 2))
  26. #define TPM_NV_INDEX0 ((uint32_t) 0x00000000)
  27. #define TPM_NV_INDEX_LOCK ((uint32_t) 0xffffffff)
  28. #define TPM_NV_PER_GLOBALLOCK (((uint32_t) 1) << 15)
  29. #define TPM_NV_PER_PPWRITE (((uint32_t) 1) << 0)
  30. #define TPM_NV_PER_READ_STCLEAR (((uint32_t)1) << 31)
  31. #define TPM_NV_PER_WRITE_STCLEAR (((uint32_t)1) << 14)
  32. #define TPM_TAG_NV_ATTRIBUTES ((uint16_t) 0x0017)
  33. #define TPM_TAG_NV_DATA_PUBLIC ((uint16_t) 0x0018)
  34. #define TPM_TAG_RQU_COMMAND ((uint16_t) 0xc1)
  35. #define TPM_TAG_RQU_AUTH1_COMMAND ((uint16_t) 0xc2)
  36. #define TPM_TAG_RQU_AUTH2_COMMAND ((uint16_t) 0xc3)
  37. #define TPM_TAG_RSP_COMMAND ((uint16_t) 0xc4)
  38. #define TPM_TAG_RSP_AUTH1_COMMAND ((uint16_t) 0xc5)
  39. #define TPM_TAG_RSP_AUTH2_COMMAND ((uint16_t) 0xc6)
  40. typedef uint8_t TSS_BOOL;
  41. typedef uint8_t TPM_BOOL;
  42. typedef uint16_t TPM_TAG;
  43. typedef uint16_t TPM_STRUCTURE_TAG;
  44. typedef uint32_t TPM_NV_INDEX;
  45. typedef uint32_t TPM_NV_PER_ATTRIBUTES;
  46. typedef uint8_t TPM_LOCALITY_SELECTION;
  47. typedef uint32_t TPM_COMMAND_CODE;
  48. typedef uint16_t TPM_PHYSICAL_PRESENCE;
  49. typedef uint16_t TPM_STARTUP_TYPE;
  50. typedef uint32_t TPM_CAPABILITY_AREA;
  51. #define TPM_CAP_FLAG ((uint32_t) 0x00000004)
  52. #define TPM_CAP_FLAG_PERMANENT ((uint32_t) 0x00000108)
  53. #define TPM_CAP_FLAG_VOLATILE ((uint32_t) 0x00000109)
  54. #define TPM_CAP_PROPERTY ((uint32_t) 0x00000005)
  55. #define TPM_CAP_PROP_OWNER ((uint32_t) 0x00000111)
  56. #define TPM_CAP_NV_INDEX ((uint32_t) 0x00000011)
  57. #define TPM_ST_CLEAR ((uint16_t) 0x0001)
  58. #define TPM_ST_STATE ((uint16_t) 0x0002)
  59. #define TPM_ST_DEACTIVATED ((uint16_t) 0x0003)
  60. #define TPM_LOC_FOUR (((uint32_t)1)<<4)
  61. #define TPM_LOC_THREE (((uint32_t)1)<<3)
  62. #define TPM_LOC_TWO (((uint32_t)1)<<2)
  63. #define TPM_LOC_ONE (((uint32_t)1)<<1)
  64. #define TPM_LOC_ZERO (((uint32_t)1)<<0)
  65. #define TPM_PHYSICAL_PRESENCE_LOCK ((uint16_t) 0x0004)
  66. #define TPM_PHYSICAL_PRESENCE_PRESENT ((uint16_t) 0x0008)
  67. #define TPM_PHYSICAL_PRESENCE_NOTPRESENT ((uint16_t) 0x0010)
  68. #define TPM_PHYSICAL_PRESENCE_CMD_ENABLE ((uint16_t) 0x0020)
  69. #define TPM_PHYSICAL_PRESENCE_HW_ENABLE ((uint16_t) 0x0040)
  70. #define TPM_PHYSICAL_PRESENCE_LIFETIME_LOCK ((uint16_t) 0x0080)
  71. #define TPM_PHYSICAL_PRESENCE_CMD_DISABLE ((uint16_t) 0x0100)
  72. #define TPM_PHYSICAL_PRESENCE_HW_DISABLE ((uint16_t) 0x0200)
  73. #define TPM_SHA1_160_HASH_LEN 0x14
  74. #define TPM_SHA1BASED_NONCE_LEN TPM_SHA1_160_HASH_LEN
  75. typedef struct tdTPM_DIGEST
  76. {
  77. uint8_t digest[TPM_SHA1_160_HASH_LEN];
  78. } TPM_DIGEST;
  79. typedef TPM_DIGEST TPM_COMPOSITE_HASH;
  80. typedef struct tdTPM_PCR_SELECTION
  81. {
  82. uint16_t sizeOfSelect;
  83. uint8_t *pcrSelect;
  84. } TPM_PCR_SELECTION;
  85. typedef struct tdTPM_NV_ATTRIBUTES
  86. {
  87. TPM_STRUCTURE_TAG tag;
  88. TPM_NV_PER_ATTRIBUTES attributes;
  89. } TPM_NV_ATTRIBUTES;
  90. typedef struct tdTPM_PCR_INFO_SHORT
  91. {
  92. TPM_PCR_SELECTION pcrSelection;
  93. TPM_LOCALITY_SELECTION localityAtRelease;
  94. TPM_COMPOSITE_HASH digestAtRelease;
  95. } TPM_PCR_INFO_SHORT;
  96. typedef struct tdTPM_PERMANENT_FLAGS
  97. {
  98. TPM_STRUCTURE_TAG tag;
  99. TSS_BOOL disable;
  100. TSS_BOOL ownership;
  101. TSS_BOOL deactivated;
  102. TSS_BOOL readPubek;
  103. TSS_BOOL disableOwnerClear;
  104. TSS_BOOL allowMaintenance;
  105. TSS_BOOL physicalPresenceLifetimeLock;
  106. TSS_BOOL physicalPresenceHWEnable;
  107. TSS_BOOL physicalPresenceCMDEnable;
  108. TSS_BOOL CEKPUsed;
  109. TSS_BOOL TPMpost;
  110. TSS_BOOL TPMpostLock;
  111. TSS_BOOL FIPS;
  112. TSS_BOOL Operator;
  113. TSS_BOOL enableRevokeEK;
  114. TSS_BOOL nvLocked;
  115. TSS_BOOL readSRKPub;
  116. TSS_BOOL tpmEstablished;
  117. TSS_BOOL maintenanceDone;
  118. TSS_BOOL disableFullDALogicInfo;
  119. } TPM_PERMANENT_FLAGS;
  120. typedef struct tdTPM_STCLEAR_FLAGS{
  121. TPM_STRUCTURE_TAG tag;
  122. TSS_BOOL deactivated;
  123. TSS_BOOL disableForceClear;
  124. TSS_BOOL physicalPresence;
  125. TSS_BOOL physicalPresenceLock;
  126. TSS_BOOL bGlobalLock;
  127. } TPM_STCLEAR_FLAGS;
  128. typedef struct tdTPM_NV_DATA_PUBLIC
  129. {
  130. TPM_STRUCTURE_TAG tag;
  131. TPM_NV_INDEX nvIndex;
  132. TPM_PCR_INFO_SHORT pcrInfoRead;
  133. TPM_PCR_INFO_SHORT pcrInfoWrite;
  134. TPM_NV_ATTRIBUTES permission;
  135. TPM_BOOL bReadSTClear;
  136. TPM_BOOL bWriteSTClear;
  137. TPM_BOOL bWriteDefine;
  138. uint32_t dataSize;
  139. } TPM_NV_DATA_PUBLIC;
  140. typedef struct tdTPM_NONCE
  141. {
  142. uint8_t nonce[TPM_SHA1BASED_NONCE_LEN];
  143. } TPM_NONCE;
  144. /* Ordinals */
  145. #define TPM_ORD_ContinueSelfTest ((uint32_t) 0x00000053)
  146. #define TPM_ORD_Extend ((uint32_t) 0x00000014)
  147. #define TPM_ORD_ForceClear ((uint32_t) 0x0000005D)
  148. #define TPM_ORD_GetCapability ((uint32_t) 0x00000065)
  149. #define TPM_ORD_GetRandom ((uint32_t) 0x00000046)
  150. #define TPM_ORD_NV_DefineSpace ((uint32_t) 0x000000CC)
  151. #define TPM_ORD_NV_ReadValue ((uint32_t) 0x000000CF)
  152. #define TPM_ORD_NV_WriteValue ((uint32_t) 0x000000CD)
  153. #define TPM_ORD_PcrRead ((uint32_t) 0x00000015)
  154. #define TPM_ORD_PhysicalEnable ((uint32_t) 0x0000006F)
  155. #define TPM_ORD_PhysicalDisable ((uint32_t) 0x00000070)
  156. #define TSC_ORD_PhysicalPresence ((uint32_t) 0x4000000A)
  157. #define TPM_ORD_PhysicalSetDeactivated ((uint32_t) 0x00000072)
  158. #define TPM_ORD_ReadPubek ((uint32_t) 0x0000007C)
  159. #define TPM_ORD_SaveState ((uint32_t) 0x00000098)
  160. #define TPM_ORD_SelfTestFull ((uint32_t) 0x00000050)
  161. #define TPM_ORD_Startup ((uint32_t) 0x00000099)
  162. #endif /* ! __VBOOT_REFERENCE_FIRMWARE_INCLUDE_TPM1_TSS_CONSTANTS_H */