From 78220644c425c1286123016ce6919d0329d4c15c Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 4 Mar 2026 13:46:33 -0600 Subject: [PATCH 1/4] Fix comments --- chacha20/src/legacy.rs | 2 +- chacha20/src/rng.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/chacha20/src/legacy.rs b/chacha20/src/legacy.rs index df599f04..9ec0d94a 100644 --- a/chacha20/src/legacy.rs +++ b/chacha20/src/legacy.rs @@ -15,7 +15,7 @@ use crate::variants::Legacy; /// The ChaCha20 stream cipher (legacy "djb" construction with 64-bit nonce). pub type ChaCha20Legacy = StreamCipherCoreWrapper; -/// /// The ChaCha20 stream cipher (legacy "djb" construction with 64-bit nonce). +/// The ChaCha20 stream cipher (legacy "djb" construction with 64-bit nonce). pub type ChaCha20LegacyCore = ChaChaCore; impl KeySizeUser for ChaCha20LegacyCore { diff --git a/chacha20/src/rng.rs b/chacha20/src/rng.rs index 94fe1d1c..f90fd626 100644 --- a/chacha20/src/rng.rs +++ b/chacha20/src/rng.rs @@ -193,7 +193,7 @@ macro_rules! impl_chacha_rng { impl $Rng { /// Get the offset from the start of the stream, in 32-bit words. /// - /// Since the generated blocks are 64 words (26) long and the + /// Since the generated blocks are 16 words (24) long and the /// counter is 64-bits, the offset is a 68-bit number. Sub-word offsets are /// not supported, hence the result can simply be multiplied by 4 to get a /// byte-offset. From 7fdf7eec6c62b60fa3a8ca1796af293ca60e5962 Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 4 Mar 2026 13:48:10 -0600 Subject: [PATCH 2/4] Fix ignored Clippy lint Changing from <*mut _>::offset() to <*mut _>::add() causes the compiler to infer that the type of state_row is usize instead of isize. This means the later cast is no longer needed. --- chacha20/src/backends/neon.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/chacha20/src/backends/neon.rs b/chacha20/src/backends/neon.rs index 8f27963b..279e87ad 100644 --- a/chacha20/src/backends/neon.rs +++ b/chacha20/src/backends/neon.rs @@ -180,10 +180,9 @@ impl StreamCipherBackend for Backend { } // write blocks to dest for state_row in 0..4 { - #[allow(clippy::cast_sign_loss, reason = "needs triage")] vst1q_u8( - dest[block].as_mut_ptr().offset(state_row << 4), - vreinterpretq_u8_u32(blocks[block][state_row as usize]), + dest[block].as_mut_ptr().add(state_row << 4), + vreinterpretq_u8_u32(blocks[block][state_row]), ); } } From fe7ef3fa948524981cf5a2b5fed85b31baf2f445 Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 4 Mar 2026 13:51:41 -0600 Subject: [PATCH 3/4] Replace literal value with constant --- chacha20/src/rng.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chacha20/src/rng.rs b/chacha20/src/rng.rs index f90fd626..d8c28240 100644 --- a/chacha20/src/rng.rs +++ b/chacha20/src/rng.rs @@ -252,7 +252,7 @@ macro_rules! impl_chacha_rng { let counter = self.core.core.get_block_pos(); let offset = self.core.word_offset(); if offset != 0 { - counter - u64::from(BUF_BLOCKS) + offset as u64 / 16 + counter - u64::from(BUF_BLOCKS) + offset as u64 / u64::from(BLOCK_WORDS) } else { counter } From 8778da35494ed4f65a3e239c5cba2e291d6255cb Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 4 Mar 2026 13:54:00 -0600 Subject: [PATCH 4/4] Change repeated section of test to match comment --- chacha20/tests/rng.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/chacha20/tests/rng.rs b/chacha20/tests/rng.rs index a89a4a99..49723c96 100644 --- a/chacha20/tests/rng.rs +++ b/chacha20/tests/rng.rs @@ -125,11 +125,12 @@ fn test_chacha_true_values_c() { // Test block 2 by using `set_block_pos` and [u8; 8] let mut rng4 = ChaCha20Rng::from_seed(seed); rng4.set_block_pos(2); - results = [0u32; 16]; - for i in results.iter_mut() { - *i = rng4.next_u32(); + let mut buf = [0u8; 8]; + for chunk in expected.chunks_exact(2) { + rng4.fill_bytes(&mut buf); + assert_eq!(buf[..4], chunk[0].to_le_bytes()); + assert_eq!(buf[4..], chunk[1].to_le_bytes()); } - assert_eq!(results, expected); assert_eq!(rng4.get_word_pos(), expected_end); // Test skipping behaviour with other types