[vlc-commits] [Git][videolan/vlc][master] Simplify vlc_rand_bytes on Windows
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Wed May 8 16:57:32 UTC 2024
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
12237bd0 by visuve at 2024-05-08T16:39:15+00:00
Simplify vlc_rand_bytes on Windows
Use system preferred RNG and skip the unnecessary initialization steps (in this
context, which is definitely not security related)
The vlc_rand_bytes function is now about 55x faster when called repeatedly in a loop
See https://learn.microsoft.com/en-us/windows/win32/api/bcrypt/nf-bcrypt-bcryptgenrandom for more details
Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>
- - - - -
1 changed file:
- src/win32/rand.c
Changes:
=====================================
src/win32/rand.c
=====================================
@@ -27,15 +27,11 @@
#include <windows.h>
#include <bcrypt.h>
+#include <assert.h>
void vlc_rand_bytes (void *buf, size_t len)
{
- BCRYPT_ALG_HANDLE algo_handle;
- NTSTATUS ret = BCryptOpenAlgorithmProvider(&algo_handle, BCRYPT_RNG_ALGORITHM,
- MS_PRIMITIVE_PROVIDER, 0);
- if (BCRYPT_SUCCESS(ret))
- {
- BCryptGenRandom(algo_handle, buf, len, 0);
- BCryptCloseAlgorithmProvider(algo_handle, 0);
- }
+ NTSTATUS ret;
+ ret = BCryptGenRandom(0, buf, len, BCRYPT_USE_SYSTEM_PREFERRED_RNG);
+ assert(BCRYPT_SUCCESS(ret));
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/12237bd0f96c9833b7fffc78b1723d9b1f5739a7
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/12237bd0f96c9833b7fffc78b1723d9b1f5739a7
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list