The Secure Hash Algorithm (SHA) is a family of cryptographic hash functions published by the US National Institute of Standards and Technology (NIST) as federal information processing standards. Each function takes an input of almost any length and produces a fixed-length output, called a digest or hash, that acts as a compact fingerprint of the data. SHA functions are used to check that files and messages have not been altered, inside digital signatures and message authentication codes, and in many blockchains, most famously Bitcoin, which relies on SHA-256.
The family has four generations: SHA-0, SHA-1, SHA-2 and SHA-3. The first three were designed by the US National Security Agency and share a similar internal structure. SHA-3 is based on a different design, Keccak, chosen through a public competition. SHA-1 is now considered broken for collision resistance and is being retired, while SHA-2 and SHA-3 remain approved for government and commercial use.
History of the SHA family
NIST published the original algorithm in 1993. It was withdrawn soon afterwards because of an undisclosed weakness and replaced in 1995 by SHA-1, which produces a 160-bit digest; the withdrawn version became known as SHA-0. SHA-1 spread widely through security protocols, software distribution and version-control systems. The SHA-2 family followed in 2001, offering digests of 224, 256, 384 and 512 bits.
Research in the mid-2000s showed theoretical shortcuts for finding SHA-1 collisions, and in 2007 NIST opened a competition for a new standard. Keccak, designed by a team of European cryptographers, won in 2012 and was published as SHA-3 in 2015. In 2017 researchers from Google and the CWI institute in Amsterdam produced the first practical SHA-1 collision: two different PDF files with the same digest.
How a SHA function works
SHA-1 and SHA-2 use the Merkle–Damgård construction. The message is padded and split into fixed-size blocks, and a compression function mixes each block into an internal state through many rounds of bitwise operations, modular additions and rotations; the final state is the digest. This design allows so-called length-extension tricks, which is why SHA-2 is normally wrapped in a keyed construction when used for authentication. SHA-3 uses a sponge construction instead, absorbing the input into a large internal state and then squeezing out the output, and it is not exposed to length extension.
A secure hash function must meet three properties:
- Preimage resistance. Given a digest, it should be infeasible to find any input that produces it.
- Second-preimage resistance. Given one input, it should be infeasible to find a different input with the same digest.
- Collision resistance. It should be infeasible to find any two inputs that share a digest.
Because of the birthday paradox, a generic search for a collision needs roughly:
where is the number of hash evaluations and is the digest length in bits. For SHA-256, , so ; for SHA-1, , so . The 2017 attack needed about SHA-1 computations, roughly , or about 131,000, times fewer than the generic bound, which is why it counted as a practical break.
SHA in Bitcoin and other blockchains
Bitcoin applies SHA-256 twice in succession to compute block hashes and transaction identifiers. Proof-of-work mining consists of hashing a block header again and again with different nonce values until the result falls below a difficulty target, and the demand for this work created a market for specialised ASIC miners. Bitcoin addresses derived from public keys combine SHA-256 with a second function, RIPEMD-160, and Merkle trees of transaction hashes let lightweight wallets confirm that a transaction is included in a block.
The Ethereum blockchain uses Keccak-256, the version of Keccak submitted to the competition before NIST adjusted its padding rule. As a result, an Ethereum hash differs from the standard SHA3-256 output for the same input, a detail that matters to developers moving data between systems.
Current status and use
NIST has deprecated SHA-1 for digital signatures and has announced that it will be phased out entirely by 2030. SHA-2, especially SHA-256, is the default in Transport Layer Security (TLS) certificates, code signing and public-key infrastructure, and banks and payment networks run it inside hardware security modules. Plain SHA functions are too fast for storing passwords; password systems add a salt and use deliberately slow functions such as scrypt. SHA-3 is less widely deployed but offers a structurally different fallback should weaknesses appear in SHA-2. Quantum computers are expected to weaken hash functions far less than they weaken public-key schemes such as RSA and ECDSA.
External links
Ref 1300000346