From db5bbbd6cf340fd8e77244ad452089fae0ff33ae Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sun, 4 Oct 2026 16:04:21 -0500 Subject: Common: Create MD5Context class and ComputeMD5 function to minimize exposure to mbedtls throughout the project. --- Source/Core/Common/Hash.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'Source/Core/Common/Hash.cpp') 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 +#include + #include "Common/CPUDetect.h" #include "Common/Intrinsics.h" @@ -457,4 +459,34 @@ u32 ComputeCRC32(std::string_view data) { return ComputeCRC32(reinterpret_cast(data.data()), data.size()); } + +struct MD5Context::Impl +{ + mbedtls_md5_context context; +}; + +MD5Context::MD5Context() : m_impl{std::make_unique()} +{ + 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 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 input, u8* output) +{ + mbedtls_md5_ret(input.data(), input.size(), output); +} + } // namespace Common -- cgit v1.2.3