mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
check if new tag was created
This commit is contained in:
parent
b4236b04c6
commit
86ff0d86db
@ -45,13 +45,13 @@ namespace garlic
|
||||
|
||||
uint64_t RatchetTagSet::GetNextSessionTag ()
|
||||
{
|
||||
i2p::crypto::HKDF (m_KeyData.GetSessTagCK (), m_SessTagConstant, 32, "SessionTagKeyGen", m_KeyData.buf); // [sessTag_ck, tag] = HKDF(sessTag_chainkey, SESSTAG_CONSTANT, "SessionTagKeyGen", 64)
|
||||
m_NextIndex++;
|
||||
if (m_NextIndex >= 65535)
|
||||
{
|
||||
LogPrint (eLogError, "Garlic: Tagset ", GetTagSetID (), " is empty");
|
||||
return 0;
|
||||
}
|
||||
i2p::crypto::HKDF (m_KeyData.GetSessTagCK (), m_SessTagConstant, 32, "SessionTagKeyGen", m_KeyData.buf); // [sessTag_ck, tag] = HKDF(sessTag_chainkey, SESSTAG_CONSTANT, "SessionTagKeyGen", 64)
|
||||
return m_KeyData.GetTag ();
|
||||
}
|
||||
|
||||
@ -687,6 +687,13 @@ namespace garlic
|
||||
auto index = m_SendTagset->GetNextIndex ();
|
||||
CreateNonce (index, nonce); // tag's index
|
||||
uint64_t tag = m_SendTagset->GetNextSessionTag ();
|
||||
if (!tag)
|
||||
{
|
||||
LogPrint (eLogError, "Garlic: can't create new ECIES-X25519-AEAD-Ratchet tag for send tagset");
|
||||
if (GetOwner ())
|
||||
GetOwner ()->RemoveECIESx25519Session (m_RemoteStaticKey);
|
||||
return false;
|
||||
}
|
||||
memcpy (out, &tag, 8);
|
||||
// ad = The session tag, 8 bytes
|
||||
// ciphertext = ENCRYPT(k, n, payload, ad)
|
||||
@ -1050,7 +1057,14 @@ namespace garlic
|
||||
if (GetOwner ())
|
||||
{
|
||||
for (int i = 0; i < numTags; i++)
|
||||
GetOwner ()->AddECIESx25519SessionNextTag (receiveTagset);
|
||||
{
|
||||
auto tag = GetOwner ()->AddECIESx25519SessionNextTag (receiveTagset);
|
||||
if (!tag)
|
||||
{
|
||||
LogPrint (eLogError, "Garlic: can't create new ECIES-X25519-AEAD-Ratchet tag for receive tagset");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -546,12 +546,18 @@ namespace garlic
|
||||
if (!session->HandleNextMessage (buf, length, nullptr, 0))
|
||||
{
|
||||
// try to gererate more tags for last tagset
|
||||
if (m_LastTagset)
|
||||
if (m_LastTagset && m_LastTagset->GetNextIndex () < 2*ECIESX25519_TAGSET_MAX_NUM_TAGS)
|
||||
{
|
||||
auto maxTags = std::max (m_NumRatchetInboundTags, ECIESX25519_MAX_NUM_GENERATED_TAGS);
|
||||
for (int i = 0; i < maxTags; i++)
|
||||
{
|
||||
if (AddECIESx25519SessionNextTag (m_LastTagset) == tag)
|
||||
auto nextTag = AddECIESx25519SessionNextTag (m_LastTagset);
|
||||
if (!nextTag)
|
||||
{
|
||||
LogPrint (eLogError, "Garlic: can't create new ECIES-X25519-AEAD-Ratchet tag for last tagset");
|
||||
break;
|
||||
}
|
||||
if (nextTag == tag)
|
||||
{
|
||||
LogPrint (eLogDebug, "Garlic: Missing ECIES-X25519-AEAD-Ratchet tag was generated");
|
||||
if (m_LastTagset->HandleNextMessage (buf, length, m_ECIESx25519Tags[tag].index))
|
||||
@ -1057,6 +1063,7 @@ namespace garlic
|
||||
{
|
||||
auto index = tagset->GetNextIndex ();
|
||||
uint64_t tag = tagset->GetNextSessionTag ();
|
||||
if (tag)
|
||||
m_ECIESx25519Tags.emplace (tag, ECIESX25519AEADRatchetIndexTagset{index, tagset});
|
||||
return tag;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user