Tpm2CommandLib.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  1. /** @file
  2. This library is used by other modules to send TPM2 command.
  3. Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef _TPM2_COMMAND_LIB_H_
  7. #define _TPM2_COMMAND_LIB_H_
  8. #include <IndustryStandard/Tpm20.h>
  9. /**
  10. This command starts a hash or an Event sequence.
  11. If hashAlg is an implemented hash, then a hash sequence is started.
  12. If hashAlg is TPM_ALG_NULL, then an Event sequence is started.
  13. @param[in] HashAlg The hash algorithm to use for the hash sequence
  14. An Event sequence starts if this is TPM_ALG_NULL.
  15. @param[out] SequenceHandle A handle to reference the sequence
  16. @retval EFI_SUCCESS Operation completed successfully.
  17. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  18. **/
  19. EFI_STATUS
  20. EFIAPI
  21. Tpm2HashSequenceStart (
  22. IN TPMI_ALG_HASH HashAlg,
  23. OUT TPMI_DH_OBJECT *SequenceHandle
  24. );
  25. /**
  26. This command is used to add data to a hash or HMAC sequence.
  27. The amount of data in buffer may be any size up to the limits of the TPM.
  28. NOTE: In all TPM, a buffer size of 1,024 octets is allowed.
  29. @param[in] SequenceHandle Handle for the sequence object
  30. @param[in] Buffer Data to be added to hash
  31. @retval EFI_SUCCESS Operation completed successfully.
  32. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  33. **/
  34. EFI_STATUS
  35. EFIAPI
  36. Tpm2SequenceUpdate (
  37. IN TPMI_DH_OBJECT SequenceHandle,
  38. IN TPM2B_MAX_BUFFER *Buffer
  39. );
  40. /**
  41. This command adds the last part of data, if any, to an Event sequence and returns the result in a digest list.
  42. If pcrHandle references a PCR and not TPM_RH_NULL, then the returned digest list is processed in
  43. the same manner as the digest list input parameter to TPM2_PCR_Extend() with the pcrHandle in each
  44. bank extended with the associated digest value.
  45. @param[in] PcrHandle PCR to be extended with the Event data
  46. @param[in] SequenceHandle Authorization for the sequence
  47. @param[in] Buffer Data to be added to the Event
  48. @param[out] Results List of digests computed for the PCR
  49. @retval EFI_SUCCESS Operation completed successfully.
  50. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  51. **/
  52. EFI_STATUS
  53. EFIAPI
  54. Tpm2EventSequenceComplete (
  55. IN TPMI_DH_PCR PcrHandle,
  56. IN TPMI_DH_OBJECT SequenceHandle,
  57. IN TPM2B_MAX_BUFFER *Buffer,
  58. OUT TPML_DIGEST_VALUES *Results
  59. );
  60. /**
  61. This command adds the last part of data, if any, to a hash/HMAC sequence and returns the result.
  62. @param[in] SequenceHandle Authorization for the sequence
  63. @param[in] Buffer Data to be added to the hash/HMAC
  64. @param[out] Result The returned HMAC or digest in a sized buffer
  65. @retval EFI_SUCCESS Operation completed successfully.
  66. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  67. **/
  68. EFI_STATUS
  69. EFIAPI
  70. Tpm2SequenceComplete (
  71. IN TPMI_DH_OBJECT SequenceHandle,
  72. IN TPM2B_MAX_BUFFER *Buffer,
  73. OUT TPM2B_DIGEST *Result
  74. );
  75. /**
  76. Send Startup command to TPM2.
  77. @param[in] StartupType TPM_SU_CLEAR or TPM_SU_STATE
  78. @retval EFI_SUCCESS Operation completed successfully.
  79. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  80. **/
  81. EFI_STATUS
  82. EFIAPI
  83. Tpm2Startup (
  84. IN TPM_SU StartupType
  85. );
  86. /**
  87. Send Shutdown command to TPM2.
  88. @param[in] ShutdownType TPM_SU_CLEAR or TPM_SU_STATE.
  89. @retval EFI_SUCCESS Operation completed successfully.
  90. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  91. **/
  92. EFI_STATUS
  93. EFIAPI
  94. Tpm2Shutdown (
  95. IN TPM_SU ShutdownType
  96. );
  97. /**
  98. This command causes the TPM to perform a test of its capabilities.
  99. If the fullTest is YES, the TPM will test all functions.
  100. If fullTest = NO, the TPM will only test those functions that have not previously been tested.
  101. @param[in] FullTest YES if full test to be performed
  102. NO if only test of untested functions required
  103. @retval EFI_SUCCESS Operation completed successfully.
  104. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  105. **/
  106. EFI_STATUS
  107. EFIAPI
  108. Tpm2SelfTest (
  109. IN TPMI_YES_NO FullTest
  110. );
  111. /**
  112. This command allows setting of the authorization policy for the platform hierarchy (platformPolicy), the
  113. storage hierarchy (ownerPolicy), and and the endorsement hierarchy (endorsementPolicy).
  114. @param[in] AuthHandle TPM_RH_ENDORSEMENT, TPM_RH_OWNER or TPM_RH_PLATFORM+{PP} parameters to be validated
  115. @param[in] AuthSession Auth Session context
  116. @param[in] AuthPolicy An authorization policy hash
  117. @param[in] HashAlg The hash algorithm to use for the policy
  118. @retval EFI_SUCCESS Operation completed successfully.
  119. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  120. **/
  121. EFI_STATUS
  122. EFIAPI
  123. Tpm2SetPrimaryPolicy (
  124. IN TPMI_RH_HIERARCHY_AUTH AuthHandle,
  125. IN TPMS_AUTH_COMMAND *AuthSession,
  126. IN TPM2B_DIGEST *AuthPolicy,
  127. IN TPMI_ALG_HASH HashAlg
  128. );
  129. /**
  130. This command removes all TPM context associated with a specific Owner.
  131. @param[in] AuthHandle TPM_RH_LOCKOUT or TPM_RH_PLATFORM+{PP}
  132. @param[in] AuthSession Auth Session context
  133. @retval EFI_SUCCESS Operation completed successfully.
  134. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  135. **/
  136. EFI_STATUS
  137. EFIAPI
  138. Tpm2Clear (
  139. IN TPMI_RH_CLEAR AuthHandle,
  140. IN TPMS_AUTH_COMMAND *AuthSession OPTIONAL
  141. );
  142. /**
  143. Disables and enables the execution of TPM2_Clear().
  144. @param[in] AuthHandle TPM_RH_LOCKOUT or TPM_RH_PLATFORM+{PP}
  145. @param[in] AuthSession Auth Session context
  146. @param[in] Disable YES if the disableOwnerClear flag is to be SET,
  147. NO if the flag is to be CLEAR.
  148. @retval EFI_SUCCESS Operation completed successfully.
  149. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  150. **/
  151. EFI_STATUS
  152. EFIAPI
  153. Tpm2ClearControl (
  154. IN TPMI_RH_CLEAR AuthHandle,
  155. IN TPMS_AUTH_COMMAND *AuthSession OPTIONAL,
  156. IN TPMI_YES_NO Disable
  157. );
  158. /**
  159. This command allows the authorization secret for a hierarchy or lockout to be changed using the current
  160. authorization value as the command authorization.
  161. @param[in] AuthHandle TPM_RH_LOCKOUT, TPM_RH_ENDORSEMENT, TPM_RH_OWNER or TPM_RH_PLATFORM+{PP}
  162. @param[in] AuthSession Auth Session context
  163. @param[in] NewAuth New authorization secret
  164. @retval EFI_SUCCESS Operation completed successfully.
  165. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  166. **/
  167. EFI_STATUS
  168. EFIAPI
  169. Tpm2HierarchyChangeAuth (
  170. IN TPMI_RH_HIERARCHY_AUTH AuthHandle,
  171. IN TPMS_AUTH_COMMAND *AuthSession,
  172. IN TPM2B_AUTH *NewAuth
  173. );
  174. /**
  175. This replaces the current EPS with a value from the RNG and sets the Endorsement hierarchy controls to
  176. their default initialization values.
  177. @param[in] AuthHandle TPM_RH_PLATFORM+{PP}
  178. @param[in] AuthSession Auth Session context
  179. @retval EFI_SUCCESS Operation completed successfully.
  180. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  181. **/
  182. EFI_STATUS
  183. EFIAPI
  184. Tpm2ChangeEPS (
  185. IN TPMI_RH_PLATFORM AuthHandle,
  186. IN TPMS_AUTH_COMMAND *AuthSession
  187. );
  188. /**
  189. This replaces the current PPS with a value from the RNG and sets platformPolicy to the default
  190. initialization value (the Empty Buffer).
  191. @param[in] AuthHandle TPM_RH_PLATFORM+{PP}
  192. @param[in] AuthSession Auth Session context
  193. @retval EFI_SUCCESS Operation completed successfully.
  194. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  195. **/
  196. EFI_STATUS
  197. EFIAPI
  198. Tpm2ChangePPS (
  199. IN TPMI_RH_PLATFORM AuthHandle,
  200. IN TPMS_AUTH_COMMAND *AuthSession
  201. );
  202. /**
  203. This command enables and disables use of a hierarchy.
  204. @param[in] AuthHandle TPM_RH_ENDORSEMENT, TPM_RH_OWNER or TPM_RH_PLATFORM+{PP}
  205. @param[in] AuthSession Auth Session context
  206. @param[in] Hierarchy Hierarchy of the enable being modified
  207. @param[in] State YES if the enable should be SET,
  208. NO if the enable should be CLEAR
  209. @retval EFI_SUCCESS Operation completed successfully.
  210. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  211. **/
  212. EFI_STATUS
  213. EFIAPI
  214. Tpm2HierarchyControl (
  215. IN TPMI_RH_HIERARCHY AuthHandle,
  216. IN TPMS_AUTH_COMMAND *AuthSession,
  217. IN TPMI_RH_HIERARCHY Hierarchy,
  218. IN TPMI_YES_NO State
  219. );
  220. /**
  221. This command cancels the effect of a TPM lockout due to a number of successive authorization failures.
  222. If this command is properly authorized, the lockout counter is set to zero.
  223. @param[in] LockHandle LockHandle
  224. @param[in] AuthSession Auth Session context
  225. @retval EFI_SUCCESS Operation completed successfully.
  226. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  227. **/
  228. EFI_STATUS
  229. EFIAPI
  230. Tpm2DictionaryAttackLockReset (
  231. IN TPMI_RH_LOCKOUT LockHandle,
  232. IN TPMS_AUTH_COMMAND *AuthSession
  233. );
  234. /**
  235. This command cancels the effect of a TPM lockout due to a number of successive authorization failures.
  236. If this command is properly authorized, the lockout counter is set to zero.
  237. @param[in] LockHandle LockHandle
  238. @param[in] AuthSession Auth Session context
  239. @param[in] NewMaxTries Count of authorization failures before the lockout is imposed
  240. @param[in] NewRecoveryTime Time in seconds before the authorization failure count is automatically decremented
  241. @param[in] LockoutRecovery Time in seconds after a lockoutAuth failure before use of lockoutAuth is allowed
  242. @retval EFI_SUCCESS Operation completed successfully.
  243. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  244. **/
  245. EFI_STATUS
  246. EFIAPI
  247. Tpm2DictionaryAttackParameters (
  248. IN TPMI_RH_LOCKOUT LockHandle,
  249. IN TPMS_AUTH_COMMAND *AuthSession,
  250. IN UINT32 NewMaxTries,
  251. IN UINT32 NewRecoveryTime,
  252. IN UINT32 LockoutRecovery
  253. );
  254. /**
  255. This command is used to read the public area and Name of an NV Index.
  256. @param[in] NvIndex The NV Index.
  257. @param[out] NvPublic The public area of the index.
  258. @param[out] NvName The Name of the nvIndex.
  259. @retval EFI_SUCCESS Operation completed successfully.
  260. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  261. **/
  262. EFI_STATUS
  263. EFIAPI
  264. Tpm2NvReadPublic (
  265. IN TPMI_RH_NV_INDEX NvIndex,
  266. OUT TPM2B_NV_PUBLIC *NvPublic,
  267. OUT TPM2B_NAME *NvName
  268. );
  269. /**
  270. This command defines the attributes of an NV Index and causes the TPM to
  271. reserve space to hold the data associated with the index.
  272. If a definition already exists at the index, the TPM will return TPM_RC_NV_DEFINED.
  273. @param[in] AuthHandle TPM_RH_OWNER or TPM_RH_PLATFORM+{PP}.
  274. @param[in] AuthSession Auth Session context
  275. @param[in] Auth The authorization data.
  276. @param[in] NvPublic The public area of the index.
  277. @retval EFI_SUCCESS Operation completed successfully.
  278. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  279. @retval EFI_ALREADY_STARTED The command was returned successfully, but NvIndex is already defined.
  280. **/
  281. EFI_STATUS
  282. EFIAPI
  283. Tpm2NvDefineSpace (
  284. IN TPMI_RH_PROVISION AuthHandle,
  285. IN TPMS_AUTH_COMMAND *AuthSession OPTIONAL,
  286. IN TPM2B_AUTH *Auth,
  287. IN TPM2B_NV_PUBLIC *NvPublic
  288. );
  289. /**
  290. This command removes an index from the TPM.
  291. @param[in] AuthHandle TPM_RH_OWNER or TPM_RH_PLATFORM+{PP}.
  292. @param[in] NvIndex The NV Index.
  293. @param[in] AuthSession Auth Session context
  294. @retval EFI_SUCCESS Operation completed successfully.
  295. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  296. @retval EFI_NOT_FOUND The command was returned successfully, but NvIndex is not found.
  297. **/
  298. EFI_STATUS
  299. EFIAPI
  300. Tpm2NvUndefineSpace (
  301. IN TPMI_RH_PROVISION AuthHandle,
  302. IN TPMI_RH_NV_INDEX NvIndex,
  303. IN TPMS_AUTH_COMMAND *AuthSession OPTIONAL
  304. );
  305. /**
  306. This command reads a value from an area in NV memory previously defined by TPM2_NV_DefineSpace().
  307. @param[in] AuthHandle the handle indicating the source of the authorization value.
  308. @param[in] NvIndex The index to be read.
  309. @param[in] AuthSession Auth Session context
  310. @param[in] Size Number of bytes to read.
  311. @param[in] Offset Byte offset into the area.
  312. @param[in,out] OutData The data read.
  313. @retval EFI_SUCCESS Operation completed successfully.
  314. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  315. @retval EFI_NOT_FOUND The command was returned successfully, but NvIndex is not found.
  316. **/
  317. EFI_STATUS
  318. EFIAPI
  319. Tpm2NvRead (
  320. IN TPMI_RH_NV_AUTH AuthHandle,
  321. IN TPMI_RH_NV_INDEX NvIndex,
  322. IN TPMS_AUTH_COMMAND *AuthSession OPTIONAL,
  323. IN UINT16 Size,
  324. IN UINT16 Offset,
  325. IN OUT TPM2B_MAX_BUFFER *OutData
  326. );
  327. /**
  328. This command writes a value to an area in NV memory that was previously defined by TPM2_NV_DefineSpace().
  329. @param[in] AuthHandle the handle indicating the source of the authorization value.
  330. @param[in] NvIndex The NV Index of the area to write.
  331. @param[in] AuthSession Auth Session context
  332. @param[in] InData The data to write.
  333. @param[in] Offset The offset into the NV Area.
  334. @retval EFI_SUCCESS Operation completed successfully.
  335. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  336. @retval EFI_NOT_FOUND The command was returned successfully, but NvIndex is not found.
  337. **/
  338. EFI_STATUS
  339. EFIAPI
  340. Tpm2NvWrite (
  341. IN TPMI_RH_NV_AUTH AuthHandle,
  342. IN TPMI_RH_NV_INDEX NvIndex,
  343. IN TPMS_AUTH_COMMAND *AuthSession OPTIONAL,
  344. IN TPM2B_MAX_BUFFER *InData,
  345. IN UINT16 Offset
  346. );
  347. /**
  348. This command may be used to prevent further reads of the Index until the next TPM2_Startup (TPM_SU_CLEAR).
  349. @param[in] AuthHandle the handle indicating the source of the authorization value.
  350. @param[in] NvIndex The NV Index of the area to lock.
  351. @param[in] AuthSession Auth Session context
  352. @retval EFI_SUCCESS Operation completed successfully.
  353. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  354. @retval EFI_NOT_FOUND The command was returned successfully, but NvIndex is not found.
  355. **/
  356. EFI_STATUS
  357. EFIAPI
  358. Tpm2NvReadLock (
  359. IN TPMI_RH_NV_AUTH AuthHandle,
  360. IN TPMI_RH_NV_INDEX NvIndex,
  361. IN TPMS_AUTH_COMMAND *AuthSession OPTIONAL
  362. );
  363. /**
  364. This command may be used to inhibit further writes of the Index.
  365. @param[in] AuthHandle the handle indicating the source of the authorization value.
  366. @param[in] NvIndex The NV Index of the area to lock.
  367. @param[in] AuthSession Auth Session context
  368. @retval EFI_SUCCESS Operation completed successfully.
  369. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  370. @retval EFI_NOT_FOUND The command was returned successfully, but NvIndex is not found.
  371. **/
  372. EFI_STATUS
  373. EFIAPI
  374. Tpm2NvWriteLock (
  375. IN TPMI_RH_NV_AUTH AuthHandle,
  376. IN TPMI_RH_NV_INDEX NvIndex,
  377. IN TPMS_AUTH_COMMAND *AuthSession OPTIONAL
  378. );
  379. /**
  380. The command will SET TPMA_NV_WRITELOCKED for all indexes that have their TPMA_NV_GLOBALLOCK attribute SET.
  381. @param[in] AuthHandle TPM_RH_OWNER or TPM_RH_PLATFORM+{PP}.
  382. @param[in] AuthSession Auth Session context
  383. @retval EFI_SUCCESS Operation completed successfully.
  384. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  385. @retval EFI_NOT_FOUND The command was returned successfully, but NvIndex is not found.
  386. **/
  387. EFI_STATUS
  388. EFIAPI
  389. Tpm2NvGlobalWriteLock (
  390. IN TPMI_RH_PROVISION AuthHandle,
  391. IN TPMS_AUTH_COMMAND *AuthSession OPTIONAL
  392. );
  393. /**
  394. This command is used to cause an update to the indicated PCR.
  395. The digests parameter contains one or more tagged digest value identified by an algorithm ID.
  396. For each digest, the PCR associated with pcrHandle is Extended into the bank identified by the tag (hashAlg).
  397. @param[in] PcrHandle Handle of the PCR
  398. @param[in] Digests List of tagged digest values to be extended
  399. @retval EFI_SUCCESS Operation completed successfully.
  400. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  401. **/
  402. EFI_STATUS
  403. EFIAPI
  404. Tpm2PcrExtend (
  405. IN TPMI_DH_PCR PcrHandle,
  406. IN TPML_DIGEST_VALUES *Digests
  407. );
  408. /**
  409. This command is used to cause an update to the indicated PCR.
  410. The data in eventData is hashed using the hash algorithm associated with each bank in which the
  411. indicated PCR has been allocated. After the data is hashed, the digests list is returned. If the pcrHandle
  412. references an implemented PCR and not TPM_ALG_NULL, digests list is processed as in
  413. TPM2_PCR_Extend().
  414. A TPM shall support an Event.size of zero through 1,024 inclusive.
  415. @param[in] PcrHandle Handle of the PCR
  416. @param[in] EventData Event data in sized buffer
  417. @param[out] Digests List of digest
  418. @retval EFI_SUCCESS Operation completed successfully.
  419. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  420. **/
  421. EFI_STATUS
  422. EFIAPI
  423. Tpm2PcrEvent (
  424. IN TPMI_DH_PCR PcrHandle,
  425. IN TPM2B_EVENT *EventData,
  426. OUT TPML_DIGEST_VALUES *Digests
  427. );
  428. /**
  429. This command returns the values of all PCR specified in pcrSelect.
  430. @param[in] PcrSelectionIn The selection of PCR to read.
  431. @param[out] PcrUpdateCounter The current value of the PCR update counter.
  432. @param[out] PcrSelectionOut The PCR in the returned list.
  433. @param[out] PcrValues The contents of the PCR indicated in pcrSelect.
  434. @retval EFI_SUCCESS Operation completed successfully.
  435. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  436. **/
  437. EFI_STATUS
  438. EFIAPI
  439. Tpm2PcrRead (
  440. IN TPML_PCR_SELECTION *PcrSelectionIn,
  441. OUT UINT32 *PcrUpdateCounter,
  442. OUT TPML_PCR_SELECTION *PcrSelectionOut,
  443. OUT TPML_DIGEST *PcrValues
  444. );
  445. /**
  446. This command is used to set the desired PCR allocation of PCR and algorithms.
  447. @param[in] AuthHandle TPM_RH_PLATFORM+{PP}
  448. @param[in] AuthSession Auth Session context
  449. @param[in] PcrAllocation The requested allocation
  450. @param[out] AllocationSuccess YES if the allocation succeeded
  451. @param[out] MaxPCR maximum number of PCR that may be in a bank
  452. @param[out] SizeNeeded number of octets required to satisfy the request
  453. @param[out] SizeAvailable Number of octets available. Computed before the allocation
  454. @retval EFI_SUCCESS Operation completed successfully.
  455. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  456. **/
  457. EFI_STATUS
  458. EFIAPI
  459. Tpm2PcrAllocate (
  460. IN TPMI_RH_PLATFORM AuthHandle,
  461. IN TPMS_AUTH_COMMAND *AuthSession,
  462. IN TPML_PCR_SELECTION *PcrAllocation,
  463. OUT TPMI_YES_NO *AllocationSuccess,
  464. OUT UINT32 *MaxPCR,
  465. OUT UINT32 *SizeNeeded,
  466. OUT UINT32 *SizeAvailable
  467. );
  468. /**
  469. Alloc PCR data.
  470. @param[in] PlatformAuth platform auth value. NULL means no platform auth change.
  471. @param[in] SupportedPCRBanks Supported PCR banks
  472. @param[in] PCRBanks PCR banks
  473. @retval EFI_SUCCESS Operation completed successfully.
  474. **/
  475. EFI_STATUS
  476. EFIAPI
  477. Tpm2PcrAllocateBanks (
  478. IN TPM2B_AUTH *PlatformAuth OPTIONAL,
  479. IN UINT32 SupportedPCRBanks,
  480. IN UINT32 PCRBanks
  481. );
  482. /**
  483. This command returns various information regarding the TPM and its current state.
  484. The capability parameter determines the category of data returned. The property parameter
  485. selects the first value of the selected category to be returned. If there is no property
  486. that corresponds to the value of property, the next higher value is returned, if it exists.
  487. The moreData parameter will have a value of YES if there are more values of the requested
  488. type that were not returned.
  489. If no next capability exists, the TPM will return a zero-length list and moreData will have
  490. a value of NO.
  491. NOTE:
  492. To simplify this function, leave returned CapabilityData for caller to unpack since there are
  493. many capability categories and only few categories will be used in firmware. It means the caller
  494. need swap the byte order for the fields in CapabilityData.
  495. @param[in] Capability Group selection; determines the format of the response.
  496. @param[in] Property Further definition of information.
  497. @param[in] PropertyCount Number of properties of the indicated type to return.
  498. @param[out] MoreData Flag to indicate if there are more values of this type.
  499. @param[out] CapabilityData The capability data.
  500. @retval EFI_SUCCESS Operation completed successfully.
  501. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  502. **/
  503. EFI_STATUS
  504. EFIAPI
  505. Tpm2GetCapability (
  506. IN TPM_CAP Capability,
  507. IN UINT32 Property,
  508. IN UINT32 PropertyCount,
  509. OUT TPMI_YES_NO *MoreData,
  510. OUT TPMS_CAPABILITY_DATA *CapabilityData
  511. );
  512. /**
  513. This command returns the information of TPM Family.
  514. This function parse the value got from TPM2_GetCapability and return the Family.
  515. @param[out] Family The Family of TPM. (a 4-octet character string)
  516. @retval EFI_SUCCESS Operation completed successfully.
  517. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  518. **/
  519. EFI_STATUS
  520. EFIAPI
  521. Tpm2GetCapabilityFamily (
  522. OUT CHAR8 *Family
  523. );
  524. /**
  525. This command returns the information of TPM manufacture ID.
  526. This function parse the value got from TPM2_GetCapability and return the TPM manufacture ID.
  527. @param[out] ManufactureId The manufacture ID of TPM.
  528. @retval EFI_SUCCESS Operation completed successfully.
  529. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  530. **/
  531. EFI_STATUS
  532. EFIAPI
  533. Tpm2GetCapabilityManufactureID (
  534. OUT UINT32 *ManufactureId
  535. );
  536. /**
  537. This command returns the information of TPM FirmwareVersion.
  538. This function parse the value got from TPM2_GetCapability and return the TPM FirmwareVersion.
  539. @param[out] FirmwareVersion1 The FirmwareVersion1.
  540. @param[out] FirmwareVersion2 The FirmwareVersion2.
  541. @retval EFI_SUCCESS Operation completed successfully.
  542. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  543. **/
  544. EFI_STATUS
  545. EFIAPI
  546. Tpm2GetCapabilityFirmwareVersion (
  547. OUT UINT32 *FirmwareVersion1,
  548. OUT UINT32 *FirmwareVersion2
  549. );
  550. /**
  551. This command returns the information of the maximum value for commandSize and responseSize in a command.
  552. This function parse the value got from TPM2_GetCapability and return the max command size and response size
  553. @param[out] MaxCommandSize The maximum value for commandSize in a command.
  554. @param[out] MaxResponseSize The maximum value for responseSize in a command.
  555. @retval EFI_SUCCESS Operation completed successfully.
  556. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  557. **/
  558. EFI_STATUS
  559. EFIAPI
  560. Tpm2GetCapabilityMaxCommandResponseSize (
  561. OUT UINT32 *MaxCommandSize,
  562. OUT UINT32 *MaxResponseSize
  563. );
  564. /**
  565. This command returns Returns a list of TPMS_ALG_PROPERTIES. Each entry is an
  566. algorithm ID and a set of properties of the algorithm.
  567. This function parse the value got from TPM2_GetCapability and return the list.
  568. @param[out] AlgList List of algorithm.
  569. @retval EFI_SUCCESS Operation completed successfully.
  570. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  571. **/
  572. EFI_STATUS
  573. EFIAPI
  574. Tpm2GetCapabilitySupportedAlg (
  575. OUT TPML_ALG_PROPERTY *AlgList
  576. );
  577. /**
  578. This command returns the information of TPM LockoutCounter.
  579. This function parse the value got from TPM2_GetCapability and return the LockoutCounter.
  580. @param[out] LockoutCounter The LockoutCounter of TPM.
  581. @retval EFI_SUCCESS Operation completed successfully.
  582. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  583. **/
  584. EFI_STATUS
  585. EFIAPI
  586. Tpm2GetCapabilityLockoutCounter (
  587. OUT UINT32 *LockoutCounter
  588. );
  589. /**
  590. This command returns the information of TPM LockoutInterval.
  591. This function parse the value got from TPM2_GetCapability and return the LockoutInterval.
  592. @param[out] LockoutInterval The LockoutInterval of TPM.
  593. @retval EFI_SUCCESS Operation completed successfully.
  594. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  595. **/
  596. EFI_STATUS
  597. EFIAPI
  598. Tpm2GetCapabilityLockoutInterval (
  599. OUT UINT32 *LockoutInterval
  600. );
  601. /**
  602. This command returns the information of TPM InputBufferSize.
  603. This function parse the value got from TPM2_GetCapability and return the InputBufferSize.
  604. @param[out] InputBufferSize The InputBufferSize of TPM.
  605. the maximum size of a parameter (typically, a TPM2B_MAX_BUFFER)
  606. @retval EFI_SUCCESS Operation completed successfully.
  607. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  608. **/
  609. EFI_STATUS
  610. EFIAPI
  611. Tpm2GetCapabilityInputBufferSize (
  612. OUT UINT32 *InputBufferSize
  613. );
  614. /**
  615. This command returns the information of TPM PCRs.
  616. This function parse the value got from TPM2_GetCapability and return the PcrSelection.
  617. @param[out] Pcrs The Pcr Selection
  618. @retval EFI_SUCCESS Operation completed successfully.
  619. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  620. **/
  621. EFI_STATUS
  622. EFIAPI
  623. Tpm2GetCapabilityPcrs (
  624. OUT TPML_PCR_SELECTION *Pcrs
  625. );
  626. /**
  627. This function will query the TPM to determine which hashing algorithms
  628. are supported and which PCR banks are currently active.
  629. @param[out] TpmHashAlgorithmBitmap A bitmask containing the algorithms supported by the TPM.
  630. @param[out] ActivePcrBanks A bitmask containing the PCRs currently allocated.
  631. @retval EFI_SUCCESS TPM was successfully queried and return values can be trusted.
  632. @retval Others An error occurred, likely in communication with the TPM.
  633. **/
  634. EFI_STATUS
  635. EFIAPI
  636. Tpm2GetCapabilitySupportedAndActivePcrs (
  637. OUT UINT32 *TpmHashAlgorithmBitmap,
  638. OUT UINT32 *ActivePcrBanks
  639. );
  640. /**
  641. This command returns the information of TPM AlgorithmSet.
  642. This function parse the value got from TPM2_GetCapability and return the AlgorithmSet.
  643. @param[out] AlgorithmSet The AlgorithmSet of TPM.
  644. @retval EFI_SUCCESS Operation completed successfully.
  645. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  646. **/
  647. EFI_STATUS
  648. EFIAPI
  649. Tpm2GetCapabilityAlgorithmSet (
  650. OUT UINT32 *AlgorithmSet
  651. );
  652. /**
  653. This function will query if the command is supported.
  654. @param[In] Command TPM_CC command starts from TPM_CC_FIRST.
  655. @param[out] IsCmdImpl The command is supported or not.
  656. @retval EFI_SUCCESS Operation completed successfully.
  657. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  658. **/
  659. EFI_STATUS
  660. EFIAPI
  661. Tpm2GetCapabilityIsCommandImplemented (
  662. IN TPM_CC Command,
  663. OUT BOOLEAN *IsCmdImpl
  664. );
  665. /**
  666. This command is used to check to see if specific combinations of algorithm parameters are supported.
  667. @param[in] Parameters Algorithm parameters to be validated
  668. @retval EFI_SUCCESS Operation completed successfully.
  669. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  670. **/
  671. EFI_STATUS
  672. EFIAPI
  673. Tpm2TestParms (
  674. IN TPMT_PUBLIC_PARMS *Parameters
  675. );
  676. /**
  677. This command allows the platform to change the set of algorithms that are used by the TPM.
  678. The algorithmSet setting is a vendor-dependent value.
  679. @param[in] AuthHandle TPM_RH_PLATFORM
  680. @param[in] AuthSession Auth Session context
  681. @param[in] AlgorithmSet A TPM vendor-dependent value indicating the
  682. algorithm set selection
  683. @retval EFI_SUCCESS Operation completed successfully.
  684. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  685. **/
  686. EFI_STATUS
  687. EFIAPI
  688. Tpm2SetAlgorithmSet (
  689. IN TPMI_RH_PLATFORM AuthHandle,
  690. IN TPMS_AUTH_COMMAND *AuthSession,
  691. IN UINT32 AlgorithmSet
  692. );
  693. /**
  694. This command is used to start an authorization session using alternative methods of
  695. establishing the session key (sessionKey) that is used for authorization and encrypting value.
  696. @param[in] TpmKey Handle of a loaded decrypt key used to encrypt salt.
  697. @param[in] Bind Entity providing the authValue.
  698. @param[in] NonceCaller Initial nonceCaller, sets nonce size for the session.
  699. @param[in] Salt Value encrypted according to the type of tpmKey.
  700. @param[in] SessionType Indicates the type of the session.
  701. @param[in] Symmetric The algorithm and key size for parameter encryption.
  702. @param[in] AuthHash Hash algorithm to use for the session.
  703. @param[out] SessionHandle Handle for the newly created session.
  704. @param[out] NonceTPM The initial nonce from the TPM, used in the computation of the sessionKey.
  705. @retval EFI_SUCCESS Operation completed successfully.
  706. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  707. **/
  708. EFI_STATUS
  709. EFIAPI
  710. Tpm2StartAuthSession (
  711. IN TPMI_DH_OBJECT TpmKey,
  712. IN TPMI_DH_ENTITY Bind,
  713. IN TPM2B_NONCE *NonceCaller,
  714. IN TPM2B_ENCRYPTED_SECRET *Salt,
  715. IN TPM_SE SessionType,
  716. IN TPMT_SYM_DEF *Symmetric,
  717. IN TPMI_ALG_HASH AuthHash,
  718. OUT TPMI_SH_AUTH_SESSION *SessionHandle,
  719. OUT TPM2B_NONCE *NonceTPM
  720. );
  721. /**
  722. This command causes all context associated with a loaded object or session to be removed from TPM memory.
  723. @param[in] FlushHandle The handle of the item to flush.
  724. @retval EFI_SUCCESS Operation completed successfully.
  725. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  726. **/
  727. EFI_STATUS
  728. EFIAPI
  729. Tpm2FlushContext (
  730. IN TPMI_DH_CONTEXT FlushHandle
  731. );
  732. /**
  733. This command includes a secret-based authorization to a policy.
  734. The caller proves knowledge of the secret value using an authorization
  735. session using the authValue associated with authHandle.
  736. @param[in] AuthHandle Handle for an entity providing the authorization
  737. @param[in] PolicySession Handle for the policy session being extended.
  738. @param[in] AuthSession Auth Session context
  739. @param[in] NonceTPM The policy nonce for the session.
  740. @param[in] CpHashA Digest of the command parameters to which this authorization is limited.
  741. @param[in] PolicyRef A reference to a policy relating to the authorization.
  742. @param[in] Expiration Time when authorization will expire, measured in seconds from the time that nonceTPM was generated.
  743. @param[out] Timeout Time value used to indicate to the TPM when the ticket expires.
  744. @param[out] PolicyTicket A ticket that includes a value indicating when the authorization expires.
  745. @retval EFI_SUCCESS Operation completed successfully.
  746. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  747. **/
  748. EFI_STATUS
  749. EFIAPI
  750. Tpm2PolicySecret (
  751. IN TPMI_DH_ENTITY AuthHandle,
  752. IN TPMI_SH_POLICY PolicySession,
  753. IN TPMS_AUTH_COMMAND *AuthSession OPTIONAL,
  754. IN TPM2B_NONCE *NonceTPM,
  755. IN TPM2B_DIGEST *CpHashA,
  756. IN TPM2B_NONCE *PolicyRef,
  757. IN INT32 Expiration,
  758. OUT TPM2B_TIMEOUT *Timeout,
  759. OUT TPMT_TK_AUTH *PolicyTicket
  760. );
  761. /**
  762. This command allows options in authorizations without requiring that the TPM evaluate all of the options.
  763. If a policy may be satisfied by different sets of conditions, the TPM need only evaluate one set that
  764. satisfies the policy. This command will indicate that one of the required sets of conditions has been
  765. satisfied.
  766. @param[in] PolicySession Handle for the policy session being extended.
  767. @param[in] HashList the list of hashes to check for a match.
  768. @retval EFI_SUCCESS Operation completed successfully.
  769. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  770. **/
  771. EFI_STATUS
  772. EFIAPI
  773. Tpm2PolicyOR (
  774. IN TPMI_SH_POLICY PolicySession,
  775. IN TPML_DIGEST *HashList
  776. );
  777. /**
  778. This command indicates that the authorization will be limited to a specific command code.
  779. @param[in] PolicySession Handle for the policy session being extended.
  780. @param[in] Code The allowed commandCode.
  781. @retval EFI_SUCCESS Operation completed successfully.
  782. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  783. **/
  784. EFI_STATUS
  785. EFIAPI
  786. Tpm2PolicyCommandCode (
  787. IN TPMI_SH_POLICY PolicySession,
  788. IN TPM_CC Code
  789. );
  790. /**
  791. This command returns the current policyDigest of the session. This command allows the TPM
  792. to be used to perform the actions required to precompute the authPolicy for an object.
  793. @param[in] PolicySession Handle for the policy session.
  794. @param[out] PolicyHash the current value of the policyHash of policySession.
  795. @retval EFI_SUCCESS Operation completed successfully.
  796. @retval EFI_DEVICE_ERROR The command was unsuccessful.
  797. **/
  798. EFI_STATUS
  799. EFIAPI
  800. Tpm2PolicyGetDigest (
  801. IN TPMI_SH_POLICY PolicySession,
  802. OUT TPM2B_DIGEST *PolicyHash
  803. );
  804. /**
  805. This command allows access to the public area of a loaded object.
  806. @param[in] ObjectHandle TPM handle of an object
  807. @param[out] OutPublic Structure containing the public area of an object
  808. @param[out] Name Name of the object
  809. @param[out] QualifiedName The Qualified Name of the object
  810. @retval EFI_SUCCESS Operation completed successfully.
  811. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  812. **/
  813. EFI_STATUS
  814. EFIAPI
  815. Tpm2ReadPublic (
  816. IN TPMI_DH_OBJECT ObjectHandle,
  817. OUT TPM2B_PUBLIC *OutPublic,
  818. OUT TPM2B_NAME *Name,
  819. OUT TPM2B_NAME *QualifiedName
  820. );
  821. //
  822. // Help function
  823. //
  824. /**
  825. Copy AuthSessionIn to TPM2 command buffer.
  826. @param [in] AuthSessionIn Input AuthSession data
  827. @param [out] AuthSessionOut Output AuthSession data in TPM2 command buffer
  828. @return AuthSession size
  829. **/
  830. UINT32
  831. EFIAPI
  832. CopyAuthSessionCommand (
  833. IN TPMS_AUTH_COMMAND *AuthSessionIn OPTIONAL,
  834. OUT UINT8 *AuthSessionOut
  835. );
  836. /**
  837. Copy AuthSessionIn from TPM2 response buffer.
  838. @param [in] AuthSessionIn Input AuthSession data in TPM2 response buffer
  839. @param [out] AuthSessionOut Output AuthSession data
  840. @return AuthSession size
  841. **/
  842. UINT32
  843. EFIAPI
  844. CopyAuthSessionResponse (
  845. IN UINT8 *AuthSessionIn,
  846. OUT TPMS_AUTH_RESPONSE *AuthSessionOut OPTIONAL
  847. );
  848. /**
  849. Return size of digest.
  850. @param[in] HashAlgo Hash algorithm
  851. @return size of digest
  852. **/
  853. UINT16
  854. EFIAPI
  855. GetHashSizeFromAlgo (
  856. IN TPMI_ALG_HASH HashAlgo
  857. );
  858. /**
  859. Get hash mask from algorithm.
  860. @param[in] HashAlgo Hash algorithm
  861. @return Hash mask
  862. **/
  863. UINT32
  864. EFIAPI
  865. GetHashMaskFromAlgo (
  866. IN TPMI_ALG_HASH HashAlgo
  867. );
  868. /**
  869. Return if hash alg is supported in HashAlgorithmMask.
  870. @param HashAlg Hash algorithm to be checked.
  871. @param HashAlgorithmMask Bitfield of allowed hash algorithms.
  872. @retval TRUE Hash algorithm is supported.
  873. @retval FALSE Hash algorithm is not supported.
  874. **/
  875. BOOLEAN
  876. EFIAPI
  877. IsHashAlgSupportedInHashAlgorithmMask (
  878. IN TPMI_ALG_HASH HashAlg,
  879. IN UINT32 HashAlgorithmMask
  880. );
  881. /**
  882. Copy TPML_DIGEST_VALUES into a buffer
  883. @param[in,out] Buffer Buffer to hold copied TPML_DIGEST_VALUES compact binary.
  884. @param[in] DigestList TPML_DIGEST_VALUES to be copied.
  885. @param[in] HashAlgorithmMask HASH bits corresponding to the desired digests to copy.
  886. @return The end of buffer to hold TPML_DIGEST_VALUES.
  887. **/
  888. VOID *
  889. EFIAPI
  890. CopyDigestListToBuffer (
  891. IN OUT VOID *Buffer,
  892. IN TPML_DIGEST_VALUES *DigestList,
  893. IN UINT32 HashAlgorithmMask
  894. );
  895. /**
  896. Get TPML_DIGEST_VALUES data size.
  897. @param[in] DigestList TPML_DIGEST_VALUES data.
  898. @return TPML_DIGEST_VALUES data size.
  899. **/
  900. UINT32
  901. EFIAPI
  902. GetDigestListSize (
  903. IN TPML_DIGEST_VALUES *DigestList
  904. );
  905. /**
  906. This function get digest from digest list.
  907. @param[in] HashAlg Digest algorithm
  908. @param[in] DigestList Digest list
  909. @param[out] Digest Digest
  910. @retval EFI_SUCCESS Digest is found and returned.
  911. @retval EFI_NOT_FOUND Digest is not found.
  912. **/
  913. EFI_STATUS
  914. EFIAPI
  915. GetDigestFromDigestList (
  916. IN TPMI_ALG_HASH HashAlg,
  917. IN TPML_DIGEST_VALUES *DigestList,
  918. OUT VOID *Digest
  919. );
  920. #endif