File tree 3 files changed +28
-0
lines changed
3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,8 @@ fn main() {
46
46
println ! ( "cargo:rustc-link-lib=userenv" ) ;
47
47
} else if target. contains ( "uwp" ) {
48
48
println ! ( "cargo:rustc-link-lib=ws2_32" ) ;
49
+ // For BCryptGenRandom
50
+ println ! ( "cargo:rustc-link-lib=bcrypt" ) ;
49
51
} else if target. contains ( "fuchsia" ) {
50
52
println ! ( "cargo:rustc-link-lib=zircon" ) ;
51
53
println ! ( "cargo:rustc-link-lib=fdio" ) ;
Original file line number Diff line number Diff line change @@ -321,6 +321,9 @@ pub const STACK_SIZE_PARAM_IS_A_RESERVATION: DWORD = 0x00010000;
321
321
322
322
pub const HEAP_ZERO_MEMORY : DWORD = 0x00000008 ;
323
323
324
+ #[ cfg( target_os = "uwp" ) ]
325
+ pub const BCRYPT_USE_SYSTEM_PREFERRED_RNG : DWORD = 0x00000002 ;
326
+
324
327
#[ repr( C ) ]
325
328
#[ cfg( not( target_pointer_width = "64" ) ) ]
326
329
pub struct WSADATA {
@@ -1323,8 +1326,13 @@ extern "system" {
1323
1326
timeout : * const timeval ) -> c_int ;
1324
1327
1325
1328
#[ link_name = "SystemFunction036" ]
1329
+ #[ cfg( not( target_os = "uwp" ) ) ]
1326
1330
pub fn RtlGenRandom ( RandomBuffer : * mut u8 , RandomBufferLength : ULONG ) -> BOOLEAN ;
1327
1331
1332
+ #[ cfg( target_os = "uwp" ) ]
1333
+ pub fn BCryptGenRandom ( hAlgorithm : LPVOID , pBuffer : * mut u8 ,
1334
+ cbBuffer : ULONG , dwFlags : ULONG ) -> LONG ;
1335
+
1328
1336
pub fn GetProcessHeap ( ) -> HANDLE ;
1329
1337
pub fn HeapAlloc ( hHeap : HANDLE , dwFlags : DWORD , dwBytes : SIZE_T ) -> LPVOID ;
1330
1338
pub fn HeapReAlloc ( hHeap : HANDLE , dwFlags : DWORD , lpMem : LPVOID , dwBytes : SIZE_T ) -> LPVOID ;
Original file line number Diff line number Diff line change 1
1
use crate :: io;
2
2
use crate :: mem;
3
+ #[ cfg( target_os = "uwp" ) ]
4
+ use crate :: ptr;
3
5
use crate :: sys:: c;
4
6
7
+ #[ cfg( not( target_os = "uwp" ) ) ]
5
8
pub fn hashmap_random_keys ( ) -> ( u64 , u64 ) {
6
9
let mut v = ( 0 , 0 ) ;
7
10
let ret = unsafe {
@@ -14,3 +17,18 @@ pub fn hashmap_random_keys() -> (u64, u64) {
14
17
}
15
18
return v
16
19
}
20
+
21
+ #[ cfg( target_os = "uwp" ) ]
22
+ pub fn hashmap_random_keys ( ) -> ( u64 , u64 ) {
23
+ let mut v = ( 0 , 0 ) ;
24
+ let ret = unsafe {
25
+ c:: BCryptGenRandom ( ptr:: null_mut ( ) , & mut v as * mut _ as * mut u8 ,
26
+ mem:: size_of_val ( & v) as c:: ULONG ,
27
+ c:: BCRYPT_USE_SYSTEM_PREFERRED_RNG )
28
+ } ;
29
+ if ret != 0 {
30
+ panic ! ( "couldn't generate random bytes: {}" ,
31
+ io:: Error :: last_os_error( ) ) ;
32
+ }
33
+ return v
34
+ }
You can’t perform that action at this time.
0 commit comments