sgx_dh.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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_DH_H_
  32. #define _SGX_DH_H_
  33. #include "sgx.h"
  34. #include "sgx_defs.h"
  35. #include "sgx_ecp_types.h"
  36. #pragma pack(push, 1)
  37. #define SGX_DH_MAC_SIZE 16
  38. #define SGX_DH_SESSION_DATA_SIZE 200
  39. typedef struct _sgx_dh_msg1_t
  40. {
  41. sgx_ec256_public_t g_a; /* the Endian-ness of Ga is Little-Endian */
  42. sgx_target_info_t target;
  43. } sgx_dh_msg1_t;
  44. typedef struct _sgx_dh_msg2_t
  45. {
  46. sgx_ec256_public_t g_b; /* the Endian-ness of Gb is Little-Endian */
  47. sgx_report_t report;
  48. uint8_t cmac[SGX_DH_MAC_SIZE];
  49. } sgx_dh_msg2_t;
  50. typedef struct _sgx_dh_msg3_body_t
  51. {
  52. sgx_report_t report;
  53. uint32_t additional_prop_length;
  54. uint8_t additional_prop[0];
  55. } sgx_dh_msg3_body_t;
  56. typedef struct _sgx_dh_msg3_t
  57. {
  58. uint8_t cmac[SGX_DH_MAC_SIZE];
  59. sgx_dh_msg3_body_t msg3_body;
  60. } sgx_dh_msg3_t;
  61. typedef struct _sgx_dh_session_enclave_identity_t
  62. {
  63. sgx_cpu_svn_t cpu_svn;
  64. sgx_misc_select_t misc_select;
  65. uint8_t reserved_1[28];
  66. sgx_attributes_t attributes;
  67. sgx_measurement_t mr_enclave;
  68. uint8_t reserved_2[32];
  69. sgx_measurement_t mr_signer;
  70. uint8_t reserved_3[96];
  71. sgx_prod_id_t isv_prod_id;
  72. sgx_isv_svn_t isv_svn;
  73. } sgx_dh_session_enclave_identity_t;
  74. typedef enum _sgx_dh_session_role_t
  75. {
  76. SGX_DH_SESSION_INITIATOR,
  77. SGX_DH_SESSION_RESPONDER
  78. } sgx_dh_session_role_t;
  79. typedef struct _sgx_dh_session_t
  80. {
  81. uint8_t sgx_dh_session[SGX_DH_SESSION_DATA_SIZE];
  82. } sgx_dh_session_t;
  83. #pragma pack(pop)
  84. #ifdef __cplusplus
  85. extern "C" {
  86. #endif
  87. /* The order of calling SGX DH Library APIs is restricted as below */
  88. /* As session initiator : Step.1 sgx_dh_init_session --> Step.2 sgx_dh_initiator_proc_msg1 --> Step.3 sgx_dh_initiator_proc_msg3 */
  89. /* As session responder : Step.1 sgx_dh_init_session --> Step.2 sgx_dh_responder_gen_msg1 --> Step.3 sgx_dh_responder_proc_msg2*/
  90. /* Any out of order calling will cause session establishment failure. */
  91. /*Function name: sgx_dh_init_session
  92. ** parameter description
  93. **@ [input] role: caller's role in dh session establishment
  94. **@ [output] session: point to dh session structure that is used during establishment, the buffer must be in enclave address space
  95. */
  96. sgx_status_t SGXAPI sgx_dh_init_session(sgx_dh_session_role_t role,
  97. sgx_dh_session_t* session);
  98. /*Function name: sgx_dh_responder_gen_msg1
  99. ** parameter description
  100. **@ [output] msg1: point to dh message 1 buffer, and the buffer must be in enclave address space
  101. **@ [input/output] dh_session: point to dh session structure that is used during establishment, and the buffer must be in enclave address space
  102. */
  103. sgx_status_t SGXAPI sgx_dh_responder_gen_msg1(sgx_dh_msg1_t* msg1,
  104. sgx_dh_session_t* dh_session);
  105. /*Function name: sgx_dh_initiator_proc_msg1
  106. ** parameter description
  107. **@ [input] msg1: point to dh message 1 buffer generated by session responder, and the buffer must be in enclave address space
  108. **@ [output] msg2: point to dh message 2 buffer, and the buffer must be in enclave address space
  109. **@ [input/output] dh_session: point to dh session structure that is used during establishment, and the buffer must be in enclave address space
  110. */
  111. sgx_status_t SGXAPI sgx_dh_initiator_proc_msg1(const sgx_dh_msg1_t* msg1,
  112. sgx_dh_msg2_t* msg2,
  113. sgx_dh_session_t* dh_session);
  114. /*Function name: sgx_dh_responder_proc_msg2
  115. ** parameter description
  116. **@ [input] msg2: point to dh message 2 buffer generated by session initiator, and the buffer must be in enclave address space
  117. **@ [output] msg3: point to dh message 3 buffer generated by session responder in this function, and the buffer must be in enclave address space
  118. **@ [input/output] dh_session: point to dh session structure that is used during establishment, and the buffer must be in enclave address space
  119. **@ [output] aek: AEK derived from shared key. the buffer must be in enclave address space.
  120. **@ [output] initiator_identity: identity information of initiator including isv svn, isv product id, sgx attributes, mr signer, and mr enclave. the buffer must be in enclave address space.
  121. */
  122. sgx_status_t SGXAPI sgx_dh_responder_proc_msg2(const sgx_dh_msg2_t* msg2,
  123. sgx_dh_msg3_t* msg3,
  124. sgx_dh_session_t* dh_session,
  125. sgx_key_128bit_t* aek,
  126. sgx_dh_session_enclave_identity_t* initiator_identity);
  127. /*Function name: sgx_dh_initiator_proc_msg3
  128. ** parameter description
  129. **@ [input] msg3: point to dh message 3 buffer generated by session responder, and the buffer must be in enclave address space
  130. **@ [input/output] dh_session: point to dh session structure that is used during establishment, and the buffer must be in enclave address space
  131. **@ [output] aek: AEK derived from shared key. the buffer must be in enclave address space.
  132. **@ [output] responder_identity: identity information of responder including isv svn, isv product id, sgx attributes, mr signer, and mr enclave. the buffer must be in enclave address space.
  133. */
  134. sgx_status_t SGXAPI sgx_dh_initiator_proc_msg3(const sgx_dh_msg3_t* msg3,
  135. sgx_dh_session_t* dh_session,
  136. sgx_key_128bit_t* aek,
  137. sgx_dh_session_enclave_identity_t* responder_identity);
  138. #ifdef __cplusplus
  139. }
  140. #endif
  141. #endif