SHA-1: Practical Collisions and What Replaced It
SHA-1 is a 160 bit hash defined in FIPS 180-4. A real collision was published in 2017 and a chosen prefix collision in 2020, so it is unfit for signatures or integrity against an adversary. Preimage resistance is intact, which is why HMAC-SHA-1 is not in the same trouble.
At a glance
- Digest size
- 160 bits
- Hex characters
- 40
- Block size
- 512 bits (64 bytes)
- Standard
- FIPS 180-4, first published as FIPS 180-1 in 1995. Deprecated by NIST for digital signatures
- Broken for collisions
- Yes. Identical prefix collision in 2017, chosen prefix collision in 2020
- Safe for password storage
- No. Use a memory-hard password hash such as Argon2id, scrypt or bcrypt
- Available in the generator
- Yes, and as HMAC-SHA-1 when a secret is supplied
In detail
SHA-1 uses the same Merkle-Damgard shape as MD5 with a wider 160 bit state and 80 rounds instead of 64. It was the default hash of the web for over a decade: TLS certificates, Git object identifiers, Subversion, and countless internal file manifests all settled on its 40 character hex output. Its retirement took roughly fifteen years from the first theoretical warning to the last browser dropping it.
The 2017 result, published as SHAttered, produced two PDF files with different visible content and one identical SHA-1 digest, at a cost of about 6,500 CPU years and 100 GPU years of computation. That is an identical prefix collision: the attacker controls both documents from the start. The 2020 result went further with a chosen prefix collision, meaning two meaningfully different starting documents can be forced to converge, at a cost then estimated in the tens of thousands of dollars. That price only falls.
As with MD5, no practical preimage attack exists. You cannot take a published SHA-1 digest and work backwards to an input. This is why HMAC-SHA-1 remains acceptable in existing protocols: HMAC's security proof rests on the compression function behaving like a pseudorandom function, not on collision resistance, so the collision results do not carry over.
Where it is wrong today: any certificate, any code signature, any document signature, any integrity check where the two sides of the comparison could come from different parties. Browsers stopped trusting SHA-1 certificates in 2017 and NIST barred it for signature generation. New designs should use SHA-256 by default and SHA3-256 where a different construction is wanted for diversity.
Git is the interesting survivor. Object names are SHA-1 digests, and the collision applies in principle, so Git added a hardened variant that detects the specific disturbance vectors used by known collision attacks and refuses such objects. Migration to SHA-256 repositories exists but is far from universal. And as always, SHA-1 is wrong for passwords: use Argon2id, scrypt or bcrypt, none of which ToolBox provides.
Examples
input: "" -> da39a3ee5e6b4b0d3255bfef95601890afd80709
input: "abc" -> a9993e364706816aba3e25717850c26c9cd0d89d40 hex characters. The digest of the empty string, da39a3ee..., shows up constantly in Git as the hash of an empty blob before content is written.
40 hex characters -> SHA-1, and nothing else in this generator
64 hex characters -> SHA-256, SHA3-256 or Keccak-256
The Verify tab guesses from length, so it returns a single
answer for 40 characters and a list for 64.Things that catch people out
- SHA-1 is vulnerable to length extension, exactly like MD5. Hashing a secret followed by a message is not authentication. Use HMAC-SHA-256.
- A 40 character hex string is not always SHA-1. Git short hashes, some UUID encodings and truncated SHA-256 values are also seen at that length in the wild, so identifying by length is a hint and not a proof.
- 'SHA1 is broken so my Git repository is insecure' overstates it. Git's use is content addressing plus a hardened collision detector, not signature verification, and the signed part of a signed commit is the commit object itself.
- Legacy protocol requirements often say SHA-1 when they mean HMAC-SHA-1. The two have very different security stories, and swapping one for the other because a scanner flagged the string 'SHA1' will break interoperability for no gain.
Try it: Hash Generator
Paste text or drop a file and get every digest at once, in hex or Base64, with a verify tab for comparing an expected value against what you actually have.
Hash Generator
LOCAL · Browser-OnlyGenerate MD5, SHA-1, SHA-256, SHA-384, SHA-512, SHA3-256, SHA3-512, Keccak-256, CRC32, and HMAC hashes from text or files
MD5 is cryptographically broken and should not be used for security purposes. Use SHA-256 or SHA-512 instead.
Related Hash algorithms
All hash algorithms →MD5: 128 Bit Digests, Broken Collisions, and Remaining Uses
MD5 produces a 32 character hex digest. Collisions have been practical since 2004, preimages have not. What that distinction rules out, and what it does not.
SHA-256: The Default Choice and How It Is Used
SHA-256 gives a 64 character hex digest with no practical collision or preimage attack. Where it belongs, where it does not, and its length extension flaw.
HMAC-SHA-1: Still Sound Even Though SHA-1 Collisions Are Not
HMAC-SHA-1 produces a 40 character tag and is not affected by the SHA-1 collision attacks. Why that is true, and where it is still deployed today.
SHA3-256: The Sponge Construction and How It Differs From SHA-256
SHA3-256 gives the same 64 hex characters as SHA-256 from a completely different construction. No length extension, different failure modes, FIPS 202.
SHA-384: Truncated SHA-512 and Why the Truncation Helps
SHA-384 is SHA-512 with a different starting state, cut to 384 bits. That truncation removes the length extension weakness. 96 hex characters explained.
SHA-512: 512 Bit Digests and 64 Bit Word Arithmetic
SHA-512 outputs 128 hex characters using 64 bit words and 1024 bit blocks. Why it can beat SHA-256 on 64 bit hardware, and where the extra width is pointless.
Tools for this
- Hash Generator Free online hash generator - generate MD5, SHA-1, SHA-256 hashes from any input text