Labs ICT
โญ Pro Login

Cryptographic Hashing

Hash functions, SHA-256, and data integrity

Cryptographic Hashing

Hashing is the backbone of blockchain security. A hash function takes any input data and produces a fixed-length string of characters. Even a tiny change in input produces a completely different output, making hashes ideal for verifying data integrity.

Hash Function Properties


  Input: "Hello World"        โ†’ 2ef7bde608ce5404e97d5f042f95f89f1c232871
  Input: "Hello World!"       โ†’ 8487a0e1b89ccc8870605ca0b2e0074d5c47b171
                                                  ^^^^^^^^^^^^^^^^^^^^^^^^
  Completely different from just adding "!"

  Key Properties:
  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚  1. Deterministic                                 โ”‚
  โ”‚     Same input โ†’ Always same output               โ”‚
  โ”‚                                                    โ”‚
  โ”‚  2. Fast to Compute                                โ”‚
  โ”‚     Hash calculated in microseconds                โ”‚
  โ”‚                                                    โ”‚
  โ”‚  3. Pre-image Resistant                            โ”‚
  โ”‚     Cannot reverse hash to find original input     โ”‚
  โ”‚                                                    โ”‚
  โ”‚  4. Avalanche Effect                               โ”‚
  โ”‚     Small input change โ†’ Completely different hash โ”‚
  โ”‚                                                    โ”‚
  โ”‚  5. Collision Resistant                            โ”‚
  โ”‚     Nearly impossible to find two inputs with      โ”‚
  โ”‚     the same hash output                           โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

SHA-256 in Bitcoin

Bitcoin uses the SHA-256 (Secure Hash Algorithm 256-bit) algorithm. It produces a 64-character hexadecimal string (256 bits).


  SHA-256 Example:
  Input:  "Blockchain"
  Output: 3c337cb142c3c8e5034e0e5e0f9d8b1e0c5c5a5b5d5f5e5c5a58565452504e4c

  Bitcoin Block Hash (simplified):
  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚  Block Header:                       โ”‚
  โ”‚  - Previous Block Hash               โ”‚
  โ”‚  - Merkle Root                       โ”‚
  โ”‚  - Timestamp                         โ”‚
  โ”‚  - Difficulty Target                 โ”‚
  โ”‚  - Nonce                             โ”‚
  โ”‚                                      โ”‚
  โ”‚  SHA-256(Block Header) = Block Hash  โ”‚
  โ”‚  Must start with N leading zeros     โ”‚
  โ”‚  to meet difficulty target           โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Merkle Trees

Blockchains use Merkle trees (hash trees) to efficiently summarize all transactions in a block. Each transaction is hashed, then pairs of hashes are combined and hashed again until a single root hash remains.


              Merkle Root
             /          \
        Hash(AB)      Hash(CD)
        /    \        /    \
    Hash(A) Hash(B) Hash(C) Hash(D)
      |       |       |       |
     Tx A    Tx B    Tx C    Tx D

  Merkle Root = Single hash representing ALL transactions
  Allows quick verification of any single transaction
  without downloading the entire block

๐Ÿงช Quick Quiz

What does SHA-256 produce?