Can't run sha256 more than once in intel sgx enclave

188 views Asked by At

So I'm trying to create two sha256 hashes in intel sgx using their cyrpto library. Currently, if I run the following:

sgx_sha256_hash_t *hash1;
int first = 1;
sgx_status_t = stat;
stat = sgx_sha256_msg( ( uint8_t * ) &first, 8, hash1 );

I have no problems, and I properly get hash1, however if I try

sgx_sha256_hash_t *hash1;
sgx_sha256_hash_t *hash2;
int first = 1;
int second = 2;
sgx_status_t = stat;
stat = sgx_sha256_msg( ( uint8_t * ) &first, 8, hash1 );
stat = sgx_sha256_msg( ( uint8_t * ) &second, 8, hash2 );

I get a segmentation fault. I tried doing this with the sha init, update, get_hash and close method instead, but with no imporved results, does anyone know why this might be? I was thinking I might be running out of memory in the enclave, if that's true, is there a way to expand my enclave?

1

There are 1 answers

5
Paul Sanders On

You are writing your hashes to a random location in memory through those two uninitialised pointers, hence the segfaults. Also, your src_len parameters are incorrect, and for completeness the first parameter should be const.

So, what you want is:

sgx_sha256_hash_t hash1;    // note: no asterisk
sgx_sha256_hash_t hash2;
int first = 1;
int second = 2;
sgx_status_t = stat;
stat = sgx_sha256_msg( ( const uint8_t * ) &first, sizeof (first), &hash1 );
stat = sgx_sha256_msg( ( const uint8_t * ) &second, sizeof (second), &hash2 );