So I'm reading this question to learn more about length extension attack, and I want to make sure I understand the basics of padding.

It says in the post that given the hash and the length of the message, I can easily compute the padding.

Now, from what I understand, each block will always be 512 bits, or 64 bytes.

So does this mean if I have a message that says "LengthExtensionIsSuchAnInterestingConcept", which has a length of 41, it occupies 41 bytes. (Looked at some other posts, ASCII character is 1 byte per character. please correct me if I'm wrong.)

64 - 41 = 23 bytes, so the padding will be 23 bytes. And the entire MD5 in this case will only consists of one block.

Am I correct in my understanding above?


1 Answer 1


That's correct. Here are the padding instructions from RFC1321, the MD5 spec:

3.1 Step 1. Append Padding Bits

   The message is "padded" (extended) so that its length (in bits) is
   congruent to 448, modulo 512. That is, the message is extended so
   that it is just 64 bits shy of being a multiple of 512 bits long.
   Padding is always performed, even if the length of the message is
   already congruent to 448, modulo 512.

   Padding is performed as follows: a single "1" bit is appended to the
   message, and then "0" bits are appended so that the length in bits of
   the padded message becomes congruent to 448, modulo 512. In all, at
   least one bit and at most 512 bits are appended.

3.2 Step 2. Append Length

   A 64-bit representation of b (the length of the message before the
   padding bits were added) is appended to the result of the previous
   step. In the unlikely event that b is greater than 2^64, then only
   the low-order 64 bits of b are used. (These bits are appended as two
   32-bit words and appended low-order word first in accordance with the
   previous conventions.)

   At this point the resulting message (after padding with bits and with
   b) has a length that is an exact multiple of 512 bits. Equivalently,
   this message has a length that is an exact multiple of 16 (32-bit)
   words. Let M[0 ... N-1] denote the words of the resulting message,
   where N is a multiple of 16.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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