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 →

Related concepts

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.