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

Michael Niedermayer michaelni
Tue Jun 29 23:40:39 CEST 2010


On Tue, Jun 29, 2010 at 04:17:58PM +0300, Martin Storsj? wrote:
> 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
>  random_seed.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 44684635cb03b0d0b97a1652bbf0670ff11242dd  0001-Make-av_get_random_seed-not-block-when-waiting-for-m.patch
> From 5c57ef83b1ee46baf6153f2a930a327633eb4273 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. By preferring
> /dev/urandom over /dev/random, we avoid blocking, if both alternatives
> are available.

probably ok


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Why not whip the teacher when the pupil misbehaves? -- Diogenes of Sinope
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100629/e7e29edb/attachment.pgp>



More information about the ffmpeg-devel mailing list