Browse Source

set some ECIESx25519 params

pull/1515/head
orignal 5 years ago
parent
commit
f77a58b2dc
  1. 13
      libi2pd/ECIESX25519AEADRatchetSession.cpp
  2. 7
      libi2pd/ECIESX25519AEADRatchetSession.h
  3. 2
      libi2pd/Garlic.cpp

13
libi2pd/ECIESX25519AEADRatchetSession.cpp

@ -311,7 +311,7 @@ namespace garlic @@ -311,7 +311,7 @@ namespace garlic
newTagset->SetTagSetID (tagsetID);
newTagset->DHInitialize (receiveTagset->GetNextRootKey (), tagsetKey);
newTagset->NextSessionTagRatchet ();
GenerateMoreReceiveTags (newTagset, GetOwner ()->GetNumTags ());
GenerateMoreReceiveTags (newTagset, ECIESX25519_MAX_NUM_GENERATED_TAGS);
LogPrint (eLogDebug, "Garlic: next receive tagset ", tagsetID, " created");
}
}
@ -426,7 +426,7 @@ namespace garlic @@ -426,7 +426,7 @@ namespace garlic
m_SendTagset = std::make_shared<RatchetTagSet>(shared_from_this ());
m_SendTagset->DHInitialize (m_CK, keydata + 32); // tagset_ba = DH_INITIALIZE(chainKey, k_ba)
m_SendTagset->NextSessionTagRatchet ();
GenerateMoreReceiveTags (receiveTagset, GetOwner ()->GetNumTags ());
GenerateMoreReceiveTags (receiveTagset, ECIESX25519_MIN_NUM_GENERATED_TAGS);
i2p::crypto::HKDF (keydata + 32, nullptr, 0, "AttachPayloadKDF", m_NSRKey, 32); // k = HKDF(k_ba, ZEROLEN, "AttachPayloadKDF", 32)
// encrypt payload
if (!i2p::crypto::AEADChaCha20Poly1305 (payload, len, m_H, 32, m_NSRKey, nonce, out + offset, len + 16, true)) // encrypt
@ -495,7 +495,7 @@ namespace garlic @@ -495,7 +495,7 @@ namespace garlic
auto receiveTagset = std::make_shared<RatchetTagSet>(shared_from_this ());
receiveTagset->DHInitialize (m_CK, keydata + 32); // tagset_ba = DH_INITIALIZE(chainKey, k_ba)
receiveTagset->NextSessionTagRatchet ();
GenerateMoreReceiveTags (receiveTagset, GetOwner ()->GetNumTags ());
GenerateMoreReceiveTags (receiveTagset, ECIESX25519_MIN_NUM_GENERATED_TAGS);
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);
@ -552,8 +552,11 @@ namespace garlic @@ -552,8 +552,11 @@ namespace garlic
return false;
}
HandlePayload (payload.data (), len - 16, receiveTagset, index);
if (receiveTagset->GetNextIndex () - index <= GetOwner ()->GetNumTags ()*2/3)
GenerateMoreReceiveTags (receiveTagset, GetOwner ()->GetNumTags ());
int moreTags = ECIESX25519_MIN_NUM_GENERATED_TAGS + (index >> 2); // N/4
if (moreTags > ECIESX25519_MAX_NUM_GENERATED_TAGS) moreTags = ECIESX25519_MAX_NUM_GENERATED_TAGS;
moreTags -= (receiveTagset->GetNextIndex () - index);
if (moreTags > 0)
GenerateMoreReceiveTags (receiveTagset, moreTags);
return true;
}

7
libi2pd/ECIESX25519AEADRatchetSession.h

@ -72,8 +72,11 @@ namespace garlic @@ -72,8 +72,11 @@ namespace garlic
const uint8_t ECIESX25519_NEXT_KEY_REQUEST_REVERSE_KEY_FLAG = 0x04;
const int ECIESX25519_RESTART_TIMEOUT = 120; // number of second of inactivity we should restart after
const int ECIESX25519_EXPIRATION_TIMEOUT = 600; // in seconds
const int ECIESX25519_TAGSET_MAX_NUM_TAGS = 60000; // number of tags we request new tagset after
const int ECIESX25519_EXPIRATION_TIMEOUT = 480; // in seconds
const int ECIESX25519_INCOMING_TAGS_EXPIRATION_TIMEOUT = 600; // in seconds
const int ECIESX25519_TAGSET_MAX_NUM_TAGS = 1024; // number of tags we request new tagset after
const int ECIESX25519_MIN_NUM_GENERATED_TAGS = 24;
const int ECIESX25519_MAX_NUM_GENERATED_TAGS = 160;
class ECIESX25519AEADRatchetSession: public GarlicRoutingSession, public std::enable_shared_from_this<ECIESX25519AEADRatchetSession>
{

2
libi2pd/Garlic.cpp

@ -788,7 +788,7 @@ namespace garlic @@ -788,7 +788,7 @@ namespace garlic
// ECIESx25519
for (auto it = m_ECIESx25519Tags.begin (); it != m_ECIESx25519Tags.end ();)
{
if (ts > it->second.creationTime + INCOMING_TAGS_EXPIRATION_TIMEOUT)
if (ts > it->second.creationTime + ECIESX25519_INCOMING_TAGS_EXPIRATION_TIMEOUT)
it = m_ECIESx25519Tags.erase (it);
else
++it;

Loading…
Cancel
Save