[FFmpeg-devel] [PATCH v2 2/2] random_seed: Improve behaviour with small timer increments with high precision timers
Martin Storsjö
martin at martin.st
Thu Feb 6 14:38:48 EET 2025
On Thu, 6 Feb 2025, Michael Niedermayer wrote:
>> + // If the timer resolution is high, and we get the same timer
>> + // value multiple times, use variances in the number of repeats
>> + // of each timer value as entropy. If the number of repeats changed,
>> + // proceed to the next index.
>
> Does it still work if you check against the last 2 ?
> or does this become too slow ?
> What iam thinking of is this
>
> 7,8,7,8,8,7,8,7,8,8,7,8,7,8,8,7,8,7,8,8,... and a 9 or 6 or further distant would trigger it
>
> I assume both the CPU clock and the wall time are quite precisse so if we
> just compare them the entropy could be low even with 2 alternating values
Yes, that still works for making it terminate in a reasonable amount of
time. I updated the patch to keep track of 3 numbers of repeats, and we
consider that we got valid entropy once the new number of repeats is
different from the last two.
So in the sequence above, e.g. for 7,8,7,8,8,7, at the point of the last
one, we have old repeats 8 and 8, and the new repeat count 7, which in
that context looks unique.
It's obviously not entirely unique in the wider context there, but it
should cover for cases when we alternate between two numbers at least.
It's of course not hard to make it look at an even longer history,
although the conditional becomes a bit more unwieldy in that form.
// Martin
More information about the ffmpeg-devel
mailing list