Cryptographic hash functions · 01 How it works

Hash functions: how they work

How a hash function compresses data of any length into a fixed value: blocks, internal state, the Merkle-Damgård construction and the sponge construction.

A hash function does not “summarise” content as a person would: it scrambles it deterministically until every output bit depends on every input bit.

  1. 01
    Preparation

    The message is completed with padding that includes its length, so as to obtain a whole number of blocks.

  2. 02
    Splitting into blocks

    The message is divided into fixed-size blocks, for example 512 bits for SHA-256.

  3. 03
    Initial state

    The function starts from a fixed initial value defined in the standard.

  4. 04
    Compression

    Each block is combined with the current state through many rounds of logical and arithmetic operations.

  5. 05
    Result

    After the last block, the final state is the hash value.

Two architectures

ConstructionUsed byCharacteristic
Merkle-DamgårdMD5, SHA-1, SHA-2The state passes from one block to the next via a compression function; it is subject to length-extension attacks
SpongeSHA-3The message is “absorbed” into a large internal state and the value is “squeezed” out; it does not suffer from length extension
Continue with
02 History

Hash functions: history

From the first cryptographic hash functions to the SHA family, from MD5’s success to collisions, to the competition that produced SHA-3.

↑