Skip to content

Commit

Permalink
correct frame size for I2NP msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Dec 3, 2018
1 parent 5c3d0fc commit 8fc3a1f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions libi2pd/NTCP2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,8 @@ namespace transport
buf -= 3;
buf[0] = eNTCP2BlkI2NPMessage; // blk
htobe16buf (buf + 1, len); // size
len += 3;
len += 3;
totalLen += len;
encryptBufs.push_back (std::make_pair (buf, len));
if (it == *msgs.begin ()) // first message
{
Expand All @@ -977,17 +978,17 @@ namespace transport
if (it == *msgs.rbegin () && it->len + 16 < it->maxLen) // last message
{
// if it's long enough we add padding and MAC to it
// allocate 16 bytes for MAC
len += 16;
// create padding block
auto paddingLen = CreatePaddingBlock (totalLen + len, buf + len, it->maxLen - len);
auto paddingLen = CreatePaddingBlock (totalLen, buf + len, it->maxLen - len - 16);
encryptBufs.push_back (std::make_pair (buf + len, paddingLen));
len += paddingLen;
totalLen += paddingLen;
macBuf = buf + len;
// allocate 16 bytes for MAC
len += 16;
}

bufs.push_back (boost::asio::buffer (buf, len));
totalLen += len;
}

if (!macBuf) // last block was not enough for MAC
Expand All @@ -1005,7 +1006,7 @@ namespace transport
uint8_t nonce[12];
CreateNonce (m_SendSequenceNumber, nonce); m_SendSequenceNumber++;
i2p::crypto::AEADChaCha20Poly1305Encrypt (encryptBufs, m_SendKey, nonce, macBuf); // encrypt buffers
SetNextSentFrameLength (totalLen + 16, first->GetNTCP2Header () - 2); // frame length right before first block
SetNextSentFrameLength (totalLen + 16, first->GetNTCP2Header () - 5); // frame length right before first block

// send buffers
m_IsSending = true;
Expand Down

0 comments on commit 8fc3a1f

Please sign in to comment.