How does SHAKE produce as many bytes as you need?
You can send a short seed and have both parties generate the same public matrix, saving them from having to exchange the matrix itself. If they need more coefficients as they go, they can keep reading from the same byte stream. SHAKE is an extendable-output function (XOF) that defines a reproducible byte sequence for each input and lets the caller read as many bytes as needed. ML-KEM reads candidate values from SHAKE128 output and accepts those in range as matrix coefficients. How ML-KEM works · FIPS 203
- Start at zeroInitialize all 200 state bytes to zero. SHAKE256 rate: 136 bytes; the other 64 bytes are capacity.
- Pad the inputAppend the SHAKE domain suffix, then apply pad10*1 so the input ends on a 136-byte block boundary.
- Absorb each blockXOR each padded 136-byte block into the rate, then permute the full 200-byte state after every block, including the last. Only then begin squeezing.
- Squeeze first rate blockRead bytes 0–135 from the rate: 136 output bytes.
- Squeeze the next blockPermute the full state, then read 4 bytes from the new rate. Total output: 136 + 4 = 140 bytes.
What comes after the first 32 bytes?
If you request 32 bytes and 48 bytes from SHAKE256 in separate calls with the same input, the first 32 bytes of the longer output match the shorter output. SHAKE absorbs the entire input, then advances the read position through the resulting byte sequence. With the streaming API, reading 32 bytes and then another 16 bytes from the same reader gives you those same 48 bytes.
SHAKE256 has the same 200-byte state size as SHA-3, with 136 bytes available to read at a time. If you request 140 bytes, SHAKE256 reads 136 bytes from the state left after absorption, applies the permutation to the entire state again, and reads another four bytes from the new state. During squeezing, each additional permutation makes more output available from the same input. SHA-3 absorption and permutation
What do 128 and 256 mean?
SHAKE128 has a rate of 168 bytes and a capacity of 32 bytes. For SHAKE256, those sizes are 136 bytes and 64 bytes, respectively. The number in each name gives the target security strength in bits when the output is long enough. Choose the output length separately for your application. A one-byte output, for example, has only 256 possible values. SHA3-256 and SHAKE256 share the same rate and use different domain-separation bits during absorption. FIPS 202 §6 and Appendix A, Table 4
The QuantAegis envelope takes the key and nonce from SHAKE256 output computed using a purpose-specific label, the header, and the KEM shared secret. The shared secret is what keeps the derived values confidential. When generating a matrix from a public seed, anyone can reproduce the computation. SHAKE API example · Envelope key derivation