Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pseudo random generator <=> hash function?

Tags:

random

hash

I've been thinking about this as a thought experiment to try and understand some hashing concepts. Consider the requirement for a say 128 bit hash function (i.e., its output is exactly 128 bits in length).

A. You might look at something like MD5. So you input your data to be hashed, and out pops a 128 bit number.

B. Alternatively, you find a magical pseudo random number generator (PRNG). Some sort of Frankenstein version of the Twister. It seeds itself from all of your input data to be hashed, and has an internal state size >> 128 bits. You then generate 128 pseudo random bits as output.

It seems to me that both A and B effectively produce an output that is determined solely by the input data. Are these two approaches therefore equivalent?

Supplemental:

Some feed back has suggested that there might be a security in-equivalence with my scenario. If the pseudo random number generator were to be something like Java's SecureRandom (which uses SHA-1), seeded from the input data, then might A <=> B?

like image 515
Paul Uszak Avatar asked Aug 14 '26 17:08

Paul Uszak


2 Answers

If you seed a PRNG with your input data and then extract 128 bits of random data from it, then you effectively leave the hashing to the PRNG seed function, and the size of the hash that it generates will be the size of the PRNG state buffer.

However, if the state of the PRNG is larger than the 128 bits you extract as a hash, then there's a risk that some of the input data used for the seed won't have any effect on the bits of the PRNG state that you extract. This makes it a really bad hash, so you don't want to do that.

PRNG seed functions are typically very weak hashes, because hashing is not their business. They're almost certainly insecure (which you did not ask about), and separate from that they're usually quite weak at avalanching. A strong hash typically tries to ensure that every bit of input has a fair chance of affecting every bit of output. Insecure hashes typically don't worry that they'll fail at this if the input data is too short, but a PRNG seed will often make no effort at all.

like image 181
sh1 Avatar answered Aug 18 '26 06:08

sh1


Cryptographic hash functions are designed to make it hard to create input that generates a specific hash; and/or make it hard to create two inputs that generate the same hash.

If something is designed as a random number generating algorithm, then this was not one of the requirements for the design. So if something is "just" a random number generator, there is no guarantee that it satisfies these important constraints on a cryptographic hashcode. So in that sense, they are not equivalent.

Of course there may be random number generating algorithms that were also designed as cryptographic hashing algorithms, and in that case (if the implementation did a good job at satisfying the requirements) they may be equivalent.

like image 42
Erwin Bolwidt Avatar answered Aug 18 '26 05:08

Erwin Bolwidt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!