mirror of
https://github.com/kevinbentley/Descent3.git
synced 2025-01-22 11:28:56 +00:00
fix 64n+56 bug
This commit is contained in:
parent
b12baa9715
commit
9c1f6e4b73
@ -126,9 +126,9 @@ std::array<unsigned char, 16> MD5::digest() const noexcept {
|
||||
auto buf = tmpbuf_;
|
||||
std::size_t n = tmpbuf_n_;
|
||||
|
||||
if (n > 56) {
|
||||
// must append current block, length won't fit.
|
||||
// n is never buf.size() yet
|
||||
if (n >= 56) {
|
||||
// must append current block, required padding bit and length won't fit.
|
||||
// n is never buf.size() (= 64) yet
|
||||
buf[n++] = 0x80U;
|
||||
while (n < buf.size())
|
||||
buf[n++] = 0;
|
||||
@ -137,7 +137,7 @@ std::array<unsigned char, 16> MD5::digest() const noexcept {
|
||||
// all zeroes, except for length
|
||||
std::fill(buf.begin(), buf.begin() + 56, 0);
|
||||
|
||||
} else if (n < 56) {
|
||||
} else { // n < 56
|
||||
// append padding to tmpbuf and then the length
|
||||
buf[n++] = 0x80U;
|
||||
while (n < 56)
|
||||
|
@ -52,6 +52,7 @@ TEST(D3, MD5) {
|
||||
EXPECT_EQ(hexdigest_after_n_rounds_of_fuzz(1), "c56c005504f5b9b17df9d83f1106e9b2");
|
||||
EXPECT_EQ(hexdigest_after_n_rounds_of_fuzz(2), "98327a3f4ee311c9bdc8613508922c95");
|
||||
EXPECT_EQ(hexdigest_after_n_rounds_of_fuzz(4), "f2343ce526646c087df92d708e883675");
|
||||
EXPECT_EQ(hexdigest_after_n_rounds_of_fuzz(8), "73396b338a0a769c4e6ae5b7b0bc187e");
|
||||
EXPECT_EQ(hexdigest_after_n_rounds_of_fuzz(100), "99b30c1dcc42d97c3d914c26a14bb1d7");
|
||||
EXPECT_EQ(hexdigest_after_n_rounds_of_fuzz(1999), "82eeff8c7d574c8232b0ca6ca2c9dd40");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user