summaryrefslogtreecommitdiff
path: root/src/core/crypto
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/crypto')
-rw-r--r--src/core/crypto/key_manager.cpp22
-rw-r--r--src/core/crypto/key_manager.h6
2 files changed, 13 insertions, 15 deletions
diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp
index acf635a65..1cb3fce00 100644
--- a/src/core/crypto/key_manager.cpp
+++ b/src/core/crypto/key_manager.cpp
@@ -199,7 +199,7 @@ Key256 KeyManager::GetKey(S256KeyType id, u64 field1, u64 field2) const {
199 199
200template <size_t Size> 200template <size_t Size>
201void KeyManager::WriteKeyToFile(bool title_key, std::string_view keyname, 201void KeyManager::WriteKeyToFile(bool title_key, std::string_view keyname,
202 std::array<u8, Size> key) { 202 const std::array<u8, Size>& key) {
203 const std::string yuzu_keys_dir = FileUtil::GetUserPath(FileUtil::UserPath::KeysDir); 203 const std::string yuzu_keys_dir = FileUtil::GetUserPath(FileUtil::UserPath::KeysDir);
204 std::string filename = "title.keys_autogenerated"; 204 std::string filename = "title.keys_autogenerated";
205 if (!title_key) 205 if (!title_key)
@@ -209,11 +209,10 @@ void KeyManager::WriteKeyToFile(bool title_key, std::string_view keyname,
209 if (!file.is_open()) 209 if (!file.is_open())
210 return; 210 return;
211 if (add_info_text) { 211 if (add_info_text) {
212 file << "# This file is autogenerated by Yuzu" << std::endl 212 file
213 << "# It serves to store keys that were automatically generated from the normal keys" 213 << "# This file is autogenerated by Yuzu\n"
214 << std::endl 214 << "# It serves to store keys that were automatically generated from the normal keys\n"
215 << "# If you are experiencing issues involving keys, it may help to delete this file" 215 << "# If you are experiencing issues involving keys, it may help to delete this file\n";
216 << std::endl;
217 } 216 }
218 217
219 file << std::endl 218 file << std::endl
@@ -263,11 +262,12 @@ bool KeyManager::KeyFileExists(bool title) {
263} 262}
264 263
265void KeyManager::DeriveSDSeedLazy() { 264void KeyManager::DeriveSDSeedLazy() {
266 if (!HasKey(S128KeyType::SDSeed)) { 265 if (HasKey(S128KeyType::SDSeed))
267 const auto res = DeriveSDSeed(); 266 return;
268 if (res != boost::none) 267
269 SetKey(S128KeyType::SDSeed, res.get()); 268 const auto res = DeriveSDSeed();
270 } 269 if (res != boost::none)
270 SetKey(S128KeyType::SDSeed, res.get());
271} 271}
272 272
273const boost::container::flat_map<std::string, KeyIndex<S128KeyType>> KeyManager::s128_file_id = { 273const boost::container::flat_map<std::string, KeyIndex<S128KeyType>> KeyManager::s128_file_id = {
diff --git a/src/core/crypto/key_manager.h b/src/core/crypto/key_manager.h
index 78d0b64e0..7a8728f76 100644
--- a/src/core/crypto/key_manager.h
+++ b/src/core/crypto/key_manager.h
@@ -74,9 +74,7 @@ struct KeyIndex {
74// boost flat_map requires operator< for O(log(n)) lookups. 74// boost flat_map requires operator< for O(log(n)) lookups.
75template <typename KeyType> 75template <typename KeyType>
76bool operator<(const KeyIndex<KeyType>& lhs, const KeyIndex<KeyType>& rhs) { 76bool operator<(const KeyIndex<KeyType>& lhs, const KeyIndex<KeyType>& rhs) {
77 return (static_cast<size_t>(lhs.type) < static_cast<size_t>(rhs.type)) || 77 return std::tie(lhs.type, lhs.field1, lhs.field2) < std::tie(rhs.type, rhs.field1, rhs.field2);
78 (lhs.type == rhs.type && lhs.field1 < rhs.field1) ||
79 (lhs.type == rhs.type && lhs.field1 == rhs.field1 && lhs.field2 < rhs.field2);
80} 78}
81 79
82class KeyManager { 80class KeyManager {
@@ -107,7 +105,7 @@ private:
107 void AttemptLoadKeyFile(const std::string& dir1, const std::string& dir2, 105 void AttemptLoadKeyFile(const std::string& dir1, const std::string& dir2,
108 const std::string& filename, bool title); 106 const std::string& filename, bool title);
109 template <size_t Size> 107 template <size_t Size>
110 void WriteKeyToFile(bool title_key, std::string_view keyname, std::array<u8, Size> key); 108 void WriteKeyToFile(bool title_key, std::string_view keyname, const std::array<u8, Size>& key);
111 109
112 static const boost::container::flat_map<std::string, KeyIndex<S128KeyType>> s128_file_id; 110 static const boost::container::flat_map<std::string, KeyIndex<S128KeyType>> s128_file_id;
113 static const boost::container::flat_map<std::string, KeyIndex<S256KeyType>> s256_file_id; 111 static const boost::container::flat_map<std::string, KeyIndex<S256KeyType>> s256_file_id;