# Introduction

In this blog, we shall discuss a technical term frequently used while referring to the blockchain technology, hash functions. We shall go through its definition, working, and importance when it comes to understanding the blockchains and the technology behind them.

# What is a Hash?

A hash can be defined as a mathematical function that converts some data of arbitrary length to an output of a fixed length regardless of the size of the data put in the hashing algorithm.

In the case of crypto blockchains, transactions of varying lengths are run through a hashing algorithm to get an output of a fixed length. The output is called a hash.

In 1976, Diffie and Hellman were the first to identify the need for a one-way hash function in cryptography. Ronald Rivest, in 1990 invented the MD4 and later the MD5 and MD6 hash functions.

Following this, NSA designed the SHA-1 and SHA-2. SHA-2 inspired the development of SHA-256 (Secure Hash Algorithm -256) which has become the backbone of the Bitcoin consensus mechanism.

# Properties of Cryptographic Hash Functions

A cryptographic hash function always has outputs of the same length irrespective of the amount or length of the input data. This would make the tracking of input data much easier.

The computation of the input data to generate the hash values is fast even if the input data is of high complexity.

A cryptographic hash function is one-way and hence, pre-image resistant. This means the output data does not reveal any information about the input data. This levels up the security while using these functions in blockchains.

While using hash functions, it is impossible to predict the hash value of a particular data by examining the output values of previous input data.

Hash functions are collision-free. Though the same input data generates the same hash value every time, no two inputs have the exact same output value. Changing the input data even minutely changes the hash value greatly.

# Hash Functions in the Crypto Mining Process

Let us understand the use of hashing functions by studying the case of Bitcoin.

A blockchain acts as a universal ledger that stores records of all the transactions done on it. Each block consists of transaction data which are then validated and linked together to lengthen the blockchain. Each transaction generates a unique set of numbers and letters called hash. Mining involves interacting with these hash values.

Each block consists of the block header, hash of the previous block, a nonce, a timestamp, the hash of the Merkle root, and a target hash. The purpose of the nonce is to increase the randomness of the input value and hence increase the difficulty in computation during mining Bitcoin.

A miner (node) starts hashing this data and converting it into a hash value that meets the specified criteria of difficulty. If a hash meets these criteria, then the block is shared with the rest of the miners and once validated, added to the blockchain. The first miner to validate a block gets rewarded in Bitcoin.

If the hash does not meet the difficulty criteria then the miner selects another nonce and finds the hash values for that particular nonce. The process is repeated until the miner arrives at a valid hash value.

The use of hashing functions in the mining process of cryptocurrencies, mainly the ones using the Proof-of-Work consensus mechanism, makes the blockchain immutable and secures it from fraudsters.

# Conclusion

Cryptographic hashing functions are an important part of blockchain technology. All its features make it very useful while increasing the security and efficiency levels of a blockchain. We will be posting more blogs on topics related to this in the future.