summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/crypto/aes_util.cpp13
-rw-r--r--src/core/crypto/aes_util.h4
2 files changed, 9 insertions, 8 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
60template <typename Key, size_t KeySize> 60template <typename Key, size_t KeySize>
61void AESCipher<Key, KeySize>::Transcode(const u8* src, size_t size, u8* dest, Op op) { 61void 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
diff --git a/src/core/crypto/aes_util.h b/src/core/crypto/aes_util.h
index 81fa0d73f..bda41b144 100644
--- a/src/core/crypto/aes_util.h
+++ b/src/core/crypto/aes_util.h
@@ -38,11 +38,11 @@ public:
38 void SetIV(std::vector<u8> iv); 38 void SetIV(std::vector<u8> iv);
39 39
40 template <typename Source, typename Dest> 40 template <typename Source, typename Dest>
41 void Transcode(const Source* src, size_t size, Dest* dest, Op op) { 41 void Transcode(const Source* src, size_t size, Dest* dest, Op op) const {
42 Transcode(reinterpret_cast<const u8*>(src), size, reinterpret_cast<u8*>(dest), op); 42 Transcode(reinterpret_cast<const u8*>(src), size, reinterpret_cast<u8*>(dest), op);
43 } 43 }
44 44
45 void Transcode(const u8* src, size_t size, u8* dest, Op op); 45 void Transcode(const u8* src, size_t size, u8* dest, Op op) const;
46 46
47 template <typename Source, typename Dest> 47 template <typename Source, typename Dest>
48 void XTSTranscode(const Source* src, size_t size, Dest* dest, size_t sector_id, 48 void XTSTranscode(const Source* src, size_t size, Dest* dest, size_t sector_id,