summaryrefslogtreecommitdiff
path: root/Source/Core/DiscIO/Volume.cpp
diff options
context:
space:
mode:
authorJMC47 <JMC4789@gmail.com>2020-09-06 17:14:08 -0400
committerGitHub <noreply@github.com>2020-09-06 17:14:08 -0400
commite7e51756068a450b6e920c7783c81d7df4d2d133 (patch)
tree94f0bfe833986f8d35f0d2a40842807601f53b9f /Source/Core/DiscIO/Volume.cpp
parent344fdabf23c048b81b8e87008a7a16837d180f55 (diff)
parentfc6c1931fa09513388f35507b724bc378a0758e1 (diff)
Merge pull request #8861 from JosJuice/netplay-hash
Make netplay's "same game" check more robust
Diffstat (limited to 'Source/Core/DiscIO/Volume.cpp')
-rw-r--r--Source/Core/DiscIO/Volume.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/Source/Core/DiscIO/Volume.cpp b/Source/Core/DiscIO/Volume.cpp
index 23df2afc5c..ab4b0e562b 100644
--- a/Source/Core/DiscIO/Volume.cpp
+++ b/Source/Core/DiscIO/Volume.cpp
@@ -9,12 +9,16 @@
#include <memory>
#include <optional>
#include <string>
+#include <type_traits>
#include <utility>
#include <vector>
+#include <mbedtls/sha1.h>
+
#include "Common/CommonTypes.h"
#include "Common/StringUtil.h"
+#include "Core/IOS/ES/Formats.h"
#include "DiscIO/Blob.h"
#include "DiscIO/Enums.h"
#include "DiscIO/VolumeDisc.h"
@@ -28,6 +32,43 @@ const IOS::ES::TicketReader Volume::INVALID_TICKET{};
const IOS::ES::TMDReader Volume::INVALID_TMD{};
const std::vector<u8> Volume::INVALID_CERT_CHAIN{};
+template <typename T>
+static void AddToSyncHash(mbedtls_sha1_context* context, const T& data)
+{
+ static_assert(std::is_trivially_copyable_v<T>);
+ mbedtls_sha1_update_ret(context, reinterpret_cast<const u8*>(&data), sizeof(data));
+}
+
+void Volume::ReadAndAddToSyncHash(mbedtls_sha1_context* context, u64 offset, u64 length,
+ const Partition& partition) const
+{
+ std::vector<u8> buffer(length);
+ if (Read(offset, length, buffer.data(), partition))
+ mbedtls_sha1_update_ret(context, buffer.data(), buffer.size());
+}
+
+void Volume::AddTMDToSyncHash(mbedtls_sha1_context* context, const Partition& partition) const
+{
+ // We want to hash some important parts of the TMD, but nothing that changes when fakesigning.
+ // (Fakesigned WADs are very popular, and we don't want people with properly signed WADs to
+ // unnecessarily be at a disadvantage due to most netplay partners having fakesigned WADs.)
+
+ const IOS::ES::TMDReader& tmd = GetTMD(partition);
+ if (!tmd.IsValid())
+ return;
+
+ AddToSyncHash(context, tmd.GetIOSId());
+ AddToSyncHash(context, tmd.GetTitleId());
+ AddToSyncHash(context, tmd.GetTitleFlags());
+ AddToSyncHash(context, tmd.GetGroupId());
+ AddToSyncHash(context, tmd.GetRegion());
+ AddToSyncHash(context, tmd.GetTitleVersion());
+ AddToSyncHash(context, tmd.GetBootIndex());
+
+ for (const IOS::ES::Content& content : tmd.GetContents())
+ AddToSyncHash(context, content);
+}
+
std::map<Language, std::string> Volume::ReadWiiNames(const std::vector<char16_t>& data)
{
std::map<Language, std::string> names;