Hash Function is a function which has a huge role in making a System Secure as it converts normal data given to it as an irregular value of fixed length. We can imagine it to be a Shaker in our homes.
When we put data into this function it outputs an irregular value. The Irregular value it outputs is known as “Hash Value”.Hash Values are simply number but are often written in Hexadecimal. Computers manage values as Binary. Hash value is also a data and are often managed in Binary.
Whirlpool Hash Function
Whirlpool is an iterated cryptographic hash function created by Vincent Rijmen and Paulo S.L.M. Barreto. It was first published in 2000 and revised in 2001 and 2003. It was derived form square and Advanced Encryption Standard. It is a block cipher hash function and designed after square block cipher. It takes less than 2^256 bits length input and convert it in 512 bit hash. The first version of whirlpool is called Whirlpool-0 and changed to Whirlpool-T after it’s first revision in 2001 . In this version the S-box is changed and become easier to use in hardware. In 2002 a vulnerability was founded in the Whirlpool-0’s diffusion matrix which was removed by changing the matrix and the name was also changed from Whirlpool-T to Whirlpool.
Every block cipher in whirlpool is a 8*8 matrix. The state of the function changes in every round by using four operations:
Operation Name | Function |
---|---|
Mix Rows(MR) | It is a right multiplication of each row by an 8*8 matrix. |
Substitute Bytes(SB) | It is a simple table lookup and gives nonlinear mapping. |
Add Round Key(AK) | In this the 512 bits of the round key is goes through XOR with 512 bit of current state. |
Shift Columns(SC) | In this except the first column of current state are cyclically downward shifted. |
Hash Value is calculated by using the formula:
State = MR*AK*SC*SB(State)
Install whirlpool library using
pip install whirlpool
Example 1:
Python3
# Python program to demonstrate # whirlpool hash function import whirlpool string = b "Lazyroar" h1 = whirlpool.new(string) hashed_output = h1.hexdigest() print ( "The hashed value is" ) print (hashed_output) |
Output:
The hashed value is
95cb4d2d765eb26a922b3ade5a5837a3bc6b18f9a68cec6392f7bf4284c996dd0dd8775dc77964bb9dd92f204d067d3b2c0f36f968607c88cd378ce094438e5a
Example 2:
Python3
# Python program to demonstrate # whirlpool hash function import whirlpool string = b "Lazyroar" h1 = whirlpool.new(string) hashed_output = h1.hexdigest() h1.update(b "Geeks" ) hashed_output = h1.hexdigest() print ( "The hashed value is" ) print (hashed_output) |
Output:
The hashed value is
c3a2aea5a2b487f1a3ee848870dff8ca5af0adcf7eae2a58b40927e87027918c2e9438909c50c2d2bb73f15392c8fde22c94c85a8ef5d8c3b3e86a839909d58b