From 8da651ac4d25fbb48f77b8331b61f3cfa26e8f2c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 4 Aug 2018 16:41:17 -0400 Subject: core/crypto: Remove unnecessary includes --- src/core/crypto/aes_util.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/core/crypto/aes_util.cpp') diff --git a/src/core/crypto/aes_util.cpp b/src/core/crypto/aes_util.cpp index 4690af5f8..3d939da15 100644 --- a/src/core/crypto/aes_util.cpp +++ b/src/core/crypto/aes_util.cpp @@ -3,6 +3,8 @@ // Refer to the license.txt file included. #include +#include "common/assert.h" +#include "common/logging/log.h" #include "core/crypto/aes_util.h" #include "core/crypto/key_manager.h" -- cgit v1.2.3 From b25468b4980d2e57c5e94808130196542e568282 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 4 Aug 2018 16:49:39 -0400 Subject: aes_util: Make Transcode() a const member function This doesn't modify member state, so it can be made const. --- src/core/crypto/aes_util.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/core/crypto/aes_util.cpp') diff --git a/src/core/crypto/aes_util.cpp b/src/core/crypto/aes_util.cpp index 3d939da15..e2dc4acb3 100644 --- a/src/core/crypto/aes_util.cpp +++ b/src/core/crypto/aes_util.cpp @@ -58,27 +58,28 @@ void AESCipher::SetIV(std::vector iv) { } template -void AESCipher::Transcode(const u8* src, size_t size, u8* dest, Op op) { - size_t written = 0; - - const auto context = op == Op::Encrypt ? &ctx->encryption_context : &ctx->decryption_context; +void AESCipher::Transcode(const u8* src, size_t size, u8* dest, Op op) const { + auto* const context = op == Op::Encrypt ? &ctx->encryption_context : &ctx->decryption_context; mbedtls_cipher_reset(context); + size_t written = 0; if (mbedtls_cipher_get_cipher_mode(context) == MBEDTLS_MODE_XTS) { mbedtls_cipher_update(context, src, size, dest, &written); - if (written != size) + if (written != size) { LOG_WARNING(Crypto, "Not all data was decrypted requested={:016X}, actual={:016X}.", size, written); + } } else { const auto block_size = mbedtls_cipher_get_block_size(context); 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 (written != length) { LOG_WARNING(Crypto, "Not all data was decrypted requested={:016X}, actual={:016X}.", length, written); + } } } -- cgit v1.2.3 From 64c8212ae1168e86693d05875f4284330e52f26d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 4 Aug 2018 16:52:19 -0400 Subject: aes_util: Make CalculateNintendoTweak() an internally linked function This function doesn't directly depend on class state, so it can be hidden entirely from the interface in the cpp file. --- src/core/crypto/aes_util.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/core/crypto/aes_util.cpp') diff --git a/src/core/crypto/aes_util.cpp b/src/core/crypto/aes_util.cpp index e2dc4acb3..a9876c83e 100644 --- a/src/core/crypto/aes_util.cpp +++ b/src/core/crypto/aes_util.cpp @@ -9,6 +9,16 @@ #include "core/crypto/key_manager.h" namespace Core::Crypto { +namespace { +std::vector CalculateNintendoTweak(size_t sector_id) { + std::vector out(0x10); + for (size_t i = 0xF; i <= 0xF; --i) { + out[i] = sector_id & 0xFF; + sector_id >>= 8; + } + return out; +} +} // Anonymous namespace static_assert(static_cast(Mode::CTR) == static_cast(MBEDTLS_CIPHER_AES_128_CTR), "CTR has incorrect value."); @@ -100,16 +110,6 @@ void AESCipher::XTSTranscode(const u8* src, size_t size, u8* dest, } } -template -std::vector AESCipher::CalculateNintendoTweak(size_t sector_id) { - std::vector out(0x10); - for (size_t i = 0xF; i <= 0xF; --i) { - out[i] = sector_id & 0xFF; - sector_id >>= 8; - } - return out; -} - template class AESCipher; template class AESCipher; } // namespace Core::Crypto \ No newline at end of file -- cgit v1.2.3