diff options
| author | 2018-07-29 19:00:09 -0400 | |
|---|---|---|
| committer | 2018-08-01 00:16:54 -0400 | |
| 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.gz yuzu-03149d3e4a7f8038d9c88cbeb19dee25a39e0042.tar.xz yuzu-03149d3e4a7f8038d9c88cbeb19dee25a39e0042.zip | |
Add missing includes and use const where applicable
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 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <array> | ||
| 5 | #include <fstream> | 6 | #include <fstream> |
| 6 | #include <locale> | 7 | #include <locale> |
| 7 | #include <sstream> | 8 | #include <sstream> |
| 9 | #include <string_view> | ||
| 8 | #include <mbedtls/sha256.h> | 10 | #include <mbedtls/sha256.h> |
| 9 | #include "common/assert.h" | 11 | #include "common/assert.h" |
| 10 | #include "common/common_paths.h" | 12 | #include "common/common_paths.h" |
| @@ -86,17 +88,18 @@ void KeyManager::LoadFromFile(std::string_view filename_, bool is_title_keys) { | |||
| 86 | 88 | ||
| 87 | if (is_title_keys) { | 89 | if (is_title_keys) { |
| 88 | auto rights_id_raw = HexStringToArray<16>(out[0]); | 90 | auto rights_id_raw = HexStringToArray<16>(out[0]); |
| 89 | u128 rights_id = *reinterpret_cast<std::array<u64, 2>*>(&rights_id_raw); | 91 | u128 rights_id{}; |
| 92 | std::memcpy(rights_id.data(), rights_id_raw.data(), rights_id_raw.size()); | ||
| 90 | Key128 key = HexStringToArray<16>(out[1]); | 93 | Key128 key = HexStringToArray<16>(out[1]); |
| 91 | SetKey(S128KeyType::Titlekey, key, rights_id[1], rights_id[0]); | 94 | SetKey(S128KeyType::Titlekey, key, rights_id[1], rights_id[0]); |
| 92 | } else { | 95 | } else { |
| 93 | std::transform(out[0].begin(), out[0].end(), out[0].begin(), ::tolower); | 96 | std::transform(out[0].begin(), out[0].end(), out[0].begin(), ::tolower); |
| 94 | if (s128_file_id.find(out[0]) != s128_file_id.end()) { | 97 | if (s128_file_id.find(out[0]) != s128_file_id.end()) { |
| 95 | const auto index = s128_file_id[out[0]]; | 98 | const auto index = s128_file_id.at(out[0]); |
| 96 | Key128 key = HexStringToArray<16>(out[1]); | 99 | Key128 key = HexStringToArray<16>(out[1]); |
| 97 | SetKey(index.type, key, index.field1, index.field2); | 100 | SetKey(index.type, key, index.field1, index.field2); |
| 98 | } else if (s256_file_id.find(out[0]) != s256_file_id.end()) { | 101 | } else if (s256_file_id.find(out[0]) != s256_file_id.end()) { |
| 99 | const auto index = s256_file_id[out[0]]; | 102 | const auto index = s256_file_id.at(out[0]); |
| 100 | Key256 key = HexStringToArray<32>(out[1]); | 103 | Key256 key = HexStringToArray<32>(out[1]); |
| 101 | SetKey(index.type, key, index.field1, index.field2); | 104 | SetKey(index.type, key, index.field1, index.field2); |
| 102 | } | 105 | } |
| @@ -143,7 +146,7 @@ void KeyManager::SetKey(S256KeyType id, Key256 key, u64 field1, u64 field2) { | |||
| 143 | s256_keys[{id, field1, field2}] = key; | 146 | s256_keys[{id, field1, field2}] = key; |
| 144 | } | 147 | } |
| 145 | 148 | ||
| 146 | std::unordered_map<std::string, KeyIndex<S128KeyType>> KeyManager::s128_file_id = { | 149 | const std::unordered_map<std::string, KeyIndex<S128KeyType>> KeyManager::s128_file_id = { |
| 147 | {"master_key_00", {S128KeyType::Master, 0, 0}}, | 150 | {"master_key_00", {S128KeyType::Master, 0, 0}}, |
| 148 | {"master_key_01", {S128KeyType::Master, 1, 0}}, | 151 | {"master_key_01", {S128KeyType::Master, 1, 0}}, |
| 149 | {"master_key_02", {S128KeyType::Master, 2, 0}}, | 152 | {"master_key_02", {S128KeyType::Master, 2, 0}}, |
| @@ -187,7 +190,7 @@ std::unordered_map<std::string, KeyIndex<S128KeyType>> KeyManager::s128_file_id | |||
| 187 | {"key_area_key_system_04", {S128KeyType::KeyArea, 4, static_cast<u64>(KeyAreaKeyType::System)}}, | 190 | {"key_area_key_system_04", {S128KeyType::KeyArea, 4, static_cast<u64>(KeyAreaKeyType::System)}}, |
| 188 | }; | 191 | }; |
| 189 | 192 | ||
| 190 | std::unordered_map<std::string, KeyIndex<S256KeyType>> KeyManager::s256_file_id = { | 193 | const std::unordered_map<std::string, KeyIndex<S256KeyType>> KeyManager::s256_file_id = { |
| 191 | {"header_key", {S256KeyType::Header, 0, 0}}, | 194 | {"header_key", {S256KeyType::Header, 0, 0}}, |
| 192 | {"sd_card_save_key", {S256KeyType::SDSave, 0, 0}}, | 195 | {"sd_card_save_key", {S256KeyType::SDSave, 0, 0}}, |
| 193 | {"sd_card_nca_key", {S256KeyType::SDNCA, 0, 0}}, | 196 | {"sd_card_nca_key", {S256KeyType::SDNCA, 0, 0}}, |