[Assignment-7] security fix in sign_firmware

This commit is contained in:
Sascha Tommasone 2024-07-01 13:55:39 +02:00
parent 29f744edab
commit 0558e0870d
Signed by: saschato
GPG key ID: 751068A86FCAA217

View file

@ -85,15 +85,20 @@ sgx_status_t sign_firmware(uint8_t *data, size_t data_size, uint8_t *signature,
sgx_ec256_public_t public; sgx_ec256_public_t public;
sgx_status_t status; sgx_status_t status;
if((status = sgx_ecc256_open_context(&ecc_handle)) != SGX_SUCCESS) if((status = sgx_ecc256_open_context(&ecc_handle)) != SGX_SUCCESS) {
return status; return status;
}
if((status = sgx_ecc256_create_key_pair(&private, &public, ecc_handle)) != SGX_SUCCESS) if((status = sgx_ecc256_create_key_pair(&private, &public, ecc_handle)) != SGX_SUCCESS) {
sgx_ecc256_close_context(ecc_handle);
return status; return status;
}
sgx_ec256_signature_t ecc_signature; sgx_ec256_signature_t ecc_signature;
if((status = sgx_ecdsa_sign(data, data_size, &private, &ecc_signature, ecc_handle)) != SGX_SUCCESS) if((status = sgx_ecdsa_sign(data, data_size, &private, &ecc_signature, ecc_handle)) != SGX_SUCCESS) {
sgx_ecc256_close_context(ecc_handle);
return status; return status;
}
memcpy(signature, ecc_signature.x, SGX_ECP256_KEY_SIZE); memcpy(signature, ecc_signature.x, SGX_ECP256_KEY_SIZE);
memcpy(signature + SGX_ECP256_KEY_SIZE, ecc_signature.y, SGX_ECP256_KEY_SIZE); memcpy(signature + SGX_ECP256_KEY_SIZE, ecc_signature.y, SGX_ECP256_KEY_SIZE);