tpm.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (c) 2013 The Chromium OS Authors.
  4. * Coypright (c) 2013 Guntermann & Drunck GmbH
  5. */
  6. #ifndef __TPM_H
  7. #define __TPM_H
  8. /*
  9. * Here is a partial implementation of TPM commands. Please consult TCG Main
  10. * Specification for definitions of TPM commands.
  11. */
  12. #define TPM_HEADER_SIZE 10
  13. enum tpm_duration {
  14. TPM_SHORT = 0,
  15. TPM_MEDIUM = 1,
  16. TPM_LONG = 2,
  17. TPM_UNDEFINED,
  18. TPM_DURATION_COUNT,
  19. };
  20. enum tpm_startup_type {
  21. TPM_ST_CLEAR = 0x0001,
  22. TPM_ST_STATE = 0x0002,
  23. TPM_ST_DEACTIVATED = 0x0003,
  24. };
  25. enum tpm_physical_presence {
  26. TPM_PHYSICAL_PRESENCE_HW_DISABLE = 0x0200,
  27. TPM_PHYSICAL_PRESENCE_CMD_DISABLE = 0x0100,
  28. TPM_PHYSICAL_PRESENCE_LIFETIME_LOCK = 0x0080,
  29. TPM_PHYSICAL_PRESENCE_HW_ENABLE = 0x0040,
  30. TPM_PHYSICAL_PRESENCE_CMD_ENABLE = 0x0020,
  31. TPM_PHYSICAL_PRESENCE_NOTPRESENT = 0x0010,
  32. TPM_PHYSICAL_PRESENCE_PRESENT = 0x0008,
  33. TPM_PHYSICAL_PRESENCE_LOCK = 0x0004,
  34. };
  35. enum tpm_nv_index {
  36. TPM_NV_INDEX_LOCK = 0xffffffff,
  37. TPM_NV_INDEX_0 = 0x00000000,
  38. TPM_NV_INDEX_DIR = 0x10000001,
  39. };
  40. enum tpm_resource_type {
  41. TPM_RT_KEY = 0x00000001,
  42. TPM_RT_AUTH = 0x00000002,
  43. TPM_RT_HASH = 0x00000003,
  44. TPM_RT_TRANS = 0x00000004,
  45. TPM_RT_CONTEXT = 0x00000005,
  46. TPM_RT_COUNTER = 0x00000006,
  47. TPM_RT_DELEGATE = 0x00000007,
  48. TPM_RT_DAA_TPM = 0x00000008,
  49. TPM_RT_DAA_V0 = 0x00000009,
  50. TPM_RT_DAA_V1 = 0x0000000A,
  51. };
  52. enum tpm_capability_areas {
  53. TPM_CAP_ORD = 0x00000001,
  54. TPM_CAP_ALG = 0x00000002,
  55. TPM_CAP_PID = 0x00000003,
  56. TPM_CAP_FLAG = 0x00000004,
  57. TPM_CAP_PROPERTY = 0x00000005,
  58. TPM_CAP_VERSION = 0x00000006,
  59. TPM_CAP_KEY_HANDLE = 0x00000007,
  60. TPM_CAP_CHECK_LOADED = 0x00000008,
  61. TPM_CAP_SYM_MODE = 0x00000009,
  62. TPM_CAP_KEY_STATUS = 0x0000000C,
  63. TPM_CAP_NV_LIST = 0x0000000D,
  64. TPM_CAP_MFR = 0x00000010,
  65. TPM_CAP_NV_INDEX = 0x00000011,
  66. TPM_CAP_TRANS_ALG = 0x00000012,
  67. TPM_CAP_HANDLE = 0x00000014,
  68. TPM_CAP_TRANS_ES = 0x00000015,
  69. TPM_CAP_AUTH_ENCRYPT = 0x00000017,
  70. TPM_CAP_SELECT_SIZE = 0x00000018,
  71. TPM_CAP_DA_LOGIC = 0x00000019,
  72. TPM_CAP_VERSION_VAL = 0x0000001A,
  73. };
  74. #define TPM_NV_PER_GLOBALLOCK (1U << 15)
  75. #define TPM_NV_PER_PPREAD (1U << 16)
  76. #define TPM_NV_PER_PPWRITE (1U << 0)
  77. #define TPM_NV_PER_READ_STCLEAR (1U << 31)
  78. #define TPM_NV_PER_WRITE_STCLEAR (1U << 14)
  79. #define TPM_NV_PER_WRITEDEFINE (1U << 13)
  80. #define TPM_NV_PER_WRITEALL (1U << 12)
  81. enum {
  82. TPM_PUBEK_SIZE = 256,
  83. };
  84. /**
  85. * TPM return codes as defined in the TCG Main specification
  86. * (TPM Main Part 2 Structures; Specification version 1.2)
  87. */
  88. enum tpm_return_code {
  89. TPM_BASE = 0x00000000,
  90. TPM_NON_FATAL = 0x00000800,
  91. TPM_SUCCESS = TPM_BASE,
  92. /* TPM-defined fatal error codes */
  93. TPM_AUTHFAIL = TPM_BASE + 1,
  94. TPM_BADINDEX = TPM_BASE + 2,
  95. TPM_BAD_PARAMETER = TPM_BASE + 3,
  96. TPM_AUDITFAILURE = TPM_BASE + 4,
  97. TPM_CLEAR_DISABLED = TPM_BASE + 5,
  98. TPM_DEACTIVATED = TPM_BASE + 6,
  99. TPM_DISABLED = TPM_BASE + 7,
  100. TPM_DISABLED_CMD = TPM_BASE + 8,
  101. TPM_FAIL = TPM_BASE + 9,
  102. TPM_BAD_ORDINAL = TPM_BASE + 10,
  103. TPM_INSTALL_DISABLED = TPM_BASE + 11,
  104. TPM_INVALID_KEYHANDLE = TPM_BASE + 12,
  105. TPM_KEYNOTFOUND = TPM_BASE + 13,
  106. TPM_INAPPROPRIATE_ENC = TPM_BASE + 14,
  107. TPM_MIGRATE_FAIL = TPM_BASE + 15,
  108. TPM_INVALID_PCR_INFO = TPM_BASE + 16,
  109. TPM_NOSPACE = TPM_BASE + 17,
  110. TPM_NOSRK = TPM_BASE + 18,
  111. TPM_NOTSEALED_BLOB = TPM_BASE + 19,
  112. TPM_OWNER_SET = TPM_BASE + 20,
  113. TPM_RESOURCES = TPM_BASE + 21,
  114. TPM_SHORTRANDOM = TPM_BASE + 22,
  115. TPM_SIZE = TPM_BASE + 23,
  116. TPM_WRONGPCRVAL = TPM_BASE + 24,
  117. TPM_BAD_PARAM_SIZE = TPM_BASE + 25,
  118. TPM_SHA_THREAD = TPM_BASE + 26,
  119. TPM_SHA_ERROR = TPM_BASE + 27,
  120. TPM_FAILEDSELFTEST = TPM_BASE + 28,
  121. TPM_AUTH2FAIL = TPM_BASE + 29,
  122. TPM_BADTAG = TPM_BASE + 30,
  123. TPM_IOERROR = TPM_BASE + 31,
  124. TPM_ENCRYPT_ERROR = TPM_BASE + 32,
  125. TPM_DECRYPT_ERROR = TPM_BASE + 33,
  126. TPM_INVALID_AUTHHANDLE = TPM_BASE + 34,
  127. TPM_NO_ENDORSEMENT = TPM_BASE + 35,
  128. TPM_INVALID_KEYUSAGE = TPM_BASE + 36,
  129. TPM_WRONG_ENTITYTYPE = TPM_BASE + 37,
  130. TPM_INVALID_POSTINIT = TPM_BASE + 38,
  131. TPM_INAPPROPRIATE_SIG = TPM_BASE + 39,
  132. TPM_BAD_KEY_PROPERTY = TPM_BASE + 40,
  133. TPM_BAD_MIGRATION = TPM_BASE + 41,
  134. TPM_BAD_SCHEME = TPM_BASE + 42,
  135. TPM_BAD_DATASIZE = TPM_BASE + 43,
  136. TPM_BAD_MODE = TPM_BASE + 44,
  137. TPM_BAD_PRESENCE = TPM_BASE + 45,
  138. TPM_BAD_VERSION = TPM_BASE + 46,
  139. TPM_NO_WRAP_TRANSPORT = TPM_BASE + 47,
  140. TPM_AUDITFAIL_UNSUCCESSFUL = TPM_BASE + 48,
  141. TPM_AUDITFAIL_SUCCESSFUL = TPM_BASE + 49,
  142. TPM_NOTRESETABLE = TPM_BASE + 50,
  143. TPM_NOTLOCAL = TPM_BASE + 51,
  144. TPM_BAD_TYPE = TPM_BASE + 52,
  145. TPM_INVALID_RESOURCE = TPM_BASE + 53,
  146. TPM_NOTFIPS = TPM_BASE + 54,
  147. TPM_INVALID_FAMILY = TPM_BASE + 55,
  148. TPM_NO_NV_PERMISSION = TPM_BASE + 56,
  149. TPM_REQUIRES_SIGN = TPM_BASE + 57,
  150. TPM_KEY_NOTSUPPORTED = TPM_BASE + 58,
  151. TPM_AUTH_CONFLICT = TPM_BASE + 59,
  152. TPM_AREA_LOCKED = TPM_BASE + 60,
  153. TPM_BAD_LOCALITY = TPM_BASE + 61,
  154. TPM_READ_ONLY = TPM_BASE + 62,
  155. TPM_PER_NOWRITE = TPM_BASE + 63,
  156. TPM_FAMILY_COUNT = TPM_BASE + 64,
  157. TPM_WRITE_LOCKED = TPM_BASE + 65,
  158. TPM_BAD_ATTRIBUTES = TPM_BASE + 66,
  159. TPM_INVALID_STRUCTURE = TPM_BASE + 67,
  160. TPM_KEY_OWNER_CONTROL = TPM_BASE + 68,
  161. TPM_BAD_COUNTER = TPM_BASE + 69,
  162. TPM_NOT_FULLWRITE = TPM_BASE + 70,
  163. TPM_CONTEXT_GAP = TPM_BASE + 71,
  164. TPM_MAXNVWRITES = TPM_BASE + 72,
  165. TPM_NOOPERATOR = TPM_BASE + 73,
  166. TPM_RESOURCEMISSING = TPM_BASE + 74,
  167. TPM_DELEGATE_LOCK = TPM_BASE + 75,
  168. TPM_DELEGATE_FAMILY = TPM_BASE + 76,
  169. TPM_DELEGATE_ADMIN = TPM_BASE + 77,
  170. TPM_TRANSPORT_NOTEXCLUSIVE = TPM_BASE + 78,
  171. TPM_OWNER_CONTROL = TPM_BASE + 79,
  172. TPM_DAA_RESOURCES = TPM_BASE + 80,
  173. TPM_DAA_INPUT_DATA0 = TPM_BASE + 81,
  174. TPM_DAA_INPUT_DATA1 = TPM_BASE + 82,
  175. TPM_DAA_ISSUER_SETTINGS = TPM_BASE + 83,
  176. TPM_DAA_TPM_SETTINGS = TPM_BASE + 84,
  177. TPM_DAA_STAGE = TPM_BASE + 85,
  178. TPM_DAA_ISSUER_VALIDITY = TPM_BASE + 86,
  179. TPM_DAA_WRONG_W = TPM_BASE + 87,
  180. TPM_BAD_HANDLE = TPM_BASE + 88,
  181. TPM_BAD_DELEGATE = TPM_BASE + 89,
  182. TPM_BADCONTEXT = TPM_BASE + 90,
  183. TPM_TOOMANYCONTEXTS = TPM_BASE + 91,
  184. TPM_MA_TICKET_SIGNATURE = TPM_BASE + 92,
  185. TPM_MA_DESTINATION = TPM_BASE + 93,
  186. TPM_MA_SOURCE = TPM_BASE + 94,
  187. TPM_MA_AUTHORITY = TPM_BASE + 95,
  188. TPM_PERMANENTEK = TPM_BASE + 97,
  189. TPM_BAD_SIGNATURE = TPM_BASE + 98,
  190. TPM_NOCONTEXTSPACE = TPM_BASE + 99,
  191. /* TPM-defined non-fatal errors */
  192. TPM_RETRY = TPM_BASE + TPM_NON_FATAL,
  193. TPM_NEEDS_SELFTEST = TPM_BASE + TPM_NON_FATAL + 1,
  194. TPM_DOING_SELFTEST = TPM_BASE + TPM_NON_FATAL + 2,
  195. TPM_DEFEND_LOCK_RUNNING = TPM_BASE + TPM_NON_FATAL + 3,
  196. };
  197. struct tpm_permanent_flags {
  198. __be16 tag;
  199. u8 disable;
  200. u8 ownership;
  201. u8 deactivated;
  202. u8 read_pubek;
  203. u8 disable_owner_clear;
  204. u8 allow_maintenance;
  205. u8 physical_presence_lifetime_lock;
  206. u8 physical_presence_hw_enable;
  207. u8 physical_presence_cmd_enable;
  208. u8 cekp_used;
  209. u8 tpm_post;
  210. u8 tpm_post_lock;
  211. u8 fips;
  212. u8 operator;
  213. u8 enable_revoke_ek;
  214. u8 nv_locked;
  215. u8 read_srk_pub;
  216. u8 tpm_established;
  217. u8 maintenance_done;
  218. u8 disable_full_da_logic_info;
  219. } __packed;
  220. /* Max buffer size supported by our tpm */
  221. #define TPM_DEV_BUFSIZE 1260
  222. /**
  223. * struct tpm_chip_priv - Information about a TPM, stored by the uclass
  224. *
  225. * These values must be set up by the device's probe() method before
  226. * communcation is attempted. If the device has an xfer() method, this is
  227. * not needed. There is no need to set up @buf.
  228. *
  229. * @duration_ms: Length of each duration type in milliseconds
  230. * @retry_time_ms: Time to wait before retrying receive
  231. */
  232. struct tpm_chip_priv {
  233. uint duration_ms[TPM_DURATION_COUNT];
  234. uint retry_time_ms;
  235. u8 buf[TPM_DEV_BUFSIZE + sizeof(u8)]; /* Max buffer size + addr */
  236. };
  237. /**
  238. * struct tpm_ops - low-level TPM operations
  239. *
  240. * These are designed to avoid loops and delays in the driver itself. These
  241. * should be handled in the uclass.
  242. *
  243. * In gneral you should implement everything except xfer(). Where you need
  244. * complete control of the transfer, then xfer() can be provided and will
  245. * override the other methods.
  246. *
  247. * This interface is for low-level TPM access. It does not understand the
  248. * concept of localities or the various TPM messages. That interface is
  249. * defined in the functions later on in this file, but they all translate
  250. * to bytes which are sent and received.
  251. */
  252. struct tpm_ops {
  253. /**
  254. * open() - Request access to locality 0 for the caller
  255. *
  256. * After all commands have been completed the caller should call
  257. * close().
  258. *
  259. * @dev: Device to close
  260. * @return 0 ok OK, -ve on error
  261. */
  262. int (*open)(struct udevice *dev);
  263. /**
  264. * close() - Close the current session
  265. *
  266. * Releasing the locked locality. Returns 0 on success, -ve 1 on
  267. * failure (in case lock removal did not succeed).
  268. *
  269. * @dev: Device to close
  270. * @return 0 ok OK, -ve on error
  271. */
  272. int (*close)(struct udevice *dev);
  273. /**
  274. * get_desc() - Get a text description of the TPM
  275. *
  276. * @dev: Device to check
  277. * @buf: Buffer to put the string
  278. * @size: Maximum size of buffer
  279. * @return length of string, or -ENOSPC it no space
  280. */
  281. int (*get_desc)(struct udevice *dev, char *buf, int size);
  282. /**
  283. * send() - send data to the TPM
  284. *
  285. * @dev: Device to talk to
  286. * @sendbuf: Buffer of the data to send
  287. * @send_size: Size of the data to send
  288. *
  289. * Returns 0 on success or -ve on failure.
  290. */
  291. int (*send)(struct udevice *dev, const uint8_t *sendbuf,
  292. size_t send_size);
  293. /**
  294. * recv() - receive a response from the TPM
  295. *
  296. * @dev: Device to talk to
  297. * @recvbuf: Buffer to save the response to
  298. * @max_size: Maximum number of bytes to receive
  299. *
  300. * Returns number of bytes received on success, -EAGAIN if the TPM
  301. * response is not ready, -EINTR if cancelled, or other -ve value on
  302. * failure.
  303. */
  304. int (*recv)(struct udevice *dev, uint8_t *recvbuf, size_t max_size);
  305. /**
  306. * cleanup() - clean up after an operation in progress
  307. *
  308. * This is called if receiving times out. The TPM may need to abort
  309. * the current transaction if it did not complete, and make itself
  310. * ready for another.
  311. *
  312. * @dev: Device to talk to
  313. */
  314. int (*cleanup)(struct udevice *dev);
  315. /**
  316. * xfer() - send data to the TPM and get response
  317. *
  318. * This method is optional. If it exists it is used in preference
  319. * to send(), recv() and cleanup(). It should handle all aspects of
  320. * TPM communication for a single transfer.
  321. *
  322. * @dev: Device to talk to
  323. * @sendbuf: Buffer of the data to send
  324. * @send_size: Size of the data to send
  325. * @recvbuf: Buffer to save the response to
  326. * @recv_size: Pointer to the size of the response buffer
  327. *
  328. * Returns 0 on success (and places the number of response bytes at
  329. * recv_size) or -ve on failure.
  330. */
  331. int (*xfer)(struct udevice *dev, const uint8_t *sendbuf,
  332. size_t send_size, uint8_t *recvbuf, size_t *recv_size);
  333. };
  334. #define tpm_get_ops(dev) ((struct tpm_ops *)device_get_ops(dev))
  335. /**
  336. * tpm_open() - Request access to locality 0 for the caller
  337. *
  338. * After all commands have been completed the caller is supposed to
  339. * call tpm_close().
  340. *
  341. * Returns 0 on success, -ve on failure.
  342. */
  343. int tpm_open(struct udevice *dev);
  344. /**
  345. * tpm_close() - Close the current session
  346. *
  347. * Releasing the locked locality. Returns 0 on success, -ve 1 on
  348. * failure (in case lock removal did not succeed).
  349. */
  350. int tpm_close(struct udevice *dev);
  351. /**
  352. * tpm_get_desc() - Get a text description of the TPM
  353. *
  354. * @dev: Device to check
  355. * @buf: Buffer to put the string
  356. * @size: Maximum size of buffer
  357. * @return length of string, or -ENOSPC it no space
  358. */
  359. int tpm_get_desc(struct udevice *dev, char *buf, int size);
  360. /**
  361. * tpm_xfer() - send data to the TPM and get response
  362. *
  363. * This first uses the device's send() method to send the bytes. Then it calls
  364. * recv() to get the reply. If recv() returns -EAGAIN then it will delay a
  365. * short time and then call recv() again.
  366. *
  367. * Regardless of whether recv() completes successfully, it will then call
  368. * cleanup() to finish the transaction.
  369. *
  370. * Note that the outgoing data is inspected to determine command type
  371. * (ordinal) and a timeout is used for that command type.
  372. *
  373. * @sendbuf - buffer of the data to send
  374. * @send_size size of the data to send
  375. * @recvbuf - memory to save the response to
  376. * @recv_len - pointer to the size of the response buffer
  377. *
  378. * Returns 0 on success (and places the number of response bytes at
  379. * recv_len) or -ve on failure.
  380. */
  381. int tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, size_t send_size,
  382. uint8_t *recvbuf, size_t *recv_size);
  383. /**
  384. * Initialize TPM device. It must be called before any TPM commands.
  385. *
  386. * @return 0 on success, non-0 on error.
  387. */
  388. int tpm_init(void);
  389. /**
  390. * Issue a TPM_Startup command.
  391. *
  392. * @param mode TPM startup mode
  393. * @return return code of the operation
  394. */
  395. uint32_t tpm_startup(enum tpm_startup_type mode);
  396. /**
  397. * Issue a TPM_SelfTestFull command.
  398. *
  399. * @return return code of the operation
  400. */
  401. uint32_t tpm_self_test_full(void);
  402. /**
  403. * Issue a TPM_ContinueSelfTest command.
  404. *
  405. * @return return code of the operation
  406. */
  407. uint32_t tpm_continue_self_test(void);
  408. /**
  409. * Issue a TPM_NV_DefineSpace command. The implementation is limited
  410. * to specify TPM_NV_ATTRIBUTES and size of the area. The area index
  411. * could be one of the special value listed in enum tpm_nv_index.
  412. *
  413. * @param index index of the area
  414. * @param perm TPM_NV_ATTRIBUTES of the area
  415. * @param size size of the area
  416. * @return return code of the operation
  417. */
  418. uint32_t tpm_nv_define_space(uint32_t index, uint32_t perm, uint32_t size);
  419. /**
  420. * Issue a TPM_NV_ReadValue command. This implementation is limited
  421. * to read the area from offset 0. The area index could be one of
  422. * the special value listed in enum tpm_nv_index.
  423. *
  424. * @param index index of the area
  425. * @param data output buffer of the area contents
  426. * @param count size of output buffer
  427. * @return return code of the operation
  428. */
  429. uint32_t tpm_nv_read_value(uint32_t index, void *data, uint32_t count);
  430. /**
  431. * Issue a TPM_NV_WriteValue command. This implementation is limited
  432. * to write the area from offset 0. The area index could be one of
  433. * the special value listed in enum tpm_nv_index.
  434. *
  435. * @param index index of the area
  436. * @param data input buffer to be wrote to the area
  437. * @param length length of data bytes of input buffer
  438. * @return return code of the operation
  439. */
  440. uint32_t tpm_nv_write_value(uint32_t index, const void *data, uint32_t length);
  441. /**
  442. * Issue a TPM_Extend command.
  443. *
  444. * @param index index of the PCR
  445. * @param in_digest 160-bit value representing the event to be
  446. * recorded
  447. * @param out_digest 160-bit PCR value after execution of the
  448. * command
  449. * @return return code of the operation
  450. */
  451. uint32_t tpm_extend(uint32_t index, const void *in_digest, void *out_digest);
  452. /**
  453. * Issue a TPM_PCRRead command.
  454. *
  455. * @param index index of the PCR
  456. * @param data output buffer for contents of the named PCR
  457. * @param count size of output buffer
  458. * @return return code of the operation
  459. */
  460. uint32_t tpm_pcr_read(uint32_t index, void *data, size_t count);
  461. /**
  462. * Issue a TSC_PhysicalPresence command. TPM physical presence flag
  463. * is bit-wise OR'ed of flags listed in enum tpm_physical_presence.
  464. *
  465. * @param presence TPM physical presence flag
  466. * @return return code of the operation
  467. */
  468. uint32_t tpm_tsc_physical_presence(uint16_t presence);
  469. /**
  470. * Issue a TPM_ReadPubek command.
  471. *
  472. * @param data output buffer for the public endorsement key
  473. * @param count size of ouput buffer
  474. * @return return code of the operation
  475. */
  476. uint32_t tpm_read_pubek(void *data, size_t count);
  477. /**
  478. * Issue a TPM_ForceClear command.
  479. *
  480. * @return return code of the operation
  481. */
  482. uint32_t tpm_force_clear(void);
  483. /**
  484. * Issue a TPM_PhysicalEnable command.
  485. *
  486. * @return return code of the operation
  487. */
  488. uint32_t tpm_physical_enable(void);
  489. /**
  490. * Issue a TPM_PhysicalDisable command.
  491. *
  492. * @return return code of the operation
  493. */
  494. uint32_t tpm_physical_disable(void);
  495. /**
  496. * Issue a TPM_PhysicalSetDeactivated command.
  497. *
  498. * @param state boolean state of the deactivated flag
  499. * @return return code of the operation
  500. */
  501. uint32_t tpm_physical_set_deactivated(uint8_t state);
  502. /**
  503. * Issue a TPM_GetCapability command. This implementation is limited
  504. * to query sub_cap index that is 4-byte wide.
  505. *
  506. * @param cap_area partition of capabilities
  507. * @param sub_cap further definition of capability, which is
  508. * limited to be 4-byte wide
  509. * @param cap output buffer for capability information
  510. * @param count size of ouput buffer
  511. * @return return code of the operation
  512. */
  513. uint32_t tpm_get_capability(uint32_t cap_area, uint32_t sub_cap,
  514. void *cap, size_t count);
  515. /**
  516. * Issue a TPM_FlushSpecific command for a AUTH ressource.
  517. *
  518. * @param auth_handle handle of the auth session
  519. * @return return code of the operation
  520. */
  521. uint32_t tpm_terminate_auth_session(uint32_t auth_handle);
  522. /**
  523. * Issue a TPM_OIAP command to setup an object independant authorization
  524. * session.
  525. * Information about the session is stored internally.
  526. * If there was already an OIAP session active it is terminated and a new
  527. * session is set up.
  528. *
  529. * @param auth_handle pointer to the (new) auth handle or NULL.
  530. * @return return code of the operation
  531. */
  532. uint32_t tpm_oiap(uint32_t *auth_handle);
  533. /**
  534. * Ends an active OIAP session.
  535. *
  536. * @return return code of the operation
  537. */
  538. uint32_t tpm_end_oiap(void);
  539. /**
  540. * Issue a TPM_LoadKey2 (Auth1) command using an OIAP session for authenticating
  541. * the usage of the parent key.
  542. *
  543. * @param parent_handle handle of the parent key.
  544. * @param key pointer to the key structure (TPM_KEY or TPM_KEY12).
  545. * @param key_length size of the key structure
  546. * @param parent_key_usage_auth usage auth for the parent key
  547. * @param key_handle pointer to the key handle
  548. * @return return code of the operation
  549. */
  550. uint32_t tpm_load_key2_oiap(uint32_t parent_handle,
  551. const void *key, size_t key_length,
  552. const void *parent_key_usage_auth,
  553. uint32_t *key_handle);
  554. /**
  555. * Issue a TPM_GetPubKey (Auth1) command using an OIAP session for
  556. * authenticating the usage of the key.
  557. *
  558. * @param key_handle handle of the key
  559. * @param usage_auth usage auth for the key
  560. * @param pubkey pointer to the pub key buffer; may be NULL if the pubkey
  561. * should not be stored.
  562. * @param pubkey_len pointer to the pub key buffer len. On entry: the size of
  563. * the provided pubkey buffer. On successful exit: the size
  564. * of the stored TPM_PUBKEY structure (iff pubkey != NULL).
  565. * @return return code of the operation
  566. */
  567. uint32_t tpm_get_pub_key_oiap(uint32_t key_handle, const void *usage_auth,
  568. void *pubkey, size_t *pubkey_len);
  569. /**
  570. * Get the TPM permanent flags value
  571. *
  572. * @param pflags Place to put permanent flags
  573. * @return return code of the operation
  574. */
  575. uint32_t tpm_get_permanent_flags(struct tpm_permanent_flags *pflags);
  576. /**
  577. * Get the TPM permissions
  578. *
  579. * @param perm Returns permissions value
  580. * @return return code of the operation
  581. */
  582. uint32_t tpm_get_permissions(uint32_t index, uint32_t *perm);
  583. /**
  584. * Flush a resource with a given handle and type from the TPM
  585. *
  586. * @param key_handle handle of the resource
  587. * @param resource_type type of the resource
  588. * @return return code of the operation
  589. */
  590. uint32_t tpm_flush_specific(uint32_t key_handle, uint32_t resource_type);
  591. #ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1
  592. /**
  593. * Search for a key by usage AuthData and the hash of the parent's pub key.
  594. *
  595. * @param auth Usage auth of the key to search for
  596. * @param pubkey_digest SHA1 hash of the pub key structure of the key
  597. * @param[out] handle The handle of the key (Non-null iff found)
  598. * @return 0 if key was found in TPM; != 0 if not.
  599. */
  600. uint32_t tpm_find_key_sha1(const uint8_t auth[20], const uint8_t
  601. pubkey_digest[20], uint32_t *handle);
  602. #endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */
  603. /**
  604. * Read random bytes from the TPM RNG. The implementation deals with the fact
  605. * that the TPM may legally return fewer bytes than requested by retrying
  606. * until @p count bytes have been received.
  607. *
  608. * @param data output buffer for the random bytes
  609. * @param count size of output buffer
  610. * @return return code of the operation
  611. */
  612. uint32_t tpm_get_random(void *data, uint32_t count);
  613. #endif /* __TPM_H */