|
|
@ -258,18 +258,23 @@ namespace garlic |
|
|
|
uint16_t keyID = bufbe16toh (buf); buf += 2; // keyID
|
|
|
|
uint16_t keyID = bufbe16toh (buf); buf += 2; // keyID
|
|
|
|
if (flag & ECIESX25519_NEXT_KEY_KEY_PRESENT_FLAG) |
|
|
|
if (flag & ECIESX25519_NEXT_KEY_KEY_PRESENT_FLAG) |
|
|
|
{ |
|
|
|
{ |
|
|
|
i2p::crypto::X25519Keys k; |
|
|
|
m_IsReverseKeyRequested = true; |
|
|
|
k.GenerateKeys (); |
|
|
|
if (!m_NextReceiveKey) |
|
|
|
|
|
|
|
m_NextReceiveKey.reset (new i2p::crypto::X25519Keys ()); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (keyID == m_ReceiveKeyID) return; |
|
|
|
|
|
|
|
else m_ReceiveKeyID++; // TODO
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
m_NextReceiveKey->GenerateKeys (); |
|
|
|
uint8_t sharedSecret[32], tagsetKey[32]; |
|
|
|
uint8_t sharedSecret[32], tagsetKey[32]; |
|
|
|
k.Agree (buf, sharedSecret); |
|
|
|
m_NextReceiveKey->Agree (buf, sharedSecret); |
|
|
|
i2p::crypto::HKDF (sharedSecret, nullptr, 0, "XDHRatchetTagSet", tagsetKey, 32); // tagsetKey = HKDF(sharedSecret, ZEROLEN, "XDHRatchetTagSet", 32)
|
|
|
|
i2p::crypto::HKDF (sharedSecret, nullptr, 0, "XDHRatchetTagSet", tagsetKey, 32); // tagsetKey = HKDF(sharedSecret, ZEROLEN, "XDHRatchetTagSet", 32)
|
|
|
|
auto newTagset = std::make_shared<RatchetTagSet>(shared_from_this ()); |
|
|
|
auto newTagset = std::make_shared<RatchetTagSet>(shared_from_this ()); |
|
|
|
newTagset->SetTagSetID (1 + keyID + m_ReceiveKeyID); |
|
|
|
newTagset->SetTagSetID (1 + keyID + m_ReceiveKeyID); |
|
|
|
newTagset->DHInitialize (receiveTagset->GetNextRootKey (), tagsetKey); |
|
|
|
newTagset->DHInitialize (receiveTagset->GetNextRootKey (), tagsetKey); |
|
|
|
newTagset->NextSessionTagRatchet (); |
|
|
|
newTagset->NextSessionTagRatchet (); |
|
|
|
GenerateMoreReceiveTags (newTagset, GetOwner ()->GetNumTags ()); |
|
|
|
GenerateMoreReceiveTags (newTagset, GetOwner ()->GetNumTags ()); |
|
|
|
m_ReverseKeys.push_back ({m_ReceiveKeyID, k.GetPublicKey ()}); |
|
|
|
|
|
|
|
m_ReceiveKeyID++; |
|
|
|
|
|
|
|
LogPrint (eLogDebug, "Garlic: next receive tagset ", newTagset->GetTagSetID (), " created"); |
|
|
|
LogPrint (eLogDebug, "Garlic: next receive tagset ", newTagset->GetTagSetID (), " created"); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
@ -580,8 +585,8 @@ namespace garlic |
|
|
|
} |
|
|
|
} |
|
|
|
if (m_AckRequests.size () > 0) |
|
|
|
if (m_AckRequests.size () > 0) |
|
|
|
payloadLen += m_AckRequests.size ()*4 + 3; |
|
|
|
payloadLen += m_AckRequests.size ()*4 + 3; |
|
|
|
if (m_ReverseKeys.size () > 0) |
|
|
|
if (m_IsReverseKeyRequested) |
|
|
|
payloadLen += m_ReverseKeys.size ()*(3 + 35); |
|
|
|
payloadLen += 3 + 35; |
|
|
|
uint8_t paddingSize; |
|
|
|
uint8_t paddingSize; |
|
|
|
RAND_bytes (&paddingSize, 1); |
|
|
|
RAND_bytes (&paddingSize, 1); |
|
|
|
paddingSize &= 0x0F; paddingSize++; // 1 - 16
|
|
|
|
paddingSize &= 0x0F; paddingSize++; // 1 - 16
|
|
|
@ -623,16 +628,14 @@ namespace garlic |
|
|
|
m_AckRequests.clear (); |
|
|
|
m_AckRequests.clear (); |
|
|
|
} |
|
|
|
} |
|
|
|
// next keys
|
|
|
|
// next keys
|
|
|
|
if (m_ReverseKeys.size () > 0) |
|
|
|
if (m_IsReverseKeyRequested) |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (auto& it: m_ReverseKeys) |
|
|
|
v[offset] = eECIESx25519BlkNextKey; offset++; |
|
|
|
{ |
|
|
|
htobe16buf (v.data () + offset, 35); offset += 2; |
|
|
|
v[offset] = eECIESx25519BlkNextKey; offset++; |
|
|
|
v[offset] = ECIESX25519_NEXT_KEY_KEY_PRESENT_FLAG | ECIESX25519_NEXT_KEY_REVERSE_KEY_FLAG; offset++; // flag
|
|
|
|
htobe16buf (v.data () + offset, 35); offset += 2; |
|
|
|
htobe16buf (v.data () + offset, m_ReceiveKeyID); offset += 2; // keyid
|
|
|
|
v[offset] = ECIESX25519_NEXT_KEY_KEY_PRESENT_FLAG | ECIESX25519_NEXT_KEY_REVERSE_KEY_FLAG; offset++; // flag
|
|
|
|
memcpy (v.data () + offset, m_NextReceiveKey->GetPublicKey (), 32); offset += 32; // public key
|
|
|
|
htobe16buf (v.data () + offset, it.first); offset += 2; // keyid
|
|
|
|
m_IsReverseKeyRequested = false; |
|
|
|
memcpy (v.data () + offset, it.second, 32); offset += 32; // public key
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// padding
|
|
|
|
// padding
|
|
|
|
v[offset] = eECIESx25519BlkPadding; offset++; |
|
|
|
v[offset] = eECIESx25519BlkPadding; offset++; |
|
|
|