bootloader_random.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 early entropy source for RNG
  21. *
  22. * Uses the SAR ADC to feed entropy into the HWRNG. The ADC is put
  23. * into a test mode that reads the 1.1V internal reference source and
  24. * feeds the LSB of data into the HWRNG.
  25. *
  26. * Can also be used from app code early during operation, if entropy
  27. * is required before WiFi stack is initialised. Call this function
  28. * from app code only if WiFi/BT are not yet enabled and I2S and SAR
  29. * ADC are not in use.
  30. *
  31. * Call bootloader_random_disable() when done.
  32. */
  33. void bootloader_random_enable(void);
  34. /**
  35. * @brief Disable early entropy source for RNG
  36. *
  37. * Disables SAR ADC source and resets the I2S hardware.
  38. *
  39. */
  40. void bootloader_random_disable(void);
  41. /**
  42. * @brief Fill buffer with 'length' random bytes
  43. *
  44. * @param buffer Pointer to buffer
  45. * @param length This many bytes of random data will be copied to buffer
  46. */
  47. void bootloader_fill_random(void *buffer, size_t length);
  48. #ifdef __cplusplus
  49. }
  50. #endif