Yes, its old and broken, but I’m trying to understand how MD2 works so I am trying to code it in C#. So far I have gotten to the padding which looks like it should be simple, but I’m unsure as to how it works exactly. https://www.rfc-editor.org/rfc/rfc1319 gives a good explanation, but the example in c is hard to understand where the padding is coming from. I’m confused as to why in the example code the numbering stops at 7 and then goes on to 10 almost as if its going from 0 to 7 for two 4-bit chunks.
I wrote this in an attempt to duplicate it, does this return the padding the way it is supposed to work?
public static byte[] getPadding(int number_needed)
{
byte[] temp = new byte[number_needed];
for (int i = 0; i < temp.Count(); i++)
{
temp[i] = BitConverter.GetBytes(number_needed)[0];
}
return temp;
}
As I understand that RFC, all padding bytes have the value of the number of padding bytes total. So if you need to add 5 padding bytes, you add 5 bytes of value 0x05.
They must be using the octal notation in the code example – that goes from 01-07, then (octal)10, 11, 12…16, 17, 20. The decimal values still are 01-16, though (padding is never 0 bytes).