diff options
| author | 2018-10-13 09:13:19 -0400 | |
|---|---|---|
| committer | 2018-10-13 09:13:19 -0400 | |
| commit | 6da2ed4232d3b3ecde7a04621c554f66de558fab (patch) | |
| tree | 83184a61eecca6dcc5f543a5f69f93234eacdbc6 /src | |
| parent | partition_data_manager: Dehardcode array bounds (diff) | |
| download | yuzu-6da2ed4232d3b3ecde7a04621c554f66de558fab.tar.gz yuzu-6da2ed4232d3b3ecde7a04621c554f66de558fab.tar.xz yuzu-6da2ed4232d3b3ecde7a04621c554f66de558fab.zip | |
key_manager/partition_data_manager: Silence truncation compiler warnings
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/crypto/key_manager.cpp | 7 | ||||
| -rw-r--r-- | src/core/crypto/key_manager.h | 2 | ||||
| -rw-r--r-- | src/core/crypto/partition_data_manager.cpp | 12 | ||||
| -rw-r--r-- | src/core/crypto/partition_data_manager.h | 4 |
4 files changed, 15 insertions, 10 deletions
diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp index d2ce4f5bf..fd0786068 100644 --- a/src/core/crypto/key_manager.cpp +++ b/src/core/crypto/key_manager.cpp | |||
| @@ -98,7 +98,7 @@ std::array<u8, 144> DecryptKeyblob(const std::array<u8, 176>& encrypted_keyblob, | |||
| 98 | return keyblob; | 98 | return keyblob; |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | void KeyManager::DeriveGeneralPurposeKeys(u8 crypto_revision) { | 101 | void KeyManager::DeriveGeneralPurposeKeys(std::size_t crypto_revision) { |
| 102 | const auto kek_generation_source = | 102 | const auto kek_generation_source = |
| 103 | GetKey(S128KeyType::Source, static_cast<u64>(SourceKeyType::AESKekGeneration)); | 103 | GetKey(S128KeyType::Source, static_cast<u64>(SourceKeyType::AESKekGeneration)); |
| 104 | const auto key_generation_source = | 104 | const auto key_generation_source = |
| @@ -270,6 +270,9 @@ static std::array<u8, size> operator^(const std::array<u8, size>& lhs, | |||
| 270 | 270 | ||
| 271 | template <size_t target_size, size_t in_size> | 271 | template <size_t target_size, size_t in_size> |
| 272 | static std::array<u8, target_size> MGF1(const std::array<u8, in_size>& seed) { | 272 | static std::array<u8, target_size> MGF1(const std::array<u8, in_size>& seed) { |
| 273 | // Avoids truncation overflow within the loop below. | ||
| 274 | static_assert(target_size <= 0xFF); | ||
| 275 | |||
| 273 | std::array<u8, in_size + 4> seed_exp{}; | 276 | std::array<u8, in_size + 4> seed_exp{}; |
| 274 | std::memcpy(seed_exp.data(), seed.data(), in_size); | 277 | std::memcpy(seed_exp.data(), seed.data(), in_size); |
| 275 | 278 | ||
| @@ -277,7 +280,7 @@ static std::array<u8, target_size> MGF1(const std::array<u8, in_size>& seed) { | |||
| 277 | size_t i = 0; | 280 | size_t i = 0; |
| 278 | while (out.size() < target_size) { | 281 | while (out.size() < target_size) { |
| 279 | out.resize(out.size() + 0x20); | 282 | out.resize(out.size() + 0x20); |
| 280 | seed_exp[in_size + 3] = i; | 283 | seed_exp[in_size + 3] = static_cast<u8>(i); |
| 281 | mbedtls_sha256(seed_exp.data(), seed_exp.size(), out.data() + out.size() - 0x20, 0); | 284 | mbedtls_sha256(seed_exp.data(), seed_exp.size(), out.data() + out.size() - 0x20, 0); |
| 282 | ++i; | 285 | ++i; |
| 283 | } | 286 | } |
diff --git a/src/core/crypto/key_manager.h b/src/core/crypto/key_manager.h index a41abbdfc..cccb3c0ae 100644 --- a/src/core/crypto/key_manager.h +++ b/src/core/crypto/key_manager.h | |||
| @@ -175,7 +175,7 @@ private: | |||
| 175 | void WriteKeyToFile(KeyCategory category, std::string_view keyname, | 175 | void WriteKeyToFile(KeyCategory category, std::string_view keyname, |
| 176 | const std::array<u8, Size>& key); | 176 | const std::array<u8, Size>& key); |
| 177 | 177 | ||
| 178 | void DeriveGeneralPurposeKeys(u8 crypto_revision); | 178 | void DeriveGeneralPurposeKeys(std::size_t crypto_revision); |
| 179 | 179 | ||
| 180 | void SetKeyWrapped(S128KeyType id, Key128 key, u64 field1 = 0, u64 field2 = 0); | 180 | void SetKeyWrapped(S128KeyType id, Key128 key, u64 field1 = 0, u64 field2 = 0); |
| 181 | void SetKeyWrapped(S256KeyType id, Key256 key, u64 field1 = 0, u64 field2 = 0); | 181 | void SetKeyWrapped(S256KeyType id, Key256 key, u64 field1 = 0, u64 field2 = 0); |
diff --git a/src/core/crypto/partition_data_manager.cpp b/src/core/crypto/partition_data_manager.cpp index bef8cdaf0..51d89508b 100644 --- a/src/core/crypto/partition_data_manager.cpp +++ b/src/core/crypto/partition_data_manager.cpp | |||
| @@ -332,7 +332,8 @@ FileSys::VirtualFile PartitionDataManager::GetBoot0Raw() const { | |||
| 332 | return boot0; | 332 | return boot0; |
| 333 | } | 333 | } |
| 334 | 334 | ||
| 335 | PartitionDataManager::EncryptedKeyBlob PartitionDataManager::GetEncryptedKeyblob(u8 index) const { | 335 | PartitionDataManager::EncryptedKeyBlob PartitionDataManager::GetEncryptedKeyblob( |
| 336 | std::size_t index) const { | ||
| 336 | if (HasBoot0() && index < NUM_ENCRYPTED_KEYBLOBS) | 337 | if (HasBoot0() && index < NUM_ENCRYPTED_KEYBLOBS) |
| 337 | return GetEncryptedKeyblobs()[index]; | 338 | return GetEncryptedKeyblobs()[index]; |
| 338 | return {}; | 339 | return {}; |
| @@ -389,7 +390,7 @@ std::array<u8, 16> PartitionDataManager::GetKeyblobMACKeySource() const { | |||
| 389 | return FindKeyFromHex(package1_decrypted_bytes, source_hashes[0]); | 390 | return FindKeyFromHex(package1_decrypted_bytes, source_hashes[0]); |
| 390 | } | 391 | } |
| 391 | 392 | ||
| 392 | std::array<u8, 16> PartitionDataManager::GetKeyblobKeySource(u8 revision) const { | 393 | std::array<u8, 16> PartitionDataManager::GetKeyblobKeySource(std::size_t revision) const { |
| 393 | if (keyblob_source_hashes[revision] == SHA256Hash{}) { | 394 | if (keyblob_source_hashes[revision] == SHA256Hash{}) { |
| 394 | LOG_WARNING(Crypto, | 395 | LOG_WARNING(Crypto, |
| 395 | "No keyblob source hash for crypto revision {:02X}! Cannot derive keys...", | 396 | "No keyblob source hash for crypto revision {:02X}! Cannot derive keys...", |
| @@ -456,11 +457,12 @@ void PartitionDataManager::DecryptPackage2(std::array<std::array<u8, 16>, 0x20> | |||
| 456 | if (file->ReadObject(&header) != sizeof(Package2Header)) | 457 | if (file->ReadObject(&header) != sizeof(Package2Header)) |
| 457 | return; | 458 | return; |
| 458 | 459 | ||
| 459 | u8 revision = 0xFF; | 460 | std::size_t revision = 0xFF; |
| 460 | if (header.magic != Common::MakeMagic('P', 'K', '2', '1')) { | 461 | if (header.magic != Common::MakeMagic('P', 'K', '2', '1')) { |
| 461 | for (size_t i = 0; i < package2_keys.size(); ++i) { | 462 | for (std::size_t i = 0; i < package2_keys.size(); ++i) { |
| 462 | if (AttemptDecrypt(package2_keys[i], header)) | 463 | if (AttemptDecrypt(package2_keys[i], header)) { |
| 463 | revision = i; | 464 | revision = i; |
| 465 | } | ||
| 464 | } | 466 | } |
| 465 | } | 467 | } |
| 466 | 468 | ||
diff --git a/src/core/crypto/partition_data_manager.h b/src/core/crypto/partition_data_manager.h index 7c9c4410a..9e448f720 100644 --- a/src/core/crypto/partition_data_manager.h +++ b/src/core/crypto/partition_data_manager.h | |||
| @@ -34,7 +34,7 @@ public: | |||
| 34 | // BOOT0 | 34 | // BOOT0 |
| 35 | bool HasBoot0() const; | 35 | bool HasBoot0() const; |
| 36 | FileSys::VirtualFile GetBoot0Raw() const; | 36 | FileSys::VirtualFile GetBoot0Raw() const; |
| 37 | EncryptedKeyBlob GetEncryptedKeyblob(u8 index) const; | 37 | EncryptedKeyBlob GetEncryptedKeyblob(std::size_t index) const; |
| 38 | EncryptedKeyBlobs GetEncryptedKeyblobs() const; | 38 | EncryptedKeyBlobs GetEncryptedKeyblobs() const; |
| 39 | std::vector<u8> GetSecureMonitor() const; | 39 | std::vector<u8> GetSecureMonitor() const; |
| 40 | std::array<u8, 0x10> GetPackage2KeySource() const; | 40 | std::array<u8, 0x10> GetPackage2KeySource() const; |
| @@ -46,7 +46,7 @@ public: | |||
| 46 | std::vector<u8> GetPackage1Decrypted() const; | 46 | std::vector<u8> GetPackage1Decrypted() const; |
| 47 | std::array<u8, 0x10> GetMasterKeySource() const; | 47 | std::array<u8, 0x10> GetMasterKeySource() const; |
| 48 | std::array<u8, 0x10> GetKeyblobMACKeySource() const; | 48 | std::array<u8, 0x10> GetKeyblobMACKeySource() const; |
| 49 | std::array<u8, 0x10> GetKeyblobKeySource(u8 revision) const; | 49 | std::array<u8, 0x10> GetKeyblobKeySource(std::size_t revision) const; |
| 50 | 50 | ||
| 51 | // Fuses | 51 | // Fuses |
| 52 | bool HasFuses() const; | 52 | bool HasFuses() const; |