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

version» Context lines:

pike.git/lib/modules/Crypto/randomness.pmod:1: - /* $Id: randomness.pmod,v 1.11 1999/08/25 17:32:54 grubba Exp $ + /* $Id: randomness.pmod,v 1.12 1999/09/13 22:19:15 hubbe 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:75:   }         //! 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)    { + #if 1 // 30% optimization /Hubbe +  string ret=""; +  if(len>=16384) +  { +  array x=allocate(16384,random); +  for(int e=0;e<(len/16384);e++) ret+=(string)x(256); +  } +  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    }   }      //! 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.