-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit required modifying the build context to allow for the AES optimizations of GxHash. It should not prove to be an issue on the system we use (x86-64 and maybe ARM64) which I've tested before this commit.
- Loading branch information
Johannes Wünsche
committed
Apr 15, 2024
1 parent
57bd6be
commit 9192b43
Showing
6 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[build] | ||
rustflags = ["-C","target-cpu=native"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/// Impl for Checksum for FxHashw. | ||
use super::{Builder, Checksum, ChecksumError, State}; | ||
use crate::size::StaticSize; | ||
use gxhash::GxHasher; | ||
use serde::{Deserialize, Serialize}; | ||
use std::hash::Hasher; | ||
|
||
/// A checksum created by `GxHash`. | ||
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)] | ||
pub struct GxHash(u64); | ||
|
||
impl StaticSize for GxHash { | ||
fn static_size() -> usize { | ||
8 | ||
} | ||
} | ||
|
||
impl Checksum for GxHash { | ||
type Builder = GxHashBuilder; | ||
|
||
fn verify_buffer<I: IntoIterator<Item = T>, T: AsRef<[u8]>>( | ||
&self, | ||
data: I, | ||
) -> Result<(), ChecksumError> { | ||
let mut state = GxHashBuilder.build(); | ||
for x in data { | ||
state.ingest(x.as_ref()); | ||
} | ||
let other = state.finish(); | ||
if *self == other { | ||
Ok(()) | ||
} else { | ||
Err(ChecksumError) | ||
} | ||
} | ||
|
||
fn builder() -> Self::Builder { | ||
GxHashBuilder | ||
} | ||
} | ||
|
||
/// The corresponding `Builder` for `GxHash`. | ||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
pub struct GxHashBuilder; | ||
|
||
impl Builder<GxHash> for GxHashBuilder { | ||
type State = GxHashState; | ||
|
||
fn build(&self) -> Self::State { | ||
// Due to security concerns the default `GxHasher` is randomized, which | ||
// does not work for us, therefore, use pinned seed. | ||
GxHashState(GxHasher::with_seed(0)) | ||
} | ||
} | ||
|
||
/// The internal state of `GxHash`. | ||
pub struct GxHashState(GxHasher); | ||
|
||
impl State for GxHashState { | ||
type Checksum = GxHash; | ||
|
||
fn ingest(&mut self, data: &[u8]) { | ||
self.0.write(data); | ||
} | ||
|
||
fn finish(self) -> Self::Checksum { | ||
GxHash(self.0.finish()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters