X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Futil%2Frng.rs;h=ae50154d95dea23b29d25c36aeff13372b4b101a;hb=7a8bec750df613085d195375aee30924af6d0c6c;hp=818528b8e13e9f35c333c18769ea12dce4543b93;hpb=24fd566567320b4d78fa868cce873bd733e30ce5;p=rust-lightning diff --git a/src/util/rng.rs b/src/util/rng.rs index 818528b8..ae50154d 100644 --- a/src/util/rng.rs +++ b/src/util/rng.rs @@ -1,16 +1,16 @@ #[cfg(not(feature = "fuzztarget"))] mod real_rng { use rand::{thread_rng,Rng}; - use bitcoin::util::uint::Uint256; pub fn fill_bytes(data: &mut [u8]) { let mut rng = thread_rng(); rng.fill_bytes(data); } - pub fn rand_uint256() -> Uint256 { - let mut rng = thread_rng(); - Uint256([rng.gen(), rng.gen(), rng.gen(), rng.gen()]) + pub fn rand_u832() -> [u8; 32] { + let mut res = [0; 32]; + fill_bytes(&mut res); + res } pub fn rand_f32() -> f32 { @@ -23,7 +23,6 @@ pub use self::real_rng::*; #[cfg(feature = "fuzztarget")] mod fuzzy_rng { - use bitcoin::util::uint::Uint256; use util::byte_utils; static mut RNG_ITER: u64 = 0; @@ -38,9 +37,15 @@ mod fuzzy_rng { data[off..].copy_from_slice(&byte_utils::be64_to_array(rng)[0..rem]); } - pub fn rand_uint256() -> Uint256 { + pub fn rand_u832() -> [u8; 32] { let rng = unsafe { RNG_ITER += 1; RNG_ITER - 1 }; - Uint256([rng, rng, rng, rng]) + let mut res = [0; 32]; + let data = byte_utils::le64_to_array(rng); + res[8*0..8*1].copy_from_slice(&data); + res[8*1..8*2].copy_from_slice(&data); + res[8*2..8*3].copy_from_slice(&data); + res[8*3..8*4].copy_from_slice(&data); + res } pub fn rand_f32() -> f32 {