mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-08 22:57:52 +00:00
different in and out buffers for tunnel encryption
This commit is contained in:
parent
9c9401ce2f
commit
1fc50a59f5
@ -22,7 +22,7 @@ namespace tunnel
|
|||||||
|
|
||||||
void TransitTunnel::EncryptTunnelMsg (std::shared_ptr<I2NPMessage> tunnelMsg)
|
void TransitTunnel::EncryptTunnelMsg (std::shared_ptr<I2NPMessage> tunnelMsg)
|
||||||
{
|
{
|
||||||
m_Encryption.Encrypt (tunnelMsg->GetPayload () + 4);
|
m_Encryption.Encrypt (tunnelMsg->GetPayload () + 4, tunnelMsg->GetPayload () + 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
TransitTunnelParticipant::~TransitTunnelParticipant ()
|
TransitTunnelParticipant::~TransitTunnelParticipant ()
|
||||||
|
@ -146,7 +146,7 @@ namespace tunnel
|
|||||||
TunnelHopConfig * hop = m_Config->GetLastHop ();
|
TunnelHopConfig * hop = m_Config->GetLastHop ();
|
||||||
while (hop)
|
while (hop)
|
||||||
{
|
{
|
||||||
hop->decryption.Decrypt (payload);
|
hop->decryption.Decrypt (payload, payload);
|
||||||
hop = hop->prev;
|
hop = hop->prev;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
46
aes.cpp
46
aes.cpp
@ -280,74 +280,76 @@ namespace crypto
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void TunnelEncryption::Encrypt (uint8_t * payload)
|
void TunnelEncryption::Encrypt (const uint8_t * in, uint8_t * out)
|
||||||
{
|
{
|
||||||
#ifdef AESNI
|
#ifdef AESNI
|
||||||
__asm__
|
__asm__
|
||||||
(
|
(
|
||||||
// encrypt IV
|
// encrypt IV
|
||||||
"movups (%[payload]), %%xmm0 \n"
|
"movups (%[in]), %%xmm0 \n"
|
||||||
EncryptAES256(sched_iv)
|
EncryptAES256(sched_iv)
|
||||||
"movaps %%xmm0, %%xmm1 \n"
|
"movaps %%xmm0, %%xmm1 \n"
|
||||||
// double IV encryption
|
// double IV encryption
|
||||||
EncryptAES256(sched_iv)
|
EncryptAES256(sched_iv)
|
||||||
"movups %%xmm0, (%[payload]) \n"
|
"movups %%xmm0, (%[out]) \n"
|
||||||
// encrypt data, IV is xmm1
|
// encrypt data, IV is xmm1
|
||||||
"1: \n"
|
"1: \n"
|
||||||
"add $16, %[payload] \n"
|
"add $16, %[in] \n"
|
||||||
"movups (%[payload]), %%xmm0 \n"
|
"add $16, %[out] \n"
|
||||||
|
"movups (%[in]), %%xmm0 \n"
|
||||||
"pxor %%xmm1, %%xmm0 \n"
|
"pxor %%xmm1, %%xmm0 \n"
|
||||||
EncryptAES256(sched_l)
|
EncryptAES256(sched_l)
|
||||||
"movaps %%xmm0, %%xmm1 \n"
|
"movaps %%xmm0, %%xmm1 \n"
|
||||||
"movups %%xmm0, (%[payload]) \n"
|
"movups %%xmm0, (%[out]) \n"
|
||||||
"dec %[num] \n"
|
"dec %[num] \n"
|
||||||
"jnz 1b \n"
|
"jnz 1b \n"
|
||||||
:
|
:
|
||||||
: [sched_iv]"r"(m_IVEncryption.GetKeySchedule ()), [sched_l]"r"(m_LayerEncryption.GetKeySchedule ()),
|
: [sched_iv]"r"(m_IVEncryption.GetKeySchedule ()), [sched_l]"r"(m_LayerEncryption.GetKeySchedule ()),
|
||||||
[payload]"r"(payload), [num]"r"(63) // 63 blocks = 1008 bytes
|
[in]"r"(in), [out]"r"(out), [num]"r"(63) // 63 blocks = 1008 bytes
|
||||||
: "%xmm0", "%xmm1", "cc", "memory"
|
: "%xmm0", "%xmm1", "cc", "memory"
|
||||||
);
|
);
|
||||||
#else
|
#else
|
||||||
m_IVEncryption.Encrypt ((ChipherBlock *)payload, (ChipherBlock *)payload); // iv
|
m_IVEncryption.Encrypt ((const ChipherBlock *)in, (ChipherBlock *)out); // iv
|
||||||
m_LayerEncryption.SetIV (payload);
|
m_LayerEncryption.SetIV (out);
|
||||||
m_LayerEncryption.Encrypt (payload + 16, i2p::tunnel::TUNNEL_DATA_ENCRYPTED_SIZE, payload + 16); // data
|
m_LayerEncryption.Encrypt (in + 16, i2p::tunnel::TUNNEL_DATA_ENCRYPTED_SIZE, out + 16); // data
|
||||||
m_IVEncryption.Encrypt ((ChipherBlock *)payload, (ChipherBlock *)payload); // double iv
|
m_IVEncryption.Encrypt ((ChipherBlock *)out, (ChipherBlock *)out); // double iv
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void TunnelDecryption::Decrypt (uint8_t * payload)
|
void TunnelDecryption::Decrypt (const uint8_t * in, uint8_t * out)
|
||||||
{
|
{
|
||||||
#ifdef AESNI
|
#ifdef AESNI
|
||||||
__asm__
|
__asm__
|
||||||
(
|
(
|
||||||
// decrypt IV
|
// decrypt IV
|
||||||
"movups (%[payload]), %%xmm0 \n"
|
"movups (%[in]), %%xmm0 \n"
|
||||||
DecryptAES256(sched_iv)
|
DecryptAES256(sched_iv)
|
||||||
"movaps %%xmm0, %%xmm1 \n"
|
"movaps %%xmm0, %%xmm1 \n"
|
||||||
// double IV encryption
|
// double IV encryption
|
||||||
DecryptAES256(sched_iv)
|
DecryptAES256(sched_iv)
|
||||||
"movups %%xmm0, (%[payload]) \n"
|
"movups %%xmm0, (%[out]) \n"
|
||||||
// decrypt data, IV is xmm1
|
// decrypt data, IV is xmm1
|
||||||
"1: \n"
|
"1: \n"
|
||||||
"add $16, %[payload] \n"
|
"add $16, %[in] \n"
|
||||||
"movups (%[payload]), %%xmm0 \n"
|
"add $16, %[out] \n"
|
||||||
|
"movups (%[in]), %%xmm0 \n"
|
||||||
"movaps %%xmm0, %%xmm2 \n"
|
"movaps %%xmm0, %%xmm2 \n"
|
||||||
DecryptAES256(sched_l)
|
DecryptAES256(sched_l)
|
||||||
"pxor %%xmm1, %%xmm0 \n"
|
"pxor %%xmm1, %%xmm0 \n"
|
||||||
"movups %%xmm0, (%[payload]) \n"
|
"movups %%xmm0, (%[out]) \n"
|
||||||
"movaps %%xmm2, %%xmm1 \n"
|
"movaps %%xmm2, %%xmm1 \n"
|
||||||
"dec %[num] \n"
|
"dec %[num] \n"
|
||||||
"jnz 1b \n"
|
"jnz 1b \n"
|
||||||
:
|
:
|
||||||
: [sched_iv]"r"(m_IVDecryption.GetKeySchedule ()), [sched_l]"r"(m_LayerDecryption.GetKeySchedule ()),
|
: [sched_iv]"r"(m_IVDecryption.GetKeySchedule ()), [sched_l]"r"(m_LayerDecryption.GetKeySchedule ()),
|
||||||
[payload]"r"(payload), [num]"r"(63) // 63 blocks = 1008 bytes
|
[in]"r"(in), [out]"r"(out), [num]"r"(63) // 63 blocks = 1008 bytes
|
||||||
: "%xmm0", "%xmm1", "%xmm2", "cc", "memory"
|
: "%xmm0", "%xmm1", "%xmm2", "cc", "memory"
|
||||||
);
|
);
|
||||||
#else
|
#else
|
||||||
m_IVDecryption.Decrypt ((ChipherBlock *)payload, (ChipherBlock *)payload); // iv
|
m_IVDecryption.Decrypt ((const ChipherBlock *)in, (ChipherBlock *)out); // iv
|
||||||
m_LayerDecryption.SetIV (payload);
|
m_LayerDecryption.SetIV (out);
|
||||||
m_LayerDecryption.Decrypt (payload + 16, i2p::tunnel::TUNNEL_DATA_ENCRYPTED_SIZE, payload + 16); // data
|
m_LayerDecryption.Decrypt (in + 16, i2p::tunnel::TUNNEL_DATA_ENCRYPTED_SIZE, out + 16); // data
|
||||||
m_IVDecryption.Decrypt ((ChipherBlock *)payload, (ChipherBlock *)payload); // double iv
|
m_IVDecryption.Decrypt ((ChipherBlock *)out, (ChipherBlock *)out); // double iv
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
aes.h
4
aes.h
@ -185,7 +185,7 @@ namespace crypto
|
|||||||
m_IVEncryption.SetKey (ivKey);
|
m_IVEncryption.SetKey (ivKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Encrypt (uint8_t * payload); // 1024 bytes (16 IV + 1008 data)
|
void Encrypt (const uint8_t * in, uint8_t * out); // 1024 bytes (16 IV + 1008 data)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -207,7 +207,7 @@ namespace crypto
|
|||||||
m_IVDecryption.SetKey (ivKey);
|
m_IVDecryption.SetKey (ivKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Decrypt (uint8_t * payload); // 1024 bytes (16 IV + 1008 data)
|
void Decrypt (const uint8_t * in, uint8_t * out); // 1024 bytes (16 IV + 1008 data)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user