Skip to content

Commit d2cd0e7

Browse files
AdityaHPatwardhanmahavirj
authored andcommitted
fix(docs): Improved RNG documentation
Updated the RNG documentation to add more details about the High speed ADC as a noise source and its limitations. Closes #14665
1 parent f4c40f7 commit d2cd0e7

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed
38.6 KB
Loading
36.2 KB
Loading

docs/en/api-reference/system/random.rst

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,83 @@ Random Number Generation
88

99
{IDF_TARGET_NAME} contains a hardware random number generator (RNG). You can use the APIs :cpp:func:`esp_random` and :cpp:func:`esp_fill_random` to obtained random values from it.
1010

11+
Every 32-bit value that the system reads from the RNG_DATA_REG register of the random number generator is a true random number. These true random numbers are generated based on the thermal noise in the system and the asynchronous clock mismatch.
12+
13+
.. only:: SOC_WIFI_SUPPORTED or SOC_IEEE802154_SUPPORTED or SOC_BT_SUPPORTED
14+
15+
- Thermal noise comes from the high-speed ADC or SAR ADC or both. Whenever the high-speed ADC or SAR ADC is enabled, bit streams will be generated and fed into the random number generator through an XOR logic gate as random seeds.
16+
17+
.. only:: not SOC_WIFI_SUPPORTED and not SOC_IEEE802154_SUPPORTED and not SOC_BT_SUPPORTED
18+
19+
- Thermal noise comes from the SAR ADC. Whenever the SAR ADC is enabled, bit streams will be generated and fed into the random number generator through an XOR logic gate as random seeds.
20+
21+
.. only:: not esp32
22+
23+
- RC_FAST_CLK is an asynchronous clock source and it increases the RNG entropy by introducing circuit metastability. See the :ref:`secondary entropy` section for more details.
24+
25+
The following digram shows the noise sources for the RNG on the {IDF_TARGET_NAME}:
26+
27+
.. only:: SOC_WIFI_SUPPORTED or SOC_IEEE802154_SUPPORTED or SOC_BT_SUPPORTED
28+
29+
.. image:: /../_static/esp_rng_noise_source_rf_available.png
30+
:scale: 80 %
31+
:align: center
32+
33+
.. only:: not SOC_WIFI_SUPPORTED and not SOC_IEEE802154_SUPPORTED and not SOC_BT_SUPPORTED
34+
35+
.. image:: /../_static/esp_rng_noise_source_rf_unavailable.png
36+
:scale: 80 %
37+
:align: center
38+
1139
The hardware RNG produces true random numbers so long as one or more of the following conditions are met:
1240

1341
.. list::
1442

15-
:SOC_WIFI_SUPPORTED or SOC_IEEE802154_SUPPORTED or SOC_BT_SUPPORTED: - RF subsystem is enabled. i.e., {IDF_TARGET_RF_NAME} {IDF_TARGET_RF_IS} enabled.
16-
- The internal entropy source (SAR ADC) has been enabled by calling :cpp:func:`bootloader_random_enable` and not yet disabled by calling :cpp:func:`bootloader_random_disable`.
43+
:SOC_WIFI_SUPPORTED or SOC_IEEE802154_SUPPORTED or SOC_BT_SUPPORTED: - RF subsystem is enabled. i.e., {IDF_TARGET_RF_NAME} {IDF_TARGET_RF_IS} enabled. When enabled, the RF subsystem internally enables the High Speed ADC that can be used as the entropy source. The High Speed ADC may only be available when the respective RF subsystem is active (e.g., not in sleep mode). See the :ref:`enabling RF subsystem` section for more details.
44+
- The internal entropy source SAR ADC has been enabled by calling :cpp:func:`bootloader_random_enable` and not yet disabled by calling :cpp:func:`bootloader_random_disable`.
1745
- While the ESP-IDF :ref:`second-stage-bootloader` is running. This is because the default ESP-IDF bootloader implementation calls :cpp:func:`bootloader_random_enable` when the bootloader starts, and :cpp:func:`bootloader_random_disable` before executing the application.
1846

1947
When any of these conditions are true, samples of physical noise are continuously mixed into the internal hardware RNG state to provide entropy. Consult the **{IDF_TARGET_NAME} Technical Reference Manual** > **Random Number Generator (RNG)** [`PDF <{IDF_TARGET_TRM_EN_URL}#rng>`__] chapter for more details.
2048

2149
If none of the above conditions are true, the output of the RNG should be considered as pseudo-random only.
2250

51+
.. only:: SOC_WIFI_SUPPORTED or SOC_IEEE802154_SUPPORTED or SOC_BT_SUPPORTED
52+
53+
.. _enabling RF subsystem:
54+
55+
Enabling RF subsystem
56+
---------------------
57+
58+
The RF subsystem can be enabled with help of the following APIs:
59+
60+
.. list::
61+
62+
:SOC_WIFI_SUPPORTED: - Wi-Fi: :cpp:func:`esp_wifi_start`
63+
:SOC_BT_SUPPORTED: - Bluetooth (NimBLE): :cpp:func:`nimble_port_init()` which internally calls :cpp:func:`esp_bt_controller_enable()`
64+
:SOC_BT_SUPPORTED: - Bluetooth (Bluedroid): :cpp:func:`esp_bt_controller_enable()`
65+
:SOC_IEEE802154_SUPPORTED: - Thread/Zigbee: :cpp:func:`esp_openthread_init`
66+
2367
Startup
2468
-------
2569

2670
During startup, the ESP-IDF bootloader temporarily enables the non-RF internal entropy source (SAR ADC using internal reference voltage noise) that provides entropy for any first boot key generation.
2771

2872
.. only:: not SOC_WIFI_SUPPORTED and not SOC_IEEE802154_SUPPORTED and not SOC_BT_SUPPORTED
2973

30-
However, after the application starts executing, then normally only pseudo-random numbers are available until the internal entropy source has been enabled again.
74+
For {IDF_TARGET_NAME}, the High Speed ADC is not available. Hence the non-RF internal entropy source (SAR ADC) is kept enabled by default at the time of application startup. Please note that if the application wants to use ADC for other purposes, it should call :cpp:func:`bootloader_random_disable` before using the ADC and :cpp:func:`bootloader_random_enable` to re-enable the entropy source when the Random Number Generator is needed again.
3175

3276
.. only:: SOC_WIFI_SUPPORTED or SOC_IEEE802154_SUPPORTED or SOC_BT_SUPPORTED
3377

3478
However, after the application starts executing, then normally only pseudo-random numbers are available until {IDF_TARGET_RF_NAME} {IDF_TARGET_RF_IS} initialized or until the internal entropy source has been enabled again.
3579

3680

37-
To re-enable the entropy source temporarily during application startup, or for an application that does not use {IDF_TARGET_RF_NAME}, call the function :cpp:func:`bootloader_random_enable` to re-enable the internal entropy source. The function :cpp:func:`bootloader_random_disable` must be called to disable the entropy source again before using any of the following features:
81+
To re-enable the entropy source temporarily during application startup, or for an application that does not use {IDF_TARGET_RF_NAME}, call the function :cpp:func:`bootloader_random_enable` to re-enable the internal entropy source. The function :cpp:func:`bootloader_random_disable` must be called to disable the entropy source again before using any of the following features:
3882

39-
.. list::
83+
.. list::
4084

41-
- ADC
42-
43-
:esp32: - I2S
44-
45-
:SOC_WIFI_SUPPORTED or SOC_IEEE802154_SUPPORTED or SOC_BT_SUPPORTED: - {IDF_TARGET_RF_NAME}
85+
- ADC
86+
:esp32: - I2S
87+
:SOC_WIFI_SUPPORTED or SOC_IEEE802154_SUPPORTED or SOC_BT_SUPPORTED: - {IDF_TARGET_RF_NAME}
4688

4789
.. note::
4890

@@ -54,6 +96,8 @@ To re-enable the entropy source temporarily during application startup, or for a
5496

5597
.. only:: not esp32
5698

99+
.. _secondary entropy:
100+
57101
Secondary Entropy
58102
-----------------
59103

0 commit comments

Comments
 (0)