Skip to content

Commit ec43f1d

Browse files
committedSep 3, 2022
Auto merge of #2533 - saethlin:windows-rng, r=ChrisDenton
Support BCRYPT_RNG_ALG_HANDLE rust-lang/rust#101325 I haven't tested this on a Windows host, brace for CI...
2 parents 9073179 + ee1c1e6 commit ec43f1d

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed
 

‎rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8c6ce6b91b172f77c795a74bfeaf74b865146b3f
1+
47d1cdb0bcac8e417071ce1929d261efe2399ae2

‎src/shims/windows/foreign_items.rs

+23-10
Original file line numberDiff line numberDiff line change
@@ -288,19 +288,32 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
288288
let [algorithm, ptr, len, flags] =
289289
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
290290
let algorithm = this.read_scalar(algorithm)?;
291+
let algorithm = algorithm.to_machine_usize(this)?;
291292
let ptr = this.read_pointer(ptr)?;
292293
let len = this.read_scalar(len)?.to_u32()?;
293294
let flags = this.read_scalar(flags)?.to_u32()?;
294-
if flags != 2 {
295-
// ^ BCRYPT_USE_SYSTEM_PREFERRED_RNG
296-
throw_unsup_format!(
297-
"BCryptGenRandom is supported only with the BCRYPT_USE_SYSTEM_PREFERRED_RNG flag"
298-
);
299-
}
300-
if algorithm.to_machine_usize(this)? != 0 {
301-
throw_unsup_format!(
302-
"BCryptGenRandom algorithm must be NULL when the flag is BCRYPT_USE_SYSTEM_PREFERRED_RNG"
303-
);
295+
match flags {
296+
0 => {
297+
// BCRYPT_RNG_ALG_HANDLE
298+
if algorithm != 0x81 {
299+
throw_unsup_format!(
300+
"BCryptGenRandom algorithm must be BCRYPT_RNG_ALG_HANDLE when the flag is 0"
301+
);
302+
}
303+
}
304+
2 => {
305+
// BCRYPT_USE_SYSTEM_PREFERRED_RNG
306+
if algorithm != 0 {
307+
throw_unsup_format!(
308+
"BCryptGenRandom algorithm must be NULL when the flag is BCRYPT_USE_SYSTEM_PREFERRED_RNG"
309+
);
310+
}
311+
}
312+
_ => {
313+
throw_unsup_format!(
314+
"BCryptGenRandom is only supported with BCRYPT_USE_SYSTEM_PREFERRED_RNG or BCRYPT_RNG_ALG_HANDLE"
315+
);
316+
}
304317
}
305318
this.gen_random(ptr, len.into())?;
306319
this.write_null(dest)?; // STATUS_SUCCESS

0 commit comments

Comments
 (0)
Please sign in to comment.