From be5e829f97b4470590a273b87e8044275b18ae28 Mon Sep 17 00:00:00 2001 From: subtly Date: Mon, 8 Dec 2014 14:41:04 +0100 Subject: [PATCH] cryptopp crash w/null plaintext passed to decrypt --- libdevcrypto/CryptoPP.cpp | 8 +++++--- test/crypto.cpp | 8 ++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/libdevcrypto/CryptoPP.cpp b/libdevcrypto/CryptoPP.cpp index f417d697b..766ca485d 100644 --- a/libdevcrypto/CryptoPP.cpp +++ b/libdevcrypto/CryptoPP.cpp @@ -52,10 +52,12 @@ void Secp256k1::decrypt(Secret const& _k, bytes& io_text) { CryptoPP::ECIES::Decryptor d; initializeDLScheme(_k, d); - - // todo: test ecies w/null plaintext or ciphertext of \0 + if (!io_text.size()) - return; + { + io_text.resize(1); + io_text[0] = 0; + } size_t clen = io_text.size(); bytes plain; diff --git a/test/crypto.cpp b/test/crypto.cpp index 08236135a..466015ad7 100644 --- a/test/crypto.cpp +++ b/test/crypto.cpp @@ -44,6 +44,14 @@ static CryptoPP::OID s_curveOID(CryptoPP::ASN1::secp256k1()); static CryptoPP::DL_GroupParameters_EC s_params(s_curveOID); static CryptoPP::DL_GroupParameters_EC::EllipticCurve s_curve(s_params.GetCurve()); +BOOST_AUTO_TEST_CASE(cryptopp_patch) +{ + KeyPair k = KeyPair::create(); + bytes io_text; + s_secp256k1.decrypt(k.sec(), io_text); + BOOST_REQUIRE_EQUAL(io_text.size(), 0); +} + BOOST_AUTO_TEST_CASE(verify_secert) { h256 empty;