diff options
| author | 2018-08-25 18:56:25 -0400 | |
|---|---|---|
| committer | 2018-09-04 16:21:40 -0400 | |
| commit | 99fbcb3bf2ddeb0e95ee4b7ce891f46f44447af3 (patch) | |
| tree | 1e33310cb59f8c6b8a0da38854d8581716453ad7 /src/core/crypto/aes_util.cpp | |
| parent | Merge pull request #1178 from DarkLordZach/nsp (diff) | |
| download | yuzu-99fbcb3bf2ddeb0e95ee4b7ce891f46f44447af3.tar.gz yuzu-99fbcb3bf2ddeb0e95ee4b7ce891f46f44447af3.tar.xz yuzu-99fbcb3bf2ddeb0e95ee4b7ce891f46f44447af3.zip | |
aes_util: Fix error involving reads of less than 0x10
Issues with block size are fixed by making all reads minimum length of 0x10
Diffstat (limited to 'src/core/crypto/aes_util.cpp')
| -rw-r--r-- | src/core/crypto/aes_util.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/core/crypto/aes_util.cpp b/src/core/crypto/aes_util.cpp index 72e4bed67..89ade5000 100644 --- a/src/core/crypto/aes_util.cpp +++ b/src/core/crypto/aes_util.cpp | |||
| @@ -82,11 +82,25 @@ void AESCipher<Key, KeySize>::Transcode(const u8* src, size_t size, u8* dest, Op | |||
| 82 | } | 82 | } |
| 83 | } else { | 83 | } else { |
| 84 | const auto block_size = mbedtls_cipher_get_block_size(context); | 84 | const auto block_size = mbedtls_cipher_get_block_size(context); |
| 85 | if (size < block_size) { | ||
| 86 | std::vector<u8> block(block_size); | ||
| 87 | std::memcpy(block.data(), src, size); | ||
| 88 | Transcode(block.data(), block.size(), block.data(), op); | ||
| 89 | std::memcpy(dest, block.data(), size); | ||
| 90 | return; | ||
| 91 | } | ||
| 85 | 92 | ||
| 86 | for (size_t offset = 0; offset < size; offset += block_size) { | 93 | for (size_t offset = 0; offset < size; offset += block_size) { |
| 87 | auto length = std::min<size_t>(block_size, size - offset); | 94 | auto length = std::min<size_t>(block_size, size - offset); |
| 88 | mbedtls_cipher_update(context, src + offset, length, dest + offset, &written); | 95 | mbedtls_cipher_update(context, src + offset, length, dest + offset, &written); |
| 89 | if (written != length) { | 96 | if (written != length) { |
| 97 | if (length < block_size) { | ||
| 98 | std::vector<u8> block(block_size); | ||
| 99 | std::memcpy(block.data(), src + offset, length); | ||
| 100 | Transcode(block.data(), block.size(), block.data(), op); | ||
| 101 | std::memcpy(dest + offset, block.data(), length); | ||
| 102 | return; | ||
| 103 | } | ||
| 90 | LOG_WARNING(Crypto, "Not all data was decrypted requested={:016X}, actual={:016X}.", | 104 | LOG_WARNING(Crypto, "Not all data was decrypted requested={:016X}, actual={:016X}.", |
| 91 | length, written); | 105 | length, written); |
| 92 | } | 106 | } |