From 6d821de2b9803e2a4993ae4e6b38a4b8126a61fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Mon, 26 Jun 2017 23:38:58 +0200 Subject: [PATCH] IOS: Use a std::array for the title key instead of vector The title key is always 16 bytes, so it doesn't make sense to make it a std::vector. --- Source/Core/Core/IOS/ES/ES.h | 2 +- Source/Core/Core/IOS/ES/Formats.cpp | 4 ++-- Source/Core/Core/IOS/ES/Formats.h | 2 +- Source/Core/DiscIO/NANDContentLoader.cpp | 2 +- Source/Core/DiscIO/VolumeWii.cpp | 5 ++--- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Source/Core/Core/IOS/ES/ES.h b/Source/Core/Core/IOS/ES/ES.h index b53a8780f5..747fa0a942 100644 --- a/Source/Core/Core/IOS/ES/ES.h +++ b/Source/Core/Core/IOS/ES/ES.h @@ -80,7 +80,7 @@ public: bool valid = false; IOS::ES::TMDReader tmd; - std::vector title_key; + std::array title_key; std::map contents; }; diff --git a/Source/Core/Core/IOS/ES/Formats.cpp b/Source/Core/Core/IOS/ES/Formats.cpp index 2a303b5d7f..04210090f9 100644 --- a/Source/Core/Core/IOS/ES/Formats.cpp +++ b/Source/Core/Core/IOS/ES/Formats.cpp @@ -380,7 +380,7 @@ u64 TicketReader::GetTitleId() const return Common::swap64(m_bytes.data() + offsetof(Ticket, title_id)); } -std::vector TicketReader::GetTitleKey() const +std::array TicketReader::GetTitleKey() const { u8 iv[16] = {}; std::copy_n(&m_bytes[offsetof(Ticket, title_id)], sizeof(Ticket::title_id), iv); @@ -398,7 +398,7 @@ std::vector TicketReader::GetTitleKey() const const HLE::IOSC::ConsoleType console_type = is_rvt ? HLE::IOSC::ConsoleType::RVT : HLE::IOSC::ConsoleType::Retail; - std::vector key(16); + std::array key; HLE::IOSC iosc(console_type); iosc.Decrypt(common_key_handle, iv, &m_bytes[offsetof(Ticket, title_key)], 16, key.data(), HLE::PID_ES); diff --git a/Source/Core/Core/IOS/ES/Formats.h b/Source/Core/Core/IOS/ES/Formats.h index dd1352b367..ac710fe660 100644 --- a/Source/Core/Core/IOS/ES/Formats.h +++ b/Source/Core/Core/IOS/ES/Formats.h @@ -222,7 +222,7 @@ public: u32 GetDeviceId() const; u64 GetTitleId() const; - std::vector GetTitleKey() const; + std::array GetTitleKey() const; // Deletes a ticket with the given ticket ID from the internal buffer. void DeleteTicket(u64 ticket_id); diff --git a/Source/Core/DiscIO/NANDContentLoader.cpp b/Source/Core/DiscIO/NANDContentLoader.cpp index fe5d77d15e..0178c3c14e 100644 --- a/Source/Core/DiscIO/NANDContentLoader.cpp +++ b/Source/Core/DiscIO/NANDContentLoader.cpp @@ -186,7 +186,7 @@ void NANDContentLoader::InitializeContentEntries(const std::vector& data_app m_Content.resize(contents.size()); u32 data_app_offset = 0; - const std::vector title_key = m_ticket.GetTitleKey(); + const std::array title_key = m_ticket.GetTitleKey(); IOS::ES::SharedContentMap shared_content{m_root}; for (size_t i = 0; i < contents.size(); ++i) diff --git a/Source/Core/DiscIO/VolumeWii.cpp b/Source/Core/DiscIO/VolumeWii.cpp index b8215527a6..8ccca04409 100644 --- a/Source/Core/DiscIO/VolumeWii.cpp +++ b/Source/Core/DiscIO/VolumeWii.cpp @@ -5,6 +5,7 @@ #include "DiscIO/VolumeWii.h" #include +#include #include #include #include @@ -97,9 +98,7 @@ VolumeWii::VolumeWii(std::unique_ptr reader) IOS::ES::TMDReader tmd{std::move(tmd_buffer)}; // Get the decryption key - const std::vector key = ticket.GetTitleKey(); - if (key.size() != 16) - continue; + const std::array key = ticket.GetTitleKey(); std::unique_ptr aes_context = std::make_unique(); mbedtls_aes_setkey_dec(aes_context.get(), key.data(), 128);