1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use log::error;
use rand::rngs::adapter::ReseedingRng;
use rand::rngs::OsRng;
use rand::FromEntropy;
use rand_chacha::ChaChaCore;
pub(super) type SessionIdentifierRng = ReseedingRng<ChaChaCore, OsRng>;
pub(super) fn session_identifier_rng() -> SessionIdentifierRng {
let os_rng = match OsRng::new() {
Ok(rng) => rng,
Err(e) => {
error!(
"Backend::random_identifier failed at rand::OsRng::new(), \
is the system RNG missing? {:?}",
e
);
unreachable!("no rng available, this should never happen");
}
};
let rng = ChaChaCore::from_entropy();
ReseedingRng::new(rng, 32_768, os_rng)
}