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