Replace Windows APIs that are banned in Windows Store apps
CryptGenRandom and lstrlenW are not permitted in Windows Store apps,
meaning apps that use mbedTLS can't ship in the Windows Store.
Instead, use BCryptGenRandom and wcslen, respectively, which are
permitted.
Also make sure conversions between size_t, ULONG, and int are
always done safely; on a 64-bit platform, these types are different
sizes.
Also suppress macro redefinition warning for intsafe.h:
Visual Studio 2010 and earlier generates C4005 when including both
<intsafe.h> and <stdint.h> because a number of <TYPE>_MAX constants
are redefined. This is fixed in later versions of Visual Studio.
The constants are guaranteed to be the same between both files,
however, so we can safely suppress the warning when including
intsafe.h.
Signed-off-by: Kevin Kane <kkane@microsoft.com>
diff --git a/programs/pkey/CMakeLists.txt b/programs/pkey/CMakeLists.txt
index 3ad5643..81f4311 100644
--- a/programs/pkey/CMakeLists.txt
+++ b/programs/pkey/CMakeLists.txt
@@ -1,3 +1,7 @@
+if(MSVC)
+ set(libs ${libs} bcrypt)
+endif()
+
set(executables_mbedtls
dh_client
dh_server
diff --git a/programs/random/CMakeLists.txt b/programs/random/CMakeLists.txt
index e5edf7b..e78ce06 100644
--- a/programs/random/CMakeLists.txt
+++ b/programs/random/CMakeLists.txt
@@ -1,3 +1,7 @@
+if(MSVC)
+ set(libs ${libs} bcrypt)
+endif()
+
set(executables
gen_entropy
gen_random_ctr_drbg
diff --git a/programs/ssl/CMakeLists.txt b/programs/ssl/CMakeLists.txt
index 280bbcf..9871952 100644
--- a/programs/ssl/CMakeLists.txt
+++ b/programs/ssl/CMakeLists.txt
@@ -5,6 +5,10 @@
${mbedtls_target}
)
+if(MSVC)
+ set(libs ${libs} bcrypt)
+endif()
+
set(executables
dtls_client
dtls_server
diff --git a/programs/test/CMakeLists.txt b/programs/test/CMakeLists.txt
index a75f8d9..1853d7f 100644
--- a/programs/test/CMakeLists.txt
+++ b/programs/test/CMakeLists.txt
@@ -2,6 +2,10 @@
${mbedtls_target}
)
+if(MSVC)
+ set(libs ${libs} bcrypt)
+endif()
+
set(executables_libs
query_included_headers
selftest
diff --git a/programs/x509/CMakeLists.txt b/programs/x509/CMakeLists.txt
index 5876b8d..30d272d 100644
--- a/programs/x509/CMakeLists.txt
+++ b/programs/x509/CMakeLists.txt
@@ -1,6 +1,9 @@
set(libs
${mbedx509_target}
)
+if(MSVC)
+ set(libs ${libs} bcrypt)
+endif()
set(executables
cert_app