Uh oh!
There was an error while loading. Please reload this page.
Use getrandom for generating HashMap seed - #80149
Conversation
rust-highfive
commented
Dec 18, 2020
r? @shepmaster (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
shepmaster
commented
Jan 1, 2021
This is a bit too deep for me... |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| // 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.
It was copied from the previous PR. I think at the time I introduced this change because [u64; 2] is slightly more idiomatic than (u64, u64).
There was a problem hiding this comment.
I personally think (u64, u64) makes more sense because it's used to fill out a RandomState which consists of two separate u64s rather than an array, but it's not a huge deal.
newpavlov
commented
Feb 9, 2021
r? @sfackler |
sfackler
commented
Feb 10, 2021
@Mark-Simulacrum what are the procedures to pull in a new std dependency? |
Mark-Simulacrum
commented
Feb 10, 2021
I'll assign myself for now and get back to you soon. |
Mark-Simulacrum
commented
Feb 12, 2021
Can you clarify whether you mean the mechanics (i.e., infrastructure of adding deps in terms of toml files to edit and such) or policy questions? I think the first is likely working in this PR already, and the latter would need more time on my side to answer properly. |
sfackler
commented
Feb 12, 2021
Yeah I'm mostly wondering about the policy side, since CI should nail down the functionality. |
bors
commented
Apr 5, 2021
☔ The latest upstream changes (presumably #83890) made this pull request unmergeable. Please resolve the merge conflicts. |
newpavlov
commented
Apr 5, 2021
@m-ou-se |
m-ou-se
commented
Apr 11, 2021
@newpavlov I reviewed the Overall the quality looks good, and I'd be happy to see this under There's a few important differences in behaviour if we switch Most importantly, Also, |
m-ou-se
commented
Apr 11, 2021
I think there's one change/addition to the API that could be somewhat useful: a way to read into uninitialized buffers. E.g. by accepting a |
| 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.
It might be good to convert the error to an std::io::Error first before panicking on it. That way, it uses the Debug implementation of std's Error and we don't pull in any of getrandoms display/debug code.
bors
commented
Apr 22, 2021
☔ The latest upstream changes (presumably #84411) made this pull request unmergeable. Please resolve the merge conflicts. |
crlf0710
commented
May 7, 2021
Marking this as S-blocked. |
gilescope
commented
Oct 18, 2021
"Use BCryptGenRandom instead of RtlGenRandom on Windows." merged. nice - that's great news. It's getting there... |
cameronelliott
commented
Nov 9, 2022
Will this change the availability of HashMap with regards to no_std ? |
bjorn3
commented
Nov 9, 2022
No, getting randomness needs interaction with an OS on every architecture other than newish x86 systems (through rdrand). |
therealprof
commented
Nov 9, 2022
So in what way does the |
bjorn3
commented
Nov 9, 2022
libstd's HashMap is a wrapper around hashbrown that uses a hasher by default using randomness to ensure hashdos resistence. |
therealprof
commented
Nov 9, 2022
Makes sense, but why can't |
bjorn3
commented
Nov 9, 2022
That would make alloc::collections::HashMap and std::collections::HashMap permanently incompatible with each other. This is bound to give a lot of confusion and would prevent merging them in the future if we find a way to support this. For example by allowing the user to specify the rng using a mechanism similar to |
therealprof
commented
Nov 9, 2022
Fair point, OTOH this is adding a bit of confusion because people can't just opt into an |
bjorn3
commented
Nov 9, 2022
Hashbrown doesn't have the same stability guarantees as rust and it exports a lot of methods that are unstable or non-existent in the libstd version. Hiding those cq giving them an |
scottmcm
commented
Jan 8, 2023
Ideally we'd be able to move the wrapper to AFAIK that doesn't work right now, though, because of some coherence restrictions. |
newpavlov
commented
Apr 2, 2023
This PR is significantly outdated, so I will close it. I will create a new PR after we address the @m-ou-se's review. |
Closes: #62079
Note that in future versions of
getrandomwe plan to remove Windows XP support, thusstdshould not update it fromv0.2.0until rust-lang/compiler-team#378 gets resolved. Also ideally it should be done together with updatingwasito v0.10.Since the
rdrandfeature is enabled unconditionally, RDRAND will be used not only on SGX targets, but also on all x86(-64) targets which are not supported ingetrandomby default (e.g. UEFI and Hermit targets, see rust-random/getrandom#61).As mentioned in the previous PR discussion, if it will be deemed necessary, we (
getrandommaintainers) are ready to transfergetrandomto the rust-lang organization.Blocked on m-ou-se/getrandom#1