Skip to content
Snippets Groups Projects
Commit e0c0da60 authored by Steve Lhomme's avatar Steve Lhomme
Browse files

win32: use bcrypt for random generators

The API is available since Vista and is also available in winstore app. We
don't have to support 2 different versions anymore in 4.0.
parent 568aba0b
No related branches found
No related tags found
1 merge request!773win32: use bcrypt for random generators
Pipeline #148308 passed with stage
in 20 minutes and 48 seconds
......@@ -1298,12 +1298,6 @@ AS_IF([test "${enable_ssp}" != "no" -a "${enable_optimizations}" != "no"], [
])
])
AS_IF([test "${SYS}" = "mingw32"], [
dnl library for BCrypt APIs
AS_IF([test "${vlc_winstore_app}" = 1],
VLC_ADD_LIBS([libvlccore], [-lbcrypt]))
])
VLC_SAVE_FLAGS
LDFLAGS="${LDFLAGS} -Wl,-Bsymbolic"
AC_CACHE_CHECK([if linker supports -Bsymbolic], [ac_cv_ld_bsymbolic], [
......
......@@ -418,6 +418,7 @@ libvlccore_la_SOURCES += posix/timer.c win32/dirs-uap.c
else
libvlccore_la_SOURCES += win32/timer.c win32/dirs.c
endif
libvlccore_la_LIBADD += -lbcrypt
endif
if HAVE_OS2
......
......@@ -25,15 +25,10 @@
#include <vlc_common.h>
#include <vlc_rand.h>
#ifdef VLC_WINSTORE_APP
# include <bcrypt.h>
#else
# include <wincrypt.h>
#endif
#include <bcrypt.h>
void vlc_rand_bytes (void *buf, size_t len)
{
#ifdef VLC_WINSTORE_APP
BCRYPT_ALG_HANDLE algo_handle;
NTSTATUS ret = BCryptOpenAlgorithmProvider(&algo_handle, BCRYPT_RNG_ALGORITHM,
MS_PRIMITIVE_PROVIDER, 0);
......@@ -42,39 +37,4 @@ void vlc_rand_bytes (void *buf, size_t len)
BCryptGenRandom(algo_handle, buf, len, 0);
BCryptCloseAlgorithmProvider(algo_handle, 0);
}
#else
size_t count = len;
uint8_t *p_buf = (uint8_t *)buf;
/* fill buffer with pseudo-random data */
while (count > 0)
{
unsigned int val;
val = rand();
if (count < sizeof (val))
{
memcpy (p_buf, &val, count);
break;
}
memcpy (p_buf, &val, sizeof (val));
count -= sizeof (val);
p_buf += sizeof (val);
}
HCRYPTPROV hProv;
/* acquire default encryption context */
if( CryptAcquireContext(
&hProv, // Variable to hold returned handle.
NULL, // Use default key container.
MS_DEF_PROV, // Use default CSP.
PROV_RSA_FULL, // Type of provider to acquire.
CRYPT_VERIFYCONTEXT) ) // Flag values
{
/* fill buffer with pseudo-random data, initial buffer content
is used as auxiliary random seed */
CryptGenRandom(hProv, len, buf);
CryptReleaseContext(hProv, 0);
}
#endif /* VLC_WINSTORE_APP */
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment