File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -65,6 +65,9 @@ fuchsia-zircon = { version = "0.3.2", optional = true }
6565stdweb = { version = " 0.4" , optional = true }
6666wasm-bindgen = { version = " 0.2.12" , optional = true }
6767
68+ [target .'cfg(target_env = "sgx")' .dependencies ]
69+ rdrand = " 0.4.0"
70+
6871[dev-dependencies ]
6972# This has a histogram implementation used for testing uniformity.
7073average = " 0.9.2"
@@ -74,3 +77,7 @@ autocfg = "0.1"
7477
7578[package .metadata .docs .rs ]
7679all-features = true
80+
81+ [patch .crates-io ]
82+ rand_core = { path = " rand_core" , version = " 0.3" , default-features = false }
83+
Original file line number Diff line number Diff line change @@ -72,6 +72,9 @@ extern crate stdweb;
7272#[ cfg( all( target_arch = "wasm32" , feature = "wasm-bindgen" ) ) ]
7373extern crate wasm_bindgen;
7474
75+ #[ cfg( target_env = "sgx" ) ]
76+ extern crate rdrand;
77+
7578extern crate rand_core;
7679extern crate rand_isaac; // only for deprecations
7780extern crate rand_chacha; // only for deprecations
Original file line number Diff line number Diff line change @@ -194,6 +194,7 @@ pub use self::std::StdRng;
194194 windows,
195195 all( target_arch = "wasm32" , feature = "stdweb" ) ,
196196 all( target_arch = "wasm32" , feature = "wasm-bindgen" ) ,
197+ target_env = "sgx" ,
197198) ) ) ]
198199mod os;
199200
Original file line number Diff line number Diff line change @@ -1191,6 +1191,40 @@ mod imp {
11911191 }
11921192}
11931193
1194+ #[ cfg( target_env = "sgx" ) ]
1195+ mod imp {
1196+ use super :: OsRngImpl ;
1197+ use Error ;
1198+ use rdrand:: RdRand ;
1199+ use rand_core:: RngCore ;
1200+ use std:: fmt:: { Debug , Formatter , Result as FmtResult } ;
1201+
1202+ #[ derive( Clone ) ]
1203+ pub struct OsRng {
1204+ gen : RdRand
1205+ }
1206+
1207+ impl OsRngImpl for OsRng {
1208+ fn new ( ) -> Result < OsRng , Error > {
1209+ let rng = RdRand :: new ( ) ?;
1210+ Ok ( OsRng { gen : rng } )
1211+ }
1212+
1213+ fn fill_chunk ( & mut self , dest : & mut [ u8 ] ) -> Result < ( ) , Error > {
1214+ self . gen . try_fill_bytes ( dest)
1215+ }
1216+
1217+ fn method_str ( & self ) -> & ' static str { "RDRAND" }
1218+ }
1219+
1220+ impl Debug for OsRng {
1221+ fn fmt ( & self , f : & mut Formatter ) -> FmtResult {
1222+ f. debug_struct ( "OsRng" )
1223+ . field ( "gen" , & String :: from ( "No information" ) )
1224+ . finish ( )
1225+ }
1226+ }
1227+ }
11941228
11951229#[ cfg( test) ]
11961230mod test {
You can’t perform that action at this time.
0 commit comments