MD4: Difference between revisions
Content added Content deleted
m (Reformatting code.) |
m (Minor improveents to coding.) |
||
Line 590: | Line 590: | ||
engine_update(string_to_byte_vector(text), 0, text.length()); |
engine_update(string_to_byte_vector(text), 0, text.length()); |
||
const int32_t buffer_index = |
const int32_t buffer_index = static_cast<int32_t>(count % BLOCK_LENGTH); |
||
const int32_t padding_length = ( buffer_index < 56 ) ? 56 - buffer_index : 120 - buffer_index; |
const int32_t padding_length = ( buffer_index < 56 ) ? 56 - buffer_index : 120 - buffer_index; |
||
Line 597: | Line 597: | ||
for ( int32_t i = 0; i < 8; ++i ) { |
for ( int32_t i = 0; i < 8; ++i ) { |
||
tail[padding_length + i] = ( |
tail[padding_length + i] = static_cast<int8_t>(unsigned_right_shift(count * 8, 8 * i)); |
||
} |
} |
||
Line 605: | Line 605: | ||
for ( int32_t i = 0; i < 4; ++i ) { |
for ( int32_t i = 0; i < 4; ++i ) { |
||
for ( int32_t j = 0; j < 4; ++j ) { |
for ( int32_t j = 0; j < 4; ++j ) { |
||
result[i * 4 + j] = ( |
result[i * 4 + j] = static_cast<int8_t>(unsigned_right_shift(context[i], 8 * j)); |
||
} |
} |
||
} |
} |
||
Line 621: | Line 621: | ||
} |
} |
||
int32_t buffer_index = |
int32_t buffer_index = static_cast<int32_t>(count % BLOCK_LENGTH); |
||
count += message_length; |
count += message_length; |
||
const int32_t partial_length = BLOCK_LENGTH - buffer_index; |
const int32_t partial_length = BLOCK_LENGTH - buffer_index; |
||
Line 686: | Line 686: | ||
context[3] += d; |
context[3] += d; |
||
} |
} |
||
void engine_reset() { |
void engine_reset() { |
||
count = 0; |
count = 0; |
||
Line 703: | Line 703: | ||
std::transform(text.begin(), text.end(), std::back_inserter(bytes), |
std::transform(text.begin(), text.end(), std::back_inserter(bytes), |
||
[](char ch){ return |
[](char ch){ return static_cast<int8_t>(ch); }); |
||
return bytes; |
return bytes; |
||
Line 712: | Line 712: | ||
return 0; |
return 0; |
||
} |
} |
||
return ( base > 0 ) ? base >> shift : ( base + |
return ( base > 0 ) ? base >> shift : ( base + TWO_POWER_32 ) >> shift; |
||
} |
} |
||
Line 740: | Line 740: | ||
const int32_t BLOCK_LENGTH = 64; |
const int32_t BLOCK_LENGTH = 64; |
||
const int64_t TWO_POWER_32 = 4'294'967'296; |
|||
}; |
}; |
||