1

I am trying to pass two integers to the SGX enclave, combine them and then return the result back to the application. However, nothing seems to happen when compiling the code aside from the enclave getting created. No error given and it seemingly never reaches the ECALL function.

If anyone is aware of a tutorial that does this that I can use as reference then that would be hugely appreciated.

EDL:

enclave {
    from "sgx_tae_service.edl" import *;

    /* enum definition */
    enum TEE_ERROR {
        TEE_ERROR_INVALID_SIGNATURE = 0,
        TEE_ERROR_INVALID_COUNTER = 1,
        TEE_ERROR_INVALID_SECRET = 2
    };


    trusted {
        /* define ECALLs here. */
        public int in_enclave([in] int* a, [in] int* b);
};

    untrusted {
        /* define OCALLs here. */
        void ocall_print_int([out] int* i);
    };
};

Enclave.cpp

int in_enclave(int* a, int* b){
        ocall_print("In the Enclave.");
        int result =0;
        result = a + b;
        ocall_print_int(&result);

}

App.cpp

int test(void) {
    if (initialize_enclave(&global_eid, "enclave.token", "enclave.signed.so") < 0) {
        std::cout << "Fail to initialize enclave." << std::endl;
        return 1;
    }else{

    std::cout<<"Enclave made. "<<"\n";
}
        int a =34, b =23,point = 0;
        in_enclave(global_eid,&point,&a,&b);

    return 0;                                                                                                                                                                                                                                                                             }

1 Answers1

0

See the corrections below. The trusted function in_enclave receives a and b, computes the sum, and returns the result. In the (untrusted) application code the function result is placed in point.

When calling the function check the return value. The return value, from the perspective of the main application code, is of type sgx_status_t where OK is SGX_SUCCESS. There is a list of error codes in the SGX developer reference or look for sgx_error.h in the source code. In this example, we could use the value of status to find why the ecall failed.

EDL

    trusted {
        public int in_enclave(int a, int b);
    };

Enclave

    int in_enclave(int a, int b){
        return a + b;
    }

Application

    int a = 34, b = 23, point = 0;
    sgx_status_t status = in_enclave(global_eid, &point, a, b);
    if (SGX_SUCCESS != status) {
        // error occurred! 
    }
    printf("%d\n", point);
Daniel
  • 2,380
  • 29
  • 44