bootloader_random.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2010-2016 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. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include <stddef.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /**
  20. * @brief Enable an entropy source for RNG if RF is disabled
  21. *
  22. * The exact internal entropy source mechanism depends on the chip in use but
  23. * all SoCs use the SAR ADC to continuously mix random bits (an internal
  24. * noise reading) into the HWRNG. Consult the SoC Technical Reference
  25. * Manual for more information.
  26. *
  27. * Can also be used from app code early during operation, if true
  28. * random numbers are required before RF is initialised. Consult
  29. * ESP-IDF Programming Guide "Random Number Generation" section for
  30. * details.
  31. */
  32. void bootloader_random_enable(void);
  33. /**
  34. * @brief Disable entropy source for RNG
  35. *
  36. * Disables internal entropy source. Must be called after
  37. * bootloader_random_enable() and before RF features, ADC, or
  38. * I2S (ESP32 only) are initialized.
  39. *
  40. * Consult the ESP-IDF Programming Guide "Random Number Generation"
  41. * section for details.
  42. */
  43. void bootloader_random_disable(void);
  44. /**
  45. * @brief Fill buffer with 'length' random bytes
  46. *
  47. * @note If this function is being called from app code only, and never
  48. * from the bootloader, then it's better to call esp_fill_random().
  49. *
  50. * @param buffer Pointer to buffer
  51. * @param length This many bytes of random data will be copied to buffer
  52. */
  53. void bootloader_fill_random(void *buffer, size_t length);
  54. #ifdef __cplusplus
  55. }
  56. #endif