avutil/random_seed: use bcrypt instead of the old wincrypt API

Remove the wincrypt API calls since we don't support XP anymore and bcrypt is
available since Vista, even on Windows Store builds.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
pull/285/head
Steve Lhomme 7 years ago committed by James Almer
parent a56580b117
commit aedbf1640c
  1. 6
      configure
  2. 19
      libavutil/random_seed.c

6
configure vendored

@ -2142,10 +2142,10 @@ SYSTEM_FUNCS="
" "
SYSTEM_LIBRARIES=" SYSTEM_LIBRARIES="
bcrypt
vaapi_drm vaapi_drm
vaapi_x11 vaapi_x11
vdpau_x11 vdpau_x11
wincrypt
" "
TOOLCHAIN_FEATURES=" TOOLCHAIN_FEATURES="
@ -3445,7 +3445,7 @@ avformat_deps="avcodec avutil"
avformat_suggest="libm network zlib" avformat_suggest="libm network zlib"
avresample_deps="avutil" avresample_deps="avutil"
avresample_suggest="libm" 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"
postproc_deps="avutil gpl" postproc_deps="avutil gpl"
postproc_suggest="libm" postproc_suggest="libm"
swresample_deps="avutil" swresample_deps="avutil"
@ -5828,9 +5828,9 @@ check_header asm/types.h
check_builtin stdatomic stdatomic.h "atomic_int foo, bar = ATOMIC_VAR_INIT(-1); atomic_store(&foo, 0); foo += bar" check_builtin stdatomic stdatomic.h "atomic_int foo, bar = ATOMIC_VAR_INIT(-1); atomic_store(&foo, 0); foo += bar"
check_lib advapi32 "windows.h" RegCloseKey -ladvapi32 check_lib advapi32 "windows.h" RegCloseKey -ladvapi32
check_lib bcrypt "windows.h bcrypt.h" BCryptGenRandom -lbcrypt
check_lib ole32 "windows.h" CoTaskMemFree -lole32 check_lib ole32 "windows.h" CoTaskMemFree -lole32
check_lib shell32 "windows.h shellapi.h" CommandLineToArgvW -lshell32 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_lib psapi "windows.h psapi.h" GetProcessMemoryInfo -lpsapi
check_lib android android/native_window.h ANativeWindow_acquire -landroid check_lib android android/native_window.h ANativeWindow_acquire -landroid

@ -26,9 +26,9 @@
#if HAVE_IO_H #if HAVE_IO_H
#include <io.h> #include <io.h>
#endif #endif
#if HAVE_WINCRYPT #if HAVE_BCRYPT
#include <windows.h> #include <windows.h>
#include <wincrypt.h> #include <bcrypt.h>
#endif #endif
#include <fcntl.h> #include <fcntl.h>
#include <math.h> #include <math.h>
@ -121,13 +121,14 @@ uint32_t av_get_random_seed(void)
{ {
uint32_t seed; uint32_t seed;
#if HAVE_WINCRYPT #if HAVE_BCRYPT
HCRYPTPROV provider; BCRYPT_ALG_HANDLE algo_handle;
if (CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, NTSTATUS ret = BCryptOpenAlgorithmProvider(&algo_handle, BCRYPT_RNG_ALGORITHM,
CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) { MS_PRIMITIVE_PROVIDER, 0);
BOOL ret = CryptGenRandom(provider, sizeof(seed), (PBYTE) &seed); if (BCRYPT_SUCCESS(ret)) {
CryptReleaseContext(provider, 0); NTSTATUS ret = BCryptGenRandom(algo_handle, (UCHAR*)&seed, sizeof(seed), 0);
if (ret) BCryptCloseAlgorithmProvider(algo_handle, 0);
if (BCRYPT_SUCCESS(ret))
return seed; return seed;
} }
#endif #endif

Loading…
Cancel
Save