MCPcopy Create free account
hub / github.com/ciphermodelabs/ciphercore / new

Method new

ciphercore-base/src/random.rs:43–60  ·  view source on GitHub ↗
(seed: Option<[u8; SEED_SIZE]>)

Source from the content-addressed store, hash-verified

41/// can concurrently access the system random generator
42impl PRNG {
43 pub fn new(seed: Option<[u8; SEED_SIZE]>) -> Result<PRNG> {
44 let err = |_| runtime_error!("Crypter didn't initialize");
45 let bytes = match seed {
46 Some(bytes) => bytes,
47 None => {
48 let mut bytes = [0u8; SEED_SIZE];
49 get_bytes_from_os(&mut bytes)?;
50 bytes
51 }
52 };
53 let mut c =
54 Crypter::new(Cipher::aes_128_ecb(), Mode::Encrypt, &bytes, None).map_err(err)?;
55 c.pad(false);
56 Ok(PRNG {
57 aes: c,
58 random_source: PrfSession::new(0, BUFFER_SIZE)?,
59 })
60 }
61
62 pub fn get_random_bytes(&mut self, n: usize) -> Result<Vec<u8>> {
63 self.random_source

Callers

nothing calls this directly

Calls 2

get_bytes_from_osFunction · 0.85
get_random_keyMethod · 0.80

Tested by

no test coverage detected