mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 13:27:17 +01:00
random non-zero padding
This commit is contained in:
parent
be1a4548e6
commit
bf4c33325c
|
@ -10,6 +10,14 @@ namespace i2p
|
|||
{
|
||||
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 ()
|
||||
{
|
||||
}
|
||||
|
@ -160,7 +168,11 @@ namespace tunnel
|
|||
payload[-1] = 0; // zero
|
||||
ptrdiff_t paddingSize = payload - buf - 25; // 25 = 24 + 1
|
||||
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
|
||||
m_TunnelDataMsgs.push_back (m_CurrentTunnelDataMsg);
|
||||
|
|
|
@ -14,8 +14,7 @@ namespace tunnel
|
|||
class TunnelGatewayBuffer
|
||||
{
|
||||
public:
|
||||
TunnelGatewayBuffer (uint32_t tunnelID): m_TunnelID (tunnelID),
|
||||
m_CurrentTunnelDataMsg (nullptr), m_RemainingSize (0) {};
|
||||
TunnelGatewayBuffer (uint32_t tunnelID);
|
||||
~TunnelGatewayBuffer ();
|
||||
void PutI2NPMsg (const TunnelMessageBlock& block);
|
||||
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::shared_ptr<I2NPMessage> m_CurrentTunnelDataMsg;
|
||||
size_t m_RemainingSize;
|
||||
uint8_t m_NonZeroRandomBuffer[TUNNEL_DATA_MAX_PAYLOAD_SIZE];
|
||||
};
|
||||
|
||||
class TunnelGateway
|
||||
|
|
Loading…
Reference in a new issue