[vlc-devel] [PATCH] Simplify vlc_rand_bytes on Windows
visuve
veli-matti.visuri at iki.fi
Fri Apr 5 15:46:58 UTC 2024
- 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
---
src/win32/rand.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/src/win32/rand.c b/src/win32/rand.c
index 54cbe3c5..25a0c668 100644
--- a/src/win32/rand.c
+++ b/src/win32/rand.c
@@ -30,12 +30,5 @@
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);
- }
+ BCryptGenRandom(nullptr, buf, len, BCRYPT_USE_SYSTEM_PREFERRED_RNG);
}
--
2.43.0.windows.1
More information about the vlc-devel
mailing list