summaryrefslogtreecommitdiffstats
path: root/vendor/ahash/src/fallback_hash.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /vendor/ahash/src/fallback_hash.rs
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/ahash/src/fallback_hash.rs')
-rw-r--r--vendor/ahash/src/fallback_hash.rs40
1 files changed, 8 insertions, 32 deletions
diff --git a/vendor/ahash/src/fallback_hash.rs b/vendor/ahash/src/fallback_hash.rs
index aad9efc85..f78074d77 100644
--- a/vendor/ahash/src/fallback_hash.rs
+++ b/vendor/ahash/src/fallback_hash.rs
@@ -1,12 +1,11 @@
use crate::convert::*;
use crate::operations::folded_multiply;
use crate::operations::read_small;
+use crate::operations::MULTIPLE;
use crate::random_state::PI;
use crate::RandomState;
use core::hash::Hasher;
-///This constant come from Kunth's prng (Empirically it works better than those from splitmix32).
-pub(crate) const MULTIPLE: u64 = 6364136223846793005;
const ROT: u32 = 23; //17
/// A `Hasher` for hashing an arbitrary stream of bytes.
@@ -31,7 +30,7 @@ impl AHasher {
/// Creates a new hasher keyed to the provided key.
#[inline]
#[allow(dead_code)] // Is not called if non-fallback hash is used.
- pub fn new_with_keys(key1: u128, key2: u128) -> AHasher {
+ pub(crate) fn new_with_keys(key1: u128, key2: u128) -> AHasher {
let pi: [u128; 2] = PI.convert();
let key1: [u64; 2] = (key1 ^ pi[0]).convert();
let key2: [u64; 2] = (key2 ^ pi[1]).convert();
@@ -93,19 +92,10 @@ impl AHasher {
/// attacker somehow knew part of (but not all) the contents of the buffer before hand,
/// they would not be able to predict any of the bits in the buffer at the end.
#[inline(always)]
- #[cfg(feature = "folded_multiply")]
fn update(&mut self, new_data: u64) {
self.buffer = folded_multiply(new_data ^ self.buffer, MULTIPLE);
}
- #[inline(always)]
- #[cfg(not(feature = "folded_multiply"))]
- fn update(&mut self, new_data: u64) {
- let d1 = (new_data ^ self.buffer).wrapping_mul(MULTIPLE);
- self.pad = (self.pad ^ d1).rotate_left(8).wrapping_mul(MULTIPLE);
- self.buffer = (self.buffer ^ self.pad).rotate_left(24);
- }
-
/// Similar to the above this function performs an update using a "folded multiply".
/// However it takes in 128 bits of data instead of 64. Both halves must be masked.
///
@@ -118,21 +108,12 @@ impl AHasher {
/// can't be changed by the same set of input bits. To cancel this sequence with subsequent input would require
/// knowing the keys.
#[inline(always)]
- #[cfg(feature = "folded_multiply")]
fn large_update(&mut self, new_data: u128) {
let block: [u64; 2] = new_data.convert();
let combined = folded_multiply(block[0] ^ self.extra_keys[0], block[1] ^ self.extra_keys[1]);
self.buffer = (self.buffer.wrapping_add(self.pad) ^ combined).rotate_left(ROT);
}
- #[inline(always)]
- #[cfg(not(feature = "folded_multiply"))]
- fn large_update(&mut self, new_data: u128) {
- let block: [u64; 2] = new_data.convert();
- self.update(block[0] ^ self.extra_keys[0]);
- self.update(block[1] ^ self.extra_keys[1]);
- }
-
#[inline]
#[cfg(feature = "specialize")]
fn short_finish(&self) -> u64 {
@@ -170,7 +151,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);
}
@@ -208,18 +193,10 @@ impl Hasher for AHasher {
}
#[inline]
- #[cfg(feature = "folded_multiply")]
fn finish(&self) -> u64 {
let rot = (self.buffer & 63) as u32;
folded_multiply(self.buffer, self.pad).rotate_left(rot)
}
-
- #[inline]
- #[cfg(not(feature = "folded_multiply"))]
- fn finish(&self) -> u64 {
- let rot = (self.buffer & 63) as u32;
- (self.buffer.wrapping_mul(MULTIPLE) ^ self.pad).rotate_left(rot)
- }
}
#[cfg(feature = "specialize")]
@@ -338,8 +315,7 @@ impl Hasher for AHasherStr {
self.0.write(bytes)
} else {
let value = read_small(bytes);
- self.0.buffer = folded_multiply(value[0] ^ self.0.buffer,
- value[1] ^ self.0.extra_keys[1]);
+ self.0.buffer = folded_multiply(value[0] ^ self.0.buffer, value[1] ^ self.0.extra_keys[1]);
self.0.pad = self.0.pad.wrapping_add(bytes.len() as u64);
}
}