From 5337aa10f762c98535d2170f367aa8cece7910b6 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 2 Jan 2020 13:30:54 -0500 Subject: [PATCH] check AES tag first --- libi2pd/Garlic.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/libi2pd/Garlic.cpp b/libi2pd/Garlic.cpp index 3c255d0d..1ee69df5 100644 --- a/libi2pd/Garlic.cpp +++ b/libi2pd/Garlic.cpp @@ -435,13 +435,8 @@ namespace garlic return; } buf += 4; // length - if (GetEncryptionType () == i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD_RARCHET) - { - HandleECIESx25519 (buf, length - 4); - return; - } - // otherwise assume ElGamal/AES auto it = m_Tags.find (SessionTag(buf)); + // AES tag might be used even if encryption type is not ElGamal/AES if (it != m_Tags.end ()) { // tag found. Use AES @@ -460,7 +455,13 @@ namespace garlic } else { - // tag not found. Use ElGamal + // tag not found. Handle depending on encryption type + if (GetEncryptionType () == i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD_RARCHET) + { + HandleECIESx25519 (buf, length - 4); + return; + } + // otherwise assume ElGamal/AES ElGamalBlock elGamal; if (length >= 514 && Decrypt (buf, (uint8_t *)&elGamal, m_Ctx)) {