sgx_tkey_exchange.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * Copyright (C) 2011-2017 Intel Corporation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in
  12. * the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Intel Corporation nor the names of its
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. */
  31. #ifndef _SGX_TKEY_EXCHANGE_H_
  32. #define _SGX_TKEY_EXCHANGE_H_
  33. #include "sgx.h"
  34. #include "sgx_defs.h"
  35. #include "sgx_key_exchange.h"
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. /*
  40. * The sgx_ra_init function creates a context for the remote attestation and
  41. * key exchange process.
  42. *
  43. * @param p_pub_key The EC public key of the service provider based on the NIST
  44. * P-256 elliptic curve.
  45. * @param b_pse If true, platform service information is needed in message
  46. * 3. The caller should make sure a PSE session has been
  47. * established using sgx_create_pse_session before attempting
  48. * to establish a remote attestation and key exchange session
  49. * involving platform service information.
  50. * @param p_context The output context for the subsequent remote attestation
  51. * and key exchange process, to be used in sgx_ra_get_msg1 and
  52. * sgx_ra_proc_msg2.
  53. * @return sgx_status_t SGX_SUCCESS Indicates success.
  54. * SGX_ERROR_INVALID_PARAMETER Indicates an error that
  55. * the input parameters are
  56. * invalid.
  57. * SGX_ERROR_OUT_OF_MEMORY There is not enough
  58. * memory available to
  59. * complete this operation.
  60. * SGX_ERROR_AE_SESSION_INVALID Session is invalid or
  61. * ended by server.
  62. * SGX_ERROR_UNEXPECTED Indicates an unexpected
  63. * error occurs.
  64. */
  65. sgx_status_t SGXAPI sgx_ra_init(
  66. const sgx_ec256_public_t *p_pub_key,
  67. int b_pse,
  68. sgx_ra_context_t *p_context);
  69. /*
  70. * The sgx_ra_derive_secret_keys_t function should takes the Diffie-Hellman
  71. * shared secret as input to allow the ISV enclave to generate their own derived
  72. * shared keys (SMK, SK, MK and VK).
  73. *
  74. * @param p_shared_key The the Diffie-Hellman shared secret.
  75. * @param kdf_id, Key Derivation Function ID
  76. * @param p_smk_key The output SMK.
  77. * @param p_sk_key The output SK.
  78. * @param p_mk_key The output MK.
  79. * @param p_vk_key The output VK.
  80. * @return sgx_status_t SGX_SUCCESS Indicates success.
  81. * SGX_ERROR_INVALID_PARAMETER Indicates an error that
  82. * the input parameters are
  83. * invalid.
  84. * SGX_ERROR_KDF_MISMATCH Indicates key derivation
  85. * function doesn't match.
  86. * SGX_ERROR_OUT_OF_MEMORY There is not enough
  87. * memory available to
  88. * complete this operation.
  89. * SGX_ERROR_UNEXPECTED Indicates an unexpected
  90. * error occurs.
  91. */
  92. typedef sgx_status_t(*sgx_ra_derive_secret_keys_t)(
  93. const sgx_ec256_dh_shared_t* p_shared_key,
  94. uint16_t kdf_id,
  95. sgx_ec_key_128bit_t* p_smk_key,
  96. sgx_ec_key_128bit_t* p_sk_key,
  97. sgx_ec_key_128bit_t* p_mk_key,
  98. sgx_ec_key_128bit_t* p_vk_key);
  99. /*
  100. * The sgx_ra_init_ex function creates a context for the remote attestation and
  101. * key exchange process asociated with a key derive function.
  102. *
  103. * @param p_pub_key The EC public key of the service provider based on the NIST
  104. * P-256 elliptic curve.
  105. * @param b_pse If true, platform service information is needed in message
  106. * 3. The caller should make sure a PSE session has been
  107. * established using sgx_create_pse_session before attempting
  108. * to establish a remote attestation and key exchange session
  109. * involving platform service information.
  110. * @param derive_key_cb A pointer to a call back routine matching the
  111. * function prototype of sgx_ra_derive_secret_keys_t. This
  112. * function takes the Diffie-Hellman shared secret as input
  113. * to allow the ISV enclave to generate their own derived
  114. * shared keys (SMK, SK, MK and VK).
  115. * @param p_context The output context for the subsequent remote attestation
  116. * and key exchange process, to be used in sgx_ra_get_msg1 and
  117. * sgx_ra_get_msg2.
  118. * @return sgx_status_t SGX_SUCCESS Indicates success.
  119. * SGX_ERROR_INVALID_PARAMETER Indicates an error that
  120. * the input parameters are
  121. * invalid.
  122. * SGX_ERROR_OUT_OF_MEMORY There is not enough
  123. * memory available to
  124. * complete this operation.
  125. * SGX_ERROR_AE_SESSION_INVALID Session is invalid or
  126. * ended by server.
  127. * SGX_ERROR_UNEXPECTED Indicates an unexpected
  128. * error occurs.
  129. */
  130. sgx_status_t SGXAPI sgx_ra_init_ex(
  131. const sgx_ec256_public_t *p_pub_key,
  132. int b_pse,
  133. sgx_ra_derive_secret_keys_t derive_key_cb,
  134. sgx_ra_context_t *p_context);
  135. /*
  136. * The sgx_ra_get_keys function is used to get the negotiated keys of a remote
  137. * attestation and key exchange session. This function should only be called
  138. * after the service provider accepts the remote attestation and key exchange
  139. * protocol message 3 produced by sgx_ra_proc_msg2.
  140. *
  141. * @param context Context returned by sgx_ra_init.
  142. * @param type The specifier of keys, can be SGX_RA_KEY_MK, SGX_RA_KEY_SK
  143. * and SGX_RA_VK.
  144. * @param p_key The key returned.
  145. * @return sgx_status_t SGX_SUCCESS Indicates success.
  146. * SGX_ERROR_INVALID_PARAMETER Indicates an error that
  147. * the input parameters are
  148. * invalid.
  149. * SGX_ERROR_INVALID_STATE Indicates this function
  150. * is called out of order.
  151. */
  152. sgx_status_t SGXAPI sgx_ra_get_keys(
  153. sgx_ra_context_t context,
  154. sgx_ra_key_type_t type,
  155. sgx_ra_key_128_t *p_key);
  156. /*
  157. * Call the sgx_ra_close function to release the remote attestation and key
  158. * exchange context after the process is done and the context isn't needed
  159. * anymore.
  160. *
  161. * @param context Context returned by sgx_ra_init.
  162. * @return sgx_status_t SGX_SUCCESS Indicates success.
  163. * SGX_ERROR_INVALID_PARAMETER Indicates an error that
  164. * the input parameters are
  165. * invalid.
  166. */
  167. sgx_status_t SGXAPI sgx_ra_close(
  168. sgx_ra_context_t context);
  169. #ifdef __cplusplus
  170. }
  171. #endif
  172. #endif