In my previous post I have wrote about what is a hash in blockchain. Today we are going to share a little more about hash and explain the main characteristics of a hash function.
Main Characteristics of a Hash Function
It Needs to be Deterministic:
The same input needs to generate the same output, like SHA-256 or the function I've shown in my previous post.
It Needs to be Quick
Hashing happens so often, it should be quick.
Today we have no issue producing fast hash functions.
It Must Work One Way Only
The input can generate the output, but given the output, one must not be able to generate the input. This is a special feature of cryptographic hash functions. So our previous example cannot fulfill this demand, because given an output of 5, we know that 55 is a possible input.
In cryptography, this means I have broken the code. For computer it is theoretically possible to reverse the input, however, the longer hash you have, the harder it becomes to solve it.
A Small Change in the Input Must Change the Output Massively
Even after a minor change in the input, two outputs would look completely different. In this example, our little hash function also fails.
If I change 888 to 889, the output changes from 8.0 to 8.3.
It matters because otherwise breaking the hash is too easy.
It Must be Infeasible to Find Two Different Messages With the Same Hash
Again, that little hash function, we've talked before fails here.
5, 55 and 64 all have the same output 5. This makes breaking the code easier. If there are more correct inputs, your chances of finding the correct one is higher. However, it also can lead to dramatic crashes in systems.
Although, most hash functions are designed to decrease the possibility of two same outputs. It's still not fully achievable. Why? There is an infinite number of inputs, but the hashing function can only give a finite number of outputs because the length is set. However, if you make it less likely than for example a meteor crashing into Earth. Then we can consider it infeasible, which is all we need for now.