mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-31 04:44:13 +00:00
try ECIESx25519 tag first
This commit is contained in:
parent
e3c8f3fd6f
commit
510b85fd23
@ -487,6 +487,24 @@ namespace garlic
|
|||||||
LogPrint (eLogWarning, "Garlic: message length ", length, " is less than 32 bytes");
|
LogPrint (eLogWarning, "Garlic: message length ", length, " is less than 32 bytes");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
bool found = false;
|
||||||
|
if (SupportsEncryptionType (i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD_RATCHET))
|
||||||
|
{
|
||||||
|
// try ECIESx25519 tag
|
||||||
|
uint64_t tag;
|
||||||
|
memcpy (&tag, buf, 8);
|
||||||
|
auto it1 = m_ECIESx25519Tags.find (tag);
|
||||||
|
if (it1 != m_ECIESx25519Tags.end ())
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
|
if (!it1->second.session->HandleNextMessage (buf, length, it1->second.index))
|
||||||
|
LogPrint (eLogError, "Garlic: can't handle ECIES-X25519-AEAD-Ratchet message");
|
||||||
|
m_ECIESx25519Tags.erase (it1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found) // assume new session
|
||||||
{
|
{
|
||||||
// AES tag not found. Handle depending on encryption type
|
// AES tag not found. Handle depending on encryption type
|
||||||
// try ElGamal/AES first if leading block is 514
|
// try ElGamal/AES first if leading block is 514
|
||||||
@ -502,12 +520,17 @@ namespace garlic
|
|||||||
HandleAESBlock (buf + 514, length - 514, decryption, msg->from);
|
HandleAESBlock (buf + 514, length - 514, decryption, msg->from);
|
||||||
}
|
}
|
||||||
else if (SupportsEncryptionType (i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD_RATCHET))
|
else if (SupportsEncryptionType (i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD_RATCHET))
|
||||||
|
{
|
||||||
// otherwise ECIESx25519
|
// otherwise ECIESx25519
|
||||||
HandleECIESx25519 (buf, length); // TODO: check tag first
|
auto session = std::make_shared<ECIESX25519AEADRatchetSession> (this, false); // incoming
|
||||||
|
if (!session->HandleNextMessage (buf, length, 0))
|
||||||
|
LogPrint (eLogError, "Garlic: can't handle ECIES-X25519-AEAD-Ratchet message");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
LogPrint (eLogError, "Garlic: Failed to decrypt message");
|
LogPrint (eLogError, "Garlic: Failed to decrypt message");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GarlicDestination::HandleAESBlock (uint8_t * buf, size_t len, std::shared_ptr<AESDecryption> decryption,
|
void GarlicDestination::HandleAESBlock (uint8_t * buf, size_t len, std::shared_ptr<AESDecryption> decryption,
|
||||||
std::shared_ptr<i2p::tunnel::InboundTunnel> from)
|
std::shared_ptr<i2p::tunnel::InboundTunnel> from)
|
||||||
@ -906,26 +929,6 @@ namespace garlic
|
|||||||
i2p::fs::Remove (it);
|
i2p::fs::Remove (it);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GarlicDestination::HandleECIESx25519 (const uint8_t * buf, size_t len)
|
|
||||||
{
|
|
||||||
uint64_t tag;
|
|
||||||
memcpy (&tag, buf, 8);
|
|
||||||
ECIESX25519AEADRatchetSessionPtr session;
|
|
||||||
int index = 0;
|
|
||||||
auto it = m_ECIESx25519Tags.find (tag);
|
|
||||||
if (it != m_ECIESx25519Tags.end ())
|
|
||||||
{
|
|
||||||
session = it->second.session;
|
|
||||||
index = it->second.index;
|
|
||||||
m_ECIESx25519Tags.erase (tag);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
session = std::make_shared<ECIESX25519AEADRatchetSession> (this, false); // incoming
|
|
||||||
|
|
||||||
if (!session->HandleNextMessage (buf, len, index))
|
|
||||||
LogPrint (eLogError, "Garlic: can't handle ECIES-X25519-AEAD-Ratchet message");
|
|
||||||
}
|
|
||||||
|
|
||||||
void GarlicDestination::HandleECIESx25519GarlicClove (const uint8_t * buf, size_t len)
|
void GarlicDestination::HandleECIESx25519GarlicClove (const uint8_t * buf, size_t len)
|
||||||
{
|
{
|
||||||
const uint8_t * buf1 = buf;
|
const uint8_t * buf1 = buf;
|
||||||
|
@ -255,9 +255,6 @@ namespace garlic
|
|||||||
std::shared_ptr<i2p::tunnel::InboundTunnel> from);
|
std::shared_ptr<i2p::tunnel::InboundTunnel> from);
|
||||||
void HandleGarlicPayload (uint8_t * buf, size_t len, std::shared_ptr<i2p::tunnel::InboundTunnel> from);
|
void HandleGarlicPayload (uint8_t * buf, size_t len, std::shared_ptr<i2p::tunnel::InboundTunnel> from);
|
||||||
|
|
||||||
// ECIES-X25519-AEAD-Ratchet
|
|
||||||
void HandleECIESx25519 (const uint8_t * buf, size_t len);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
BN_CTX * m_Ctx; // incoming
|
BN_CTX * m_Ctx; // incoming
|
||||||
|
Loading…
x
Reference in New Issue
Block a user