mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 12:24:19 +00:00
correct endianness for siphash length
This commit is contained in:
parent
634101ceb5
commit
cd39a52c25
@ -522,14 +522,14 @@ namespace transport
|
|||||||
m_ReceiveKey = m_Kba;
|
m_ReceiveKey = m_Kba;
|
||||||
m_SendSipKey = m_Sipkeysab;
|
m_SendSipKey = m_Sipkeysab;
|
||||||
m_ReceiveSipKey = m_Sipkeysba;
|
m_ReceiveSipKey = m_Sipkeysba;
|
||||||
memcpy (m_ReceiveIV, m_Sipkeysba + 16, 8);
|
memcpy (m_ReceiveIV.buf, m_Sipkeysba + 16, 8);
|
||||||
memcpy (m_SendIV, m_Sipkeysab + 16, 8);
|
memcpy (m_SendIV.buf, m_Sipkeysab + 16, 8);
|
||||||
Established ();
|
Established ();
|
||||||
ReceiveLength ();
|
ReceiveLength ();
|
||||||
|
|
||||||
// TODO: remove
|
// TODO: remove
|
||||||
//m_SendQueue.push_back (CreateDeliveryStatusMsg (1));
|
// m_SendQueue.push_back (CreateDeliveryStatusMsg (1));
|
||||||
//SendQueue ();
|
// SendQueue ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NTCP2Session::HandleSessionCreatedSent (const boost::system::error_code& ecode, std::size_t bytes_transferred)
|
void NTCP2Session::HandleSessionCreatedSent (const boost::system::error_code& ecode, std::size_t bytes_transferred)
|
||||||
@ -597,8 +597,8 @@ namespace transport
|
|||||||
m_ReceiveKey = m_Kab;
|
m_ReceiveKey = m_Kab;
|
||||||
m_SendSipKey = m_Sipkeysba;
|
m_SendSipKey = m_Sipkeysba;
|
||||||
m_ReceiveSipKey = m_Sipkeysab;
|
m_ReceiveSipKey = m_Sipkeysab;
|
||||||
memcpy (m_ReceiveIV, m_Sipkeysab + 16, 8);
|
memcpy (m_ReceiveIV.buf, m_Sipkeysab + 16, 8);
|
||||||
memcpy (m_SendIV, m_Sipkeysba + 16, 8);
|
memcpy (m_SendIV.buf, m_Sipkeysba + 16, 8);
|
||||||
|
|
||||||
// process RI
|
// process RI
|
||||||
if (buf[0] != eNTCP2BlkRouterInfo)
|
if (buf[0] != eNTCP2BlkRouterInfo)
|
||||||
@ -691,8 +691,9 @@ namespace transport
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i2p::crypto::Siphash<8> (m_ReceiveIV, m_ReceiveIV, 8, m_ReceiveSipKey);
|
i2p::crypto::Siphash<8> (m_ReceiveIV.buf, m_ReceiveIV.buf, 8, m_ReceiveSipKey);
|
||||||
m_NextReceivedLen = be16toh (m_NextReceivedLen ^ bufbe16toh(m_ReceiveIV));
|
// m_NextRecivedLen comes from the network in BigEndian
|
||||||
|
m_NextReceivedLen = be16toh (m_NextReceivedLen) ^ m_ReceiveIV.key;
|
||||||
LogPrint (eLogDebug, "NTCP2: received length ", m_NextReceivedLen);
|
LogPrint (eLogDebug, "NTCP2: received length ", m_NextReceivedLen);
|
||||||
if (m_NextReceivedBuffer) delete[] m_NextReceivedBuffer;
|
if (m_NextReceivedBuffer) delete[] m_NextReceivedBuffer;
|
||||||
m_NextReceivedBuffer = new uint8_t[m_NextReceivedLen];
|
m_NextReceivedBuffer = new uint8_t[m_NextReceivedLen];
|
||||||
@ -803,8 +804,9 @@ namespace transport
|
|||||||
CreateNonce (m_SendSequenceNumber, nonce); m_SendSequenceNumber++;
|
CreateNonce (m_SendSequenceNumber, nonce); m_SendSequenceNumber++;
|
||||||
m_NextSendBuffer = new uint8_t[len + 16 + 2];
|
m_NextSendBuffer = new uint8_t[len + 16 + 2];
|
||||||
i2p::crypto::AEADChaCha20Poly1305 (payload, len, nullptr, 0, m_SendKey, nonce, m_NextSendBuffer + 2, len + 16, true);
|
i2p::crypto::AEADChaCha20Poly1305 (payload, len, nullptr, 0, m_SendKey, nonce, m_NextSendBuffer + 2, len + 16, true);
|
||||||
i2p::crypto::Siphash<8> (m_SendIV, m_SendIV, 8, m_SendSipKey);
|
i2p::crypto::Siphash<8> (m_SendIV.buf, m_SendIV.buf, 8, m_SendSipKey);
|
||||||
htobuf16 (m_NextSendBuffer, bufbe16toh (m_SendIV) ^ htobe16(len + 16));
|
// length must be in BigEndian
|
||||||
|
htobe16buf (m_NextSendBuffer, (len + 16) ^ m_SendIV.key);
|
||||||
LogPrint (eLogDebug, "NTCP2: sent length ", len + 16);
|
LogPrint (eLogDebug, "NTCP2: sent length ", len + 16);
|
||||||
|
|
||||||
// send message
|
// send message
|
||||||
|
@ -170,7 +170,11 @@ namespace transport
|
|||||||
const uint8_t * m_SendKey, * m_ReceiveKey, * m_SendSipKey, * m_ReceiveSipKey;
|
const uint8_t * m_SendKey, * m_ReceiveKey, * m_SendSipKey, * m_ReceiveSipKey;
|
||||||
uint16_t m_NextReceivedLen;
|
uint16_t m_NextReceivedLen;
|
||||||
uint8_t * m_NextReceivedBuffer, * m_NextSendBuffer;
|
uint8_t * m_NextReceivedBuffer, * m_NextSendBuffer;
|
||||||
uint8_t m_ReceiveIV[8], m_SendIV[8];
|
union
|
||||||
|
{
|
||||||
|
uint8_t buf[8];
|
||||||
|
uint16_t key;
|
||||||
|
} m_ReceiveIV, m_SendIV;
|
||||||
uint64_t m_ReceiveSequenceNumber, m_SendSequenceNumber;
|
uint64_t m_ReceiveSequenceNumber, m_SendSequenceNumber;
|
||||||
|
|
||||||
i2p::I2NPMessagesHandler m_Handler;
|
i2p::I2NPMessagesHandler m_Handler;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user