Skip to content

Commit 713da83

Browse files
committed
Apply #[target_feature=avx2] and #[inline(always)] liberally
1 parent c160d1c commit 713da83

File tree

5 files changed

+201
-184
lines changed

5 files changed

+201
-184
lines changed

poly1305/src/autodetect.rs

+13
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,16 @@ impl Clone for State {
8383
}
8484
}
8585
}
86+
87+
#[cfg(feature = "zeroize")]
88+
impl Drop for State {
89+
fn drop(&mut self) {
90+
use zeroize::Zeroize;
91+
92+
if self.token.get() {
93+
// TODO(tarcieri): impl `Zeroize` for AVX2 backend (need SIMD register support)
94+
} else {
95+
unsafe { self.inner.soft.zeroize() }
96+
}
97+
}
98+
}

poly1305/src/backend/avx2.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl State {
4545
/// Initialize Poly1305 [`State`] with the given key
4646
pub(crate) fn new(key: &Key) -> Self {
4747
// Prepare addition key and polynomial key.
48-
let (k, r1) = prepare_keys(key);
48+
let (k, r1) = unsafe { prepare_keys(key) };
4949

5050
// Precompute R^2.
5151
let r2 = (r1 * r1).reduce();
@@ -68,7 +68,8 @@ impl State {
6868
}
6969

7070
/// Compute a Poly1305 block
71-
pub(crate) fn compute_block(&mut self, block: &Block, partial: bool) {
71+
#[target_feature(enable = "avx2")]
72+
pub(crate) unsafe fn compute_block(&mut self, block: &Block, partial: bool) {
7273
// We can cache a single partial block.
7374
if partial {
7475
assert!(self.partial_block.is_none());
@@ -101,7 +102,8 @@ impl State {
101102
}
102103

103104
/// Finalize output producing a [`Tag`]
104-
pub(crate) fn finalize(&mut self) -> Tag {
105+
#[target_feature(enable = "avx2")]
106+
pub(crate) unsafe fn finalize(&mut self) -> Tag {
105107
assert!(self.num_cached_blocks < 4);
106108
let mut data = &self.cached_blocks[..];
107109

0 commit comments

Comments
 (0)