summaryrefslogtreecommitdiffstats
path: root/vendor/ahash/src/aes_hash.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ahash/src/aes_hash.rs')
-rw-r--r--vendor/ahash/src/aes_hash.rs30
1 files changed, 12 insertions, 18 deletions
diff --git a/vendor/ahash/src/aes_hash.rs b/vendor/ahash/src/aes_hash.rs
index 1c98582ce..702044e5e 100644
--- a/vendor/ahash/src/aes_hash.rs
+++ b/vendor/ahash/src/aes_hash.rs
@@ -1,10 +1,8 @@
use crate::convert::*;
-#[cfg(feature = "specialize")]
-use crate::fallback_hash::MULTIPLE;
use crate::operations::*;
+use crate::random_state::PI;
use crate::RandomState;
use core::hash::Hasher;
-use crate::random_state::PI;
/// A `Hasher` for hashing an arbitrary stream of bytes.
///
@@ -50,7 +48,7 @@ impl AHasher {
/// println!("Hash is {:x}!", hasher.finish());
/// ```
#[inline]
- pub fn new_with_keys(key1: u128, key2: u128) -> Self {
+ pub(crate) fn new_with_keys(key1: u128, key2: u128) -> Self {
let pi: [u128; 2] = PI.convert();
let key1 = key1 ^ pi[0];
let key2 = key2 ^ pi[1];
@@ -70,7 +68,6 @@ impl AHasher {
}
}
-
#[inline]
pub(crate) fn from_random_state(rand_state: &RandomState) -> Self {
let key1 = [rand_state.k0, rand_state.k1].convert();
@@ -83,14 +80,6 @@ impl AHasher {
}
#[inline(always)]
- fn add_in_length(&mut self, length: u64) {
- //This will be scrambled by the next AES round.
- let mut enc: [u64; 2] = self.enc.convert();
- enc[0] = enc[0].wrapping_add(length);
- self.enc = enc.convert();
- }
-
- #[inline(always)]
fn hash_in(&mut self, new_value: u128) {
self.enc = aesenc(self.enc, new_value);
self.sum = shuffle_and_add(self.sum, new_value);
@@ -138,7 +127,11 @@ impl Hasher for AHasher {
}
#[inline]
- #[cfg(any(target_pointer_width = "64", target_pointer_width = "32", target_pointer_width = "16"))]
+ #[cfg(any(
+ target_pointer_width = "64",
+ target_pointer_width = "32",
+ target_pointer_width = "16"
+ ))]
fn write_usize(&mut self, i: usize) {
self.write_u64(i as u64);
}
@@ -159,7 +152,8 @@ impl Hasher for AHasher {
fn write(&mut self, input: &[u8]) {
let mut data = input;
let length = data.len();
- self.add_in_length(length as u64);
+ add_in_length(&mut self.enc, length as u64);
+
//A 'binary search' on sizes reduces the number of comparisons.
if data.len() <= 8 {
let value = read_small(data);
@@ -326,7 +320,7 @@ pub(crate) struct AHasherStr(pub AHasher);
impl Hasher for AHasherStr {
#[inline]
fn finish(&self) -> u64 {
- let result : [u64; 2] = self.0.enc.convert();
+ let result: [u64; 2] = self.0.enc.convert();
result[0]
}
@@ -337,7 +331,8 @@ impl Hasher for AHasherStr {
self.0.enc = aesdec(self.0.sum, self.0.enc);
self.0.enc = aesenc(aesenc(self.0.enc, self.0.key), self.0.enc);
} else {
- self.0.add_in_length(bytes.len() as u64);
+ add_in_length(&mut self.0.enc, bytes.len() as u64);
+
let value = read_small(bytes).convert();
self.0.sum = shuffle_and_add(self.0.sum, value);
self.0.enc = aesdec(self.0.sum, self.0.enc);
@@ -436,4 +431,3 @@ mod tests {
assert_eq!(bytes, 0x6464646464646464);
}
}
-