From 285b79f31e292f6648148ebc27481acc57c123b9 Mon Sep 17 00:00:00 2001 From: Justus Garbe Date: Sun, 13 Aug 2023 15:27:01 +0200 Subject: [PATCH] fix: Crypto buffered hexadecimal encoding --- lib/libimhex/source/helpers/crypto.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/libimhex/source/helpers/crypto.cpp b/lib/libimhex/source/helpers/crypto.cpp index df3725f90..7539d859d 100644 --- a/lib/libimhex/source/helpers/crypto.cpp +++ b/lib/libimhex/source/helpers/crypto.cpp @@ -396,14 +396,14 @@ namespace hex::crypt { ON_SCOPE_EXIT { mbedtls_mpi_free(&ctx); }; + // read buffered constexpr static auto BufferSize = 0x100; for (size_t offset = 0; offset < input.size(); offset += BufferSize) { std::string inputPart = input.substr(offset, std::min(BufferSize, input.size() - offset)); if (mbedtls_mpi_read_string(&ctx, 16, inputPart.c_str())) return {}; - auto size = std::min(BufferSize / 2, input.size() - offset); - if (mbedtls_mpi_write_binary(&ctx, output.data() + offset / 2, size) != 0) + if (mbedtls_mpi_write_binary(&ctx, output.data() + offset / 2, inputPart.size() / 2)) return {}; }