esp_random.h 1.2 KB

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