mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-13 01:20:22 +03:00
tunnel encryption using AES-NI
This commit is contained in:
parent
6d1d816153
commit
b4b3ba16cc
27
aes.cpp
27
aes.cpp
@ -291,9 +291,36 @@ namespace crypto
|
|||||||
|
|
||||||
void TunnelEncryption::Encrypt (uint8_t * payload)
|
void TunnelEncryption::Encrypt (uint8_t * payload)
|
||||||
{
|
{
|
||||||
|
#ifdef __x86_64__
|
||||||
|
__asm__
|
||||||
|
(
|
||||||
|
// encrypt IV
|
||||||
|
"movups (%[payload]), %%xmm0 \n"
|
||||||
|
EncryptAES256(sched_iv)
|
||||||
|
"movaps %%xmm0, %%xmm1 \n"
|
||||||
|
// double IV encryption
|
||||||
|
EncryptAES256(sched_iv)
|
||||||
|
"movups %%xmm0, (%[payload]) \n"
|
||||||
|
// encrypt data, IV is xmm1
|
||||||
|
"block_et: \n"
|
||||||
|
"add $16, %[payload] \n"
|
||||||
|
"movups (%[payload]), %%xmm0 \n"
|
||||||
|
"pxor %%xmm1, %%xmm0 \n"
|
||||||
|
EncryptAES256(sched_l)
|
||||||
|
"movaps %%xmm0, %%xmm1 \n"
|
||||||
|
"movups %%xmm0, (%[payload]) \n"
|
||||||
|
"dec %[num] \n"
|
||||||
|
"jnz block_et; \n"
|
||||||
|
:
|
||||||
|
: [sched_iv]"r"(m_IVEncryption.GetKeySchedule ()), [sched_l]"r"(m_LayerEncryption.GetKeySchedule ()),
|
||||||
|
[payload]"r"(payload), [num]"r"(63) // 63 blocks = 1008 bytes
|
||||||
|
: "%xmm0", "%xmm1", "cc", "memory"
|
||||||
|
);
|
||||||
|
#else
|
||||||
m_IVEncryption.Encrypt ((ChipherBlock *)payload, (ChipherBlock *)payload); // iv
|
m_IVEncryption.Encrypt ((ChipherBlock *)payload, (ChipherBlock *)payload); // iv
|
||||||
m_LayerEncryption.Encrypt (payload + 16, i2p::tunnel::TUNNEL_DATA_ENCRYPTED_SIZE, payload + 16); // data
|
m_LayerEncryption.Encrypt (payload + 16, i2p::tunnel::TUNNEL_DATA_ENCRYPTED_SIZE, payload + 16); // data
|
||||||
m_IVEncryption.Encrypt ((ChipherBlock *)payload, (ChipherBlock *)payload); // double iv
|
m_IVEncryption.Encrypt ((ChipherBlock *)payload, (ChipherBlock *)payload); // double iv
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void TunnelDecryption::Decrypt (uint8_t * payload)
|
void TunnelDecryption::Decrypt (uint8_t * payload)
|
||||||
|
4
aes.h
4
aes.h
@ -154,7 +154,11 @@ namespace crypto
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
ECBEncryption m_IVEncryption;
|
ECBEncryption m_IVEncryption;
|
||||||
|
#ifdef __x86_64__
|
||||||
|
ECBEncryption m_LayerEncryption;
|
||||||
|
#else
|
||||||
CBCEncryption m_LayerEncryption;
|
CBCEncryption m_LayerEncryption;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
class TunnelDecryption // with double IV encryption
|
class TunnelDecryption // with double IV encryption
|
||||||
|
Loading…
Reference in New Issue
Block a user