-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Use getrandom for generating HashMap seed #80149
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
Changes from 5 commits
688ba4b
7d0be77
636bbf4
0117047
528fb0d
582566d
cd7f142
9d93d10
2011fe5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ use crate::fmt::{self, Debug}; | |
use crate::hash::{BuildHasher, Hash, Hasher, SipHasher13}; | ||
use crate::iter::{FromIterator, FusedIterator}; | ||
use crate::ops::Index; | ||
use crate::sys; | ||
|
||
/// A hash map implemented with quadratic probing and SIMD lookup. | ||
/// | ||
|
@@ -2783,13 +2782,24 @@ impl RandomState { | |
// iteration order allows a form of DOS attack. To counter that we | ||
// increment one of the seeds on every RandomState creation, giving | ||
// every corresponding HashMap a different iteration order. | ||
thread_local!(static KEYS: Cell<(u64, u64)> = { | ||
Cell::new(sys::hashmap_random_keys()) | ||
thread_local!(static KEYS: Cell<[u64; 2]> = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the change to an array? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was copied from the previous PR. I think at the time I introduced this change because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I personally think |
||
let mut buf = [0u8; 16]; | ||
// Use a constant seed on `wasm32-unknown-unknown` and Hermit targets. | ||
// FIXME: remove the Hermit part after its support will be added to `getrandom` | ||
// FIXME: replace the WASM part with `cfg(target = "..")`: | ||
newpavlov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// https://github.com/rust-lang/rust/issues/63217 | ||
#[cfg(not(any( | ||
all(target_arch = "wasm32", target_vendor = "unknown", target_os = "unknown"), | ||
all(target_arch = "aarch64", target_os = "hermit"), | ||
)))] | ||
getrandom::getrandom(&mut buf).expect("failed to get system entropy"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be good to convert the error to an |
||
let n = u128::from_ne_bytes(buf); | ||
Cell::new([n as u64, (n >> 64) as u64]) | ||
}); | ||
|
||
KEYS.with(|keys| { | ||
let (k0, k1) = keys.get(); | ||
keys.set((k0.wrapping_add(1), k1)); | ||
let [k0, k1] = keys.get(); | ||
keys.set([k0.wrapping_add(1), k1]); | ||
RandomState { k0, k1 } | ||
}) | ||
} | ||
|
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.