<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Hi Swarup, in Intel® Software Guard Extensions (Intel® SGX)</title>
    <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Using-random-library-within-enclave/m-p/1074123#M380</link>
    <description>&lt;P&gt;Hi Swarup,&lt;/P&gt;

&lt;P&gt;1. The sgx_read_rand() function populates a buffer with random bytes. To turn these into an integer, you simply populate a buffer of the corresponding size (1 byte for an 8-bit integer, 2 bytes for a 16-bit integer, 4 bytes for a 32-bit integer, and 8 bytes for a 64-bit integer) and recast it to the appropriate integer type.&lt;/P&gt;

&lt;P&gt;A quick and easy way of doing this is:&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; uint32_t val;&amp;nbsp;&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sgx_read_rand((unsigned char *) &amp;amp;val, 4); &amp;nbsp;And you have an unsigned, 32-bit random number in val.&amp;nbsp;(Converting that to a number from 0 to N is an exercise for the reader. There are plenty of references online for unbiased algorithms that do this.)&lt;BR /&gt;
	&amp;nbsp;&lt;BR /&gt;
	2. std::random is part of the C++11 standard. At this time, enclaves only support the C++03 standard.&lt;/P&gt;

&lt;P&gt;Thanks and Reagrds,&lt;BR /&gt;
	Surenthar Selvaraj&lt;/P&gt;</description>
    <pubDate>Fri, 29 Jul 2016 03:59:18 GMT</pubDate>
    <dc:creator>Surenthar_S_Intel</dc:creator>
    <dc:date>2016-07-29T03:59:18Z</dc:date>
    <item>
      <title>Using random library within enclave</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Using-random-library-within-enclave/m-p/1074122#M379</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I need to generate random numbers (integers or double) and use binomial distribution within an enclave. The user guide mentions that &amp;lt;random.h&amp;gt; is not included for SGX, while a random number can be generated using sgx_read_rand function in &amp;lt;sgx_trts.h&amp;gt;.&lt;/P&gt;

&lt;P&gt;First, how do I use sgx_read_rand to generate random integers? It seems only unsigned char is added to the input buffer.&lt;/P&gt;

&lt;P&gt;Second, I want to use the binomial_distribution and beta_distribution class available in the standard &amp;lt;random.h&amp;gt;. How do I invoke this within the enclave?&lt;/P&gt;

&lt;P&gt;Any help is appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2016 17:27:55 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Using-random-library-within-enclave/m-p/1074122#M379</guid>
      <dc:creator>swarup</dc:creator>
      <dc:date>2016-07-27T17:27:55Z</dc:date>
    </item>
    <item>
      <title>Hi Swarup,</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Using-random-library-within-enclave/m-p/1074123#M380</link>
      <description>&lt;P&gt;Hi Swarup,&lt;/P&gt;

&lt;P&gt;1. The sgx_read_rand() function populates a buffer with random bytes. To turn these into an integer, you simply populate a buffer of the corresponding size (1 byte for an 8-bit integer, 2 bytes for a 16-bit integer, 4 bytes for a 32-bit integer, and 8 bytes for a 64-bit integer) and recast it to the appropriate integer type.&lt;/P&gt;

&lt;P&gt;A quick and easy way of doing this is:&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; uint32_t val;&amp;nbsp;&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sgx_read_rand((unsigned char *) &amp;amp;val, 4); &amp;nbsp;And you have an unsigned, 32-bit random number in val.&amp;nbsp;(Converting that to a number from 0 to N is an exercise for the reader. There are plenty of references online for unbiased algorithms that do this.)&lt;BR /&gt;
	&amp;nbsp;&lt;BR /&gt;
	2. std::random is part of the C++11 standard. At this time, enclaves only support the C++03 standard.&lt;/P&gt;

&lt;P&gt;Thanks and Reagrds,&lt;BR /&gt;
	Surenthar Selvaraj&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jul 2016 03:59:18 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Using-random-library-within-enclave/m-p/1074123#M380</guid>
      <dc:creator>Surenthar_S_Intel</dc:creator>
      <dc:date>2016-07-29T03:59:18Z</dc:date>
    </item>
  </channel>
</rss>

