0

Note:- This question is very similar to Passing C++ struct to enclave from app in Intel SGX . I am posting it again as the post is almost 1 year old, hoping that there might be some solution. Please delete this if you think this is duplicate.

I am developing an Intel SGX app. I have a class(called SkipList) with a struct(called node) inside it, in my untrusted app . I am trying to pass this struct as a *void**** with **[user_check] attribute into the enclave.

struct node {
    size_t key;
    T2 value;
    vector<size_t> hashlabel;
    vector<node*> forward;
};

Once I receive this inside the enclave I cast this into the struct type as below.

SkipList<int,string>::node* head = static_cast<SkipList<int,string>::node*>(Node);

When I start debugging this, I see that the address of "head" after casting is correct ( I checked this address on application side too, both addresses are same) and also the address of the "forward" member is correct. But when I try to see the elements of "forward", I can see only 1 element. Actually there should be more 15 elements.

Can someone please tell me if this is an issue with SGX STL implementation of vectors? Why am I not able to see it as expected ?

Naveen KH
  • 153
  • 2
  • 11
  • I am now trying to put everything into a std::unordered_map and sending it as a void* into the enclave. Can someone tell me if we can cast void* to std::unordered_map ? Because my IDE is saying I cannot. Isnt it not possible to cast void pointers to STL types ? – Naveen KH Jan 23 '19 at 12:31

1 Answers1

1

I was able to resolve the issue.

The problem was my node structure. If you see the second member of the structure, it is a template parameter. I had set it to string type during runtime. But the size of the string is not fixed at compile time. Since compiler does not know how long the size of the string is, it was not able to typecast correctly

SkipList<int,string>::node* head = static_cast<SkipList<int,string>::node*>(Node);

So the solution was to move the member value to the end of the structure :).

Now I have progressed further and stuck at another problem. The problem is that the std::hash calculation of a string varies inside and outside the enclave. I am trying to calculate the std::hash of a string in untrusted layer and then verify the same inside the enclave. Since enclave has its own implementation of stdlib, the implementation differs and hence the output of std::hash :(

Naveen KH
  • 153
  • 2
  • 11