Intel® Software Guard Extensions (Intel® SGX)
Discussion board focused on hardware-based isolation and memory encryption to provide extended code protection in solutions.
1457 Discussions

How to use <iostream> of C++, time() rand() srand() of C, at Enclave.cpp

MoonHasSevenColor
1,063 Views

Hello Intel Community,

 

  May I ask how can I use std::cout at Enclave.cpp? And time(), rand() and srand() of C standard libraries?

  I have tried above functions, but it reports undefined reference error for time(), rand() and srand(). And error: cout is not a member of std, when I has written #include <iostream> reference. Thank you!

 I attach the code for your review:) if needed. You can make at the root, and then ./app 

 Have a nice day! 

 

 

 

Best Regards,

Jin Xin

0 Kudos
1 Solution
Wan_Intel
Moderator
1,005 Views

Hello MoonHasSevenColor,

Thanks for your patience.


Referring to Page 472 in Intel® SGX Developer Reference Linux 2.20 Open Source document, std::cout from class <iostream> is not supported by Intel® SGX. As a workaround to accessing <iostream> functions within an Enclave, create an Ocall that calls the <iostream> functions in the untrusted app on behalf of the enclave.

 

The following example in the Intel® SGX Software Development Kit (Intel® SGX) demonstrates how to implement an Ocall for using printf within an enclave:

https://github.com/intel/linux-sgx/tree/master/SampleCode/SampleEnclave

 

On another note, referring to pages 468 and 469 in Intel® SGX Developer Reference Linux 2.20 Open Source document, time(), rand(), and srand() are not supported by Intel® SGX. As a workaround for rand() and srand(), enclave developers should use the sgx_read_rand function to get true random numbers.

 

For more information, please refer to the following page in Intel® SGX Developer Reference Linux 2.20 Open Source document and links:



Regards,

Wan


View solution in original post

4 Replies
Wan_Intel
Moderator
1,028 Views

Hello MoonHasSevenColor,

Thanks for reaching out to us.

Let me check with relevant team and I'll update you as soon as possible.



Regards,

Wan


0 Kudos
Wan_Intel
Moderator
1,006 Views

Hello MoonHasSevenColor,

Thanks for your patience.


Referring to Page 472 in Intel® SGX Developer Reference Linux 2.20 Open Source document, std::cout from class <iostream> is not supported by Intel® SGX. As a workaround to accessing <iostream> functions within an Enclave, create an Ocall that calls the <iostream> functions in the untrusted app on behalf of the enclave.

 

The following example in the Intel® SGX Software Development Kit (Intel® SGX) demonstrates how to implement an Ocall for using printf within an enclave:

https://github.com/intel/linux-sgx/tree/master/SampleCode/SampleEnclave

 

On another note, referring to pages 468 and 469 in Intel® SGX Developer Reference Linux 2.20 Open Source document, time(), rand(), and srand() are not supported by Intel® SGX. As a workaround for rand() and srand(), enclave developers should use the sgx_read_rand function to get true random numbers.

 

For more information, please refer to the following page in Intel® SGX Developer Reference Linux 2.20 Open Source document and links:



Regards,

Wan


MoonHasSevenColor
881 Views

Dear Wan,

 

  Sorry for the late reply! Thank you for your patient and nice answer, it helps a lot. Thank you!

 

 

Best Regards,

Jin Xin

Wan_Intel
Moderator
925 Views

Hello MoonHasSevenColor,

Thanks for your question.


If you need additional information from Intel, please submit a new question as this thread will no longer be monitored.



Regards,

Wan


0 Kudos
Reply