• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 Developers of the Rand project.
2 //
3 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4 // https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5 // <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6 // option. This file may not be copied, modified, or distributed
7 // except according to those terms.
8 
9 //! Implementation for ESP-IDF
10 use crate::Error;
11 use core::ffi::c_void;
12 
13 extern "C" {
esp_fill_random(buf: *mut c_void, len: usize) -> u3214     fn esp_fill_random(buf: *mut c_void, len: usize) -> u32;
15 }
16 
getrandom_inner(dest: &mut [u8]) -> Result<(), Error>17 pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
18     // Not that NOT enabling WiFi, BT, or the voltage noise entropy source (via `bootloader_random_enable`)
19     // will cause ESP-IDF to return pseudo-random numbers based on the voltage noise entropy, after the initial boot process:
20     // https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/random.html
21     //
22     // However tracking if some of these entropy sources is enabled is way too difficult to implement here
23     unsafe { esp_fill_random(dest.as_mut_ptr().cast(), dest.len()) };
24 
25     Ok(())
26 }
27