.. index:: single: hash_state_protocol .. _hash_state_protocol/0: .. rst-class:: right **protocol** ``hash_state_protocol`` ======================= Protocol for genuine incremental hashing via an opaque caller-driven state. Retained state is bounded independently of total message length. Leftover buffers are smaller than one block or rate, except BLAKE2 may retain one full final block. Processing may allocate temporary lists proportional to the current chunk. Callers must release processed chunks and old states to obtain bounded retained memory. | **Availability:** | ``logtalk_load(hashes(loader))`` | **Author:** Paulo Moura | **Version:** 1:1:0 | **Date:** 2026-10-12 | **Compilation flags:** | ``static`` | **Extends:** | ``public`` :ref:`hash_protocol ` | **Remarks:** | (none) | **Inherited public predicates:** |  :ref:`hash_protocol/0::hash/2`   .. contents:: :local: :backlinks: top Public predicates ----------------- .. index:: new_hash_state/1 .. _hash_state_protocol/0::new_hash_state/1: ``new_hash_state/1`` ^^^^^^^^^^^^^^^^^^^^ Creates a fresh hashing state, equivalent to having hashed the empty message so far. The state is an opaque, algorithm-specific term; callers should only pass it to update_hash_state/3 and final_hash_state/2, never inspect or construct it directly. | **Compilation flags:** | ``static`` | **Template:** | ``new_hash_state(State)`` | **Mode and number of proofs:** | ``new_hash_state(--nonvar)`` - ``one_or_error`` | **Exceptions:** | The key, digest size, or output length is not sufficiently instantiated:: | ``instantiation_error`` | The digest size is invalid for BLAKE2:: | ``domain_error(blake2_digest_size,DigestSize)`` | The key is ground but invalid for BLAKE2:: | ``domain_error(blake2_key,Key)`` | The key is ground but not a list of 16 bytes for SipHash:: | ``domain_error(siphash_key,Key)`` | The output length is ground but not a nonnegative integer for SHAKE:: | ``domain_error(shake_output_size,OutputBytes)`` ------------ .. index:: update_hash_state/3 .. _hash_state_protocol/0::update_hash_state/3: ``update_hash_state/3`` ^^^^^^^^^^^^^^^^^^^^^^^ Folds one chunk of bytes into a hashing state, returning the updated state. Can be called repeatedly, once per chunk, to fold in an arbitrarily long message without ever holding more than one chunk and the (bounded-size) state in memory at the same time. The chunks do not need to be the same length, and the empty chunk is allowed and is a no-op. | **Compilation flags:** | ``static`` | **Template:** | ``update_hash_state(State,Bytes,NewState)`` | **Mode and number of proofs:** | ``update_hash_state(+nonvar,+list(byte),--nonvar)`` - ``one`` ------------ .. index:: final_hash_state/2 .. _hash_state_protocol/0::final_hash_state/2: ``final_hash_state/2`` ^^^^^^^^^^^^^^^^^^^^^^ Finalizes a hashing state and returns the resulting hash, in the same representation as hash/2. The state must not be reused after finalization. | **Compilation flags:** | ``static`` | **Template:** | ``final_hash_state(State,Hash)`` | **Mode and number of proofs:** | ``final_hash_state(+nonvar,--atom)`` - ``one_or_error`` | **Exceptions:** | The key, digest size, or output length is not sufficiently instantiated:: | ``instantiation_error`` | The digest size is invalid for BLAKE2:: | ``domain_error(blake2_digest_size,DigestSize)`` | The key is ground but invalid for BLAKE2:: | ``domain_error(blake2_key,Key)`` | The key is ground but not a list of 16 bytes for SipHash:: | ``domain_error(siphash_key,Key)`` | The output length is ground but not a nonnegative integer for SHAKE:: | ``domain_error(shake_output_size,OutputBytes)`` ------------ Protected predicates -------------------- (no local declarations; see entity ancestors if any) Private predicates ------------------ (no local declarations; see entity ancestors if any) Operators --------- (none)