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

Michael Niedermayer michaelni
Thu Jul 1 22:54:22 CEST 2010


On Thu, Jul 01, 2010 at 12:44:29PM +0100, M?ns Rullg?rd wrote:
> Michael Niedermayer <michaelni at gmx.at> writes:
> 
> > On Thu, Jul 01, 2010 at 01:02:08AM +0100, M?ns Rullg?rd wrote:
> >> Michael Niedermayer <michaelni at gmx.at> writes:
> >> 
> >> >> There are systems, many in fact, without /dev/[u]random or
> >> >> AV_READ_TIME.
> >> >
> >> > yes but the question was about blocking /dev/random and non existing
> >> > /dev/urandom at the same time.  (or a unrealistic blocking
> >> > /dev/urandom)
> >> >
> >> > open(/dev/urandom)
> >> > if(fail)
> >> >     open(/dev/random)
> >> > read()
> >> >
> >> > is sufficient if such system does not exist
> >> 
> >> Fine, let's dig.
> >
> > thanks
> >
> > from what i understand the code suggested above should work or am i missing
> > something. Some of the documentation quoted is somewhat vague
> 
> OK, I've made the reads blocking again.
> 
> Now then, what do we do if no random device or AV_READ_TIME exists?

int last_t= -1;
int bits=0;
int random=0;
int i;
for(i=0;bits<32;i++){
    int t= clock();
    if(last_t!=-1 && t != last_t){
        random= 2*random + ((i^t)&1);
        bits++;
    }
    last_t= t;
}

you also could read 64 bit and take it modulo a prime close to 32bit

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

I wish the Xiph folks would stop pretending they've got something they
do not.  Somehow I fear this will remain a wish. -- M?ns Rullg?rd
-------------- 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/20100701/8ae7ac70/attachment.pgp>



More information about the ffmpeg-devel mailing list