From cb9917f7b40256b936c7b59511a9f14741055d90 Mon Sep 17 00:00:00 2001 From: Sascha Tommasone Date: Wed, 3 Jul 2024 16:57:53 +0200 Subject: [PATCH] [Assignment-7] new function 'static sgx_status_t verify_signature' --- 7-SGX_Hands-on/src/enclave/enclave.c | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/7-SGX_Hands-on/src/enclave/enclave.c b/7-SGX_Hands-on/src/enclave/enclave.c index 08cdee1..50bb056 100644 --- a/7-SGX_Hands-on/src/enclave/enclave.c +++ b/7-SGX_Hands-on/src/enclave/enclave.c @@ -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)) {