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 extension

Related terms

Taught in

References