Weekly edition Kernel Security Distributions Contact Us Search Archives Calendar Subscribe Write for LWN LWN.net FAQ Sponsors

# offtopic

## offtopic

Posted Dec 18, 2007 4:10 UTC (Tue) by ikm (subscriber, #493)
In reply to: offtopic by dlang
Parent article: On entropy and randomness

Well, I personally have no idea how hashes work. As long as they comply with the usual requirements (i.e. resistance to reversion and collision-finding), I'm quite happy. What I am concerned about is their use as RNGs, as I can't google out any papers on how mathematically correct it is to feed a hash output to its input to build an RNG. What would be the period? Does it depend on the seed supplied? The aforementioned requirements for hashes don't allow any conclusions to be drawn on these questions. Hashes are simply designed for a different purpose. While using a hash to compress the resulting entropy from another source is probably ok (as I doubt it would make it less random than it was), looping it to itself seems questionable to me. E.g., consider an example RNG, for instance, a very simple Marsaglia's SHR3. It has a period of exactly 2^32-1, which means that it iterates through all numbers within [1..2^32-1] in some random order. You can use any value to seed it other than 0, and it would still have an exact same period (and a value of zero would make it always produce zeroes). Usually RNGs have these properties well understood. Did anyone make a research on SHA1 in that regard? I don't know and I would want to know. Not that all this stuff matters in real life, but still it's interesting.

p.s. While I can't make google find any real stuff, I found posts of other people concerned with the same question, e.g. this thread. Someone there made statistical conclusions on the period based solely on the hash length, but that's statistical, while the algorithms are deterministic and not too perfect.

offtopic

Posted Dec 18, 2007 15:11 UTC (Tue) by njs (guest, #40338) [Link]

```Okay, seriously, last crypto tutorial comment from me for a while, I swear...

There's a lot of research of how you generate good cryptographic PRNGs.  Some approaches use
hashes, some don't.  The analysis in general is utterly different from the analysis of
scientific PRNGs, for the natural reason that you don't care so much about having provably
insane period and provably insane equidistribution requirements; but you do care a huge amount
about e.g. making sure that the internal state remains secret even when people can observe the
PRNG's output, and that even if current state *were* revealed that this would not let you "run
the PRNG backwards" and work out what earlier states were, and that you are clever about how
you mix in new entropy from whatever external sources.  Of course, you'd *like* a provably
insane period too (to the extent that "period" is even meaningful when you are mixing in
entropy as you go), but it's very hard to get an algorithm that resists all cryptographic
analysis, *but* is still amenable to period analysis...

Random posts on python-list are, unfortunately, pretty useless for grokking this stuff.  If
you really are curious to learn how CPRNGs are designed, one convenient place to start might
be Schneier's various online-accessible writings on the subject:
http://www.schneier.com/paper-prngs.html
http://www.schneier.com/paper-yarrow.html
http://www.schneier.com/blog/archives/2007/11/the_strange...
(Yarrow in particular is a fun and interesting algorithm, though no longer quite considered
state of the art.  The last link is awesome for anyone who enjoys some geeky conspiracy, and
has lots more links.)
```

offtopic

Posted Dec 19, 2007 3:39 UTC (Wed) by ikm (subscriber, #493) [Link]

```Yay! Thanks. You're right -- I've never thought too much about the use of RNGs outside
Monte-Carlos and such, and the properties you've mentioned can mean a lot more than typical
equidistribution/period requirements in other contexts indeed.

I'll go dig the links you've provided. Thanks again, your help is much appreciated.
```

offtopic

Posted Dec 20, 2007 17:57 UTC (Thu) by njs (guest, #40338) [Link]

```Cool, glad to help.  Have fun!

(If you really want to get into this, I also highly recommend Ferguson and Schneier's
/Practical Cryptography/.  /Applied Cryptography/ is better known, but it's all like "so in
RSA you use modular arithmetic on primes in the following way" while /Practical Cryptography/
is all like "so if for some reason you want to reinvent SSL, here are the design trade-offs
you have to decide about, and here are the subtle bugs you're going to put in that will break
everything".)

```