Browse Source

use SessionTag

pull/93/head
orignal 11 years ago
parent
commit
b1c2ba53d1
  1. 21
      Garlic.cpp
  2. 6
      Garlic.h

21
Garlic.cpp

@ -23,20 +23,20 @@ namespace garlic
m_Encryption.SetKey (m_SessionKey); m_Encryption.SetKey (m_SessionKey);
if (m_NumTags > 0) if (m_NumTags > 0)
{ {
m_SessionTags = new uint8_t[m_NumTags*32]; m_SessionTags = new SessionTag[m_NumTags];
GenerateSessionTags (); GenerateSessionTags ();
} }
else else
m_SessionTags = nullptr; m_SessionTags = nullptr;
} }
GarlicRoutingSession::GarlicRoutingSession (const uint8_t * sessionKey, const uint8_t * sessionTag): GarlicRoutingSession::GarlicRoutingSession (const uint8_t * sessionKey, const SessionTag& sessionTag):
m_Destination (nullptr), m_FirstMsgID (0), m_IsAcknowledged (true), m_NumTags (1), m_NextTag (0) m_Destination (nullptr), m_FirstMsgID (0), m_IsAcknowledged (true), m_NumTags (1), m_NextTag (0)
{ {
memcpy (m_SessionKey, sessionKey, 32); memcpy (m_SessionKey, sessionKey, 32);
m_Encryption.SetKey (m_SessionKey); m_Encryption.SetKey (m_SessionKey);
m_SessionTags = new uint8_t[1]; // 1 tag m_SessionTags = new SessionTag[1]; // 1 tag
memcpy (m_SessionTags, sessionTag, 32); m_SessionTags[0] = sessionTag;
m_TagsCreationTime = i2p::util::GetSecondsSinceEpoch (); m_TagsCreationTime = i2p::util::GetSecondsSinceEpoch ();
} }
@ -50,7 +50,7 @@ namespace garlic
if (m_SessionTags) if (m_SessionTags)
{ {
for (int i = 0; i < m_NumTags; i++) for (int i = 0; i < m_NumTags; i++)
m_Rnd.GenerateBlock (m_SessionTags + i*32, 32); m_Rnd.GenerateBlock (m_SessionTags[i], 32);
m_TagsCreationTime = i2p::util::GetSecondsSinceEpoch (); m_TagsCreationTime = i2p::util::GetSecondsSinceEpoch ();
SetAcknowledged (false); SetAcknowledged (false);
} }
@ -100,9 +100,9 @@ namespace garlic
else // existing session else // existing session
{ {
// session tag // session tag
memcpy (buf, m_SessionTags + m_NextTag*32, 32); memcpy (buf, m_SessionTags[m_NextTag], 32);
uint8_t iv[32]; // IV is first 16 bytes uint8_t iv[32]; // IV is first 16 bytes
CryptoPP::SHA256().CalculateDigest(iv, m_SessionTags + m_NextTag*32, 32); CryptoPP::SHA256().CalculateDigest(iv, m_SessionTags[m_NextTag], 32);
m_Encryption.SetIV (iv); m_Encryption.SetIV (iv);
buf += 32; buf += 32;
len += 32; len += 32;
@ -132,8 +132,11 @@ namespace garlic
blockSize += 2; blockSize += 2;
if (m_NextTag < 0) // session tags recreated if (m_NextTag < 0) // session tags recreated
{ {
memcpy (buf + blockSize, m_SessionTags, m_NumTags*32); // tags for (int i = 0; i < m_NumTags; i++)
blockSize += m_NumTags*32; {
memcpy (buf + blockSize, m_SessionTags[i], 32); // tags
blockSize += 32;
}
} }
uint32_t * payloadSize = (uint32_t *)(buf + blockSize); uint32_t * payloadSize = (uint32_t *)(buf + blockSize);
blockSize += 4; blockSize += 4;

6
Garlic.h

@ -37,12 +37,13 @@ namespace garlic
const int TAGS_EXPIRATION_TIMEOUT = 900; // 15 minutes const int TAGS_EXPIRATION_TIMEOUT = 900; // 15 minutes
typedef i2p::data::Tag<32> SessionTag;
class GarlicRoutingSession class GarlicRoutingSession
{ {
public: public:
GarlicRoutingSession (const i2p::data::RoutingDestination * destination, int numTags); GarlicRoutingSession (const i2p::data::RoutingDestination * destination, int numTags);
GarlicRoutingSession (const uint8_t * sessionKey, const uint8_t * sessionTag); // one time encryption GarlicRoutingSession (const uint8_t * sessionKey, const SessionTag& sessionTag); // one time encryption
~GarlicRoutingSession (); ~GarlicRoutingSession ();
I2NPMessage * WrapSingleMessage (I2NPMessage * msg, const I2NPMessage * leaseSet); I2NPMessage * WrapSingleMessage (I2NPMessage * msg, const I2NPMessage * leaseSet);
int GetNextTag () const { return m_NextTag; }; int GetNextTag () const { return m_NextTag; };
@ -67,7 +68,7 @@ namespace garlic
uint32_t m_FirstMsgID; // first message ID uint32_t m_FirstMsgID; // first message ID
bool m_IsAcknowledged; bool m_IsAcknowledged;
int m_NumTags, m_NextTag; int m_NumTags, m_NextTag;
uint8_t * m_SessionTags; // m_NumTags*32 bytes SessionTag * m_SessionTags; // m_NumTags*32 bytes
uint32_t m_TagsCreationTime; // seconds since epoch uint32_t m_TagsCreationTime; // seconds since epoch
i2p::crypto::CBCEncryption m_Encryption; i2p::crypto::CBCEncryption m_Encryption;
@ -76,7 +77,6 @@ namespace garlic
class GarlicRouting class GarlicRouting
{ {
typedef i2p::data::Tag<32> SessionTag;
class SessionDecryption: public i2p::crypto::CBCDecryption class SessionDecryption: public i2p::crypto::CBCDecryption
{ {
public: public:

Loading…
Cancel
Save