diff options
| author | Ralf Jung <post@ralfj.de> | 2024-02-26 08:58:21 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-02-26 09:01:04 +0100 |
| commit | db0b49b945f56356ee495cd8b909545d566ef92e (patch) | |
| tree | 0cc9d713cfbed1a362010c110d1ba7f421ec2f07 | |
| parent | e9c7cc2087a5bfeffdc94a87cf86d2ce8f0d2902 (diff) | |
| download | rust-db0b49b945f56356ee495cd8b909545d566ef92e.tar.gz rust-db0b49b945f56356ee495cd8b909545d566ef92e.zip | |
add direct test for new ProcessPrng shim
| -rw-r--r-- | src/tools/miri/tests/pass/shims/windows-rand.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/tools/miri/tests/pass/shims/windows-rand.rs b/src/tools/miri/tests/pass/shims/windows-rand.rs index e2bcb7bd7cb..5754a82d890 100644 --- a/src/tools/miri/tests/pass/shims/windows-rand.rs +++ b/src/tools/miri/tests/pass/shims/windows-rand.rs @@ -6,6 +6,7 @@ use core::ptr::null_mut; // Windows API definitions. type NTSTATUS = i32; type BOOLEAN = u8; +type BOOL = i32; // yes, seriously, BOOL and BOOLEAN are very different... const BCRYPT_USE_SYSTEM_PREFERRED_RNG: u32 = 0x00000002; const BCRYPT_RNG_ALG_HANDLE: *mut c_void = 0x81 as *mut c_void; #[link(name = "bcrypt")] @@ -22,6 +23,16 @@ extern "system" { #[link_name = "SystemFunction036"] fn RtlGenRandom(RandomBuffer: *mut u8, RandomBufferLength: u32) -> BOOLEAN; } +#[cfg(target_arch = "x86")] +#[link(name = "bcryptprimitives", kind = "raw-dylib", import_name_type = "undecorated")] +extern "system" { + pub fn ProcessPrng(pbdata: *mut u8, cbdata: usize) -> BOOL; +} +#[cfg(not(target_arch = "x86"))] +#[link(name = "bcryptprimitives", kind = "raw-dylib")] +extern "system" { + pub fn ProcessPrng(pbdata: *mut u8, cbdata: usize) -> BOOL; +} fn main() { let mut key = [0u8; 24]; @@ -38,4 +49,10 @@ fn main() { let ret = unsafe { RtlGenRandom(key.as_mut_ptr(), len) }; // RtlGenRandom returns a BOOLEAN where 0 indicates an error assert_ne!(ret, 0); + + let len = key.len(); + let ret = unsafe { ProcessPrng(key.as_mut_ptr(), len) }; + // ProcessPrng is documented as always returning `TRUE`. + // https://learn.microsoft.com/en-us/windows/win32/seccng/processprng#return-value + assert_eq!(ret, 1); } |
