diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index b1e25af45b..8f3bc99562 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -25,6 +25,8 @@ add_library(common Config/Layer.cpp Config/Layer.h CPUDetect.h + CRC32.cpp + CRC32.h Crypto/AES.cpp Crypto/AES.h Crypto/bn.cpp diff --git a/Source/Core/Common/CRC32.cpp b/Source/Core/Common/CRC32.cpp new file mode 100644 index 0000000000..843b0c3333 --- /dev/null +++ b/Source/Core/Common/CRC32.cpp @@ -0,0 +1,19 @@ +// Copyright 2021 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include + +#include "Common/CRC32.h" + +namespace Common +{ +u32 ComputeCRC32(std::string_view data) +{ + const Bytef* buf = reinterpret_cast(data.data()); + uInt len = static_cast(data.size()); + // Use zlibs crc32 implementation to compute the hash + u32 hash = crc32(0L, Z_NULL, 0); + hash = crc32(hash, buf, len); + return hash; +} +} // namespace Common diff --git a/Source/Core/Common/CRC32.h b/Source/Core/Common/CRC32.h new file mode 100644 index 0000000000..3f3f52b96a --- /dev/null +++ b/Source/Core/Common/CRC32.h @@ -0,0 +1,11 @@ +// Copyright 2021 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include + +#include "Common/CommonTypes.h" + +namespace Common +{ +u32 ComputeCRC32(std::string_view data); +} // namespace Common diff --git a/Source/Core/Core/Boot/Boot.cpp b/Source/Core/Core/Boot/Boot.cpp index df7cf9014f..3bb2c5e53d 100644 --- a/Source/Core/Core/Boot/Boot.cpp +++ b/Source/Core/Core/Boot/Boot.cpp @@ -20,10 +20,9 @@ namespace fs = std::filesystem; #include #include -#include - #include "Common/Align.h" #include "Common/CDUtils.h" +#include "Common/CRC32.h" #include "Common/CommonPaths.h" #include "Common/CommonTypes.h" #include "Common/Config/Config.h" @@ -355,9 +354,7 @@ bool CBoot::Load_BS2(const std::string& boot_rom_filename) if (!File::ReadFileToString(boot_rom_filename, data)) return false; - // Use zlibs crc32 implementation to compute the hash - u32 ipl_hash = crc32(0L, Z_NULL, 0); - ipl_hash = crc32(ipl_hash, (const Bytef*)data.data(), (u32)data.size()); + const u32 ipl_hash = Common::ComputeCRC32(data); bool known_ipl = false; bool pal_ipl = false; switch (ipl_hash) diff --git a/Source/Core/DolphinLib.props b/Source/Core/DolphinLib.props index fc429c0ab4..96b489f555 100644 --- a/Source/Core/DolphinLib.props +++ b/Source/Core/DolphinLib.props @@ -21,6 +21,7 @@ + @@ -689,6 +690,7 @@ +