mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-13 11:17:53 +00:00
generate more receive tags when needed
This commit is contained in:
parent
694d851cdb
commit
53a6162b0c
@ -295,13 +295,7 @@ namespace garlic
|
||||
m_ReceiveTagset.NextSessionTagRatchet ();
|
||||
m_SendTagset.DHInitialize (m_CK, keydata + 32); // tagset_ba = DH_INITIALIZE(chainKey, k_ba)
|
||||
m_SendTagset.NextSessionTagRatchet ();
|
||||
auto numTags = GetOwner ()->GetNumTags ();
|
||||
for (int i = 0; i < numTags; i++)
|
||||
{
|
||||
auto index = m_ReceiveTagset.GetNextIndex ();
|
||||
uint64_t tag = m_ReceiveTagset.GetNextSessionTag ();
|
||||
GetOwner ()->AddECIESx25519SessionTag (index, tag, shared_from_this ());
|
||||
}
|
||||
GenerateMoreReceiveTags (GetOwner ()->GetNumTags ());
|
||||
i2p::crypto::HKDF (keydata + 32, nullptr, 0, "AttachPayloadKDF", keydata, 32); // k = HKDF(k_ba, ZEROLEN, "AttachPayloadKDF", 32)
|
||||
// encrypt payload
|
||||
if (!i2p::crypto::AEADChaCha20Poly1305 (payload, len, m_H, 32, keydata, nonce, out + offset, len + 16, true)) // encrypt
|
||||
@ -310,7 +304,7 @@ namespace garlic
|
||||
return false;
|
||||
}
|
||||
m_State = eSessionStateEstablished;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -353,13 +347,7 @@ namespace garlic
|
||||
m_SendTagset.NextSessionTagRatchet ();
|
||||
m_ReceiveTagset.DHInitialize (m_CK, keydata + 32); // tagset_ba = DH_INITIALIZE(chainKey, k_ba)
|
||||
m_ReceiveTagset.NextSessionTagRatchet ();
|
||||
auto numTags = GetOwner ()->GetNumTags ();
|
||||
for (int i = 0; i < numTags; i++)
|
||||
{
|
||||
auto index = m_ReceiveTagset.GetNextIndex ();
|
||||
uint64_t tag = m_ReceiveTagset.GetNextSessionTag ();
|
||||
GetOwner ()->AddECIESx25519SessionTag (index, tag, shared_from_this ());
|
||||
}
|
||||
GenerateMoreReceiveTags (GetOwner ()->GetNumTags ());
|
||||
i2p::crypto::HKDF (keydata + 32, nullptr, 0, "AttachPayloadKDF", keydata, 32); // k = HKDF(k_ba, ZEROLEN, "AttachPayloadKDF", 32)
|
||||
// decrypt payload
|
||||
std::vector<uint8_t> payload (len - 16);
|
||||
@ -405,6 +393,9 @@ namespace garlic
|
||||
return false;
|
||||
}
|
||||
HandlePayload (payload.data (), len - 16);
|
||||
if (m_NumReceiveTags > 0)m_NumReceiveTags--;
|
||||
if (m_NumReceiveTags <= GetOwner ()->GetNumTags ()*2/3)
|
||||
GenerateMoreReceiveTags (GetOwner ()->GetNumTags ());
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -513,6 +504,17 @@ namespace garlic
|
||||
memcpy (buf + 9, msg->GetPayload (), msg->GetPayloadLength ());
|
||||
return cloveSize + 3;
|
||||
}
|
||||
|
||||
void ECIESX25519AEADRatchetSession::GenerateMoreReceiveTags (int numTags)
|
||||
{
|
||||
for (int i = 0; i < numTags; i++)
|
||||
{
|
||||
auto index = m_ReceiveTagset.GetNextIndex ();
|
||||
uint64_t tag = m_ReceiveTagset.GetNextSessionTag ();
|
||||
GetOwner ()->AddECIESx25519SessionTag (index, tag, shared_from_this ());
|
||||
}
|
||||
m_NumReceiveTags += numTags;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ namespace garlic
|
||||
{
|
||||
if (!m_Destination) m_Destination.reset (new i2p::data::IdentHash (dest));
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void ResetKeys ();
|
||||
@ -101,6 +101,8 @@ namespace garlic
|
||||
std::vector<uint8_t> CreatePayload (std::shared_ptr<const I2NPMessage> msg);
|
||||
size_t CreateGarlicClove (std::shared_ptr<const I2NPMessage> msg, uint8_t * buf, size_t len, bool isDestination = false);
|
||||
|
||||
void GenerateMoreReceiveTags (int numTags);
|
||||
|
||||
private:
|
||||
|
||||
uint8_t m_H[32], m_CK[64] /* [chainkey, key] */, m_RemoteStaticKey[32];
|
||||
@ -108,6 +110,7 @@ namespace garlic
|
||||
i2p::crypto::X25519Keys m_EphemeralKeys;
|
||||
SessionState m_State = eSessionStateNew;
|
||||
RatchetTagSet m_SendTagset, m_ReceiveTagset;
|
||||
int m_NumReceiveTags = 0;
|
||||
std::unique_ptr<i2p::data::IdentHash> m_Destination;// TODO: might not need it
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user