diff options
author | Zach Hilman <zachhilman@gmail.com> | 2018-07-30 01:00:09 +0200 |
---|---|---|
committer | Zach Hilman <zachhilman@gmail.com> | 2018-08-01 06:16:54 +0200 |
commit | 03149d3e4a7f8038d9c88cbeb19dee25a39e0042 (patch) | |
tree | cae04a5eefd883d1a665d9502370ec5ff9faa3fd /src/core/crypto/key_manager.cpp | |
parent | Allow key loading from %YUZU_DIR%/keys in addition to ~/.switch (diff) | |
download | yuzu-03149d3e4a7f8038d9c88cbeb19dee25a39e0042.tar yuzu-03149d3e4a7f8038d9c88cbeb19dee25a39e0042.tar.gz yuzu-03149d3e4a7f8038d9c88cbeb19dee25a39e0042.tar.bz2 yuzu-03149d3e4a7f8038d9c88cbeb19dee25a39e0042.tar.lz yuzu-03149d3e4a7f8038d9c88cbeb19dee25a39e0042.tar.xz yuzu-03149d3e4a7f8038d9c88cbeb19dee25a39e0042.tar.zst yuzu-03149d3e4a7f8038d9c88cbeb19dee25a39e0042.zip |
Diffstat (limited to 'src/core/crypto/key_manager.cpp')
-rw-r--r-- | src/core/crypto/key_manager.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp index dea092b5e..33633de7e 100644 --- a/src/core/crypto/key_manager.cpp +++ b/src/core/crypto/key_manager.cpp @@ -2,9 +2,11 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include <array> #include <fstream> #include <locale> #include <sstream> +#include <string_view> #include <mbedtls/sha256.h> #include "common/assert.h" #include "common/common_paths.h" @@ -86,17 +88,18 @@ void KeyManager::LoadFromFile(std::string_view filename_, bool is_title_keys) { if (is_title_keys) { auto rights_id_raw = HexStringToArray<16>(out[0]); - u128 rights_id = *reinterpret_cast<std::array<u64, 2>*>(&rights_id_raw); + u128 rights_id{}; + std::memcpy(rights_id.data(), rights_id_raw.data(), rights_id_raw.size()); Key128 key = HexStringToArray<16>(out[1]); SetKey(S128KeyType::Titlekey, key, rights_id[1], rights_id[0]); } else { std::transform(out[0].begin(), out[0].end(), out[0].begin(), ::tolower); if (s128_file_id.find(out[0]) != s128_file_id.end()) { - const auto index = s128_file_id[out[0]]; + const auto index = s128_file_id.at(out[0]); Key128 key = HexStringToArray<16>(out[1]); SetKey(index.type, key, index.field1, index.field2); } else if (s256_file_id.find(out[0]) != s256_file_id.end()) { - const auto index = s256_file_id[out[0]]; + const auto index = s256_file_id.at(out[0]); Key256 key = HexStringToArray<32>(out[1]); SetKey(index.type, key, index.field1, index.field2); } @@ -143,7 +146,7 @@ void KeyManager::SetKey(S256KeyType id, Key256 key, u64 field1, u64 field2) { s256_keys[{id, field1, field2}] = key; } -std::unordered_map<std::string, KeyIndex<S128KeyType>> KeyManager::s128_file_id = { +const std::unordered_map<std::string, KeyIndex<S128KeyType>> KeyManager::s128_file_id = { {"master_key_00", {S128KeyType::Master, 0, 0}}, {"master_key_01", {S128KeyType::Master, 1, 0}}, {"master_key_02", {S128KeyType::Master, 2, 0}}, @@ -187,7 +190,7 @@ std::unordered_map<std::string, KeyIndex<S128KeyType>> KeyManager::s128_file_id {"key_area_key_system_04", {S128KeyType::KeyArea, 4, static_cast<u64>(KeyAreaKeyType::System)}}, }; -std::unordered_map<std::string, KeyIndex<S256KeyType>> KeyManager::s256_file_id = { +const std::unordered_map<std::string, KeyIndex<S256KeyType>> KeyManager::s256_file_id = { {"header_key", {S256KeyType::Header, 0, 0}}, {"sd_card_save_key", {S256KeyType::SDSave, 0, 0}}, {"sd_card_nca_key", {S256KeyType::SDNCA, 0, 0}}, |