Using SHA1 as RNG

Christopher A. Craig list-python at ccraig.org
Mon Mar 17 09:11:34 EST 2003


Klaus Alexander Seistrup <spam at magnetic-ink.dk> writes:

> I was looking at python's whrandom and random modules the other day.
> Both seem to have a period of 27814431486575L (30268*30306*30322-1),
> which is, of course, quite a number, but not that long anyway.  So I
> thought, why not use SHA1 in the core generator?  Perhaps something
> along these lines:

whrandom isn't made for crypto applications.  It's intended to be used
for random number generation like shuffling a deck of cards in your
blackjack game (which probably unless you plan on running a high
stakes casino, is most likely not going to recieve the sort of
treatment that requires a cryptographically strong rng.  It works
quite well for this because 1) it's portable 2) it's fast 3) it has a
pretty big period.

If you have a specific application where you really want something to
be unguessable after you give some information away, you have to think
about what you need.  SHA will help you if you're worried about
somebody who has a certain number trying to guess a previous number,
but it obviously won't help if they're trying to guess a future number
and I don't know the minimum period of running SHA a bunch of times.

If you really want cryptographically secure random numbers you need a
hardware noise generator.

-- 
Christopher A. Craig <list-python at ccraig.org>
"The absolute value of the TA was less than epsilon" - MIT Course Evaluation





More information about the Python-list mailing list