[FFmpeg-devel] [PATCH] Make av_get_random_seed not block when waiting for more entropy
Måns Rullgård
mans
Tue Jun 29 15:08:08 CEST 2010
Martin Storsj? <martin at martin.st> writes:
> Hi,
>
> I recently ran into a situation where av_get_random_seed() blocks for long
> times if a machine is out of entropy. Since most (all?) uses of
> av_get_random_seed() within ffmpeg don't really need full cryptographic
> strength, using /dev/urandom instead of blocking while waiting for data
> from /dev/random - the attached patch does this.
>
> // Martin
>
> From d793a93fd6f8504e9a454c109ca992fb59b2c104 Mon Sep 17 00:00:00 2001
> From: Martin Storsjo <martin at martin.st>
> Date: Tue, 29 Jun 2010 15:21:35 +0300
> Subject: [PATCH] Make av_get_random_seed not block when waiting for more entropy
>
> The /dev/random device currently used for gathering entropy may block
> for (very) long times if the kernel is out of entropy.
> ---
> libavutil/random_seed.c | 1 -
> 1 files changed, 0 insertions(+), 1 deletions(-)
>
> diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c
> index 00d6317..7f82a4f 100644
> --- a/libavutil/random_seed.c
> +++ b/libavutil/random_seed.c
> @@ -29,7 +29,6 @@ uint32_t av_get_random_seed(void)
> uint32_t seed;
> int fd;
>
> - if ((fd = open("/dev/random", O_RDONLY)) == -1)
> fd = open("/dev/urandom", O_RDONLY);
> if (fd != -1){
> int err = read(fd, &seed, 4);
Neither /dev/random nor /dev/urandom are standard devices and may or
may not be available on a given system. Attempting both is probably a
good idea. Since we don't need cryptographically strong random
numbers, giving priority to /dev/urandom makes sense.
--
M?ns Rullg?rd
mans at mansr.com
More information about the ffmpeg-devel
mailing list