Skip to content

Commit

Permalink
Rollup merge of rust-lang#64372 - Wind-River:master, r=alexcrichton
Browse files Browse the repository at this point in the history
use randSecure and randABytes

r? @alexcrichton

cc @n-salim
  • Loading branch information
Centril authored Sep 14, 2019
2 parents 07d9cd2 + 83e7976 commit 0b74b2d
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/libstd/sys/vxworks/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,24 @@ pub fn hashmap_random_keys() -> (u64, u64) {
mod imp {
use libc;
use crate::io;

extern "C" {
fn randBytes (randBuf: *mut libc::c_uchar,
numOfBytes: libc::c_int) -> libc::c_int;
}
use core::sync::atomic::{AtomicBool, Ordering::Relaxed};

pub fn fill_bytes(v: &mut [u8]) {
static RNG_INIT: AtomicBool = AtomicBool::new(false);
while !RNG_INIT.load(Relaxed) {
let ret = unsafe { libc::randSecure() };
if ret < 0 {
panic!("couldn't generate random bytes: {}", io::Error::last_os_error());
} else if ret > 0 {
RNG_INIT.store(true, Relaxed);
break;
}
unsafe { libc::usleep(10) };
}
let ret = unsafe {
randBytes(v.as_mut_ptr() as *mut libc::c_uchar, v.len() as libc::c_int)
libc::randABytes(v.as_mut_ptr() as *mut libc::c_uchar, v.len() as libc::c_int)
};
if ret == -1 {
if ret < 0 {
panic!("couldn't generate random bytes: {}", io::Error::last_os_error());
}
}
Expand Down

0 comments on commit 0b74b2d

Please sign in to comment.