From 349c4e30b677436e73dca6e280468cdc1cbda5a9 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 6 Aug 2024 13:58:21 -0400 Subject: [PATCH] correct receive ratchet tagsetid calculation --- libi2pd/ECIESX25519AEADRatchetSession.cpp | 8 ++++---- libi2pd/ECIESX25519AEADRatchetSession.h | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libi2pd/ECIESX25519AEADRatchetSession.cpp b/libi2pd/ECIESX25519AEADRatchetSession.cpp index 1aca5ed8..528762fd 100644 --- a/libi2pd/ECIESX25519AEADRatchetSession.cpp +++ b/libi2pd/ECIESX25519AEADRatchetSession.cpp @@ -409,16 +409,14 @@ namespace garlic } m_NextReceiveRatchet->keyID = keyID; } - m_SendReverseKey = true; - int tagsetID = 2*keyID; if (newKey) { m_NextReceiveRatchet->key = i2p::transport::transports.GetNextX25519KeysPair (); m_NextReceiveRatchet->newKey = true; - tagsetID++; } else m_NextReceiveRatchet->newKey = false; + auto tagsetID = m_NextReceiveRatchet->GetReceiveTagSetID (); if (flag & ECIESX25519_NEXT_KEY_KEY_PRESENT_FLAG) memcpy (m_NextReceiveRatchet->remote, buf, 32); @@ -432,7 +430,9 @@ namespace garlic GenerateMoreReceiveTags (newTagset, (GetOwner () && GetOwner ()->GetNumRatchetInboundTags () > 0) ? GetOwner ()->GetNumRatchetInboundTags () : ECIESX25519_MAX_NUM_GENERATED_TAGS); receiveTagset->Expire (); + LogPrint (eLogDebug, "Garlic: Next receive tagset ", tagsetID, " created"); + m_SendReverseKey = true; } } @@ -781,7 +781,7 @@ namespace garlic [[fallthrough]]; #endif case eSessionStateEstablished: - if (m_SendReverseKey && receiveTagset->GetTagSetID () == 2*m_NextReceiveRatchet->keyID) + if (m_SendReverseKey && receiveTagset->GetTagSetID () == m_NextReceiveRatchet->GetReceiveTagSetID ()) m_SendReverseKey = false; // tag received on new tagset if (receiveTagset->IsNS ()) { diff --git a/libi2pd/ECIESX25519AEADRatchetSession.h b/libi2pd/ECIESX25519AEADRatchetSession.h index e6deb2bc..18cac434 100644 --- a/libi2pd/ECIESX25519AEADRatchetSession.h +++ b/libi2pd/ECIESX25519AEADRatchetSession.h @@ -149,6 +149,7 @@ namespace garlic std::shared_ptr key; uint8_t remote[32]; // last remote public key bool newKey = true; + int GetReceiveTagSetID () const { return newKey ? (2*keyID + 1) : 2*keyID; } }; public: