Skip to content

Commit 2c1daf1

Browse files
committed
More pre-mixing to guard against partially weak keys
Signed-off-by: Tom Kaitchuck <[email protected]>
1 parent c069bdc commit 2c1daf1

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/random_state.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,17 @@ impl RandomState {
212212
let &[k0, k1, k2, k3] = a;
213213
let mut hasher = AHasher::from_random_state(&RandomState { k0, k1, k2, k3 });
214214
hasher.write_usize(c);
215-
let mix = |k: u64| {
215+
let mix = |l: u64, r: u64| {
216216
let mut h = hasher.clone();
217-
h.write_u64(k);
217+
h.write_u64(l);
218+
h.write_u64(r);
218219
h.finish()
219220
};
220221
RandomState {
221-
k0: mix(b[0]),
222-
k1: mix(b[1]),
223-
k2: mix(b[2]),
224-
k3: mix(b[3]),
222+
k0: mix(b[0], b[2]),
223+
k1: mix(b[1], b[3]),
224+
k2: mix(b[2], b[1]),
225+
k3: mix(b[3], b[0]),
225226
}
226227
}
227228

0 commit comments

Comments
 (0)