epid_pve_type.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. * Copyright (C) 2011-2018 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. /**
  32. * File: epid_pve_type.h
  33. * Description: Header file to declare common types used in pve trust/untrusted code
  34. */
  35. #ifndef _EPID_PVE_TYPE_H_
  36. #define _EPID_PVE_TYPE_H_
  37. #include "epid/common/types.h"
  38. #include "epid/member/api.h"
  39. #include "se_types.h"
  40. #include "sgx_key.h"
  41. /*Some basic macro definition*/
  42. #define EPID_VERSION_MAJOR 2
  43. #define EPID_VERSION_MINOR 0
  44. #define EPID_TYPE_GROUP_CERT 12
  45. #define IV_SIZE 12 /*length in bytes of iv in block cipher. */
  46. #define SK_SIZE 16 /*length in bytes of SK, which is used in block cipher info*/
  47. #define GID_SIZE sizeof(GroupId) /*length in bytes of GroupID*/
  48. #define SK_CMAC_KEY_LEN IppsRijndaelKey128
  49. #define XID_SIZE 8 /*length in bytes of transaction id*/
  50. #define NONCE_SIZE 8 /*length in bytes of Nonce R in ProvMsg*/
  51. #define NONCE_2_SIZE 16 /*length in bytes of Nonce in ProvMsg3*/
  52. #define CHALLENGE_NONCE_SIZE 32 /*length in bytes of Challenge nonce in ProvMsg2*/
  53. #define PSVN_SIZE sizeof(psvn_t) /*18*/
  54. #define FLAGS_SIZE sizeof(flags_t) /*256*/
  55. #define MAC_SIZE 16 /*length in bytes of the tag in output of AES-GCM*/
  56. #define JOIN_PROOF_SIZE sizeof(JoinRequest)
  57. #define BLIND_ESCROW_SIZE sizeof(blind_escrow_data_t)
  58. #define PEK_PUB ((uint8_t)0)
  59. #define PEK_PRIV ((uint8_t)1)
  60. #define PEK_3072_PUB ((uint8_t)3)
  61. #define PEK_3072_PRIV ((uint8_t)4)
  62. #define ECDSA_SIGN_SIZE 32 /*This is the size of biginteger for ECDSA signature appended at the end of SIG-RL and the total signature size is size of two such kind of integer*/
  63. #define RSA_3072_KEY_BITS 3072
  64. #define RSA_3072_KEY_BYTES (RSA_3072_KEY_BITS/8)
  65. #define RSA_2048_KEY_BITS 2048
  66. #define RSA_2048_KEY_BYTES (RSA_2048_KEY_BITS/8)
  67. #define PVE_RSA_SEED_SIZE 32
  68. #define XEGB_SIZE 456 /*hardcoded size of extended_epid_group_blob_t*/
  69. #define XEGB_FORMAT_ID 0x0100 /*hardcoded format id in extended_epid_group_blob to be 16bits big-endian 1*/
  70. #pragma pack(push, 1)
  71. /*Define some structure will be used in TLV payload. Make sure the alignment of all of them is 1 since they'll be used in an unaligned buffer
  72. type for Platform Provisioning Identifier, it could be calculated inside PvE*/
  73. typedef struct _ppid_t{
  74. uint8_t ppid[16];
  75. }ppid_t;
  76. typedef struct _fmsp_t{
  77. uint8_t fmsp[4];
  78. }fmsp_t;
  79. /*type for provisioning server Identifier, the hash of provisioning server public key*/
  80. typedef struct _psid_t{
  81. uint8_t psid[32];
  82. }psid_t;
  83. /*Data structure without alignment required. */
  84. typedef struct _psvn_t{
  85. sgx_cpu_svn_t cpu_svn;
  86. sgx_isv_svn_t isv_svn; /*PvE/QE SVN*/
  87. }psvn_t;
  88. /*type for the optional Flags in ProvMsg1. Currently only the 1st bit is defined for performance rekey flag*/
  89. typedef struct _flags_t{
  90. uint8_t flags[16];
  91. }flags_t;
  92. typedef struct _bk_platform_info_t{
  93. sgx_cpu_svn_t cpu_svn;
  94. sgx_isv_svn_t pve_svn;
  95. sgx_isv_svn_t pce_svn;
  96. uint16_t pce_id;
  97. fmsp_t fmsp;
  98. }bk_platform_info_t;
  99. /*type for EpidVersion used in Epid Data which is two bytes big endian integer*/
  100. typedef struct _epid_version_t{
  101. uint8_t data[2];
  102. }epid_version_t;
  103. /*type for EpidType used in Epid Data which is two bytes big endian integer*/
  104. typedef struct _epid_type_t{
  105. uint8_t data[2];
  106. }epid_type_t;
  107. /*Type for signed Epid Group Public Cert*/
  108. typedef struct _signed_epid_group_cert_t{
  109. epid_version_t version;
  110. epid_type_t type;
  111. GroupPubKey key;
  112. uint8_t ecdsa_signature[2*ECDSA_SIGN_SIZE];
  113. }signed_epid_group_cert_t;
  114. #define PEK_MOD_SIZE 384
  115. typedef struct _signed_pek_t{
  116. uint8_t n[PEK_MOD_SIZE];
  117. uint8_t e[4];
  118. uint8_t sha1_ne[20];
  119. uint8_t pek_signature[2*ECDSA_SIGN_SIZE];
  120. uint8_t sha1_sign[20];
  121. }signed_pek_t;
  122. /*Type for Blind Escrow Data which is used in provisioning message 3 and message 4.
  123. The data structure is only used by PvE*/
  124. typedef struct _blind_escrow_data_t{
  125. uint32_t version;
  126. uint8_t iv[IV_SIZE];
  127. FpElemStr f;
  128. uint8_t mac[MAC_SIZE];
  129. }blind_escrow_data_t;
  130. /*The Join Proof with Escrow data in provisioning message 3*/
  131. typedef struct _join_proof_with_escrow_t{
  132. JoinRequest jr;
  133. blind_escrow_data_t escrow;
  134. }join_proof_with_escrow_t;
  135. /*The Membership Credential with Escrow Data used in provisioning message 4*/
  136. typedef struct _membership_credential_with_escrow_t{
  137. FpElemStr x;
  138. G1ElemStr A;
  139. blind_escrow_data_t escrow;
  140. }membership_credential_with_escrow_t;
  141. /*The Device ID structure used in Provisioning message*/
  142. typedef struct _device_id_t{
  143. ppid_t ppid;
  144. psvn_t psvn;
  145. fmsp_t fmsp;
  146. }device_id_t;
  147. #define EPID_KEY_BLOB_VERSION_SIK 2
  148. #define EPID_KEY_BLOB_VERSION_SDK 3
  149. #define PVE_SEAL_EPID_KEY_BLOB 0
  150. typedef struct _se_secret_epid_data_sik_t {
  151. PrivKey epid_private_key;
  152. }se_secret_epid_data_sik_t;
  153. typedef struct _se_secret_epid_data_sdk_t{
  154. PrivKey epid_private_key; /*This field must be the first field of the structure so that offset of epid_private_key is same in both se_secret_epid_data_sik_t and se_secret_epid_data_sdk_t*/
  155. MemberPrecomp member_precomp_data;
  156. }se_secret_epid_data_sdk_t;
  157. /*The first two fields are same for plaintext part of both EPID Blob Data*/
  158. typedef struct _se_plaintext_epid_data_sik_t {
  159. uint8_t seal_blob_type; /*Enclave-specific Sealblob Type, currently only one Sealblob type defined: PVE_SEAL_EPID_KEY_BLOB=0*/
  160. uint8_t epid_key_version; /*epid_key_version specifies version number, should be EPID_KEY_BLOB_VERSION_SIK*/
  161. sgx_cpu_svn_t equiv_cpu_svn;
  162. sgx_isv_svn_t equiv_pve_isv_svn;
  163. Epid2Params epid_param_cert;
  164. GroupPubKey epid_group_cert;
  165. uint8_t qsdk_exp[4]; /*little endian*/
  166. uint8_t qsdk_mod[RSA_2048_KEY_BYTES];/*little endian*/
  167. uint8_t epid_sk[2*ECDSA_SIGN_SIZE]; /*little endian*/
  168. uint32_t xeid; /*ExtEPIDGroup ID, little endian*/
  169. }se_plaintext_epid_data_sik_t;
  170. typedef struct _se_plaintext_epid_data_sdk_t{
  171. uint8_t seal_blob_type; /*Enclave-specific Sealblob Type, currently only one Sealblob type defined: PVE_SEAL_EPID_KEY_BLOB=0*/
  172. uint8_t epid_key_version; /*epid_key_versione specifies version number, should be EPID_KEY_BLOB_VERSION_SDK*/
  173. sgx_cpu_svn_t equiv_cpu_svn;
  174. sgx_isv_svn_t equiv_pve_isv_svn;
  175. GroupPubKey epid_group_cert;
  176. uint8_t qsdk_exp[4]; /*little endian*/
  177. uint8_t qsdk_mod[RSA_2048_KEY_BYTES];/*little endian*/
  178. uint8_t epid_sk[2*ECDSA_SIGN_SIZE]; /*little endian*/
  179. uint32_t xeid; /*ExtEPIDGroup ID, little endian*/
  180. }se_plaintext_epid_data_sdk_t;
  181. typedef struct _extended_epid_group_blob_t{
  182. uint16_t format_id; /*must be 1 in big-endian*/
  183. uint16_t data_length; /*big-endian length for fields after it but not including signature*/
  184. uint32_t xeid; /*ExtEPIDGroup ID, little endian*/
  185. uint8_t epid_sk[2*ECDSA_SIGN_SIZE]; /*ecdsa public key for EPID sign Key in little endian*/
  186. uint8_t pek_sk[2*ECDSA_SIGN_SIZE]; /*ecdsa public key for PEKSK in little endian*/
  187. uint8_t qsdk_exp[4]; /*exponient of RSA key for QSDK, little endian*/
  188. uint8_t qsdk_mod[RSA_2048_KEY_BYTES]; /*Modulus of RSA key for QSDK. current it is 2048 bits, little endian*/
  189. uint8_t signature[2*ECDSA_SIGN_SIZE];/*ECDSA signature of the data, big endian*/
  190. }extended_epid_group_blob_t;
  191. #define EXTENDED_EPID_GROUP_BLOB_DATA_LEN ((uint32_t)(sizeof(uint32_t)+4*(ECDSA_SIGN_SIZE)+4+(RSA_2048_KEY_BYTES)))
  192. #define SGX_TRUSTED_EPID_BLOB_SIZE_SIK ((uint32_t)(sizeof(sgx_sealed_data_t)+sizeof(se_secret_epid_data_sik_t)+sizeof(se_plaintext_epid_data_sik_t)))
  193. #define SGX_TRUSTED_EPID_BLOB_SIZE_SDK ((uint32_t)(sizeof(sgx_sealed_data_t)+sizeof(se_secret_epid_data_sdk_t)+sizeof(se_plaintext_epid_data_sdk_t)))
  194. #pragma pack(pop)
  195. #endif