]> git.sesse.net Git - vlc/commitdiff
Don't use CryptGenRandom in Windows Store app
authorRafaël Carré <funman@videolan.org>
Tue, 23 Jul 2013 11:13:13 +0000 (13:13 +0200)
committerRafaël Carré <funman@videolan.org>
Tue, 23 Jul 2013 11:17:56 +0000 (13:17 +0200)
configure.ac
src/win32/rand.c

index ab6fc7d31ef3918a54e0e5963c037c0f36040b9f..b69fc64a97f4814eadcd10987ac23d02ea42c87b 100644 (file)
@@ -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])
 
 
index 49c8d5e76e7500bf0c40c919a67a86c0715ae577..886ace88db89cc1e4504ba4c11f66fd314742622 100644 (file)
 #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 */
 }