From 1ca55ac77db698f3816d8b7ed4051ddb5a579a29 Mon Sep 17 00:00:00 2001 From: Nick Johnson Date: Wed, 19 Feb 2025 13:04:20 -0800 Subject: [PATCH] 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. --- chacha20_poly1305/src/chacha20.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/chacha20_poly1305/src/chacha20.rs b/chacha20_poly1305/src/chacha20.rs index a93e0f1e6..b9080b40e 100644 --- a/chacha20_poly1305/src/chacha20.rs +++ b/chacha20_poly1305/src/chacha20.rs @@ -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();