Commit 86de045d authored by Rafaël Carré's avatar Rafaël Carré

Don't use CryptGenRandom in Windows Store app

parent c53d5900
......@@ -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])
......
......@@ -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 */
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment