Added gmp

parent 5fba6748
......@@ -31,24 +31,22 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sgx_urts.h>
#include "create_enclave.h"
#include "secure_enclave_u.h"
#include "sgx_detect.h"
#include <gmp.h>
#include <sgx_urts.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "sgx_detect.h"
#include "secure_enclave_u.h"
#include "create_enclave.h"
#define ENCLAVE_NAME "secure_enclave.signed.so"
unsigned char *carray2Hex(const uint8_t *d, int _len) {
unsigned char *hex = malloc(2 * _len);
unsigned char* carray2Hex(const uint8_t *d, int _len) {
unsigned char* hex = malloc(2 * _len);
static char hexval[16] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
static char hexval[16] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
for (int j = 0; j < _len; j++) {
hex[j * 2] = hexval[((d[j] >> 4) & 0xF)];
......@@ -58,92 +56,87 @@ unsigned char* carray2Hex(const uint8_t *d, int _len) {
return hex;
}
int char2int( char _input ) {
if ( _input >= '0' && _input <= '9' )
int char2int(char _input) {
if (_input >= '0' && _input <= '9')
return _input - '0';
if
( _input >= 'A' && _input <= 'F' )
if (_input >= 'A' && _input <= 'F')
return _input - 'A' + 10;
if ( _input >= 'a' && _input <= 'f' )
if (_input >= 'a' && _input <= 'f')
return _input - 'a' + 10;
return -1;
}
void usage () {
void usage() {
fprintf(stderr, "usage: sgxd\n");
exit(1);
}
int main (int argc, char *argv[])
{
sgx_launch_token_t token= { 0 };
sgx_enclave_id_t eid= 0;
sgx_status_t status;
int updated= 0;
unsigned long support;
int opt;
sgx_launch_token_t token = {0};
sgx_enclave_id_t eid;
sgx_status_t status;
int updated;
while ( (opt= getopt(argc, argv, "h")) != -1 ) {
switch (opt) {
case 'h':
default:
usage();
}
}
void init_enclave() {
argc-= optind;
argv+= optind;
eid = 0;
updated = 0;
if ( argc != 0 ) usage();
/*
digits= strtoull(argv[0], NULL, 10);
if ( digits == 0 ) {
fprintf(stderr, "invalid digit count\n");
return 1;
}
*/
unsigned long support;
#ifndef SGX_HW_SIM
support= get_sgx_support();
if ( ! SGX_OK(support) ) {
support = get_sgx_support();
if (!SGX_OK(support)) {
sgx_support_perror(support);
return 1;
exit(1);
}
#endif
status= sgx_create_enclave_search(ENCLAVE_NAME, SGX_DEBUG_FLAG,
&token, &updated, &eid, 0);
status = sgx_create_enclave_search(ENCLAVE_NAME, SGX_DEBUG_FLAG, &token,
&updated, &eid, 0);
if ( status != SGX_SUCCESS ) {
if ( status == SGX_ERROR_ENCLAVE_FILE_ACCESS ) {
fprintf(stderr, "sgx_create_enclave: %s: file not found\n",
ENCLAVE_NAME);
if (status != SGX_SUCCESS) {
if (status == SGX_ERROR_ENCLAVE_FILE_ACCESS) {
fprintf(stderr, "sgx_create_enclave: %s: file not found\n", ENCLAVE_NAME);
fprintf(stderr, "Did you forget to set LD_LIBRARY_PATH?\n");
} else {
fprintf(stderr, "%s: 0x%04x\n", ENCLAVE_NAME, status);
}
return 1;
exit(1);
}
fprintf(stderr, "Enclave launched\n");
status= tgmp_init(eid);
if ( status != SGX_SUCCESS ) {
status = tgmp_init(eid);
if (status != SGX_SUCCESS) {
fprintf(stderr, "ECALL tgmp_init: 0x%04x\n", status);
return 1;
exit(1);
}
fprintf(stderr, "libtgmp initialized\n");
}
int main(int argc, char *argv[]) {
const char* key = "4160780231445160889237664391382223604184857153814275770598791864649971919844";
int opt;
while ((opt = getopt(argc, argv, "h")) != -1) {
switch (opt) {
case 'h':
default:
usage();
}
}
argc -= optind;
argv += optind;
if (argc != 0)
usage();
init_enclave();
const char *key = "4160780231445160889237664391382223604184857153814275770598"
"791864649971919844";
char keyArray[128];
......@@ -151,30 +144,24 @@ int main (int argc, char *argv[])
strncpy(keyArray, key, 128);
int err_status = -2;
int err_status = 0;
int enc_len = -1;
int enc_len = 0;
status = encrypt_key(eid, &err_status, keyArray, encryptedKey, &enc_len);
status= encrypt_key(eid, &err_status, keyArray, encryptedKey, &enc_len);
if ( status != SGX_SUCCESS || enc_len < 10 ) {
if (status != SGX_SUCCESS || enc_len < 10) {
fprintf(stderr, "ECALL encrypt_key: 0x%04x\n", status);
return 1;
}
gmp_printf("Encrypt key completed with status: %d \n", err_status);
unsigned char* result = carray2Hex(encryptedKey, enc_len);
unsigned char *result = carray2Hex(encryptedKey, enc_len);
gmp_printf("Result: %s", result);
gmp_printf("\n Length: %d \n", enc_len);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment