Hash function types are the most common mathematical functions used in cryptography to implement security. In this Pooyan Music article, we will get to know the hash function in simple language.

A hash function converts an input value of any arbitrary size into a fixed-size value. Therefore, the input can be of any length, but the output produced is always of fixed length. The generated output is called hash or hash values.

Another important thing to note is that hash functions and cryptography are completely different from each other. Encryption is a two-way operation, i.e. encrypted data must be decrypted using a private key, so they are reversible. Hash functions or hash functions are one-way (that is, hashes are not reversible). Therefore, hashing is faster than encryption.

The most common use of hashes is password verification. When the user enters the password, a hash of the password is generated and compared to the hash in the database. If both hashes are the same, the user is allowed to login, otherwise the user must re-enter the password.

The most commonly used hash functions are listed below:

**MD**: stands for Message Digest. This function can be MD2, MD4, MD5 and MD6. MD is a 128-bit hash function.

**SHA**: stands for Secure Hash. It can be SHA-0, SHA-1, SHA-2 and SHA-3. SHA-224, SHA-256, SHA-384 and SHA-512 are variants of the SHA-2 family.

**RIPEMD**: stands for RACE Integrity Primitives Evaluation Message Digest. RIPEMD, RIPEMD-128 and RIPEMD-160 are widely used. There are also 256 and 320-bit versions of this algorithm.

**Whirlpool**: Whirlpool is a 512-bit hash function and a modified version of AES. WHIRLPOOL-0, WHIRLPOOL-T and WHIRLPOOL are three versions of Whirlpool.

An ideal hash function is desired to have the following properties to be effective against various attackers’ attacks. They are as follows:

Pre-image resistance means that the hash function cannot be reversed.

Simply put, if every hash function “a” produces the hash value “c”, it is very difficult to find the input value “b” that hashes to “c”.

This feature makes it impossible for an attacker who has the hash value and tries to find the input.

Pre-second image resistance means that for any input and its hash value, it is very difficult to find a different input that produces the same hash.

In simple words, if any hash function produces a hash value h(a) for the input “a”, then it will not be possible to find another input value “b” such that h(b) = h(a).

Collision resistance means that it is very difficult to find two different inputs of any length that produce the same hash. This feature is also known as collisionless hash function. This feature prevents an attack known as a hash collision attack.

Simply put, for a given hash function h, it is very difficult to find both inputs x and y, i.e. h(x) = h(y).

This no-collision property confirms that these collisions are difficult to find for a given hash function.

Also, this feature makes it difficult for an attacker to find two input values that produce the same hash.

Below are the fields where the hash function is widely used:

- Digital currency

Confirm password for authentication

Check the integrity of data and files

Digital signature