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 27
27
//! | Hermit | `x86_64-*-hermit` | [`RDRAND`][18]
28
28
//! | SGX | `x86_64‑*‑sgx` | [RDRAND][18]
29
29
//! | VxWorks | `*‑wrs‑vxworks‑*` | `randABytes` after checking entropy pool initialization with `randSecure`
30
+ //! | ESP-IDF | `*‑espidf` | [`getrandom()`][23]
30
31
//! | Emscripten | `*‑emscripten` | `/dev/random` (identical to `/dev/urandom`)
31
32
//! | WASI | `wasm32‑wasi` | [`random_get`][17]
32
33
//! | Web Browser | `wasm32‑*‑unknown` | [`Crypto.getRandomValues()`][14], see [WebAssembly support][16]
142
143
//! [20]: https://www.unix.com/man-page/mojave/4/random/
143
144
//! [21]: https://www.freebsd.org/cgi/man.cgi?query=getrandom&manpath=FreeBSD+12.0-stable
144
145
//! [22]: https://leaf.dragonflybsd.org/cgi/web-man?command=getrandom
146
+ //! [23]: https://cygwin.com/git/?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/include/sys/random.h;hb=HEAD#l22
145
147
146
148
#![ doc(
147
149
html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png" ,
@@ -209,6 +211,8 @@ cfg_if! {
209
211
#[ path = "vxworks.rs" ] mod imp;
210
212
} else if #[ cfg( target_os = "solid_asp3" ) ] {
211
213
#[ path = "solid.rs" ] mod imp;
214
+ } else if #[ cfg( target_os = "espidf" ) ] {
215
+ #[ path = "espidf.rs" ] mod imp;
212
216
} else if #[ cfg( windows) ] {
213
217
#[ path = "windows.rs" ] mod imp;
214
218
} else if #[ cfg( all( target_arch = "x86_64" , target_env = "sgx" ) ) ] {
You can’t perform that action at this time.
0 commit comments