Browse Source

shorter padding for optimal packet length

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

12
libi2pd/ECIESX25519AEADRatchetSession.cpp

@ -716,11 +716,17 @@ namespace garlic @@ -716,11 +716,17 @@ 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
paddingSize &= 0x0F; // 0 - 15
if (delta > 3)
{
delta -= 3;
if (paddingSize >= delta) paddingSize %= delta;
}
paddingSize++;
payloadLen += paddingSize + 3;
}
}

Loading…
Cancel
Save