diff options
| author | 2018-09-19 19:53:11 +0800 | |
|---|---|---|
| committer | 2018-09-19 19:53:11 +0800 | |
| commit | c8f9bbbf859c0e38cf691b64c67761382fcebfc2 (patch) | |
| tree | 99529c2277a6b740a6e278985c5147fa649c5497 /src/core/crypto | |
| parent | Add 1D sampler for TLDS - TexelFetch (Mario Rabbids) (diff) | |
| parent | Merge pull request #1348 from ogniK5377/GetImageSize (diff) | |
| download | yuzu-c8f9bbbf859c0e38cf691b64c67761382fcebfc2.tar.gz yuzu-c8f9bbbf859c0e38cf691b64c67761382fcebfc2.tar.xz yuzu-c8f9bbbf859c0e38cf691b64c67761382fcebfc2.zip | |
Merge branch 'master' into tlds
Diffstat (limited to 'src/core/crypto')
| -rw-r--r-- | src/core/crypto/aes_util.cpp | 37 | ||||
| -rw-r--r-- | src/core/crypto/aes_util.h | 14 | ||||
| -rw-r--r-- | src/core/crypto/ctr_encryption_layer.cpp | 11 | ||||
| -rw-r--r-- | src/core/crypto/ctr_encryption_layer.h | 8 | ||||
| -rw-r--r-- | src/core/crypto/encryption_layer.cpp | 6 | ||||
| -rw-r--r-- | src/core/crypto/encryption_layer.h | 8 | ||||
| -rw-r--r-- | src/core/crypto/key_manager.cpp | 6 | ||||
| -rw-r--r-- | src/core/crypto/key_manager.h | 2 | ||||
| -rw-r--r-- | src/core/crypto/xts_encryption_layer.cpp | 4 | ||||
| -rw-r--r-- | src/core/crypto/xts_encryption_layer.h | 2 |
10 files changed, 51 insertions, 47 deletions
diff --git a/src/core/crypto/aes_util.cpp b/src/core/crypto/aes_util.cpp index 89ade5000..4be76bb43 100644 --- a/src/core/crypto/aes_util.cpp +++ b/src/core/crypto/aes_util.cpp | |||
| @@ -10,9 +10,9 @@ | |||
| 10 | 10 | ||
| 11 | namespace Core::Crypto { | 11 | namespace Core::Crypto { |
| 12 | namespace { | 12 | namespace { |
| 13 | std::vector<u8> CalculateNintendoTweak(size_t sector_id) { | 13 | std::vector<u8> CalculateNintendoTweak(std::size_t sector_id) { |
| 14 | std::vector<u8> out(0x10); | 14 | std::vector<u8> out(0x10); |
| 15 | for (size_t i = 0xF; i <= 0xF; --i) { | 15 | for (std::size_t i = 0xF; i <= 0xF; --i) { |
| 16 | out[i] = sector_id & 0xFF; | 16 | out[i] = sector_id & 0xFF; |
| 17 | sector_id >>= 8; | 17 | sector_id >>= 8; |
| 18 | } | 18 | } |
| @@ -20,11 +20,14 @@ std::vector<u8> CalculateNintendoTweak(size_t sector_id) { | |||
| 20 | } | 20 | } |
| 21 | } // Anonymous namespace | 21 | } // Anonymous namespace |
| 22 | 22 | ||
| 23 | static_assert(static_cast<size_t>(Mode::CTR) == static_cast<size_t>(MBEDTLS_CIPHER_AES_128_CTR), | 23 | static_assert(static_cast<std::size_t>(Mode::CTR) == |
| 24 | static_cast<std::size_t>(MBEDTLS_CIPHER_AES_128_CTR), | ||
| 24 | "CTR has incorrect value."); | 25 | "CTR has incorrect value."); |
| 25 | static_assert(static_cast<size_t>(Mode::ECB) == static_cast<size_t>(MBEDTLS_CIPHER_AES_128_ECB), | 26 | static_assert(static_cast<std::size_t>(Mode::ECB) == |
| 27 | static_cast<std::size_t>(MBEDTLS_CIPHER_AES_128_ECB), | ||
| 26 | "ECB has incorrect value."); | 28 | "ECB has incorrect value."); |
| 27 | static_assert(static_cast<size_t>(Mode::XTS) == static_cast<size_t>(MBEDTLS_CIPHER_AES_128_XTS), | 29 | static_assert(static_cast<std::size_t>(Mode::XTS) == |
| 30 | static_cast<std::size_t>(MBEDTLS_CIPHER_AES_128_XTS), | ||
| 28 | "XTS has incorrect value."); | 31 | "XTS has incorrect value."); |
| 29 | 32 | ||
| 30 | // Structure to hide mbedtls types from header file | 33 | // Structure to hide mbedtls types from header file |
| @@ -33,7 +36,7 @@ struct CipherContext { | |||
| 33 | mbedtls_cipher_context_t decryption_context; | 36 | mbedtls_cipher_context_t decryption_context; |
| 34 | }; | 37 | }; |
| 35 | 38 | ||
| 36 | template <typename Key, size_t KeySize> | 39 | template <typename Key, std::size_t KeySize> |
| 37 | Crypto::AESCipher<Key, KeySize>::AESCipher(Key key, Mode mode) | 40 | Crypto::AESCipher<Key, KeySize>::AESCipher(Key key, Mode mode) |
| 38 | : ctx(std::make_unique<CipherContext>()) { | 41 | : ctx(std::make_unique<CipherContext>()) { |
| 39 | mbedtls_cipher_init(&ctx->encryption_context); | 42 | mbedtls_cipher_init(&ctx->encryption_context); |
| @@ -54,26 +57,26 @@ Crypto::AESCipher<Key, KeySize>::AESCipher(Key key, Mode mode) | |||
| 54 | //"Failed to set key on mbedtls ciphers."); | 57 | //"Failed to set key on mbedtls ciphers."); |
| 55 | } | 58 | } |
| 56 | 59 | ||
| 57 | template <typename Key, size_t KeySize> | 60 | template <typename Key, std::size_t KeySize> |
| 58 | AESCipher<Key, KeySize>::~AESCipher() { | 61 | AESCipher<Key, KeySize>::~AESCipher() { |
| 59 | mbedtls_cipher_free(&ctx->encryption_context); | 62 | mbedtls_cipher_free(&ctx->encryption_context); |
| 60 | mbedtls_cipher_free(&ctx->decryption_context); | 63 | mbedtls_cipher_free(&ctx->decryption_context); |
| 61 | } | 64 | } |
| 62 | 65 | ||
| 63 | template <typename Key, size_t KeySize> | 66 | template <typename Key, std::size_t KeySize> |
| 64 | void AESCipher<Key, KeySize>::SetIV(std::vector<u8> iv) { | 67 | void AESCipher<Key, KeySize>::SetIV(std::vector<u8> iv) { |
| 65 | ASSERT_MSG((mbedtls_cipher_set_iv(&ctx->encryption_context, iv.data(), iv.size()) || | 68 | ASSERT_MSG((mbedtls_cipher_set_iv(&ctx->encryption_context, iv.data(), iv.size()) || |
| 66 | mbedtls_cipher_set_iv(&ctx->decryption_context, iv.data(), iv.size())) == 0, | 69 | mbedtls_cipher_set_iv(&ctx->decryption_context, iv.data(), iv.size())) == 0, |
| 67 | "Failed to set IV on mbedtls ciphers."); | 70 | "Failed to set IV on mbedtls ciphers."); |
| 68 | } | 71 | } |
| 69 | 72 | ||
| 70 | template <typename Key, size_t KeySize> | 73 | template <typename Key, std::size_t KeySize> |
| 71 | void AESCipher<Key, KeySize>::Transcode(const u8* src, size_t size, u8* dest, Op op) const { | 74 | void AESCipher<Key, KeySize>::Transcode(const u8* src, std::size_t size, u8* dest, Op op) const { |
| 72 | auto* const context = op == Op::Encrypt ? &ctx->encryption_context : &ctx->decryption_context; | 75 | auto* const context = op == Op::Encrypt ? &ctx->encryption_context : &ctx->decryption_context; |
| 73 | 76 | ||
| 74 | mbedtls_cipher_reset(context); | 77 | mbedtls_cipher_reset(context); |
| 75 | 78 | ||
| 76 | size_t written = 0; | 79 | std::size_t written = 0; |
| 77 | if (mbedtls_cipher_get_cipher_mode(context) == MBEDTLS_MODE_XTS) { | 80 | if (mbedtls_cipher_get_cipher_mode(context) == MBEDTLS_MODE_XTS) { |
| 78 | mbedtls_cipher_update(context, src, size, dest, &written); | 81 | mbedtls_cipher_update(context, src, size, dest, &written); |
| 79 | if (written != size) { | 82 | if (written != size) { |
| @@ -90,8 +93,8 @@ void AESCipher<Key, KeySize>::Transcode(const u8* src, size_t size, u8* dest, Op | |||
| 90 | return; | 93 | return; |
| 91 | } | 94 | } |
| 92 | 95 | ||
| 93 | for (size_t offset = 0; offset < size; offset += block_size) { | 96 | for (std::size_t offset = 0; offset < size; offset += block_size) { |
| 94 | auto length = std::min<size_t>(block_size, size - offset); | 97 | auto length = std::min<std::size_t>(block_size, size - offset); |
| 95 | mbedtls_cipher_update(context, src + offset, length, dest + offset, &written); | 98 | mbedtls_cipher_update(context, src + offset, length, dest + offset, &written); |
| 96 | if (written != length) { | 99 | if (written != length) { |
| 97 | if (length < block_size) { | 100 | if (length < block_size) { |
| @@ -110,12 +113,12 @@ void AESCipher<Key, KeySize>::Transcode(const u8* src, size_t size, u8* dest, Op | |||
| 110 | mbedtls_cipher_finish(context, nullptr, nullptr); | 113 | mbedtls_cipher_finish(context, nullptr, nullptr); |
| 111 | } | 114 | } |
| 112 | 115 | ||
| 113 | template <typename Key, size_t KeySize> | 116 | template <typename Key, std::size_t KeySize> |
| 114 | void AESCipher<Key, KeySize>::XTSTranscode(const u8* src, size_t size, u8* dest, size_t sector_id, | 117 | void AESCipher<Key, KeySize>::XTSTranscode(const u8* src, std::size_t size, u8* dest, |
| 115 | size_t sector_size, Op op) { | 118 | std::size_t sector_id, std::size_t sector_size, Op op) { |
| 116 | ASSERT_MSG(size % sector_size == 0, "XTS decryption size must be a multiple of sector size."); | 119 | ASSERT_MSG(size % sector_size == 0, "XTS decryption size must be a multiple of sector size."); |
| 117 | 120 | ||
| 118 | for (size_t i = 0; i < size; i += sector_size) { | 121 | for (std::size_t i = 0; i < size; i += sector_size) { |
| 119 | SetIV(CalculateNintendoTweak(sector_id++)); | 122 | SetIV(CalculateNintendoTweak(sector_id++)); |
| 120 | Transcode<u8, u8>(src + i, sector_size, dest + i, op); | 123 | Transcode<u8, u8>(src + i, sector_size, dest + i, op); |
| 121 | } | 124 | } |
diff --git a/src/core/crypto/aes_util.h b/src/core/crypto/aes_util.h index 8ce9d6612..edc4ab910 100644 --- a/src/core/crypto/aes_util.h +++ b/src/core/crypto/aes_util.h | |||
| @@ -25,7 +25,7 @@ enum class Op { | |||
| 25 | Decrypt, | 25 | Decrypt, |
| 26 | }; | 26 | }; |
| 27 | 27 | ||
| 28 | template <typename Key, size_t KeySize = sizeof(Key)> | 28 | template <typename Key, std::size_t KeySize = sizeof(Key)> |
| 29 | class AESCipher { | 29 | class AESCipher { |
| 30 | static_assert(std::is_same_v<Key, std::array<u8, KeySize>>, "Key must be std::array of u8."); | 30 | static_assert(std::is_same_v<Key, std::array<u8, KeySize>>, "Key must be std::array of u8."); |
| 31 | static_assert(KeySize == 0x10 || KeySize == 0x20, "KeySize must be 128 or 256."); | 31 | static_assert(KeySize == 0x10 || KeySize == 0x20, "KeySize must be 128 or 256."); |
| @@ -38,25 +38,25 @@ public: | |||
| 38 | void SetIV(std::vector<u8> iv); | 38 | void SetIV(std::vector<u8> iv); |
| 39 | 39 | ||
| 40 | template <typename Source, typename Dest> | 40 | template <typename Source, typename Dest> |
| 41 | void Transcode(const Source* src, size_t size, Dest* dest, Op op) const { | 41 | void Transcode(const Source* src, std::size_t size, Dest* dest, Op op) const { |
| 42 | static_assert(std::is_trivially_copyable_v<Source> && std::is_trivially_copyable_v<Dest>, | 42 | static_assert(std::is_trivially_copyable_v<Source> && std::is_trivially_copyable_v<Dest>, |
| 43 | "Transcode source and destination types must be trivially copyable."); | 43 | "Transcode source and destination types must be trivially copyable."); |
| 44 | Transcode(reinterpret_cast<const u8*>(src), size, reinterpret_cast<u8*>(dest), op); | 44 | Transcode(reinterpret_cast<const u8*>(src), size, reinterpret_cast<u8*>(dest), op); |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | void Transcode(const u8* src, size_t size, u8* dest, Op op) const; | 47 | void Transcode(const u8* src, std::size_t size, u8* dest, Op op) const; |
| 48 | 48 | ||
| 49 | template <typename Source, typename Dest> | 49 | template <typename Source, typename Dest> |
| 50 | void XTSTranscode(const Source* src, size_t size, Dest* dest, size_t sector_id, | 50 | void XTSTranscode(const Source* src, std::size_t size, Dest* dest, std::size_t sector_id, |
| 51 | size_t sector_size, Op op) { | 51 | std::size_t sector_size, Op op) { |
| 52 | static_assert(std::is_trivially_copyable_v<Source> && std::is_trivially_copyable_v<Dest>, | 52 | static_assert(std::is_trivially_copyable_v<Source> && std::is_trivially_copyable_v<Dest>, |
| 53 | "XTSTranscode source and destination types must be trivially copyable."); | 53 | "XTSTranscode source and destination types must be trivially copyable."); |
| 54 | XTSTranscode(reinterpret_cast<const u8*>(src), size, reinterpret_cast<u8*>(dest), sector_id, | 54 | XTSTranscode(reinterpret_cast<const u8*>(src), size, reinterpret_cast<u8*>(dest), sector_id, |
| 55 | sector_size, op); | 55 | sector_size, op); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | void XTSTranscode(const u8* src, size_t size, u8* dest, size_t sector_id, size_t sector_size, | 58 | void XTSTranscode(const u8* src, std::size_t size, u8* dest, std::size_t sector_id, |
| 59 | Op op); | 59 | std::size_t sector_size, Op op); |
| 60 | 60 | ||
| 61 | private: | 61 | private: |
| 62 | std::unique_ptr<CipherContext> ctx; | 62 | std::unique_ptr<CipherContext> ctx; |
diff --git a/src/core/crypto/ctr_encryption_layer.cpp b/src/core/crypto/ctr_encryption_layer.cpp index 296fad419..902841c77 100644 --- a/src/core/crypto/ctr_encryption_layer.cpp +++ b/src/core/crypto/ctr_encryption_layer.cpp | |||
| @@ -8,11 +8,12 @@ | |||
| 8 | 8 | ||
| 9 | namespace Core::Crypto { | 9 | namespace Core::Crypto { |
| 10 | 10 | ||
| 11 | CTREncryptionLayer::CTREncryptionLayer(FileSys::VirtualFile base_, Key128 key_, size_t base_offset) | 11 | CTREncryptionLayer::CTREncryptionLayer(FileSys::VirtualFile base_, Key128 key_, |
| 12 | std::size_t base_offset) | ||
| 12 | : EncryptionLayer(std::move(base_)), base_offset(base_offset), cipher(key_, Mode::CTR), | 13 | : EncryptionLayer(std::move(base_)), base_offset(base_offset), cipher(key_, Mode::CTR), |
| 13 | iv(16, 0) {} | 14 | iv(16, 0) {} |
| 14 | 15 | ||
| 15 | size_t CTREncryptionLayer::Read(u8* data, size_t length, size_t offset) const { | 16 | std::size_t CTREncryptionLayer::Read(u8* data, std::size_t length, std::size_t offset) const { |
| 16 | if (length == 0) | 17 | if (length == 0) |
| 17 | return 0; | 18 | return 0; |
| 18 | 19 | ||
| @@ -28,7 +29,7 @@ size_t CTREncryptionLayer::Read(u8* data, size_t length, size_t offset) const { | |||
| 28 | std::vector<u8> block = base->ReadBytes(0x10, offset - sector_offset); | 29 | std::vector<u8> block = base->ReadBytes(0x10, offset - sector_offset); |
| 29 | UpdateIV(base_offset + offset - sector_offset); | 30 | UpdateIV(base_offset + offset - sector_offset); |
| 30 | cipher.Transcode(block.data(), block.size(), block.data(), Op::Decrypt); | 31 | cipher.Transcode(block.data(), block.size(), block.data(), Op::Decrypt); |
| 31 | size_t read = 0x10 - sector_offset; | 32 | std::size_t read = 0x10 - sector_offset; |
| 32 | 33 | ||
| 33 | if (length + sector_offset < 0x10) { | 34 | if (length + sector_offset < 0x10) { |
| 34 | std::memcpy(data, block.data() + sector_offset, std::min<u64>(length, read)); | 35 | std::memcpy(data, block.data() + sector_offset, std::min<u64>(length, read)); |
| @@ -43,9 +44,9 @@ void CTREncryptionLayer::SetIV(const std::vector<u8>& iv_) { | |||
| 43 | iv.assign(iv_.cbegin(), iv_.cbegin() + length); | 44 | iv.assign(iv_.cbegin(), iv_.cbegin() + length); |
| 44 | } | 45 | } |
| 45 | 46 | ||
| 46 | void CTREncryptionLayer::UpdateIV(size_t offset) const { | 47 | void CTREncryptionLayer::UpdateIV(std::size_t offset) const { |
| 47 | offset >>= 4; | 48 | offset >>= 4; |
| 48 | for (size_t i = 0; i < 8; ++i) { | 49 | for (std::size_t i = 0; i < 8; ++i) { |
| 49 | iv[16 - i - 1] = offset & 0xFF; | 50 | iv[16 - i - 1] = offset & 0xFF; |
| 50 | offset >>= 8; | 51 | offset >>= 8; |
| 51 | } | 52 | } |
diff --git a/src/core/crypto/ctr_encryption_layer.h b/src/core/crypto/ctr_encryption_layer.h index 11b8683c7..a7bf810f4 100644 --- a/src/core/crypto/ctr_encryption_layer.h +++ b/src/core/crypto/ctr_encryption_layer.h | |||
| @@ -14,20 +14,20 @@ namespace Core::Crypto { | |||
| 14 | // Sits on top of a VirtualFile and provides CTR-mode AES decription. | 14 | // Sits on top of a VirtualFile and provides CTR-mode AES decription. |
| 15 | class CTREncryptionLayer : public EncryptionLayer { | 15 | class CTREncryptionLayer : public EncryptionLayer { |
| 16 | public: | 16 | public: |
| 17 | CTREncryptionLayer(FileSys::VirtualFile base, Key128 key, size_t base_offset); | 17 | CTREncryptionLayer(FileSys::VirtualFile base, Key128 key, std::size_t base_offset); |
| 18 | 18 | ||
| 19 | size_t Read(u8* data, size_t length, size_t offset) const override; | 19 | std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override; |
| 20 | 20 | ||
| 21 | void SetIV(const std::vector<u8>& iv); | 21 | void SetIV(const std::vector<u8>& iv); |
| 22 | 22 | ||
| 23 | private: | 23 | private: |
| 24 | size_t base_offset; | 24 | std::size_t base_offset; |
| 25 | 25 | ||
| 26 | // Must be mutable as operations modify cipher contexts. | 26 | // Must be mutable as operations modify cipher contexts. |
| 27 | mutable AESCipher<Key128> cipher; | 27 | mutable AESCipher<Key128> cipher; |
| 28 | mutable std::vector<u8> iv; | 28 | mutable std::vector<u8> iv; |
| 29 | 29 | ||
| 30 | void UpdateIV(size_t offset) const; | 30 | void UpdateIV(std::size_t offset) const; |
| 31 | }; | 31 | }; |
| 32 | 32 | ||
| 33 | } // namespace Core::Crypto | 33 | } // namespace Core::Crypto |
diff --git a/src/core/crypto/encryption_layer.cpp b/src/core/crypto/encryption_layer.cpp index 4204527e3..4c377d7d4 100644 --- a/src/core/crypto/encryption_layer.cpp +++ b/src/core/crypto/encryption_layer.cpp | |||
| @@ -12,11 +12,11 @@ std::string EncryptionLayer::GetName() const { | |||
| 12 | return base->GetName(); | 12 | return base->GetName(); |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | size_t EncryptionLayer::GetSize() const { | 15 | std::size_t EncryptionLayer::GetSize() const { |
| 16 | return base->GetSize(); | 16 | return base->GetSize(); |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | bool EncryptionLayer::Resize(size_t new_size) { | 19 | bool EncryptionLayer::Resize(std::size_t new_size) { |
| 20 | return false; | 20 | return false; |
| 21 | } | 21 | } |
| 22 | 22 | ||
| @@ -32,7 +32,7 @@ bool EncryptionLayer::IsReadable() const { | |||
| 32 | return true; | 32 | return true; |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | size_t EncryptionLayer::Write(const u8* data, size_t length, size_t offset) { | 35 | std::size_t EncryptionLayer::Write(const u8* data, std::size_t length, std::size_t offset) { |
| 36 | return 0; | 36 | return 0; |
| 37 | } | 37 | } |
| 38 | 38 | ||
diff --git a/src/core/crypto/encryption_layer.h b/src/core/crypto/encryption_layer.h index 7f05af9b4..53619cb38 100644 --- a/src/core/crypto/encryption_layer.h +++ b/src/core/crypto/encryption_layer.h | |||
| @@ -15,15 +15,15 @@ class EncryptionLayer : public FileSys::VfsFile { | |||
| 15 | public: | 15 | public: |
| 16 | explicit EncryptionLayer(FileSys::VirtualFile base); | 16 | explicit EncryptionLayer(FileSys::VirtualFile base); |
| 17 | 17 | ||
| 18 | size_t Read(u8* data, size_t length, size_t offset) const override = 0; | 18 | std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override = 0; |
| 19 | 19 | ||
| 20 | std::string GetName() const override; | 20 | std::string GetName() const override; |
| 21 | size_t GetSize() const override; | 21 | std::size_t GetSize() const override; |
| 22 | bool Resize(size_t new_size) override; | 22 | bool Resize(std::size_t new_size) override; |
| 23 | std::shared_ptr<FileSys::VfsDirectory> GetContainingDirectory() const override; | 23 | std::shared_ptr<FileSys::VfsDirectory> GetContainingDirectory() const override; |
| 24 | bool IsWritable() const override; | 24 | bool IsWritable() const override; |
| 25 | bool IsReadable() const override; | 25 | bool IsReadable() const override; |
| 26 | size_t Write(const u8* data, size_t length, size_t offset) override; | 26 | std::size_t Write(const u8* data, std::size_t length, std::size_t offset) override; |
| 27 | bool Rename(std::string_view name) override; | 27 | bool Rename(std::string_view name) override; |
| 28 | 28 | ||
| 29 | protected: | 29 | protected: |
diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp index 6f27f990b..bf3a70944 100644 --- a/src/core/crypto/key_manager.cpp +++ b/src/core/crypto/key_manager.cpp | |||
| @@ -54,7 +54,7 @@ boost::optional<Key128> DeriveSDSeed() { | |||
| 54 | return boost::none; | 54 | return boost::none; |
| 55 | 55 | ||
| 56 | std::array<u8, 0x10> buffer{}; | 56 | std::array<u8, 0x10> buffer{}; |
| 57 | size_t offset = 0; | 57 | std::size_t offset = 0; |
| 58 | for (; offset + 0x10 < save_43.GetSize(); ++offset) { | 58 | for (; offset + 0x10 < save_43.GetSize(); ++offset) { |
| 59 | save_43.Seek(offset, SEEK_SET); | 59 | save_43.Seek(offset, SEEK_SET); |
| 60 | save_43.ReadBytes(buffer.data(), buffer.size()); | 60 | save_43.ReadBytes(buffer.data(), buffer.size()); |
| @@ -105,7 +105,7 @@ Loader::ResultStatus DeriveSDKeys(std::array<Key256, 2>& sd_keys, const KeyManag | |||
| 105 | 105 | ||
| 106 | // Combine sources and seed | 106 | // Combine sources and seed |
| 107 | for (auto& source : sd_key_sources) { | 107 | for (auto& source : sd_key_sources) { |
| 108 | for (size_t i = 0; i < source.size(); ++i) | 108 | for (std::size_t i = 0; i < source.size(); ++i) |
| 109 | source[i] ^= sd_seed[i & 0xF]; | 109 | source[i] ^= sd_seed[i & 0xF]; |
| 110 | } | 110 | } |
| 111 | 111 | ||
| @@ -207,7 +207,7 @@ Key256 KeyManager::GetKey(S256KeyType id, u64 field1, u64 field2) const { | |||
| 207 | return s256_keys.at({id, field1, field2}); | 207 | return s256_keys.at({id, field1, field2}); |
| 208 | } | 208 | } |
| 209 | 209 | ||
| 210 | template <size_t Size> | 210 | template <std::size_t Size> |
| 211 | void KeyManager::WriteKeyToFile(bool title_key, std::string_view keyname, | 211 | void KeyManager::WriteKeyToFile(bool title_key, std::string_view keyname, |
| 212 | const std::array<u8, Size>& key) { | 212 | const std::array<u8, Size>& key) { |
| 213 | const std::string yuzu_keys_dir = FileUtil::GetUserPath(FileUtil::UserPath::KeysDir); | 213 | const std::string yuzu_keys_dir = FileUtil::GetUserPath(FileUtil::UserPath::KeysDir); |
diff --git a/src/core/crypto/key_manager.h b/src/core/crypto/key_manager.h index ce67913bb..978eec8dc 100644 --- a/src/core/crypto/key_manager.h +++ b/src/core/crypto/key_manager.h | |||
| @@ -108,7 +108,7 @@ private: | |||
| 108 | void LoadFromFile(const std::string& filename, bool is_title_keys); | 108 | void LoadFromFile(const std::string& filename, bool is_title_keys); |
| 109 | void AttemptLoadKeyFile(const std::string& dir1, const std::string& dir2, | 109 | void AttemptLoadKeyFile(const std::string& dir1, const std::string& dir2, |
| 110 | const std::string& filename, bool title); | 110 | const std::string& filename, bool title); |
| 111 | template <size_t Size> | 111 | template <std::size_t Size> |
| 112 | void WriteKeyToFile(bool title_key, std::string_view keyname, const std::array<u8, Size>& key); | 112 | void WriteKeyToFile(bool title_key, std::string_view keyname, const std::array<u8, Size>& key); |
| 113 | 113 | ||
| 114 | static const boost::container::flat_map<std::string, KeyIndex<S128KeyType>> s128_file_id; | 114 | static const boost::container::flat_map<std::string, KeyIndex<S128KeyType>> s128_file_id; |
diff --git a/src/core/crypto/xts_encryption_layer.cpp b/src/core/crypto/xts_encryption_layer.cpp index c10832cfe..8f0ba4ee7 100644 --- a/src/core/crypto/xts_encryption_layer.cpp +++ b/src/core/crypto/xts_encryption_layer.cpp | |||
| @@ -14,7 +14,7 @@ constexpr u64 XTS_SECTOR_SIZE = 0x4000; | |||
| 14 | XTSEncryptionLayer::XTSEncryptionLayer(FileSys::VirtualFile base_, Key256 key_) | 14 | XTSEncryptionLayer::XTSEncryptionLayer(FileSys::VirtualFile base_, Key256 key_) |
| 15 | : EncryptionLayer(std::move(base_)), cipher(key_, Mode::XTS) {} | 15 | : EncryptionLayer(std::move(base_)), cipher(key_, Mode::XTS) {} |
| 16 | 16 | ||
| 17 | size_t XTSEncryptionLayer::Read(u8* data, size_t length, size_t offset) const { | 17 | std::size_t XTSEncryptionLayer::Read(u8* data, std::size_t length, std::size_t offset) const { |
| 18 | if (length == 0) | 18 | if (length == 0) |
| 19 | return 0; | 19 | return 0; |
| 20 | 20 | ||
| @@ -46,7 +46,7 @@ size_t XTSEncryptionLayer::Read(u8* data, size_t length, size_t offset) const { | |||
| 46 | block.resize(XTS_SECTOR_SIZE); | 46 | block.resize(XTS_SECTOR_SIZE); |
| 47 | cipher.XTSTranscode(block.data(), block.size(), block.data(), | 47 | cipher.XTSTranscode(block.data(), block.size(), block.data(), |
| 48 | (offset - sector_offset) / XTS_SECTOR_SIZE, XTS_SECTOR_SIZE, Op::Decrypt); | 48 | (offset - sector_offset) / XTS_SECTOR_SIZE, XTS_SECTOR_SIZE, Op::Decrypt); |
| 49 | const size_t read = XTS_SECTOR_SIZE - sector_offset; | 49 | const std::size_t read = XTS_SECTOR_SIZE - sector_offset; |
| 50 | 50 | ||
| 51 | if (length + sector_offset < XTS_SECTOR_SIZE) { | 51 | if (length + sector_offset < XTS_SECTOR_SIZE) { |
| 52 | std::memcpy(data, block.data() + sector_offset, std::min<u64>(length, read)); | 52 | std::memcpy(data, block.data() + sector_offset, std::min<u64>(length, read)); |
diff --git a/src/core/crypto/xts_encryption_layer.h b/src/core/crypto/xts_encryption_layer.h index 7a1f1dc64..5f8f00fe7 100644 --- a/src/core/crypto/xts_encryption_layer.h +++ b/src/core/crypto/xts_encryption_layer.h | |||
| @@ -15,7 +15,7 @@ class XTSEncryptionLayer : public EncryptionLayer { | |||
| 15 | public: | 15 | public: |
| 16 | XTSEncryptionLayer(FileSys::VirtualFile base, Key256 key); | 16 | XTSEncryptionLayer(FileSys::VirtualFile base, Key256 key); |
| 17 | 17 | ||
| 18 | size_t Read(u8* data, size_t length, size_t offset) const override; | 18 | std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override; |
| 19 | 19 | ||
| 20 | private: | 20 | private: |
| 21 | // Must be mutable as operations modify cipher contexts. | 21 | // Must be mutable as operations modify cipher contexts. |