tpm_tss.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * Copyright (C) 2018 Tobias Brunner
  3. * Copyright (C) 2016-2018 Andreas Steffen
  4. * HSR Hochschule fuer Technik Rapperswil
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  13. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14. * for more details.
  15. */
  16. /**
  17. * @defgroup libtpmtss libtpmtss
  18. *
  19. * @addtogroup libtpmtss
  20. * @{
  21. */
  22. #ifndef TPM_TSS_H_
  23. #define TPM_TSS_H_
  24. #include "tpm_tss_quote_info.h"
  25. #include <library.h>
  26. #include <crypto/hashers/hasher.h>
  27. typedef enum tpm_version_t tpm_version_t;
  28. typedef struct tpm_tss_t tpm_tss_t;
  29. /**
  30. * TPM Versions
  31. */
  32. enum tpm_version_t {
  33. TPM_VERSION_ANY,
  34. TPM_VERSION_1_2,
  35. TPM_VERSION_2_0,
  36. };
  37. /**
  38. * TPM access via TSS public interface
  39. */
  40. struct tpm_tss_t {
  41. /**
  42. * Get TPM version supported by TSS
  43. *
  44. * @return TPM version
  45. */
  46. tpm_version_t (*get_version)(tpm_tss_t *this);
  47. /**
  48. * Get TPM version info (TPM 1.2 only)
  49. *
  50. * @return TPM version info struct
  51. */
  52. chunk_t (*get_version_info)(tpm_tss_t *this);
  53. /**
  54. * Generate AIK key pair bound to TPM (TPM 1.2 only)
  55. *
  56. * @param ca_modulus RSA modulus of CA public key
  57. * @param aik_blob AIK private key blob
  58. * @param aik_pubkey AIK public key
  59. * @return TRUE if AIK key generation succeeded
  60. */
  61. bool (*generate_aik)(tpm_tss_t *this, chunk_t ca_modulus,
  62. chunk_t *aik_blob, chunk_t *aik_pubkey,
  63. chunk_t *identity_req);
  64. /**
  65. * Get public key from TPM using its object handle (TPM 2.0 only)
  66. *
  67. * @param handle key object handle
  68. * @return public key in PKCS#1 format
  69. */
  70. chunk_t (*get_public)(tpm_tss_t *this, uint32_t handle);
  71. /**
  72. * Return signature schemes supported by the given key (TPM 2.0 only)
  73. *
  74. * @param handle key object handle
  75. * @return enumerator over signature_params_t*
  76. */
  77. enumerator_t *(*supported_signature_schemes)(tpm_tss_t *this,
  78. uint32_t handle);
  79. /**
  80. * Retrieve the current value of a PCR register in a given PCR bank
  81. *
  82. * @param pcr_num PCR number
  83. * @param pcr_value PCR value returned
  84. * @param alg hash algorithm, selects PCR bank (TPM 2.0 only)
  85. * @return TRUE if PCR value retrieval succeeded
  86. */
  87. bool (*read_pcr)(tpm_tss_t *this, uint32_t pcr_num, chunk_t *pcr_value,
  88. hash_algorithm_t alg);
  89. /**
  90. * Extend a PCR register in a given PCR bank with a hash value
  91. *
  92. * @param pcr_num PCR number
  93. * @param pcr_value extended PCR value returned
  94. * @param hash data to be extended into the PCR
  95. * @param alg hash algorithm, selects PCR bank (TPM 2.0 only)
  96. * @return TRUE if PCR extension succeeded
  97. */
  98. bool (*extend_pcr)(tpm_tss_t *this, uint32_t pcr_num, chunk_t *pcr_value,
  99. chunk_t data, hash_algorithm_t alg);
  100. /**
  101. * Do a quote signature over a selection of PCR registers
  102. *
  103. * @param aik_handle object handle of AIK to be used for quote signature
  104. * @param pcr_sel selection of PCR registers
  105. * @param alg hash algorithm to be used for quote signature
  106. * @param data additional data to be hashed into the quote
  107. * @param quote_mode define current and legacy TPM quote modes
  108. * @param quote_info returns various info covered by quote signature
  109. * @param quote_sig returns quote signature
  110. * @return TRUE if quote signature succeeded
  111. */
  112. bool (*quote)(tpm_tss_t *this, uint32_t aik_handle, uint32_t pcr_sel,
  113. hash_algorithm_t alg, chunk_t data,
  114. tpm_quote_mode_t *quote_mode,
  115. tpm_tss_quote_info_t **quote_info, chunk_t *quote_sig);
  116. /**
  117. * Do a signature over a data hash using a TPM key handle (TPM 2.0 only)
  118. *
  119. * @param handle object handle of TPM key to be used for signature
  120. * @param hierarchy hierarchy the TPM key object is attached to
  121. * @param scheme scheme to be used for signature
  122. * @param param signature scheme parameters
  123. * @param data data to be hashed and signed
  124. * @param pin PIN code or empty chunk
  125. * @param signature returns signature
  126. * @return TRUE if signature succeeded
  127. */
  128. bool (*sign)(tpm_tss_t *this, uint32_t hierarchy, uint32_t handle,
  129. signature_scheme_t scheme, void *params, chunk_t data,
  130. chunk_t pin, chunk_t *signature);
  131. /**
  132. * Get random bytes from the TPM
  133. *
  134. * @param bytes number of random bytes requested
  135. * @param buffer buffer where the random bytes are written into
  136. * @return TRUE if random bytes could be delivered
  137. */
  138. bool (*get_random)(tpm_tss_t *this, size_t bytes, uint8_t *buffer);
  139. /**
  140. * Get a data blob from TPM NV store using its object handle (TPM 2.0 only)
  141. *
  142. * @param handle object handle of TPM key to be used for signature
  143. * @param hierarchy hierarchy the TPM key object is attached to
  144. * @param pin PIN code or empty chunk
  145. * @param data returns data blob
  146. * @return TRUE if data retrieval succeeded
  147. */
  148. bool (*get_data)(tpm_tss_t *this, uint32_t hierarchy, uint32_t handle,
  149. chunk_t pin, chunk_t *data);
  150. /**
  151. * Destroy a tpm_tss_t.
  152. */
  153. void (*destroy)(tpm_tss_t *this);
  154. };
  155. /**
  156. * Create a tpm_tss instance.
  157. *
  158. * @param version TPM version that must be supported by TSS
  159. */
  160. tpm_tss_t *tpm_tss_probe(tpm_version_t version);
  161. /**
  162. * libtpmtss initialization function
  163. *
  164. * @return TRUE if initialization was successful
  165. */
  166. bool libtpmtss_init(void);
  167. /**
  168. * libtpmtss de-initialization function
  169. */
  170. void libtpmtss_deinit(void);
  171. #endif /** TPM_TSS_H_ @}*/