The SHAKE family of extensible-output-functions are sometimes used as e.g. a deterministic random number generator in the following pattern (with functions named per the sponge nature of Keccak):
# pseudocode
xof = xof.new()
xof.absorb(bytes)
xof.absorb(bytes)
xof.finalize() # absorb should fail now
ten_bytes_of_output = xof.squeeze(10)
another_1000_bytes = xof.squeeze(1000)
(finalize may be implicit in the first squeeze, note that you usually can't absorb, squeeze, and absorb again without keeping the pre-finalize state).
The current API of shake256 supported by both Python's own hashlib and by cryptography return the same bytes every time you call .digest(len).
References:
N.b. This relates somewhat to #2358, but that one seems more encryption-focused.
The SHAKE family of extensible-output-functions are sometimes used as e.g. a deterministic random number generator in the following pattern (with functions named per the sponge nature of Keccak):
(finalize may be implicit in the first
squeeze, note that you usually can'tabsorb,squeeze, andabsorbagain without keeping the pre-finalize state).The current API of shake256 supported by both Python's own
hashliband bycryptographyreturn the same bytes every time you call.digest(len).References:
hashlib's implementation in a streaming interface https://github.com/GiacomoPope/dilithium-py/blob/a431369cb639c2e161e2cd9ef69fdd1eef033801/shake_wrapper.pyN.b. This relates somewhat to #2358, but that one seems more encryption-focused.