[FFmpeg-devel] [PATCH] libavutil/random_seed: Ensure that get_generic_seed() spends at least 1/32 sec gathering entropy

James Almer jamrial at gmail.com
Thu Dec 29 04:37:44 EET 2016


On 12/28/2016 8:34 PM, Michael Niedermayer wrote:
> This may fix the failures on windows

Not sure what failures this is about, but compiling with mingw-w64 x86_64 (GCC
6.2.0) and running on a Haswell i5 on Win10 x86_64 i got this before this patch

$ time libavutil/tests/random_seed.exe
seeds OK
seeds OK

real    0m2.082s
user    0m0.000s
sys     0m0.000s

And this after

$ time libavutil/tests/random_seed.exe
seeds OK
seeds OK

real    0m8.100s
user    0m0.000s
sys     0m0.015s

> 
> Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> ---
>  libavutil/random_seed.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c
> index 0c58c8ffa1..d1c9a3f704 100644
> --- a/libavutil/random_seed.c
> +++ b/libavutil/random_seed.c
> @@ -68,6 +68,7 @@ static uint32_t get_generic_seed(void)
>      struct AVSHA *sha = (void*)tmp;
>      clock_t last_t  = 0;
>      clock_t last_td = 0;
> +    clock_t init_t = 0;
>      static uint64_t i = 0;
>      static uint32_t buffer[512] = { 0 };
>      unsigned char digest[20];
> @@ -93,10 +94,13 @@ static uint32_t get_generic_seed(void)
>          } else {
>              last_td = t - last_t;
>              buffer[++i & 511] += last_td % 3294638521U;
> -            if (last_i && i - last_i > 4 || i - last_i > 64 || TEST && i - last_i > 8)
> -                break;
> +            if ((t - init_t) >= CLOCKS_PER_SEC>>5)
> +                if (last_i && i - last_i > 4 || i - last_i > 64 || TEST && i - last_i > 8)
> +                    break;
>          }
>          last_t = t;
> +        if (!init_t)
> +            init_t = t;
>      }
>  
>      if(TEST) {
> 



More information about the ffmpeg-devel mailing list