type_length_value.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. /**
  32. * File: type_length_value.h
  33. * Description: Header file for data structure and macro definition of the TLV, the type length value encoding format of Provision Message
  34. *
  35. * Unaligned data will be used and for TLV, no data structure but some macros to extract information from TLV(due to var size of some fields)
  36. * A tlv_info_t structure is defined for decoded TLV header information
  37. * special macro to begin with upper case letter and end with lower case letter to indicate it will extract one field from the msg, such as
  38. * EPID_GID_TLV_gid
  39. * to extract the gid field from and EPID_GID_TLV
  40. *
  41. *To encoding TLV:
  42. * i) declare array of tlv_info_t and filling type/version/size of each TLV
  43. * ii) call get_tlv_msg_size to calculate size of encoded buffer
  44. * iii) prepare the output buffer in tlv_msg_t (set both msg_buf and msg_size)
  45. * iv) call tlv_msg_init to initialize tlv headers of all sub-tlv
  46. * v) use function like cipher_text_tlv_get_encrypted_text(...) to get pointer to each payload component
  47. * vi) copy correspondent data into each payload
  48. *To decoding TLV:
  49. * i) initialize tlv_msg_t to input buffer (msg_buf and msg_size)
  50. * ii) call read_tlv_info to get correpondent tlv_info_t array
  51. * iii) use function like cipher_text_tlv_get_encrypted_text(...) to get pointer to each payload component
  52. * or access size field of tlv_info_t directly to get size of payload
  53. *Usually, there're multiple level of TLVs. To save memory which is critical inside enclave
  54. * we need reuse the memory buffer for all levels of TLV.
  55. * So in encoding TLV, we need
  56. * go through step i) and ii) from inner-most level TLV to out-most level of TLV to define
  57. * tlv_info_t of all level of TLVs and get msg size for them
  58. * Usually, the tlv_info_t of outer level is dependent on size of inner level
  59. * After that, we could prepare the output buffer which is step iii) according to size of outmost level TLVs
  60. * call tlv_msg_init to initialize TLV headers and get start address of payload (where inner TLV will share the memory)
  61. * from outmost level to innermost level which is step iv) and v)
  62. * Now we could copy-in correpondent data from innermost level to outermost level and do correpondent encryption if required
  63. * inplace encryption function provided so that no new memory required
  64. * In decoding TLV, it is simpler, just decode from outmost-level to innermost-level and do decryption if required
  65. */
  66. #ifndef _PVE_TLV_H
  67. #define _PVE_TLV_H
  68. #include "epid_types.h"
  69. #include "sgx_urts.h"
  70. #include <string.h>
  71. #include <stdlib.h>
  72. #include <assert.h>
  73. #include "oal/oal.h"
  74. #include "tlv_common.h"
  75. #include "se_sig_rl.h"
  76. #include "pce_cert.h"
  77. #include "sgx_report.h"
  78. #define FOUR_BYTES_SIZE_TYPE 128 /*mask used in type of TLV to indicate that 'size' field uses 4 bytes*/
  79. #ifndef UINT16_MAX
  80. #define UINT16_MAX 0xFFFF
  81. #endif
  82. #ifndef UINT32_MAX
  83. #define UINT32_MAX 0xFFFFFFFFU
  84. #endif
  85. #define IS_FOUR_BYTES_SIZE_TYPE(x) (((x)&FOUR_BYTES_SIZE_TYPE)!=0)
  86. #define GET_TLV_TYPE(x) ((uint8_t)((x)&~FOUR_BYTES_SIZE_TYPE))
  87. typedef enum _tlv_status_t {
  88. TLV_SUCCESS=0,
  89. TLV_OUT_OF_MEMORY_ERROR=1,
  90. TLV_INVALID_PARAMETER_ERROR,
  91. TLV_INVALID_MSG_ERROR,
  92. TLV_UNKNOWN_ERROR,
  93. TLV_MORE_TLVS, /*There're more TLVs in the encoded buffer than user's expectation*/
  94. TLV_INSUFFICIENT_MEMORY, /*There'ld be more data in the TLV buffer according to the partially decoded data*/
  95. TLV_INVALID_FORMAT, /*Invalid data format in the TLV buffer to be decoded*/
  96. TLV_UNSUPPORTED /*the feature has not been supported such as version is later than supported version*/
  97. }tlv_status_t;
  98. /*usually, we could initialize header_size by UNKOWN_TLV_HEADER_SIZE
  99. * but sometimes, we could initialize it by LARGE_TLV_HEADER_SIZE if we want to always use 4 bytes for size even though it is small such as in EPIDSignature TLV
  100. */
  101. #define UNKNOWN_TLV_HEADER_SIZE 0
  102. #define TLV_HEADER_SIZE_OFFSET 2
  103. #define SMALL_TLV_HEADER_SIZE 4
  104. #define LARGE_TLV_HEADER_SIZE 6
  105. #define MAX_TLV_HEADER_SIZE 6 /*an upper bound for TLV header size*/
  106. #define SHORT_TLV_MAX_SIZE UINT16_MAX
  107. /*It defines a TLV information
  108. *All those information is encoded inside a TLV but not in this structure
  109. */
  110. typedef struct _tlv_info_t{
  111. uint8_t type; /*type of tlv must be between 0 and 127 before encoding*/
  112. uint8_t version;
  113. uint16_t header_size; /*header_size used to easy query begin and end address of TLV*/
  114. uint32_t size; /*2 or 4 bytes size after encoding but always 4 bytes in this structure*/
  115. uint8_t *payload; /*pointer to payload of the TLV*/
  116. }tlv_info_t;
  117. typedef struct _tlv_msg_t{
  118. uint8_t *msg_buf;
  119. uint32_t msg_size;
  120. }tlv_msg_t;
  121. #define SIGRL_CERT_PREFIX_SIZE (sizeof(se_sig_rl_t)-sizeof(SigRL)) /*size for version and type*/
  122. #define SIGRL_CERT_HEADER_SIZE (sizeof(se_sig_rl_t)-sizeof(SigRLEntry))
  123. #define SIGRL_CERT_SIZE(sigrl_count) (sizeof(se_sig_rl_t)+((sigrl_count)-1)*sizeof(SigRLEntry)+2*SE_ECDSA_SIGN_SIZE)
  124. #define EPID_SIGNATURE_HEADER_SIZE (sizeof(EPIDSignature)-sizeof(NRProof))
  125. #define EPID_SIGNATURE_SIZE(sign_count) (sizeof(EPIDSignature)+((sign_count)-1)*sizeof(NRProof))
  126. /*Function to decode a buffer which contains a list of TLV containers
  127. *msg.msg_buf: pointer to the start address of the buffer
  128. *msg.msg_size: number of bytes of the buffer
  129. *tlvs_count: input/output parameter, the input *tlvs_count gives size of array infos and offsets
  130. * when the function return successful (TLV_SUCCESS) or there're too many TLVs (TLV_MORE_TLVS),
  131. * the output of *tlvs_count returns the number of TLVs in the msg
  132. *infos: output parameter, infos[i] gives the decoded TLV structure information of the i'th TLV in the msg
  133. *return: TLV_SUCCESS on success or other value to indicate error
  134. */
  135. tlv_status_t read_tlv_infos(const tlv_msg_t& msg, uint32_t *tlvs_count, tlv_info_t infos[]);
  136. /*Function to return the header size in encoded TLV buffer*/
  137. uint32_t get_tlv_header_size(const tlv_info_t *info);
  138. /*Function to return the estimated upper bound of length of TLV in bytes given length in bytes of payload.
  139. * Currently, it returns the exact value for TLV encoding, it should not be used for TLV decoding
  140. *return 0 if there's any error
  141. */
  142. inline static uint32_t get_tlv_total_size(size_t payload_size)
  143. {
  144. if(payload_size>UINT16_MAX){ /*6 bytes TLV header*/
  145. if(payload_size>UINT32_MAX-LARGE_TLV_HEADER_SIZE)/*overflow of uint32_t, return 0 to indicate error*/
  146. return 0;
  147. return static_cast<uint32_t>(payload_size+LARGE_TLV_HEADER_SIZE);
  148. }else{
  149. return static_cast<uint32_t>(payload_size+SMALL_TLV_HEADER_SIZE);/*4 bytes TLV header*/
  150. }
  151. }
  152. /*Function to return number in bytes of a msg with some encoded TLVs
  153. *tlvs_count gives number of TLVs in the msg and infos[i] gives info of the i'th TLV
  154. */
  155. uint32_t get_tlv_msg_size(uint32_t tlvs_count, const tlv_info_t infos[]);
  156. /*Function to initialize a msg of some encoded TLVs
  157. *Before calling the function, all fields except payload of infos[.] has been initialized
  158. *After calling to the function, the TLV header of all TLVs will be fill in and payload of info[.] will be initialized
  159. *After calling to the function, we could use payload field
  160. *tlvs_count: input parameter gives number of TLV in the msg
  161. *infos: input parameter where infos[i] is the tlv structure information of the i'th TLV
  162. *tlv_msg.msg_buf: the msg buffer to be initialized
  163. *tlv_msg.msg_size: input parameter gives the size of the msg buffer, it must be result of function get_tlv_msg_count(tlvs_count, infos);
  164. *The function return TLV_SUCCESS on success and other to indicate any error
  165. */
  166. tlv_status_t tlv_msg_init(uint32_t tlvs_count, tlv_info_t infos[], const tlv_msg_t& tlv_msg);
  167. /*Function used to initialize msg header only without checking payload size
  168. *The function will return size in bytes of the header to be filled
  169. * the payload field will be set but payload size not checked
  170. *msg: The buffer to fill
  171. *info: the tlv_info of the TLV
  172. */
  173. uint32_t tlv_msg_init_one_header(uint8_t msg[MAX_TLV_HEADER_SIZE], tlv_info_t& info);
  174. /*Macro used to crach tlv structure, the pointer type of payload must be uint8_t *
  175. *The alignment of all types used inside payload should be 1 (which means no alignment)
  176. *cipher text TLV
  177. */
  178. #define CIPHER_TEXT_TLV_PAYLOAD_SIZE(text_size) ((text_size)+1) /*size of payload*/
  179. #define CIPHER_TEXT_TLV_SIZE(text_size) get_tlv_total_size(CIPHER_TEXT_TLV_PAYLOAD_SIZE(text_size)) /*size of TLV*/
  180. uint8_t *cipher_text_tlv_get_key_id(const tlv_info_t& info); /*given tlv_info_t, return pointer to key_id*/
  181. tlv_msg_t cipher_text_tlv_get_encrypted_text(const tlv_info_t& info); /*given tlv_info_t return tlv_msg for encrypted text so that we could restart decode*/
  182. /*block cipher text TLV*/
  183. #define BLOCK_CIPHER_TEXT_TLV_PAYLOAD_SIZE(text_size) ((text_size)+IV_SIZE) /*size of payload*/
  184. #define BLOCK_CIPHER_TEXT_TLV_SIZE(text_size) get_tlv_total_size(BLOCK_CIPHER_TEXT_TLV_PAYLOAD_SIZE(text_size)) /*size of TLV*/
  185. struct _tlv_iv_t;/*an incomplete type for iv only*/
  186. typedef struct _tlv_iv_t tlv_iv_t;
  187. tlv_iv_t *block_cipher_tlv_get_iv(const tlv_info_t& info);
  188. tlv_msg_t block_cipher_tlv_get_encrypted_text(const tlv_info_t& info);
  189. #define BLOCK_CIPHER_TEXT_SIZE_FROM_PAYLOAD_SIZE(psize) ((psize)-IV_SIZE)
  190. /*block cipher info TLV*/
  191. #define BLOCK_CIPHER_INFO_TLV_PAYLOAD_SIZE() SK_SIZE /*size of payload*/
  192. #define BLOCK_CIPHER_INFO_TLV_SIZE() get_tlv_total_size(BLOCK_CIPHER_INFO_TLV_PAYLOAD_SIZE())
  193. struct _tlv_sk_t; /*an incomplete type for SK only*/
  194. typedef struct _tlv_sk_t tlv_sk_t;
  195. tlv_sk_t *block_cipher_info_tlv_get_sk(const tlv_info_t& info);
  196. /*message authentication code TLV*/
  197. #define MAC_TLV_PAYLOAD_SIZE(mac_size) (mac_size)
  198. #define MAC_TLV_SIZE(mac_size) get_tlv_total_size(MAC_TLV_PAYLOAD_SIZE(mac_size))
  199. struct _tlv_mac_t; /*an incomplete type for MAC only*/
  200. typedef struct _tlv_mac_t tlv_mac_t;
  201. tlv_mac_t *mac_tlv_get_mac(const tlv_info_t& info);
  202. /*NONCE TLV*/
  203. #define NONCE_TLV_PAYLOAD_SIZE(nonce_size) (nonce_size)
  204. #define NONCE_TLV_SIZE(nonce_size) get_tlv_total_size(NONCE_TLV_PAYLOAD_SIZE(nonce_size))
  205. struct _tlv_nonce_t;
  206. typedef struct _tlv_nonce_t tlv_nonce_t;
  207. tlv_nonce_t *nonce_tlv_get_nonce(const tlv_info_t& info);
  208. /*EPID GID TLV*/
  209. #define EPID_GID_TLV_PAYLOAD_SIZE() (sizeof(GroupID))
  210. #define EPID_GID_TLV_SIZE() get_tlv_total_size(EPID_GID_TLV_PAYLOAD_SIZE())
  211. struct _tlv_gid_t; /*an incomplete type for GID only*/
  212. typedef struct _tlv_gid_t tlv_gid_t;
  213. tlv_sk_t *epid_gid_tlv_get_gid(const tlv_info_t& info);
  214. /*EPID SigRL TLV*/
  215. #define EPID_SIGRL_TLV_PAYLOAD_SIZE(sigrl_count) (sizeof(se_sig_rl_t)+sizeof(SigRLEntry)*(sigrl_count)-sizeof(SigRLEntry)+ECDSA_SIGN_SIZE*2)
  216. #define EPID_SIGRL_TLV_SIZE(sigrl_count) (sigrl_count>0?get_tlv_total_size(EPID_SIGRL_TLV_PAYLOAD_SIZE(sigrl_count)):0)
  217. /*EPID SigRL PSVN TLV*/
  218. #define EPID_SIGRL_PSVN_TLV_PAYLOAD_SIZE() (sizeof(psvn_t))
  219. #define EPID_SIGRL_PSVN_TLV_SIZE() get_tlv_total_size(EPID_SIGRL_PSVN_TLV_PAYLOAD_SIZE())
  220. psvn_t *epid_sigrl_psvn_tlv_get_psvn(const tlv_info_t& info);
  221. /*EPID group certificate TLV*/
  222. #define EPID_GROUP_CERT_TLV_PAYLOAD_SIZE() (sizeof(signed_epid_group_cert_t))
  223. #define EPID_GROUP_CERT_TLV_SIZE() get_tlv_total_size(EPID_GROUP_CERT_TLV_PAYLOAD_SIZE())
  224. /*Device ID TLV*/
  225. #define DEVICE_ID_TLV_PAYLOAD_SIZE() (sizeof(ppid_t)+sizeof(fmsp_t)+sizeof(psvn_t))
  226. #define DEVICE_ID_TLV_SIZE() get_tlv_total_size(DEVICE_ID_TLV_PAYLOAD_SIZE())
  227. ppid_t *device_id_tlv_get_ppid(const tlv_info_t& info);
  228. /*PPID TLV*/
  229. #define PPID_TLV_PAYLOAD_SIZE() (sizeof(ppid_t))
  230. #define PPID_TLV_SIZE() get_tlv_total_size(PPID_TLV_PAYLOAD_SIZE())
  231. /*PWK2 TLV*/
  232. #define PWK2_TLV_PAYLOAD_SIZE() (SK_SIZE)
  233. #define PWK2_TLV_SIZE() get_tlv_total_size(PWK2_TLV_PAYLOAD_SIZE())
  234. /*PlatfromInfo TLV*/
  235. #define PLATFORM_INFO_TLV_PAYLOAD_SIZE() (sizeof(bk_platform_info_t))
  236. #define PLATFORM_INFO_TLV_SIZE() get_tlv_total_size(PLATFORM_INFO_TLV_PAYLOAD_SIZE())
  237. fmsp_t *platform_info_tlv_get_fmsp(const tlv_info_t& info);
  238. psvn_t *platform_info_tlv_get_psvn(const tlv_info_t& info);
  239. /*SE_REPORT_TLV*/
  240. #define SE_REPORT_TLV_PAYLOAD_SIZE() (sizeof(sgx_report_body_t)+2*ECDSA_SIGN_SIZE)
  241. #define SE_REPORT_TLV_SIZE() (LARGE_TLV_HEADER_SIZE+SE_REPORT_TLV_PAYLOAD_SIZE())
  242. /*PSID TLV*/
  243. #define PSID_TLV_PAYLOAD_SIZE() (sizeof(psid_t))
  244. #define PSID_TLV_SIZE() get_tlv_total_size(PSID_TLV_PAYLOAD_SIZE())
  245. psid_t *psid_tlv_get_psid(const tlv_info_t& info);
  246. /*Join Proof TLV*/
  247. #define EPID_JOIN_PROOF_TLV_PAYLOAD_SIZE() (JOIN_PROOF_SIZE+BLIND_ESCROW_SIZE)
  248. #define EPID_JOIN_PROOF_TLV_SIZE() get_tlv_total_size(EPID_JOIN_PROOF_TLV_PAYLOAD_SIZE())
  249. /*EPID Signature TLV*/
  250. #define EPID_SIGNATURE_TLV_PAYLOAD_SIZE(sign_count) (sizeof(EPIDSignature)+sizeof(NRProof)*(sign_count)-sizeof(NRProof))
  251. #define EPID_SIGNATURE_TLV_SIZE(sign_count) (LARGE_TLV_HEADER_SIZE+EPID_SIGNATURE_TLV_PAYLOAD_SIZE(sign_count)) /*always use large header size for Signature TLV*/
  252. /*EPID Membership Credential TLV*/
  253. #define MEMBERSHIP_CREDENTIAL_TLV_PAYLOAD_SIZE() (sizeof(membership_credential_with_escrow_t))
  254. #define MEMBERSHIP_CREDENTIAL_TLV_SIZE() get_tlv_total_size(MEMBERSHIP_CREDENTIAL_TLV_PAYLOAD_SIZE())
  255. PElemStr *membership_credential_tlv_get_x(const tlv_info_t& info);
  256. G1ElemStr *membership_credential_tlv_get_A(const tlv_info_t& info);
  257. /*FLAGS TLV*/
  258. #define FLAGS_TLV_PAYLOAD_SIZE() FLAGS_SIZE
  259. #define FLAGS_TLV_SIZE() get_tlv_total_size(FLAGS_TLV_PAYLOAD_SIZE())
  260. #define ES_SELECTOR_TLV_PAYLOAD_SIZE() 2
  261. #define ES_SELECTOR_TLV_SIZE() get_tlv_total_size(ES_SELECTOR_TLV_PAYLOAD_SIZE())
  262. uint8_t *es_selector_tlv_get_es_type(const tlv_info_t& info);
  263. uint8_t *es_selector_tlv_get_selector_id(const tlv_info_t& info);
  264. #define PCE_CERT_TLV_PAYLOAD_SIZE() sizeof(pce_tcb_cert_t)
  265. #define PCE_CERT_TLV_SIZE() get_tlv_total_size(PCE_CERT_TLV_PAYLOAD_SIZE())
  266. #define PCE_SIGNATURE_TLV_PAYLOAD_SIZE() (2*SE_ECDSA_SIGN_SIZE+sizeof(sgx_report_t))
  267. #define PCE_SIGNATURE_TLV_SIZE() get_tlv_total_size(PCE_SIGNATURE_TLV_PAYLOAD_SIZE())
  268. class TLVsMsg{
  269. uint32_t num_infos;
  270. tlv_info_t* infos;
  271. tlv_msg_t msg;
  272. CLASS_UNCOPYABLE(TLVsMsg)
  273. protected:
  274. void clear(){
  275. if(msg.msg_buf!=NULL){free(msg.msg_buf);msg.msg_buf=NULL;msg.msg_size=0;}
  276. if(infos!=NULL){free(infos);infos=NULL;num_infos=0;}
  277. }
  278. tlv_status_t alloc_more_buffer(uint32_t buffer, tlv_msg_t& new_buf);
  279. tlv_status_t create_new_info(tlv_info_t *& new_info){
  280. if(num_infos==0){
  281. assert(infos==NULL);
  282. infos = (tlv_info_t *)malloc(sizeof(tlv_info_t));
  283. if(infos==NULL) return TLV_OUT_OF_MEMORY_ERROR;
  284. num_infos=1;
  285. new_info = infos;
  286. }else{
  287. tlv_info_t * p = (tlv_info_t *)malloc(sizeof(tlv_info_t)*(num_infos+1));
  288. if(p==NULL){
  289. return TLV_OUT_OF_MEMORY_ERROR;
  290. }
  291. memcpy(p, infos, sizeof(tlv_info_t)*num_infos);
  292. free(infos);
  293. infos = p;
  294. new_info = infos + (num_infos);
  295. num_infos ++;
  296. }
  297. return TLV_SUCCESS;
  298. }
  299. public:
  300. TLVsMsg(){
  301. num_infos = 0;
  302. infos = NULL;
  303. msg.msg_size = 0;
  304. msg.msg_buf = NULL;
  305. }
  306. ~TLVsMsg(){
  307. clear();
  308. }
  309. tlv_status_t init_from_buffer(const uint8_t *msg, uint32_t msg_size);
  310. tlv_status_t init_from_tlv_msg(const tlv_msg_t& tlv_msg);
  311. uint32_t get_tlv_count()const{return num_infos;}
  312. tlv_info_t& operator[](uint32_t x){
  313. assert(x<num_infos&&infos!=NULL);
  314. return infos[x];
  315. }
  316. const tlv_info_t& operator[](uint32_t x)const{
  317. assert(x<num_infos&&infos!=NULL);
  318. return infos[x];
  319. }
  320. uint32_t get_tlv_msg_size()const{return msg.msg_size;}
  321. const uint8_t *get_tlv_msg()const{return msg.msg_buf;}
  322. /*Functions to add different types of TLV into the TLVsMsg*/
  323. tlv_status_t add_cipher_text(const uint8_t *text, uint32_t len, uint8_t key_id);
  324. tlv_status_t add_block_cipher_text(const uint8_t iv[IV_SIZE],const uint8_t *text, uint32_t len);
  325. tlv_status_t add_block_cipher_info(const uint8_t sk[SK_SIZE]);
  326. tlv_status_t add_mac(const uint8_t mac[MAC_SIZE]);
  327. tlv_status_t add_nonce(const uint8_t *nonce, uint32_t nonce_size);
  328. tlv_status_t add_epid_gid(const GroupID& gid);
  329. tlv_status_t add_platform_info(const bk_platform_info_t& pi);
  330. tlv_status_t add_pce_report_sign(const sgx_report_body_t& report, const uint8_t ecdsa_sign[64]);
  331. tlv_status_t add_psid(const psid_t *psid);
  332. tlv_status_t add_flags(const flags_t *flags);
  333. tlv_status_t add_es_selector(uint8_t protocol, uint8_t selector_id);
  334. tlv_status_t add_quote(const uint8_t *quote_data, uint32_t quote_size);
  335. tlv_status_t add_quote_signature(const uint8_t *quote_signature, uint32_t sign_size);
  336. tlv_status_t add_x509_csr(const uint8_t *csr_data, uint32_t csr_size);
  337. };
  338. #endif