Assignment-7-sgximpl #13

Merged
saschato merged 62 commits from Assignment-7-sgximpl into Assignment-7 2024-07-08 11:03:28 +02:00
Showing only changes of commit 29f744edab - Show all commits

View file

@ -3,6 +3,42 @@
#include <sgx_error.h> #include <sgx_error.h>
#include <sgx_tcrypto.h> #include <sgx_tcrypto.h>
sgx_status_t seal_key_pair(sgx_ec256_private_t *private, sgx_ec256_public_t *public, uint8_t *sealed, uint32_t *sealed_size) {
// handle missing keypair
if((private == NULL) || (public == NULL))
return SGX_ERROR_UNEXPECTED;
// allocate temporary buffers on stack
uint8_t pk[2*SGX_ECP256_KEY_SIZE] = {0};
uint8_t sk[SGX_ECP256_KEY_SIZE] = {0};
// copy keypair into buffers
memcpy(pk, public->gx, SGX_ECP256_KEY_SIZE);
memcpy(pk + SGX_ECP256_KEY_SIZE, public->gy, SGX_ECP256_KEY_SIZE);
memcpy(sk, private->r, SGX_ECP256_KEY_SIZE);
// calculate needed size
*sealed_size = sgx_calc_sealed_data_size((uint32_t)(2*SGX_ECP256_KEY_SIZE), (uint32_t)SGX_ECP256_KEY_SIZE);
if(*sealed_size == UINT32_MAX)
return SGX_ERROR_UNEXPECTED;
// allocate buffer on heap
sealed = (uint8_t *)malloc(*sealed_size);
if(sealed == NULL) {
free(sealed);
return SGX_ERROR_OUT_OF_MEMORY;
}
// seal keypair
sgx_status_t status = sgx_seal_data((uint32_t)2*SGX_ECP256_KEY_SIZE, (const uint8_t *)pk, (uint32_t)SGX_ECP256_KEY_SIZE, (uint8_t *)sk, *sealed_size, (sgx_sealed_data_t *) sealed);
if(status != SGX_SUCCESS) {
free(sealed);
return SGX_ERROR_UNEXPECTED;
}
return SGX_SUCCESS;
}
sgx_status_t public_key(const uint8_t *sealed, const size_t sealed_size, uint8_t *gx, uint8_t *gy) { sgx_status_t public_key(const uint8_t *sealed, const size_t sealed_size, uint8_t *gx, uint8_t *gy) {
// return if no sealed data provided // return if no sealed data provided
if(sealed == NULL) if(sealed == NULL)