Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions App/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ int main(int argc, char const *argv[]) {
}
printf("Random number: %d\n", ptr);

// Perform a simple addition in the enclave
int a = ptr;
int b = 100;
status = ecall_add(global_eid, &ptr, a, b);
if (status != SGX_SUCCESS) {
std::cout << "Enclave addition failed :(" << std::endl;
return 1;
}
std::cout << "Enclave addition success! " << a << " + " << b << " = " << ptr << std::endl;

// Seal the random number
size_t sealed_size = sizeof(sgx_sealed_data_t) + sizeof(ptr);
uint8_t* sealed_data = (uint8_t*)malloc(sealed_size);
Expand All @@ -49,5 +59,13 @@ int main(int argc, char const *argv[]) {

std::cout << "Seal round trip success! Receive back " << unsealed << std::endl;


// Destroy enclave
status = sgx_destroy_enclave(global_eid);
if(status != SGX_SUCCESS) {
std::cout << "Fail to destroy enclave.\n" << std::endl;
return 1;
}

return 0;
}
14 changes: 14 additions & 0 deletions Enclave/Add/Add.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "Enclave_t.h"


/*
*@brief Performs a simple addition in the enclave
*
* @param a The first input for our simple addition
* @param b The second input for our simple addition
*
* @return Truthy if addition successful, falsy otherwise.
*/
int ecall_add(int a, int b) {
return a + b;
}
18 changes: 18 additions & 0 deletions Enclave/Add/Add.edl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
enclave {

// ECALLs
trusted {

/*
*@brief Performs a simple addition in the enclave
*
* @param a The first input for our simple addition
* @param b The second input for our simple addition
*
* @return Truthy if addition successful, falsy otherwise.
*/
public int ecall_add(int a, int b);

};

};
1 change: 1 addition & 0 deletions Enclave/Enclave.edl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
enclave {
from "Add/Add.edl" import *;
from "Sealing/Sealing.edl" import *;

trusted {
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ endif
Crypto_Library_Name := sgx_tcrypto

# Enclave_Cpp_Files := Enclave/Enclave.cpp $(wildcard Enclave/Edger8rSyntax/*.cpp) $(wildcard Enclave/TrustedLibrary/*.cpp)
Enclave_Cpp_Files := Enclave/Enclave.cpp Enclave/Sealing/Sealing.cpp
Enclave_Cpp_Files := Enclave/Enclave.cpp Enclave/Sealing/Sealing.cpp Enclave/Add/Add.cpp
# Enclave_Include_Paths := -IInclude -IEnclave -I$(SGX_SDK)/include -I$(SGX_SDK)/include/tlibc -I$(SGX_SDK)/include/stlport
Enclave_Include_Paths := -IEnclave -I$(SGX_SDK)/include -I$(SGX_SDK)/include/tlibc -I$(SGX_SDK)/include/stlport

Expand Down