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

version» Context lines:

pike.git/lib/modules/Crypto/randomness.pmod:1: - /* $Id: randomness.pmod,v 1.20 2001/11/08 01:45:39 nilsson Exp $ + /* $Id: randomness.pmod,v 1.21 2002/03/09 18:13:09 nilsson Exp $    */      //! Assorted stronger or weaker randomnumber generators.   //! These devices try 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 __REAL_VERSION__   
pike.git/lib/modules/Crypto/randomness.pmod:39:   private object global_arcfour;      // Executes several programs to generate some entropy from their output.   private string some_entropy()   {   #ifdef __NT__    object ctx = Crypto.nt.CryptAcquireContext(0, 0, Crypto.nt.PROV_RSA_FULL,    Crypto.nt.CRYPT_VERIFYCONTEXT    /*|Crypto.nt.CRYPT_SILENT*/);    if(!ctx) -  throw(({ "Crypto.random: couldn't create crypto context\n", backtrace()})); +  error( "Crypto.random: couldn't create crypto context.\n" );       string res = ctx->CryptGenRandom(8192);       if(!res) -  throw(({ "Crypto.random: couldn't generate randomness\n", backtrace()})); +  error( "Crypto.random: couldn't generate randomness.\n" );       destruct(ctx);       return res;   #else /* !__NT__ */    string res;    object parent_pipe, child_pipe;    mapping env=getenv()+([]);       parent_pipe = Stdio.File();    child_pipe = parent_pipe->pipe();    if (!child_pipe) -  throw( ({ "Crypto.random->popen: couldn't create pipe\n", backtrace() }) ); +  error( "Crypto.random->popen: couldn't create pipe.\n" );       object null=Stdio.File("/dev/null","rw");    env["PATH"]=PATH;       foreach(SYSTEM_COMMANDS, string cmd)    {    catch {    Process.create_process(Process.split_quoted_string(cmd),    (["stdin":null,    "stdout":child_pipe,
pike.git/lib/modules/Crypto/randomness.pmod:153:    return global_arcfour;      #if constant(Crypto.arcfour)    string seed = some_entropy();    if (strlen(seed) > 2000)    return (global_arcfour = arcfour_random(sprintf("%4c%O%s", time(), _memory_usage(), seed)));   #else /* !constant(Crypto.arcfour) */    /* Not very random, but at least a fallback... */    return global_arcfour = pike_random();   #endif /* constant(Crypto.arcfour) */ -  throw( ({ "Crypto.randomness.reasonably_random: No source found\n", backtrace() }) ); +  error( "Crypto.randomness.reasonably_random: No source found.\n" );   }      //!   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;    }       if (file_stat(PRANDOM_DEVICE))    {    if (res->open(PRANDOM_DEVICE, "r"))    return res;    }    -  throw( ({ "Crypto.randomness.really_random: No source found\n", backtrace() }) ); +  error( "Crypto.randomness.really_random: No source found.\n" );   }