@@ -6,6 +6,7 @@ use core::ptr::null_mut;
66// Windows API definitions.
77type NTSTATUS = i32 ;
88type BOOLEAN = u8 ;
9+ type BOOL = i32 ; // yes, seriously, BOOL and BOOLEAN are very different...
910const BCRYPT_USE_SYSTEM_PREFERRED_RNG : u32 = 0x00000002 ;
1011const BCRYPT_RNG_ALG_HANDLE : * mut c_void = 0x81 as * mut c_void ;
1112#[ link( name = "bcrypt" ) ]
@@ -22,6 +23,16 @@ extern "system" {
2223 #[ link_name = "SystemFunction036" ]
2324 fn RtlGenRandom ( RandomBuffer : * mut u8 , RandomBufferLength : u32 ) -> BOOLEAN ;
2425}
26+ #[ cfg( target_arch = "x86" ) ]
27+ #[ link( name = "bcryptprimitives" , kind = "raw-dylib" , import_name_type = "undecorated" ) ]
28+ extern "system" {
29+ pub fn ProcessPrng ( pbdata : * mut u8 , cbdata : usize ) -> BOOL ;
30+ }
31+ #[ cfg( not( target_arch = "x86" ) ) ]
32+ #[ link( name = "bcryptprimitives" , kind = "raw-dylib" ) ]
33+ extern "system" {
34+ pub fn ProcessPrng ( pbdata : * mut u8 , cbdata : usize ) -> BOOL ;
35+ }
2536
2637fn main ( ) {
2738 let mut key = [ 0u8 ; 24 ] ;
@@ -38,4 +49,10 @@ fn main() {
3849 let ret = unsafe { RtlGenRandom ( key. as_mut_ptr ( ) , len) } ;
3950 // RtlGenRandom returns a BOOLEAN where 0 indicates an error
4051 assert_ne ! ( ret, 0 ) ;
52+
53+ let len = key. len ( ) ;
54+ let ret = unsafe { ProcessPrng ( key. as_mut_ptr ( ) , len) } ;
55+ // ProcessPrng is documented as always returning `TRUE`.
56+ // https://learn.microsoft.com/en-us/windows/win32/seccng/processprng#return-value
57+ assert_eq ! ( ret, 1 ) ;
4158}
0 commit comments