From fd1ee48dbe7e41ab15448f1369d2f9802a5a0778 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 23 Jan 2020 14:26:40 -0500 Subject: [PATCH] datetime and padding blocks --- libi2pd/ECIESX25519AEADRatchetSession.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/libi2pd/ECIESX25519AEADRatchetSession.cpp b/libi2pd/ECIESX25519AEADRatchetSession.cpp index 1276ef3e..29171584 100644 --- a/libi2pd/ECIESX25519AEADRatchetSession.cpp +++ b/libi2pd/ECIESX25519AEADRatchetSession.cpp @@ -5,6 +5,7 @@ #include "Elligator.h" #include "Tag.h" #include "I2PEndian.h" +#include "Timestamp.h" #include "ECIESX25519AEADRatchetSession.h" namespace i2p @@ -309,18 +310,32 @@ namespace garlic std::vector ECIESX25519AEADRatchetSession::CreatePayload (std::shared_ptr msg) { - size_t payloadLen = 0; + size_t payloadLen = 7; // datatime if (msg) payloadLen += msg->GetPayloadLength () + 13; auto leaseSet = CreateDatabaseStoreMsg (GetOwner ()->GetLeaseSet ()); if (leaseSet) - payloadLen += leaseSet->GetPayloadLength () + 13; + payloadLen += leaseSet->GetPayloadLength () + 13; + uint8_t paddingSize; + RAND_bytes (&paddingSize, 1); + paddingSize &= 0x0F; paddingSize++; // 1 - 16 + payloadLen += paddingSize; std::vector v(payloadLen); size_t offset = 0; + // DateTime + v[offset] = eECIESx25519BlkDateTime; offset++; + htobe16buf (v.data () + offset, 4); offset += 2; + htobe32buf (v.data () + offset, i2p::util::GetSecondsSinceEpoch ()); offset += 4; + // LeaseSet if (leaseSet) offset += CreateGarlicClove (leaseSet, v.data () + offset, payloadLen - offset); + // msg if (msg) offset += CreateGarlicClove (msg, v.data () + offset, payloadLen - offset); + // padding + v[offset] = eECIESx25519BlkPadding; offset++; + htobe16buf (v.data () + offset, paddingSize); offset += 2; + memset (v.data () + offset, 0, paddingSize); offset += paddingSize; return v; }