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

any limitation to call nrf_drv_rng_rand?

I am developing SDK17.0.0 based application with S112. 

when I try getting a random value at the end of main, the nrf_drv_rng_rand return err_code=0x05, and it leads to "<error> app: Fatal error and <warning> app: System reset".

When I use button to trigger nrf_drv_rng_rand call, it works well.

Is it known issue? How can I workaround it?

Thanks,

srony

  • May you show off your code about the function which is called the random procedure?

    According to your debug messages, it's seems like occurred the error. Then the system will be reset. However, it's must some reasons before you call the  nrf_drv_rng_rand(). May you show that?

  • Hi,

    0x05 is NRF_ERROR_NOT_FOUND and that is returned if there is not enough buffered random data (underlying call to sd_rand_application_vector_get() returned NRF_ERROR_SOC_RAND_NOT_ENOUGH_VALUES). So in this case you could wait a bit and try again later or request fewer random bytes and try again. Generally you need to wait a bit for the random data to be generated, and if you need more TRNG data in one go you may also need to set RNG_CONFIG_POOL_SIZE in sdk_config.h higher.

    (If you need a lot of random data and/or need it fast you may want to use the RNG feature of nrf_crypto instead. That way you can get much more random numbers faster, as it uses the RNG peripheral to seed the mbed TLS CTR-DRBG implementation. This would also follow NIST SP 800-90A Revision 1.)

  • Einar, thanks for your explanation.

    My function calls to nrf_drv_rng_rand with length=2, is it possible because of too long to generate in time?

    Besides, I realized there is a nrf_drv_rng_init in nrf_drv_rng.c, but it's not called in main.c or anywhere of my code. So I want to confirm if it's essential to run nrf_drv_rng_init before using nrf_drv_rng_rand?

    Thanks,

    srony

  • Hi Srony,

    srony said:
    My function calls to nrf_drv_rng_rand with length=2, is it possible because of too long to generate in time?

    It could have been, if the driver was initialized immediately before this call, but It seems there is another problem here.

    srony said:
    So I want to confirm if it's essential to run nrf_drv_rng_init before using nrf_drv_rng_rand?

    Yes, that is necessary. The RNG driver has an assert for that, but the assert is only used for debug builds, which is probably why you have not noticed before. It cannot work without calling nrf_drv_rng_init() first, before any other calls to nrf_drv_rng_*

Related