File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,8 @@ fn main() {
4646 println ! ( "cargo:rustc-link-lib=userenv" ) ;
4747 } else if target. contains ( "uwp" ) {
4848 println ! ( "cargo:rustc-link-lib=ws2_32" ) ;
49+ // For BCryptGenRandom
50+ println ! ( "cargo:rustc-link-lib=bcrypt" ) ;
4951 } else if target. contains ( "fuchsia" ) {
5052 println ! ( "cargo:rustc-link-lib=zircon" ) ;
5153 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;
321321
322322pub const HEAP_ZERO_MEMORY : DWORD = 0x00000008 ;
323323
324+ #[ cfg( target_os = "uwp" ) ]
325+ pub const BCRYPT_USE_SYSTEM_PREFERRED_RNG : DWORD = 0x00000002 ;
326+
324327#[ repr( C ) ]
325328#[ cfg( not( target_pointer_width = "64" ) ) ]
326329pub struct WSADATA {
@@ -1323,8 +1326,13 @@ extern "system" {
13231326 timeout : * const timeval ) -> c_int ;
13241327
13251328 #[ link_name = "SystemFunction036" ]
1329+ #[ cfg( not( target_os = "uwp" ) ) ]
13261330 pub fn RtlGenRandom ( RandomBuffer : * mut u8 , RandomBufferLength : ULONG ) -> BOOLEAN ;
13271331
1332+ #[ cfg( target_os = "uwp" ) ]
1333+ pub fn BCryptGenRandom ( hAlgorithm : LPVOID , pBuffer : * mut u8 ,
1334+ cbBuffer : ULONG , dwFlags : ULONG ) -> LONG ;
1335+
13281336 pub fn GetProcessHeap ( ) -> HANDLE ;
13291337 pub fn HeapAlloc ( hHeap : HANDLE , dwFlags : DWORD , dwBytes : SIZE_T ) -> LPVOID ;
13301338 pub fn HeapReAlloc ( hHeap : HANDLE , dwFlags : DWORD , lpMem : LPVOID , dwBytes : SIZE_T ) -> LPVOID ;
Original file line number Diff line number Diff line change 11use crate :: io;
22use crate :: mem;
3+ #[ cfg( target_os = "uwp" ) ]
4+ use crate :: ptr;
35use crate :: sys:: c;
46
7+ #[ cfg( not( target_os = "uwp" ) ) ]
58pub fn hashmap_random_keys ( ) -> ( u64 , u64 ) {
69 let mut v = ( 0 , 0 ) ;
710 let ret = unsafe {
@@ -14,3 +17,18 @@ pub fn hashmap_random_keys() -> (u64, u64) {
1417 }
1518 return v
1619}
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