Skip to content

Commit e998b15

Browse files
committed
Add inherent {get,set}_block_pos methods
1 parent 8b9650e commit e998b15

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

chacha20/src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,16 @@ impl<R: Rounds, V: Variant> ChaChaCore<R, V> {
265265
_pd: PhantomData,
266266
}
267267
}
268+
269+
#[inline(always)]
270+
fn get_block_pos(&self) -> V::Counter {
271+
V::get_block_pos(&self.state[12..])
272+
}
273+
274+
#[inline(always)]
275+
fn set_block_pos(&mut self, pos: V::Counter) {
276+
V::set_block_pos(&mut self.state[12..], pos);
277+
}
268278
}
269279

270280
#[cfg(feature = "cipher")]
@@ -273,12 +283,12 @@ impl<R: Rounds, V: Variant> StreamCipherSeekCore for ChaChaCore<R, V> {
273283

274284
#[inline(always)]
275285
fn get_block_pos(&self) -> Self::Counter {
276-
V::get_block_pos(&self.state[12..])
286+
self.get_block_pos()
277287
}
278288

279289
#[inline(always)]
280290
fn set_block_pos(&mut self, pos: Self::Counter) {
281-
V::set_block_pos(&mut self.state[12..], pos);
291+
self.set_block_pos(pos)
282292
}
283293
}
284294

chacha20/src/rng.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,7 @@ macro_rules! impl_chacha_rng {
385385
#[inline]
386386
#[allow(unused)]
387387
pub fn get_block_pos(&self) -> u64 {
388-
let counter =
389-
self.core.core.state[12] as u64 | ((self.core.core.state[13] as u64) << 32);
388+
let counter = self.core.get_block_pos();
390389
if self.core.word_offset() != 0 {
391390
counter - BUF_BLOCKS as u64 + self.core.word_offset() as u64 / 16
392391
} else {

0 commit comments

Comments
 (0)