summaryrefslogtreecommitdiff
path: root/src/core/crypto/key_manager.cpp
diff options
context:
space:
mode:
authorGravatar Zach Hilman2018-08-21 21:12:53 -0400
committerGravatar Zach Hilman2018-08-23 11:53:30 -0400
commitccfd17638211140b97cbf43b8486a80221f47c9d (patch)
tree196ad320e78d43eaaf19faba99216dc749b39f18 /src/core/crypto/key_manager.cpp
parentkey_manager: Create keys dir if it dosen't exist (diff)
downloadyuzu-ccfd17638211140b97cbf43b8486a80221f47c9d.tar.gz
yuzu-ccfd17638211140b97cbf43b8486a80221f47c9d.tar.xz
yuzu-ccfd17638211140b97cbf43b8486a80221f47c9d.zip
key_manager: Eliminate indexed for loop
Diffstat (limited to 'src/core/crypto/key_manager.cpp')
-rw-r--r--src/core/crypto/key_manager.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp
index daa779434..0b14bf15c 100644
--- a/src/core/crypto/key_manager.cpp
+++ b/src/core/crypto/key_manager.cpp
@@ -100,14 +100,21 @@ Loader::ResultStatus DeriveSDKeys(std::array<Key256, 2>& sd_keys, const KeyManag
100 keys.GetKey(S256KeyType::SDKeySource, static_cast<u64>(SDKeyType::NCA)), 100 keys.GetKey(S256KeyType::SDKeySource, static_cast<u64>(SDKeyType::NCA)),
101 }; 101 };
102 102
103 AESCipher<Key128> cipher(sd_kek, Mode::ECB); 103 // Combine sources and seed
104 for (size_t i = 0; i < 2; ++i) { 104 for (auto& source : sd_key_sources) {
105 for (size_t j = 0; j < sd_key_sources[i].size(); ++j) 105 for (size_t i = 0; i < source.size(); ++i)
106 sd_key_sources[i][j] ^= sd_seed[j & 0xF]; 106 source[i] ^= sd_seed[i & 0xF];
107 cipher.Transcode(sd_key_sources[i].data(), sd_key_sources[i].size(), sd_keys[i].data(),
108 Op::Decrypt);
109 } 107 }
110 108
109 AESCipher<Key128> cipher(sd_kek, Mode::ECB);
110 // The transform manipulates sd_keys as part of the Transcode, so the return/output is
111 // unnecessary. This does not alter sd_keys_sources.
112 std::transform(sd_key_sources.begin(), sd_key_sources.end(), sd_keys.begin(),
113 sd_key_sources.begin(), [&cipher](const Key256& source, Key256& out) {
114 cipher.Transcode(source.data(), source.size(), out.data(), Op::Decrypt);
115 return source; ///< Return unaltered source to satisfy output requirement.
116 });
117
111 return Loader::ResultStatus::Success; 118 return Loader::ResultStatus::Success;
112} 119}
113 120