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