Live data from Hacker News

How Hash Algorithms Work (2007)

metamorphosite.com

11–20 of 61 posts

Re: How Hash Algorithms Work (2007)

#12

As someone extremely new to this; can this procedure be worked backwards to retrieve the original text? If no, why not?

No, one important property of hashes in security applications is irreversibility (except for brute force, i.e. try and error).

For example, user passwords on a server should only be stored in hashed form (ideally with salt[1]). If an attacker gets access to that database, they will not be able to restore the original passwords without enormous computation costs.

The "why not" is harder two answer and I don't know all the details either. But the general idea is that the hashing algorithm contains irreversible operations where multiple (intermediate) inputs would result in the same (intermediate) output, so you cannot derive a unique input from the output.

A simple example for this is the modulo function: 9 mod 7 = 2, but also 16 mod 7 = 2. If you now see the result 2, the original number could have been 2, 9, 16, 23 or anything else of the form n*7 + 2.

[1]: https://en.wikipedia.org/wiki/Salt_(cryptography)

Re: How Hash Algorithms Work (2007)

#13
The title probably should be 'Cryptographic Hash Algorithms'. The definitions from the post are approximately true for cryptographic hashes but not really for hash functions in general.

Re: How Hash Algorithms Work (2007)

#14

As someone extremely new to this; can this procedure be worked backwards to retrieve the original text? If no, why not?

Not all operations are reversible, which makes it difficult to work out a simple inverse. Of course you could work backwards to find out which inputs could lead to a particular result, but this set of possible inputs would grow rapidly as you work your way back through the algorithm, making it nigh impossible to work out the original message, even if you have some idea what it's supposed to look like. Of course this…

> Of course you could work backwards to find out which inputs could lead to a particular result

AKA rainbow tables, which explains why it is important not to use just a single word from the dictionary as a password.

https://en.wikipedia.org/wiki/Rainbow_table

Re: How Hash Algorithms Work (2007)

#15

As someone extremely new to this; can this procedure be worked backwards to retrieve the original text? If no, why not?

This type of crypto hash is like hamburgers and cows (as a rather crude analogy): it's fairly easy to make a hamburger from the meat of the dead cow, almost impossible to make a cow from the hamburger meat.

Re: How Hash Algorithms Work (2007)

#16

Earlier quoted context omitted.

Not all operations are reversible, which makes it difficult to work out a simple inverse. Of course you could work backwards to find out which inputs could lead to a particular result, but this set of possible inputs would grow rapidly as you work your way back through the algorithm, making it nigh impossible to work out the original message, even if you have some idea what it's supposed to look like. Of course this…

> Of course you could work backwards to find out which inputs could lead to a particular result AKA rainbow tables, which explains why it is important not to use just a single word from the dictionary as a password. https://en.wikipedia.org/wiki/Rainbow_table

As explained in your link, rainbow tables make salts important. Imposing arbitrary requirements on users is misguided.

Re: How Hash Algorithms Work (2007)

#17
post #6
post #2

>The word 'cat' will hash to something that no other word hashes too, but it will always hash to the same thing. Don't hashing functions have collisions?

> Don't hashing functions have collisions? They do. The text is somewhat misleading and not properly explaining that. All hash functions have collisions. But from a cryptographically secure hash function we expect that nobody is able to find such a collision. They exist, but the computational power to find one is not available to humans.

To be fair, it is better explained later in the text. But definitely misleading.

> Also, it should be computationally infeasible to find any other word which also hashes to '...'

Re: How Hash Algorithms Work (2007)

#19
post #6
post #2

>The word 'cat' will hash to something that no other word hashes too, but it will always hash to the same thing. Don't hashing functions have collisions?

> Don't hashing functions have collisions? They do. The text is somewhat misleading and not properly explaining that. All hash functions have collisions. But from a cryptographically secure hash function we expect that nobody is able to find such a collision. They exist, but the computational power to find one is not available to humans.

>They do. >All hash functions have collisions.

This is wrong. There is something called a perfect hash function:

https://en.wikipedia.org/wiki/Perfect_hash_function

>a perfect hash function for a set S is a hash function that maps distinct elements in S to a set of integers, with no collisions. In mathematical terms, it is a total injective function.

They are very handy for hash tables with constant worst-case lookup time.

Re: How Hash Algorithms Work (2007)

#20
post #13

The title probably should be 'Cryptographic Hash Algorithms'. The definitions from the post are approximately true for cryptographic hashes but not really for hash functions in general.

I agree, it's definitely not a "comprehensive" guide. If it was comprehensive, it would include different algorithms, trade offs, talk about things like perfect hashing, hashes that preserve ordering, etc.
Post reply on HN