From b3ee41bd91709593865541278a345db180a212f6 Mon Sep 17 00:00:00 2001 From: cpubug Date: Tue, 8 Apr 2014 11:11:48 +0400 Subject: [PATCH 1/3] replace CalcuateIdentHash to identity.Hash to avoid duplication --- Identity.cpp | 7 ------- Identity.h | 1 - LeaseSet.cpp | 2 +- RouterInfo.cpp | 2 +- Streaming.cpp | 2 +- 5 files changed, 3 insertions(+), 11 deletions(-) diff --git a/Identity.cpp b/Identity.cpp index 435c0c9b..c7c3ed0e 100644 --- a/Identity.cpp +++ b/Identity.cpp @@ -40,13 +40,6 @@ namespace data return *this; } - IdentHash CalculateIdentHash (const Identity& identity) - { - IdentHash hash; - CryptoPP::SHA256().CalculateDigest((uint8_t *)hash, (uint8_t *)&identity, sizeof (Identity)); - return hash; - } - Keys CreateRandomKeys () { Keys keys; diff --git a/Identity.h b/Identity.h index 902153dc..c5e90a16 100644 --- a/Identity.h +++ b/Identity.h @@ -79,7 +79,6 @@ namespace data uint8_t m_Hash[32]; }; - IdentHash CalculateIdentHash (const Identity& identity); Keys CreateRandomKeys (); void CreateRandomDHKeysPair (DHKeysPair * keys); // for transport sessions diff --git a/LeaseSet.cpp b/LeaseSet.cpp index 1383792e..7a7ebbc0 100644 --- a/LeaseSet.cpp +++ b/LeaseSet.cpp @@ -25,7 +25,7 @@ namespace data const H * header = (const H *)buf; m_Identity = header->destination; - m_IdentHash = CalculateIdentHash (m_Identity); + m_IdentHash = m_Identity.Hash(); memcpy (m_EncryptionKey, header->encryptionKey, 256); LogPrint ("LeaseSet num=", (int)header->num); diff --git a/RouterInfo.cpp b/RouterInfo.cpp index 735453c8..d3cbb865 100644 --- a/RouterInfo.cpp +++ b/RouterInfo.cpp @@ -34,7 +34,7 @@ namespace data void RouterInfo::SetRouterIdentity (const Identity& identity) { m_RouterIdentity = identity; - m_IdentHash = CalculateIdentHash (m_RouterIdentity); + m_IdentHash = m_RouterIdentity.Hash (); UpdateIdentHashBase64 (); UpdateRoutingKey (); m_Timestamp = i2p::util::GetMillisecondsSinceEpoch (); diff --git a/Streaming.cpp b/Streaming.cpp index 9291235a..090a0d04 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -345,7 +345,7 @@ namespace stream StreamingDestination::StreamingDestination (): m_LeaseSet (nullptr) { m_Keys = i2p::data::CreateRandomKeys (); - m_IdentHash = i2p::data::CalculateIdentHash (m_Keys.pub); + m_IdentHash = m_Keys.pub.Hash (); m_SigningPrivateKey.Initialize (i2p::crypto::dsap, i2p::crypto::dsaq, i2p::crypto::dsag, CryptoPP::Integer (m_Keys.signingPrivateKey, 20)); CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg); From 61001ef0470076b72583d36f8e7a075d68ea08b0 Mon Sep 17 00:00:00 2001 From: cpubug Date: Tue, 8 Apr 2014 11:24:34 +0400 Subject: [PATCH 2/3] added pointer check in RoutingDestination destructor --- Identity.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Identity.h b/Identity.h index c5e90a16..a4fb8f95 100644 --- a/Identity.h +++ b/Identity.h @@ -106,7 +106,7 @@ namespace data public: RoutingDestination (): m_ElGamalEncryption (nullptr) {}; - virtual ~RoutingDestination () { delete m_ElGamalEncryption; }; + virtual ~RoutingDestination () { if (m_ElGamalEncryption) delete m_ElGamalEncryption; }; virtual const IdentHash& GetIdentHash () const = 0; virtual const uint8_t * GetEncryptionPublicKey () const = 0; From ad8559d91162cab0000704b5d530fa5908dc0756 Mon Sep 17 00:00:00 2001 From: cpubug Date: Tue, 8 Apr 2014 21:01:14 +0400 Subject: [PATCH 3/3] fix gcc warning: deleting object of polymorphic class type 'i2p::stream::StreamingDestination' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor] --- Identity.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Identity.h b/Identity.h index a4fb8f95..ff35a7db 100644 --- a/Identity.h +++ b/Identity.h @@ -128,6 +128,7 @@ namespace data { public: + virtual ~LocalDestination() {}; virtual const IdentHash& GetIdentHash () const = 0; virtual const uint8_t * GetEncryptionPrivateKey () const = 0; virtual const uint8_t * GetEncryptionPublicKey () const = 0;