Browse Source

bugfix and doc clarification. fix test.

cl-refactor
subtly 10 years ago
parent
commit
3292c58599
  1. 7
      libdevcrypto/CryptoPP.cpp
  2. 8
      libdevcrypto/CryptoPP.h
  3. 2
      libp2p/Host.h
  4. 2
      test/crypto.cpp

7
libdevcrypto/CryptoPP.cpp

@ -319,13 +319,14 @@ bool Secp256k1::verifySecret(Secret const& _s, Public& _p)
void Secp256k1::agree(Secret const& _s, Public const& _r, h256& o_s)
{
(void)o_s;
(void)_s;
// TODO: mutex ASN1::secp256k1() singleton
// Creating Domain is non-const for m_oid and m_oid is not thread-safe
ECDH<ECP>::Domain d(ASN1::secp256k1());
assert(d.AgreedValueLength() == sizeof(o_s));
byte remote[65] = {0x04};
memcpy(&remote[1], _r.data(), 64);
assert(d.Agree(o_s.data(), _s.data(), remote));
bool result = d.Agree(o_s.data(), _s.data(), remote);
assert(result);
}
void Secp256k1::exportPublicKey(CryptoPP::DL_PublicKey_EC<CryptoPP::ECP> const& _k, Public& o_p)

8
libdevcrypto/CryptoPP.h

@ -76,16 +76,16 @@ public:
void toPublic(Secret const& _s, Public& o_public) { exponentToPublic(Integer(_s.data(), sizeof(_s)), o_public); }
/// Encrypts text (replace input). (ECIES w/XOR)
/// Encrypts text (replace input). (ECIES w/XOR-SHA1)
void encrypt(Public const& _k, bytes& io_cipher);
/// Decrypts text (replace input). (ECIES w/XOR)
/// Decrypts text (replace input). (ECIES w/XOR-SHA1)
void decrypt(Secret const& _k, bytes& io_text);
/// Encrypts text (replace input). (ECIES w/AES128-CTR)
/// Encrypts text (replace input). (ECIES w/AES128-CTR-SHA256)
void encryptECIES(Public const& _k, bytes& io_cipher);
/// Decrypts text (replace input). (ECIES w/AES128-CTR)
/// Decrypts text (replace input). (ECIES w/AES128-CTR-SHA256)
bool decryptECIES(Secret const& _k, bytes& io_text);
/// Key derivation function used by encryptECIES and decryptECIES.

2
libp2p/Host.h

@ -226,7 +226,7 @@ private:
mutable RecursiveMutex x_sessions;
std::list<std::weak_ptr<RLPXHandshake>> m_connecting; ///< Pending connections.
Mutex x_connecting;
Mutex x_connecting; ///< Mutex for m_connecting.
unsigned m_idealPeerCount = 5; ///< Ideal number of peers to be connected to.

2
test/crypto.cpp

@ -299,7 +299,7 @@ BOOST_AUTO_TEST_CASE(ecies_standard)
s_secp256k1.encryptECIES(k.pub(), b);
BOOST_REQUIRE(b != asBytes(original));
BOOST_REQUIRE(b.size() > 0 && ((u128)h128(b)) > 0);
BOOST_REQUIRE(b.size() > 0 && b[0] == 0x04);
s_secp256k1.decryptECIES(k.sec(), b);
BOOST_REQUIRE(bytesConstRef(&b).cropped(0, original.size()).toBytes() == asBytes(original));

Loading…
Cancel
Save