Browse Source

shorter padding for optimal packet length

pull/1514/head
orignal 5 years ago
parent
commit
7ebf2f010c
  1. 16
      libi2pd/ECIESX25519AEADRatchetSession.cpp

16
libi2pd/ECIESX25519AEADRatchetSession.cpp

@ -716,12 +716,18 @@ namespace garlic
uint8_t paddingSize = 0; uint8_t paddingSize = 0;
if (payloadLen) if (payloadLen)
{ {
// don't create padding if we are close to optimal size int delta = (int)ECIESX25519_OPTIMAL_PAYLOAD_SIZE - (int)payloadLen;
if (first || payloadLen + 19 <= ECIESX25519_OPTIMAL_PAYLOAD_SIZE || payloadLen > ECIESX25519_OPTIMAL_PAYLOAD_SIZE) if (delta < 0 || delta > 3) // don't create padding if we are close to optimal size
{ {
RAND_bytes (&paddingSize, 1); RAND_bytes (&paddingSize, 1);
paddingSize &= 0x0F; paddingSize++; // 1 - 16 paddingSize &= 0x0F; // 0 - 15
payloadLen += paddingSize + 3; if (delta > 3)
{
delta -= 3;
if (paddingSize >= delta) paddingSize %= delta;
}
paddingSize++;
payloadLen += paddingSize + 3;
} }
} }
std::vector<uint8_t> v(payloadLen); std::vector<uint8_t> v(payloadLen);

Loading…
Cancel
Save