|
|
|
@ -295,13 +295,7 @@ namespace garlic
@@ -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
|
|
|
|
@ -353,13 +347,7 @@ namespace garlic
@@ -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
@@ -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
@@ -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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|