tpm.h 19 KB

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