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

version» Context lines:

pike.git/lib/modules/Crypto/randomness.pmod:1: - /* $Id: randomness.pmod,v 1.13 1999/11/25 23:10:52 grubba Exp $ + /* $Id: randomness.pmod,v 1.14 1999/12/01 22:37:22 marcus 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:34:   #endif      #define PRIVATE      PRIVATE object global_rc4;      // method string some_entropy()   // 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()})); +  +  string res = ctx->CryptGenRandom(8192); +  +  if(!res) +  throw(({ "Crypto.random: couldn't generate randomness\n", backtrace()})); +  +  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() }) );    -  - #ifndef __NT__ +     object null=Stdio.File("/dev/null","rw");    env["PATH"]=PATH; - #else -  object null=Stdio.File("nul:","rw"); - #endif +        foreach(SYSTEM_COMMANDS, string cmd)    {    catch {    Process.create_process(Process.split_quoted_string(cmd),    (["stdin":null,    "stdout":child_pipe,    "stderr":null,    "env":env]));    };    }       destruct(child_pipe);       return parent_pipe->read(); -  + #endif   }         //! class pike_random   //! A pseudo random generator based on the ordinary random() function.   class pike_random {    //! method string read(int len)    //! Returns a string of length len with pseudo random values.    string read(int len)    {