From 99fbcb3bf2ddeb0e95ee4b7ce891f46f44447af3 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Sat, 25 Aug 2018 18:56:25 -0400 Subject: aes_util: Fix error involving reads of less than 0x10 Issues with block size are fixed by making all reads minimum length of 0x10 --- src/core/crypto/aes_util.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/core') 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::Transcode(const u8* src, size_t size, u8* dest, Op } } else { const auto block_size = mbedtls_cipher_get_block_size(context); + if (size < block_size) { + std::vector 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) { auto length = std::min(block_size, size - offset); mbedtls_cipher_update(context, src + offset, length, dest + offset, &written); if (written != length) { + if (length < block_size) { + std::vector 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}.", length, written); } -- cgit v1.2.3