diff options
| author | 2018-08-04 16:49:39 -0400 | |
|---|---|---|
| committer | 2018-08-04 16:49:42 -0400 | |
| commit | b25468b4980d2e57c5e94808130196542e568282 (patch) | |
| tree | eb504e6526e1a9dcc44af7d5f8631b51669975fc /src/core/crypto/aes_util.cpp | |
| parent | core/crypto: Remove unnecessary includes (diff) | |
| download | yuzu-b25468b4980d2e57c5e94808130196542e568282.tar.gz yuzu-b25468b4980d2e57c5e94808130196542e568282.tar.xz yuzu-b25468b4980d2e57c5e94808130196542e568282.zip | |
aes_util: Make Transcode() a const member function
This doesn't modify member state, so it can be made const.
Diffstat (limited to 'src/core/crypto/aes_util.cpp')
| -rw-r--r-- | src/core/crypto/aes_util.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
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<Key, KeySize>::SetIV(std::vector<u8> iv) { | |||
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | template <typename Key, size_t KeySize> | 60 | template <typename Key, size_t KeySize> |
| 61 | void AESCipher<Key, KeySize>::Transcode(const u8* src, size_t size, u8* dest, Op op) { | 61 | void AESCipher<Key, KeySize>::Transcode(const u8* src, size_t size, u8* dest, Op op) const { |
| 62 | size_t written = 0; | 62 | auto* const context = op == Op::Encrypt ? &ctx->encryption_context : &ctx->decryption_context; |
| 63 | |||
| 64 | const auto context = op == Op::Encrypt ? &ctx->encryption_context : &ctx->decryption_context; | ||
| 65 | 63 | ||
| 66 | mbedtls_cipher_reset(context); | 64 | mbedtls_cipher_reset(context); |
| 67 | 65 | ||
| 66 | size_t written = 0; | ||
| 68 | if (mbedtls_cipher_get_cipher_mode(context) == MBEDTLS_MODE_XTS) { | 67 | if (mbedtls_cipher_get_cipher_mode(context) == MBEDTLS_MODE_XTS) { |
| 69 | mbedtls_cipher_update(context, src, size, dest, &written); | 68 | mbedtls_cipher_update(context, src, size, dest, &written); |
| 70 | if (written != size) | 69 | if (written != size) { |
| 71 | LOG_WARNING(Crypto, "Not all data was decrypted requested={:016X}, actual={:016X}.", | 70 | LOG_WARNING(Crypto, "Not all data was decrypted requested={:016X}, actual={:016X}.", |
| 72 | size, written); | 71 | size, written); |
| 72 | } | ||
| 73 | } else { | 73 | } else { |
| 74 | const auto block_size = mbedtls_cipher_get_block_size(context); | 74 | const auto block_size = mbedtls_cipher_get_block_size(context); |
| 75 | 75 | ||
| 76 | for (size_t offset = 0; offset < size; offset += block_size) { | 76 | for (size_t offset = 0; offset < size; offset += block_size) { |
| 77 | auto length = std::min<size_t>(block_size, size - offset); | 77 | auto length = std::min<size_t>(block_size, size - offset); |
| 78 | mbedtls_cipher_update(context, src + offset, length, dest + offset, &written); | 78 | mbedtls_cipher_update(context, src + offset, length, dest + offset, &written); |
| 79 | if (written != length) | 79 | if (written != length) { |
| 80 | LOG_WARNING(Crypto, "Not all data was decrypted requested={:016X}, actual={:016X}.", | 80 | LOG_WARNING(Crypto, "Not all data was decrypted requested={:016X}, actual={:016X}.", |
| 81 | length, written); | 81 | length, written); |
| 82 | } | ||
| 82 | } | 83 | } |
| 83 | } | 84 | } |
| 84 | 85 | ||