length extension attack
An attack on hashes such as SHA-256 that lets someone who knows hash(secret + message) compute a valid hash for that message with extra data added, without the secret.
Attackers can forge valid tags for altered requests when a keyed hash is built by simple concatenation.
In more detail
It works because SHA-2 and MD5 output their full internal state, so an attacker can carry on hashing from where the original stopped. It breaks home-made message authentication codes built as sha256(secret + message), letting an attacker append parameters to an authenticated request. HMAC was designed to prevent this, and SHA-3 is not affected.
Example
sha256(secret + message) is not a MAC: length extensionRelated terms
- HMAC — A way of combining a secret key with a hash function to produce a tag that shows a message came from someone holding the key and was not changed.
- MAC — A short tag computed from a message and a secret key, which lets the receiver check the message is unchanged and came from a key holder.
- SHA-256 — A widely used hash function that turns any data into a 256-bit fingerprint, shown as 64 hexadecimal characters.
- SHA-3 — The newest family of standard hash functions from NIST, built on a different design called Keccak as a backup in case SHA-2 is ever weakened.
Taught in
- Cryptographic Hashing: SHA-256, SHA-3 & Passwords — Cybersecurity Fundamentals, GRC & Cryptography