vfhe.crypto.hash¶
BLAKE3 hashing: digest of a byte string and the chain DigestChain.
Every digest is DIGEST_LEN bytes. DigestChain accumulates
h_i = H(h_{i-1} | part_i) from a fixed seed. How a value of another type
becomes bytes, and how types are kept apart, is the caller’s encoding.
>>> from vfhe.crypto.hash import DigestChain, digest
>>> digest(b"").hex()[:8]
'af1349b9'
>>> DigestChain([b"a", b"b"]).digest() == DigestChain().absorb(b"a").absorb(b"b").digest()
True
- class vfhe.crypto.hash.DigestChain(parts: Iterable[Bytes] = ())¶
Accumulates the chain
h_i = H(h_{i-1} | part_i)from a fixed seed, in native memory.The BCS sigma-chain [BCS16] over already-digested parts:
h_0isH("vfhe.chain")and each part replaces the state by the digest of the state followed by the part, so a sequence can cache the state after a prefix and extend it.absorbtakes one part of any length;absorb_packedtakes digests laid out end to end, in one native call. Both return the chain, so calls read in sequence;DigestChain(parts).digest()is the chain ofpartsin one expression. A chain belongs to one thread at a time.Starts the chain at the seed and absorbs
partsin order.- Parameters:
parts – Byte strings of any length, absorbed one by one.
- absorb(part: bytes | bytearray | memoryview) DigestChain¶
Absorbs one part.
- Parameters:
part – Bytes of any length.
- Returns:
This chain, advanced.
- absorb_packed(digests: bytes | bytearray | memoryview) DigestChain¶
Absorbs digests packed end to end, each as one part, in one native call.
- Parameters:
digests – A whole number of
DIGEST_LEN-byte digests, in order.- Returns:
This chain, advanced once per digest.
- Raises:
ValueError – The length of
digestsis no multiple ofDIGEST_LEN.
- digest() bytes¶
Reads the state: the digest of every part absorbed so far.
- Returns:
The
DIGEST_LEN-byte state; the seed when nothing was absorbed.
- vfhe.crypto.hash.digest(data: bytes | bytearray | memoryview) bytes¶
Computes the BLAKE3 digest of a byte string. Thread-safe, no state.
- Parameters:
data – The bytes to hash, any length; a memoryview of any shape is read as its bytes.
- Returns:
The
DIGEST_LEN-byte digest.