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

Michael Niedermayer michaelni
Thu Jul 1 23:17:56 CEST 2010


On Thu, Jul 01, 2010 at 10:54:22PM +0200, Michael Niedermayer wrote:
> 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

heres a better one

int last_t=0;
int bits=0;
uint64_t random=0;
int i;
int s=0;
for(i=0;bits<64;i++){
    int t= clock()>>s;
    if(last_t && t != last_t){
        if(i<10000){
             s++;
             i=last_t=0;
        }else{
            random= 2*random + (i&1);
            bits++;
        }
    }
    last_t= t;
}
random ^= clock();
random += random>>32;


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

Dictatorship naturally arises out of democracy, and the most aggravated
form of tyranny and slavery out of the most extreme liberty. -- Plato
-------------- 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/3791ee42/attachment.pgp>



More information about the ffmpeg-devel mailing list