Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use SipHash-1-3 instead of SipHash-2-4 for StableHasher #107925

Merged
merged 10 commits into from
Apr 5, 2023
20 changes: 9 additions & 11 deletions compiler/rustc_data_structures/src/sip128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl SipHasher128 {
for i in 0..BUFFER_CAPACITY {
let elem = self.buf.get_unchecked(i).assume_init().to_le();
self.state.v3 ^= elem;
Sip24Rounds::c_rounds(&mut self.state);
Sip13Rounds::c_rounds(&mut self.state);
self.state.v0 ^= elem;
}

Expand Down Expand Up @@ -327,7 +327,7 @@ impl SipHasher128 {
for i in 0..last {
let elem = self.buf.get_unchecked(i).assume_init().to_le();
self.state.v3 ^= elem;
Sip24Rounds::c_rounds(&mut self.state);
Sip13Rounds::c_rounds(&mut self.state);
self.state.v0 ^= elem;
}

Expand All @@ -340,7 +340,7 @@ impl SipHasher128 {
for _ in 0..elems_left {
let elem = (msg.as_ptr().add(processed) as *const u64).read_unaligned().to_le();
self.state.v3 ^= elem;
Sip24Rounds::c_rounds(&mut self.state);
Sip13Rounds::c_rounds(&mut self.state);
self.state.v0 ^= elem;
processed += ELEM_SIZE;
}
Expand Down Expand Up @@ -368,7 +368,7 @@ impl SipHasher128 {
for i in 0..last {
let elem = unsafe { self.buf.get_unchecked(i).assume_init().to_le() };
state.v3 ^= elem;
Sip24Rounds::c_rounds(&mut state);
Sip13Rounds::c_rounds(&mut state);
state.v0 ^= elem;
}

Expand All @@ -392,15 +392,15 @@ impl SipHasher128 {
let b: u64 = ((length as u64 & 0xff) << 56) | elem;

state.v3 ^= b;
Sip24Rounds::c_rounds(&mut state);
Sip13Rounds::c_rounds(&mut state);
state.v0 ^= b;

state.v2 ^= 0xee;
Sip24Rounds::d_rounds(&mut state);
Sip13Rounds::d_rounds(&mut state);
let _0 = state.v0 ^ state.v1 ^ state.v2 ^ state.v3;

state.v1 ^= 0xdd;
Sip24Rounds::d_rounds(&mut state);
Sip13Rounds::d_rounds(&mut state);
let _1 = state.v0 ^ state.v1 ^ state.v2 ^ state.v3;

(_0, _1)
Expand Down Expand Up @@ -477,20 +477,18 @@ impl Hasher for SipHasher128 {
}

#[derive(Debug, Clone, Default)]
struct Sip24Rounds;
struct Sip13Rounds;

impl Sip24Rounds {
impl Sip13Rounds {
#[inline]
fn c_rounds(state: &mut State) {
compress!(state);
compress!(state);
}

#[inline]
fn d_rounds(state: &mut State) {
compress!(state);
compress!(state);
compress!(state);
compress!(state);
}
}
Loading