diff options
author | bunnei <bunneidev@gmail.com> | 2018-09-04 22:20:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-04 22:20:40 +0200 |
commit | faa9e066aba320bcd38fd023ee58c6f9e1d3efdd (patch) | |
tree | c369b13af5a30698564ee54acbae639be4576482 /src/core/crypto | |
parent | Merge pull request #1238 from lioncash/explicit (diff) | |
parent | main: Only show DRD deprecation warning once (diff) | |
download | yuzu-faa9e066aba320bcd38fd023ee58c6f9e1d3efdd.tar yuzu-faa9e066aba320bcd38fd023ee58c6f9e1d3efdd.tar.gz yuzu-faa9e066aba320bcd38fd023ee58c6f9e1d3efdd.tar.bz2 yuzu-faa9e066aba320bcd38fd023ee58c6f9e1d3efdd.tar.lz yuzu-faa9e066aba320bcd38fd023ee58c6f9e1d3efdd.tar.xz yuzu-faa9e066aba320bcd38fd023ee58c6f9e1d3efdd.tar.zst yuzu-faa9e066aba320bcd38fd023ee58c6f9e1d3efdd.zip |
Diffstat (limited to 'src/core/crypto')
-rw-r--r-- | src/core/crypto/key_manager.cpp | 16 | ||||
-rw-r--r-- | src/core/crypto/key_manager.h | 2 |
2 files changed, 15 insertions, 3 deletions
diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp index f768533da..6f27f990b 100644 --- a/src/core/crypto/key_manager.cpp +++ b/src/core/crypto/key_manager.cpp @@ -231,18 +231,28 @@ void KeyManager::WriteKeyToFile(bool title_key, std::string_view keyname, } void KeyManager::SetKey(S128KeyType id, Key128 key, u64 field1, u64 field2) { - const auto iter = std::find_if( + if (s128_keys.find({id, field1, field2}) != s128_keys.end()) + return; + if (id == S128KeyType::Titlekey) { + Key128 rights_id; + std::memcpy(rights_id.data(), &field2, sizeof(u64)); + std::memcpy(rights_id.data() + sizeof(u64), &field1, sizeof(u64)); + WriteKeyToFile(true, Common::HexArrayToString(rights_id), key); + } + const auto iter2 = std::find_if( s128_file_id.begin(), s128_file_id.end(), [&id, &field1, &field2](const std::pair<std::string, KeyIndex<S128KeyType>> elem) { return std::tie(elem.second.type, elem.second.field1, elem.second.field2) == std::tie(id, field1, field2); }); - if (iter != s128_file_id.end()) - WriteKeyToFile(id == S128KeyType::Titlekey, iter->first, key); + if (iter2 != s128_file_id.end()) + WriteKeyToFile(false, iter2->first, key); s128_keys[{id, field1, field2}] = key; } void KeyManager::SetKey(S256KeyType id, Key256 key, u64 field1, u64 field2) { + if (s256_keys.find({id, field1, field2}) != s256_keys.end()) + return; const auto iter = std::find_if( s256_file_id.begin(), s256_file_id.end(), [&id, &field1, &field2](const std::pair<std::string, KeyIndex<S256KeyType>> elem) { diff --git a/src/core/crypto/key_manager.h b/src/core/crypto/key_manager.h index bf51bf31f..ce67913bb 100644 --- a/src/core/crypto/key_manager.h +++ b/src/core/crypto/key_manager.h @@ -17,6 +17,8 @@ enum class ResultStatus : u16; namespace Core::Crypto { +constexpr u64 TICKET_FILE_TITLEKEY_OFFSET = 0x180; + using Key128 = std::array<u8, 0x10>; using Key256 = std::array<u8, 0x20>; using SHA256Hash = std::array<u8, 0x20>; |