Overview
Thehash module provides hashing functions for strings and data, including cryptographic algorithms (MD5, SHA family, BLAKE2), HMACs, and fast non-cryptographic hashes for caching and hash tables.
Total functions: 25+
Cryptographic hashes
Secure hashing algorithms suitable for passwords, signatures, and integrity verification.hash::md5
hash::md5
Compute MD5 hash of string.Requires:
md5sum (Linux) or md5 (macOS)hash::sha1
hash::sha1
Compute SHA-1 hash of string.Requires:
sha1sum, shasum, or opensslhash::sha256
hash::sha256
Compute SHA-256 hash of string.Requires:
sha256sum, shasum, or opensslThis is the recommended algorithm for most security purposes.hash::sha512
hash::sha512
Compute SHA-512 hash of string.Requires:
sha512sum, shasum, or opensslProvides higher security margin than SHA-256.hash::sha3_256
hash::sha3_256
Compute SHA-3 (Keccak) 256-bit hash.Requires:
openssl with SHA-3 support (OpenSSL 1.1.1+)SHA-3 is the latest SHA family member with different internal design.hash::blake2b
hash::blake2b
Compute BLAKE2b hash (512-bit).Requires:
b2sum or openssl with BLAKE2 supportBLAKE2 is faster than MD5 while being cryptographically secure.HMAC (keyed hashing)
Hash-based Message Authentication Codes for verifying authenticity and integrity.hash::hmac::sha256
hash::hmac::sha256
Compute HMAC-SHA256.Parameters:
key- Secret key for HMACmessage- Data to authenticate
opensslUsed for API signatures, JWT tokens, webhook verification.hash::hmac::sha512
hash::hmac::sha512
Compute HMAC-SHA512.Requires:
opensslStronger variant of HMAC-SHA256.hash::hmac::md5
hash::hmac::md5
Compute HMAC-MD5.Requires:
opensslNon-cryptographic hashes
Fast, pure Bash hashing functions for hash tables, caching, and data structures. Not suitable for security.hash::djb2
hash::djb2
DJB2 hash (Daniel J. Bernstein).Classic, fast hash. Good general-purpose choice for hash tables.Pure Bash - No external dependencies
hash::djb2a
hash::djb2a
DJB2a hash (XOR variant).Slightly better distribution than DJB2 for certain inputs.Pure Bash
hash::sdbm
hash::sdbm
SDBM hash (from SDBM database).Often outperforms DJB2 for database keys.Pure Bash
hash::fnv1a32
hash::fnv1a32
FNV-1a 32-bit hash (Fowler-Noll-Vo).Excellent avalanche properties, widely used in hash tables.Pure Bash
hash::fnv1a64
hash::fnv1a64
FNV-1a 64-bit hash.Better for longer strings due to larger state.Pure Bash
hash::adler32
hash::adler32
Adler-32 checksum (used in zlib/PNG).Fast integrity checksum, not a true hash function.Pure Bash
hash::crc32
hash::crc32
CRC32 checksum.Requires:
crc32, python3, or cksumWhen using
cksum, algorithm differs slightly from standard CRC32.hash::murmur2
hash::murmur2
MurmurHash2 with optional seed.Parameters:
string- Data to hashseed- Optional seed value (default: 0)
Utility functions
Higher-level helpers for common hashing tasks.hash::verify
hash::verify
Verify string matches expected hash.Parameters:
string- Data to hashexpected_hash- Expected hash valuealgorithm- Hash function name (default: sha256)
hash::slot
hash::slot
Map value to bucket using consistent hashing.Parameters:
n_buckets- Number of buckets (0 to n-1)value- Value to hash
hash::short
hash::short
Generate short hash (truncated SHA-256).Parameters:
string- Data to hashlength- Number of characters (default: 8)
hash::combine
hash::combine
Hash multiple values into single hash.Parameters: Multiple values to combineUseful for cache keys from multiple inputs:
hash::equal
hash::equal
Check if two strings have the same hash.Parameters:
string1- First stringstring2- Second stringalgorithm- Hash function (default: sha256)
hash::uuid5
hash::uuid5
Generate UUID v5 (name-based, SHA-1).Parameters:
namespace- UUID namespace or domain stringname- Name to hash
python3 or uuidgenUnlike UUID v4, generates same UUID for same inputs (deterministic).Performance comparison
Non-cryptographic (fastest to slowest)
- DJB2/DJB2a - Simplest, very fast
- SDBM - Good for database keys
- FNV-1a - Best distribution
- Adler-32 - Fast checksum
- MurmurHash2 - Good balance
Cryptographic (fastest to slowest)
- BLAKE2 - Faster than MD5, secure
- SHA-256 - Industry standard
- SHA-512 - Higher security
- SHA-3 - Newest standard