Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Blockchain – Block Hashing

  • Last Updated : 26 Nov, 2021

Blockchain is the backbone Technology of Digital CryptoCurrency BitCoin. The blockchain is a distributed database of records of all transactions or digital events that have been executed and shared among participating parties. Each transaction is verified by the majority of participants of the system. It contains every single record of each transaction. In order to understand how blockchain works, it’s very important to understand in detail the concept of Hashing.

There are three main parts of any blockchain network:

  • Node/ Block: It is the main building block of any blockchain. It acts as a database to store the information related to all transactions. The size, period, and triggering event for blocks are different for every blockchain. Each block or node contains a complete record of all the transactions that were ever recorded in that blockchain.
  • Network: The network is composed of “full nodes”. Think of them as the computer running an algorithm that is securing the network.
  • Hash:  It acts as a chain that links one block to another, mathematically one can say that it’s “chaining” all blocks together. This is one of the most difficult concepts in blockchain to comprehend. It’s like magic that glues blockchains together and allows them to create mathematical trust and maintain privacy as well as security in the network. The hash in the blockchain is created from the data that was in the previous block. So we can say that the hash is a fingerprint of this data and locks blocks in order and time.

Hashing In Blockchain:

In simple words, hashing refers to the process of having an input of any length but showing an output item of a fixed length. If we take the example of blockchain use in online transactions(using bitcoins), transactions of different lengths are run through a given hashing algorithm, and all give an output that is of a fixed length. This output is independent of the length of the input transaction.

  • Secure Hashing Algorithm 256 (SHA-256): This hashing algorithm always gives an output of fixed length 256-bits or 32 bytes, no matter whatever is the size of the input transaction. It means if we hash two different input using SHA-256, let’s say one is a movie of 1 gigabyte and another is an image of 5 kilobytes, then in both cases, the output hash will be 256-bits in length. The only difference between the two will be the hash pattern. Currently, this algorithm is used in the Bitcoin network.
  • Keccak-256: This hashing algorithm always gives an output of fixed length 256-bit; currently it is used in the Ethereum network.

Hash Functions:

Basically, the process of using a given hash function to produce a transaction is called hashing. A hash function, will take any transaction or data input and rehash it to produce an output of a fixed size. The transaction output of that given hash function is what we call a hash.

INPUT DATA —>

       H(X)

HASH FUNCTION

—->HASH—->

         H(x)

HASH FUNCTION

—-> OUTPUT  

This complete process is known as Hashing. It consists of two subparts, one is encryption of data (the process of generating a hash from input data) and the second one is the decryption of data (the process of generating output from hash using a cryptographic hash function).

Properties of Hash Function: Three main properties of cryptographic hash functions are:

  • Its Input can be any string of any size.
  • It produces a fixed size output. We had already seen the example of SHA-256 regarding this property.
  • And the third one is, It is efficiently Computable, this means that for a given input string, we can figure out what the output of the hash function is in a reasonable amount of time. If I talk more technically, computing the hash of an n-bit string has a running time that is O(N). 

For a hash function to be strong and more secure, it has the following three additional properties:

  • Collision-resistance: A collision occurs when two distinct inputs produce the same output. A hash function H(x) is collision-resistant if nobody can find a collision. It means for two values x and y, such that x ≠ y, if h(x) =H(y), it means the function h(.) is collision-resistant. We want to increase data security then it’s very important to use a strong hash function that is not collision-resistant.
  • Hiding: This property of hash functions ensures that if we’re given the output of hash function y=H(x), then there’s no feasible way to figure out what the input, x, was. In a more technical and mathematical way “A hash function H is hiding if: when a secret value r is chosen from a probability distribution that has high min-entropy, then given H(r // x) it is infeasible to find x.
  • Puzzle friendliness: This property of the hash function is a bit complicated to understand, but I will try to make you understand in simple words. According to this property, if someone wants to target the hash function to come out to some particular output value y, that if there’s part of the input that is chosen in a suitably randomized way, it’s very difficult to find another value that hits exactly that target. In a more technical way, this property states that ” A hash function H is said to be a puzzle – friendly if for every possible n-bit output value y, if k is chosen from a distribution with high min-entropy, then it is infeasible to find x such that H(k // x)=y in time significantly less than 2n.

Applications:

1. Signature generation and verification: Almost all digital signature schemes require a cryptographic hash to be calculated over the message. The message is considered authentic if the signature verification succeeds given the signature and recalculated hash digest over the message. So the message integrity property of the cryptographic hash is used to create secure and efficient digital signature schemes.

2. Password verification: To authenticate a user, the password presented by the user is hashed and compared with the stored hash. A password hashing is performed; the original password cannot be recalculated from the stored hash value.

3. Verification of files and messages: An important application of secure hashes is the verification of message integrity. Comparing messages digests( hash digest over the message) calculated before, and after, transmission can determine whether any changes have been made to the message or file.

Conclusion: The cryptographic hash function is an integral part of blockchain innovation. It is essentially a feature that gives security capabilities to the processed transactions, making them immutable. Hashing is also at the center of “Merkle Trees”, which is an advanced approach to blockchain hashing. It is useful in issues of scalability, and mobile/ light wallets.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!