Browse Source

random non-zero padding

pull/225/head
orignal 10 years ago
parent
commit
bf4c33325c
  1. 14
      TunnelGateway.cpp
  2. 4
      TunnelGateway.h

14
TunnelGateway.cpp

@ -10,6 +10,14 @@ namespace i2p
{ {
namespace tunnel namespace tunnel
{ {
TunnelGatewayBuffer::TunnelGatewayBuffer (uint32_t tunnelID): m_TunnelID (tunnelID),
m_CurrentTunnelDataMsg (nullptr), m_RemainingSize (0)
{
context.GetRandomNumberGenerator ().GenerateBlock (m_NonZeroRandomBuffer, TUNNEL_DATA_MAX_PAYLOAD_SIZE);
for (size_t i = 0; i < TUNNEL_DATA_MAX_PAYLOAD_SIZE; i++)
if (!m_NonZeroRandomBuffer[i]) m_NonZeroRandomBuffer[i] = 1;
}
TunnelGatewayBuffer::~TunnelGatewayBuffer () TunnelGatewayBuffer::~TunnelGatewayBuffer ()
{ {
} }
@ -160,7 +168,11 @@ namespace tunnel
payload[-1] = 0; // zero payload[-1] = 0; // zero
ptrdiff_t paddingSize = payload - buf - 25; // 25 = 24 + 1 ptrdiff_t paddingSize = payload - buf - 25; // 25 = 24 + 1
if (paddingSize > 0) if (paddingSize > 0)
memset (buf + 24, 1, paddingSize); // padding TODO: fill with random data {
// non-zero padding
auto randomOffset = rnd.GenerateWord32 (0, TUNNEL_DATA_MAX_PAYLOAD_SIZE - paddingSize);
memcpy (buf + 24, m_NonZeroRandomBuffer + randomOffset, paddingSize);
}
// we can't fill message header yet because encryption is required // we can't fill message header yet because encryption is required
m_TunnelDataMsgs.push_back (m_CurrentTunnelDataMsg); m_TunnelDataMsgs.push_back (m_CurrentTunnelDataMsg);

4
TunnelGateway.h

@ -14,8 +14,7 @@ namespace tunnel
class TunnelGatewayBuffer class TunnelGatewayBuffer
{ {
public: public:
TunnelGatewayBuffer (uint32_t tunnelID): m_TunnelID (tunnelID), TunnelGatewayBuffer (uint32_t tunnelID);
m_CurrentTunnelDataMsg (nullptr), m_RemainingSize (0) {};
~TunnelGatewayBuffer (); ~TunnelGatewayBuffer ();
void PutI2NPMsg (const TunnelMessageBlock& block); void PutI2NPMsg (const TunnelMessageBlock& block);
const std::vector<std::shared_ptr<I2NPMessage> >& GetTunnelDataMsgs () const { return m_TunnelDataMsgs; }; const std::vector<std::shared_ptr<I2NPMessage> >& GetTunnelDataMsgs () const { return m_TunnelDataMsgs; };
@ -32,6 +31,7 @@ namespace tunnel
std::vector<std::shared_ptr<I2NPMessage> > m_TunnelDataMsgs; std::vector<std::shared_ptr<I2NPMessage> > m_TunnelDataMsgs;
std::shared_ptr<I2NPMessage> m_CurrentTunnelDataMsg; std::shared_ptr<I2NPMessage> m_CurrentTunnelDataMsg;
size_t m_RemainingSize; size_t m_RemainingSize;
uint8_t m_NonZeroRandomBuffer[TUNNEL_DATA_MAX_PAYLOAD_SIZE];
}; };
class TunnelGateway class TunnelGateway

Loading…
Cancel
Save