mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
shorter padding for optimal packet length
This commit is contained in:
parent
3db4421aa7
commit
7ebf2f010c
@ -716,12 +716,18 @@ namespace garlic
|
||||
uint8_t paddingSize = 0;
|
||||
if (payloadLen)
|
||||
{
|
||||
// don't create padding if we are close to optimal size
|
||||
if (first || payloadLen + 19 <= ECIESX25519_OPTIMAL_PAYLOAD_SIZE || payloadLen > ECIESX25519_OPTIMAL_PAYLOAD_SIZE)
|
||||
{
|
||||
int delta = (int)ECIESX25519_OPTIMAL_PAYLOAD_SIZE - (int)payloadLen;
|
||||
if (delta < 0 || delta > 3) // don't create padding if we are close to optimal size
|
||||
{
|
||||
RAND_bytes (&paddingSize, 1);
|
||||
paddingSize &= 0x0F; paddingSize++; // 1 - 16
|
||||
payloadLen += paddingSize + 3;
|
||||
paddingSize &= 0x0F; // 0 - 15
|
||||
if (delta > 3)
|
||||
{
|
||||
delta -= 3;
|
||||
if (paddingSize >= delta) paddingSize %= delta;
|
||||
}
|
||||
paddingSize++;
|
||||
payloadLen += paddingSize + 3;
|
||||
}
|
||||
}
|
||||
std::vector<uint8_t> v(payloadLen);
|
||||
|
Loading…
Reference in New Issue
Block a user