refactor block

This commit is contained in:
Neemek 2025-11-06 23:14:14 +01:00
parent c7b4502db0
commit 76695723ed

View file

@ -38,6 +38,10 @@ impl Block {
pub fn advance(&mut self) { pub fn advance(&mut self) {
self.counter += 1; self.counter += 1;
self.compute_block();
}
fn compute_block(&mut self) {
self.chunk = few_u32_to_many_u8(&chacha_block(&self.key, self.counter, self.nonce, self.rounds)); self.chunk = few_u32_to_many_u8(&chacha_block(&self.key, self.counter, self.nonce, self.rounds));
} }
@ -53,6 +57,12 @@ impl Block {
} }
} }
} }
pub fn reset(&mut self, next_nonce: [u32; 3]) {
self.counter = 0;
self.nonce = next_nonce;
self.compute_block();
}
} }
#[inline] #[inline]