SHAKE256
SHAKE256
As many bytes as you ask, 114 for an Ed448 key.
- Digest
- 512-bit · 64 bytes
- HMAC
- no key mode
- Security
- 256-bit security from 64 bytes of output up; shorter outputs give half their bits against collisions
- Used by
- Ed448, ML-KEM, ML-DSA
Sample
- hex
- 369771bb2cb9d2b04c1d54cca487e372d9f187f73f7ba3f65b95c8ee7798c527f4f3c2d55c2d46a29f2e945d469c3df27853a8735271f5cc2d9e889544357116
- base64
- Npdxuyy50rBMHVTMpIfjctnxh/c/e6P2W5XI7neYxSf088LVXC1Gop8ulF1GnD3yeFOoc1Jx9cwtnoiVRDVxFg==
Options
Access
- Create
create("shake256") - CLI
hashes shake256 'hello world' - Tryplayground with the sample above
- Kinsha256, sha384, sha512, sha224 +9
SHAKE256 doesn't stop at a fixed digest size. Ask for 114 bytes and it gives you 114. Why 114? Ed448 hashes its keys and signatures with exactly that much. ML-KEM and ML-DSA use it too. SHAKE256 is a FIPS 202 extendable output function. It shares the Keccak sponge with SHA-3 but uses different padding.
Set outputLength to a whole number of bytes from zero. The default is 64 bytes, SHAKE256's full 256-bit security. Comparing with openssl dgst? Pass -xoflen 64, it refuses to pick one for you. Shorter outputs have less collision resistance. Stick with the default unless your protocol specifies another length.
create("shake256").hash("abc").digest;
// "483366601360a8771c6863080cc4114d8db44530f8f1e1ee4f94ea37e78b5739d5a15bef186a5386c75744c0527e1faa9f8726e462a12a4feb06bd8801e751e4"
create("shake256").hash("abc", { outputLength: 114 }).options;
// { encoding: "hex", outputLength: 114 }
hashes shake256 abc --output-length 114
The default digest is the first 64 bytes of that longer output, byte for byte. Nothing gets reshuffled when you ask for more, the sponge just keeps going. Different lengths for one input aren't independent. A result reports outputLength in its options only when explicitly set.
Agent tools allow at most 1024 output bytes per call. They also limit rounds times outputLength to 64 million bytes. Library callers can choose any length. A gigabyte of SHAKE? Your call.
There's no HMAC mode, and SHAKE doesn't miss it. For direct byte functions, import shake256(bytes, length) from @agntn/hashes/keccak. The Hashing guide has more. Compare SHAKE128 and SHA3-256.