aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/md5.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zencore/md5.cpp')
-rw-r--r--src/zencore/md5.cpp24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/zencore/md5.cpp b/src/zencore/md5.cpp
index 83ed53fc8..f8cfee3ac 100644
--- a/src/zencore/md5.cpp
+++ b/src/zencore/md5.cpp
@@ -56,9 +56,9 @@ struct MD5_CTX
unsigned char digest[16]; /* actual digest after MD5Final call */
};
-void MD5Init();
-void MD5Update();
-void MD5Final();
+void MD5Init(MD5_CTX* mdContext);
+void MD5Update(MD5_CTX* mdContext, unsigned char* inBuf, unsigned int inLen);
+void MD5Final(MD5_CTX* mdContext);
/*
**********************************************************************
@@ -370,28 +370,32 @@ MD5 MD5::Zero; // Initialized to all zeroes
MD5Stream::MD5Stream()
{
+ static_assert(sizeof(MD5_CTX) <= sizeof(m_Context));
Reset();
}
void
MD5Stream::Reset()
{
+ MD5Init(reinterpret_cast<MD5_CTX*>(m_Context));
}
MD5Stream&
MD5Stream::Append(const void* Data, size_t ByteCount)
{
- ZEN_UNUSED(Data);
- ZEN_UNUSED(ByteCount);
-
+ MD5Update(reinterpret_cast<MD5_CTX*>(m_Context), (unsigned char*)Data, (unsigned int)ByteCount);
return *this;
}
MD5
MD5Stream::GetHash()
{
- MD5 md5{};
+ MD5_CTX FinalCtx;
+ memcpy(&FinalCtx, m_Context, sizeof(MD5_CTX));
+ MD5Final(&FinalCtx);
+ MD5 md5{};
+ memcpy(md5.Hash, FinalCtx.digest, 16);
return md5;
}
@@ -428,7 +432,7 @@ MD5::ToHexString(StringBuilderBase& outBuilder) const
char str[41];
ToHexString(str);
- outBuilder.AppendRange(str, &str[40]);
+ outBuilder.AppendRange(str, &str[StringLength]);
return outBuilder;
}
@@ -470,11 +474,11 @@ TEST_CASE("MD5")
MD5::String_t Buffer;
Result.ToHexString(Buffer);
- CHECK(Output.compare(Buffer));
+ CHECK(Output.compare(Buffer) == 0);
MD5 Reresult = MD5::FromHexString(Buffer);
Reresult.ToHexString(Buffer);
- CHECK(Output.compare(Buffer));
+ CHECK(Output.compare(Buffer) == 0);
}
TEST_SUITE_END();