In this lecture we'll talk about the properties and the use cases of hash algorithms. Though all cryptographic
hash functions have different mathematical foundations
they do have the same properties.
Let's consider a cryptographic hash function and see what are its properties.
The first property is called determinism.
This means that the output of a hash function doesn't change between executions if it runs on the same
input.
It doesn't matter when or on what machine you calculate the hash, it will be the same
if you use the same algorithm and input. In these examples I've calculated the hash of word Linux into
different ways: using the sha512 some command and using the Openssl command; is the
same hash. If I calculate the hash using an online tool we get the same result.
Another important property of hash functions is that two different inputs always have different hashes
or we can say that if two inputs like two files have the same hash they must be equal.
If a single beat changes across inputs it will produce an entirely different hash. Let's calculated the
hash of the word computer using sha256
computer and the algorithm is sha256.
This is the hash; now let's calculated the hash of the word computer1 using the same algorithm.
We notice that two different words have two different hashes.
Each input has its own unique hash.
Keep this in mind! Now, theoretically speaking, it's possible to have collisions and that means different
inputs with the same hash; but with a good cryptographic hash function
there isn't a known way of finding a collision with all the computing resources in the world.
We'll discuss hash collisions in a dedicated lecture later in the course. A hash function is one-way,
meaning that it’s computationally infeasible to determine the original message from its hash value. Hashes
work based on an irreversible mathematical transformation.
In other words, given a hash, it would be impossible or extremely difficult to determine the deterministic
steps taken to reproduce the input of that hash. Look at this hash.
There is no way, no matter how much computational power you possess, to find the file or the text that
has produced this hash.
Hash functions always produce a fixed length output regardless of size of the input.
For example SHA256 always produces a hash of 256 bits and sha-512 a hash of 512 bits.
In fact the number after the Sha word means the length of the output hash. Let's see some examples. I'll
calculate the hash of two characters, a and b, using SHA256.
This is the hash which has a length of 256 bits or 64 hexadecimal characters.
Now I calculated the hash of a phrase!
And the output hash has the same length 64 symbols in base 16. Let's
see now the hash of a file. I'm not interested in how big the file is; it's hate will have a length of
256 bits or 64 hexadecimal characters.
Sorry the command is SHA256sum.
Okay.
Permission denied.
Okay let's choose another file etc/password
or
etc group/password.
Or
/bin/ls
and so on.
We see the hash it's the same length.
If I had the file of one gigabyte its hash would be of the same length. Another property of hash algorithms
is that the avalanche effect. Changing one bit in the input should create an avalanche effect and its
result is an entirely different hash. Let's an example!
Let's take a bigger file, for example a dictionary file that comes with Kali Linux. Let's see how many
characters and the words are in that file.
usr/share/dict and american-english; there are almost 1 million characters. Let's calculate the hash
of that file.
This is the hash and I'll change a single character.
I am opening the file using vim
and at the end of the file I'll add a whitespace ; okay.
And I'm saving the file.
Okay I must be root in order to be able to edit the file.
No problem.
It's very easy.
So at the end I'm adding a white space and I'm saving the file.
Let' see its hash!
And we noticed that
its hash is entirely different.
It's in fact a new hash.
This is the avalanche effect. These five properties we've just discussed are the most important ones
of any hash function.
A good cryptographic hash function must also provide compression, efficiency and collision and preimage
resistance. Compression means that the length of the output should be small enough.
Efficiency means that the output hash should be computed easily enough in terms of time and hardware
resources and collision and preimage resistance means to be secure enough.
I'll go deeper into these two properties in a dedicated lecture where we'll talk about the attacks on
hash algorithms.