Intel® Software Guard Extensions (Intel® SGX)
Discussion board focused on hardware-based isolation and memory encryption to provide extended code protection in solutions.

sgx_ecc256_create_key_pair fail

AArya2
New Contributor I
1,493 Views

Hi,

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.

0 Kudos
1 Solution
Surenthar_S_Intel
1,493 Views

Hi,

use the below statement instead of this "status = sgx_ecc256_create_key_pair(&sk, &pk, &handle);"

  • status = sgx_ecc256_create_key_pair(&sk, &pk, handle);

-Surenthar

View solution in original post

0 Kudos
4 Replies
Surenthar_S_Intel
1,494 Views

Hi,

use the below statement instead of this "status = sgx_ecc256_create_key_pair(&sk, &pk, &handle);"

  • status = sgx_ecc256_create_key_pair(&sk, &pk, handle);

-Surenthar

0 Kudos
AArya2
New Contributor I
1,493 Views

It worked. Thank you!

0 Kudos
larguet__ramzi
Beginner
1,493 Views

hi Arya P,

I am very happy that it worked for you.

Could you please, Arya P, share the EDL file of  the Test() function, because I have a problem in thedeclaration of this function in my EDL file.

Thank you

0 Kudos
larguet__ramzi
Beginner
1,493 Views

hi,

How could I get the public key  created by the function sgx_ecc256_create_key_pair out of the enclave?

0 Kudos
Reply