use {Rng, SeedableRng, Rand};
-const KEY_WORDS : usize = 8; // 8 words for the 256-bit key
-const STATE_WORDS : usize = 16;
+const KEY_WORDS: usize = 8; // 8 words for the 256-bit key
+const STATE_WORDS: usize = 16;
const CHACHA_ROUNDS: usize = 20; // Cryptographically secure from 8 upwards as of this writing
/// A random number generator that uses the ChaCha20 algorithm [1].
}
impl ChaChaRng {
-
/// Create an ChaCha random number generator using the default
/// fixed key of 8 zero words.
pub fn new_unseeded() -> ChaChaRng {
}
impl<'a> SeedableRng<&'a [u32]> for ChaChaRng {
-
fn reseed(&mut self, seed: &'a [u32]) {
// reset state
self.init(&[0; KEY_WORDS]);
mod tests {
use std::prelude::v1::*;
- use core::iter::order;
use {Rng, SeedableRng};
use super::ChaChaRng;
let s = ::test::rng().gen_iter::<u32>().take(8).collect::<Vec<u32>>();
let mut ra: ChaChaRng = SeedableRng::from_seed(&*s);
let mut rb: ChaChaRng = SeedableRng::from_seed(&*s);
- assert!(order::equals(ra.gen_ascii_chars().take(100),
- rb.gen_ascii_chars().take(100)));
+ assert!(ra.gen_ascii_chars().take(100)
+ .eq(rb.gen_ascii_chars().take(100)));
}
#[test]
let seed: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7];
let mut ra: ChaChaRng = SeedableRng::from_seed(seed);
let mut rb: ChaChaRng = SeedableRng::from_seed(seed);
- assert!(order::equals(ra.gen_ascii_chars().take(100),
- rb.gen_ascii_chars().take(100)));
+ assert!(ra.gen_ascii_chars().take(100)
+ .eq(rb.gen_ascii_chars().take(100)));
}
#[test]