Skip to content

Commit

Permalink
Use getrandom directly
Browse files Browse the repository at this point in the history
  • Loading branch information
mkj committed Mar 5, 2023
1 parent c4473e1 commit 9c0d6c2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ no-panic = "0.1"
# allows avoiding utf8 for SSH identifier names
ascii = { version = "1.0", default-features = false }

rand = { version = "0.8", default-features = false, features = ["getrandom"] }
rand_core = { version = "0.6", default-features = false }
getrandom = "0.2"

ctr = { version = "0.9", features = ["zeroize"] }
aes = { version = "0.8", features = ["zeroize"] }
Expand Down
16 changes: 4 additions & 12 deletions src/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,9 @@ use {
log::{debug, error, info, log, trace, warn},
};

use rand::{RngCore, Rng, CryptoRng};
use core::num::Wrapping;

pub type SunsetRng = rand::rngs::OsRng;

pub fn fill_random(buf: &mut [u8]) -> Result<(), Error> {
// TODO: can this return an error?
let mut rng = SunsetRng::default();
rng.try_fill_bytes(buf)
.map_err(|e| {
debug!("RNG failed: {e:?}");
Error::msg("RNG failed")
})
getrandom::getrandom(buf)
.map_err(|_| {
Error::msg("RNG failed")
})
}

0 comments on commit 9c0d6c2

Please sign in to comment.