diff options
| author | bors <bors@rust-lang.org> | 2022-09-03 19:32:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-09-03 19:32:09 +0000 |
| commit | ec43f1dd9b8bfed8939e8df8424d329d7e1c0253 (patch) | |
| tree | 7d935147831c51db288961e8bae8be97395539e1 | |
| parent | 90731796c5b91d0699215270ad8872eaa4b0515d (diff) | |
| parent | ee1c1e6d7850cc5ff366b5e1855918e0fc1d80b5 (diff) | |
| download | rust-ec43f1dd9b8bfed8939e8df8424d329d7e1c0253.tar.gz rust-ec43f1dd9b8bfed8939e8df8424d329d7e1c0253.zip | |
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...
| -rw-r--r-- | rust-version | 2 | ||||
| -rw-r--r-- | src/shims/windows/foreign_items.rs | 33 |
2 files changed, 24 insertions, 11 deletions
diff --git a/rust-version b/rust-version index 1b1d2b0f2b5..5ce9544acc7 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -8c6ce6b91b172f77c795a74bfeaf74b865146b3f +47d1cdb0bcac8e417071ce1929d261efe2399ae2 diff --git a/src/shims/windows/foreign_items.rs b/src/shims/windows/foreign_items.rs index 9b8f32b0ab6..05014a3331d 100644 --- a/src/shims/windows/foreign_items.rs +++ b/src/shims/windows/foreign_items.rs @@ -288,19 +288,32 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let [algorithm, ptr, len, flags] = this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; let algorithm = this.read_scalar(algorithm)?; + let algorithm = algorithm.to_machine_usize(this)?; let ptr = this.read_pointer(ptr)?; let len = this.read_scalar(len)?.to_u32()?; let flags = this.read_scalar(flags)?.to_u32()?; - if flags != 2 { - // ^ BCRYPT_USE_SYSTEM_PREFERRED_RNG - throw_unsup_format!( - "BCryptGenRandom is supported only with the BCRYPT_USE_SYSTEM_PREFERRED_RNG flag" - ); - } - if algorithm.to_machine_usize(this)? != 0 { - throw_unsup_format!( - "BCryptGenRandom algorithm must be NULL when the flag is BCRYPT_USE_SYSTEM_PREFERRED_RNG" - ); + match flags { + 0 => { + // BCRYPT_RNG_ALG_HANDLE + if algorithm != 0x81 { + throw_unsup_format!( + "BCryptGenRandom algorithm must be BCRYPT_RNG_ALG_HANDLE when the flag is 0" + ); + } + } + 2 => { + // BCRYPT_USE_SYSTEM_PREFERRED_RNG + if algorithm != 0 { + throw_unsup_format!( + "BCryptGenRandom algorithm must be NULL when the flag is BCRYPT_USE_SYSTEM_PREFERRED_RNG" + ); + } + } + _ => { + throw_unsup_format!( + "BCryptGenRandom is only supported with BCRYPT_USE_SYSTEM_PREFERRED_RNG or BCRYPT_RNG_ALG_HANDLE" + ); + } } this.gen_random(ptr, len.into())?; this.write_null(dest)?; // STATUS_SUCCESS |
