Skip to content
Snippets Groups Projects
Commit 12237bd0 authored by visuve's avatar visuve Committed by Jean-Baptiste Kempf
Browse files

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: default avatarSteve Lhomme <robux4@ycbcr.xyz>
parent 46c57f4d
No related branches found
No related tags found
1 merge request!5366Simplify vlc_rand_bytes on Windows
Pipeline #468018 passed with warnings with stages
in 35 minutes and 58 seconds
......@@ -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));
}
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