Hello guys!
In this lecture we'll talk about hashes!
You'll find them in many areas of computer science. Hashes are a critical part of best art systems digital,
signatures, security certificates, blockchain technology cryptocurrencies like Bitcoint and Ethereum
or even how the supermarket POS verifies the PIN of your credit card when you want to pay for
something.
Let's dive deeper into hashes! A hashing algorithm is a cryptographic function that takes an input, runs it
through some magical mathematical processes and then creates a unique output called hash.The output
hash is sometimes called message digest checksum or cryptographic fingerprint. The input of the hash
function can be literally anything from binary information like a file a packet a single character to
a word or a phrase. I'd like to show you a practical example using a Linux machine (since it already has
all applications needed to calculate hashes). If you are using Windows
you need to install the required tools.
So I'm executing sha256sum /etc/passwd
Let's take a deeper look at the command, its argument and its output. The hash function or the hash algorithm
used is sha256; sha stands for Secure Hash Algorithm, is pronounced sha, and is in fact a family of more
more hash protocols. Sha256sum
is the Linux application, the tool that implements the hash protocol which as I said is sha256.
/etc/passwd is the input of the hash function and this string written in hexadecimal or base 16
is the hash of the input. We can simply say that sha256 hash of password file is this value,
the value you are seeing right now. You should know that all hash algorithms are public. They are like a public
math formula that anyone can see and use; for example sha256 is part of a bigger family of hash algorithms
called sha-2. You can read more about them even on Wikipedia.
Look, this is the pseudo code for a sha256 algorithm; you can implement it in any programming language.
It's public!
Other well known hash algorithms besides sha-2 are md5 and sha1 which are considered insecure
and obsolete.
Let’s see the hash of Linux
word calculated with md5 and sha1:
echo -n the word "linux"
You can write anything you want.
| md5sum
-n is used not to add a new line; by default the echo command ends a new line at the end.
I want to calculated the hash only of this word.
And the hash calculated using sha1
That's the hash.
They are written
always in hexadecimal numbers; Other very secure and new hash
algorithms are sha-3 or Keccak, Blake2b and RIPEMD-160. Blake2b is used by Ethereum 2.0 and RIPEMD-160
is one of the two hash functions used by Bitcoin. And they were never
hacked! Another way to calculate a hash is using the openssl command like this:
openssl dgst -sha3-256
This is the hash algorithm and the file for example /etc/passwd
Okay.
This is the hash.
This is different than this one because it's another hash algorithm used.
Or you can calculate the hash of a string
this way:
echo -n "linux" | openssl dgst -rmd160
That's the hash; you can see a list of all hash algorithms implemented in openssl
by executing openssl and then help.
These are all hash algorithms implemented in openssl.
Let's try another example!
Let’s calculate the hash of word “linux” using this time the sha512 algorithm, in different ways:
In the first example
I'll be using the sha512sum command like this: echo -n "linux" | sha512sum
This is the hash; Or using the openssl command.
This is the hash! I can also use an online tool to calculate the hash; I am selecting sha512 and the
input Linux.
And this is the hash and we notice something very important: no matter how we calculate the hash if we
use the same algorithm we get the same hash, the same output.
Look at this output
and look at the same output here.
This is one of the properties of hashes which is called determinism and it means that the output of
a hash function doesn't change between runs.
It's in fact the same mathematical process applied.
These hash functions are also called one way functions. Another important property of a hash function
is that it's very easy to compute the hash from the given input but infeasible to find out the original
input from the resulting hash; or if you have the hash you are seeing right now there is no way to find
out what information, what word, file or packet, has given that hash.
Note that hashing is not encryption.
There is no secret, no key in hashing.