[Assignment-7] new function 'static sgx_status_t verify_signature'

This commit is contained in:
Sascha Tommasone 2024-07-03 16:57:53 +02:00
parent 1a9db0a0f3
commit cb9917f7b4
Signed by: saschato
GPG key ID: 751068A86FCAA217

View file

@ -161,6 +161,39 @@ sgx_status_t get_public_key(const uint8_t *sealed, uint32_t sealed_size, uint8_t
return status;
}
static sgx_status_t verify_signature(const uint8_t *data, const uint32_t data_size, const sgx_ec256_public_t *public, const sgx_ec256_signature_t* ecc_signature) {
// invalid parameter handling
if((data == NULL) || (data_size == 0)) {
return SGX_ERROR_INVALID_PARAMETER;
} else if(public == NULL) {
return SGX_ERROR_INVALID_PARAMETER;
} else if(ecc_signature == NULL) {
return SGX_ERROR_INVALID_PARAMETER;
}
// declare needed structure
sgx_ecc_state_handle_t ecc_handle;
// open ecc handle
sgx_status_t status;
if((status = sgx_ecc256_open_context(&ecc_handle)) != SGX_SUCCESS) {
return status;
}
// verify signature
uint8_t result;
sgx_status_t verification_status = sgx_ecdsa_verify(data, data_size, public, ecc_signature, &result, ecc_handle);
// handle failed verification process
if(verification_status != SGX_SUCCESS) {
result = verification_status;
}
// close context and return valid signature
sgx_ecc256_close_context(ecc_handle);
return result;
}
sgx_status_t sign_firmware(const uint8_t *data, uint32_t data_size, uint8_t *sealed, uint32_t sealed_size, uint8_t *signature, uint32_t signature_size) {
// invalid parameter handling
if((data == NULL) || (data_size == 0)) {