Skip to content

Commit

Permalink
poly1305,polyval: import UhfClosure for better cosmetics (#211)
Browse files Browse the repository at this point in the history
Reduces the multi-line function signatures to a single line
  • Loading branch information
tarcieri authored Jul 26, 2024
1 parent 1d319ca commit bca110f
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 30 deletions.
7 changes: 2 additions & 5 deletions poly1305/src/backend/autodetect.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Autodetection support for AVX2 CPU intrinsics on x86 CPUs, with fallback
//! to the "soft" backend when it's unavailable.
use universal_hash::{consts::U16, crypto_common::BlockSizeUser, UniversalHash};
use universal_hash::{consts::U16, crypto_common::BlockSizeUser, UhfClosure, UniversalHash};

use crate::{backend, Block, Key, Tag};
use core::mem::ManuallyDrop;
Expand Down Expand Up @@ -53,10 +53,7 @@ impl State {
}

impl UniversalHash for State {
fn update_with_backend(
&mut self,
f: impl universal_hash::UhfClosure<BlockSize = Self::BlockSize>,
) {
fn update_with_backend(&mut self, f: impl UhfClosure<BlockSize = Self::BlockSize>) {
if self.token.get() {
unsafe { f.call(&mut *self.inner.avx2) }
} else {
Expand Down
7 changes: 2 additions & 5 deletions poly1305/src/backend/soft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use universal_hash::{
consts::{U1, U16},
crypto_common::{BlockSizeUser, ParBlocksSizeUser},
UhfBackend, UniversalHash,
UhfBackend, UhfClosure, UniversalHash,
};

use crate::{Block, Key, Tag};
Expand Down Expand Up @@ -257,10 +257,7 @@ impl UhfBackend for State {
}

impl UniversalHash for State {
fn update_with_backend(
&mut self,
f: impl universal_hash::UhfClosure<BlockSize = Self::BlockSize>,
) {
fn update_with_backend(&mut self, f: impl UhfClosure<BlockSize = Self::BlockSize>) {
f.call(self);
}

Expand Down
7 changes: 2 additions & 5 deletions poly1305/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub use universal_hash;
use universal_hash::{
consts::{U16, U32},
crypto_common::{BlockSizeUser, KeySizeUser},
KeyInit, UniversalHash,
KeyInit, UhfClosure, UniversalHash,
};

mod backend;
Expand Down Expand Up @@ -125,10 +125,7 @@ impl BlockSizeUser for Poly1305 {
}

impl UniversalHash for Poly1305 {
fn update_with_backend(
&mut self,
f: impl universal_hash::UhfClosure<BlockSize = Self::BlockSize>,
) {
fn update_with_backend(&mut self, f: impl UhfClosure<BlockSize = Self::BlockSize>) {
self.state.update_with_backend(f);
}

Expand Down
7 changes: 2 additions & 5 deletions polyval/src/backend/autodetect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use core::mem::ManuallyDrop;
use universal_hash::{
consts::U16,
crypto_common::{BlockSizeUser, KeySizeUser},
KeyInit, Reset, UniversalHash,
KeyInit, Reset, UhfClosure, UniversalHash,
};

#[cfg(all(target_arch = "aarch64", polyval_armv8))]
Expand Down Expand Up @@ -69,10 +69,7 @@ impl BlockSizeUser for Polyval {
}

impl UniversalHash for Polyval {
fn update_with_backend(
&mut self,
f: impl universal_hash::UhfClosure<BlockSize = Self::BlockSize>,
) {
fn update_with_backend(&mut self, f: impl UhfClosure<BlockSize = Self::BlockSize>) {
unsafe {
if self.token.get() {
f.call(&mut *self.inner.intrinsics)
Expand Down
7 changes: 2 additions & 5 deletions polyval/src/backend/soft32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use core::{
use universal_hash::{
consts::{U1, U16},
crypto_common::{BlockSizeUser, KeySizeUser, ParBlocksSizeUser},
KeyInit, Reset, UhfBackend, UniversalHash,
KeyInit, Reset, UhfBackend, UhfClosure, UniversalHash,
};

#[cfg(feature = "zeroize")]
Expand Down Expand Up @@ -86,10 +86,7 @@ impl UhfBackend for Polyval {
}

impl UniversalHash for Polyval {
fn update_with_backend(
&mut self,
f: impl universal_hash::UhfClosure<BlockSize = Self::BlockSize>,
) {
fn update_with_backend(&mut self, f: impl UhfClosure<BlockSize = Self::BlockSize>) {
f.call(self);
}

Expand Down
7 changes: 2 additions & 5 deletions polyval/src/backend/soft64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use core::{
use universal_hash::{
consts::{U1, U16},
crypto_common::{BlockSizeUser, KeySizeUser, ParBlocksSizeUser},
KeyInit, Reset, UhfBackend, UniversalHash,
KeyInit, Reset, UhfBackend, UhfClosure, UniversalHash,
};

#[cfg(feature = "zeroize")]
Expand Down Expand Up @@ -68,10 +68,7 @@ impl UhfBackend for Polyval {
}

impl UniversalHash for Polyval {
fn update_with_backend(
&mut self,
f: impl universal_hash::UhfClosure<BlockSize = Self::BlockSize>,
) {
fn update_with_backend(&mut self, f: impl UhfClosure<BlockSize = Self::BlockSize>) {
f.call(self);
}

Expand Down

0 comments on commit bca110f

Please sign in to comment.