Skip to content

Commit 889c79a

Browse files
committed
Auto merge of #121337 - ChrisDenton:ProcessPrng, r=Mark-Simulacrum
Windows: Use ProcessPrng for random keys Windows 10 introduced [`ProcessPrng`](https://learn.microsoft.com/en-us/windows/win32/seccng/processprng) for random number generation. This allows us to replace the overly complicated (and prone to failure) `BCryptGenRandom` with a documented function. For the tier 3 Windows 7 target, we simply use the older `RtlGenRandom`, which is undocumented. It should be fine even on modern systems (for comparability reasons) as it's just a wrapper for `ProcessPrng`. However, it does require loading an extra intermediary DLL which we can avoid when we know we have Windows 10+.
2 parents 18893c9 + 3c12154 commit 889c79a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/shims/windows/foreign_items.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
427427
this.gen_random(ptr, len.into())?;
428428
this.write_scalar(Scalar::from_bool(true), dest)?;
429429
}
430+
"ProcessPrng" => {
431+
let [ptr, len] =
432+
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
433+
let ptr = this.read_pointer(ptr)?;
434+
let len = this.read_target_usize(len)?;
435+
this.gen_random(ptr, len.into())?;
436+
this.write_scalar(Scalar::from_i32(1), dest)?;
437+
}
430438
"BCryptGenRandom" => {
431439
let [algorithm, ptr, len, flags] =
432440
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;

0 commit comments

Comments
 (0)