Introduction
A hashing algorithm’s goal is to generate a value computed from a base input number using a hashing function which are one way functions. It’s generally a cryptographic function that maps data of arbitrary size to a hash of a fixed size.
The ideal hash function should respect the following points :
- Fast to compute.
- Impossible to regenerate a message from its hash value.
- The smallest change of a message should change the entire hash value.
As you can see on this example, a simple change will affect the digest :
Functions with these properties are used as hash functions for a variety of purposes, not only in cryptography. Practical applications include message integrity checks, digital signatures, authentication, and various information security applications.
Famous Hash Algorithms
MD5
Unfortunately, this algorithm as been compromised due to extensive vulnerabilities. It can still be used as a checksum to verify data integrity, but only against unintentional corruption. It remains suitable for other non-cryptographic purposes, for example for determining the partition for a particular key in a partitioned database
SHA
MD5 produces producing a 128-bit hash value, SHA 160-bit hash value. The first version was designed by the NSA but since 2005, it is not considered as a secured algorithm. Two other versions have been designed : SHA-2 and SHA-3
Easy example
If User 1 sends a file to User 2, checksums are used to validate the integrity of the file.
Indeed, before sending the file, User 1 uses a hashing algorithm to generate a checksum for his file. Then he sends it alongside the file itself.
User 2 receives both the file and the checksum.
With that, he can use the same hashing algorithm on the received file to verify that both files are the same and no corruption have been detected !