randombytes_esp32.c 821 B

12345678910111213141516171819202122232425262728
  1. /*
  2. * SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "randombytes_internal.h"
  7. #include "esp_system.h"
  8. static const char *randombytes_esp32xx_implementation_name(void)
  9. {
  10. return CONFIG_IDF_TARGET;
  11. }
  12. /*
  13. Plug the ESP32 hardware RNG into libsodium's custom RNG support, as per
  14. https://download.libsodium.org/doc/advanced/custom_rng.html
  15. Note that this RNG is selected by default (see randombytes_default.h), so there
  16. is no need to call randombytes_set_implementation().
  17. */
  18. const struct randombytes_implementation randombytes_esp32_implementation = {
  19. .implementation_name = randombytes_esp32xx_implementation_name,
  20. .random = esp_random,
  21. .stir = NULL,
  22. .uniform = NULL,
  23. .buf = esp_fill_random,
  24. .close = NULL,
  25. };