Hash function
A hash function maps input data of arbitrary size to fixed-size values. Used in data structures, integrity checks, and cryptography, with distinct properties and trade-offs for different applications.
Overview
A hash function is a deterministic procedure that converts arbitrary input (often called a message or key) into a fixed-size value, commonly called a hash value, hash code, digest, or checksum. In everyday computing, programs use hash functions to summarize large quantities of data so they can be stored, indexed, or compared efficiently — for example in a hash table. The output is typically represented in a compact, readable form such as a hexadecimal or alphanumeric string.
Key properties
Different applications require different properties from a hash function. Common desirable characteristics include:
- Determinism: the same input always produces the same output.
- Fixed output length: regardless of input size, the digest has a fixed number of bits or characters.
- Uniform distribution: outputs are spread evenly over the output space to avoid clustering in tables or indexes.
- Avalanche effect: a small change in input yields a large, unpredictable change in output.
- Collision resistance: it should be hard to find two different inputs that produce the same hash (important for cryptographic use).
- Preimage resistance: given a digest, it should be computationally infeasible to recover an input that produces it.
History and development
Hashing ideas date back to early computer science work on storage and retrieval; practical techniques evolved alongside programming languages and data-structure research in the mid-to-late 20th century. As digital communications and security needs grew, researchers devised cryptographic hash functions that add security-focused properties. Several widely known algorithms and families (often discussed in literature and standards) illustrate the field's evolution; some older designs are now considered insecure and have been superseded by more robust constructions.
Common uses and examples
Hash functions appear across computing and information security. Non-cryptographic hashes power hash tables, caches, bloom filters, and deduplication systems because they are fast and provide good distribution. Simple checksums and cyclic redundancy checks (CRCs) detect accidental changes during storage or transmission. Cryptographic hashes — a category used in cryptographic hash function discussions and within broader cryptography — serve in digital signatures, file integrity verification, and commitment schemes. Password storage relies on specialized, slow, salted hash algorithms (key derivation functions) to resist brute-force attacks.
Cryptographic vs non-cryptographic hashing
Not all hashes are intended to resist deliberate attack. Non-cryptographic hashes prioritize speed and uniformity; cryptographic hashes add security guarantees like collision and preimage resistance. Because collisions are theoretically unavoidable by the pigeonhole principle, cryptographic design aims to make finding collisions computationally infeasible. Practical differences also affect choice: a hashing routine for a memory table prioritizes throughput, while one used for digital signatures must be vetted for known weaknesses and chosen from current standards.
Notable facts and cautions
Several older hash algorithms that were once common are now deprecated for security use because researchers discovered practical collision or other attacks. For passwords and key derivation, simple fast hashes are inadequate — one should use algorithms explicitly designed to be slow and include a unique salt. When selecting a hash function for any critical role, consider the function's security evaluation, intended purpose, and resistance to modern attack techniques.
For further reading, consult algorithm specifications and guides from standards bodies and reputable textbooks. Useful entry points include general programming resources for hash-table usage and security-focused material for cryptographic hashing and password storage best practices.
Programming resources | Data management | Hash tables | Cryptographic hash | Cryptography | Alphanumeric representation
Related articles
Author
AlegsaOnline.com Hash function Leandro Alegsa
URL: https://en.alegsaonline.com/art/42727