bug 496234 - fix md4 implementation by appending the input length as a 64-bit number r=mayhemer

This commit is contained in:
David Keeler 2015-06-25 12:32:44 -07:00
Родитель ef236972ed
Коммит 8f50e96227
1 изменённых файлов: 11 добавлений и 2 удалений

Просмотреть файл

@ -104,6 +104,9 @@ void md4sum(const uint8_t *input, uint32_t inputLen, uint8_t *result)
{
uint8_t final[128];
uint32_t i, n, m, state[4];
uint64_t inputLenBits;
uint32_t inputLenBitsLow;
uint32_t inputLenBitsHigh;
/* magic initial states */
state[0] = 0x67452301;
@ -124,8 +127,14 @@ void md4sum(const uint8_t *input, uint32_t inputLen, uint8_t *result)
final[n] = 0x80;
memset(final + n + 1, 0, 120 - (n + 1));
inputLen = inputLen << 3;
w2b(final + (n >= 56 ? 120 : 56), &inputLen, 4);
/* Append the original input length in bits as a 64-bit number. This is done
* in two 32-bit chunks, with the least-significant 32 bits first.
* w2b will handle endianness. */
inputLenBits = inputLen << 3;
inputLenBitsLow = (uint32_t)(inputLenBits & 0xFFFFFFFF);
w2b(final + (n >= 56 ? 120 : 56), &inputLenBitsLow, 4);
inputLenBitsHigh = (uint32_t)((inputLenBits >> 32) & 0xFFFFFFFF);
w2b(final + (n >= 56 ? 124 : 60), &inputLenBitsHigh, 4);
md4step(state, final);
if (n >= 56)