Skip to content

Commit

Permalink
remove rand_core-0.7-dependent test; remove unnecessary comments; ren…
Browse files Browse the repository at this point in the history
…ame LesserBlock to Block
  • Loading branch information
nstilt1 committed Oct 28, 2023
1 parent b227065 commit 5713e7e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 36 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target/
**/Cargo.lock
*/.cargo/config
*/.cargo/config
.vscode/
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

9 changes: 2 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion chacha20/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ categories = ["cryptography", "no-std"]
[dependencies]
cfg-if = "1"
cipher = "0.4.4"
rand_core = { version = "0.7.0", git = "https://github.com/rust-random/rand.git", package = "rand_core", branch = "master", optional = true, default-features = false, features = ["getrandom"] }
rand_core = { version = "0.6.4", optional = true, default-features = false, features = ["getrandom"] }
serde = { version = "1.0", features = ["derive"], optional = true }

[target.'cfg(any(target_arch = "x86_64", target_arch = "x86"))'.dependencies]
Expand Down
39 changes: 15 additions & 24 deletions chacha20/src/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ impl AsMut<[u32]> for BlockRngResults {
impl BlockSizeUser for BlockRngResults {
type BlockSize = U64;
fn block_size() -> usize {
256 // for U32x64
//512 // for U64x64
//256 // for U64x32
256
}
}

Expand All @@ -79,20 +77,20 @@ impl ZeroizeOnDrop for BlockRngResults {}

/// This is the internal block of ChaChaCore
#[derive(Copy, Clone)]
struct LesserBlock(GenericArray<u8, U64>);
impl AsRef<[u8]> for LesserBlock {
struct Block(GenericArray<u8, U64>);
impl AsRef<[u8]> for Block {
fn as_ref(&self) -> &[u8] {
&self.0
}
}

impl BlockSizeUser for LesserBlock {
impl BlockSizeUser for Block {
type BlockSize = U64;
fn block_size() -> usize {
64
}
}
impl ParBlocksSizeUser for LesserBlock {
impl ParBlocksSizeUser for Block {
type ParBlocksSize = U4;
}

Expand Down Expand Up @@ -237,7 +235,7 @@ macro_rules! impl_chacha_rng {
#[derive(Clone)]
pub struct $ChaChaXCore {
block: ChaChaCore<$rounds>,
parallel_blocks: ParBlocks<LesserBlock>,
parallel_blocks: ParBlocks<Block>,
counter: u32,
}

Expand All @@ -260,10 +258,6 @@ macro_rules! impl_chacha_rng {
type Results = BlockRngResults;

fn generate(&mut self, results: &mut Self::Results) {
// builds a wide buffer to send into Backend .gen_par_ks_blocks()
// through StreamBackend's .write_keystream_blocks()
// Buffer is [[u8; 64]; 4] and will run .gen_ks_block() 4 times if
// it uses soft.rs instead of SIMD
self.block.write_keystream_blocks(&mut self.parallel_blocks);
let mut offset = 0;
for block in self.parallel_blocks {
Expand Down Expand Up @@ -528,9 +522,6 @@ mod tests {

assert_eq!(rng.get_seed(), seed);
assert_eq!(rng.get_stream(), stream);
// set_word_pos() rounds it down to the nearest multiple of 16
// which would fail this:
// assert_eq!(rng.get_word_pos(), word_pos);
assert_eq!(rng.get_word_pos(), original_rng.get_word_pos() as u64);
assert_eq!(rng.get_word_pos(), word_pos);
}
Expand Down Expand Up @@ -829,14 +820,14 @@ mod tests {
assert_eq!(rng.get_word_pos(), 0);
}

#[test]
fn test_trait_objects() {
use rand_core::CryptoRng;
// #[test]
// fn test_trait_objects() {
// use rand_core::CryptoRng;

let mut rng1 = ChaChaRng::from_seed(Default::default());
let rng2 = &mut rng1.clone() as &mut dyn CryptoRng;
for _ in 0..1000 {
assert_eq!(rng1.next_u64(), rng2.next_u64());
}
}
// let mut rng1 = ChaChaRng::from_seed(Default::default());
// let rng2 = &mut rng1.clone() as &mut dyn CryptoRng;
// for _ in 0..1000 {
// assert_eq!(rng1.next_u64(), rng2.next_u64());
// }
// }
}

0 comments on commit 5713e7e

Please sign in to comment.