docs: Add description for Linux getrandom() function

This commit is contained in:
Angus Gratton
2021-05-20 17:08:17 +10:00
parent e14edecf5f
commit 5c812742c6
2 changed files with 19 additions and 1 deletions

View File

@@ -29,7 +29,8 @@ extern "C" {
* Guide "Random Number Generation" section for necessary prerequisites.
*
* This function automatically busy-waits to ensure enough external entropy has been
* introduced into the hardware RNG state, before returning a new random number.
* introduced into the hardware RNG state, before returning a new random number. This delay
* is very short (always less than 100 CPU cycles).
*
* @return Random value between 0 and UINT32_MAX
*/

View File

@@ -45,5 +45,22 @@ API Reference
.. include-build-file:: inc/esp_random.inc
.. include-build-file:: inc/bootloader_random.inc
getrandom
---------
A compatible version of the Linux ``getrandom()`` function is also provided for ease of porting:
.. code-block:: c
#include <sys/random.h>
ssize_t getrandom(void *buf, size_t buflen, unsigned int flags);
This function is implemented by calling :cpp:func:`esp_fill_random` internally.
The ``flags`` argument is ignored, this function is always non-blocking but the strength of any random numbers is dependent on the same conditions described above.
Return value is -1 (with ``errno`` set to ``EFAULT``) if the ``buf`` argument is NULL, and equal to ``buflen`` otherwise.
.. _Dieharder: https://webhome.phy.duke.edu/~rgb/General/dieharder.php