7 Replies Latest reply on Dec 5, 2014 2:34 AM by mhahn

    /dev/random and Edison

    mcabral

      Hi there,

       

      Does anybody know if  /dev/random on Edison is random (not pseudo-random) ? Is /dev/random fed by some hardware on the Edison ?

       

      thanks!

        • 1. Re: /dev/random and Edison
          mhahn

          I guess RDRAND should be one source for /dev/random entropy

          • 2. Re: /dev/random and Edison
            mcabral

            Thanks - so http://en.wikipedia.org/wiki/RdRand  is officially available at the Intel Edison ?


             

            • 3. Re: /dev/random and Edison
              mhahn

              cat /proc/cpuinfo

              [...]

              flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx rdtscp lm constant_tsc arch_perfmon pebs bts xtopology nonstop_tsc aperfmperf nonstop_tsc_s3 pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm sse4_1 sse4_2 movbe popcnt tsc_deadline_timer aes rdrand lahf_lm 3dnowprefetch ida arat epb dtherm tpr_shadow vnmi flexpriority ept vpid tsc_adjust smep erms

              [...]

              • 4. Re: /dev/random and Edison
                mcabral

                Thanks mhahn

                • 5. Re: /dev/random and Edison
                  hk101

                  Not sure how to use RdRand in  a c prog? I need to generate a random number, so I included math.h

                  but unable to find random or rand functions.

                   

                  Any code snippet would help.

                   

                  Thanks in advance,

                  • 6. Re: /dev/random and Edison
                    mhahn

                    hk101 "Not sure how to use RdRand in  a c prog?"

                     

                    you may have a look on Intel® Digital Random Number Generator (DRNG) Software Implementation Guide | Intel® Developer Zone.

                    From there you can download sample code: https://software.intel.com/sites/default/files/managed/c5/d8/drng_samples_0514.tgz

                    Just follow the README to compile the code. Below running the compiled sample on Intel(R) Edison:

                     

                    # ./testdrng
                    This CPU supports the RDRAND instruction
                    This CPU does not support the RDSEED instruction
                    RDRAND without retries
                    rand16= 20472
                    rand32= 408006393
                    RDRAND with up to 10 retries, each
                    rand16= 44158
                    rand32= 2153658120
                    Fill an array of 16 unsigned ints with random values
                    Got 16 rands:
                    val[0]= 1728893872
                    val[1]= 2017116121
                    val[2]= 433132553
                    val[3]= 2342905587
                    val[4]= 3124925269
                    val[5]= 1457122969
                    val[6]= 3821026880
                    val[7]= 575284211
                    val[8]= 1915252668
                    val[9]= 549585579
                    val[10]= 597455724
                    val[11]= 3003994417
                    val[12]= 2980331772
                    val[13]= 4072111801
                    val[14]= 2269136231
                    val[15]= 1767551203
                    Fill unaligned buffer with 112 random bytes
                    Got 112 bytes:
                    0xffffffffbf940e20:  00 00 00 00 00 A1 7C AD  79 91 F8 59 68 6F 8C ED
                    0xffffffffbf940e30:  BD 02 31 FF 56 64 C4 D0  EF F4 22 1B AE 72 55 59
                    0xffffffffbf940e40:  CA 8E FE 6B 59 96 CC 08  58 1E 75 43 9D 3A A9 99
                    0xffffffffbf940e50:  D7 74 1D 39 C4 DF 51 20  F0 91 36 A1 76 BD 78 81
                    0xffffffffbf940e60:  BA E7 01 9C 8F 96 E5 61  24 E6 E6 9F 0F 21 81 82
                    0xffffffffbf940e70:  33 FC BD DE 45 50 B0 15  10 91 6F 46 5B 68 55 FA
                    0xffffffffbf940e80:  C0 B3 54 7C B9 BB 40 80  08 A0 B9 34 DA D1 22 16
                    0xffffffffbf940e90:  41 F2 2D CA 01 00 00 00  00 00 00 00 00 00 00 00
                    Fill an aligned buffer with 128 random bytes
                    Got 128 bytes:
                    0xffffffffbf940e20:  8E F7 67 AD F6 3F D2 25  9D 4B 84 C3 30 C5 A2 34
                    0xffffffffbf940e30:  81 C5 8A F6 21 DA 5A 8E  8C 9D 13 69 28 B4 0C 8C
                    0xffffffffbf940e40:  A9 93 E1 C8 D3 0D 3B F1  85 F5 3E 89 AD C0 DA 84
                    0xffffffffbf940e50:  D5 50 6F DB 63 21 E7 2A  E7 CD A8 CF 9C 66 B0 D8
                    0xffffffffbf940e60:  14 F0 C8 B7 D1 6D 98 9C  9B 9D 41 8B D4 30 47 83
                    0xffffffffbf940e70:  BB 69 B2 0D A0 24 CB E6  DD 11 73 70 06 51 95 0F
                    0xffffffffbf940e80:  57 74 A1 ED A5 22 1F CC  D2 73 C4 01 44 22 20 ED
                    0xffffffffbf940e90:  AD 4D 0C B1 0D F1 E6 AB  C1 C9 5A A1 37 FA 1D 03
                    
                    • 7. Re: /dev/random and Edison
                      mhahn

                      I need to generate a random number, so I included math.h

                       

                      #include <stdlib.h>

                       

                      would be your friend on that - but that's standard C. Just do a quick online search.