@@ -29,7 +29,6 @@ use {Rng, Error};
29
29
/// - Windows: calls `RtlGenRandom`, exported from `advapi32.dll` as
30
30
/// `SystemFunction036`.
31
31
/// - iOS: calls SecRandomCopyBytes as /dev/(u)random is sandboxed.
32
- /// - PNaCl: calls into the `nacl-irt-random-0.1` IRT interface.
33
32
///
34
33
/// This usually does not block. On some systems (e.g. FreeBSD, OpenBSD,
35
34
/// Max OS X, and modern Linux) this may block very early in the init
@@ -419,71 +418,6 @@ mod imp {
419
418
}
420
419
}
421
420
422
- #[ cfg( target_os = "nacl" ) ]
423
- mod imp {
424
- extern crate libc;
425
-
426
- use std:: io;
427
- use std:: mem;
428
-
429
- #[ derive( Debug ) ]
430
- pub struct OsRng ( extern fn ( dest : * mut libc:: c_void ,
431
- bytes : libc:: size_t ,
432
- read : * mut libc:: size_t ) -> libc:: c_int ) ;
433
-
434
- extern {
435
- fn nacl_interface_query ( name : * const libc:: c_char ,
436
- table : * mut libc:: c_void ,
437
- table_size : libc:: size_t ) -> libc:: size_t ;
438
- }
439
-
440
- const INTERFACE : & ' static [ u8 ] = b"nacl-irt-random-0.1\0 " ;
441
-
442
- #[ repr( C ) ]
443
- struct NaClIRTRandom {
444
- get_random_bytes : Option < extern fn ( dest : * mut libc:: c_void ,
445
- bytes : libc:: size_t ,
446
- read : * mut libc:: size_t ) -> libc:: c_int > ,
447
- }
448
-
449
- impl OsRng {
450
- pub fn new ( ) -> Result < OsRng , Error > {
451
- let mut iface = NaClIRTRandom {
452
- get_random_bytes : None ,
453
- } ;
454
- let result = unsafe {
455
- nacl_interface_query ( INTERFACE . as_ptr ( ) as * const _ ,
456
- mem:: transmute ( & mut iface) ,
457
- mem:: size_of :: < NaClIRTRandom > ( ) as libc:: size_t )
458
- } ;
459
- if result != 0 {
460
- assert ! ( iface. get_random_bytes. is_some( ) ) ;
461
- let result = OsRng ( iface. get_random_bytes . take ( ) . unwrap ( ) ) ;
462
- Ok ( result)
463
- } else {
464
- // let error = io::ErrorKind::NotFound;
465
- // let error = io::Error::new(error, "IRT random interface missing");
466
- Err ( Result )
467
- }
468
- }
469
- pub fn try_fill ( & mut self , v : & mut [ u8 ] ) -> Result < ( ) , Error > {
470
- let mut read = 0 ;
471
- loop {
472
- let mut r: libc:: size_t = 0 ;
473
- let len = v. len ( ) ;
474
- let error = ( self . 0 ) ( v[ read..] . as_mut_ptr ( ) as * mut _ ,
475
- ( len - read) as libc:: size_t ,
476
- & mut r as * mut _ ) ;
477
- assert ! ( error == 0 , "`get_random_bytes` failed!" ) ;
478
- read += r as usize ;
479
-
480
- if read >= v. len ( ) { break ; }
481
- }
482
- Ok ( ( ) )
483
- }
484
- }
485
- }
486
-
487
421
488
422
#[ cfg( test) ]
489
423
mod test {
0 commit comments