File tree Expand file tree Collapse file tree 3 files changed +43
-2
lines changed Expand file tree Collapse file tree 3 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,8 @@ fn main() {
41
41
println ! ( "cargo:rustc-link-lib=resolv" ) ;
42
42
} else if target. contains ( "uwp" ) {
43
43
println ! ( "cargo:rustc-link-lib=ws2_32" ) ;
44
+ // For BCryptGenRandom
45
+ println ! ( "cargo:rustc-link-lib=bcrypt" ) ;
44
46
} else if target. contains ( "windows" ) {
45
47
println ! ( "cargo:rustc-link-lib=advapi32" ) ;
46
48
println ! ( "cargo:rustc-link-lib=ws2_32" ) ;
Original file line number Diff line number Diff line change @@ -655,6 +655,29 @@ pub struct timeval {
655
655
pub tv_usec : c_long ,
656
656
}
657
657
658
+ // Functions forbidden when targeting UWP
659
+ cfg_if:: cfg_if! {
660
+ if #[ cfg( not( target_vendor = "uwp" ) ) ] {
661
+ extern "system" {
662
+ #[ link_name = "SystemFunction036" ]
663
+ pub fn RtlGenRandom ( RandomBuffer : * mut u8 , RandomBufferLength : ULONG ) -> BOOLEAN ;
664
+ }
665
+ }
666
+ }
667
+
668
+ // UWP specific functions & types
669
+ cfg_if:: cfg_if! {
670
+ if #[ cfg( target_vendor = "uwp" ) ] {
671
+ pub const BCRYPT_USE_SYSTEM_PREFERRED_RNG : DWORD = 0x00000002 ;
672
+
673
+ extern "system" {
674
+ pub fn BCryptGenRandom ( hAlgorithm: LPVOID , pBuffer: * mut u8 ,
675
+ cbBuffer: ULONG , dwFlags: ULONG ) -> LONG ;
676
+ }
677
+ }
678
+ }
679
+
680
+ // Shared between Desktop & UWP
658
681
extern "system" {
659
682
pub fn WSAStartup ( wVersionRequested : WORD ,
660
683
lpWSAData : LPWSADATA ) -> c_int ;
@@ -950,8 +973,6 @@ extern "system" {
950
973
exceptfds : * mut fd_set ,
951
974
timeout : * const timeval ) -> c_int ;
952
975
953
- #[ link_name = "SystemFunction036" ]
954
- pub fn RtlGenRandom ( RandomBuffer : * mut u8 , RandomBufferLength : ULONG ) -> BOOLEAN ;
955
976
956
977
pub fn GetProcessHeap ( ) -> HANDLE ;
957
978
pub fn HeapAlloc ( hHeap : HANDLE , dwFlags : DWORD , dwBytes : SIZE_T ) -> LPVOID ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ use crate::io;
2
2
use crate :: mem;
3
3
use crate :: sys:: c;
4
4
5
+ #[ cfg( not( target_vendor = "uwp" ) ) ]
5
6
pub fn hashmap_random_keys ( ) -> ( u64 , u64 ) {
6
7
let mut v = ( 0 , 0 ) ;
7
8
let ret = unsafe {
@@ -14,3 +15,20 @@ pub fn hashmap_random_keys() -> (u64, u64) {
14
15
}
15
16
return v
16
17
}
18
+
19
+ #[ cfg( target_vendor = "uwp" ) ]
20
+ pub fn hashmap_random_keys ( ) -> ( u64 , u64 ) {
21
+ use crate :: ptr;
22
+
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