[FFmpeg-devel] [PATCH] Make av_get_random_seed not block when waiting for more entropy

Martin Storsjö martin
Tue Jun 29 15:17:58 CEST 2010


On Tue, 29 Jun 2010, M?ns Rullg?rd wrote:

> 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.

Good point, updated patch attached.

// Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Make-av_get_random_seed-not-block-when-waiting-for-m.patch
Type: text/x-diff
Size: 1107 bytes
Desc: 
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100629/063ca148/attachment.patch>



More information about the ffmpeg-devel mailing list