Skip to content

Commit

Permalink
if set_word_pos_bytes is desirable, pick your poison between this com…
Browse files Browse the repository at this point in the history
…mit and what is there now, or suggest something prettier
  • Loading branch information
nstilt1 committed Nov 3, 2023
1 parent c77dcc2 commit 842d0de
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions chacha20/src/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,21 +321,22 @@ macro_rules! impl_chacha_rng {
/// 28 bits.
#[inline]
pub fn set_word_pos_bytes(&mut self, word_offset: &[u8; 8]) {
#[cfg(feature = "zeroize")]
let mut original_word_offset = u64::from_le_bytes(*word_offset);
#[cfg(feature = "zeroize")]
let mut block = original_word_offset >> 4;

#[cfg(not(feature = "zeroize"))]
{
let original_word_offset = u64::from_le_bytes(*word_offset);
let block = original_word_offset >> 4;
self.rng.core.block.set_block_pos(block as u32);
self.rng
.generate_and_set((original_word_offset - block) as usize);
}
let original_word_offset = u64::from_le_bytes(*word_offset);
#[cfg(not(feature = "zeroize"))]
let block = original_word_offset >> 4;

self.rng.core.block.set_block_pos(block as u32);
self.rng
.generate_and_set((original_word_offset - block) as usize);

#[cfg(feature = "zeroize")]
{
let mut original_word_offset = u64::from_le_bytes(*word_offset);
let mut block = original_word_offset >> 4;
self.rng.core.block.set_block_pos(block as u32);
self.rng
.generate_and_set((original_word_offset - block) as usize);
original_word_offset.zeroize();
block.zeroize();
}
Expand Down

0 comments on commit 842d0de

Please sign in to comment.