mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
shared hash seed in process
This commit is contained in:
1 parent
42c7c79031
commit
7105073c91
2 files changed
+13
-5
No files matched your search
+3
-2
@@ -54,8 +54,9 @@ impl HashSecret {
|
||||
pub fn new(seed: u32) -> Self {
|
||||
let mut buf = [0u8; 16];
|
||||
lcg_urandom(seed, &mut buf);
|
||||
let k0 = u64::from_le_bytes(buf[..8].try_into().unwrap());
|
||||
let k1 = u64::from_le_bytes(buf[8..].try_into().unwrap());
|
||||
let (left, right) = buf.split_at(8);
|
||||
let k0 = u64::from_le_bytes(left.try_into().unwrap());
|
||||
let k1 = u64::from_le_bytes(right.try_into().unwrap());
|
||||
Self { k0, k1 }
|
||||
}
|
||||
}
|
||||
|
||||
+10
-3
@@ -88,6 +88,12 @@ pub struct PyGlobalState {
|
||||
pub codec_registry: CodecsRegistry,
|
||||
}
|
||||
|
||||
pub fn process_hash_secret_seed() -> u32 {
|
||||
use once_cell::sync::OnceCell;
|
||||
static SEED: OnceCell<u32> = OnceCell::new();
|
||||
*SEED.get_or_init(rand::random)
|
||||
}
|
||||
|
||||
impl VirtualMachine {
|
||||
/// Create a new `VirtualMachine` structure.
|
||||
fn new(settings: Settings, ctx: PyRc<Context>) -> VirtualMachine {
|
||||
@@ -120,10 +126,11 @@ impl VirtualMachine {
|
||||
|
||||
let module_inits = stdlib::get_module_inits();
|
||||
|
||||
let hash_secret = match settings.hash_seed {
|
||||
Some(seed) => HashSecret::new(seed),
|
||||
None => rand::random(),
|
||||
let seed = match settings.hash_seed {
|
||||
Some(seed) => seed,
|
||||
None => process_hash_secret_seed(),
|
||||
};
|
||||
let hash_secret = HashSecret::new(seed);
|
||||
|
||||
let codec_registry = CodecsRegistry::new(&ctx);
|
||||
|
||||
|
||||
Reference in new issue
Block a user