esp_random.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2021 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #pragma once
  14. #include <stddef.h>
  15. #include <stdint.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /**
  20. * @brief Get one random 32-bit word from hardware RNG
  21. *
  22. * If Wi-Fi or Bluetooth are enabled, this function returns true random numbers. In other
  23. * situations, if true random numbers are required then consult the ESP-IDF Programming
  24. * Guide "Random Number Generation" section for necessary prerequisites.
  25. *
  26. * This function automatically busy-waits to ensure enough external entropy has been
  27. * introduced into the hardware RNG state, before returning a new random number. This delay
  28. * is very short (always less than 100 CPU cycles).
  29. *
  30. * @return Random value between 0 and UINT32_MAX
  31. */
  32. uint32_t esp_random(void);
  33. /**
  34. * @brief Fill a buffer with random bytes from hardware RNG
  35. *
  36. * @note This function is implemented via calls to esp_random(), so the same
  37. * constraints apply.
  38. *
  39. * @param buf Pointer to buffer to fill with random numbers.
  40. * @param len Length of buffer in bytes
  41. */
  42. void esp_fill_random(void *buf, size_t len);
  43. #ifdef __cplusplus
  44. }
  45. #endif