diff mbox

[FFmpeg-devel] use bcrypt instead of the old wincrypt API

Message ID 20180330072352.18020-1-robux4@ycbcr.xyz
State Superseded
Headers show

Commit Message

Steve Lhomme March 30, 2018, 7:23 a.m. UTC
When targeting Windows Vista and above
The wincrypt API is deprecated and not allowed for Windows Store apps.
---
 configure               |  4 +++-
 libavutil/random_seed.c | 16 ++++++++++++++--
 2 files changed, 17 insertions(+), 3 deletions(-)

Comments

Hendrik Leppkes March 30, 2018, 10:42 a.m. UTC | #1
On Fri, Mar 30, 2018 at 9:23 AM, Steve Lhomme <robux4@ycbcr.xyz> wrote:
> When targeting Windows Vista and above
> The wincrypt API is deprecated and not allowed for Windows Store apps.
> ---
>  configure               |  4 +++-
>  libavutil/random_seed.c | 16 ++++++++++++++--
>  2 files changed, 17 insertions(+), 3 deletions(-)
>
> diff --git a/configure b/configure
> index 99570a1415..6d34728b83 100755
> --- a/configure
> +++ b/configure
> @@ -2144,6 +2144,7 @@ SYSTEM_LIBRARIES="
>      vaapi_drm
>      vaapi_x11
>      vdpau_x11
> +    bcrypt
>      wincrypt
>  "
>
> @@ -3442,7 +3443,7 @@ avformat_deps="avcodec avutil"
>  avformat_suggest="libm network zlib"
>  avresample_deps="avutil"
>  avresample_suggest="libm"
> -avutil_suggest="clock_gettime ffnvcodec libm libdrm libmfx opencl user32 vaapi videotoolbox corefoundation corevideo coremedia wincrypt"
> +avutil_suggest="clock_gettime ffnvcodec libm libdrm libmfx opencl user32 vaapi videotoolbox corefoundation corevideo coremedia bcrypt wincrypt"
>  postproc_deps="avutil gpl"
>  postproc_suggest="libm"
>  swresample_deps="avutil"
> @@ -5827,6 +5828,7 @@ check_lib ole32    "windows.h"            CoTaskMemFree        -lole32
>  check_lib shell32  "windows.h shellapi.h" CommandLineToArgvW   -lshell32
>  check_lib wincrypt "windows.h wincrypt.h" CryptGenRandom       -ladvapi32
>  check_lib psapi    "windows.h psapi.h"    GetProcessMemoryInfo -lpsapi
> +check_cpp_condition windows.h "_WIN32_WINNT >= 0x0600" && check_lib bcrypt "windows.h bcrypt.h" BCryptGenRandom  -lbcrypt
>

FFmpeg does not support building for XP anymore, so you can skip that condition.

- Hendrik
diff mbox

Patch

diff --git a/configure b/configure
index 99570a1415..6d34728b83 100755
--- a/configure
+++ b/configure
@@ -2144,6 +2144,7 @@  SYSTEM_LIBRARIES="
     vaapi_drm
     vaapi_x11
     vdpau_x11
+    bcrypt
     wincrypt
 "
 
@@ -3442,7 +3443,7 @@  avformat_deps="avcodec avutil"
 avformat_suggest="libm network zlib"
 avresample_deps="avutil"
 avresample_suggest="libm"
-avutil_suggest="clock_gettime ffnvcodec libm libdrm libmfx opencl user32 vaapi videotoolbox corefoundation corevideo coremedia wincrypt"
+avutil_suggest="clock_gettime ffnvcodec libm libdrm libmfx opencl user32 vaapi videotoolbox corefoundation corevideo coremedia bcrypt wincrypt"
 postproc_deps="avutil gpl"
 postproc_suggest="libm"
 swresample_deps="avutil"
@@ -5827,6 +5828,7 @@  check_lib ole32    "windows.h"            CoTaskMemFree        -lole32
 check_lib shell32  "windows.h shellapi.h" CommandLineToArgvW   -lshell32
 check_lib wincrypt "windows.h wincrypt.h" CryptGenRandom       -ladvapi32
 check_lib psapi    "windows.h psapi.h"    GetProcessMemoryInfo -lpsapi
+check_cpp_condition windows.h "_WIN32_WINNT >= 0x0600" && check_lib bcrypt "windows.h bcrypt.h" BCryptGenRandom  -lbcrypt
 
 check_lib android android/native_window.h ANativeWindow_acquire -landroid
 check_lib mediandk "stdint.h media/NdkImage.h" AImage_delete -lmediandk
diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c
index 881c23c8c8..d7186146d9 100644
--- a/libavutil/random_seed.c
+++ b/libavutil/random_seed.c
@@ -26,7 +26,9 @@ 
 #if HAVE_IO_H
 #include <io.h>
 #endif
-#if HAVE_WINCRYPT
+#if HAVE_BCRYPT
+#include <bcrypt.h>
+#elif HAVE_WINCRYPT
 #include <windows.h>
 #include <wincrypt.h>
 #endif
@@ -121,7 +123,17 @@  uint32_t av_get_random_seed(void)
 {
     uint32_t seed;
 
-#if HAVE_WINCRYPT
+#if HAVE_BCRYPT
+    BCRYPT_ALG_HANDLE algo_handle;
+    NTSTATUS ret = BCryptOpenAlgorithmProvider(&algo_handle, BCRYPT_RNG_ALGORITHM,
+                                               MS_PRIMITIVE_PROVIDER, 0);
+    if (BCRYPT_SUCCESS(ret)) {
+        NTSTATUS ret = BCryptGenRandom(algo_handle, &seed, sizeof(seed), 0);
+        BCryptCloseAlgorithmProvider(algo_handle, 0);
+        if (BCRYPT_SUCCESS(ret))
+            return seed;
+    }
+#elif HAVE_WINCRYPT
     HCRYPTPROV provider;
     if (CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL,
                             CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {