Skip to content

Commit

Permalink
Add true_bytes tests for ChaCha and Isaac; fix 2 bugs in fill_bytes i…
Browse files Browse the repository at this point in the history
…mpls

[Cherry-picked from ae365ef]
  • Loading branch information
dhardy committed Dec 15, 2017
1 parent e154d22 commit a2e7314
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/prng/chacha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,20 @@ mod test {
0x2c5bad8f, 0x898881dc, 0x5f1c86d9, 0xc1f8e7f4));
}

#[test]
fn test_rng_true_bytes() {
let seed : &[_] = &[0u32; 8];
let mut ra: ChaChaRng = SeedableRng::from_seed(seed);
let mut buf = [0u8; 32];
ra.fill_bytes(&mut buf);
// Same as first values in test_isaac_true_values as bytes in LE order
assert_eq!(buf,
[118, 184, 224, 173, 160, 241, 61, 144,
64, 93, 106, 229, 83, 134, 189, 40,
189, 210, 25, 184, 160, 141, 237, 26,
168, 54, 239, 204, 139, 119, 13, 199]);
}

#[test]
fn test_rng_clone() {
let seed : &[_] = &[0u32; 8];
Expand Down
14 changes: 14 additions & 0 deletions src/prng/isaac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,20 @@ mod test {
1576568959, 3507990155, 179069555, 141456972, 2478885421));
}

#[test]
fn test_isaac_true_bytes() {
let seed: &[_] = &[1, 23, 456, 7890, 12345];
let mut rng1 = IsaacRng::from_seed(seed);
let mut buf = [0u8; 32];
rng1.fill_bytes(&mut buf);
// Same as first values in test_isaac_true_values as bytes in LE order
assert_eq!(buf,
[82, 186, 128, 152, 71, 240, 20, 52,
45, 175, 180, 15, 86, 16, 99, 125,
101, 203, 81, 214, 97, 162, 134, 250,
103, 78, 203, 15, 150, 3, 210, 164]);
}

#[test]
fn test_isaac_new_uninitialized() {
// Compare the results from initializing `IsaacRng` with
Expand Down
16 changes: 15 additions & 1 deletion src/prng/isaac64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,21 @@ mod test {
596345674630742204, 9947027391921273664, 11788097613744130851,
10391409374914919106));
}


#[test]
fn test_isaac64_true_bytes() {
let seed: &[_] = &[1, 23, 456, 7890, 12345];
let mut rng1 = Isaac64Rng::from_seed(seed);
let mut buf = [0u8; 32];
rng1.fill_bytes(&mut buf);
// Same as first values in test_isaac64_true_values as bytes in LE order
assert_eq!(buf,
[140, 237, 103, 8, 93, 196, 151, 7,
156, 242, 26, 63, 54, 166, 135, 199,
141, 186, 192, 50, 116, 69, 205, 240,
98, 205, 127, 160, 83, 98, 49, 17]);
}

#[test]
fn test_isaac_new_uninitialized() {
// Compare the results from initializing `IsaacRng` with
Expand Down

0 comments on commit a2e7314

Please sign in to comment.