← Hash function

Compare versions

Version 1 → Version 2 (current). Removed · Added. This shows the entry's text as it is written, including its formatting marks.

Version 1 · Version 2 (current) · Version history

Side by side · Together

A hash function is a function that turns data of any length into a short, fixed-length value, designed so that the value works as a digital fingerprint of the data.[6] ## What a hash function does NIST's glossary gives the core definition as a function on bit strings in which the length of the output is fixed.[6] The standards that NIST approves for security use take a message of nearly any size and produce a condensed representation called a message digest.[1] The output is also called a hash or hash value. A cryptographic hash function is one that is built to resist attack, and NIST's glossary lists the properties expected of an approved one:[6] - **One-way (preimage resistance):** it is computationally infeasible to find an input that maps to a new, pre-specified output.[6] - **Collision-resistant:** it is computationally infeasible to find two different inputs that map to the same output.[6] A further property, second-preimage resistance, appears in NIST's definitions of approved hash functions alongside the other two.[6] The use that gives hashing its place in security follows from these properties. The Secure Hash Standard states that any change to a message will, with very high probability, produce a different message digest, which lets a receiver determine whether the message's integrity has been preserved.[1] The same standard names digital signatures, message authentication codes and the generation of random numbers or bits as uses of that property.[1] ## The SHA families NIST specifies its approved hash algorithms in two standards.[3] **FIPS 180-4, the Secure Hash Standard** (August 2015) covers SHA-1 and the SHA-2 family: SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224 and SHA-512/256.[1][3] The standard describes each algorithm in two stages: preprocessing, which pads the message and splits it into fixed-size blocks, and hash computation, which works through those blocks to produce the digest.[1] The algorithms differ in digest size and in block and word size, as the standard's table shows:[1] | Algorithm | Block size (bits) | Word size (bits) | Digest size (bits) | |---|---|---|---| | SHA-1 | 512 | 32 | 160 | | SHA-224 | 512 | 32 | 224 | | SHA-256 | 512 | 32 | 256 | | SHA-384 | 1024 | 64 | 384 | | SHA-512 | 1024 | 64 | 512 | | SHA-512/224 | 1024 | 64 | 224 | | SHA-512/256 | 1024 | 64 | 256 | The standard says the algorithms differ most in the security strength they provide for the data being hashed.[1] **FIPS 202, the SHA-3 Standard** was also released in August 2015. It specifies the SHA-3 family, based on the KECCAK algorithm that NIST selected in its SHA-3 Cryptographic Hash Algorithm Competition.[4] The family has four hash functions (SHA3-224, SHA3-256, SHA3-384 and SHA3-512) and two extendable-output functions, SHAKE128 and SHAKE256, and the standard supplements SHA-1 and SHA-2 rather than replacing them.[4] As of September 2026, NIST's page states that only the four fixed-length SHA-3 algorithms are approved as hash algorithms, and that the extendable-output functions can be used as hash functions subject to additional security considerations.[3] ## When a hash function is broken: SHA-1 Collision resistance can fail. NIST deprecated SHA-1 in 2011 and disallowed it for digital signatures at the end of 2013, and in December 2022 published a plan to transition away from its remaining limited use.[3] On 23 February 2017, researchers at CWI Amsterdam and Google announced the first real SHA-1 collision, which they called SHAttered: two visibly different PDF files with the same SHA-1 value, while their SHA-256 values differ.[5] They put the cost at about nine quintillion SHA-1 computations, roughly 6,500 CPU-years and 110 GPU-years, and said it was thousands of times faster than brute force and expected to become cheaper over time.[5] A later result removed the remaining practical doubt. In 2020 Gaëtan Leurent and Thomas Peyrin announced the first chosen-prefix collision for SHA-1, in which an attacker can choose two different starting texts and then find suffixes that make the two full messages collide.[7] They estimated the attack cost about 75,000 US dollars to run and put the cost of a classical SHA-1 collision at about 11,000 US dollars.[7] To show the effect they built two PGP keys with colliding SHA-1 certifications, and the issue was tracked as CVE-2019-14855 and addressed in GnuPG 2.2.18 by treating SHA-1 identity signatures created after 19 January 2019 as invalid.[7] ## Hash functions in Bitcoin ![A diagram of a Merkle tree, in which leaf blocks are hashed and the hashes are combined pairwise up to a single root hash.](/m/2026/12/hjB9rRLgPhNgL7eH.png) *Via Wikimedia Commons: [Hash Tree](https://commons.wikimedia.org/wiki/File:Hash_Tree.svg) by Azaghal, [CC0](http://creativecommons.org/publicdomain/zero/1.0/deed.en).* Bitcoin's design paper uses hashing in three places. - **Proof of work.** The paper's [proof-of-work](/t/3595/proof-of-work) scans for a value that, when hashed, "such as with SHA-256", gives a hash that begins with a required number of zero bits.[2] The average work needed grows exponentially with the number of zero bits, yet it can be verified by executing a single hash.[2] A block's proof is found by incrementing a nonce in the block until its hash has the required zero bits, after which the block cannot be changed without redoing the work.[2] How hard the target is set is covered in [Mining difficulty](/t/3607/mining-difficulty) and the network's total rate of hashing in [Hash rate](/t/3800/hash-rate). - **Chaining.** Each timestamp includes the previous timestamp in its hash, forming a chain, and each block carries the hash of the previous one; this is the structure described in [Blockchain](/t/3610/blockchain).[2] - **Merkle trees.** To let old blocks be compacted without breaking a block's hash, the paper hashes transactions in a Merkle tree and includes only its root in the block's hash.[2] The paper also describes ownership as a chain of digital signatures, each made over a hash of the previous transaction and the next owner's public key.[2] See [Bitcoin](/t/1497/bitcoin) for the wider system. ## Password storage A system that checks passwords should not keep them in readable form. The OWASP Password Storage Cheat Sheet says passwords should never be stored in plain text, and that because a hash is a one-way function, an attacker who obtains a hashed password cannot use it to log in as the victim.[8] It defines a salt as a unique, randomly generated string added to each password as part of the hashing process.[8] The same guidance warns that fast hashing algorithms such as SHA-256 are not suitable for password storage, because algorithms such as MD5 and SHA-1 were designed to be fast.[8] It instead ranks purpose-built password hashes: Argon2id first, scrypt where Argon2id is unavailable, bcrypt for legacy systems, and PBKDF2 where FIPS-140 compliance is required.[8] Its stated minimums are, for Argon2id, 19 MiB of memory, an iteration count of 2 and one degree of parallelism, and, for PBKDF2 with HMAC-SHA-256, a work factor of 600,000 or more.[8] The page shows no date, so these figures should be checked against the current version of the cheat sheet.[8] ## Sources 1. [Secure Hash Standard (SHS), FIPS PUB 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf), National Institute of Standards and Technology, August 2015. 2. [Bitcoin: A Peer-to-Peer Electronic Cash System](https://bitcoin.org/bitcoin.pdf), Satoshi Nakamoto, bitcoin.org. 3. [Hash Functions](https://csrc.nist.gov/projects/hash-functions), NIST Computer Security Resource Center, page updated 16 September 2026. 4. [SHA-3 Standard: Permutation-Based Hash and Extendable-Output Functions, FIPS 202](https://csrc.nist.gov/pubs/fips/202/final), NIST, August 2015. 5. [The first collision for full SHA-1 (SHAttered)](https://shattered.io/), CWI Amsterdam and Google, 23 February 2017. 6. ["Hash function"](https://csrc.nist.gov/glossary/term/hash_function) and ["Collision resistance"](https://csrc.nist.gov/glossary/term/collision_resistance), NIST Computer Security Resource Center glossary, accessed 3 December 2026. 7. [SHA-1 is a Shambles: first chosen-prefix collision on SHA-1](https://sha-mbles.github.io/), Gaëtan Leurent and Thomas Peyrin, 2020 (IACR ePrint 2020/014). 8. [Password Storage Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html), OWASP Cheat Sheet Series, undated, accessed 3 December 2026.