Browse Source

Initial working local attestation commit with the sdk library - version 2.1

dettanym 5 years ago
commit
812ae31801

+ 807 - 0
App/App.cpp

@@ -0,0 +1,807 @@
+/*
+ * Copyright (C) 2011-2017 Intel Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *   * Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   * Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in
+ *     the documentation and/or other materials provided with the
+ *     distribution.
+ *   * Neither the name of Intel Corporation nor the names of its
+ *     contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.challa
+ *
+ */
+
+#define SGX_DH_MAC_SIZE 16
+#define SGX_TARGET_INFO_RESERVED1_BYTES 4
+#define SGX_TARGET_INFO_RESERVED2_BYTES 456
+#define SGX_ECP256_KEY_SIZE 32
+#define SGX_CPUSVN_SIZE 16
+#define SGX_REPORT_DATA_SIZE 64
+#define SGX_MAC_SIZE 16 /* Message Authentication Code - 16 bytes */
+#define SGX_KEYID_SIZE 32
+#define SGX_HASH_SIZE 32 /* SHA256 */
+
+#define SGX_REPORT_BODY_RESERVED1 28
+#define SGX_REPORT_BODY_RESERVED2 32
+#define SGX_REPORT_BODY_RESERVED3 96
+#define SGX_REPORT_BODY_RESERVED4 60
+
+// App.cpp : Defines the entry point for the console application.
+#include <stdio.h>
+#include <map>
+#include "../Decryptor/Decryptor_u.h"
+#include "sgx_eid.h"
+#include "sgx_urts.h"
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
+#include<unistd.h>
+// for sealing - sgx_calc_sealed_data_size
+#include "sgx_tseal.h"
+
+// For socket programming
+#include <sys/socket.h>
+#include <stdlib.h>
+#include <netinet/in.h>
+#include <string.h>
+#include <errno.h>
+#include<unistd.h>
+
+// For reading from/writing to file -sealing.
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+// For google proto buffers
+#include "dhmsgs.pb.h"
+#include <inttypes.h>
+#include <google/protobuf/io/coded_stream.h>
+#include <google/protobuf/io/zero_copy_stream_impl.h>
+#include "SgxProtobufLATransforms_initiator.h"
+using namespace google::protobuf::io;
+
+
+
+//#define UNUSED(val) (void)(val)
+#define TCHAR   char
+#define _TCHAR  char
+#define _T(str) str
+#define scanf_s scanf
+
+// Not sure if I need this later - as such, I (decryptor app) will only ever need to talk to 1 enclave at a time - verifier enclave first and then the apache enclave.
+//extern std::map<sgx_enclave_id_t, uint32_t>g_enclave_id_map;
+
+sgx_enclave_id_t e2_enclave_id = 0;
+#define Decryptor_PATH "libDecryptor.so"
+////////////////////////////////////////////////// 
+
+
+
+
+// For google proto buffers
+#include "dhmsgs.pb.h"
+#include <inttypes.h>
+#include <google/protobuf/io/coded_stream.h>
+#include <google/protobuf/io/zero_copy_stream_impl.h>
+using namespace google::protobuf::io;
+#include <stdio.h>
+//#include "sgx_eid.h"
+//#include "sgx_urts.h"
+
+
+
+int fit_32_into_uint8_t(google::protobuf::uint32 temp32, uint8_t* temp8)
+{
+ if(temp32 > UINT8_MAX)
+	 return -1;
+ else
+ {
+	 //		 *temp8 = *(uint8_t*)&temp32; // Probably works irrespective of endianness but not sure.
+	 *temp8 = (uint8_t)temp32;
+	 return 0;
+ }
+}
+
+int fit_32_into_uint16_t(google::protobuf::uint32 temp32, uint16_t* temp16)
+{
+ if(temp32 > UINT16_MAX)
+	 return -1;
+ else
+ {
+	 //		 *temp8 = *(uint8_t*)&temp32; // Probably works irrespective of endianness but not sure.
+	 *temp16 = (uint16_t)temp32;
+	 return 0;
+ }
+}
+
+void encode_ec256_public_key_to_protobuf(protobuf_sgx_ec256_public_t* protobuf_g_a , sgx_ec256_public_t* g_a)
+{
+	int counter; google::protobuf::uint32 temp32;
+	for(counter=0;counter<SGX_ECP256_KEY_SIZE;counter++)
+	{
+		temp32 = g_a->gx[counter];
+		protobuf_g_a->add_gx(temp32);
+		temp32 = g_a->gy[counter];
+		protobuf_g_a->add_gy(temp32);
+	}
+}
+
+int decode_ec256_public_key_from_protobuf(protobuf_sgx_ec256_public_t* protobuf_g_a , sgx_ec256_public_t* g_a)
+{
+  printf("\n ec256 pub key\n");
+	int counter; google::protobuf::uint32 temp32;
+	for(counter=0;counter<SGX_ECP256_KEY_SIZE;counter++)
+	{
+		temp32 = protobuf_g_a->gx(counter);
+		if(fit_32_into_uint8_t(temp32, &(g_a->gx[counter]))!=0)
+		 return -1;
+    printf("%d ",g_a->gx[counter]);
+		temp32 = protobuf_g_a->gy(counter);
+		if(fit_32_into_uint8_t(temp32, &(g_a->gy[counter]))!=0)
+		 return -1;
+    printf("%d ",g_a->gy[counter]);
+	}
+  return 0;
+}
+
+void encode_attributes_to_protobuf(protobuf_sgx_attributes_t* protobuf_attributes, sgx_attributes_t* attributes)
+{
+	protobuf_attributes->set_flags(attributes->flags); // 64 bit
+	protobuf_attributes->set_xfrm(attributes->xfrm); // 64 bit
+}
+
+int decode_attributes_from_protobuf(protobuf_sgx_attributes_t* protobuf_attributes, sgx_attributes_t* attributes)
+{
+	attributes->flags = protobuf_attributes->flags();
+  printf("\n flags %" PRIu64 " \n", attributes->flags);
+	attributes->xfrm = protobuf_attributes->xfrm();
+  printf("\n xfrm %" PRIu64 " \n", attributes->xfrm);
+	return 0;
+}
+
+void encode_report_to_protobuf(protobuf_sgx_report_t* protobuf_report, sgx_report_t* report)
+{
+	int counter; google::protobuf::uint32 temp32;
+	for(counter=0;counter<SGX_KEYID_SIZE;counter++)
+	{
+		temp32=report->key_id.id[counter];
+		protobuf_report->add_key_id(temp32);
+	}
+
+	for(counter=0;counter<SGX_MAC_SIZE;counter++)
+	{
+		temp32=report->mac[counter];
+		protobuf_report->add_mac(temp32);
+	}
+
+	protobuf_report->mutable_body()->set_misc_select(report->body.misc_select); // 32 bit
+	protobuf_report->mutable_body()->set_isv_svn(report->body.isv_svn); // 16 bit
+	protobuf_report->mutable_body()->set_isv_prod_id(report->body.isv_prod_id); // 16 bit
+	encode_attributes_to_protobuf(protobuf_report->mutable_body()->mutable_attributes(), &(report->body.attributes));
+
+	for(counter=0;counter<SGX_CPUSVN_SIZE;counter++)
+	{
+		temp32=report->body.cpu_svn.svn[counter];
+		protobuf_report->mutable_body()->add_cpu_svn(temp32);
+	}
+
+	for(counter=0;counter<SGX_REPORT_BODY_RESERVED1;counter++)
+	{
+		temp32=report->body.reserved1[counter]; // TODO: Could be optimized out - if these are determined to be 0s.
+		protobuf_report->mutable_body()->add_reserved1(temp32);
+ 	}
+
+	for(counter=0;counter<SGX_REPORT_BODY_RESERVED2;counter++)
+	{
+		temp32=report->body.reserved2[counter]; // TODO: Could be optimized out - if these are determined to be 0s.
+		protobuf_report->mutable_body()->add_reserved2(temp32);
+	}
+
+	for(counter=0;counter<SGX_REPORT_BODY_RESERVED3;counter++)
+	{
+		temp32=report->body.reserved3[counter]; // TODO: Could be optimized out - if these are determined to be 0s.
+		protobuf_report->mutable_body()->add_reserved3(temp32);
+ 	}
+
+	for(counter=0;counter<SGX_REPORT_BODY_RESERVED4;counter++)
+	{
+		temp32=report->body.reserved4[counter]; // TODO: Could be optimized out - if these are determined to be 0s.
+		protobuf_report->mutable_body()->add_reserved4(temp32);
+ 	}
+
+	for(counter=0;counter<SGX_HASH_SIZE;counter++)
+	{
+		temp32=report->body.mr_enclave.m[counter];
+		protobuf_report->mutable_body()->add_mr_enclave(temp32);
+ 	}
+
+	for(counter=0;counter<SGX_HASH_SIZE;counter++)
+	{
+		temp32=report->body.mr_signer.m[counter];
+		protobuf_report->mutable_body()->add_mr_signer(temp32);
+ 	}
+
+	for(counter=0;counter<SGX_REPORT_DATA_SIZE;counter++)
+	{
+		temp32=report->body.report_data.d[counter];
+		protobuf_report->mutable_body()->add_report_data(temp32);
+ 	}
+}
+
+int decode_report_from_protobuf(protobuf_sgx_report_t* protobuf_report, sgx_report_t* report)
+{
+  int counter; google::protobuf::uint32 temp32;
+
+  printf("\nreport body keyid\n");
+  for(counter=0;counter<SGX_KEYID_SIZE;counter++)
+  {
+    temp32=protobuf_report->key_id(counter);
+    if(fit_32_into_uint8_t(temp32, &(report->key_id.id[counter]))!=0)
+		  return -1;
+    printf("%d ", report->key_id.id[counter]);
+  }
+
+  printf("\nreport mac\n");
+  for(counter=0;counter<SGX_MAC_SIZE;counter++)
+  {
+    temp32=protobuf_report->mac(counter);
+    if(fit_32_into_uint8_t(temp32, &(report->mac[counter]))!=0)
+      return -1;
+    printf("%d ", report->mac[counter]);
+  }
+
+  report->body.misc_select=protobuf_report->mutable_body()->misc_select(); // 32 bit
+  temp32=protobuf_report->mutable_body()->isv_svn();
+  if(fit_32_into_uint16_t(temp32, &(report->body.isv_svn))!=0)
+   return -1;
+  printf("\nmisc select %d \n", report->body.misc_select);
+
+  temp32=protobuf_report->mutable_body()->isv_prod_id();
+   if(fit_32_into_uint16_t(temp32, &(report->body.isv_prod_id))!=0)
+    return -1;
+  printf("\nprod id %d \n", report->body.isv_prod_id);
+
+  decode_attributes_from_protobuf(protobuf_report->mutable_body()->mutable_attributes(), &(report->body.attributes));
+
+  printf("\n cpu svn\n");
+  for(counter=0;counter<SGX_CPUSVN_SIZE;counter++)
+  {
+    temp32=protobuf_report->mutable_body()->cpu_svn(counter);
+    if(fit_32_into_uint8_t(temp32, &(report->body.cpu_svn.svn[counter]))!=0)
+      return -1;
+    printf("%d ", report->body.cpu_svn.svn[counter]);
+
+  }
+
+  printf("\n reserved1 \n");
+  for(counter=0;counter<SGX_REPORT_BODY_RESERVED1;counter++)
+  {
+    temp32=protobuf_report->mutable_body()->reserved1(counter);
+    if(fit_32_into_uint8_t(temp32, &(report->body.reserved1[counter]))!=0)
+      return -1;
+    printf("%d ", report->body.reserved1[counter]);
+  }
+
+  printf("\n reserved2 \n");
+  for(counter=0;counter<SGX_REPORT_BODY_RESERVED2;counter++)
+  {
+    temp32=protobuf_report->mutable_body()->reserved2(counter);
+    if(fit_32_into_uint8_t(temp32, &(report->body.reserved2[counter]))!=0)
+      return -1;
+    printf("%d ", report->body.reserved2[counter]);
+  }
+
+  printf("\n reserved3 \n");
+  for(counter=0;counter<SGX_REPORT_BODY_RESERVED3;counter++)
+  {
+    temp32=protobuf_report->mutable_body()->reserved3(counter);
+    if(fit_32_into_uint8_t(temp32, &(report->body.reserved3[counter]))!=0)
+      return -1;
+    printf("%d ", report->body.reserved3[counter]);
+  }
+
+  printf("\n reserved4 \n");
+  for(counter=0;counter<SGX_REPORT_BODY_RESERVED4;counter++)
+  {
+    temp32=protobuf_report->mutable_body()->reserved4(counter);
+    if(fit_32_into_uint8_t(temp32, &(report->body.reserved4[counter]))!=0)
+      return -1;
+    printf("%d ", report->body.reserved4[counter]);
+
+  }
+
+  printf("\n mrenclave \n");
+  for(counter=0;counter<SGX_HASH_SIZE;counter++)
+  {
+    temp32=protobuf_report->mutable_body()->mr_enclave(counter);
+    if(fit_32_into_uint8_t(temp32, &(report->body.mr_enclave.m[counter]))!=0)
+      return -1;
+    printf("%x ", report->body.mr_enclave.m[counter]);
+  }
+
+  printf("\n mrsigner \n");
+  for(counter=0;counter<SGX_HASH_SIZE;counter++)
+  {
+    temp32=protobuf_report->mutable_body()->mr_signer(counter);
+    if(fit_32_into_uint8_t(temp32, &(report->body.mr_signer.m[counter]))!=0)
+      return -1;
+    printf("%x ", report->body.mr_signer.m[counter]);
+  }
+
+  printf("\n report data\n");
+  for(counter=0;counter<SGX_REPORT_DATA_SIZE;counter++)
+  {
+    temp32=protobuf_report->mutable_body()->report_data(counter);
+    if(fit_32_into_uint8_t(temp32, &(report->body.report_data.d[counter]))!=0)
+      return -1;
+    printf("%d ", report->body.report_data.d[counter]);
+  }
+	return 0;
+}
+
+void encode_msg1_to_protobuf( protobuf_sgx_dh_msg1_t& protobuf_dhmsg1, sgx_dh_msg1_t* native_dhmsg1)
+{
+   int counter; google::protobuf::uint32 temp32; // google::protobuf::uint64 temp64;
+
+   encode_ec256_public_key_to_protobuf(protobuf_dhmsg1.mutable_g_a(), &(native_dhmsg1->g_a));
+
+   for(counter=0;counter<SGX_HASH_SIZE;counter++)
+   {
+     temp32=native_dhmsg1->target.mr_enclave.m[counter];
+     protobuf_dhmsg1.mutable_target()->add_mr_enclave(temp32);
+   }
+
+   for(counter=0;counter<SGX_TARGET_INFO_RESERVED1_BYTES;counter++)
+   {
+     temp32=native_dhmsg1->target.reserved1[counter];
+     protobuf_dhmsg1.mutable_target()->add_reserved1(temp32);
+   }
+
+   for(counter=0;counter<SGX_TARGET_INFO_RESERVED2_BYTES;counter++)
+   {
+     temp32=native_dhmsg1->target.reserved2[counter];
+     protobuf_dhmsg1.mutable_target()->add_reserved2(temp32);
+   }
+
+   encode_attributes_to_protobuf(protobuf_dhmsg1.mutable_target()->mutable_attributes(), &(native_dhmsg1->target.attributes));
+
+   temp32=native_dhmsg1->target.misc_select ;
+   protobuf_dhmsg1.mutable_target()->set_misc_select(temp32);
+}
+
+void encode_msg3_to_protobuf(protobuf_sgx_dh_msg3_t& protobuf_dhmsg3, sgx_dh_msg3_t* native_dhmsg3)
+{
+  int counter; google::protobuf::uint32 temp32;
+  for(counter=0;counter<SGX_DH_MAC_SIZE;counter++)
+	{
+		temp32=native_dhmsg3->cmac[counter];
+		protobuf_dhmsg3.add_cmac(temp32);
+	}
+
+  encode_report_to_protobuf(protobuf_dhmsg3.mutable_msg3_body()->mutable_report(), &(native_dhmsg3->msg3_body.report));
+  int max_counter=native_dhmsg3->msg3_body.additional_prop_length;
+  unsigned char*temp;
+  for(counter=0,temp=native_dhmsg3->msg3_body.additional_prop;counter<max_counter;counter++,temp++)
+  {
+    protobuf_dhmsg3.mutable_msg3_body()->add_additional_prop(*temp);
+  }
+}
+
+int decode_msg2_from_protobuf(protobuf_sgx_dh_msg2_t& protobuf_dhmsg2, sgx_dh_msg2_t* native_dhmsg2)
+{
+  int counter; google::protobuf::uint32 temp32; //google::protobuf::uint64 temp64;
+  printf("\ncmac\n");
+  for(counter=0;counter<SGX_DH_MAC_SIZE;counter++)
+  {
+    temp32=protobuf_dhmsg2.cmac(counter);
+    if(fit_32_into_uint8_t(temp32, &(native_dhmsg2->cmac[counter]))!=0)
+     return -1;
+    printf("%d ",native_dhmsg2->cmac[counter]);
+  }
+
+  if(decode_ec256_public_key_from_protobuf(protobuf_dhmsg2.mutable_g_b(), &(native_dhmsg2->g_b)) !=0)
+	return -1;
+
+  if(decode_report_from_protobuf(protobuf_dhmsg2.mutable_report(), &(native_dhmsg2->report)) !=0)
+	return -1;
+
+  return 0;
+}
+
+int print_initialized_msg1( protobuf_sgx_dh_msg1_t& protobuf_dhmsg1, sgx_dh_msg1_t* native_dhmsg1)
+{
+   int counter;
+	 printf("gx\n");
+   for(counter=0;counter<SGX_ECP256_KEY_SIZE;counter++)
+   {
+      printf("%d ", protobuf_dhmsg1.g_a().gx(counter));
+      printf("%d ", native_dhmsg1->g_a.gx[counter]);
+   }
+   printf("\ngy\n");
+   for(counter=0;counter<SGX_ECP256_KEY_SIZE;counter++)
+   {
+      printf("%d ", protobuf_dhmsg1.g_a().gy(counter));
+      printf("%d ", native_dhmsg1->g_a.gy[counter]);
+   }
+
+   printf("\nmrenclave in target\n");
+   for(counter=0;counter<SGX_HASH_SIZE;counter++)
+   {
+      printf("%" PRIu32 " ", protobuf_dhmsg1.target().mr_enclave(counter));
+      printf("%d ", native_dhmsg1->target.mr_enclave.m[counter]);
+
+   }
+   printf("\nreserved1 in target\n");
+   for(counter=0;counter<SGX_TARGET_INFO_RESERVED1_BYTES;counter++)
+   {
+      printf("%" PRIu32 " ", protobuf_dhmsg1.target().reserved1(counter));
+      printf("%d ", native_dhmsg1->target.reserved1[counter]);
+
+   }
+   printf("\nreserved2 in target\n");
+   for(counter=0;counter<SGX_TARGET_INFO_RESERVED2_BYTES;counter++)
+   {
+      printf("%" PRIu32 " ", protobuf_dhmsg1.target().reserved2(counter));
+      printf("%d ", native_dhmsg1->target.reserved2[counter]);
+   }
+
+   printf("\n %" PRIu64 "\n", native_dhmsg1->target.attributes.flags);
+   printf("\n %" PRIu64 "\n", protobuf_dhmsg1.target().attributes().flags());
+   printf("\n %" PRIu64 "\n", native_dhmsg1->target.attributes.xfrm);
+   printf("\n %" PRIu64 "\n", protobuf_dhmsg1.target().attributes().xfrm());
+   printf("\n %" PRIu32 "\n", native_dhmsg1->target.misc_select);
+   printf("\n %" PRIu32 "\n", protobuf_dhmsg1.target().misc_select());
+
+	return 0;
+}
+
+int read_protobuf_msg_from_fd(int accept_fd, google::protobuf::MessageLite& message)
+{
+  ZeroCopyInputStream* raw_input;
+  CodedInputStream* coded_input;
+  uint32_t size;
+  CodedInputStream::Limit limit;
+  raw_input = new FileInputStream(accept_fd);
+  coded_input = new CodedInputStream(raw_input);
+  if(!coded_input->ReadVarint32(&size))
+  {
+    printf("Error in reading size of msg");
+    fflush(stdout);
+    return -1;
+  }
+  //printf("size of msg was read to be %" PRIu32 " \n", size);
+  fflush(stdout);
+  limit = coded_input->PushLimit(size);
+  if(!message.ParseFromCodedStream(coded_input))
+  {
+    printf("Error in parsing msg");
+    fflush(stdout);
+    return -1;
+  }
+  coded_input->PopLimit(limit);
+  return 0;
+}
+
+int write_protobuf_msg_to_fd(int accept_fd, google::protobuf::MessageLite& message)
+{
+  ZeroCopyOutputStream* raw_output = new FileOutputStream(accept_fd);
+  CodedOutputStream* coded_output  = new CodedOutputStream(raw_output);
+  coded_output->WriteVarint32(message.ByteSize());
+  if(!message.SerializeToCodedStream(coded_output))
+  {
+    printf("SerializeToCodedStream failed");
+    fflush(stdout);
+    return -1;
+  }
+  // As per this - https://stackoverflow.com/questions/22881876/protocol-buffers-how-to-serialize-and-deserialize-multiple-messages-into-a-file?noredirect=1&lq=1
+  // TODO: There may be a better way to do this - 1) this happens with every accept now and 2) make it happen on the stack vs heap - destructor will be called on return from this function (main) and the items will then be written out. (We probably don't want that, actually)
+  delete coded_output;
+  delete raw_output;
+  fflush(stdout);
+  return 0;
+}
+
+
+
+
+
+
+
+
+
+
+
+///////////// TRY TO INCLUDE RIGHT SGX HEADERS IN SGX_PROTOBUF CPP
+
+
+
+
+
+
+
+
+
+
+
+uint32_t write_to_fd(int fd, uint8_t* msg, uint32_t* expected_msg_length)
+{
+  ssize_t bytes_written; 
+  bytes_written = write(fd, msg, *expected_msg_length);
+  if(bytes_written <= 0)
+    return 0xFFFFFFFF;
+
+  fsync(fd);
+  *expected_msg_length = bytes_written;
+  return 0;
+}
+
+uint32_t read_from_fd(int fd, uint8_t* msg, uint32_t* expected_msg_length)
+{
+  ssize_t bytes_read;
+  lseek(fd, 0, SEEK_SET);
+  bytes_read = read(fd, msg, *expected_msg_length);
+  if(bytes_read <= 0)
+    return 0xFFFFFFFF;
+  return 0;
+}
+
+// Sets up a socket to bind and listen to the given port. Returns FD of the socket on success, -1 on failure (and prints a msg to stdout with the errno)
+int set_up_socket(int port,   sockaddr_in* address)
+{
+  int server_fd = 0;
+
+  // Creating socket file descriptor for listening for attestation requests.
+  server_fd = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
+  if (server_fd == -1)
+  {
+     printf("Error in creating a socket - %d", errno);
+      return -1;
+  }
+
+  // Preparing the address struct for binding
+  address->sin_family = AF_INET;
+  address->sin_addr.s_addr = INADDR_ANY; // Todo: should this be localhost?
+  address->sin_port = htons(port);
+  //  memset(address->sin_zero,0,sizeof(address->sin_zero));
+
+  socklen_t addrlen = sizeof(*address);
+  // Binding
+  if (bind(server_fd, (sockaddr*)address, addrlen)<0)
+  {
+      printf("Error in binding %d - port was %d - ", errno, port);
+      return -1;
+  }
+
+  // Listening
+  if (listen(server_fd, 128) < 0)
+  {
+      printf("Error in listening %d", errno);
+      return -1;
+  }
+
+  return server_fd;
+}
+
+int local_attestation_initiator(__attribute__((unused))   uint8_t* expected_mr_signer)
+{
+  // declare msg1, msg2, msg3 protobuf objects and native SGX structs
+  protobuf_sgx_dh_msg1_t protobuf_msg1;
+  protobuf_sgx_dh_msg2_t protobuf_msg2;
+  protobuf_sgx_dh_msg3_t protobuf_msg3;
+  // For sgx - ecalls and storing msgs rcvd from pipes for processing.
+  uint32_t session_id;
+  sgx_dh_msg1_t dh_msg1;            //Diffie-Hellman Message 1
+  sgx_dh_msg2_t dh_msg2;            //Diffie-Hellman Message 2
+  sgx_dh_msg3_t dh_msg3;            //Diffie-Hellman Message 3
+  sgx_key_128bit_t dh_aek;        // Session Key
+  // initializing native sgx structs
+  memset(&dh_aek,0, sizeof(sgx_key_128bit_t));
+  memset(&dh_msg1, 0, sizeof(sgx_dh_msg1_t));
+  memset(&dh_msg2, 0, sizeof(sgx_dh_msg2_t));
+  memset(&dh_msg3, 0, sizeof(sgx_dh_msg3_t));
+
+  // For socket to listen to the Apache enclave.
+      int apache_port = 3825; int server_fd=0; int accept_fd = 0;
+      struct sockaddr_in own_addr;
+      struct sockaddr_storage apache_addr; socklen_t apache_addr_size = sizeof(apache_addr);
+    //  int counter;
+
+      server_fd=set_up_socket(apache_port, &own_addr);
+      if(server_fd==-1)
+        return -1;
+      printf("Successfully set up a socket to communicate with the Apache enclave.");
+      fflush(stdout);
+
+      uint32_t ret_status;
+      Decryptor_session_request(e2_enclave_id, &ret_status, &dh_msg1, &session_id); // TODO: Check Return status
+      if(ret_status != SGX_SUCCESS) 
+      {
+	printf("session request returned failure\n");  fflush(stdout); return 0xffffffff;
+      }
+      encode_msg1_to_protobuf(protobuf_msg1, &dh_msg1);
+      print_initialized_msg1(protobuf_msg1, &dh_msg1);
+      printf("Done initialization");
+      fflush(stdout);
+
+      int no_of_msgs_xchanged=0;
+      accept_fd = accept(server_fd, (struct sockaddr *)&apache_addr,&apache_addr_size);
+      if (accept_fd <0)
+      {
+        printf("Error in accepting %d", errno);
+        return -1;
+      }
+      do
+      {
+        if(no_of_msgs_xchanged==0){
+          if(write_protobuf_msg_to_fd(accept_fd, protobuf_msg1)!=0)
+  		      return -1;
+        }
+        else
+        {
+          printf("about to read msg2\n");
+  	      fflush(stdout);
+          // read msg2 -
+          if(read_protobuf_msg_from_fd(accept_fd, protobuf_msg2)!=0)
+  		      return -1;
+          if(decode_msg2_from_protobuf(protobuf_msg2, &dh_msg2)!=0)
+  		      return -1;
+          printf("Done reading and decoding msg2\n");
+          // process msg2 and generate msg3
+          Decryptor_exchange_report(e2_enclave_id, &ret_status, &dh_msg2, &dh_msg3, &session_id);
+          if(ret_status!=SGX_SUCCESS)
+  	      {
+            fflush(stdout);
+            printf("exchange report failed:%x\n", ret_status);
+            fflush(stdout);
+            return -1;
+          }
+          printf("return status %d", ret_status);
+          fflush(stdout);
+          // convert msg3 sgx_dh_msg3_t object to a protobuf msg3 object.
+          encode_msg3_to_protobuf(protobuf_msg3, &dh_msg3);
+          printf("about to write msg3\n");
+          fflush(stdout);
+          // write msg3 -
+          if(write_protobuf_msg_to_fd(accept_fd, protobuf_msg3)!=0)
+            return -1;
+          no_of_msgs_xchanged+=1;
+        }
+        no_of_msgs_xchanged++;
+      }
+      while(no_of_msgs_xchanged!=3);
+  	printf("Out of while loop\n");
+  	fflush(stdout);
+	return 0;
+}
+/*
+uint32_t unseal_signing_key_pair_from_disk(int fd, __attribute__((unused))  sgx_ec256_public_t* pub_key, uint32_t* actual_sealed_msg_length)
+{
+  uint32_t ret_status;
+  uint8_t* sgx_sealed_msg;
+  sgx_sealed_msg = (uint8_t*) malloc(*actual_sealed_msg_length);
+  ret_status = read_from_fd(fd, sgx_sealed_msg, actual_sealed_msg_length);
+  if(ret_status != 0)
+  {
+    free(sgx_sealed_msg);
+    return 0xFFFFFFFF;
+  }
+   
+  Decryptor_unseal_and_restore_sealed_signing_key_pair(e2_enclave_id, &ret_status, pub_key, sgx_sealed_msg, actual_sealed_msg_length);
+  free(sgx_sealed_msg);
+  return ret_status;
+}
+
+uint32_t create_and_seal_signing_key_pair_to_disk(int fd, sgx_ec256_public_t* pub_key, uint32_t* actual_sealed_msg_length)
+{
+  uint32_t ret_status;
+  // Generating a signing ECDSA key to sign the encryption key.
+  
+  Decryptor_calculate_sealed_data_size(e2_enclave_id, 3*SGX_ECP256_KEY_SIZE, actual_sealed_msg_length); // sgx_calc_sealed_data_size(0,3*SGX_ECP256_KEY_SIZE);
+  if(*actual_sealed_msg_length == 0xFFFFFFFF)
+    return 0xFFFFFFFF;
+  printf("%x bytes for sealed msg\n", *actual_sealed_msg_length); fflush(stdout); 
+  uint8_t* sealed_data=(uint8_t*) malloc(*actual_sealed_msg_length);
+  printf("Made call to sgx_calc_sealed_data_size\n");  fflush(stdout); 
+  Decryptor_create_and_seal_ecdsa_signing_key_pair(e2_enclave_id, &ret_status, (sgx_ec256_public_t*)pub_key, actual_sealed_msg_length, sealed_data);
+  if(ret_status != SGX_SUCCESS)
+  {
+    printf("create_and_seal called returned an error: %x", ret_status); 
+    free(sealed_data);
+    return 0xFFFFFFFF;
+  }
+  printf("It returned sgx_success\n"); fflush(stdout); 
+  ret_status = write_to_fd(fd, sealed_data, actual_sealed_msg_length);
+  free(sealed_data);
+  return ret_status;
+}
+*/
+int main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[])
+{
+    uint32_t ret_status;
+    sgx_status_t status;
+    // For sgx setup
+    int launch_token_updated;
+    sgx_launch_token_t launch_token;
+//    uint8_t* pub_key = (uint8_t*) malloc(2*SGX_ECP256_KEY_SIZE);
+//    sgx_ec256_public_t pub_key; 
+    
+
+  //  uint32_t actual_sealed_msg_length;
+    status = sgx_create_enclave(Decryptor_PATH, SGX_DEBUG_FLAG, &launch_token, &launch_token_updated, &e2_enclave_id, NULL);
+    if(status != SGX_SUCCESS)
+    {
+        printf("\nLoad Enclave Failure");
+        return -1;
+    }
+    printf("\nDecryptor - EnclaveID %" PRIx64, e2_enclave_id);
+    fflush(stdout);
+    ret_status=local_attestation_initiator(NULL); 
+    if(ret_status!=0)
+    {
+	printf("local attestation did not successfully return: %x\n", ret_status); fflush(stdout); return 0xFFFFFFFF; 
+
+    }
+/*    int sealed_signing_key_fd = open("sealed_signing_key.txt", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
+    if(sealed_signing_key_fd == -1)
+    {
+      perror("\nError in opening the file sealed_signing_key.txt - ");
+      fflush(stderr);
+      return 0xFFFFFFFF;
+    }
+    printf("\nSuccessfully opened a file to seal the signing key pair for the client.\n");
+    fflush(stdout);
+    int start = lseek(sealed_signing_key_fd, 0, SEEK_CUR);
+    int end = lseek(sealed_signing_key_fd, 0, SEEK_END);
+    if(start == end && start != -1)
+    {
+      // TODO: file is empty. create signing key pair.
+      start = lseek(sealed_signing_key_fd, 0, SEEK_CUR);
+      ret_status = create_and_seal_signing_key_pair_to_disk(sealed_signing_key_fd, &pub_key, &actual_sealed_msg_length);
+      if(ret_status != 0)
+      {
+        printf("\n error in generating the ecdsa signing key pair \n");
+        fflush(stdout);
+        return 0xFFFFFFFF;
+      }
+	fflush(stdout);
+      printf("\n Generated the ecdsa key pair successfully - gx, gy\n");
+      fflush(stdout);
+    }
+    else {
+      start = lseek(sealed_signing_key_fd, 0, SEEK_CUR);
+      if(actual_sealed_msg_length == 0)
+        actual_sealed_msg_length = end - start;
+      ret_status = unseal_signing_key_pair_from_disk(sealed_signing_key_fd, &pub_key, &actual_sealed_msg_length);
+      if(ret_status != SGX_SUCCESS)
+      {
+        printf("\n error in unsealing the ecdsa signing key pair:%d \n", ret_status);
+        fflush(stdout);
+        return 0xFFFFFFFF;
+      }
+      printf("\n Recovered the ecdsa key pair successfully - gx, gy\n");
+      fflush(stdout);
+    }
+*/
+
+    // TODO: Continue with other msgs - send sign(enc | verifier mr_enclave)
+    sgx_destroy_enclave(e2_enclave_id);
+
+    return 0;
+}

+ 692 - 0
App/App_old.txt

@@ -0,0 +1,692 @@
+/*
+ * Copyright (C) 2011-2017 Intel Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *   * Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   * Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in
+ *     the documentation and/or other materials provided with the
+ *     distribution.
+ *   * Neither the name of Intel Corporation nor the names of its
+ *     contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.challa
+ *
+ */
+
+#define SGX_DH_MAC_SIZE 16
+#define SGX_TARGET_INFO_RESERVED1_BYTES 4
+#define SGX_TARGET_INFO_RESERVED2_BYTES 456
+#define SGX_ECP256_KEY_SIZE 32
+#define SGX_CPUSVN_SIZE 16
+#define SGX_REPORT_DATA_SIZE 64
+#define SGX_MAC_SIZE 16 /* Message Authentication Code - 16 bytes */
+#define SGX_KEYID_SIZE 32
+#define SGX_HASH_SIZE 32 /* SHA256 */
+
+#define SGX_REPORT_BODY_RESERVED1 28
+#define SGX_REPORT_BODY_RESERVED2 32
+#define SGX_REPORT_BODY_RESERVED3 96
+#define SGX_REPORT_BODY_RESERVED4 60
+
+// App.cpp : Defines the entry point for the console application.
+#include <stdio.h>
+#include <map>
+#include "../Decryptor/Decryptor_u.h"
+#include "sgx_eid.h"
+#include "sgx_urts.h"
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
+#include<unistd.h>
+
+// For ecdsa signing key generation 
+#include "sgx_tcrypto.h"
+
+// For socket programming
+#include <sys/socket.h>
+#include <stdlib.h>
+#include <netinet/in.h>
+#include <string.h>
+#include <errno.h>
+#include<unistd.h>
+
+// For google proto buffers
+#include "dhmsgs.pb.h"
+#include <inttypes.h>
+#include <google/protobuf/io/coded_stream.h>
+#include <google/protobuf/io/zero_copy_stream_impl.h>
+using namespace google::protobuf::io;
+
+#define UNUSED(val) (void)(val)
+#define TCHAR   char
+#define _TCHAR  char
+#define _T(str) str
+#define scanf_s scanf
+#define _tmain  main
+
+// Not sure if I need this later - as such, I (decryptor app) will only ever need to talk to 1 enclave at a time - verifier enclave first and then the apache enclave.
+//extern std::map<sgx_enclave_id_t, uint32_t>g_enclave_id_map;
+
+sgx_enclave_id_t e2_enclave_id = 0;
+#define Decryptor_PATH "libDecryptor.so"
+
+int fit_32_into_uint8_t(google::protobuf::uint32 temp32, uint8_t* temp8)
+{
+ if(temp32 > UINT8_MAX)
+	 return -1;
+ else
+ {
+	 //		 *temp8 = *(uint8_t*)&temp32; // Probably works irrespective of endianness but not sure.
+	 *temp8 = (uint8_t)temp32;
+	 return 0;
+ }
+}
+
+int fit_32_into_uint16_t(google::protobuf::uint32 temp32, uint16_t* temp16)
+{
+ if(temp32 > UINT16_MAX)
+	 return -1;
+ else
+ {
+	 //		 *temp8 = *(uint8_t*)&temp32; // Probably works irrespective of endianness but not sure.
+	 *temp16 = (uint16_t)temp32;
+	 return 0;
+ }
+}
+// Sets up a socket to bind and listen to the given port. Returns FD of the socket on success, -1 on failure (and prints a msg to stdout with the errno)
+int set_up_socket(int port,   sockaddr_in* address)
+{
+  int server_fd = 0;
+
+  // Creating socket file descriptor for listening for attestation requests.
+  server_fd = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
+  if (server_fd == -1)
+  {
+     printf("Error in creating a socket - %d", errno);
+      return -1;
+  }
+
+  // Preparing the address struct for binding
+  address->sin_family = AF_INET;
+  address->sin_addr.s_addr = INADDR_ANY; // Todo: should this be localhost?
+  address->sin_port = htons(port);
+  //  memset(address->sin_zero,0,sizeof(address->sin_zero));
+
+  socklen_t addrlen = sizeof(*address);
+  // Binding
+  if (bind(server_fd, (sockaddr*)address, addrlen)<0)
+  {
+      printf("Error in binding %d - port was %d - ", errno, port);
+      return -1;
+  }
+
+  // Listening
+  if (listen(server_fd, 128) < 0)
+  {
+      printf("Error in listening %d", errno);
+      return -1;
+  }
+
+  return server_fd;
+}
+
+void encode_ec256_public_key_to_protobuf(protobuf_sgx_ec256_public_t* protobuf_g_a , sgx_ec256_public_t* g_a)
+{
+	int counter; google::protobuf::uint32 temp32;
+	for(counter=0;counter<SGX_ECP256_KEY_SIZE;counter++)
+	{
+		temp32 = g_a->gx[counter];
+		protobuf_g_a->add_gx(temp32);
+		temp32 = g_a->gy[counter];
+		protobuf_g_a->add_gy(temp32);
+	}
+}
+
+int decode_ec256_public_key_from_protobuf(protobuf_sgx_ec256_public_t* protobuf_g_a , sgx_ec256_public_t* g_a)
+{
+  printf("\n ec256 pub key\n");
+	int counter; google::protobuf::uint32 temp32;
+	for(counter=0;counter<SGX_ECP256_KEY_SIZE;counter++)
+	{
+		temp32 = protobuf_g_a->gx(counter);
+		if(fit_32_into_uint8_t(temp32, &(g_a->gx[counter]))!=0)
+		 return -1;
+    printf("%d ",g_a->gx[counter]);
+		temp32 = protobuf_g_a->gy(counter);
+		if(fit_32_into_uint8_t(temp32, &(g_a->gy[counter]))!=0)
+		 return -1;
+    printf("%d ",g_a->gy[counter]);
+	}
+  return 0;
+}
+
+void encode_attributes_to_protobuf(protobuf_sgx_attributes_t* protobuf_attributes, sgx_attributes_t* attributes)
+{
+	protobuf_attributes->set_flags(attributes->flags); // 64 bit
+	protobuf_attributes->set_xfrm(attributes->xfrm); // 64 bit
+}
+
+int decode_attributes_from_protobuf(protobuf_sgx_attributes_t* protobuf_attributes, sgx_attributes_t* attributes)
+{
+	attributes->flags = protobuf_attributes->flags();
+  printf("\n flags %" PRIu64 " \n", attributes->flags);
+	attributes->xfrm = protobuf_attributes->xfrm();
+  printf("\n xfrm %" PRIu64 " \n", attributes->xfrm);
+	return 0; 
+}
+
+void encode_report_to_protobuf(protobuf_sgx_report_t* protobuf_report, sgx_report_t* report)
+{
+	int counter; google::protobuf::uint32 temp32;
+	for(counter=0;counter<SGX_KEYID_SIZE;counter++)
+	{
+		temp32=report->key_id.id[counter];
+		protobuf_report->add_key_id(temp32);
+	}
+
+	for(counter=0;counter<SGX_MAC_SIZE;counter++)
+	{
+		temp32=report->mac[counter];
+		protobuf_report->add_mac(temp32);
+	}
+
+	protobuf_report->mutable_body()->set_misc_select(report->body.misc_select); // 32 bit
+	protobuf_report->mutable_body()->set_isv_svn(report->body.isv_svn); // 16 bit
+	protobuf_report->mutable_body()->set_isv_prod_id(report->body.isv_prod_id); // 16 bit
+	encode_attributes_to_protobuf(protobuf_report->mutable_body()->mutable_attributes(), &(report->body.attributes));
+
+	for(counter=0;counter<SGX_CPUSVN_SIZE;counter++)
+	{
+		temp32=report->body.cpu_svn.svn[counter];
+		protobuf_report->mutable_body()->add_cpu_svn(temp32);
+	}
+
+	for(counter=0;counter<SGX_REPORT_BODY_RESERVED1;counter++)
+	{
+		temp32=report->body.reserved1[counter]; // TODO: Could be optimized out - if these are determined to be 0s.
+		protobuf_report->mutable_body()->add_reserved1(temp32);
+ 	}
+
+	for(counter=0;counter<SGX_REPORT_BODY_RESERVED2;counter++)
+	{
+		temp32=report->body.reserved2[counter]; // TODO: Could be optimized out - if these are determined to be 0s.
+		protobuf_report->mutable_body()->add_reserved2(temp32);
+	}
+
+	for(counter=0;counter<SGX_REPORT_BODY_RESERVED3;counter++)
+	{
+		temp32=report->body.reserved3[counter]; // TODO: Could be optimized out - if these are determined to be 0s.
+		protobuf_report->mutable_body()->add_reserved3(temp32);
+ 	}
+
+	for(counter=0;counter<SGX_REPORT_BODY_RESERVED4;counter++)
+	{
+		temp32=report->body.reserved4[counter]; // TODO: Could be optimized out - if these are determined to be 0s.
+		protobuf_report->mutable_body()->add_reserved4(temp32);
+ 	}
+
+	for(counter=0;counter<SGX_HASH_SIZE;counter++)
+	{
+		temp32=report->body.mr_enclave.m[counter];
+		protobuf_report->mutable_body()->add_mr_enclave(temp32);
+ 	}
+
+	for(counter=0;counter<SGX_HASH_SIZE;counter++)
+	{
+		temp32=report->body.mr_signer.m[counter];
+		protobuf_report->mutable_body()->add_mr_signer(temp32);
+ 	}
+
+	for(counter=0;counter<SGX_REPORT_DATA_SIZE;counter++)
+	{
+		temp32=report->body.report_data.d[counter];
+		protobuf_report->mutable_body()->add_report_data(temp32);
+ 	}
+}
+
+int decode_report_from_protobuf(protobuf_sgx_report_t* protobuf_report, sgx_report_t* report)
+{
+  int counter; google::protobuf::uint32 temp32;
+
+  printf("\nreport body keyid\n");
+  for(counter=0;counter<SGX_KEYID_SIZE;counter++)
+  {
+    temp32=protobuf_report->key_id(counter);
+    if(fit_32_into_uint8_t(temp32, &(report->key_id.id[counter]))!=0)
+		  return -1;
+    printf("%d ", report->key_id.id[counter]);
+  }
+
+  printf("\nreport mac\n");
+  for(counter=0;counter<SGX_MAC_SIZE;counter++)
+  {
+    temp32=protobuf_report->mac(counter);
+    if(fit_32_into_uint8_t(temp32, &(report->mac[counter]))!=0)
+      return -1;
+    printf("%d ", report->mac[counter]);
+  }
+
+  report->body.misc_select=protobuf_report->mutable_body()->misc_select(); // 32 bit
+  temp32=protobuf_report->mutable_body()->isv_svn();
+  if(fit_32_into_uint16_t(temp32, &(report->body.isv_svn))!=0)
+   return -1;
+  printf("\nmisc select %d \n", report->body.misc_select);
+
+  temp32=protobuf_report->mutable_body()->isv_prod_id();
+   if(fit_32_into_uint16_t(temp32, &(report->body.isv_prod_id))!=0)
+    return -1;
+  printf("\nprod id %d \n", report->body.isv_prod_id);
+
+  decode_attributes_from_protobuf(protobuf_report->mutable_body()->mutable_attributes(), &(report->body.attributes));
+
+  printf("\n cpu svn\n");
+  for(counter=0;counter<SGX_CPUSVN_SIZE;counter++)
+  {
+    temp32=protobuf_report->mutable_body()->cpu_svn(counter);
+    if(fit_32_into_uint8_t(temp32, &(report->body.cpu_svn.svn[counter]))!=0)
+      return -1;
+    printf("%d ", report->body.cpu_svn.svn[counter]);
+
+  }
+
+  printf("\n reserved1 \n");
+  for(counter=0;counter<SGX_REPORT_BODY_RESERVED1;counter++)
+  {
+    temp32=protobuf_report->mutable_body()->reserved1(counter);
+    if(fit_32_into_uint8_t(temp32, &(report->body.reserved1[counter]))!=0)
+      return -1;
+    printf("%d ", report->body.reserved1[counter]);
+  }
+
+  printf("\n reserved2 \n");
+  for(counter=0;counter<SGX_REPORT_BODY_RESERVED2;counter++)
+  {
+    temp32=protobuf_report->mutable_body()->reserved2(counter);
+    if(fit_32_into_uint8_t(temp32, &(report->body.reserved2[counter]))!=0)
+      return -1;
+    printf("%d ", report->body.reserved2[counter]);
+  }
+
+  printf("\n reserved3 \n");
+  for(counter=0;counter<SGX_REPORT_BODY_RESERVED3;counter++)
+  {
+    temp32=protobuf_report->mutable_body()->reserved3(counter);
+    if(fit_32_into_uint8_t(temp32, &(report->body.reserved3[counter]))!=0)
+      return -1;
+    printf("%d ", report->body.reserved3[counter]);
+  }
+
+  printf("\n reserved4 \n");
+  for(counter=0;counter<SGX_REPORT_BODY_RESERVED4;counter++)
+  {
+    temp32=protobuf_report->mutable_body()->reserved4(counter);
+    if(fit_32_into_uint8_t(temp32, &(report->body.reserved4[counter]))!=0)
+      return -1;
+    printf("%d ", report->body.reserved4[counter]);
+
+  }
+
+  printf("\n mrenclave \n");
+  for(counter=0;counter<SGX_HASH_SIZE;counter++)
+  {
+    temp32=protobuf_report->mutable_body()->mr_enclave(counter);
+    if(fit_32_into_uint8_t(temp32, &(report->body.mr_enclave.m[counter]))!=0)
+      return -1;
+    printf("%x ", report->body.mr_enclave.m[counter]);
+  }
+
+  printf("\n mrsigner \n");
+  for(counter=0;counter<SGX_HASH_SIZE;counter++)
+  {
+    temp32=protobuf_report->mutable_body()->mr_signer(counter);
+    if(fit_32_into_uint8_t(temp32, &(report->body.mr_signer.m[counter]))!=0)
+      return -1;
+    printf("%x ", report->body.mr_signer.m[counter]);
+  }
+
+  printf("\n report data\n");
+  for(counter=0;counter<SGX_REPORT_DATA_SIZE;counter++)
+  {
+    temp32=protobuf_report->mutable_body()->report_data(counter);
+    if(fit_32_into_uint8_t(temp32, &(report->body.report_data.d[counter]))!=0)
+      return -1;
+    printf("%d ", report->body.report_data.d[counter]);
+  }
+	return 0;
+}
+
+void encode_msg1_to_protobuf( protobuf_sgx_dh_msg1_t& protobuf_dhmsg1, sgx_dh_msg1_t* native_dhmsg1)
+{
+   int counter; google::protobuf::uint32 temp32; // google::protobuf::uint64 temp64;
+
+   encode_ec256_public_key_to_protobuf(protobuf_dhmsg1.mutable_g_a(), &(native_dhmsg1->g_a));
+
+   for(counter=0;counter<SGX_HASH_SIZE;counter++)
+   {
+     temp32=native_dhmsg1->target.mr_enclave.m[counter];
+     protobuf_dhmsg1.mutable_target()->add_mr_enclave(temp32);
+   }
+
+   for(counter=0;counter<SGX_TARGET_INFO_RESERVED1_BYTES;counter++)
+   {
+     temp32=native_dhmsg1->target.reserved1[counter];
+     protobuf_dhmsg1.mutable_target()->add_reserved1(temp32);
+   }
+
+   for(counter=0;counter<SGX_TARGET_INFO_RESERVED2_BYTES;counter++)
+   {
+     temp32=native_dhmsg1->target.reserved2[counter];
+     protobuf_dhmsg1.mutable_target()->add_reserved2(temp32);
+   }
+
+   encode_attributes_to_protobuf(protobuf_dhmsg1.mutable_target()->mutable_attributes(), &(native_dhmsg1->target.attributes));
+
+   temp32=native_dhmsg1->target.misc_select ;
+   protobuf_dhmsg1.mutable_target()->set_misc_select(temp32);
+}
+
+void encode_msg3_to_protobuf(protobuf_sgx_dh_msg3_t& protobuf_dhmsg3, sgx_dh_msg3_t* native_dhmsg3)
+{
+  int counter; google::protobuf::uint32 temp32;
+  for(counter=0;counter<SGX_DH_MAC_SIZE;counter++)
+	{
+		temp32=native_dhmsg3->cmac[counter];
+		protobuf_dhmsg3.add_cmac(temp32);
+	}
+
+  encode_report_to_protobuf(protobuf_dhmsg3.mutable_msg3_body()->mutable_report(), &(native_dhmsg3->msg3_body.report));
+  int max_counter=native_dhmsg3->msg3_body.additional_prop_length;
+  unsigned char*temp;
+  for(counter=0,temp=native_dhmsg3->msg3_body.additional_prop;counter<max_counter;counter++,temp++)
+  {
+    protobuf_dhmsg3.mutable_msg3_body()->add_additional_prop(*temp);
+  }
+}
+
+int decode_msg2_from_protobuf(protobuf_sgx_dh_msg2_t& protobuf_dhmsg2, sgx_dh_msg2_t* native_dhmsg2)
+{
+  int counter; google::protobuf::uint32 temp32; //google::protobuf::uint64 temp64;
+  printf("\ncmac\n");
+  for(counter=0;counter<SGX_DH_MAC_SIZE;counter++)
+  {
+    temp32=protobuf_dhmsg2.cmac(counter);
+    if(fit_32_into_uint8_t(temp32, &(native_dhmsg2->cmac[counter]))!=0)
+     return -1;
+    printf("%d ",native_dhmsg2->cmac[counter]);
+  }
+
+  if(decode_ec256_public_key_from_protobuf(protobuf_dhmsg2.mutable_g_b(), &(native_dhmsg2->g_b)) !=0)
+	return -1;
+
+  if(decode_report_from_protobuf(protobuf_dhmsg2.mutable_report(), &(native_dhmsg2->report)) !=0)
+	return -1;
+
+  return 0;
+}
+
+int print_initialized_msg1( protobuf_sgx_dh_msg1_t& protobuf_dhmsg1, sgx_dh_msg1_t* native_dhmsg1)
+{
+   int counter;
+	 printf("gx\n");
+   for(counter=0;counter<SGX_ECP256_KEY_SIZE;counter++)
+   {
+      printf("%d ", protobuf_dhmsg1.g_a().gx(counter));
+      printf("%d ", native_dhmsg1->g_a.gx[counter]);
+   }
+   printf("\ngy\n");
+   for(counter=0;counter<SGX_ECP256_KEY_SIZE;counter++)
+   {
+      printf("%d ", protobuf_dhmsg1.g_a().gy(counter));
+      printf("%d ", native_dhmsg1->g_a.gy[counter]);
+   }
+
+   printf("\nmrenclave in target\n");
+   for(counter=0;counter<SGX_HASH_SIZE;counter++)
+   {
+      printf("%" PRIu32 " ", protobuf_dhmsg1.target().mr_enclave(counter));
+      printf("%d ", native_dhmsg1->target.mr_enclave.m[counter]);
+
+   }
+   printf("\nreserved1 in target\n");
+   for(counter=0;counter<SGX_TARGET_INFO_RESERVED1_BYTES;counter++)
+   {
+      printf("%" PRIu32 " ", protobuf_dhmsg1.target().reserved1(counter));
+      printf("%d ", native_dhmsg1->target.reserved1[counter]);
+
+   }
+   printf("\nreserved2 in target\n");
+   for(counter=0;counter<SGX_TARGET_INFO_RESERVED2_BYTES;counter++)
+   {
+      printf("%" PRIu32 " ", protobuf_dhmsg1.target().reserved2(counter));
+      printf("%d ", native_dhmsg1->target.reserved2[counter]);
+   }
+
+   printf("\n %" PRIu64 "\n", native_dhmsg1->target.attributes.flags);
+   printf("\n %" PRIu64 "\n", protobuf_dhmsg1.target().attributes().flags());
+   printf("\n %" PRIu64 "\n", native_dhmsg1->target.attributes.xfrm);
+   printf("\n %" PRIu64 "\n", protobuf_dhmsg1.target().attributes().xfrm());
+   printf("\n %" PRIu32 "\n", native_dhmsg1->target.misc_select);
+   printf("\n %" PRIu32 "\n", protobuf_dhmsg1.target().misc_select());
+
+	return 0;
+}
+
+int read_protobuf_msg_from_fd(int accept_fd, google::protobuf::MessageLite& message)
+{
+  ZeroCopyInputStream* raw_input;
+  CodedInputStream* coded_input;
+  uint32_t size;
+  CodedInputStream::Limit limit;
+  raw_input = new FileInputStream(accept_fd);
+  coded_input = new CodedInputStream(raw_input);
+  if(!coded_input->ReadVarint32(&size))
+  {
+    printf("Error in reading size of msg");
+    fflush(stdout);
+    return -1;
+  }
+  //printf("size of msg was read to be %" PRIu32 " \n", size);
+  fflush(stdout);
+  limit = coded_input->PushLimit(size);
+  if(!message.ParseFromCodedStream(coded_input))
+  {
+    printf("Error in parsing msg");
+    fflush(stdout);
+    return -1;
+  }
+  coded_input->PopLimit(limit);
+  return 0;
+}
+
+int write_protobuf_msg_to_fd(int accept_fd, google::protobuf::MessageLite& message)
+{
+  ZeroCopyOutputStream* raw_output = new FileOutputStream(accept_fd);
+  CodedOutputStream* coded_output  = new CodedOutputStream(raw_output);
+  coded_output->WriteVarint32(message.ByteSize());
+  if(!message.SerializeToCodedStream(coded_output))
+  {
+    printf("SerializeToCodedStream failed");
+    fflush(stdout);
+    return -1;
+  }
+  // As per this - https://stackoverflow.com/questions/22881876/protocol-buffers-how-to-serialize-and-deserialize-multiple-messages-into-a-file?noredirect=1&lq=1
+  // TODO: There may be a better way to do this - 1) this happens with every accept now and 2) make it happen on the stack vs heap - destructor will be called on return from this function (main) and the items will then be written out. (We probably don't want that, actually)
+  delete coded_output;
+  delete raw_output;
+  fflush(stdout);
+  return 0;
+}
+
+int _tmain(int argc, _TCHAR* argv[])
+{
+    uint32_t ret_status;
+    sgx_status_t status;
+    // For sgx setup
+    int launch_token_updated;
+    sgx_launch_token_t launch_token;
+    // declare msg1, msg2, msg3 protobuf objects and native SGX structs
+    protobuf_sgx_dh_msg1_t protobuf_msg1;
+    protobuf_sgx_dh_msg2_t protobuf_msg2;
+    protobuf_sgx_dh_msg3_t protobuf_msg3;
+    // For sgx - ecalls and storing msgs rcvd from pipes for processing.
+    uint32_t session_id;
+    sgx_dh_msg1_t dh_msg1;            //Diffie-Hellman Message 1
+    sgx_dh_msg2_t dh_msg2;            //Diffie-Hellman Message 2
+    sgx_dh_msg3_t dh_msg3;            //Diffie-Hellman Message 3
+    sgx_key_128bit_t dh_aek;        // Session Key
+    // initializing native sgx structs
+    memset(&dh_aek,0, sizeof(sgx_key_128bit_t));
+    memset(&dh_msg1, 0, sizeof(sgx_dh_msg1_t));
+    memset(&dh_msg2, 0, sizeof(sgx_dh_msg2_t));
+    memset(&dh_msg3, 0, sizeof(sgx_dh_msg3_t));
+    // For socket to listen to the Apache enclave.
+    int apache_port = 3825; int server_fd=0; int accept_fd = 0;
+    struct sockaddr_in own_addr;
+    struct sockaddr_storage apache_addr; socklen_t apache_addr_size = sizeof(apache_addr);
+    int counter;
+    UNUSED(argc);
+    UNUSED(argv);
+
+    server_fd=set_up_socket(apache_port, &own_addr);
+    if(server_fd==-1)
+      return -1;
+    printf("Successfully set up a socket to communicate with the Apache enclave.");
+    fflush(stdout);
+
+    status = sgx_create_enclave(Decryptor_PATH, SGX_DEBUG_FLAG, &launch_token, &launch_token_updated, &e2_enclave_id, NULL);
+    if(status != SGX_SUCCESS)
+    {
+        printf("\nLoad Enclave Failure");
+        close(server_fd);
+        return -1;
+    }
+    printf("\nDecryptor - EnclaveID %" PRIx64, e2_enclave_id);
+    fflush(stdout);
+
+    // Generating a signing ECDSA key to sign the encryption key. 
+    sgx_ec256_public_t pub_key; 
+    Decryptor_create_ecdsa_signing_key_pair(e2_enclave_id, &ret_status, &pub_key);
+    if(ret_status != SGX_SUCCESS) 
+    {
+	printf("\n error in generating the ecdsa signing key pair \n"); 
+	fflush(stdout); 
+	return 0xFFFFFFFF;
+    }
+    printf("\n Generated the ecdsa key pair successfully - gx, gy\n"); 
+    fflush(stdout); 
+    for(counter=0; counter<SGX_ECP256_KEY_SIZE; counter++) 
+    {
+	printf("%x ", pub_key.gx[counter]); 
+    }
+    printf("\n"); fflush(stdout); 
+    for(counter=0; counter<SGX_ECP256_KEY_SIZE; counter++) 
+    {
+        printf("%x ", pub_key.gy[counter]); 
+    }
+    printf("\n"); fflush(stdout);  
+
+    Decryptor_session_request(e2_enclave_id, &ret_status, &dh_msg1, &session_id); // TODO: Check Return status 
+    encode_msg1_to_protobuf(protobuf_msg1, &dh_msg1);
+    print_initialized_msg1(protobuf_msg1, &dh_msg1);
+    printf("Done initialization");
+    fflush(stdout);
+    //
+    int no_of_msgs_xchanged=0;
+//    do
+//    {
+      // accept incoming connection
+    accept_fd = accept(server_fd, (struct sockaddr *)&apache_addr,&apache_addr_size);
+    if (accept_fd <0)
+    {
+      printf("Error in accepting %d", errno);
+      return -1;
+    }
+    printf("Accepted the fd");
+    do
+    {
+      // read msg(none,2) and then write(1,3)
+      if(no_of_msgs_xchanged==0){
+        // call SerializeToFileDescriptor on msg1 object, accept_fd.
+        if(write_protobuf_msg_to_fd(accept_fd, protobuf_msg1)!=0)
+		return -1; 
+      }
+      else
+      {
+	       printf("about to read msg2\n");
+	        fflush(stdout);
+        // read msg2 -
+        if(read_protobuf_msg_from_fd(accept_fd, protobuf_msg2)!=0)
+		return -1;
+
+        if(decode_msg2_from_protobuf(protobuf_msg2, &dh_msg2)!=0)
+		return -1; 
+	printf("Done decoding msg2\n"); 
+        // TODO: call fn to generate msg3 for the responder.
+	Decryptor_exchange_report(e2_enclave_id, &ret_status, &dh_msg2, &dh_msg3, &session_id);
+	if(ret_status!=SGX_SUCCESS)
+	{
+		fflush(stdout);
+		printf("exchange report failed:%x\n", ret_status);
+		fflush(stdout);
+		return -1;
+	}
+	printf("return status %d", ret_status);
+	fflush(stdout);
+        // convert msg3 sgx_dh_msg3_t object to a protobuf msg3 object.
+        encode_msg3_to_protobuf(protobuf_msg3, &dh_msg3);
+	printf("about to write msg3\n");
+	fflush(stdout);
+        // write msg3 -
+        if(write_protobuf_msg_to_fd(accept_fd, protobuf_msg3)!=0)
+		return -1; 
+        no_of_msgs_xchanged+=1;
+      }
+      no_of_msgs_xchanged++;
+
+    }
+    while(no_of_msgs_xchanged!=3);
+	printf("Out of while loop\n");
+	fflush(stdout);
+    // TODO: Continue with other msgs.
+//    sleep(500);
+    sgx_destroy_enclave(e2_enclave_id);
+
+    return 0;
+}
+
+/*
+// Reads from a server fd that is set up successfully for accept, into a buffer buf and upto the length len.
+// Returns the number of characters read on success and -1 on error. Also, on error, prints the errno for the accept system call.
+int accept_and_read(int server_fd, char* buf, int len)
+{
+int initialize_msg1( protobuf_sgx_dh_msg1_t& protobuf_dhmsg1, sgx_dh_msg1_t* native_dhmsg1)
+     int accept_fd=0;
+     // accept connections and then forward them to the main enclave.
+     if ((accept_fd = accept(server_fd, (struct sockaddr *)&address,
+                       (socklen_t*)&addrlen))<0)
+    {
+        printf("Error in accepting %d", errno);
+        return -1;
+    }
+    valread = read(accept_fd, buf, len);
+    if(valread == -1)
+        printf("Error in reading %d", errno);
+    return valread;
+}
+*/
+

+ 2997 - 0
App/dhmsgs.pb.cpp

@@ -0,0 +1,2997 @@
+// Generated by the protocol buffer compiler.  DO NOT EDIT!
+// source: dhmsgs.proto
+
+#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION
+#include "dhmsgs.pb.h"
+
+#include <algorithm>
+
+#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/stubs/once.h>
+#include <google/protobuf/io/coded_stream.h>
+#include <google/protobuf/wire_format_lite_inl.h>
+#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
+// @@protoc_insertion_point(includes)
+
+void protobuf_ShutdownFile_dhmsgs_2eproto() {
+  delete protobuf_sgx_attributes_t::default_instance_;
+  delete protobuf_sgx_ec256_public_t::default_instance_;
+  delete protobuf_sgx_report_body_t::default_instance_;
+  delete protobuf_sgx_report_t::default_instance_;
+  delete protobuf_sgx_target_info_t::default_instance_;
+  delete protobuf_sgx_dh_msg1_t::default_instance_;
+  delete protobuf_sgx_dh_msg2_t::default_instance_;
+  delete protobuf_sgx_dh_msg3_body_t::default_instance_;
+  delete protobuf_sgx_dh_msg3_t::default_instance_;
+}
+
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+void protobuf_AddDesc_dhmsgs_2eproto_impl() {
+  GOOGLE_PROTOBUF_VERIFY_VERSION;
+
+#else
+void protobuf_AddDesc_dhmsgs_2eproto() {
+  static bool already_here = false;
+  if (already_here) return;
+  already_here = true;
+  GOOGLE_PROTOBUF_VERIFY_VERSION;
+
+#endif
+  protobuf_sgx_attributes_t::default_instance_ = new protobuf_sgx_attributes_t();
+  protobuf_sgx_ec256_public_t::default_instance_ = new protobuf_sgx_ec256_public_t();
+  protobuf_sgx_report_body_t::default_instance_ = new protobuf_sgx_report_body_t();
+  protobuf_sgx_report_t::default_instance_ = new protobuf_sgx_report_t();
+  protobuf_sgx_target_info_t::default_instance_ = new protobuf_sgx_target_info_t();
+  protobuf_sgx_dh_msg1_t::default_instance_ = new protobuf_sgx_dh_msg1_t();
+  protobuf_sgx_dh_msg2_t::default_instance_ = new protobuf_sgx_dh_msg2_t();
+  protobuf_sgx_dh_msg3_body_t::default_instance_ = new protobuf_sgx_dh_msg3_body_t();
+  protobuf_sgx_dh_msg3_t::default_instance_ = new protobuf_sgx_dh_msg3_t();
+  protobuf_sgx_attributes_t::default_instance_->InitAsDefaultInstance();
+  protobuf_sgx_ec256_public_t::default_instance_->InitAsDefaultInstance();
+  protobuf_sgx_report_body_t::default_instance_->InitAsDefaultInstance();
+  protobuf_sgx_report_t::default_instance_->InitAsDefaultInstance();
+  protobuf_sgx_target_info_t::default_instance_->InitAsDefaultInstance();
+  protobuf_sgx_dh_msg1_t::default_instance_->InitAsDefaultInstance();
+  protobuf_sgx_dh_msg2_t::default_instance_->InitAsDefaultInstance();
+  protobuf_sgx_dh_msg3_body_t::default_instance_->InitAsDefaultInstance();
+  protobuf_sgx_dh_msg3_t::default_instance_->InitAsDefaultInstance();
+  ::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_dhmsgs_2eproto);
+}
+
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AddDesc_dhmsgs_2eproto_once_);
+void protobuf_AddDesc_dhmsgs_2eproto() {
+  ::google::protobuf::GoogleOnceInit(&protobuf_AddDesc_dhmsgs_2eproto_once_,
+                 &protobuf_AddDesc_dhmsgs_2eproto_impl);
+}
+#else
+// Force AddDescriptors() to be called at static initialization time.
+struct StaticDescriptorInitializer_dhmsgs_2eproto {
+  StaticDescriptorInitializer_dhmsgs_2eproto() {
+    protobuf_AddDesc_dhmsgs_2eproto();
+  }
+} static_descriptor_initializer_dhmsgs_2eproto_;
+#endif
+
+// ===================================================================
+
+#ifndef _MSC_VER
+const int protobuf_sgx_attributes_t::kFlagsFieldNumber;
+const int protobuf_sgx_attributes_t::kXfrmFieldNumber;
+#endif  // !_MSC_VER
+
+protobuf_sgx_attributes_t::protobuf_sgx_attributes_t()
+  : ::google::protobuf::MessageLite() {
+  SharedCtor();
+  // @@protoc_insertion_point(constructor:protobuf_sgx_attributes_t)
+}
+
+void protobuf_sgx_attributes_t::InitAsDefaultInstance() {
+}
+
+protobuf_sgx_attributes_t::protobuf_sgx_attributes_t(const protobuf_sgx_attributes_t& from)
+  : ::google::protobuf::MessageLite() {
+  SharedCtor();
+  MergeFrom(from);
+  // @@protoc_insertion_point(copy_constructor:protobuf_sgx_attributes_t)
+}
+
+void protobuf_sgx_attributes_t::SharedCtor() {
+  _cached_size_ = 0;
+  flags_ = GOOGLE_ULONGLONG(0);
+  xfrm_ = GOOGLE_ULONGLONG(0);
+  ::memset(_has_bits_, 0, sizeof(_has_bits_));
+}
+
+protobuf_sgx_attributes_t::~protobuf_sgx_attributes_t() {
+  // @@protoc_insertion_point(destructor:protobuf_sgx_attributes_t)
+  SharedDtor();
+}
+
+void protobuf_sgx_attributes_t::SharedDtor() {
+  #ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+  if (this != &default_instance()) {
+  #else
+  if (this != default_instance_) {
+  #endif
+  }
+}
+
+void protobuf_sgx_attributes_t::SetCachedSize(int size) const {
+  GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+  _cached_size_ = size;
+  GOOGLE_SAFE_CONCURRENT_WRITES_END();
+}
+const protobuf_sgx_attributes_t& protobuf_sgx_attributes_t::default_instance() {
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+  protobuf_AddDesc_dhmsgs_2eproto();
+#else
+  if (default_instance_ == NULL) protobuf_AddDesc_dhmsgs_2eproto();
+#endif
+  return *default_instance_;
+}
+
+protobuf_sgx_attributes_t* protobuf_sgx_attributes_t::default_instance_ = NULL;
+
+protobuf_sgx_attributes_t* protobuf_sgx_attributes_t::New() const {
+  return new protobuf_sgx_attributes_t;
+}
+
+void protobuf_sgx_attributes_t::Clear() {
+#define OFFSET_OF_FIELD_(f) (reinterpret_cast<char*>(      \
+  &reinterpret_cast<protobuf_sgx_attributes_t*>(16)->f) - \
+   reinterpret_cast<char*>(16))
+
+#define ZR_(first, last) do {                              \
+    size_t f = OFFSET_OF_FIELD_(first);                    \
+    size_t n = OFFSET_OF_FIELD_(last) - f + sizeof(last);  \
+    ::memset(&first, 0, n);                                \
+  } while (0)
+
+  ZR_(flags_, xfrm_);
+
+#undef OFFSET_OF_FIELD_
+#undef ZR_
+
+  ::memset(_has_bits_, 0, sizeof(_has_bits_));
+  mutable_unknown_fields()->clear();
+}
+
+bool protobuf_sgx_attributes_t::MergePartialFromCodedStream(
+    ::google::protobuf::io::CodedInputStream* input) {
+#define DO_(EXPRESSION) if (!(EXPRESSION)) goto failure
+  ::google::protobuf::uint32 tag;
+  ::google::protobuf::io::StringOutputStream unknown_fields_string(
+      mutable_unknown_fields());
+  ::google::protobuf::io::CodedOutputStream unknown_fields_stream(
+      &unknown_fields_string);
+  // @@protoc_insertion_point(parse_start:protobuf_sgx_attributes_t)
+  for (;;) {
+    ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+    tag = p.first;
+    if (!p.second) goto handle_unusual;
+    switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
+      // required uint64 flags = 1;
+      case 1: {
+        if (tag == 8) {
+          DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
+                   ::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_UINT64>(
+                 input, &flags_)));
+          set_has_flags();
+        } else {
+          goto handle_unusual;
+        }
+        if (input->ExpectTag(16)) goto parse_xfrm;
+        break;
+      }
+
+      // required uint64 xfrm = 2;
+      case 2: {
+        if (tag == 16) {
+         parse_xfrm:
+          DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
+                   ::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_UINT64>(
+                 input, &xfrm_)));
+          set_has_xfrm();
+        } else {
+          goto handle_unusual;
+        }
+        if (input->ExpectAtEnd()) goto success;
+        break;
+      }
+
+      default: {
+      handle_unusual:
+        if (tag == 0 ||
+            ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
+            ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
+          goto success;
+        }
+        DO_(::google::protobuf::internal::WireFormatLite::SkipField(
+            input, tag, &unknown_fields_stream));
+        break;
+      }
+    }
+  }
+success:
+  // @@protoc_insertion_point(parse_success:protobuf_sgx_attributes_t)
+  return true;
+failure:
+  // @@protoc_insertion_point(parse_failure:protobuf_sgx_attributes_t)
+  return false;
+#undef DO_
+}
+
+void protobuf_sgx_attributes_t::SerializeWithCachedSizes(
+    ::google::protobuf::io::CodedOutputStream* output) const {
+  // @@protoc_insertion_point(serialize_start:protobuf_sgx_attributes_t)
+  // required uint64 flags = 1;
+  if (has_flags()) {
+    ::google::protobuf::internal::WireFormatLite::WriteUInt64(1, this->flags(), output);
+  }
+
+  // required uint64 xfrm = 2;
+  if (has_xfrm()) {
+    ::google::protobuf::internal::WireFormatLite::WriteUInt64(2, this->xfrm(), output);
+  }
+
+  output->WriteRaw(unknown_fields().data(),
+                   unknown_fields().size());
+  // @@protoc_insertion_point(serialize_end:protobuf_sgx_attributes_t)
+}
+
+int protobuf_sgx_attributes_t::ByteSize() const {
+  int total_size = 0;
+
+  if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
+    // required uint64 flags = 1;
+    if (has_flags()) {
+      total_size += 1 +
+        ::google::protobuf::internal::WireFormatLite::UInt64Size(
+          this->flags());
+    }
+
+    // required uint64 xfrm = 2;
+    if (has_xfrm()) {
+      total_size += 1 +
+        ::google::protobuf::internal::WireFormatLite::UInt64Size(
+          this->xfrm());
+    }
+
+  }
+  total_size += unknown_fields().size();
+
+  GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+  _cached_size_ = total_size;
+  GOOGLE_SAFE_CONCURRENT_WRITES_END();
+  return total_size;
+}
+
+void protobuf_sgx_attributes_t::CheckTypeAndMergeFrom(
+    const ::google::protobuf::MessageLite& from) {
+  MergeFrom(*::google::protobuf::down_cast<const protobuf_sgx_attributes_t*>(&from));
+}
+
+void protobuf_sgx_attributes_t::MergeFrom(const protobuf_sgx_attributes_t& from) {
+  GOOGLE_CHECK_NE(&from, this);
+  if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
+    if (from.has_flags()) {
+      set_flags(from.flags());
+    }
+    if (from.has_xfrm()) {
+      set_xfrm(from.xfrm());
+    }
+  }
+  mutable_unknown_fields()->append(from.unknown_fields());
+}
+
+void protobuf_sgx_attributes_t::CopyFrom(const protobuf_sgx_attributes_t& from) {
+  if (&from == this) return;
+  Clear();
+  MergeFrom(from);
+}
+
+bool protobuf_sgx_attributes_t::IsInitialized() const {
+  if ((_has_bits_[0] & 0x00000003) != 0x00000003) return false;
+
+  return true;
+}
+
+void protobuf_sgx_attributes_t::Swap(protobuf_sgx_attributes_t* other) {
+  if (other != this) {
+    std::swap(flags_, other->flags_);
+    std::swap(xfrm_, other->xfrm_);
+    std::swap(_has_bits_[0], other->_has_bits_[0]);
+    _unknown_fields_.swap(other->_unknown_fields_);
+    std::swap(_cached_size_, other->_cached_size_);
+  }
+}
+
+::std::string protobuf_sgx_attributes_t::GetTypeName() const {
+  return "protobuf_sgx_attributes_t";
+}
+
+
+// ===================================================================
+
+#ifndef _MSC_VER
+const int protobuf_sgx_ec256_public_t::kGxFieldNumber;
+const int protobuf_sgx_ec256_public_t::kGyFieldNumber;
+#endif  // !_MSC_VER
+
+protobuf_sgx_ec256_public_t::protobuf_sgx_ec256_public_t()
+  : ::google::protobuf::MessageLite() {
+  SharedCtor();
+  // @@protoc_insertion_point(constructor:protobuf_sgx_ec256_public_t)
+}
+
+void protobuf_sgx_ec256_public_t::InitAsDefaultInstance() {
+}
+
+protobuf_sgx_ec256_public_t::protobuf_sgx_ec256_public_t(const protobuf_sgx_ec256_public_t& from)
+  : ::google::protobuf::MessageLite() {
+  SharedCtor();
+  MergeFrom(from);
+  // @@protoc_insertion_point(copy_constructor:protobuf_sgx_ec256_public_t)
+}
+
+void protobuf_sgx_ec256_public_t::SharedCtor() {
+  _cached_size_ = 0;
+  ::memset(_has_bits_, 0, sizeof(_has_bits_));
+}
+
+protobuf_sgx_ec256_public_t::~protobuf_sgx_ec256_public_t() {
+  // @@protoc_insertion_point(destructor:protobuf_sgx_ec256_public_t)
+  SharedDtor();
+}
+
+void protobuf_sgx_ec256_public_t::SharedDtor() {
+  #ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+  if (this != &default_instance()) {
+  #else
+  if (this != default_instance_) {
+  #endif
+  }
+}
+
+void protobuf_sgx_ec256_public_t::SetCachedSize(int size) const {
+  GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+  _cached_size_ = size;
+  GOOGLE_SAFE_CONCURRENT_WRITES_END();
+}
+const protobuf_sgx_ec256_public_t& protobuf_sgx_ec256_public_t::default_instance() {
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+  protobuf_AddDesc_dhmsgs_2eproto();
+#else
+  if (default_instance_ == NULL) protobuf_AddDesc_dhmsgs_2eproto();
+#endif
+  return *default_instance_;
+}
+
+protobuf_sgx_ec256_public_t* protobuf_sgx_ec256_public_t::default_instance_ = NULL;
+
+protobuf_sgx_ec256_public_t* protobuf_sgx_ec256_public_t::New() const {
+  return new protobuf_sgx_ec256_public_t;
+}
+
+void protobuf_sgx_ec256_public_t::Clear() {
+  gx_.Clear();
+  gy_.Clear();
+  ::memset(_has_bits_, 0, sizeof(_has_bits_));
+  mutable_unknown_fields()->clear();
+}
+
+bool protobuf_sgx_ec256_public_t::MergePartialFromCodedStream(
+    ::google::protobuf::io::CodedInputStream* input) {
+#define DO_(EXPRESSION) if (!(EXPRESSION)) goto failure
+  ::google::protobuf::uint32 tag;
+  ::google::protobuf::io::StringOutputStream unknown_fields_string(
+      mutable_unknown_fields());
+  ::google::protobuf::io::CodedOutputStream unknown_fields_stream(
+      &unknown_fields_string);
+  // @@protoc_insertion_point(parse_start:protobuf_sgx_ec256_public_t)
+  for (;;) {
+    ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+    tag = p.first;
+    if (!p.second) goto handle_unusual;
+    switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
+      // repeated uint32 gx = 1 [packed = true];
+      case 1: {
+        if (tag == 10) {
+          DO_((::google::protobuf::internal::WireFormatLite::ReadPackedPrimitive<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 input, this->mutable_gx())));
+        } else if (tag == 8) {
+          DO_((::google::protobuf::internal::WireFormatLite::ReadRepeatedPrimitiveNoInline<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 1, 10, input, this->mutable_gx())));
+        } else {
+          goto handle_unusual;
+        }
+        if (input->ExpectTag(18)) goto parse_gy;
+        break;
+      }
+
+      // repeated uint32 gy = 2 [packed = true];
+      case 2: {
+        if (tag == 18) {
+         parse_gy:
+          DO_((::google::protobuf::internal::WireFormatLite::ReadPackedPrimitive<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 input, this->mutable_gy())));
+        } else if (tag == 16) {
+          DO_((::google::protobuf::internal::WireFormatLite::ReadRepeatedPrimitiveNoInline<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 1, 18, input, this->mutable_gy())));
+        } else {
+          goto handle_unusual;
+        }
+        if (input->ExpectAtEnd()) goto success;
+        break;
+      }
+
+      default: {
+      handle_unusual:
+        if (tag == 0 ||
+            ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
+            ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
+          goto success;
+        }
+        DO_(::google::protobuf::internal::WireFormatLite::SkipField(
+            input, tag, &unknown_fields_stream));
+        break;
+      }
+    }
+  }
+success:
+  // @@protoc_insertion_point(parse_success:protobuf_sgx_ec256_public_t)
+  return true;
+failure:
+  // @@protoc_insertion_point(parse_failure:protobuf_sgx_ec256_public_t)
+  return false;
+#undef DO_
+}
+
+void protobuf_sgx_ec256_public_t::SerializeWithCachedSizes(
+    ::google::protobuf::io::CodedOutputStream* output) const {
+  // @@protoc_insertion_point(serialize_start:protobuf_sgx_ec256_public_t)
+  // repeated uint32 gx = 1 [packed = true];
+  if (this->gx_size() > 0) {
+    ::google::protobuf::internal::WireFormatLite::WriteTag(1, ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output);
+    output->WriteVarint32(_gx_cached_byte_size_);
+  }
+  for (int i = 0; i < this->gx_size(); i++) {
+    ::google::protobuf::internal::WireFormatLite::WriteUInt32NoTag(
+      this->gx(i), output);
+  }
+
+  // repeated uint32 gy = 2 [packed = true];
+  if (this->gy_size() > 0) {
+    ::google::protobuf::internal::WireFormatLite::WriteTag(2, ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output);
+    output->WriteVarint32(_gy_cached_byte_size_);
+  }
+  for (int i = 0; i < this->gy_size(); i++) {
+    ::google::protobuf::internal::WireFormatLite::WriteUInt32NoTag(
+      this->gy(i), output);
+  }
+
+  output->WriteRaw(unknown_fields().data(),
+                   unknown_fields().size());
+  // @@protoc_insertion_point(serialize_end:protobuf_sgx_ec256_public_t)
+}
+
+int protobuf_sgx_ec256_public_t::ByteSize() const {
+  int total_size = 0;
+
+  // repeated uint32 gx = 1 [packed = true];
+  {
+    int data_size = 0;
+    for (int i = 0; i < this->gx_size(); i++) {
+      data_size += ::google::protobuf::internal::WireFormatLite::
+        UInt32Size(this->gx(i));
+    }
+    if (data_size > 0) {
+      total_size += 1 +
+        ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);
+    }
+    GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+    _gx_cached_byte_size_ = data_size;
+    GOOGLE_SAFE_CONCURRENT_WRITES_END();
+    total_size += data_size;
+  }
+
+  // repeated uint32 gy = 2 [packed = true];
+  {
+    int data_size = 0;
+    for (int i = 0; i < this->gy_size(); i++) {
+      data_size += ::google::protobuf::internal::WireFormatLite::
+        UInt32Size(this->gy(i));
+    }
+    if (data_size > 0) {
+      total_size += 1 +
+        ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);
+    }
+    GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+    _gy_cached_byte_size_ = data_size;
+    GOOGLE_SAFE_CONCURRENT_WRITES_END();
+    total_size += data_size;
+  }
+
+  total_size += unknown_fields().size();
+
+  GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+  _cached_size_ = total_size;
+  GOOGLE_SAFE_CONCURRENT_WRITES_END();
+  return total_size;
+}
+
+void protobuf_sgx_ec256_public_t::CheckTypeAndMergeFrom(
+    const ::google::protobuf::MessageLite& from) {
+  MergeFrom(*::google::protobuf::down_cast<const protobuf_sgx_ec256_public_t*>(&from));
+}
+
+void protobuf_sgx_ec256_public_t::MergeFrom(const protobuf_sgx_ec256_public_t& from) {
+  GOOGLE_CHECK_NE(&from, this);
+  gx_.MergeFrom(from.gx_);
+  gy_.MergeFrom(from.gy_);
+  mutable_unknown_fields()->append(from.unknown_fields());
+}
+
+void protobuf_sgx_ec256_public_t::CopyFrom(const protobuf_sgx_ec256_public_t& from) {
+  if (&from == this) return;
+  Clear();
+  MergeFrom(from);
+}
+
+bool protobuf_sgx_ec256_public_t::IsInitialized() const {
+
+  return true;
+}
+
+void protobuf_sgx_ec256_public_t::Swap(protobuf_sgx_ec256_public_t* other) {
+  if (other != this) {
+    gx_.Swap(&other->gx_);
+    gy_.Swap(&other->gy_);
+    std::swap(_has_bits_[0], other->_has_bits_[0]);
+    _unknown_fields_.swap(other->_unknown_fields_);
+    std::swap(_cached_size_, other->_cached_size_);
+  }
+}
+
+::std::string protobuf_sgx_ec256_public_t::GetTypeName() const {
+  return "protobuf_sgx_ec256_public_t";
+}
+
+
+// ===================================================================
+
+#ifndef _MSC_VER
+const int protobuf_sgx_report_body_t::kCpuSvnFieldNumber;
+const int protobuf_sgx_report_body_t::kMiscSelectFieldNumber;
+const int protobuf_sgx_report_body_t::kReserved1FieldNumber;
+const int protobuf_sgx_report_body_t::kAttributesFieldNumber;
+const int protobuf_sgx_report_body_t::kMrEnclaveFieldNumber;
+const int protobuf_sgx_report_body_t::kReserved2FieldNumber;
+const int protobuf_sgx_report_body_t::kMrSignerFieldNumber;
+const int protobuf_sgx_report_body_t::kReserved3FieldNumber;
+const int protobuf_sgx_report_body_t::kIsvProdIdFieldNumber;
+const int protobuf_sgx_report_body_t::kIsvSvnFieldNumber;
+const int protobuf_sgx_report_body_t::kReserved4FieldNumber;
+const int protobuf_sgx_report_body_t::kReportDataFieldNumber;
+#endif  // !_MSC_VER
+
+protobuf_sgx_report_body_t::protobuf_sgx_report_body_t()
+  : ::google::protobuf::MessageLite() {
+  SharedCtor();
+  // @@protoc_insertion_point(constructor:protobuf_sgx_report_body_t)
+}
+
+void protobuf_sgx_report_body_t::InitAsDefaultInstance() {
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+  attributes_ = const_cast< ::protobuf_sgx_attributes_t*>(
+      ::protobuf_sgx_attributes_t::internal_default_instance());
+#else
+  attributes_ = const_cast< ::protobuf_sgx_attributes_t*>(&::protobuf_sgx_attributes_t::default_instance());
+#endif
+}
+
+protobuf_sgx_report_body_t::protobuf_sgx_report_body_t(const protobuf_sgx_report_body_t& from)
+  : ::google::protobuf::MessageLite() {
+  SharedCtor();
+  MergeFrom(from);
+  // @@protoc_insertion_point(copy_constructor:protobuf_sgx_report_body_t)
+}
+
+void protobuf_sgx_report_body_t::SharedCtor() {
+  _cached_size_ = 0;
+  misc_select_ = 0u;
+  attributes_ = NULL;
+  isv_prod_id_ = 0u;
+  isv_svn_ = 0u;
+  ::memset(_has_bits_, 0, sizeof(_has_bits_));
+}
+
+protobuf_sgx_report_body_t::~protobuf_sgx_report_body_t() {
+  // @@protoc_insertion_point(destructor:protobuf_sgx_report_body_t)
+  SharedDtor();
+}
+
+void protobuf_sgx_report_body_t::SharedDtor() {
+  #ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+  if (this != &default_instance()) {
+  #else
+  if (this != default_instance_) {
+  #endif
+    delete attributes_;
+  }
+}
+
+void protobuf_sgx_report_body_t::SetCachedSize(int size) const {
+  GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+  _cached_size_ = size;
+  GOOGLE_SAFE_CONCURRENT_WRITES_END();
+}
+const protobuf_sgx_report_body_t& protobuf_sgx_report_body_t::default_instance() {
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+  protobuf_AddDesc_dhmsgs_2eproto();
+#else
+  if (default_instance_ == NULL) protobuf_AddDesc_dhmsgs_2eproto();
+#endif
+  return *default_instance_;
+}
+
+protobuf_sgx_report_body_t* protobuf_sgx_report_body_t::default_instance_ = NULL;
+
+protobuf_sgx_report_body_t* protobuf_sgx_report_body_t::New() const {
+  return new protobuf_sgx_report_body_t;
+}
+
+void protobuf_sgx_report_body_t::Clear() {
+  if (_has_bits_[0 / 32] & 10) {
+    misc_select_ = 0u;
+    if (has_attributes()) {
+      if (attributes_ != NULL) attributes_->::protobuf_sgx_attributes_t::Clear();
+    }
+  }
+  if (_has_bits_[8 / 32] & 768) {
+    isv_prod_id_ = 0u;
+    isv_svn_ = 0u;
+  }
+  cpu_svn_.Clear();
+  reserved1_.Clear();
+  mr_enclave_.Clear();
+  reserved2_.Clear();
+  mr_signer_.Clear();
+  reserved3_.Clear();
+  reserved4_.Clear();
+  report_data_.Clear();
+  ::memset(_has_bits_, 0, sizeof(_has_bits_));
+  mutable_unknown_fields()->clear();
+}
+
+bool protobuf_sgx_report_body_t::MergePartialFromCodedStream(
+    ::google::protobuf::io::CodedInputStream* input) {
+#define DO_(EXPRESSION) if (!(EXPRESSION)) goto failure
+  ::google::protobuf::uint32 tag;
+  ::google::protobuf::io::StringOutputStream unknown_fields_string(
+      mutable_unknown_fields());
+  ::google::protobuf::io::CodedOutputStream unknown_fields_stream(
+      &unknown_fields_string);
+  // @@protoc_insertion_point(parse_start:protobuf_sgx_report_body_t)
+  for (;;) {
+    ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+    tag = p.first;
+    if (!p.second) goto handle_unusual;
+    switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
+      // repeated uint32 cpu_svn = 1 [packed = true];
+      case 1: {
+        if (tag == 10) {
+          DO_((::google::protobuf::internal::WireFormatLite::ReadPackedPrimitive<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 input, this->mutable_cpu_svn())));
+        } else if (tag == 8) {
+          DO_((::google::protobuf::internal::WireFormatLite::ReadRepeatedPrimitiveNoInline<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 1, 10, input, this->mutable_cpu_svn())));
+        } else {
+          goto handle_unusual;
+        }
+        if (input->ExpectTag(18)) goto parse_reserved1;
+        break;
+      }
+
+      // repeated uint32 reserved1 = 2 [packed = true];
+      case 2: {
+        if (tag == 18) {
+         parse_reserved1:
+          DO_((::google::protobuf::internal::WireFormatLite::ReadPackedPrimitive<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 input, this->mutable_reserved1())));
+        } else if (tag == 16) {
+          DO_((::google::protobuf::internal::WireFormatLite::ReadRepeatedPrimitiveNoInline<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 1, 18, input, this->mutable_reserved1())));
+        } else {
+          goto handle_unusual;
+        }
+        if (input->ExpectTag(26)) goto parse_mr_enclave;
+        break;
+      }
+
+      // repeated uint32 mr_enclave = 3 [packed = true];
+      case 3: {
+        if (tag == 26) {
+         parse_mr_enclave:
+          DO_((::google::protobuf::internal::WireFormatLite::ReadPackedPrimitive<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 input, this->mutable_mr_enclave())));
+        } else if (tag == 24) {
+          DO_((::google::protobuf::internal::WireFormatLite::ReadRepeatedPrimitiveNoInline<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 1, 26, input, this->mutable_mr_enclave())));
+        } else {
+          goto handle_unusual;
+        }
+        if (input->ExpectTag(34)) goto parse_reserved2;
+        break;
+      }
+
+      // repeated uint32 reserved2 = 4 [packed = true];
+      case 4: {
+        if (tag == 34) {
+         parse_reserved2:
+          DO_((::google::protobuf::internal::WireFormatLite::ReadPackedPrimitive<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 input, this->mutable_reserved2())));
+        } else if (tag == 32) {
+          DO_((::google::protobuf::internal::WireFormatLite::ReadRepeatedPrimitiveNoInline<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 1, 34, input, this->mutable_reserved2())));
+        } else {
+          goto handle_unusual;
+        }
+        if (input->ExpectTag(42)) goto parse_mr_signer;
+        break;
+      }
+
+      // repeated uint32 mr_signer = 5 [packed = true];
+      case 5: {
+        if (tag == 42) {
+         parse_mr_signer:
+          DO_((::google::protobuf::internal::WireFormatLite::ReadPackedPrimitive<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 input, this->mutable_mr_signer())));
+        } else if (tag == 40) {
+          DO_((::google::protobuf::internal::WireFormatLite::ReadRepeatedPrimitiveNoInline<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 1, 42, input, this->mutable_mr_signer())));
+        } else {
+          goto handle_unusual;
+        }
+        if (input->ExpectTag(50)) goto parse_reserved3;
+        break;
+      }
+
+      // repeated uint32 reserved3 = 6 [packed = true];
+      case 6: {
+        if (tag == 50) {
+         parse_reserved3:
+          DO_((::google::protobuf::internal::WireFormatLite::ReadPackedPrimitive<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 input, this->mutable_reserved3())));
+        } else if (tag == 48) {
+          DO_((::google::protobuf::internal::WireFormatLite::ReadRepeatedPrimitiveNoInline<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 1, 50, input, this->mutable_reserved3())));
+        } else {
+          goto handle_unusual;
+        }
+        if (input->ExpectTag(58)) goto parse_reserved4;
+        break;
+      }
+
+      // repeated uint32 reserved4 = 7 [packed = true];
+      case 7: {
+        if (tag == 58) {
+         parse_reserved4:
+          DO_((::google::protobuf::internal::WireFormatLite::ReadPackedPrimitive<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 input, this->mutable_reserved4())));
+        } else if (tag == 56) {
+          DO_((::google::protobuf::internal::WireFormatLite::ReadRepeatedPrimitiveNoInline<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 1, 58, input, this->mutable_reserved4())));
+        } else {
+          goto handle_unusual;
+        }
+        if (input->ExpectTag(66)) goto parse_report_data;
+        break;
+      }
+
+      // repeated uint32 report_data = 8 [packed = true];
+      case 8: {
+        if (tag == 66) {
+         parse_report_data:
+          DO_((::google::protobuf::internal::WireFormatLite::ReadPackedPrimitive<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 input, this->mutable_report_data())));
+        } else if (tag == 64) {
+          DO_((::google::protobuf::internal::WireFormatLite::ReadRepeatedPrimitiveNoInline<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 1, 66, input, this->mutable_report_data())));
+        } else {
+          goto handle_unusual;
+        }
+        if (input->ExpectTag(72)) goto parse_misc_select;
+        break;
+      }
+
+      // required uint32 misc_select = 9;
+      case 9: {
+        if (tag == 72) {
+         parse_misc_select:
+          DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 input, &misc_select_)));
+          set_has_misc_select();
+        } else {
+          goto handle_unusual;
+        }
+        if (input->ExpectTag(82)) goto parse_attributes;
+        break;
+      }
+
+      // required .protobuf_sgx_attributes_t attributes = 10;
+      case 10: {
+        if (tag == 82) {
+         parse_attributes:
+          DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
+               input, mutable_attributes()));
+        } else {
+          goto handle_unusual;
+        }
+        if (input->ExpectTag(88)) goto parse_isv_prod_id;
+        break;
+      }
+
+      // required uint32 isv_prod_id = 11;
+      case 11: {
+        if (tag == 88) {
+         parse_isv_prod_id:
+          DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 input, &isv_prod_id_)));
+          set_has_isv_prod_id();
+        } else {
+          goto handle_unusual;
+        }
+        if (input->ExpectTag(96)) goto parse_isv_svn;
+        break;
+      }
+
+      // required uint32 isv_svn = 12;
+      case 12: {
+        if (tag == 96) {
+         parse_isv_svn:
+          DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 input, &isv_svn_)));
+          set_has_isv_svn();
+        } else {
+          goto handle_unusual;
+        }
+        if (input->ExpectAtEnd()) goto success;
+        break;
+      }
+
+      default: {
+      handle_unusual:
+        if (tag == 0 ||
+            ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
+            ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
+          goto success;
+        }
+        DO_(::google::protobuf::internal::WireFormatLite::SkipField(
+            input, tag, &unknown_fields_stream));
+        break;
+      }
+    }
+  }
+success:
+  // @@protoc_insertion_point(parse_success:protobuf_sgx_report_body_t)
+  return true;
+failure:
+  // @@protoc_insertion_point(parse_failure:protobuf_sgx_report_body_t)
+  return false;
+#undef DO_
+}
+
+void protobuf_sgx_report_body_t::SerializeWithCachedSizes(
+    ::google::protobuf::io::CodedOutputStream* output) const {
+  // @@protoc_insertion_point(serialize_start:protobuf_sgx_report_body_t)
+  // repeated uint32 cpu_svn = 1 [packed = true];
+  if (this->cpu_svn_size() > 0) {
+    ::google::protobuf::internal::WireFormatLite::WriteTag(1, ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output);
+    output->WriteVarint32(_cpu_svn_cached_byte_size_);
+  }
+  for (int i = 0; i < this->cpu_svn_size(); i++) {
+    ::google::protobuf::internal::WireFormatLite::WriteUInt32NoTag(
+      this->cpu_svn(i), output);
+  }
+
+  // repeated uint32 reserved1 = 2 [packed = true];
+  if (this->reserved1_size() > 0) {
+    ::google::protobuf::internal::WireFormatLite::WriteTag(2, ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output);
+    output->WriteVarint32(_reserved1_cached_byte_size_);
+  }
+  for (int i = 0; i < this->reserved1_size(); i++) {
+    ::google::protobuf::internal::WireFormatLite::WriteUInt32NoTag(
+      this->reserved1(i), output);
+  }
+
+  // repeated uint32 mr_enclave = 3 [packed = true];
+  if (this->mr_enclave_size() > 0) {
+    ::google::protobuf::internal::WireFormatLite::WriteTag(3, ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output);
+    output->WriteVarint32(_mr_enclave_cached_byte_size_);
+  }
+  for (int i = 0; i < this->mr_enclave_size(); i++) {
+    ::google::protobuf::internal::WireFormatLite::WriteUInt32NoTag(
+      this->mr_enclave(i), output);
+  }
+
+  // repeated uint32 reserved2 = 4 [packed = true];
+  if (this->reserved2_size() > 0) {
+    ::google::protobuf::internal::WireFormatLite::WriteTag(4, ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output);
+    output->WriteVarint32(_reserved2_cached_byte_size_);
+  }
+  for (int i = 0; i < this->reserved2_size(); i++) {
+    ::google::protobuf::internal::WireFormatLite::WriteUInt32NoTag(
+      this->reserved2(i), output);
+  }
+
+  // repeated uint32 mr_signer = 5 [packed = true];
+  if (this->mr_signer_size() > 0) {
+    ::google::protobuf::internal::WireFormatLite::WriteTag(5, ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output);
+    output->WriteVarint32(_mr_signer_cached_byte_size_);
+  }
+  for (int i = 0; i < this->mr_signer_size(); i++) {
+    ::google::protobuf::internal::WireFormatLite::WriteUInt32NoTag(
+      this->mr_signer(i), output);
+  }
+
+  // repeated uint32 reserved3 = 6 [packed = true];
+  if (this->reserved3_size() > 0) {
+    ::google::protobuf::internal::WireFormatLite::WriteTag(6, ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output);
+    output->WriteVarint32(_reserved3_cached_byte_size_);
+  }
+  for (int i = 0; i < this->reserved3_size(); i++) {
+    ::google::protobuf::internal::WireFormatLite::WriteUInt32NoTag(
+      this->reserved3(i), output);
+  }
+
+  // repeated uint32 reserved4 = 7 [packed = true];
+  if (this->reserved4_size() > 0) {
+    ::google::protobuf::internal::WireFormatLite::WriteTag(7, ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output);
+    output->WriteVarint32(_reserved4_cached_byte_size_);
+  }
+  for (int i = 0; i < this->reserved4_size(); i++) {
+    ::google::protobuf::internal::WireFormatLite::WriteUInt32NoTag(
+      this->reserved4(i), output);
+  }
+
+  // repeated uint32 report_data = 8 [packed = true];
+  if (this->report_data_size() > 0) {
+    ::google::protobuf::internal::WireFormatLite::WriteTag(8, ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output);
+    output->WriteVarint32(_report_data_cached_byte_size_);
+  }
+  for (int i = 0; i < this->report_data_size(); i++) {
+    ::google::protobuf::internal::WireFormatLite::WriteUInt32NoTag(
+      this->report_data(i), output);
+  }
+
+  // required uint32 misc_select = 9;
+  if (has_misc_select()) {
+    ::google::protobuf::internal::WireFormatLite::WriteUInt32(9, this->misc_select(), output);
+  }
+
+  // required .protobuf_sgx_attributes_t attributes = 10;
+  if (has_attributes()) {
+    ::google::protobuf::internal::WireFormatLite::WriteMessage(
+      10, this->attributes(), output);
+  }
+
+  // required uint32 isv_prod_id = 11;
+  if (has_isv_prod_id()) {
+    ::google::protobuf::internal::WireFormatLite::WriteUInt32(11, this->isv_prod_id(), output);
+  }
+
+  // required uint32 isv_svn = 12;
+  if (has_isv_svn()) {
+    ::google::protobuf::internal::WireFormatLite::WriteUInt32(12, this->isv_svn(), output);
+  }
+
+  output->WriteRaw(unknown_fields().data(),
+                   unknown_fields().size());
+  // @@protoc_insertion_point(serialize_end:protobuf_sgx_report_body_t)
+}
+
+int protobuf_sgx_report_body_t::ByteSize() const {
+  int total_size = 0;
+
+  if (_has_bits_[1 / 32] & (0xffu << (1 % 32))) {
+    // required uint32 misc_select = 9;
+    if (has_misc_select()) {
+      total_size += 1 +
+        ::google::protobuf::internal::WireFormatLite::UInt32Size(
+          this->misc_select());
+    }
+
+    // required .protobuf_sgx_attributes_t attributes = 10;
+    if (has_attributes()) {
+      total_size += 1 +
+        ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual(
+          this->attributes());
+    }
+
+  }
+  if (_has_bits_[8 / 32] & (0xffu << (8 % 32))) {
+    // required uint32 isv_prod_id = 11;
+    if (has_isv_prod_id()) {
+      total_size += 1 +
+        ::google::protobuf::internal::WireFormatLite::UInt32Size(
+          this->isv_prod_id());
+    }
+
+    // required uint32 isv_svn = 12;
+    if (has_isv_svn()) {
+      total_size += 1 +
+        ::google::protobuf::internal::WireFormatLite::UInt32Size(
+          this->isv_svn());
+    }
+
+  }
+  // repeated uint32 cpu_svn = 1 [packed = true];
+  {
+    int data_size = 0;
+    for (int i = 0; i < this->cpu_svn_size(); i++) {
+      data_size += ::google::protobuf::internal::WireFormatLite::
+        UInt32Size(this->cpu_svn(i));
+    }
+    if (data_size > 0) {
+      total_size += 1 +
+        ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);
+    }
+    GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+    _cpu_svn_cached_byte_size_ = data_size;
+    GOOGLE_SAFE_CONCURRENT_WRITES_END();
+    total_size += data_size;
+  }
+
+  // repeated uint32 reserved1 = 2 [packed = true];
+  {
+    int data_size = 0;
+    for (int i = 0; i < this->reserved1_size(); i++) {
+      data_size += ::google::protobuf::internal::WireFormatLite::
+        UInt32Size(this->reserved1(i));
+    }
+    if (data_size > 0) {
+      total_size += 1 +
+        ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);
+    }
+    GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+    _reserved1_cached_byte_size_ = data_size;
+    GOOGLE_SAFE_CONCURRENT_WRITES_END();
+    total_size += data_size;
+  }
+
+  // repeated uint32 mr_enclave = 3 [packed = true];
+  {
+    int data_size = 0;
+    for (int i = 0; i < this->mr_enclave_size(); i++) {
+      data_size += ::google::protobuf::internal::WireFormatLite::
+        UInt32Size(this->mr_enclave(i));
+    }
+    if (data_size > 0) {
+      total_size += 1 +
+        ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);
+    }
+    GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+    _mr_enclave_cached_byte_size_ = data_size;
+    GOOGLE_SAFE_CONCURRENT_WRITES_END();
+    total_size += data_size;
+  }
+
+  // repeated uint32 reserved2 = 4 [packed = true];
+  {
+    int data_size = 0;
+    for (int i = 0; i < this->reserved2_size(); i++) {
+      data_size += ::google::protobuf::internal::WireFormatLite::
+        UInt32Size(this->reserved2(i));
+    }
+    if (data_size > 0) {
+      total_size += 1 +
+        ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);
+    }
+    GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+    _reserved2_cached_byte_size_ = data_size;
+    GOOGLE_SAFE_CONCURRENT_WRITES_END();
+    total_size += data_size;
+  }
+
+  // repeated uint32 mr_signer = 5 [packed = true];
+  {
+    int data_size = 0;
+    for (int i = 0; i < this->mr_signer_size(); i++) {
+      data_size += ::google::protobuf::internal::WireFormatLite::
+        UInt32Size(this->mr_signer(i));
+    }
+    if (data_size > 0) {
+      total_size += 1 +
+        ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);
+    }
+    GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+    _mr_signer_cached_byte_size_ = data_size;
+    GOOGLE_SAFE_CONCURRENT_WRITES_END();
+    total_size += data_size;
+  }
+
+  // repeated uint32 reserved3 = 6 [packed = true];
+  {
+    int data_size = 0;
+    for (int i = 0; i < this->reserved3_size(); i++) {
+      data_size += ::google::protobuf::internal::WireFormatLite::
+        UInt32Size(this->reserved3(i));
+    }
+    if (data_size > 0) {
+      total_size += 1 +
+        ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);
+    }
+    GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+    _reserved3_cached_byte_size_ = data_size;
+    GOOGLE_SAFE_CONCURRENT_WRITES_END();
+    total_size += data_size;
+  }
+
+  // repeated uint32 reserved4 = 7 [packed = true];
+  {
+    int data_size = 0;
+    for (int i = 0; i < this->reserved4_size(); i++) {
+      data_size += ::google::protobuf::internal::WireFormatLite::
+        UInt32Size(this->reserved4(i));
+    }
+    if (data_size > 0) {
+      total_size += 1 +
+        ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);
+    }
+    GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+    _reserved4_cached_byte_size_ = data_size;
+    GOOGLE_SAFE_CONCURRENT_WRITES_END();
+    total_size += data_size;
+  }
+
+  // repeated uint32 report_data = 8 [packed = true];
+  {
+    int data_size = 0;
+    for (int i = 0; i < this->report_data_size(); i++) {
+      data_size += ::google::protobuf::internal::WireFormatLite::
+        UInt32Size(this->report_data(i));
+    }
+    if (data_size > 0) {
+      total_size += 1 +
+        ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);
+    }
+    GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+    _report_data_cached_byte_size_ = data_size;
+    GOOGLE_SAFE_CONCURRENT_WRITES_END();
+    total_size += data_size;
+  }
+
+  total_size += unknown_fields().size();
+
+  GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+  _cached_size_ = total_size;
+  GOOGLE_SAFE_CONCURRENT_WRITES_END();
+  return total_size;
+}
+
+void protobuf_sgx_report_body_t::CheckTypeAndMergeFrom(
+    const ::google::protobuf::MessageLite& from) {
+  MergeFrom(*::google::protobuf::down_cast<const protobuf_sgx_report_body_t*>(&from));
+}
+
+void protobuf_sgx_report_body_t::MergeFrom(const protobuf_sgx_report_body_t& from) {
+  GOOGLE_CHECK_NE(&from, this);
+  cpu_svn_.MergeFrom(from.cpu_svn_);
+  reserved1_.MergeFrom(from.reserved1_);
+  mr_enclave_.MergeFrom(from.mr_enclave_);
+  reserved2_.MergeFrom(from.reserved2_);
+  mr_signer_.MergeFrom(from.mr_signer_);
+  reserved3_.MergeFrom(from.reserved3_);
+  reserved4_.MergeFrom(from.reserved4_);
+  report_data_.MergeFrom(from.report_data_);
+  if (from._has_bits_[1 / 32] & (0xffu << (1 % 32))) {
+    if (from.has_misc_select()) {
+      set_misc_select(from.misc_select());
+    }
+    if (from.has_attributes()) {
+      mutable_attributes()->::protobuf_sgx_attributes_t::MergeFrom(from.attributes());
+    }
+  }
+  if (from._has_bits_[8 / 32] & (0xffu << (8 % 32))) {
+    if (from.has_isv_prod_id()) {
+      set_isv_prod_id(from.isv_prod_id());
+    }
+    if (from.has_isv_svn()) {
+      set_isv_svn(from.isv_svn());
+    }
+  }
+  mutable_unknown_fields()->append(from.unknown_fields());
+}
+
+void protobuf_sgx_report_body_t::CopyFrom(const protobuf_sgx_report_body_t& from) {
+  if (&from == this) return;
+  Clear();
+  MergeFrom(from);
+}
+
+bool protobuf_sgx_report_body_t::IsInitialized() const {
+  if ((_has_bits_[0] & 0x0000030a) != 0x0000030a) return false;
+
+  if (has_attributes()) {
+    if (!this->attributes().IsInitialized()) return false;
+  }
+  return true;
+}
+
+void protobuf_sgx_report_body_t::Swap(protobuf_sgx_report_body_t* other) {
+  if (other != this) {
+    cpu_svn_.Swap(&other->cpu_svn_);
+    std::swap(misc_select_, other->misc_select_);
+    reserved1_.Swap(&other->reserved1_);
+    std::swap(attributes_, other->attributes_);
+    mr_enclave_.Swap(&other->mr_enclave_);
+    reserved2_.Swap(&other->reserved2_);
+    mr_signer_.Swap(&other->mr_signer_);
+    reserved3_.Swap(&other->reserved3_);
+    std::swap(isv_prod_id_, other->isv_prod_id_);
+    std::swap(isv_svn_, other->isv_svn_);
+    reserved4_.Swap(&other->reserved4_);
+    report_data_.Swap(&other->report_data_);
+    std::swap(_has_bits_[0], other->_has_bits_[0]);
+    _unknown_fields_.swap(other->_unknown_fields_);
+    std::swap(_cached_size_, other->_cached_size_);
+  }
+}
+
+::std::string protobuf_sgx_report_body_t::GetTypeName() const {
+  return "protobuf_sgx_report_body_t";
+}
+
+
+// ===================================================================
+
+#ifndef _MSC_VER
+const int protobuf_sgx_report_t::kBodyFieldNumber;
+const int protobuf_sgx_report_t::kKeyIdFieldNumber;
+const int protobuf_sgx_report_t::kMacFieldNumber;
+#endif  // !_MSC_VER
+
+protobuf_sgx_report_t::protobuf_sgx_report_t()
+  : ::google::protobuf::MessageLite() {
+  SharedCtor();
+  // @@protoc_insertion_point(constructor:protobuf_sgx_report_t)
+}
+
+void protobuf_sgx_report_t::InitAsDefaultInstance() {
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+  body_ = const_cast< ::protobuf_sgx_report_body_t*>(
+      ::protobuf_sgx_report_body_t::internal_default_instance());
+#else
+  body_ = const_cast< ::protobuf_sgx_report_body_t*>(&::protobuf_sgx_report_body_t::default_instance());
+#endif
+}
+
+protobuf_sgx_report_t::protobuf_sgx_report_t(const protobuf_sgx_report_t& from)
+  : ::google::protobuf::MessageLite() {
+  SharedCtor();
+  MergeFrom(from);
+  // @@protoc_insertion_point(copy_constructor:protobuf_sgx_report_t)
+}
+
+void protobuf_sgx_report_t::SharedCtor() {
+  _cached_size_ = 0;
+  body_ = NULL;
+  ::memset(_has_bits_, 0, sizeof(_has_bits_));
+}
+
+protobuf_sgx_report_t::~protobuf_sgx_report_t() {
+  // @@protoc_insertion_point(destructor:protobuf_sgx_report_t)
+  SharedDtor();
+}
+
+void protobuf_sgx_report_t::SharedDtor() {
+  #ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+  if (this != &default_instance()) {
+  #else
+  if (this != default_instance_) {
+  #endif
+    delete body_;
+  }
+}
+
+void protobuf_sgx_report_t::SetCachedSize(int size) const {
+  GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+  _cached_size_ = size;
+  GOOGLE_SAFE_CONCURRENT_WRITES_END();
+}
+const protobuf_sgx_report_t& protobuf_sgx_report_t::default_instance() {
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+  protobuf_AddDesc_dhmsgs_2eproto();
+#else
+  if (default_instance_ == NULL) protobuf_AddDesc_dhmsgs_2eproto();
+#endif
+  return *default_instance_;
+}
+
+protobuf_sgx_report_t* protobuf_sgx_report_t::default_instance_ = NULL;
+
+protobuf_sgx_report_t* protobuf_sgx_report_t::New() const {
+  return new protobuf_sgx_report_t;
+}
+
+void protobuf_sgx_report_t::Clear() {
+  if (has_body()) {
+    if (body_ != NULL) body_->::protobuf_sgx_report_body_t::Clear();
+  }
+  key_id_.Clear();
+  mac_.Clear();
+  ::memset(_has_bits_, 0, sizeof(_has_bits_));
+  mutable_unknown_fields()->clear();
+}
+
+bool protobuf_sgx_report_t::MergePartialFromCodedStream(
+    ::google::protobuf::io::CodedInputStream* input) {
+#define DO_(EXPRESSION) if (!(EXPRESSION)) goto failure
+  ::google::protobuf::uint32 tag;
+  ::google::protobuf::io::StringOutputStream unknown_fields_string(
+      mutable_unknown_fields());
+  ::google::protobuf::io::CodedOutputStream unknown_fields_stream(
+      &unknown_fields_string);
+  // @@protoc_insertion_point(parse_start:protobuf_sgx_report_t)
+  for (;;) {
+    ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+    tag = p.first;
+    if (!p.second) goto handle_unusual;
+    switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
+      // required .protobuf_sgx_report_body_t body = 1;
+      case 1: {
+        if (tag == 10) {
+          DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
+               input, mutable_body()));
+        } else {
+          goto handle_unusual;
+        }
+        if (input->ExpectTag(18)) goto parse_key_id;
+        break;
+      }
+
+      // repeated uint32 key_id = 2 [packed = true];
+      case 2: {
+        if (tag == 18) {
+         parse_key_id:
+          DO_((::google::protobuf::internal::WireFormatLite::ReadPackedPrimitive<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 input, this->mutable_key_id())));
+        } else if (tag == 16) {
+          DO_((::google::protobuf::internal::WireFormatLite::ReadRepeatedPrimitiveNoInline<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 1, 18, input, this->mutable_key_id())));
+        } else {
+          goto handle_unusual;
+        }
+        if (input->ExpectTag(26)) goto parse_mac;
+        break;
+      }
+
+      // repeated uint32 mac = 3 [packed = true];
+      case 3: {
+        if (tag == 26) {
+         parse_mac:
+          DO_((::google::protobuf::internal::WireFormatLite::ReadPackedPrimitive<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 input, this->mutable_mac())));
+        } else if (tag == 24) {
+          DO_((::google::protobuf::internal::WireFormatLite::ReadRepeatedPrimitiveNoInline<
+                   ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
+                 1, 26, input, this->mutable_mac())));
+        } else {
+          goto handle_unusual;
+        }
+        if (input->ExpectAtEnd()) goto success;
+        break;
+      }
+
+      default: {
+      handle_unusual:
+        if (tag == 0 ||