We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 60c9a88 commit 83ad711Copy full SHA for 83ad711
library/std/src/hash/random.rs
@@ -65,13 +65,16 @@ impl RandomState {
65
// iteration order allows a form of DOS attack. To counter that we
66
// increment one of the seeds on every RandomState creation, giving
67
// every corresponding HashMap a different iteration order.
68
- thread_local!(static KEYS: Cell<(u64, u64)> = {
+ thread_local!(static KEYS: Cell<[u8; 16]> = {
69
Cell::new(hashmap_random_keys())
70
});
71
72
KEYS.with(|keys| {
73
- let (k0, k1) = keys.get();
74
- keys.set((k0.wrapping_add(1), k1));
+ let [n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15] = keys.get();
+ let k0 = u64::from_ne_bytes([n0, n1, n2, n3, n4, n5, n6, n7]);
75
+ let k1 = u64::from_ne_bytes([n8, n9, n10, n11, n12, n13, n14, n15]);
76
+ let [n0, n1, n2, n3, n4, n5, n6, n7] = k0.wrapping_add(1).to_ne_bytes();
77
+ keys.set([n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15]);
78
RandomState { k0, k1 }
79
})
80
}
library/std/src/sys/random/mod.rs
@@ -89,10 +89,8 @@ cfg_if::cfg_if! {
89
all(target_family = "wasm", target_os = "unknown"),
90
target_os = "xous",
91
)))]
92
-pub fn hashmap_random_keys() -> (u64, u64) {
+pub fn hashmap_random_keys() -> [u8; 16] {
93
let mut buf = [0; 16];
94
fill_bytes(&mut buf);
95
- let k1 = u64::from_ne_bytes(buf[..8].try_into().unwrap());
96
- let k2 = u64::from_ne_bytes(buf[8..].try_into().unwrap());
97
- (k1, k2)
+ buf
98
0 commit comments