diff options
| author | Stefan Boberg <[email protected]> | 2025-10-26 20:37:00 +0100 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2025-10-26 20:37:00 +0100 |
| commit | 4e4bc87c3d29235bb800d619b45423a6888c5b4c (patch) | |
| tree | cd4f3c398c9a7fa859498f78837f69ed09879fba /src | |
| parent | remove vcpkg from github actions (diff) | |
| download | zen-4e4bc87c3d29235bb800d619b45423a6888c5b4c.tar.xz zen-4e4bc87c3d29235bb800d619b45423a6888c5b4c.zip | |
fix mbedtls crypto impl
Diffstat (limited to 'src')
| -rw-r--r-- | src/zencore/crypto.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/zencore/crypto.cpp b/src/zencore/crypto.cpp index 253fa59eb..e218c5953 100644 --- a/src/zencore/crypto.cpp +++ b/src/zencore/crypto.cpp @@ -108,18 +108,18 @@ namespace crypto { return MemoryView(); } - ret = mbedtls_cipher_reset(Ctx.get()); + ret = mbedtls_cipher_set_padding_mode(Ctx.get(), MBEDTLS_PADDING_PKCS7); + if (ret != 0) { - Reason = fmt::format("mbedTLS reset failed, ret={}", ret); + Reason = fmt::format("mbedTLS padding mode configuration failed, ret={}", ret); return MemoryView(); } - // Ensure output buffer is large enough: worst case = input + block size - const size_t BlockSize = 16; - if (Out.GetSize() < In.GetSize() + BlockSize) + ret = mbedtls_cipher_reset(Ctx.get()); + if (ret != 0) { - Reason = "invalid output buffer size"sv; + Reason = fmt::format("mbedTLS reset failed, ret={}", ret); return MemoryView(); } @@ -474,7 +474,9 @@ TEST_CASE("crypto.aes") DecryptionBuffer.resize(PlainText.size() + Aes::BlockSize); MemoryView EncryptedView = Aes::Encrypt(Key, IV, MakeMemoryView(PlainText), MakeMutableMemoryView(EncryptionBuffer), Reason); + CHECK(Reason.has_value() == false); MemoryView DecryptedView = Aes::Decrypt(Key, IV, EncryptedView, MakeMutableMemoryView(DecryptionBuffer), Reason); + CHECK(Reason.has_value() == false); std::string_view EncryptedDecryptedText = std::string_view(reinterpret_cast<const char*>(DecryptedView.GetData()), DecryptedView.GetSize()); |