File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change
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
+
12
+ pub fn getrandom_inner ( dest : & mut [ u8 ] ) -> Result < ( ) , Error > {
13
+ // ESP-IDF fails and returns -1 only when the passed buffer is NULL, which cannot happen in our case:
14
+ // https://github.com/espressif/esp-idf/blob/master/components/newlib/random.c#L33
15
+ //
16
+ // Not that NOT enabling WiFi, BT, or the voltage noise entropy source (via `bootloader_random_enable`)
17
+ // will cause ESP-IDF to return pseudo-random numbers based on the voltage noise entropy, after the initial boot process:
18
+ // https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/random.html
19
+ //
20
+ // However tracking if some of these entropy sources is enabled is way too difficult to implement here
21
+ unsafe { libc:: getrandom ( dest. as_mut_ptr ( ) . cast ( ) , dest. len ( ) , 0 ) } ;
22
+
23
+ Ok ( ( ) )
24
+ }
Original file line number Diff line number Diff line change 26
26
//! | Haiku | `*‑haiku` | `/dev/random` (identical to `/dev/urandom`)
27
27
//! | SGX | `x86_64‑*‑sgx` | [RDRAND][18]
28
28
//! | VxWorks | `*‑wrs‑vxworks‑*` | `randABytes` after checking entropy pool initialization with `randSecure`
29
+ //! | ESP-IDF | `*‑espidf` | [`getrandom()`][23]
29
30
//! | Emscripten | `*‑emscripten` | `/dev/random` (identical to `/dev/urandom`)
30
31
//! | WASI | `wasm32‑wasi` | [`random_get`][17]
31
32
//! | Web Browser | `wasm32‑*‑unknown` | [`Crypto.getRandomValues()`][14], see [WebAssembly support][16]
140
141
//! [20]: https://www.unix.com/man-page/mojave/4/random/
141
142
//! [21]: https://www.freebsd.org/cgi/man.cgi?query=getrandom&manpath=FreeBSD+12.0-stable
142
143
//! [22]: https://leaf.dragonflybsd.org/cgi/web-man?command=getrandom
144
+ //! [23]: https://cygwin.com/git/?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/include/sys/random.h;hb=HEAD#l22
143
145
144
146
#![ doc(
145
147
html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png" ,
@@ -203,6 +205,8 @@ cfg_if! {
203
205
} else if #[ cfg( target_os = "vxworks" ) ] {
204
206
mod util_libc;
205
207
#[ path = "vxworks.rs" ] mod imp;
208
+ } else if #[ cfg( target_os = "espidf" ) ] {
209
+ #[ path = "espidf.rs" ] mod imp;
206
210
} else if #[ cfg( windows) ] {
207
211
#[ path = "windows.rs" ] mod imp;
208
212
} else if #[ cfg( all( target_arch = "x86_64" , target_env = "sgx" ) ) ] {
You can’t perform that action at this time.
0 commit comments