A from-scratch implementation of the SHA-3 hash function family in Java, following the FIPS 202 standard.
SHA-3 is based on the Keccak sponge construction, which applies a permutation function (Keccak-p) to absorb the input and squeeze out the digest. This implementation covers all four standardized variants:
| Variant | Digest size | Capacity |
|---|---|---|
| SHA3-224 | 224 bits | 448 bits |
| SHA3-256 | 256 bits | 512 bits |
| SHA3-384 | 384 bits | 768 bits |
| SHA3-512 | 512 bits | 1024 bits |
The Keccak-p permutation is built from five step mappings applied each round:
- θ (Theta) — XORs each bit with the parity of two columns
- ρ (Rho) — rotates each lane by a fixed offset
- π (Pi) — rearranges the positions of the lanes
- χ (Chi) — applies a non-linear function to each row
- ι (Iota) — XORs lane (0,0) with a round constant
javac Sha3.java && java -cp . Sha3All methods take and return binary strings (sequences of '0' and '1'). Use the provided HexToBin and BinToHex helpers to convert to/from hex.
String input = Sha3.HexToBin("A3A3A3...");
String digest = Sha3.BinToHex(Sha3.SHA3_256(input));The test() method verifies the implementation against the official NIST test vectors from FIPS 202, including:
- Empty input
- 1600-bit input (
A3repeated 200 times)
Run the main class to execute all tests. Expected output is true for each variant.