[vlc-commits] Don't use CryptGenRandom in Windows Store app
Rafaël Carré
git at videolan.org
Tue Jul 23 13:18:02 CEST 2013
vlc | branch: master | Rafaël Carré <funman at videolan.org> | Tue Jul 23 13:13:13 2013 +0200| [86de045d68dcdba9b6cd95835aca3f546ad5cfe5] | committer: Rafaël Carré
Don't use CryptGenRandom in Windows Store app
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=86de045d68dcdba9b6cd95835aca3f546ad5cfe5
---
configure.ac | 5 ++++-
src/win32/rand.c | 41 +++++++++++++++++++++++++++++++++++++++--
2 files changed, 43 insertions(+), 3 deletions(-)
diff --git a/configure.ac b/configure.ac
index ab6fc7d..b69fc64 100644
--- a/configure.ac
+++ b/configure.ac
@@ -475,7 +475,10 @@ AC_ARG_ENABLE(winstore_app,
[Build targetted for Windows Store apps (default disabled)]))
vlc_winstore_app=0
-AS_IF([test "${SYS}" = "mingw32" -a "${enable_winstore_app}" = "yes"], [vlc_winstore_app=1])
+AS_IF([test "${SYS}" = "mingw32" -a "${enable_winstore_app}" = "yes"], [
+ vlc_winstore_app=1
+ VLC_ADD_LIBS([libvlccore], [-lole32 -lruntimeobject])
+ ])
AC_DEFINE_UNQUOTED(VLC_WINSTORE_APP, ${vlc_winstore_app}, [Define to 1 if you want to build for Windows Store apps])
diff --git a/src/win32/rand.c b/src/win32/rand.c
index 49c8d5e..886ace8 100644
--- a/src/win32/rand.c
+++ b/src/win32/rand.c
@@ -26,11 +26,18 @@
#include <vlc_common.h>
#include <vlc_rand.h>
-#include <wincrypt.h>
+#if VLC_WINSTORE_APP
+# define COBJMACROS
+# define INITGUID
+# include <winstring.h>
+# include <roapi.h>
+# include <windows.security.cryptography.h>
+#else
+# include <wincrypt.h>
+#endif
void vlc_rand_bytes (void *buf, size_t len)
{
- HCRYPTPROV hProv;
size_t count = len;
uint8_t *p_buf = (uint8_t *)buf;
@@ -50,6 +57,35 @@ void vlc_rand_bytes (void *buf, size_t len)
p_buf += sizeof (val);
}
+#if VLC_WINSTORE_APP
+ static const WCHAR *className = L"Windows.Security.Cryptography.CryptographicBuffer";
+ const UINT32 clen = wcslen(className);
+
+ HSTRING hClassName = NULL;
+ HSTRING_HEADER header;
+ HRESULT hr = WindowsCreateStringReference(className, clen, &header, &hClassName);
+ if (hr) {
+ WindowsDeleteString(hClassName);
+ return;
+ }
+
+ ICryptographicBufferStatics *cryptoStatics = NULL;
+ hr = RoGetActivationFactory(hClassName, &IID_ICryptographicBufferStatics, (void**)&cryptoStatics);
+ WindowsDeleteString(hClassName);
+
+ if (hr)
+ return;
+
+ IBuffer *buffer = NULL;
+ hr = ICryptographicBufferStatics_GenerateRandom(cryptoStatics, len, &buffer);
+ if (hr)
+ return;
+ UINT32 olength;
+ unsigned char *rnd = NULL;
+ hr = ICryptographicBufferStatics_CopyToByteArray(cryptoStatics, buffer, &olength, (BYTE**)&rnd);
+ memcpy(buf, rnd, len);
+#else
+ HCRYPTPROV hProv;
/* acquire default encryption context */
if( CryptAcquireContext(
&hProv, // Variable to hold returned handle.
@@ -63,4 +99,5 @@ void vlc_rand_bytes (void *buf, size_t len)
CryptGenRandom(hProv, len, buf);
CryptReleaseContext(hProv, 0);
}
+#endif /* VLC_WINSTORE_APP */
}
More information about the vlc-commits
mailing list