I've written a very simple test to learn working with elliptic curve cryptography inside an enclave. But the key creation method fails with SGX_ERROR_UNEXPECTED.
Here is my enclave:
#include "Enc_t.h"
#include "sgx_trts.h"
#include "sgx_tcrypto.h"
int Test(sgx_status_t *error)
{
sgx_ecc_state_handle_t handle;
sgx_ec256_private_t sk;
sgx_ec256_public_t pk;
sgx_status_t status;
status = sgx_ecc256_open_context(&handle);
if (status)
{
*error = status;
return 1;
}
status = sgx_ecc256_create_key_pair(&sk, &pk, &handle);
if (status)
{
*error = status;
return 2;
}
*error = SGX_SUCCESS;
return 0;
}
and this is my host app:
#include "Enc_u.h"
#include "sgx_urts.h"
#include <cstdio>
#include <tchar.h>
#define ENC _T("../Debug/Enc.signed.dll")
int main()
{
sgx_status_t error;
sgx_enclave_id_t eid;
sgx_launch_token_t token;
int updated = 0;
int step;
error = sgx_create_enclave(ENC, SGX_DEBUG_FLAG, &token, &updated, &eid, nullptr);
if (error)
printf("Failed to create enclave\n");
Test(eid, &step, &error);
if (error)
printf("Failed on step %d\n", step);
return 0;
}
The result is error = 1 on step = 2.
Any ideas what I'm doing wrong or what I might have configured incorrectly? I'm using Visual Studio Community 2015 and Intel C++ Compiler 17.0.
P.S: This is a replica of my post on an Intel forum. If it's properly answered on each of these platforms, I'll post the answer to the other, also citing its author.
Use the statement below instead of status = sgx_ecc256_create_key_pair(&sk, &pk, &handle);
status = sgx_ecc256_create_key_pair(&sk, &pk, handle);