1
$\begingroup$

What is the condition if the message size in md5 increses from 448 as the 64 bits are the length and we have to make the block of 512. So what will be the bits if it increases from 448

$\endgroup$
  • $\begingroup$ Computing the padding of MD5 $\endgroup$ – kelalaka Oct 21 '18 at 19:22
  • 1
    $\begingroup$ Message size is always padded to congruent to 448, modulo 512. The remaining 64 bit are the size of the message. At the end we will have exact multiple of 512. $\endgroup$ – kelalaka Oct 21 '18 at 19:28
1
$\begingroup$

The padding will always be applied. So if the final block contains 448 bits or over then an additional block will be needed.

The first block is padded as usual, but instead of ending at bit 448, it will now continue up to the end of the block, bit 512. Then the padding will continue in the final block. So zero valued bits are added up to bit 448, after which the length is appended and the final hash value can be calculated.

It is easy to see that a message length of 448 to 511 bits will always result in a padding of 448 zero valued bits in the final block. This is however of little use because the encoded length does change, and internal state variables will differ as well.


Let's assume bytes, and look at the situation where 55 bytes / 440 bits are input:

MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMPLLLLLLLL

and the situation where 56 bytes / 448 bits are input:

MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMP0000000
00000000000000000000000000000000000000000000000000000000LLLLLLLL

the situation for 63 bytes / 504 bits:

MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMP
00000000000000000000000000000000000000000000000000000000LLLLLLLL

and finally a situation where 64 bytes / 512 bits are input:

MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
P0000000000000000000000000000000000000000000000000000000LLLLLLLL

where M is a byte of the message, P is the byte containing the first padding bit set to 1 (value 80 hex), 0 is of course a byte with just zero bits (value 00 hex) and L is the length encoding.


OT, but the LLLLLLLL is the encoding of the message size in bits, where each L is one byte. This length encoding is in big endian format. Let's define them as hexadecimals and we get the following table for the previous paddings:

440 : 00000000000001B8
448 : 00000000000001C0
504 : 00000000000001F8
512 : 0000000000000200
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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