1 /*
2  * SPDX-FileCopyrightText: 2010-2021 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #pragma once
8 
9 #include <stddef.h>
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 /**
16  * @brief Enable an entropy source for RNG if RF subsystem is disabled
17  *
18  * @warning This function is not safe to use if any other subsystem is accessing the RF subsystem or
19  *          the ADC at the same time!
20  *
21  * The exact internal entropy source mechanism depends on the chip in use but
22  * all SoCs use the SAR ADC to continuously mix random bits (an internal
23  * noise reading) into the HWRNG. Consult the SoC Technical Reference
24  * Manual for more information.
25  *
26  * Can also be called from app code, if true random numbers are required without initialized RF subsystem.
27  * This might be the case in early startup code of the application when the RF subsystem has not
28  * started yet or if the RF subsystem should not be enabled for power saving.
29  *
30  * Consult ESP-IDF Programming Guide "Random Number Generation" section for
31  * details.
32  */
33 void bootloader_random_enable(void);
34 
35 /**
36  * @brief Disable entropy source for RNG
37  *
38  * Disables internal entropy source. Must be called after
39  * bootloader_random_enable() and before RF subsystem features, ADC, or
40  * I2S (ESP32 only) are initialized.
41  *
42  * Consult the ESP-IDF Programming Guide "Random Number Generation"
43  * section for details.
44  */
45 void bootloader_random_disable(void);
46 
47 /**
48  * @brief Fill buffer with 'length' random bytes
49  *
50  * @note If this function is being called from app code only, and never
51  * from the bootloader, then it's better to call esp_fill_random().
52  *
53  * @param buffer Pointer to buffer
54  * @param length This many bytes of random data will be copied to buffer
55  */
56 void bootloader_fill_random(void *buffer, size_t length);
57 
58 #ifdef __cplusplus
59 }
60 #endif
61