This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How random for your random generator?

Hi. I'm using nRF52832, SDK13.0.0.

The roll is peripheral.

And I'm using Oberon to use ECDH.

I think you have the result or document for random generator's performance based on Shannon or NIST or DieHard tests.

Could you please let me know your result?

Parents Reply Children
  • Thank you so much for your help. And I checked biad correction, it is enabled.

    But as I've tested with Dieharder, the result is not good as below.

    #=============================================================================#
    #            dieharder version 3.31.1 Copyright 2003 Robert G. Brown          #
    #=============================================================================#
       rng_name    |           filename             |rands/second|
         file_input|            rng_20190918_007.txt|  4.12e+06  |
    #=============================================================================#
            test_name   |ntup| tsamples |psamples|  p-value |Assessment
    #=============================================================================#
    # The file file_input was rewound 138 times
       diehard_birthdays|   0|       100|     100|0.84572623|  PASSED 
    # The file file_input was rewound 1138 times
          diehard_operm5|   0|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 2418 times
      diehard_rank_32x32|   0|     40000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 3018 times
        diehard_rank_6x8|   0|    100000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 3280 times
       diehard_bitstream|   0|   2097152|     100|0.00000009|  FAILED 
    # The file file_input was rewound 5377 times
            diehard_opso|   0|   2097152|     100|0.00000000|  FAILED 
    # The file file_input was rewound 6775 times
            diehard_oqso|   0|   2097152|     100|0.00000000|  FAILED 
    # The file file_input was rewound 7431 times
             diehard_dna|   0|   2097152|     100|0.00000000|  FAILED 
    # The file file_input was rewound 7495 times
    diehard_count_1s_str|   0|    256000|     100|0.00000294|   WEAK  
    # The file file_input was rewound 8775 times
    diehard_count_1s_byt|   0|    256000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 8799 times
     diehard_parking_lot|   0|     12000|     100|0.01394685|  PASSED 
    # The file file_input was rewound 8815 times
        diehard_2dsphere|   2|      8000|     100|0.00000599|   WEAK  
    # The file file_input was rewound 8827 times
        diehard_3dsphere|   3|      4000|     100|0.00233700|   WEAK  
    # The file file_input was rewound 11136 times
         diehard_squeeze|   0|    100000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 11136 times
            diehard_sums|   0|       100|     100|0.24065238|  PASSED 
    # The file file_input was rewound 11236 times
            diehard_runs|   0|    100000|     100|0.00000000|  FAILED 
            diehard_runs|   0|    100000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 12593 times
           diehard_craps|   0|    200000|     100|0.00000000|  FAILED 
           diehard_craps|   0|    200000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 32593 times
     marsaglia_tsang_gcd|   0|  10000000|     100|0.00000000|  FAILED 
     marsaglia_tsang_gcd|   0|  10000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 32693 times
             sts_monobit|   1|    100000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 32793 times
                sts_runs|   2|    100000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 32893 times
              sts_serial|   1|    100000|     100|0.00000000|  FAILED 
              sts_serial|   2|    100000|     100|0.00000000|  FAILED 
              sts_serial|   3|    100000|     100|0.00000000|  FAILED 
              sts_serial|   3|    100000|     100|0.00000000|  FAILED 
              sts_serial|   4|    100000|     100|0.00000000|  FAILED 
              sts_serial|   4|    100000|     100|0.00000000|  FAILED 
              sts_serial|   5|    100000|     100|0.00000000|  FAILED 
              sts_serial|   5|    100000|     100|0.00000000|  FAILED 
              sts_serial|   6|    100000|     100|0.00000000|  FAILED 
              sts_serial|   6|    100000|     100|0.00000000|  FAILED 
              sts_serial|   7|    100000|     100|0.00000000|  FAILED 
              sts_serial|   7|    100000|     100|0.00000000|  FAILED 
              sts_serial|   8|    100000|     100|0.00000000|  FAILED 
              sts_serial|   8|    100000|     100|0.00000000|  FAILED 
              sts_serial|   9|    100000|     100|0.00000000|  FAILED 
              sts_serial|   9|    100000|     100|0.00000000|  FAILED 
              sts_serial|  10|    100000|     100|0.00000000|  FAILED 
              sts_serial|  10|    100000|     100|0.00000000|  FAILED 
              sts_serial|  11|    100000|     100|0.00000000|  FAILED 
              sts_serial|  11|    100000|     100|0.00000000|  FAILED 
              sts_serial|  12|    100000|     100|0.00000000|  FAILED 
              sts_serial|  12|    100000|     100|0.00000000|  FAILED 
              sts_serial|  13|    100000|     100|0.00000000|  FAILED 
              sts_serial|  13|    100000|     100|0.00000000|  FAILED 
              sts_serial|  14|    100000|     100|0.00000000|  FAILED 
              sts_serial|  14|    100000|     100|0.00000000|  FAILED 
              sts_serial|  15|    100000|     100|0.00000000|  FAILED 
              sts_serial|  15|    100000|     100|0.00000000|  FAILED 
              sts_serial|  16|    100000|     100|0.00000000|  FAILED 
              sts_serial|  16|    100000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 33093 times
             rgb_bitdist|   1|    100000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 33493 times
             rgb_bitdist|   2|    100000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 34093 times
             rgb_bitdist|   3|    100000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 34893 times
             rgb_bitdist|   4|    100000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 35893 times
             rgb_bitdist|   5|    100000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 37093 times
             rgb_bitdist|   6|    100000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 38493 times
             rgb_bitdist|   7|    100000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 40093 times
             rgb_bitdist|   8|    100000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 41893 times
             rgb_bitdist|   9|    100000|     100|0.00000004|  FAILED 
    # The file file_input was rewound 43893 times
             rgb_bitdist|  10|    100000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 46093 times
             rgb_bitdist|  11|    100000|     100|0.00000012|  FAILED 
    # The file file_input was rewound 48493 times
             rgb_bitdist|  12|    100000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 48693 times
    rgb_minimum_distance|   2|     10000|    1000|0.00000000|  FAILED 
    # The file file_input was rewound 48993 times
    rgb_minimum_distance|   3|     10000|    1000|0.00000000|  FAILED 
    # The file file_input was rewound 49393 times
    rgb_minimum_distance|   4|     10000|    1000|0.00000000|  FAILED 
    # The file file_input was rewound 49893 times
    rgb_minimum_distance|   5|     10000|    1000|0.00000000|  FAILED 
    # The file file_input was rewound 50093 times
        rgb_permutations|   2|    100000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 50393 times
        rgb_permutations|   3|    100000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 50793 times
        rgb_permutations|   4|    100000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 51293 times
        rgb_permutations|   5|    100000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 52293 times
          rgb_lagged_sum|   0|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 54293 times
          rgb_lagged_sum|   1|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 57293 times
          rgb_lagged_sum|   2|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 61293 times
          rgb_lagged_sum|   3|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 66293 times
          rgb_lagged_sum|   4|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 72293 times
          rgb_lagged_sum|   5|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 79293 times
          rgb_lagged_sum|   6|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 87293 times
          rgb_lagged_sum|   7|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 96293 times
          rgb_lagged_sum|   8|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 106293 times
          rgb_lagged_sum|   9|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 117293 times
          rgb_lagged_sum|  10|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 129293 times
          rgb_lagged_sum|  11|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 142293 times
          rgb_lagged_sum|  12|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 156293 times
          rgb_lagged_sum|  13|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 171293 times
          rgb_lagged_sum|  14|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 187293 times
          rgb_lagged_sum|  15|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 204293 times
          rgb_lagged_sum|  16|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 222293 times
          rgb_lagged_sum|  17|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 241293 times
          rgb_lagged_sum|  18|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 261293 times
          rgb_lagged_sum|  19|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 282293 times
          rgb_lagged_sum|  20|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 304293 times
          rgb_lagged_sum|  21|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 327293 times
          rgb_lagged_sum|  22|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 351293 times
          rgb_lagged_sum|  23|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 376293 times
          rgb_lagged_sum|  24|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 402293 times
          rgb_lagged_sum|  25|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 429293 times
          rgb_lagged_sum|  26|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 457293 times
          rgb_lagged_sum|  27|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 486293 times
          rgb_lagged_sum|  28|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 516293 times
          rgb_lagged_sum|  29|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 547293 times
          rgb_lagged_sum|  30|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 579293 times
          rgb_lagged_sum|  31|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 612293 times
          rgb_lagged_sum|  32|   1000000|     100|0.00000000|  FAILED 
    # The file file_input was rewound 612393 times
         rgb_kstest_test|   0|     10000|    1000|0.00000000|  FAILED 
    # The file file_input was rewound 613929 times
         dab_bytedistrib|   0|  51200000|       1|0.00000000|  FAILED 
    # The file file_input was rewound 614057 times
                 dab_dct| 256|     50000|       1|0.00000000|  FAILED 
    Preparing to run test 207.  ntuple = 0
    # The file file_input was rewound 615185 times
            dab_filltree|  32|  15000000|       1|0.00000000|  FAILED 
            dab_filltree|  32|  15000000|       1|0.00000000|  FAILED 
    Preparing to run test 208.  ntuple = 0
    # The file file_input was rewound 615478 times
           dab_filltree2|   0|   5000000|       1|0.00000000|  FAILED 
           dab_filltree2|   1|   5000000|       1|0.00000000|  FAILED 
    Preparing to run test 209.  ntuple = 0
    # The file file_input was rewound 616128 times
            dab_monobit2|  12|  65000000|       1|1.00000000|  FAILED 

    Just 3 ttems are Passed.

    I don't know why. I can't explain what's wrong.

    I need your more help.

  • I am not familiar with diehard, but I assume you have used \nRF5_SDK_13.0.0_04a0bfd\examples\peripheral\rng, and enabled RNG_CONFIG_ERROR_CORRECTION 1 in sdk_config.h

    Then I assume you received the rng values through UART, how did you process and handle these values? Since they for instance by default output as hex in ascii format, so just want to make sure nothing happened in the conversion there. 

    What does the rng.txt file look like?

  • I'm sure that bias enable is enabed as below.

    in sdk_config.h

    #ifndef RNG_ENABLED
    #define RNG_ENABLED 1
    #endif
    #if  RNG_ENABLED
     

    #ifndef RNG_CONFIG_ERROR_CORRECTION
    #define RNG_CONFIG_ERROR_CORRECTION 1
    #endif

    #ifndef RNG_CONFIG_POOL_SIZE
    #define RNG_CONFIG_POOL_SIZE 32
    #endif

    in C file

    uint8_t rng_tester(uint8_t * p_buff, uint8_t size)
    {
        uint32_t err_code;
        uint8_t  available;

        nrf_drv_rng_bytes_available(&available);
        uint8_t length = MIN(size, available);

        err_code = nrf_drv_rng_rand(p_buff, length);
        APP_ERROR_CHECK(err_code);

        return length;
    }

    void test_rng(void)

    {

     unsigned int cnt_l = 100000;
     SEGGER_RTT_printf_log(0, RTT_CTRL_TEXT_WHITE"type: d\n");
     SEGGER_RTT_printf_log(0, RTT_CTRL_TEXT_WHITE"count: %d\n", cnt_l);
     SEGGER_RTT_printf_log(0, RTT_CTRL_TEXT_WHITE"numbit: 32\n");

     unsigned char test_buf[4];
     for(int i = 0; i <cnt_l ; i++)
     {
      rng_tester(test_buf, 4);
      int result_l = (test_buf[0] | (test_buf[1] << 8) | (test_buf[2] << 16) | (test_buf[3] << 24));
      nrf_delay_ms(10);
      SEGGER_RTT_printf_log(0, RTT_CTRL_TEXT_WHITE"%d\n", result_l);
     }

    }

    int main(void)

    {

    ......

    test_rng();

     while(1)
     {
      ;
     }

    }

    I'm getting TXT file using RTT log.

    txt file is

    type: d
    count: 100000
    numbit: 32
    142607036
    -289465569
    716407500
    -889941776
    1929543548
    -240293617
    -2144713292
    1976024794
    459320735
    -1330035274
    -28695444
    1250428465

    ......

    I'm attaching txt file.rng_20190918_007.txt

  • I just realized that Dieharder needs more than 31M integers as blow link.

    https://stackoverflow.com/questions/32954045/using-txt-file-containing-random-numbers-with-the-diehard-test-suite

    I will test with 50M integers and let you know. I wish it works well.

Related