mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +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)
|
||||
{
|
||||
#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_LayerEncryption.Encrypt (payload + 16, i2p::tunnel::TUNNEL_DATA_ENCRYPTED_SIZE, payload + 16); // data
|
||||
m_IVEncryption.Encrypt ((ChipherBlock *)payload, (ChipherBlock *)payload); // double iv
|
||||
#endif
|
||||
}
|
||||
|
||||
void TunnelDecryption::Decrypt (uint8_t * payload)
|
||||
|
Loading…
Reference in New Issue
Block a user