liveBook · Manning

Length-extension attack

A length-extension attack exploits an iterative hash construction to compute a hash for an extended message from the original hash and message length.

How 2 Manning books explain it

Hacking Cryptography

A length-extension attack computes a valid hash for an extended message from a hash of the original message and its length when the hash construction exposes a reusable internal state.

How it is used
Demonstrates how naive API authentication with secret-prefix hashing can be forged.
How deep it goes
Works through padding generation, SHA-256 state replacement, and a forged HTTP request using OpenSSL.
Examples
Uses a SHA-256-signed bank transaction, extending amount=10 into a forged amount=424242 request.
What you can do after
Diagnose/debug with it by recognizing forgeable secret-prefix MAC authentication and selecting HMAC or sponge-based hashes.

Read how Hacking Cryptography explains length-extension attack →

Real-World Cryptography

A length-extension attack is an attack that exploits iterative hash constructions to compute a hash for an extended message when given a hash of an original message and its length.

How it is used
Explains why SHA-2 cannot safely authenticate secret-prefixed messages such as cookies.
How deep it goes
Works through digest continuation, padding, and appended data, but stops short of implementation details.
Examples
Uses a user=bob cookie extended with &admin=true and illustrates successful digest reuse.
What you can do after
Evaluate whether secret-prefixed SHA-2 authentication is vulnerable and avoid using it as a homemade MAC.

Read how Real-World Cryptography explains length-extension attack →

What to know first

Related concepts

Questions about length-extension attack

What is length-extension attack?

A length-extension attack exploits an iterative hash construction to compute a hash for an extended message from the original hash and message length.

Which Manning books explain length-extension attack?

Hacking Cryptography and Real-World Cryptography.

What should I know before learning length-extension attack?

Manning books that teach length-extension attack usually introduce hash function, Merkle–Damgård construction, SHA-2 and SHA-256 first.

What is the difference between length-extension attack and HMAC?

A length-extension attack exploits an iterative hash construction to compute a hash for an extended message from the original hash and message length. HMAC is a message authentication code constructed from a cryptographic hash function and a shared secret key to verify a message’s integrity and authenticity.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.