tpm-v2.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (c) 2018 Bootlin
  4. * Author: Miquel Raynal <miquel.raynal@bootlin.com>
  5. */
  6. #ifndef __TPM_V2_H
  7. #define __TPM_V2_H
  8. #include <tpm-common.h>
  9. #define TPM2_DIGEST_LEN 32
  10. /**
  11. * TPM2 Structure Tags for command/response buffers.
  12. *
  13. * @TPM2_ST_NO_SESSIONS: the command does not need an authentication.
  14. * @TPM2_ST_SESSIONS: the command needs an authentication.
  15. */
  16. enum tpm2_structures {
  17. TPM2_ST_NO_SESSIONS = 0x8001,
  18. TPM2_ST_SESSIONS = 0x8002,
  19. };
  20. /**
  21. * TPM2 type of boolean.
  22. */
  23. enum tpm2_yes_no {
  24. TPMI_YES = 1,
  25. TPMI_NO = 0,
  26. };
  27. /**
  28. * TPM2 startup values.
  29. *
  30. * @TPM2_SU_CLEAR: reset the internal state.
  31. * @TPM2_SU_STATE: restore saved state (if any).
  32. */
  33. enum tpm2_startup_types {
  34. TPM2_SU_CLEAR = 0x0000,
  35. TPM2_SU_STATE = 0x0001,
  36. };
  37. /**
  38. * TPM2 permanent handles.
  39. *
  40. * @TPM2_RH_OWNER: refers to the 'owner' hierarchy.
  41. * @TPM2_RS_PW: indicates a password.
  42. * @TPM2_RH_LOCKOUT: refers to the 'lockout' hierarchy.
  43. * @TPM2_RH_ENDORSEMENT: refers to the 'endorsement' hierarchy.
  44. * @TPM2_RH_PLATFORM: refers to the 'platform' hierarchy.
  45. */
  46. enum tpm2_handles {
  47. TPM2_RH_OWNER = 0x40000001,
  48. TPM2_RS_PW = 0x40000009,
  49. TPM2_RH_LOCKOUT = 0x4000000A,
  50. TPM2_RH_ENDORSEMENT = 0x4000000B,
  51. TPM2_RH_PLATFORM = 0x4000000C,
  52. };
  53. /**
  54. * TPM2 command codes used at the beginning of a buffer, gives the command.
  55. *
  56. * @TPM2_CC_STARTUP: TPM2_Startup().
  57. * @TPM2_CC_SELF_TEST: TPM2_SelfTest().
  58. * @TPM2_CC_CLEAR: TPM2_Clear().
  59. * @TPM2_CC_CLEARCONTROL: TPM2_ClearControl().
  60. * @TPM2_CC_HIERCHANGEAUTH: TPM2_HierarchyChangeAuth().
  61. * @TPM2_CC_PCR_SETAUTHPOL: TPM2_PCR_SetAuthPolicy().
  62. * @TPM2_CC_DAM_RESET: TPM2_DictionaryAttackLockReset().
  63. * @TPM2_CC_DAM_PARAMETERS: TPM2_DictionaryAttackParameters().
  64. * @TPM2_CC_GET_CAPABILITY: TPM2_GetCapibility().
  65. * @TPM2_CC_PCR_READ: TPM2_PCR_Read().
  66. * @TPM2_CC_PCR_EXTEND: TPM2_PCR_Extend().
  67. * @TPM2_CC_PCR_SETAUTHVAL: TPM2_PCR_SetAuthValue().
  68. */
  69. enum tpm2_command_codes {
  70. TPM2_CC_STARTUP = 0x0144,
  71. TPM2_CC_SELF_TEST = 0x0143,
  72. TPM2_CC_CLEAR = 0x0126,
  73. TPM2_CC_CLEARCONTROL = 0x0127,
  74. TPM2_CC_HIERCHANGEAUTH = 0x0129,
  75. TPM2_CC_DAM_RESET = 0x0139,
  76. TPM2_CC_DAM_PARAMETERS = 0x013A,
  77. TPM2_CC_GET_CAPABILITY = 0x017A,
  78. TPM2_CC_PCR_READ = 0x017E,
  79. TPM2_CC_PCR_EXTEND = 0x0182,
  80. };
  81. /**
  82. * TPM2 return codes.
  83. */
  84. enum tpm2_return_codes {
  85. TPM2_RC_SUCCESS = 0x0000,
  86. TPM2_RC_BAD_TAG = 0x001E,
  87. TPM2_RC_FMT1 = 0x0080,
  88. TPM2_RC_HASH = TPM2_RC_FMT1 + 0x0003,
  89. TPM2_RC_VALUE = TPM2_RC_FMT1 + 0x0004,
  90. TPM2_RC_SIZE = TPM2_RC_FMT1 + 0x0015,
  91. TPM2_RC_BAD_AUTH = TPM2_RC_FMT1 + 0x0022,
  92. TPM2_RC_HANDLE = TPM2_RC_FMT1 + 0x000B,
  93. TPM2_RC_VER1 = 0x0100,
  94. TPM2_RC_INITIALIZE = TPM2_RC_VER1 + 0x0000,
  95. TPM2_RC_FAILURE = TPM2_RC_VER1 + 0x0001,
  96. TPM2_RC_DISABLED = TPM2_RC_VER1 + 0x0020,
  97. TPM2_RC_AUTH_MISSING = TPM2_RC_VER1 + 0x0025,
  98. TPM2_RC_COMMAND_CODE = TPM2_RC_VER1 + 0x0043,
  99. TPM2_RC_AUTHSIZE = TPM2_RC_VER1 + 0x0044,
  100. TPM2_RC_AUTH_CONTEXT = TPM2_RC_VER1 + 0x0045,
  101. TPM2_RC_NEEDS_TEST = TPM2_RC_VER1 + 0x0053,
  102. TPM2_RC_WARN = 0x0900,
  103. TPM2_RC_TESTING = TPM2_RC_WARN + 0x000A,
  104. TPM2_RC_REFERENCE_H0 = TPM2_RC_WARN + 0x0010,
  105. TPM2_RC_LOCKOUT = TPM2_RC_WARN + 0x0021,
  106. };
  107. /**
  108. * TPM2 algorithms.
  109. */
  110. enum tpm2_algorithms {
  111. TPM2_ALG_XOR = 0x0A,
  112. TPM2_ALG_SHA256 = 0x0B,
  113. TPM2_ALG_SHA384 = 0x0C,
  114. TPM2_ALG_SHA512 = 0x0D,
  115. TPM2_ALG_NULL = 0x10,
  116. };
  117. /**
  118. * Issue a TPM2_Startup command.
  119. *
  120. * @mode TPM startup mode
  121. *
  122. * @return code of the operation
  123. */
  124. u32 tpm2_startup(enum tpm2_startup_types mode);
  125. /**
  126. * Issue a TPM2_SelfTest command.
  127. *
  128. * @full_test Asking to perform all tests or only the untested ones
  129. *
  130. * @return code of the operation
  131. */
  132. u32 tpm2_self_test(enum tpm2_yes_no full_test);
  133. /**
  134. * Issue a TPM2_Clear command.
  135. *
  136. * @handle Handle
  137. * @pw Password
  138. * @pw_sz Length of the password
  139. *
  140. * @return code of the operation
  141. */
  142. u32 tpm2_clear(u32 handle, const char *pw, const ssize_t pw_sz);
  143. /**
  144. * Issue a TPM2_PCR_Extend command.
  145. *
  146. * @index Index of the PCR
  147. * @digest Value representing the event to be recorded
  148. *
  149. * @return code of the operation
  150. */
  151. u32 tpm2_pcr_extend(u32 index, const uint8_t *digest);
  152. /**
  153. * Issue a TPM2_PCR_Read command.
  154. *
  155. * @idx Index of the PCR
  156. * @idx_min_sz Minimum size in bytes of the pcrSelect array
  157. * @data Output buffer for contents of the named PCR
  158. * @updates Optional out parameter: number of updates for this PCR
  159. *
  160. * @return code of the operation
  161. */
  162. u32 tpm2_pcr_read(u32 idx, unsigned int idx_min_sz, void *data,
  163. unsigned int *updates);
  164. /**
  165. * Issue a TPM2_GetCapability command. This implementation is limited
  166. * to query property index that is 4-byte wide.
  167. *
  168. * @capability Partition of capabilities
  169. * @property Further definition of capability, limited to be 4 bytes wide
  170. * @buf Output buffer for capability information
  171. * @prop_count Size of output buffer
  172. *
  173. * @return code of the operation
  174. */
  175. u32 tpm2_get_capability(u32 capability, u32 property, void *buf,
  176. size_t prop_count);
  177. /**
  178. * Issue a TPM2_DictionaryAttackLockReset command.
  179. *
  180. * @pw Password
  181. * @pw_sz Length of the password
  182. *
  183. * @return code of the operation
  184. */
  185. u32 tpm2_dam_reset(const char *pw, const ssize_t pw_sz);
  186. /**
  187. * Issue a TPM2_DictionaryAttackParameters command.
  188. *
  189. * @pw Password
  190. * @pw_sz Length of the password
  191. * @max_tries Count of authorizations before lockout
  192. * @recovery_time Time before decrementation of the failure count
  193. * @lockout_recovery Time to wait after a lockout
  194. *
  195. * @return code of the operation
  196. */
  197. u32 tpm2_dam_parameters(const char *pw, const ssize_t pw_sz,
  198. unsigned int max_tries, unsigned int recovery_time,
  199. unsigned int lockout_recovery);
  200. #endif /* __TPM_V2_H */