Skip to Content
oxcrypto

Extendable-output functions

Generate a digest with a length chosen by the caller.

Choose an algorithm and pass the output length in bytes. Use digest for one byte string or digest_chunks for an iterable of byte chunks.

Incremental use

Every selector also has new(...), which takes the same keyword options as digest and returns an XofHasher:

from oxcrypto.xof.shake import SHAKE

hasher = SHAKE.SHAKE256.new()
hasher.update(b"hel")
hasher.update(b"lo")
reader = hasher.finalize()
assert reader.read(16) + reader.read(16) == SHAKE.SHAKE256.digest(b"hello", 32)
  • update(data) absorbs more bytes.
  • copy() returns an independent hasher with the same absorbed input.
  • reset() discards the input and keeps the options given to new.
  • finalize() returns an XofReader and leaves the hasher usable, so later update calls continue from the same state.
  • XofReader.read(n) returns the next n output bytes.

Both objects can be shared between threads but are not meant for concurrent use.

Algorithms

  • SHAKE provides SHAKE128 and SHAKE256.
  • Ascon-XOF128 and Ascon-CXOF128 Generate digest bytes with the Ascon XOFs from NIST SP 800-232.
  • Bash programmable hash Generate digest bytes for protocols using Bash programmable hashing.
  • cSHAKE Generate custom-domain digests with cSHAKE128 or cSHAKE256.
  • KangarooTwelve Generate digest bytes with the KT128 and KT256 tree hashes.
  • TupleHash Hash a sequence of byte strings with TupleHash or TupleHashXOF.
  • TurboSHAKE Generate digest bytes with TurboSHAKE128 or TurboSHAKE256 and a chosen domain separation byte.

On this page