@@ -93,7 +93,7 @@ impl SecureRandom for SystemRandom {
93
93
94
94
impl private:: Sealed for SystemRandom { }
95
95
96
- #[ cfg( not( any( target_os = "linux" , target_os = "macos" , target_os = "ios" , windows) ) ) ]
96
+ #[ cfg( not( any( target_os = "linux" , target_os = "macos" , target_os = "ios" , windows, target_env = "sgx" ) ) ) ]
97
97
use self :: urandom:: fill as fill_impl;
98
98
99
99
#[ cfg( any(
@@ -107,6 +107,9 @@ use self::sysrand_or_urandom::fill as fill_impl;
107
107
108
108
#[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ]
109
109
use self :: darwin:: fill as fill_impl;
110
+
111
+ #[ cfg( target_env = "sgx" ) ]
112
+ use self :: rdrandom:: fill as fill_impl;
110
113
use crate :: private;
111
114
112
115
#[ cfg( target_os = "linux" ) ]
@@ -275,6 +278,24 @@ mod darwin {
275
278
}
276
279
}
277
280
281
+ #[ cfg( target_env = "sgx" ) ]
282
+ mod rdrandom {
283
+ use rdrand:: RdRand ;
284
+ use crate :: error;
285
+ use crate :: endian:: LittleEndian ;
286
+
287
+ pub fn fill ( dest : & mut [ u8 ] ) -> Result < ( ) , error:: Unspecified > {
288
+ let rng = RdRand :: new ( ) . map_err ( |_| error:: Unspecified ) ?;
289
+ for dst_chunk in dest. chunks_mut ( 8 ) {
290
+ let src_num = rng. try_next_u64 ( ) . ok_or ( error:: Unspecified ) ?;
291
+ let temp = LittleEndian :: from ( src_num) ;
292
+ let src_chunk = temp. as_ref ( ) ;
293
+ dst_chunk. copy_from_slice ( & src_chunk[ ..dst_chunk. len ( ) ] ) ;
294
+ }
295
+ Ok ( ( ) )
296
+ }
297
+ }
298
+
278
299
#[ cfg( test) ]
279
300
mod tests {
280
301
use crate :: rand:: { self , SecureRandom } ;
0 commit comments