[PYTHON-CRYPTO] Yarrow 256 and PRNG API

Bryan Mongeau bryan at EEVOLVED.COM
Wed Feb 14 16:00:06 CET 2001


I've also coded up a CSPRNG for python that builds off of AMK's RandomPool
class in the python crypto toolkit.  I'm not entirely confident in this
assertion because I did it from memory, but I believe it is very close, if
not exactly a Yarrow 256 implementation.  Hopefully some of you can stick it
to me if I've flubbed somewhere. :) It uses SHA256 as the hash and AES at 256
bits as the cipher. It also leaves the entropy collection routines up to the
programmer, as to permit flexible future uses. Here is its API, as a basis
perhaps for discussion:

class Yarrow256:

  def __init__(self, numbytes = 256):
  """
        Numbytes is the size of the random pool buffer.

        The random pool is initially constructed with
        succesive time hashes. /dev/urandom existence
        is tested and used if available. Finally a call
        to stir() ensures at least somewhat entropic data.
        For real crypto applications, add entropic events
        directly by calling addBytes()
  """

  def useURandom(self):
   """
      If /dev/urandom is present on a given platform,
      we would be stupid not to use it. Grabs bytes and
      adds them to the pool.
   """

  def stir(self):
   """
        Critical function for ensuring the entropic
        quality of the random pool in a Yarrow-esque
        fashion. Proceeds as follows:

        o Adds the time to the random pool.

        o Taps /dev/urandom if available and adds
          it to the random pool.

        o Creates a stir "token". The token is a hash
          of the random pool and the two running counters.
          Adds the token to the random pool.

        o Encrypts the entire pool with AES using the token
          as the encryption key.

        Calling this function is relatively cheap on the
        cycles but remember that for real security, you
        must add other entropic events using addBytes().
   """
  def getBytes(self, N=32):
   """
     Return N bytes of random data, 32 being the default.
   """

  def addBytes(self, s):
   """
     XORs the contents of the string S into the random pool
   """

That's it. Entropy can be collected from any traditional Yarrow source, be it
the keyboard, mouse, or ps aux. Personally, I have implemented a thread
scheduling entropy collection mechanism to feed to addBytes() and built what
I consider to be a good CSPRNG.

When I wake up, I should have a nice tarball for you people itching for the
source... :)

Regards,
--
<==================================>
Bryan Mongeau
Lead Developer, Director
eEvolved Real-Time Technologies Inc.
http://www.eevolved.com
<==================================>

"The universe we observe has precisely the properties we should expect if
there is, at bottom, no design, no purpose, no evil and no good, nothing but
blind pitiless indifference." -- Richard Dawkins





More information about the python-crypto mailing list