Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Zozi96/hash-forge/llms.txt

Use this file to discover all available pages before exploring further.

Blake2Hasher and Blake3Hasher provide fast cryptographic hash digests using the BLAKE2b and BLAKE3 algorithms respectively. Both are designed for data integrity, checksums, and general-purpose cryptographic hashing — not for password storage. They produce deterministic output for a given input and have no built-in work factor, making them unsuitable as password hashers.
BLAKE2 and BLAKE3 are cryptographic digest algorithms, not password hashers. They are fast by design, which means an attacker with access to a hash database can perform brute-force or dictionary attacks extremely quickly. For password storage, use a memory-hard hasher such as Argon2Hasher or ScryptHasher.

Blake2Hasher

A hasher backed by Python’s stdlib hashlib.blake2b. No additional dependencies are required.
algorithm = 'blake2'
legacy_algorithm = 'blake2b'

Import

from hash_forge.hashers import Blake2Hasher

Constructor

Blake2Hasher(key: str = "", digest_size: int = 64)
key
str
default:"\"\""
An optional key for BLAKE2b’s keyed-hashing mode. When provided, the hash is an HMAC-like keyed digest. Pass an empty string (the default) for plain, un-keyed hashing.
digest_size
int
default:"64"
Size of the BLAKE2b digest in bytes. Valid range is 1–64. The value is embedded in the hash string and checked during verification and rehash detection.

Hash format

blake2$<digest_size>$<hex_digest>

Methods

hash(string: str) -> str

Computes the BLAKE2b digest of string and returns it in the canonical blake2$<digest_size>$<hex> format.

verify(string: str, hashed_string: str) -> bool

Re-computes the BLAKE2b digest using the digest_size stored in hashed_string and compares with hmac.compare_digest. Accepts both blake2$ and blake2b$ prefixes for backward compatibility.

needs_rehash(hashed_string: str) -> bool

Returns True when the digest_size embedded in hashed_string differs from the current digest_size, or when the prefix is the legacy blake2b token instead of the canonical blake2 token.

can_handle(hashed_string: str) -> bool

Returns True if hashed_string starts with either blake2$ or blake2b$, allowing the hasher to accept hashes produced under either prefix.

Blake3Hasher

A hasher backed by the blake3 Python package. BLAKE3 is a modern cryptographic hash function that is faster than BLAKE2 on modern hardware and parallelises across CPU cores.
algorithm = 'blake3'

Installation

pip install "hash-forge[blake3]"

Import

from hash_forge.hashers import Blake3Hasher

Constructor

Blake3Hasher()
Blake3Hasher has no configurable parameters. The output size is fixed by the blake3 library’s defaults.

Hash format

blake3$<hex_digest>

Methods

hash(string: str) -> str

Computes the BLAKE3 digest of string and returns it in blake3$<hex> format.

verify(string: str, hashed_string: str) -> bool

Re-computes the BLAKE3 digest and compares using hmac.compare_digest. Returns False if the prefix does not match blake3.

needs_rehash(hashed_string: str) -> bool

Returns True only if the algorithm prefix in hashed_string is not blake3. BLAKE3 has no tunable cost parameters, so the only reason to rehash is an algorithm mismatch.

Code examples

from hash_forge.hashers import Blake2Hasher

# Default 64-byte digest
hasher = Blake2Hasher()
hashed = hasher.hash("important_data")
assert hasher.verify("important_data", hashed)
assert hasher.needs_rehash(hashed) == False

# Smaller digest — needs_rehash detects the mismatch
small = Blake2Hasher(digest_size=32)
small_hash = small.hash("important_data")
assert hasher.needs_rehash(small_hash) == True

# Keyed hashing mode
keyed = Blake2Hasher(key="my_secret_key", digest_size=64)
keyed_hash = keyed.hash("important_data")
assert keyed.verify("important_data", keyed_hash)
from hash_forge.hashers import Blake3Hasher

hasher = Blake3Hasher()
hashed = hasher.hash("important_data")
assert hasher.verify("important_data", hashed)
assert hasher.needs_rehash(hashed) == False

Build docs developers (and LLMs) love