This is a great essay on why you should never use a hash function for message authentication.<p>Except not for the reason the author thinks.<p>There are several problems here.<p>First, with SHA-1 for example, you have 64 bytes per chunk. That means you basically get a free ride on this problem for anything < 64 bytes. A lot of "application state" fits pretty well in 64 bytes.<p>Secondly, unless a message ends right on the 64 byte boundary, it is not nearly that simple. You have a bit of a problem, because the hash is padded, and when you add extra characters to your original string, that padding gets <i>replaced</i> with those values. So, it's no longer simple to just "keep going" from where you stopped.<p>Still, you can see how that leaves a distinct subset of cases where you'd be exposed. SHA-1, along with most secure hash functions, appends the length of the message the end of the source text before performing the hash function. That means that if you add even one byte to the string, you have now changed the last 8 bytes that were fed in to the "original" hash function. Oh, and your extra byte goes in <i>before</i> those bytes, so not only did you change those 8 bytes, but you shifted them down a byte.<p>So, no, it isn't nearly that easy to crack a SHA-1 based authentication, and yet, it is easy enough that you should totally NOT use them for authentication and instead use HMAC ; they <i>are</i> vulnerable to extension attacks, it's just not nearly as easy as this article suggests, and conclusions one might draw from this article (like you can solve this problem by feeding all source text in to the hash algorithm backwards) are likely ill founded.<p>It just turns out that cryptography is way more complicated, and even in terms of understanding weaknesses that arise from doing things wrong, you are going to get it wrong. Trust the experts, when they say it is a bad idea, but don't assume <i>why</i> it is a bad idea can be explained in a short blog article like this.<p><i>UPDATED</i>: Added an explanation as to why it might be dangerous to just take this article at its word.