In computing, a hash is a value produced by a hash function and can serve as a condensed representation of input data. The value, also called a digest, is the output; the function is the algorithm that computes it. Cryptographic hashing is designed to resist specific computational attacks, but not every function called a hash has those properties.
How Hashing Produces Repeatable Values
The input is a bit string—a sequence of binary digits representing data such as a file or message—and the result depends on its entire contents. Fixed-output functions accept varying input lengths, subject to length limits, and produce an output bit string whose length is set by the selected algorithm. “Fixed” does not mean all algorithms produce the same output length.
Determinism follows from the mathematical-function model: exactly the same input, function and applicable settings produce the same output. SHAKE extendable-output functions, or XOFs, differ by supporting variable-length outputs. For repeatable comparison, the selected output length must also stay constant; different length choices can have different security implications.
Collisions and Computational Resistance
A collision occurs when two distinct inputs produce the same output. By the pigeonhole principle, collisions must exist whenever the input domain is larger than the output range. In a hypothetical two-bit-output function, only four outputs are possible: 00, 01, 10 and 11. Five distinct inputs must therefore include at least one colliding pair; this is a mathematical illustration, not a real cryptographic algorithm.
Collision resistance means that finding any such pair is computationally infeasible. Preimage resistance instead starts with a randomly chosen target output and means that finding any input that produces it is computationally infeasible. Second-preimage resistance starts with one specified input and means that finding a different input with the same output is computationally infeasible. These are cryptographic design requirements, not guarantees that collisions or corresponding inputs cannot exist.
Looking for liquidity, exploring on-ramp/off-ramp services, or seeking expert guidance?
Get startedIntegrity Checks and Their Limits
Repeatable computation makes an integrity check possible: recompute the hash of received or stored data and compare it with a reference value, using the same function and settings. Under those conditions, a mismatch demonstrates that the inputs differ. A match supports, but does not logically prove, that the data is unchanged, because collisions are possible.
For adversarial integrity checking, the reference value itself must be trustworthy. A plain hash comparison does not independently bind the data to a creator: an attacker who can replace both the data and its reference value can make the comparison pass.
Hashing, Encryption, and Authentication
- Confidentiality: Reversible encryption uses an algorithm and key to turn plaintext into ciphertext that conceals its meaning, with decryption restoring the original data. Hashing instead produces a representation, has no corresponding decryption operation and does not itself guarantee confidentiality.
- Shared-Secret Authentication: HMAC is a hash-based message-authentication mechanism using a secret key established between sender and receiver. It provides a shared-secret authentication context, not proof that a uniquely identified person created the message.
- Public-Key Verification: Digital signatures use a private key to sign and a public key to verify. Origin authentication depends on proper implementation and supporting infrastructure and policy, not merely on a successful calculation or possession of a public key.
Algorithm Choice and Security Limits
SHA-256 is a cryptographic hash algorithm in the SHA-2 family, not the name of a particular digest. Which resistance properties matter depends on the application. Neither output length nor output format alone establishes that the required resistance is adequate. MD5, for example, is not acceptable where collision resistance is required.