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.

SHA3_256Hasher and SHA3_512Hasher provide salted SHA-3 digests using Python’s stdlib hashlib. Both classes inherit from the internal SHA3Hasher base, which implements the Template Method pattern for hashing and verification. A random salt is generated at hash time and embedded in the output string, ensuring that two calls with the same input produce different hashes. No third-party packages are required.
SHA-3 is a cryptographic digest algorithm, not a password hasher. Because SHA-3 is designed to be fast, an attacker with access to the hash database can perform brute-force attacks at very high speed. For password storage, use a memory-hard algorithm such as Argon2Hasher or ScryptHasher.

Import

from hash_forge.hashers import SHA3_256Hasher, SHA3_512Hasher
No extra dependencies are required — SHA-3 is part of Python’s stdlib hashlib.

SHA3_256Hasher

Produces a 256-bit (32-byte) SHA-3 digest.
algorithm = 'sha3_256'

Constructor

SHA3_256Hasher(salt_length: int = 16)
salt_length
int
default:"16"
Number of random bytes used to generate the salt. The salt is hex-encoded and embedded in the hash string alongside the digest.

Hash format

sha3_256$<salt>$<hex_digest>
<salt> is a hex-encoded random byte sequence generated freshly on every hash() call.

Methods

hash(string: str) -> str

Generates a random salt, appends it to the input before hashing, and returns the hash in the canonical sha3_256$<salt>$<hex> format.

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

Parses the salt from hashed_string, re-derives the SHA3-256 digest using the same salt, and compares with hmac.compare_digest to prevent timing attacks.

needs_rehash(hashed_string: str) -> bool

Always returns False. SHA-3 hashers have no tunable cost parameters, so there is no configuration drift to detect.

SHA3_512Hasher

Produces a 512-bit (64-byte) SHA-3 digest. Identical in behaviour to SHA3_256Hasher but uses the SHA3-512 digest function.
algorithm = 'sha3_512'

Constructor

SHA3_512Hasher(salt_length: int = 16)
salt_length
int
default:"16"
Number of random bytes used to generate the salt. The salt is hex-encoded and embedded in the hash string.

Hash format

sha3_512$<salt>$<hex_digest>

Methods

hash(string: str) -> str

Generates a random salt and returns the SHA3-512 hash in sha3_512$<salt>$<hex> format.

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

Re-derives the SHA3-512 digest using the stored salt and compares the result in constant time.

needs_rehash(hashed_string: str) -> bool

Always returns False.

Base class

Both hashers subclass the internal SHA3Hasher base class, which uses the Template Method pattern. SHA3Hasher implements hash, verify, and needs_rehash in terms of four abstract hooks — _do_hash, _parse_hash, _do_verify, and _check_needs_rehash — that concrete subclasses fill in by setting algorithm and _digest_name class variables. You do not need to interact with SHA3Hasher directly.

Code example

from hash_forge.hashers import SHA3_256Hasher, SHA3_512Hasher

# SHA3-256
hasher_256 = SHA3_256Hasher()
hashed = hasher_256.hash("my_data")
assert hasher_256.verify("my_data", hashed)
assert hasher_256.needs_rehash(hashed) == False

# Two hashes of the same input differ (random salt)
hashed2 = hasher_256.hash("my_data")
assert hashed != hashed2

# SHA3-512
hasher_512 = SHA3_512Hasher()
hashed_512 = hasher_512.hash("my_data")
assert hasher_512.verify("my_data", hashed_512)

Build docs developers (and LLMs) love