Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

A lot of hash functions, including the SHA-2 family(but not the SHA-3 candidates and SHA256d) are vulnerable to length extension attacks. But when is this property a problem?

I guess certain naive MAC implementations might have issues. Are there also some situations where length-extensions cause problems for unkeyed hashes?

share|improve this question

The archetypal situation where the length-extension property becomes problematic is when ones builds a Message Authentication Code from a hash function as $$BadMAC(K,M)=Hash(K||M)$$ where $K||M$ is the concatenation of the Key and the Message.

The length extension property then translates directly into the capability to forge a different message, starting as the original, for which computing the $BadMAC$ is trivial.

In practice, that could allow adding an appendix to a text protected by $BadMAC$ (after a short rash of garbage in most cases, but often it could be invisible when printed). Also, that could allow extending the size of a short signed message so that it creates a buffer overflow after its integrity is checked using $BadMAC$.

HMAC is secure against that; and then more.

The length extension property obviously allows to obtain many more hash collisions from a single one.

If SHA-1 was experimentally broken with just one collision found (due to the high cost of the attack), the collision property would make that one-time attack a more immediately damaging issue.

That's especially true if the collision was devised so that the colliding messages (of same length) start with an appropriate code header (which likely requires no more work than any other collision): it would be possible to generate, at low computational cost, two programs with the same SHA-1 but any two different behavior.

Another (artificial) example could be when it is asked the hash of increasingly long messages (with precisely the wrong content) as a Proof-Of-Work: one user knowing the hash constituting the POW of a user could abuse that into another POW indicative of slightly more work.

share|improve this answer
Similar multi collision attacks apply to all narrow pipe hashes, since for them, finding a state collision isn't harder than finding an output collision. – CodesInChaos Jun 19 '15 at 6:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.