bootloader_random.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 subsystem is disabled
  13. *
  14. * @warning This function is not safe to use if any other subsystem is accessing the RF subsystem or
  15. * the ADC at the same time!
  16. *
  17. * The exact internal entropy source mechanism depends on the chip in use but
  18. * all SoCs use the SAR ADC to continuously mix random bits (an internal
  19. * noise reading) into the HWRNG. Consult the SoC Technical Reference
  20. * Manual for more information.
  21. *
  22. * Can also be called from app code, if true random numbers are required without initialized RF subsystem.
  23. * This might be the case in early startup code of the application when the RF subsystem has not
  24. * started yet or if the RF subsystem should not be enabled for power saving.
  25. *
  26. * Consult ESP-IDF Programming Guide "Random Number Generation" section for
  27. * details.
  28. */
  29. void bootloader_random_enable(void);
  30. /**
  31. * @brief Disable entropy source for RNG
  32. *
  33. * Disables internal entropy source. Must be called after
  34. * bootloader_random_enable() and before RF subsystem features, ADC, or
  35. * I2S (ESP32 only) are initialized.
  36. *
  37. * Consult the ESP-IDF Programming Guide "Random Number Generation"
  38. * section for details.
  39. */
  40. void bootloader_random_disable(void);
  41. /**
  42. * @brief Fill buffer with 'length' random bytes
  43. *
  44. * @note If this function is being called from app code only, and never
  45. * from the bootloader, then it's better to call esp_fill_random().
  46. *
  47. * @param buffer Pointer to buffer
  48. * @param length This many bytes of random data will be copied to buffer
  49. */
  50. void bootloader_fill_random(void *buffer, size_t length);
  51. #ifdef __cplusplus
  52. }
  53. #endif