Cryptographic hashing

A cryptographic hash function is a type of function that maps arbitrary sized data to a fixed size string called a hash. Hash functions possess certain properties that make them ideal for use in cryptography.

Hash functions are widely used in hash table data structures. A hash table stores the data in a key-value pair. Hash tables are used when large keys need to be converted into smaller keys using a hash function, and then the values are mapped to these smaller keys. This makes the mapping of key to value quite easy, and this could be achieved in O(1) time complexity. This is due to the fact that hash functions have a constant time complexity.

We have repeatedly mentioned that hashing is the backbone of blockchain architecture, and it has several properties that make it really valuable and ideal for blockchain implementation.

Every hash function has the following properties:

  • Pre-image resistance: Given a computed hash h = hash (m), where m is the message, it should be infeasible to find the message from the given hash value.
  • Second pre-image resistance: Given a message m1, it should be infeasible to find another message m2 such that hash (m1) = hash (m2).
  • Collision resistance: A hash is said to have collided when there are at least two messages that produce the same hash value. It should be infeasible to find two messages m1 and m2 where hash (m1) = hash (m2), that is, it should be challenging to find two messages that have the same hash value. This is similar to the second pre-image resistance, but any two messages can be chosen here. So, this property implies second pre-image resistance.

Although every hash function has these properties, a good hash function is expected to possess additional properties in order to provide strong security:

  • A hash function should take a constant time for any input.
  • Any bit changed in the message should result in a completely new hash value compared to the hash of the previous message. It should be very difficult to analyze the hash value created by the hash function.
Hashing is used in blockchain to create a unique identity string for each block by computing its hash value. Each block will maintain the hash value of the previous block and thus form a chain of blocks. Hashing provides integrity to the blocks of the blockchain ledger.