chacha20_poly1305: inline simd functions

* Inline all the block operations to give the compiler the best chance
to optimize the SIMD instruction usage. This squeezed out another
percent or two on the benchmarks when comparing target-cpu=native
builds to standard.
This commit is contained in:
Nick Johnson 2025-02-19 13:04:20 -08:00
parent 30920c4d84
commit 1ca55ac77d
No known key found for this signature in database
GPG Key ID: 97B34267D0DBC8BF
1 changed files with 3 additions and 0 deletions

View File

@ -223,6 +223,7 @@ impl State {
}
/// Transform the state by performing the ChaCha block function.
#[inline(always)]
fn chacha_block(&mut self) {
let mut working_state = self.matrix;
@ -237,6 +238,7 @@ impl State {
}
/// Expose the 512-bit state as a byte stream.
#[inline(always)]
fn keystream(&self) -> [u8; 64] {
let mut keystream = [0u8; 64];
for i in 0..4 {
@ -275,6 +277,7 @@ impl ChaCha20 {
}
/// Get the keystream for a specific block.
#[inline(always)]
fn keystream_at_block(&self, block: u32) -> [u8; 64] {
let mut state = State::new(self.key, self.nonce, block);
state.chacha_block();