1 /* 2 * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef __ESP_RANDOM_H__ 8 #define __ESP_RANDOM_H__ 9 10 #include <stddef.h> 11 #include <stdint.h> 12 13 #ifdef __cplusplus 14 extern "C" { 15 #endif 16 17 /** 18 * @brief Get one random 32-bit word from hardware RNG 19 * 20 * If Wi-Fi or Bluetooth are enabled, this function returns true random numbers. In other 21 * situations, if true random numbers are required then consult the ESP-IDF Programming 22 * Guide "Random Number Generation" section for necessary prerequisites. 23 * 24 * This function automatically busy-waits to ensure enough external entropy has been 25 * introduced into the hardware RNG state, before returning a new random number. This delay 26 * is very short (always less than 100 CPU cycles). 27 * 28 * @return Random value between 0 and UINT32_MAX 29 */ 30 uint32_t esp_random(void); 31 32 /** 33 * @brief Fill a buffer with random bytes from hardware RNG 34 * 35 * @note This function is implemented via calls to esp_random(), so the same 36 * constraints apply. 37 * 38 * @param buf Pointer to buffer to fill with random numbers. 39 * @param len Length of buffer in bytes 40 */ 41 void esp_fill_random(void *buf, size_t len); 42 43 #ifdef __cplusplus 44 } 45 #endif 46 47 #endif /* __ESP_RANDOM_H__ */ 48