From cf82ac179492f181e1632ee5083b8ff4687a0469 Mon Sep 17 00:00:00 2001 From: Sascha Tommasone Date: Tue, 2 Jul 2024 23:15:10 +0200 Subject: [PATCH] [Assignment-7] public_key: renamed to get_public_key; improved error handling --- .../src/enclave/enclave.c | 21 +++++++++++-------- .../src/enclave/enclave.edl | 2 +- .../src/enclave/enclave.h | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Assignment 7 - SGX Hands-on/src/enclave/enclave.c b/Assignment 7 - SGX Hands-on/src/enclave/enclave.c index bdd0cbd..86441a9 100644 --- a/Assignment 7 - SGX Hands-on/src/enclave/enclave.c +++ b/Assignment 7 - SGX Hands-on/src/enclave/enclave.c @@ -127,24 +127,27 @@ sgx_status_t unseal_key_pair(const uint8_t *sealed, sgx_ec256_private_t *private return status; } -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 - if(sealed == NULL) - return SGX_ERROR_UNEXPECTED; +sgx_status_t get_public_key(const uint8_t *sealed, uint32_t sealed_size, uint8_t *gx, uint32_t gx_size, uint8_t *gy, uint32_t gy_size) { + // invalid parameter handling + if((sealed == NULL) || (sealed_size == 0)) { + return SGX_ERROR_INVALID_PARAMETER; + } // unseal public key + sgx_status_t status; sgx_ec256_public_t public; - if(unseal_key_pair(sealed, sealed_size, NULL, &public) != SGX_SUCCESS) { - return SGX_ERROR_UNEXPECTED; + if((status = unseal_key_pair(sealed, NULL, &public)) != SGX_SUCCESS) { + return status; } // copy public key into return buffers if((gx != NULL) && (gy != NULL)) { - memcpy(gx, public.gx, SGX_ECP256_KEY_SIZE); - memcpy(gy, public.gy, SGX_ECP256_KEY_SIZE); + memcpy(gx, public.gx, SK_SIZE); + memcpy(gy, public.gy, SK_SIZE); } - return SGX_SUCCESS; + // return success + return status; } sgx_status_t sign_firmware(const uint8_t *sealed, size_t sealed_size, uint8_t *data, size_t data_size, uint8_t *signature, size_t signature_size) { diff --git a/Assignment 7 - SGX Hands-on/src/enclave/enclave.edl b/Assignment 7 - SGX Hands-on/src/enclave/enclave.edl index 81363d4..8a930bd 100644 --- a/Assignment 7 - SGX Hands-on/src/enclave/enclave.edl +++ b/Assignment 7 - SGX Hands-on/src/enclave/enclave.edl @@ -44,7 +44,7 @@ enclave { public int get_signature_size(); public int get_public_key_size(); public int get_private_key_size(); - public sgx_status_t public_key([in, size=sealed_size]const uint8_t *sealed, size_t sealed_size, [out]uint8_t *gx, [out]uint8_t *gy); + public sgx_status_t get_public_key([in, size=sealed_size]const uint8_t *sealed, uint32_t sealed_size, [out, size=gx_size]uint8_t *gx, uint32_t gx_size, [out, size=gx_size]uint8_t *gy, uint32_t gy_size); public sgx_status_t sign_firmware([in, size=data_size]const uint8_t *sealed, size_t sealed_size, [in, size=data_size]uint8_t *data, size_t data_size, [out, size=signature_size]uint8_t *signature, size_t signature_size); }; diff --git a/Assignment 7 - SGX Hands-on/src/enclave/enclave.h b/Assignment 7 - SGX Hands-on/src/enclave/enclave.h index 2a26180..77dce7b 100644 --- a/Assignment 7 - SGX Hands-on/src/enclave/enclave.h +++ b/Assignment 7 - SGX Hands-on/src/enclave/enclave.h @@ -44,7 +44,7 @@ int get_signature_size(); int get_public_key_size(); int get_private_key_size(); -sgx_status_t public_key(const uint8_t *sealed, const size_t sealed_size, uint8_t *gx, uint8_t *gy); +sgx_status_t get_public_key(const uint8_t *sealed, const uint32_t sealed_size, uint8_t *gx, uint32_t gx_size, uint8_t *gy, uint32_t gy_size); sgx_status_t sign_firmware(const uint8_t *sealed, size_t sealed_size, uint8_t *data, size_t data_size, uint8_t *signature, size_t signature_size); #endif /* !_ENCLAVE_H_ */ \ No newline at end of file