mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-07-04 23:31:19 +01:00
aes_util: Fix error involving reads of less than 0x10
Issues with block size are fixed by making all reads minimum length of 0x10
This commit is contained in:
parent
faa9e066ab
commit
99fbcb3bf2
1 changed files with 14 additions and 0 deletions
|
@ -82,11 +82,25 @@ void AESCipher<Key, KeySize>::Transcode(const u8* src, size_t size, u8* dest, Op
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const auto block_size = mbedtls_cipher_get_block_size(context);
|
const auto block_size = mbedtls_cipher_get_block_size(context);
|
||||||
|
if (size < block_size) {
|
||||||
|
std::vector<u8> block(block_size);
|
||||||
|
std::memcpy(block.data(), src, size);
|
||||||
|
Transcode(block.data(), block.size(), block.data(), op);
|
||||||
|
std::memcpy(dest, block.data(), size);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t offset = 0; offset < size; offset += block_size) {
|
for (size_t offset = 0; offset < size; offset += block_size) {
|
||||||
auto length = std::min<size_t>(block_size, size - offset);
|
auto length = std::min<size_t>(block_size, size - offset);
|
||||||
mbedtls_cipher_update(context, src + offset, length, dest + offset, &written);
|
mbedtls_cipher_update(context, src + offset, length, dest + offset, &written);
|
||||||
if (written != length) {
|
if (written != length) {
|
||||||
|
if (length < block_size) {
|
||||||
|
std::vector<u8> block(block_size);
|
||||||
|
std::memcpy(block.data(), src + offset, length);
|
||||||
|
Transcode(block.data(), block.size(), block.data(), op);
|
||||||
|
std::memcpy(dest + offset, block.data(), length);
|
||||||
|
return;
|
||||||
|
}
|
||||||
LOG_WARNING(Crypto, "Not all data was decrypted requested={:016X}, actual={:016X}.",
|
LOG_WARNING(Crypto, "Not all data was decrypted requested={:016X}, actual={:016X}.",
|
||||||
length, written);
|
length, written);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue