- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please have a look at the code below. When I run this in software emulation, i.e., not with SGX_MODE=HW, then the output is very predictable (0, 1, 2, 3, 0, 1, 2, 3, ...). Other values of x give me similarly predictable sequences. This makes debugging programs relying on randomness very tedious. Compiling and running with SGX_MODE=HW produces "real" randomness.
What am I missing?
unsigned int r; unsigned int x = 4; for (int i=0 ;i<100;i++) { sgx_read_rand((unsigned char *) &r, sizeof(unsigned int)); r = r % x; printf("%u\n", r); }
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
By default, the simulation library uses a pseudo-random generator instead of the RDRAND instruction, see #ifndef SE_SIM below.
static sgx_status_t __do_get_rand32(uint32_t* rand_num) { #ifndef SE_SIM /* We expect the CPU has RDRAND support for HW mode. Otherwise, an exception will be thrown * do_rdrand() will try to call RDRAND for 10 times */ if(0 == do_rdrand(rand_num)) return SGX_ERROR_UNEXPECTED; #else /* use LCG in simulation mode */ *rand_num = get_rand_lcg(); #endif return SGX_SUCCESS; }
Enable that code section and build your tRTS library again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok, thanks!
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page