feat: Use the rand crate for random values instead of sodium

This commit is contained in:
Karolin Varner
2023-11-30 18:23:59 +01:00
committed by Karolin Varner
parent 77cd8a9fd1
commit 5448cdc565
10 changed files with 70 additions and 26 deletions

View File

@@ -26,22 +26,3 @@ pub fn increment(v: &mut [u8]) {
libsodium::sodium_increment(v.as_mut_ptr(), v.len());
}
}
#[inline]
pub fn randombytes_buf(buf: &mut [u8]) {
unsafe { libsodium::randombytes_buf(buf.as_mut_ptr() as *mut c_void, buf.len()) };
}
// Choose a fully random u64
// TODO: Replace with ::rand::random
pub fn rand_u64() -> u64 {
let mut buf = [0u8; 8];
randombytes_buf(&mut buf);
u64::from_le_bytes(buf)
}
// Choose a random f64 in [0; 1] inclusive; quick and dirty
// TODO: Replace with ::rand::random
pub fn rand_f64() -> f64 {
(rand_u64() as f64) / (u64::MAX as f64)
}