1cfg_select! {
2 any(target_os = "linux", target_os = "android") => {
4 mod linux;
5 pub use linux::{fill_bytes, hashmap_random_keys};
6 }
7 target_os = "windows" => {
8 mod windows;
9 pub use windows::fill_bytes;
10 }
11 target_vendor = "apple" => {
12 mod apple;
13 pub use apple::fill_bytes;
14 }
16 any(
17 target_os = "dragonfly",
18 target_os = "freebsd",
19 target_os = "haiku",
20 target_os = "illumos",
21 target_os = "netbsd",
22 target_os = "openbsd",
23 target_os = "rtems",
24 target_os = "solaris",
25 target_os = "vita",
26 target_os = "nuttx",
27 ) => {
28 mod arc4random;
29 pub use arc4random::fill_bytes;
30 }
31 target_os = "emscripten" => {
32 mod getentropy;
33 pub use getentropy::fill_bytes;
34 }
35 target_os = "espidf" => {
36 mod espidf;
37 pub use espidf::fill_bytes;
38 }
39 target_os = "fuchsia" => {
40 mod fuchsia;
41 pub use fuchsia::fill_bytes;
42 }
43 target_os = "hermit" => {
44 mod hermit;
45 pub use hermit::fill_bytes;
46 }
47 any(target_os = "horizon", target_os = "cygwin") => {
48 mod getrandom;
50 pub use getrandom::fill_bytes;
51 }
52 any(
53 target_os = "aix",
54 target_os = "hurd",
55 target_os = "l4re",
56 target_os = "nto",
57 ) => {
58 mod unix_legacy;
59 pub use unix_legacy::fill_bytes;
60 }
61 target_os = "redox" => {
62 mod redox;
63 pub use redox::fill_bytes;
64 }
65 all(target_vendor = "fortanix", target_env = "sgx") => {
66 mod sgx;
67 pub use sgx::fill_bytes;
68 }
69 target_os = "solid_asp3" => {
70 mod solid;
71 pub use solid::fill_bytes;
72 }
73 target_os = "teeos" => {
74 mod teeos;
75 pub use teeos::fill_bytes;
76 }
77 target_os = "trusty" => {
78 mod trusty;
79 pub use trusty::fill_bytes;
80 }
81 target_os = "uefi" => {
82 mod uefi;
83 pub use uefi::fill_bytes;
84 }
85 target_os = "vxworks" => {
86 mod vxworks;
87 pub use vxworks::fill_bytes;
88 }
89 all(target_os = "wasi", target_env = "p1") => {
90 mod wasip1;
91 pub use wasip1::fill_bytes;
92 }
93 all(target_os = "wasi", target_env = "p2") => {
94 mod wasip2;
95 pub use wasip2::{fill_bytes, hashmap_random_keys};
96 }
97 target_os = "zkvm" => {
98 mod zkvm;
99 pub use zkvm::fill_bytes;
100 }
101 any(
102 all(target_family = "wasm", target_os = "unknown"),
103 target_os = "xous",
104 target_os = "vexos",
105 ) => {
106 mod unsupported;
109 pub use unsupported::{fill_bytes, hashmap_random_keys};
110 }
111 _ => {}
112}
113
114#[cfg(not(any(
115 target_os = "linux",
116 target_os = "android",
117 all(target_family = "wasm", target_os = "unknown"),
118 all(target_os = "wasi", target_env = "p2"),
119 target_os = "xous",
120 target_os = "vexos",
121)))]
122pub fn hashmap_random_keys() -> (u64, u64) {
123 let mut buf = [0; 16];
124 fill_bytes(&mut buf);
125 let k1 = u64::from_ne_bytes(buf[..8].try_into().unwrap());
126 let k2 = u64::from_ne_bytes(buf[8..].try_into().unwrap());
127 (k1, k2)
128}