sgx_dh_internal.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (C) 2011-2016 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_INTERNAL_H_
  32. #define _SGX_DH_INTERNAL_H_
  33. #include "sgx.h"
  34. #include "sgx_defs.h"
  35. #include "sgx_ecp_types.h"
  36. #include "sgx_dh.h"
  37. #pragma pack(push, 1)
  38. typedef enum _sgx_dh_session_state_t
  39. {
  40. SGX_DH_SESSION_STATE_ERROR,
  41. SGX_DH_SESSION_STATE_RESET,
  42. SGX_DH_SESSION_RESPONDER_WAIT_M2,
  43. SGX_DH_SESSION_INITIATOR_WAIT_M1,
  44. SGX_DH_SESSION_INITIATOR_WAIT_M3,
  45. SGX_DH_SESSION_ACTIVE
  46. } sgx_dh_session_state_t;
  47. typedef struct _sgx_dh_responder_t{
  48. sgx_dh_session_state_t state; /*Responder State Machine State */
  49. sgx_ec256_private_t prv_key; /* 256bit EC private key */
  50. sgx_ec256_public_t pub_key; /* 512 bit EC public key */
  51. } sgx_dh_responder_t;
  52. typedef struct _sgx_dh_initator_t{
  53. sgx_dh_session_state_t state; /* Initiator State Machine State */
  54. union{
  55. sgx_ec256_private_t prv_key; /* 256bit EC private key */
  56. sgx_key_128bit_t smk_aek; /* 128bit SMK or AEK. Depending on the State */
  57. };
  58. sgx_ec256_public_t pub_key; /* 512 bit EC public key */
  59. sgx_ec256_public_t peer_pub_key; /* 512 bit EC public key from the Responder */
  60. sgx_ec256_dh_shared_t shared_key;
  61. } sgx_dh_initator_t;
  62. typedef struct _sgx_internal_dh_session_t{
  63. sgx_dh_session_role_t role; /* Initiator or Responder */
  64. union{
  65. sgx_dh_responder_t responder;
  66. sgx_dh_initator_t initiator;
  67. };
  68. } sgx_internal_dh_session_t;
  69. static_assert(sizeof(sgx_internal_dh_session_t) == SGX_DH_SESSION_DATA_SIZE, "size mismatch on sgx_internal_dh_session_t and sgx_dh_session_t");
  70. #pragma pack(pop)
  71. #endif