SHA-3 and Keccak Are Not the Same Hash: A Tour of One Padding Byte
SHA3-256 and Keccak-256 share a permutation but pad with different bytes, 0x06 vs 0x01. That byte is why Ethereum's keccak256 never matches Node's sha3-256.
Hash the empty string with both algorithms. Compare the output:
SHA3-256("") = a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a
Keccak-256("") = c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470
Nothing in common. No prefix, no suffix, no shared bits beyond what you would expect from two random 256-bit strings. And yet both algorithms are running the exact same 1600-bit permutation — Keccak-f[1600] — with the exact same rate (1088 bits) and the exact same capacity (512 bits). They produce the same internal state at every step of the computation, right up until one specific point near the end. That point is the padding rule, and the entire visible difference between the two algorithms is one byte appended to the input before the final permutation: 0x06 for SHA-3, 0x01 for original Keccak.
The fact that this byte exists is the reason an entire generation of Ethereum developers periodically discovers that Node's crypto.createHash('sha3-256') does not match web3.utils.keccak256, despite the names suggesting they should.
Why There Are Two Algorithms
The two-algorithm split is an artefact of timing. In October 2012 NIST announced Keccak as the winner of its hash function competition, but the standard itself took almost three more years. Ethereum's design started in late 2013, and its April 2014 Yellow Paper already specified Keccak-256 as submitted to the competition. By 30 July 2015, when the Ethereum mainnet launched, the codebase had keccak256 baked into every address, transaction hash, and Merkle root. The hashing primitive was now permanently part of the chain's consensus.
NIST published the draft of FIPS 202 in May 2014 and finalised it on 5 August 2015, six days after Ethereum launched. The draft already carried one small change from the competition version: a domain-separation prefix to distinguish SHA-3 hashes from the other functions in the same family (the SHAKE variable-output XOFs use a different domain byte, 0x1F). The change is good cryptographic hygiene — it means a SHA3-256 output and a SHAKE128 output can never collide even if they happen to consume the same internal state. But Ethereum had committed to the competition version before the draft appeared, and it never switched. Ethereum's keccak256 is, technically, original Keccak with no domain separation. SHA-3, the NIST-standardised version, is the same primitive plus a byte.
Every hashing tool that came after August 2015 had a choice to make: implement the standard (SHA-3 with 0x06), implement the pre-standard variant Ethereum uses (Keccak with 0x01), or both. A surprising number of libraries pick "one of them" and label it sha3, which is how you end up debugging a wallet integration at 2am.
The Byte, in Code
The padding rule for both algorithms is identical except for one byte. After the input message is absorbed in full-rate blocks, the final partial block is laid out like this:
[message bytes][SUFFIX][zeros…][0x80]
The SUFFIX byte sits immediately after the message; the rest of the block is zeros until the last byte, which has its high bit set as the end-of-padding marker. Our implementation parameterises the constructor with whichever suffix the caller wants:
export interface KeccakOpts {
/** Rate in bytes (e.g. 136 for SHA3-256, 72 for SHA3-512). */
rate: number;
/** Padding suffix byte: 0x06 for SHA3, 0x01 for original Keccak. */
suffix: number;
/** Output byte length (32 for 256-bit, 64 for 512-bit). */
outputBytes: number;
}
export function sha3_256(data: Uint8Array): Uint8Array {
return new KeccakSponge({ rate: 136, suffix: 0x06, outputBytes: 32 })
.update(data).digest();
}
export function keccak256(data: Uint8Array): Uint8Array {
return new KeccakSponge({ rate: 136, suffix: 0x01, outputBytes: 32 })
.update(data).digest();
}
Inside digest(), the line that consumes the suffix is exactly one assignment:
const block = new Uint8Array(this.rate);
block.set(this.buffer.subarray(0, this.bufLen));
block[this.bufLen] = this.suffix; // ← the entire difference
block[this.rate - 1] |= 0x80;
this.absorbBlock(block, 0);
Everything else — the 24 rounds of θ, ρ, π, χ, ι; the round constants; the 1600-bit state laid out as 25 lanes of 64 bits; the rate of 1088 bits; the final squeeze of 32 output bytes — is byte-for-byte identical. Strip the suffix parameter out of the constructor and the two algorithms collapse into one.
Why One Byte Produces Two Universes
The natural question is: how can a single byte at a single position in a single block produce two completely uncorrelated 256-bit outputs? The answer is the avalanche property of Keccak-f. The 1600-bit permutation is specifically designed so that flipping any single input bit causes roughly half the output bits to flip after just one round, and the diffusion is total within two or three rounds. By the time the final squeeze runs, the difference between absorbing a block ending in 0x06 and a block ending in 0x01 has propagated through 24 rounds. The two output states are statistically indistinguishable from "completely independent random 256-bit values." That is exactly what a hash function is supposed to do — and the reason this byte cannot be allowed to be ambiguous.
The corollary is that you cannot derive one hash from the other. There is no transform that takes SHA3-256(x) and produces Keccak-256(x) without rerunning the entire algorithm. They are not different encodings of the same hash; they are different hashes that happened to be computed by neighbouring code paths.
The Failure Modes You Will See in the Wild
The most common bug this produces, by a large margin, is the Ethereum address mismatch. Someone writing a tool that needs to compute an Ethereum address — keccak256(publicKey)[12:] — reaches for Node's built-in crypto.createHash('sha3-256'), plugs in the public key, and gets back an address that looks like a perfectly valid Ethereum address except no one has the private key to it. The bug is silent: the output is the right length, the right format, and is even a valid hex string. It is just not the address Ethereum will derive from the same public key.
The same trap shows up in Solidity testing tools that call web3.utils.sha3() (which is actually keccak256 despite the name — web3.js aliases the two), then port the same test to a non-Web3 environment using "real" SHA-3 and watch every assertion fail. Or in audit reports that say "the contract uses SHA-3" when it uses Keccak-256, which is a meaningfully different statement to a security reviewer.
Our hash generator exposes both as separate algorithms. Drop hello into the input and you can read SHA3-256 and Keccak-256 side-by-side, with the test-vector for "" baked into the unit tests so the discrepancy is verified on every commit:
sha3_256("") → a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a
keccak256("") → c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470
Same Keccak-f[1600], same rate, same capacity, same 24 rounds. One byte of padding apart. Two hashes that will never agree on any input.
Try It Yourself
The hash generator runs all nine algorithms — MD5, SHA-1, SHA-256, SHA-384, SHA-512, SHA3-256, SHA3-512, Keccak-256, and CRC-32 — against the same input simultaneously. Anything ≥100KB is offloaded to a Web Worker so the main thread does not stutter; the million-a NIST test vector (SHA-256 = cdc76e5c…2cd0) computes in well under 15 seconds in the browser.