pse_pr_sigma_common_defs.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 SigmaCommonDefs.h
  33. @author Kapil Anantahraman
  34. @brief This file contains all the defines and data structures that are common for Sigma 1.0 and Sigma 1.1
  35. */
  36. #ifndef PSE_PR_SIGMA_COMMON_DEFS_H
  37. #define PSE_PR_SIGMA_COMMON_DEFS_H
  38. #include "pse_pr_types.h"
  39. //
  40. // both of these symbols are used in untrusted, pse cert provisioning code
  41. // the first, LEAFTOROOT, controls the order of the certs and of the ocsp responses
  42. // in the sigma s2 message. for sgx, as of now, LEAFTOROOT true gives leaf, leaf-1, leaf-2
  43. // LEAFTOROOT false gives leaf-2, leaf-1, leaf. LEAFTOROOT false is necessary, at least for the
  44. // certs. i don't think the order of ocsp responses matters.
  45. // MORE_PADDING determines how the S2 message is padded
  46. // MORE_PADDING false gives
  47. // Root+1 | root+2 | root+3 | padding to next dword
  48. // MORE_PADDING true gives
  49. // Root+1 | padding to next dword | root+2 | padding to next dword | root+3 | padding to next dword
  50. // we need true for the LPT emulator customized for SGX
  51. // we need false for SPT
  52. //
  53. #define LEAFTOROOT 0
  54. #include "pse_pr_padding.hh"
  55. #define NEXT_DWORD_BOUNDARY(x) ((x + 3) & ~3)
  56. #define NEXT_16_BYTE_BOUNDARY(x) ((x + 15) & ~15)
  57. #define REQUIRED_PADDING_DWORD_ALIGNMENT(x) ((x % 4) ? (4 - (x%4)) : 0)
  58. //#define ECDSA_SECKEY_LENGTH 32
  59. #define ECDSA_PUBKEY_LENGTH 64
  60. #define ECDSA_SIG_LENGTH 64
  61. #define SIGMA_SESSION_PRIVKEY_LENGTH 32
  62. #define SIGMA_SESSION_PUBKEY_LENGTH 64
  63. #define SIGMA_HMAC_LENGTH 32
  64. #define SIGMA_HMAC_SHA256_HASH_LENGTH 32
  65. #define SIGMA_SK_LENGTH 16
  66. #define SIGMA_MK_LENGTH 16
  67. #define SIGMA_IV_LENGTH 16
  68. #define SIGMA_SMK_LENGTH SIGMA_HMAC_SHA256_HASH_LENGTH
  69. #define SIGMA_SESSION_STATE_LENGTH (32+64+2*64+SIGMA_SK_LENGTH+SIGMA_MK_LENGTH) //256bytes
  70. #define EPID_SIG_LEN 569
  71. #define SIGMA_NONCE_LENGTH 32
  72. #define SIGMA_BASENAME_LENGTH 32
  73. #define SIG_RL_HEADER_SIZE sizeof(UINT32) + sizeof(UINT32) + sizeof(UINT32) + sizeof(UINT32) // For Serialization Tag, Gid, RLver and Number of entries
  74. #define NR_PROOFS_HEADER_SIZE sizeof(UINT32) + sizeof(UINT32) // For RLver and Number of entries
  75. #define SIGMA_PUBCERT3P_VER0 0x0000
  76. #define SIGMA_PUBCERT3P_VER1 0x0001
  77. #define SIGMA_PUBCERT3P_TYPE_VER0_UNDEFINED 0xffff
  78. #define SIGMA_PUBCERT3P_TYPE_VER1_PROTECTED_OUTPUT 0x0000
  79. #define SIGMA_PUBCERT3P_TYPE_VER1_MV 0x0001
  80. typedef UINT8 EphemeralPublicKey[SIGMA_SESSION_PUBKEY_LENGTH];
  81. typedef UINT8 EPID_SIGNATURE[EPID_SIG_LEN];
  82. typedef UINT8 SIGMA_HMAC[SIGMA_HMAC_LENGTH];
  83. typedef UINT8 VERIFIER_SIGNATURE[ECDSA_SIG_LENGTH];
  84. typedef UINT8 SIGMA_MAC_KEY[SIGMA_MK_LENGTH];
  85. typedef UINT8 SIGMA_SIGN_KEY[SIGMA_SK_LENGTH];
  86. typedef UINT8 SIGMA_INIT_VECTOR_KEY[SIGMA_IV_LENGTH];
  87. typedef UINT8 SIGMA_NONCE[SIGMA_NONCE_LENGTH];
  88. typedef UINT8 SIGMA_BASENAME[SIGMA_BASENAME_LENGTH];
  89. typedef UINT8 SIGMA_SESSION_STATE[SIGMA_SESSION_STATE_LENGTH];
  90. typedef enum
  91. {
  92. SESSION_UNINITIATED = 0,
  93. SESSION_PUBKEY_CREATED,
  94. SESSION_3RD_PARTY_CERT_VALID,
  95. SESSION_3RD_PARTY_CERT_INVALID,
  96. SESSION_PUBKEY_GENERATION_FAILED,
  97. #ifndef KC_TEST
  98. // SESSION_ESTABLISHED = SESSION_3RD_PARTY_CERT_VALID,
  99. #endif
  100. } SIGMA_SESSION_STATUS;
  101. #pragma pack(1)
  102. typedef struct _SessmgrFwVer
  103. {
  104. UINT32 Reserved;
  105. UINT16 MajorVersion;
  106. UINT16 MinorVersion;
  107. UINT16 HotfixVersion;
  108. UINT16 BuildVersion;
  109. UINT32 SecureVersionNumber;
  110. } SessmgrFwVer;
  111. // length includes the size of the header also.
  112. typedef struct _SIGMA_VLR_HEADER
  113. {
  114. UINT8 ID;
  115. // payload following the Sigma VLR are DWORD aligned. PaddedBytes can be 0, 1, 2 or 3 based on how many bytes were padded to make the structure DWORD aligned.
  116. UINT8 PaddedBytes;
  117. // Length includes the size of the VLR header.
  118. UINT16 Length;
  119. } SIGMA_VLR_HEADER;
  120. // All variable and optional field in Sigma messages will use a VLR format
  121. // To simplify the FW code, the length of VLR data should be DWORD aligned. The data will be padded with 0’s at the end to make the VLR’s data DWORD aligned.
  122. // Supported VLR IDs in the Sigma message
  123. #define X509_GROUP_CERTIFICATE_VLR_ID 30
  124. #define VERIFIER_CERTIFICATE_CHAIN_VLR_ID 31
  125. #define SIGNATURE_REVOCATION_LIST_VLR_ID 32
  126. #define OCSP_RESPONSE_VLR_ID 33
  127. #define EPID_SIGNATURE_VLR_ID 34
  128. #define NRPROOFS_VLR_ID 35
  129. // length field in Sigma VLR include the size of the header also. This Macro can be used to get the size of the payload alone. Just to reduce clutter in the code.
  130. #define VLR_UNPADDED_PAYLOAD_SIZE(VlrHdr) (VlrHdr.Length - VlrHdr.PaddedBytes - sizeof(SIGMA_VLR_HEADER))
  131. // Total bytes required for creating a VLR for Data of x bytes
  132. #define TOTAL_VLR_SIZE(x) (sizeof(SIGMA_VLR_HEADER) + NEXT_DWORD_BOUNDARY(x))
  133. typedef struct _X509_GROUP_CERTIFICATE_VLR
  134. {
  135. SIGMA_VLR_HEADER VlrHeader;
  136. UINT8 X509GroupCertData[0];
  137. } X509_GROUP_CERTIFICATE_VLR;
  138. typedef struct _VERIFIER_CERT_CHAIN_VLR
  139. {
  140. SIGMA_VLR_HEADER VlrHeader;
  141. UINT8 VerifierCertificateChain[0];
  142. } VERIFIER_CERT_CHAIN_VLR;
  143. typedef struct _SIGNATURE_REV_LIST_VLR
  144. {
  145. SIGMA_VLR_HEADER VlrHeader;
  146. UINT8 SigRl[0];
  147. }SIGNATURE_REV_LIST_VLR;
  148. typedef struct _OCSP_RESPONSE_VLR
  149. {
  150. SIGMA_VLR_HEADER VlrHeader;
  151. UINT8 OcspResponse[0];
  152. }OCSP_RESPONSE_VLR;
  153. typedef struct _EPID_SIGNATURE_VLR
  154. {
  155. SIGMA_VLR_HEADER VlrHeader;
  156. UINT8 EpidSig[0];
  157. }EPID_SIGNATURE_VLR;
  158. #define NONCE_LENGTH 32
  159. // OCSP Request Info
  160. typedef struct _OCSPRequestInfo
  161. {
  162. char *urlOcspResponder; // OCSP Responder URL
  163. char *certName; // Verifier Certificate Name
  164. char *issuerName; // Verifier Issuer Certificate Name
  165. //char *ocspResponderCertName; // OCSP Responder Certificate Name to verify OCSP response
  166. unsigned char ocspNonce[NONCE_LENGTH];
  167. } OCSPRequestInfo;
  168. #pragma pack()
  169. #endif