Transforms.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // Created by miti on 2019-12-21.
  3. //
  4. #ifndef VERIFIER_INITIATOR_TRANSFORMS_H
  5. #define VERIFIER_INITIATOR_TRANSFORMS_H
  6. #include "sgx_eid.h"
  7. #include "error_codes.h"
  8. #include "datatypes.h"
  9. #include "sgx_urts.h"
  10. #include "sgx_dh.h"
  11. // For msg1
  12. #define SGX_TARGET_INFO_RESERVED1_BYTES 4
  13. #define SGX_TARGET_INFO_RESERVED2_BYTES 456
  14. #define SGX_ECP256_KEY_SIZE 32
  15. #define SGX_HASH_SIZE 32 /* SHA256 */
  16. // For msg2
  17. #define SGX_REPORT_DATA_SIZE 64
  18. #define SGX_KEYID_SIZE 32
  19. #define SGX_DH_MAC_SIZE 16
  20. #define SGX_REPORT_BODY_RESERVED1 28
  21. #define SGX_REPORT_BODY_RESERVED2 32
  22. #define SGX_REPORT_BODY_RESERVED3 96
  23. #define SGX_REPORT_BODY_RESERVED4 60
  24. #include <stdio.h>
  25. // For google protobufs and deserialization/serialization
  26. #include "ProtobufLAMessages.pb.h"
  27. #include <google/protobuf/io/coded_stream.h>
  28. #include <google/protobuf/io/zero_copy_stream_impl.h>
  29. using namespace google::protobuf::io;
  30. #include <inttypes.h>
  31. class Transforms {
  32. static int fit_32_into_uint8_t(google::protobuf::uint32 temp32, uint8_t* temp8);
  33. static int fit_32_into_uint16_t(google::protobuf::uint32 temp32, uint16_t* temp16);
  34. static void encode_ec256_public_key_to_protobuf(protobuf_sgx_ec256_public_t* protobuf_g_a , sgx_ec256_public_t* g_a);
  35. static int decode_ec256_public_key_from_protobuf(protobuf_sgx_ec256_public_t* protobuf_g_a , sgx_ec256_public_t* g_a);
  36. static void encode_attributes_to_protobuf(protobuf_sgx_attributes_t* protobuf_attributes, sgx_attributes_t* attributes);
  37. static void encode_report_to_protobuf(protobuf_sgx_report_t* protobuf_report, sgx_report_t* report);
  38. static int decode_attributes_from_protobuf(protobuf_sgx_attributes_t* protobuf_attributes, sgx_attributes_t* attributes);
  39. static int decode_report_from_protobuf(protobuf_sgx_report_t* protobuf_report, sgx_report_t* report);
  40. public:
  41. static int decode_msg1_from_protobuf( protobuf_sgx_dh_msg1_t& protobuf_dhmsg1, sgx_dh_msg1_t* native_dhmsg1);
  42. static int decode_msg3_from_protobuf(protobuf_sgx_dh_msg3_t& protobuf_dhmsg3, sgx_dh_msg3_t* native_dhmsg3);
  43. static void encode_msg2_to_protobuf( protobuf_sgx_dh_msg2_t& protobuf_dhmsg2, sgx_dh_msg2_t* native_dhmsg2);
  44. static int print_initialized_msg1( protobuf_sgx_dh_msg1_t& protobuf_dhmsg1);
  45. };
  46. #endif //VERIFIER_INITIATOR_TRANSFORMS_H