Whirlpool Hash Function in Python (original) (raw)

Last Updated : 7 Apr, 2026

Whirlpool is a cryptographic hash function designed by Vincent Rijmen and Paulo S. L. M. Barreto. It generates a 512-bit hash value, making it suitable for secure hashing.

A hash function converts input data into a fixed-length output called a hash value. It is widely used in data integrity, password storage and cryptography. The same input always produces the same hash, while even a small change in input generates a completely different output.

Internal Working

Whirlpool processes input data of variable length and produces a fixed 512-bit hash value. The algorithm went through multiple versions:

Internally, Whirlpool operates on a 512-bit state represented as an 8 × 8 byte matrix. The state is updated in multiple rounds using four main operations:

Operation Name Function
Substitute Bytes (SB) Applies non-linear transformation using a lookup table
Shift Columns (SC) Rearranges data by shifting columns
Mix Rows (MR) Mixes data using matrix multiplication
Add Round Key (AK) Combines data with a round key using XOR

Whirlpool processes the input data in multiple rounds. In each round, the internal state (represented as an 8 × 8 matrix) is updated by applying a sequence of transformations. These transformations are the core operations of the algorithm and are repeated multiple times to produce the final hash value.

The transformation can be represented as:

State = MR ∘ AK ∘ SC ∘ SB (State)

Installation

Install the Whirlpool library using:

pip install whirlpool

**Note: Whirlpool library may require additional system dependencies (such as C++ build tools) to install successfully. If installation fails, ensure the required compilers are installed on your system.

Examples

**Example 1: In this example, a string is converted into its Whirlpool hash value.

Python `

import whirlpool s = b"GeeksforGeeks" h = whirlpool.new(s) print(h.hexdigest())

`

**Output

95cb4d2d765eb26a922b3ade5a5837a3bc6b18f9a68cec6392f7bf4284c996dd...

**Explanation: whirlpool.new(s) creates hash object and hexdigest() returns hash in hexadecimal format

**Example 2: In this example, additional data is added to the existing hash using the update method.

Python `

import whirlpool s = b"GeeksforGeeks" h = whirlpool.new(s) h.update(b"Geeks") print(h.hexdigest())

`

**Output

c3a2aea5a2b487f1a3ee848870dff8ca5af0adcf7eae2a58b40927e87027918c...

**Explanation: update() adds more data to the hash

Applications

Limitations