type_length_value.h 19 KB

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