diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2026-10-22 15:05:23 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-10-22 15:05:23 -0500 |
| commit | e1d35f666cc35f6ead55d32ea2679df44d04da72 (patch) | |
| tree | dbcb08cbc40cb0f3e630a5c63201876a7a1e467a /Source/Core/Common/Hash.cpp | |
| parent | 10d958e66bb5d7574166a10f57839a288c5a7c64 (diff) | |
| parent | 7e46e85e8fb3cff68f05bc160c7ac3ed77b1414b (diff) | |
Merge pull request #14913 from jordan-woyak/md5
Common: Introduce MD5Context class and ComputeMD5 function to minimize mbedtls dependence.
Diffstat (limited to 'Source/Core/Common/Hash.cpp')
| -rw-r--r-- | Source/Core/Common/Hash.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Source/Core/Common/Hash.cpp b/Source/Core/Common/Hash.cpp index f5b9da1b20..6e2ee8fb2b 100644 --- a/Source/Core/Common/Hash.cpp +++ b/Source/Core/Common/Hash.cpp @@ -9,6 +9,8 @@ #include <zlib.h> +#include <mbedtls/md5.h> + #include "Common/CPUDetect.h" #include "Common/Intrinsics.h" @@ -457,4 +459,34 @@ u32 ComputeCRC32(std::string_view data) { return ComputeCRC32(reinterpret_cast<const u8*>(data.data()), data.size()); } + +struct MD5Context::Impl +{ + mbedtls_md5_context context; +}; + +MD5Context::MD5Context() : m_impl{std::make_unique<Impl>()} +{ + mbedtls_md5_init(&m_impl->context); + mbedtls_md5_starts_ret(&m_impl->context); +} + +// FYI: mbedtls_md5_free is unnecessary. It just zeroes the struct. +MD5Context::~MD5Context() = default; + +void MD5Context::Update(std::span<const u8> data) +{ + mbedtls_md5_update_ret(&m_impl->context, data.data(), data.size()); +} + +void MD5Context::Finish(u8* output) +{ + mbedtls_md5_finish_ret(&m_impl->context, output); +} + +void ComputeMD5(std::span<const u8> input, u8* output) +{ + mbedtls_md5_ret(input.data(), input.size(), output); +} + } // namespace Common |
