// // Created by miti on 21/07/19. // #include "protobufSgxTransformsInitiator.h" namespace protobufSgxTransformsInitiator { 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; protobufSgxTransformsHelper::encode_ec256_public_key_to_protobuf(protobuf_dhmsg1.mutable_g_a(), &(native_dhmsg1->g_a)); for(counter=0;countertarget.mr_enclave.m[counter]; protobuf_dhmsg1.mutable_target()->add_mr_enclave(temp32); } for(counter=0;countertarget.reserved1[counter]; protobuf_dhmsg1.mutable_target()->add_reserved1(temp32); } for(counter=0;countertarget.reserved2[counter]; protobuf_dhmsg1.mutable_target()->add_reserved2(temp32); } protobufSgxTransformsHelper::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;countercmac[counter]; protobuf_dhmsg3.add_cmac(temp32); } protobufSgxTransformsHelper::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;counteradd_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("RECEIVED the following msg2\n"); fflush(stdout); printf("\ncmac\n"); for(counter=0;countercmac[counter]))!=0) return -1; printf("%02x ",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("Printing msg1:\n"); printf("gx\n"); for(counter=0;counterg_a.gx[counter]); } printf("\ngy\n"); for(counter=0;counterg_a.gy[counter]); } printf("\nmrenclave for target\n"); for(counter=0;countertarget.mr_enclave.m[counter]); } printf("\nreserved1 in target\n"); for(counter=0;countertarget.reserved1[counter]); } printf("\nreserved2 in target\n"); for(counter=0;countertarget.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()); fflush(stdout); return 0; } };