123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- #include "sgx_utils.h"
- #include "util.h"
- #include <stdlib.h>
- #include <string.h>
- #include "se_memcpy.h"
- #include "sgx_trts.h"
- #include "trts_inst.h"
- #include "se_cdefs.h"
- SGX_ACCESS_VERSION(tservice, 1)
- sgx_status_t sgx_create_report(const sgx_target_info_t *target_info, const sgx_report_data_t *report_data, sgx_report_t *report)
- {
- int i = 0;
-
-
-
- if(target_info)
- {
- if (!sgx_is_within_enclave(target_info, sizeof(*target_info)))
- return SGX_ERROR_INVALID_PARAMETER;
- for(i=0; i<SGX_TARGET_INFO_RESERVED1_BYTES; ++i)
- {
- if (target_info->reserved1[i] != 0)
- return SGX_ERROR_INVALID_PARAMETER;
- }
- for(i=0; i<SGX_TARGET_INFO_RESERVED2_BYTES; ++i)
- {
- if (target_info->reserved2[i] != 0)
- return SGX_ERROR_INVALID_PARAMETER;
- }
- }
-
- if(report_data && !sgx_is_within_enclave(report_data, sizeof(*report_data)))
- {
- return SGX_ERROR_INVALID_PARAMETER;
- }
-
- if(!report || !sgx_is_within_enclave(report, sizeof(*report)))
- {
- return SGX_ERROR_INVALID_PARAMETER;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- size_t size = ROUND_TO(sizeof(sgx_target_info_t), TARGET_INFO_ALIGN_SIZE) +
- ROUND_TO(sizeof(sgx_report_data_t), REPORT_DATA_ALIGN_SIZE) +
- ROUND_TO(sizeof(sgx_report_t), REPORT_ALIGN_SIZE);
- size += MAX(MAX(TARGET_INFO_ALIGN_SIZE, REPORT_DATA_ALIGN_SIZE), REPORT_ALIGN_SIZE) - 1;
- void *buffer = malloc(size);
- if(buffer == NULL)
- {
- return SGX_ERROR_OUT_OF_MEMORY;
- }
- memset(buffer, 0, size);
- size_t buf_ptr = reinterpret_cast<size_t>(buffer);
- buf_ptr = ROUND_TO(buf_ptr, REPORT_ALIGN_SIZE);
- sgx_report_t *tmp_report = reinterpret_cast<sgx_report_t *>(buf_ptr);
- buf_ptr += sizeof(*tmp_report);
- buf_ptr = ROUND_TO(buf_ptr, TARGET_INFO_ALIGN_SIZE);
- sgx_target_info_t *tmp_target_info = reinterpret_cast<sgx_target_info_t *>(buf_ptr);
- buf_ptr += sizeof(*tmp_target_info);
- buf_ptr = ROUND_TO(buf_ptr, REPORT_DATA_ALIGN_SIZE);
- sgx_report_data_t *tmp_report_data = reinterpret_cast<sgx_report_data_t *>(buf_ptr);
-
- if(target_info)
- {
- memcpy_s(tmp_target_info, sizeof(*tmp_target_info), target_info, sizeof(*target_info));
- }
- if(report_data)
- {
- memcpy_s(tmp_report_data, sizeof(*tmp_report_data), report_data, sizeof(*report_data));
- }
-
- do_ereport(tmp_target_info, tmp_report_data, tmp_report);
-
- memcpy_s(report, sizeof(*report), tmp_report, sizeof(*tmp_report));
-
- memset_s(buffer, size, 0, size);
- free(buffer);
- return SGX_SUCCESS;
- }
|