How does SHA-3 turn a large file into a fixed-length digest?
Suppose you want to compare a digest authenticated by the publisher’s signature with one you compute as you read your local copy of a file. With SHA3-256, you compare 32 bytes whether the file is one byte or 1 GB. The algorithm is public, so anyone can recompute the digest. Deliberately producing another file with the same digest is believed to be hard. Using hashes
- Start with zero stateKeccak-f[1600] state: 200 bytes; rate (input/output area): 136 bytes; capacity (hidden mixing area): 64 bytes.
- Absorb block 1XOR message bytes 0–135 into the rate; permute the entire state.
- Absorb block 2Append SHA-3 domain-separation bits and final padding to the remaining 4 message bytes; XOR this padded rate block into state; permute again.
- Read digestRead 32 bytes from the rate. Output: the SHA3-256 digest; capacity is never read directly.
What does the sponge do when it absorbs data?
Keccak keeps a fixed-size internal state. It takes input through one part of the state and repeatedly mixes the entire state. This is called a sponge construction because it absorbs input and then squeezes out output. The SHA3-256 state is 200 bytes. It uses 136 bytes for input and output (the rate) and reserves the other 64 bytes for internal mixing (the capacity). The capacity is never read or written directly by the absorb or squeeze operations. FIPS 202 §§3–6
For a 140-byte file, XOR the first 136 bytes into the rate portion of the initially zero state and mix the entire state. Append the SHA-3 domain-separation bits and final padding to the remaining four bytes, then XOR and mix again. Read the first 32 bytes from the resulting state to get the digest. Reading the file in two 70-byte chunks gives the same result as long as you absorb the bytes in order and add the domain-separation bits and padding only once at the end.
What does mixing the state involve?
The Keccak-f[1600] permutation arranges twenty-five 64-bit words in a five-by-five grid and updates them over 24 rounds. In each round it XORs the words in each column and uses the result to update neighboring columns. It rotates the words and moves them to new positions, applies a nonlinear operation using neighboring words within each row, and XORs in a round constant. A change introduced through the rate spreads to the capacity, which remains hidden from direct input and output.
SHA3-512 uses the same permutation. Its rate is 72 bytes, its capacity is 128 bytes, and its output is 64 bytes. SHA3-512 and SHA3-256 therefore absorb input at different block boundaries starting with the first block. QuantAegis uses both functions in ML-KEM. Rust SHA-3 API · SHAKE and variable-length output