[vlc-devel] [PATCH] Simplify vlc_rand_bytes on Windows

Steve Lhomme robux4 at ycbcr.xyz
Mon Apr 8 05:26:19 UTC 2024


Hello,

Can you open a merge request on https://code.videolan.org/videolan/vlc ?

Thanks

On 05/04/2024 17:46, visuve wrote:
> - 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
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list