SHAKE128
SHAKE128
The sponge that stops when you say so.
- Digest
- 256-bit · 32 bytes
- HMAC
- no key mode
- Security
- 128-bit security from 32 bytes of output up; shorter outputs give half their bits against collisions
- Used by
- ML-KEM, ML-DSA
Sample
- hex
- 3a9159f071e4dd1c8c4f968607c30942e120d8156b8b1e72e0d376e8871cb8b8
- base64
- OpFZ8HHk3RyMT5aGB8MJQuEg2BVrix5y4NN26IccuLg=
Options
Access
- Create
create("shake128") - CLI
hashes shake128 'hello world' - Tryplayground with the sample above
- Kinsha256, sha384, sha512, sha224 +9
Need a digest with a length you choose? SHAKE128 keeps squeezing until you tell it to stop. ML-KEM and ML-DSA lean on it all day. It's a FIPS 202 extendable output function. It uses the same Keccak sponge as SHA-3, with different padding. SHA3-256 is the same sponge with the length welded on.
outputLength sets the number of output bytes. It accepts any whole number from zero.
The default is 32 bytes. That's SHAKE128's full 128-bit security. Node's own default is 16, half of it, and OpenSSL 3 won't guess at all without -xoflen. Shorter output gives less collision resistance. At 16 bytes, it's 64 bits. Use the default unless you have a reason to shorten it.
create("shake128").hash("abc").digest;
// "5881092dd818bf5cf8a3ddb793fbcba74097d5c526a6d35f97b83351940f2cc8"
create("shake128").hash("abc", { outputLength: 16 }).digest;
// "5881092dd818bf5cf8a3ddb793fbcba7"
Those 16 bytes are the start of the longer output. Less output means less of the same stream, not another hash. So two lengths of one input aren't independent. Don't treat them as two keys.
The CLI flag is --output-length. Agent tools cap output at 1024 bytes per call. They also cap rounds times outputLength at 64 million bytes. Library callers can choose any length. Results report outputLength in their options only when you set it.
For bytes without the registry, import shake128(bytes, length) from @agntn/hashes/keccak. See Hashing and SHAKE256.