From a3074aea1ef4e1e13b4f336fb834aa740d2f7372 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 25 Jun 2026 11:34:49 -0400 Subject: [PATCH] GetGarlicKey return [key,tag] pair. Remove replyIV --- libi2pd/Tunnel.cpp | 3 +-- libi2pd/TunnelConfig.cpp | 15 ++------------- libi2pd/TunnelConfig.h | 7 +++---- 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/libi2pd/Tunnel.cpp b/libi2pd/Tunnel.cpp index 3f243c32..73b4b11f 100644 --- a/libi2pd/Tunnel.cpp +++ b/libi2pd/Tunnel.cpp @@ -120,8 +120,7 @@ namespace tunnel if (m_Config->GetLastHop () && m_Config->GetLastHop ()->ident->GetIdentHash () != m_Config->GetLastHop ()->nextIdent) { // add garlic key/tag for reply - uint8_t key[32]; - uint64_t tag = m_Config->GetLastHop ()->GetGarlicKey (key); + auto [key, tag] = m_Config->GetLastHop ()->GetGarlicKey (); if (m_Pool && m_Pool->GetLocalDestination ()) m_Pool->GetLocalDestination ()->SubmitECIESx25519Key (key, tag); else diff --git a/libi2pd/TunnelConfig.cpp b/libi2pd/TunnelConfig.cpp index ca831c6e..23f94221 100644 --- a/libi2pd/TunnelConfig.cpp +++ b/libi2pd/TunnelConfig.cpp @@ -75,14 +75,6 @@ namespace tunnel } } - void TunnelHopConfig::DecryptRecord (uint8_t * records, int index) const - { - uint8_t * record = records + index*TUNNEL_BUILD_RECORD_SIZE; - i2p::crypto::CBCDecryption decryption; - decryption.SetKey (replyKey); - decryption.Decrypt(record, TUNNEL_BUILD_RECORD_SIZE, replyIV, record); - } - void ShortECIESTunnelHopConfig::EncryptECIES (const uint8_t * plainText, uint8_t * encrypted) { if (!ident) return; @@ -169,12 +161,9 @@ namespace tunnel i2p::crypto::ChaCha20 (record, SHORT_TUNNEL_BUILD_RECORD_SIZE, replyKey, nonce, record); } - uint64_t ShortECIESTunnelHopConfig::GetGarlicKey (uint8_t * key) const + std::pair ShortECIESTunnelHopConfig::GetGarlicKey () const { - uint64_t tag; - memcpy (&tag, m_CK, 8); - memcpy (key, m_CK + 32, 32); - return tag; + return { m_CK + 32, buf64toh (m_CK) }; } void ShortPhonyTunnelHopConfig::CreateBuildRequestRecord (uint8_t * records, uint32_t replyMsgID) diff --git a/libi2pd/TunnelConfig.h b/libi2pd/TunnelConfig.h index b998f5a2..f83744a1 100644 --- a/libi2pd/TunnelConfig.h +++ b/libi2pd/TunnelConfig.h @@ -26,7 +26,6 @@ namespace tunnel uint8_t layerKey[32]; uint8_t ivKey[32]; uint8_t replyKey[32]; - uint8_t replyIV[16]; bool isGateway, isEndpoint; TunnelHopConfig * next, * prev; @@ -43,8 +42,8 @@ namespace tunnel virtual uint8_t GetRetCode (const uint8_t * records) const = 0; virtual void CreateBuildRequestRecord (uint8_t * records, uint32_t replyMsgID) = 0; virtual bool DecryptBuildResponseRecord (uint8_t * records) const = 0; - virtual void DecryptRecord (uint8_t * records, int index) const; // AES - virtual uint64_t GetGarlicKey (uint8_t * key) const { return 0; }; // return tag + virtual void DecryptRecord (uint8_t * records, int index) const = 0; + virtual std::pair GetGarlicKey () const { return { nullptr, 0}; }; // return [key,tag] }; struct ShortECIESTunnelHopConfig: public TunnelHopConfig, public i2p::crypto::NoiseSymmetricState @@ -59,7 +58,7 @@ namespace tunnel void CreateBuildRequestRecord (uint8_t * records, uint32_t replyMsgID) override; bool DecryptBuildResponseRecord (uint8_t * records) const override; void DecryptRecord (uint8_t * records, int index) const override; // Chacha20 - uint64_t GetGarlicKey (uint8_t * key) const override; + std::pair GetGarlicKey () const override; }; struct ShortPhonyTunnelHopConfig: public TunnelHopConfig