Browse Source

use generic Decrypt instead ElGamalDecrypt

pull/996/head
orignal 7 years ago
parent
commit
19a03c42a5
  1. 5
      libi2pd/Destination.cpp
  2. 3
      libi2pd/Destination.h
  3. 2
      libi2pd/Garlic.cpp
  4. 2
      libi2pd/I2NPProtocol.cpp
  5. 3
      libi2pd/Identity.h
  6. 5
      libi2pd/RouterContext.cpp
  7. 8
      libi2pd/RouterContext.h
  8. 7
      libi2pd_client/I2CP.cpp
  9. 3
      libi2pd_client/I2CP.h

5
libi2pd/Destination.cpp

@ -953,12 +953,13 @@ namespace client @@ -953,12 +953,13 @@ namespace client
if (m_DatagramDestination) m_DatagramDestination->CleanUp ();
}
void ClientDestination::Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const
bool ClientDestination::Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const
{
if (m_Decryptor)
m_Decryptor->Decrypt (encrypted, data, ctx);
return m_Decryptor->Decrypt (encrypted, data, ctx);
else
LogPrint (eLogError, "Destinations: decryptor is not set");
return false;
}
}
}

3
libi2pd/Destination.h

@ -205,8 +205,7 @@ namespace client @@ -205,8 +205,7 @@ namespace client
i2p::datagram::DatagramDestination * CreateDatagramDestination ();
// implements LocalDestination
const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; };
void Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const;
bool Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const;
std::shared_ptr<const i2p::data::IdentityEx> GetIdentity () const { return m_Keys.GetPublic (); };
protected:

2
libi2pd/Garlic.cpp

@ -454,7 +454,7 @@ namespace garlic @@ -454,7 +454,7 @@ namespace garlic
{
// tag not found. Use ElGamal
ElGamalBlock elGamal;
if (length >= 514 && i2p::crypto::ElGamalDecrypt (GetEncryptionPrivateKey (), buf, (uint8_t *)&elGamal, m_Ctx, true))
if (length >= 514 && Decrypt (buf, (uint8_t *)&elGamal, m_Ctx))
{
auto decryption = std::make_shared<AESDecryption>(elGamal.sessionKey);
uint8_t iv[32]; // IV is first 16 bytes

2
libi2pd/I2NPProtocol.cpp

@ -327,7 +327,7 @@ namespace i2p @@ -327,7 +327,7 @@ namespace i2p
{
LogPrint (eLogDebug, "I2NP: Build request record ", i, " is ours");
BN_CTX * ctx = BN_CTX_new ();
i2p::crypto::ElGamalDecrypt (i2p::context.GetEncryptionPrivateKey (), record + BUILD_REQUEST_RECORD_ENCRYPTED_OFFSET, clearText, ctx);
i2p::crypto::ElGamalDecrypt (i2p::context.GetPrivateKeys ().GetPrivateKey () , record + BUILD_REQUEST_RECORD_ENCRYPTED_OFFSET, clearText, ctx);
BN_CTX_free (ctx);
// replace record to reply
if (i2p::context.AcceptsTunnels () &&

3
libi2pd/Identity.h

@ -203,8 +203,7 @@ namespace data @@ -203,8 +203,7 @@ namespace data
public:
virtual ~LocalDestination() {};
virtual const uint8_t * GetEncryptionPrivateKey () const = 0; // deprecated
virtual void Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const = 0;
virtual bool Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const = 0;
virtual std::shared_ptr<const IdentityEx> GetIdentity () const = 0;
const IdentHash& GetIdentHash () const { return GetIdentity ()->GetIdentHash (); };

5
libi2pd/RouterContext.cpp

@ -480,9 +480,8 @@ namespace i2p @@ -480,9 +480,8 @@ namespace i2p
return i2p::util::GetSecondsSinceEpoch () - m_StartupTime;
}
void RouterContext::Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const
bool RouterContext::Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const
{
if (m_Decryptor)
m_Decryptor->Decrypt (encrypted, data, ctx);
return m_Decryptor ? m_Decryptor->Decrypt (encrypted, data, ctx) : false;
}
}

8
libi2pd/RouterContext.h

@ -48,8 +48,8 @@ namespace i2p @@ -48,8 +48,8 @@ namespace i2p
{
return std::shared_ptr<i2p::garlic::GarlicDestination> (this,
[](i2p::garlic::GarlicDestination *) {});
}
}
uint32_t GetUptime () const;
uint32_t GetStartupTime () const { return m_StartupTime; };
uint64_t GetLastUpdateTime () const { return m_LastUpdateTime; };
@ -89,9 +89,7 @@ namespace i2p @@ -89,9 +89,7 @@ namespace i2p
// implements LocalDestination
std::shared_ptr<const i2p::data::IdentityEx> GetIdentity () const { return m_Keys.GetPublic (); };
const uint8_t * GetEncryptionPrivateKey () const { return m_Keys.GetPrivateKey (); }; // deprecated
void Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const;
const uint8_t * GetEncryptionPublicKey () const { return GetIdentity ()->GetStandardIdentity ().publicKey; };
bool Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const;
void Sign (const uint8_t * buf, int len, uint8_t * signature) const { m_Keys.Sign (buf, len, signature); };
void SetLeaseSetUpdated () {};

7
libi2pd_client/I2CP.cpp

@ -34,12 +34,13 @@ namespace client @@ -34,12 +34,13 @@ namespace client
m_Decryptor = i2p::data::PrivateKeys::CreateDecryptor (m_Identity->GetCryptoKeyType (), m_EncryptionPrivateKey);
}
void I2CPDestination::Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const
bool I2CPDestination::Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const
{
if (m_Decryptor)
m_Decryptor->Decrypt (encrypted, data, ctx);
return m_Decryptor->Decrypt (encrypted, data, ctx);
else
LogPrint (eLogError, "I2CP: decryptor is not set");
LogPrint (eLogError, "I2CP: decryptor is not set");
return false;
}
void I2CPDestination::HandleDataMessage (const uint8_t * buf, size_t len)

3
libi2pd_client/I2CP.h

@ -71,8 +71,7 @@ namespace client @@ -71,8 +71,7 @@ namespace client
void SendMsgTo (const uint8_t * payload, size_t len, const i2p::data::IdentHash& ident, uint32_t nonce); // called from I2CPSession
// implements LocalDestination
const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; }; // deprecated
void Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const;
bool Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const;
std::shared_ptr<const i2p::data::IdentityEx> GetIdentity () const { return m_Identity; };
protected:

Loading…
Cancel
Save