[FFmpeg-devel] [PATCH 1/2] avutil/random_seed: use arc4random() when available

Ganesh Ajjanagadde gajjanagadde at gmail.com
Thu Dec 17 17:14:38 CET 2015


On Mon, Dec 14, 2015 at 8:05 AM, Ganesh Ajjanagadde
<gajjanagadde at gmail.com> wrote:
> On Thu, Dec 10, 2015 at 3:31 PM, Ganesh Ajjanagadde
> <gajjanagadde at gmail.com> wrote:
>> On Wed, Dec 9, 2015 at 8:08 AM, Ganesh Ajjanagadde
>> <gajjanagadde at gmail.com> wrote:
>>> On Sun, Dec 6, 2015 at 10:56 PM, Ganesh Ajjanagadde
>>> <gajjanagadde at gmail.com> wrote:
>>>> arc4random() was designed as a superior interface for system random
>>>> number generation, designed for OpenBSD. It is thus an improvement to
>>>> use it whenever available.
>>>>
>>>> As a side note, this may or may not get included in glibc, and there is
>>>> a proposal to create a posix_random family based on these ideas:
>>>> http://austingroupbugs.net/view.php?id=859.
>>>>
>>>> Untested as I lack OpenBSD.
>>>>
>>>> Signed-off-by: Ganesh Ajjanagadde <gajjanagadde at gmail.com>
>>>> ---
>>>>  configure               | 2 ++
>>>>  libavutil/random_seed.c | 4 ++++
>>>>  2 files changed, 6 insertions(+)
>>>>
>>>> diff --git a/configure b/configure
>>>> index 7530c88..e676269 100755
>>>> --- a/configure
>>>> +++ b/configure
>>>> @@ -1840,6 +1840,7 @@ MATH_FUNCS="
>>>>  SYSTEM_FUNCS="
>>>>      access
>>>>      aligned_malloc
>>>> +    arc4random
>>>>      clock_gettime
>>>>      closesocket
>>>>      CommandLineToArgvW
>>>> @@ -5218,6 +5219,7 @@ check_func  ${malloc_prefix}memalign            && enable memalign
>>>>  check_func  ${malloc_prefix}posix_memalign      && enable posix_memalign
>>>>
>>>>  check_func  access
>>>> +check_func  arc4random
>>>>  check_func_headers time.h clock_gettime || { check_func_headers time.h clock_gettime -lrt && add_extralibs -lrt && LIBRT="-lrt"; }
>>>>  check_func  fcntl
>>>>  check_func  fork
>>>> diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c
>>>> index 8aa8c38..205a636 100644
>>>> --- a/libavutil/random_seed.c
>>>> +++ b/libavutil/random_seed.c
>>>> @@ -121,6 +121,10 @@ uint32_t av_get_random_seed(void)
>>>>      }
>>>>  #endif
>>>>
>>>> +#if HAVE_ARC4RANDOM
>>>> +    return arc4random();
>>>> +#endif
>>>> +
>>>>      if (read_random(&seed, "/dev/urandom") == sizeof(seed))
>>>>          return seed;
>>>>      if (read_random(&seed, "/dev/random")  == sizeof(seed))
>>>> --
>>>> 2.6.3
>>>>
>>>
>>> any objections to this: all objections so far have been for 2/2, i.e
>>> for the more controversial one that harnesses libbsd for non-native
>>> functionality?
>>
>> To clarify, none of wm4's comments apply here. It will provide
>> benefits not just to OpenBSD, but also to other BSD's, Mac OS X, and
>> some alternative libc's (not glibc, which refused and continues to
>> refuse arc4random).
>>
>> @Ronald, or anyone else with a Mac: can you please try at least a build test?
>>
>> I have now shelved 2/2, as it has got drawn into a stalemate.
>
> Going in tomorrow provided it works as intended when I test it on a
> Mac and in the absence of comments.

got a little delayed; but finally tested on a Mac and it works as
intended. Pushed.


More information about the ffmpeg-devel mailing list