How Does SHA-3 Work?
SHA-3 differs fundamentally in its construction from hash functions such as SHA-256 or SHA-512. While the SHA-2 family processes messages block by block with compression functions, SHA-3 is based on a Sponge Construction.
In the article What Is SHA-3?, we have already looked at what SHA-3 is and how the hash family differs from SHA-2.
Now we take one step further.
I will show you what happens inside SHA3-256 – from the input, through padding and absorbing, to the finished 256-bit hash value.
We use the following message as an example:
hello
SHA3-256 produces from this:
3338be694f50c5f338814986cdf06864
53a888b84f424d792af4b9202398f392
The decisive question is:
What happens between hello and this hash value?
The SHA3-256 Process at a Glance
In simplified form, SHA3-256 can be broken down into several steps:
Message
│
▼
UTF-8 bytes
│
▼
Domain separation + padding
│
▼
Division into rate blocks
│
▼
Absorbing
│
▼
Keccak permutation
│
▼
Squeezing
│
▼
256-bit hash value
At the center is an internal state with a size of 1600 bits.
The following parameters apply to SHA3-256:
| Parameter | SHA3-256 |
|---|---|
| State | 1600 bits |
| Rate | 1088 bits |
| Capacity | 512 bits |
| Hash length | 256 bits |
| Permutation | KECCAK-p[1600,24] |
| Rounds | 24 |
In this case:
Rate + Capacity = State
1088 + 512 = 1600 bits
These values will accompany us through the entire algorithm.
Try the Process Yourself
With the following explorer, you can examine the complete SHA3-256 process for an input of your own.
Among other things, you can see:
- which UTF-8 bytes result from your input,
- what domain separation and padding look like,
- how many rate blocks the message is divided into,
- how the internal 1600-bit state is structured,
- how a message block is XORed with the state,
- how the state changes through Keccak-f,
- and which bytes finally form the SHA3-256 hash value.
SHA3-256 in Process
Follow step by step how an input becomes a SHA3-256 hash value. The tool shows intermediate states of the same computation that produces the hash value.
- State
- 1600 bit
- Rate
- 1088 bit / 136 byte
- Capacity
- 512 bit / 64 byte
- Output
- 256 bit / 32 byte
- Permutation
- Keccak-f[1600]
- Rounds
- 24
This implementation is for illustration. For production cryptography, vetted cryptographic libraries should be used.
The intermediate states shown are not merely a simplified illustration. They come directly from the same SHA3-256 computation that produces the final hash value.
Let us now look at the individual steps in more detail.
Step 1: The Message Is Converted into Bytes
A hash function does not work directly with letters or words.
It processes bits, or rather bytes.
Our example message is:
hello
In UTF-8, the five characters correspond to the following bytes:
68 65 6c 6c 6f
The message therefore consists of:
5 bytes = 40 bits
For simple ASCII characters, each character corresponds to exactly one byte.
This does not hold for all texts, however.
A character such as:
ö
requires more than one byte in UTF-8, for example. That is why what matters for processing is not the number of visible characters, but the actual byte sequence of the encoded message.
SHA3-256 ultimately processes exactly this bit sequence.
Step 2: SHA-3 Adds Domain Separation and Padding
Before the message can be absorbed, it has to be brought to a suitable length.
Two things happen here:
- SHA-3 appends bits for domain separation.
- The message is then padded with the Keccak padding.
For the four SHA-3 hash functions, FIPS 202 defines:
M || 01
M stands for the original message.
So first, the two bits:
01
are appended to the message.
These bits serve domain separation. Among other things, they ensure that the SHA-3 hash functions can be distinguished from other functions that use the same underlying Keccak construction.
Then the padding:
pad10*1
is applied.
The name already describes the basic pattern:
1
0...
1
So a 1 bit is appended, followed by as many 0 bits as necessary, and finally another 1 bit.
The message is thereby extended so that its length fits the blocks of the sponge construction.
Why Do 0x06 and 0x80 Often Appear with SHA3-256?
In implementations, the byte value:
0x06
is frequently encountered with SHA-3, and at the end of a padding block often:
0x80
This can easily lead to the simplified idea that SHA-3 just appends the bytes 06 and 80 to a message.
However, it should not be understood that way.
The definition in FIPS 202 is made at the bit level:
M || 01
followed by:
pad10*1
The byte values arise from how these bits are encoded within the byte sequence.
For our input hello, the beginning of the padded block therefore looks, for example, like this:
68 65 6c 6c 6f 06 00 00 ...
and at the end of the block is the closing padding bit.
In the usual byte-oriented representation, this appears at the end as the highest bit set:
... 00 00 00 80
A special case arises when the end of the message falls directly before the block boundary.
Then the suffix bits and the closing padding bit can end up in the same byte.
For SHA3-256, this can produce, for example:
0x86
0x06, 0x80 or 0x86 are therefore not arbitrarily chosen "magic bytes", but the result of the bit-level definition of domain separation and padding.
Step 3: The Message Is Divided into Rate Blocks
SHA3-256 uses a rate of:
1088 bits
This corresponds to:
136 bytes
The prepared message is therefore divided into blocks of 136 bytes each.
Our message hello is very short.
After domain separation and padding, it fits entirely into a single rate block:
Block 1
136 bytes
For longer messages, several blocks result:
Block 1
136 bytes
Block 2
136 bytes
Block 3
136 bytes
...
It is important to note that the number of blocks does not depend on the original message length alone.
Domain separation and padding also need space.
A message of exactly 136 bytes therefore already requires one more block for the additional bits.
Step 4: SHA3-256 Uses a 1600-Bit State
The heart of the computation is the internal state – the so-called state.
In SHA-3, this state has a size of:
1600 bits
It can be viewed as 25 so-called lanes of 64 bits each:
25 × 64 bits = 1600 bits
Conceptually, these 25 lanes are arranged in a 5×5 structure:
5 × 5 lanes
At the start of the computation, all bits of this state are 0.
Simplified:
0000000000000000
0000000000000000
0000000000000000
...
for all 25 lanes.
The 5×5 representation becomes especially important when we look more closely at the Keccak permutation later.
For the basic SHA3-256 process, it is enough at first to picture an internal state of 1600 bits.
Rate and Capacity Divide the State
For the sponge construction, the 1600 bits of the state are conceptually divided into two parts:
┌───────────────────────────────────────┬──────────────────┐
│ Rate: 1088 bits │ Capacity: 512 bits│
└───────────────────────────────────────┴──────────────────┘
Together they make up:
1088 + 512 = 1600 bits
The rate is the part through which input and output interact with the state.
The capacity is not XORed directly with the message blocks.
It is an essential component of the security properties of the sponge construction.
For SHA3-256, the capacity is:
512 bits
which is twice the digest length of 256 bits.
Why rate and capacity exist, and how their sizes relate to the security properties of a sponge construction, we will examine more closely in a separate article.
Step 5: The First Block Is Absorbed
Now begins the so-called absorbing phase.
The first 136-byte block of the prepared message is combined with the rate part of the state.
For this, Keccak uses the bitwise XOR operation.
In simplified form:
Message block
│
▼
XOR
│
▼
┌──────────────────────────┬──────────────┐
│ Rate │ Capacity │
│ 1088 bits │ 512 bits │
└──────────────────────────┴──────────────┘
Only the rate part is XORed directly with the message block.
The capacity receives no message bits directly.
For the first block, the state initially consists entirely of zeros.
Therefore, after the first XOR, the rate part initially equals the bits of the message block.
On its own, this would not yet produce a cryptographically interesting transformation.
That is why the decisive step follows:
the Keccak permutation.
Step 6: Keccak-f Transforms the Entire State
After a message block has been XORed with the rate part, the entire 1600-bit state is transformed.
SHA-3 uses the permutation:
KECCAK-p[1600,24]
This corresponds to the 24-round Keccak-f permutation for a 1600-bit state.
Each round consists of five transformations:
θ Theta
ρ Rho
π Pi
χ Chi
ι Iota
These five steps change and mix the bits of the state in different ways.
To understand the basic SHA3-256 process, we do not yet need to know their exact workings.
What matters at first is:
State before the permutation
│
▼
Keccak-f[1600]
24 rounds
│
▼
State after the permutation
The state after these 24 rounds looks completely different from before.
This repeated transformation of the internal state forms the cryptographic core of SHA-3.
How Theta, Rho, Pi, Chi and Iota work in detail, we will look at separately later.
What Happens with Multiple Message Blocks?
Our example message hello needs only a single block.
For longer messages, the absorbing process repeats.
After the first block, the state already holds the result of the Keccak permutation.
The second message block is then XORed with the rate part of this already changed state.
After that, Keccak-f is applied again.
The process therefore looks like this:
Block 1
│
▼
XOR
│
▼
Keccak-f
│
▼
State 1
Block 2
│
▼
XOR
│
▼
Keccak-f
│
▼
State 2
Block 3
│
▼
XOR
│
▼
Keccak-f
│
▼
State 3
This process is repeated until all message blocks have been absorbed.
Each block thus influences the internal state on which the next block continues to work.
Why Is the State Transformed After Every Block?
The next message block is not absorbed into a fresh state.
It meets the state that has already arisen from all previously processed blocks:
State 0
+
Block 1
↓
Permutation
↓
State 1
+
Block 2
↓
Permutation
↓
State 2
The message processed so far thus influences the state into which the next block is absorbed.
At the same time, the Keccak permutation acts on the entire 1600-bit state. Changes that were first introduced through the rate part are thereby spread across the state.
Step 7: After Absorbing, Squeezing Begins
After all message blocks have been processed, the second major phase of the sponge construction begins:
the squeezing phase.
While absorbing introduces data into the state, squeezing takes output bits from the rate part of the state.
For SHA3-256, we need:
256 output bits
The rate part contains:
1088 bits
The required 256 bits therefore fit entirely into the first available output of the rate part.
For its 256-bit digest, SHA3-256 therefore does not need to perform any additional permutation to obtain further output bits.
With sponge functions that require longer output, this can be different: if the current rate part is not sufficient, the state is permuted again and further output is taken.
This principle plays an especially important role for the SHAKE functions.
Step 8: The First 256 Bits Become the SHA3-256 Hash
For our input:
hello
we finally obtain 32 bytes, or 256 bits.
In hexadecimal representation, these are:
3338be694f50c5f338814986cdf06864
53a888b84f424d792af4b9202398f392
This completes the SHA3-256 computation.
The entire data flow can now be reduced to four central phases:
Padding
↓
Absorb
↓
Permutation
↓
Squeeze
The message is first prepared for the 136-byte blocks. Each block is absorbed into the rate part, and then the entire state is transformed by Keccak-f.
After the last block, the required 256 output bits are taken from the rate part during squeezing.
From:
hello
this finally becomes:
3338be694f50c5f338814986cdf06864
53a888b84f424d792af4b9202398f392
What We Have Simplified So Far
With this process, we can already follow how a message is basically processed by SHA3-256.
However, some important details we have deliberately not yet broken down completely.
For example:
- How exactly does a sponge construction work?
- Why are there rate and capacity?
- Why is the capacity 512 bits in SHA3-256?
- How exactly are the 1600 bits distributed across the 25 lanes?
- How are bytes arranged within the lanes?
- What happens inside a single Keccak-f round?
- What do Theta, Rho, Pi, Chi and Iota do?
- How do SHA3-224, SHA3-256, SHA3-384 and SHA3-512 differ internally?
- How can SHAKE128 and SHAKE256 produce outputs of different lengths?
These questions are extensive enough for separate articles and interactive examples.
For a basic understanding of SHA3-256, what matters first is grasping the data flow:
Padding
↓
Absorb
↓
Permutation
↓
Squeeze
This flow also shows why SHA3-256, despite the same hash length, works fundamentally differently from SHA-256. SHA3-256 uses a sponge with a 1600-bit state and the Keccak permutation, instead of the compression construction of SHA-256.
The Most Important Points in Brief
SHA3-256 processes a message with the help of a sponge construction and a 1600-bit internal state.
The most important points to remember:
- SHA3-256 works with a 1600-bit state made of 25 lanes of 64 bits each.
- The rate is 1088 bits, or 136 bytes, and the capacity is 512 bits.
- Domain separation and
pad10*1prepare the message for processing. - The prepared message is divided into 136-byte blocks.
- Each block is XORed with the rate part.
KECCAK-p[1600,24]then transforms the entire state in 24 rounds.- After the last message block, the squeezing phase begins.
- The first 256 required output bits form the 32-byte SHA3-256 digest.
With that, we now know the basic path from a message to the SHA3-256 hash.
The next important building block is the construction behind this entire process:
the sponge construction.
Sources and Further Standards
-
NIST FIPS 202 – SHA-3 Standard: Permutation-Based Hash and Extendable-Output Functions
The central standard for SHA-3. It defines, among other things, the SHA-3 hash functions,KECCAK-p, the sponge construction,pad10*1, and SHAKE128 and SHAKE256. -
NIST – SHA-3 Project
Official NIST overview of the development and standardization of SHA-3, and of further SHA-3 documents. -
NIST ITL Bulletin – Additional Secure Hash Algorithm Standards Offer New Opportunities for Data Protection
NIST summary of FIPS 202 and the SHA-3 family.