From 842d0de3c6ce744b3571bdf0ce80c29dd44d7c6e Mon Sep 17 00:00:00 2001 From: Noah Stiltner <nstilt1@lsu.edu> Date: Thu, 2 Nov 2023 19:56:09 -0500 Subject: [PATCH] if set_word_pos_bytes is desirable, pick your poison between this commit and what is there now, or suggest something prettier --- chacha20/src/rng.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/chacha20/src/rng.rs b/chacha20/src/rng.rs index c3a29f08..b9bdfb6a 100644 --- a/chacha20/src/rng.rs +++ b/chacha20/src/rng.rs @@ -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(); }