Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: Crypt::Random::ISAAC - secure random number generator

by nothingmuch (Priest)
on Jul 11, 2005 at 17:03 UTC ( [id://474018]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Crypt::Random::ISAAC - secure random number generator
in thread Crypt::Random::ISAAC - secure random number generator

if (-e "/dev/random"){ .... } else { .... }

To generate a nice seed where you don't have /dev/random, you can do a checksum on your environment. Here are some sources of bits that are not random, but hard to reproduce:

  • concatenate keys and values of %ENV{}
  • process id, ppid
  • current time
  • process table
  • disk statistics
  • network interface report, especially if it can list counters
  • inode number of $0, and arguments if any
  • names of arguments, if any
  • strings coming out of the memory allocator (allocate some references, stringify them)
Once you have a big string you can pipe it through a compression or cipher algorithm, just to distribute bits across 8bit space evenly, and use unpack to count the sum (see examples in perldoc).

/dev/random collects entropy from drivers, timers, and so forth, so essentially you're doing a cheap emulation of that.

If you get something nice, make a module out of it: Entropy::Gather::Win32 or something.

-nuffin
zz zZ Z Z #!perl

Replies are listed 'Best First'.
Re^4: Crypt::Random::ISAAC - secure random number generator
by radiantmatrix (Parson) on Jul 11, 2005 at 18:38 UTC

    Some excellent ideas, which I am pursuing. Any idea on how to (reasonably quickly) determine if I got good seed values (i.e. are they random enough)? I don't have enough of a math background, I guess.

    Larry Wall is Yoda: there is no try{}
    The Code that can be seen is not the true Code
      ent measures entropy in byte streams

      -nuffin
      zz zZ Z Z #!perl

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://474018]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-25 17:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found