@@ -6,6 +6,7 @@ use core::ptr::null_mut;
6
6
// Windows API definitions.
7
7
type NTSTATUS = i32 ;
8
8
type BOOLEAN = u8 ;
9
+ type BOOL = i32 ; // yes, seriously, BOOL and BOOLEAN are very different...
9
10
const BCRYPT_USE_SYSTEM_PREFERRED_RNG : u32 = 0x00000002 ;
10
11
const BCRYPT_RNG_ALG_HANDLE : * mut c_void = 0x81 as * mut c_void ;
11
12
#[ link( name = "bcrypt" ) ]
@@ -22,6 +23,16 @@ extern "system" {
22
23
#[ link_name = "SystemFunction036" ]
23
24
fn RtlGenRandom ( RandomBuffer : * mut u8 , RandomBufferLength : u32 ) -> BOOLEAN ;
24
25
}
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
+ }
25
36
26
37
fn main ( ) {
27
38
let mut key = [ 0u8 ; 24 ] ;
@@ -38,4 +49,10 @@ fn main() {
38
49
let ret = unsafe { RtlGenRandom ( key. as_mut_ptr ( ) , len) } ;
39
50
// RtlGenRandom returns a BOOLEAN where 0 indicates an error
40
51
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 ) ;
41
58
}
0 commit comments