esp_random.h 1.2 KB

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