[vlc-commits] [Git][videolan/vlc][master] win32: use bcrypt for random generators
Steve Lhomme (@robUx4)
gitlab at videolan.org
Fri Oct 15 07:27:25 UTC 2021
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
e0c0da60 by Steve Lhomme at 2021-10-15T06:32:44+00:00
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.
- - - - -
3 changed files:
- configure.ac
- src/Makefile.am
- src/win32/rand.c
Changes:
=====================================
configure.ac
=====================================
@@ -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], [
=====================================
src/Makefile.am
=====================================
@@ -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
=====================================
src/win32/rand.c
=====================================
@@ -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 */
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/e0c0da604dc01862db0761e9318d26fd88ce49a3
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/e0c0da604dc01862db0761e9318d26fd88ce49a3
You're receiving this email because of your account on code.videolan.org.
More information about the vlc-commits
mailing list