bootloader_random.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * SPDX-FileCopyrightText: 2010-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stddef.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. /**
  12. * @brief Enable an entropy source for RNG if RF is disabled
  13. *
  14. * The exact internal entropy source mechanism depends on the chip in use but
  15. * all SoCs use the SAR ADC to continuously mix random bits (an internal
  16. * noise reading) into the HWRNG. Consult the SoC Technical Reference
  17. * Manual for more information.
  18. *
  19. * Can also be used from app code early during operation, if true
  20. * random numbers are required before RF is initialised. Consult
  21. * ESP-IDF Programming Guide "Random Number Generation" section for
  22. * details.
  23. */
  24. void bootloader_random_enable(void);
  25. /**
  26. * @brief Disable entropy source for RNG
  27. *
  28. * Disables internal entropy source. Must be called after
  29. * bootloader_random_enable() and before RF features, ADC, or
  30. * I2S (ESP32 only) are initialized.
  31. *
  32. * Consult the ESP-IDF Programming Guide "Random Number Generation"
  33. * section for details.
  34. */
  35. void bootloader_random_disable(void);
  36. /**
  37. * @brief Fill buffer with 'length' random bytes
  38. *
  39. * @note If this function is being called from app code only, and never
  40. * from the bootloader, then it's better to call esp_fill_random().
  41. *
  42. * @param buffer Pointer to buffer
  43. * @param length This many bytes of random data will be copied to buffer
  44. */
  45. void bootloader_fill_random(void *buffer, size_t length);
  46. #ifdef __cplusplus
  47. }
  48. #endif