From 71c808b229e9497947642032ec7f4b024400a783 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Wed, 11 Nov 2015 11:00:24 -0800 Subject: [PATCH] RandomPadding throws exception instead of ASSERT when data is too large --- crypto/RandomPadding.cpp | 6 ++++-- crypto/kdf/DerivedKeyConfig.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/crypto/RandomPadding.cpp b/crypto/RandomPadding.cpp index 79dd6b96..8852ea9d 100644 --- a/crypto/RandomPadding.cpp +++ b/crypto/RandomPadding.cpp @@ -8,7 +8,9 @@ using namespace cpputils::logging; namespace cpputils { Data RandomPadding::add(const Data &data, size_t targetSize) { uint32_t size = data.size(); - ASSERT(size < targetSize - sizeof(size), "Config data too large. We should increase padding target size."); + if (size >= targetSize - sizeof(size)) { + throw std::runtime_error("Data too large. We should increase padding target size."); + } Data randomData = Random::PseudoRandom().get(targetSize-sizeof(size)-size); ASSERT(sizeof(size) + size + randomData.size() == targetSize, "Calculated size of randomData incorrectly"); Data result(targetSize); @@ -29,4 +31,4 @@ namespace cpputils { std::memcpy(reinterpret_cast(result.data()), reinterpret_cast(data.dataOffset(sizeof(size))), size); return std::move(result); } -} \ No newline at end of file +} diff --git a/crypto/kdf/DerivedKeyConfig.h b/crypto/kdf/DerivedKeyConfig.h index 94109957..43f676ee 100644 --- a/crypto/kdf/DerivedKeyConfig.h +++ b/crypto/kdf/DerivedKeyConfig.h @@ -11,6 +11,7 @@ namespace cpputils { //TODO Test Copy/move constructor and assignment //TODO Test operator==/!= + //TODO Use SCryptSettings as a member here instead of storing _N, _r, _p. class DerivedKeyConfig { public: