-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Milestone
Description
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:
- This small class turns
hashlib
's implementation in a streaming interface https://github.com/GiacomoPope/dilithium-py/blob/a431369cb639c2e161e2cd9ef69fdd1eef033801/shake_wrapper.py - Raccoon (post-quantum signature scheme) uses Shake256 as a deterministic random number generator: https://github.com/masksign/raccoon/blob/72a5cf077e5f0a898a453ba84d778c550cd0a203/ref-py/racc_core.py#L334-L340
- Cryptodome does support XOF streaming https://www.pycryptodome.org/src/hash/hash#extensible-output-functions-xof
- RFC, DO NOT MERGE AS-IS: Streaming shake implementation openssl/openssl#7921
N.b. This relates somewhat to #2358, but that one seems more encryption-focused.
DavidBuchanan314
Metadata
Metadata
Assignees
Labels
No labels