pike.git / lib / modules / Crypto / randomness.pmod

version» Context lines:

pike.git/lib/modules/Crypto/randomness.pmod:1: - /* $Id: randomness.pmod,v 1.12 1999/09/13 22:19:15 hubbe Exp $ + /* $Id: randomness.pmod,v 1.13 1999/11/25 23:10:52 grubba Exp $    */      //! module Crypto   //! submodule randomness   //! Assorted stronger or weaker randomnumber generators.      /* These devices tries to collect entropy from the environment.    * They differ in behaviour when they run low on entropy, /dev/random    * will block if it can't provide enough random bits, while /dev/urandom    * will degenerate into a reasonably strong pseudo random generator */
pike.git/lib/modules/Crypto/randomness.pmod:91: Inside #if 1 // 30% optimization /Hubbe
   }    ret+=(string)allocate(len % 16384, random)(256);    return ret;   #else    if (len > 16384) return read(len/2)+read(len-len/2);    return (string)allocate(len, random)(256);   #endif    }   }    + #if constant(Crypto.rc4)   //! class rc4_random   //! A pseudo random generator based on the rc4 crypto.   class rc4_random {    inherit Crypto.rc4 : rc4;       //! method void create(string secret)    //! Initialize and seed the rc4 random generator.    void create(string secret)    {    object hash = Crypto.sha();
pike.git/lib/modules/Crypto/randomness.pmod:116:    //! method string read(int len)    //! Return a string of the next len random characters from the    //! rc4 random generator.    string read(int len)    {    if (len > 16384) return read(len/2)+read(len-len/2);    return rc4::crypt("\47" * len);    }   }    + #endif /* constant(Crypto.rc4) */      object reasonably_random()   {    if (file_stat(PRANDOM_DEVICE))    {    object res = Stdio.File();    if (res->open(PRANDOM_DEVICE, "r"))    return res;    }       if (global_rc4)    return global_rc4;    -  + #if constant(Crypto.rc4)    string seed = some_entropy();    if (strlen(seed) > 2000)    return (global_rc4 = rc4_random(sprintf("%4c%O%s", time(), _memory_usage(), seed))); -  + #else /* !constant(Crypto.rc4) */ +  /* Not very random, but at least a fallback... */ +  return global_rc4 = pike_random(); + #endif /* constant(Crypto.rc4) */    throw( ({ "Crypto.randomness.reasonably_random: No source found\n", backtrace() }) );   }      object really_random(int|void may_block)   {    object res = Stdio.File();    if (may_block && file_stat(RANDOM_DEVICE))    {    if (res->open(RANDOM_DEVICE, "r"))    return res;