diff --git a/NTCPSession.cpp b/NTCPSession.cpp index 88e4eb0a..9930dead 100644 --- a/NTCPSession.cpp +++ b/NTCPSession.cpp @@ -430,7 +430,7 @@ namespace ntcp m_NextMessage = i2p::NewI2NPMessage (); m_NextMessageOffset = 0; - m_Decryption.Decrypt (encrypted, 16, m_NextMessage->buf); + m_Decryption.Decrypt (encrypted, m_NextMessage->buf); uint16_t dataSize = be16toh (*(uint16_t *)m_NextMessage->buf); if (dataSize) { @@ -450,7 +450,7 @@ namespace ntcp } else // message continues { - m_Decryption.Decrypt (encrypted, 16, m_NextMessage->buf + m_NextMessageOffset); + m_Decryption.Decrypt (encrypted, m_NextMessage->buf + m_NextMessageOffset); m_NextMessageOffset += 16; } diff --git a/aes.cpp b/aes.cpp index 3edef651..d1d45462 100644 --- a/aes.cpp +++ b/aes.cpp @@ -204,6 +204,27 @@ namespace crypto return true; } + void CBCEncryption::Encrypt (const uint8_t * in, uint8_t * out) + { +#ifdef __x86_64__ + __asm__ + ( + "movups (%[iv]), %%xmm1 \n" + "movups (%[in]), %%xmm0 \n" + "pxor %%xmm1, %%xmm0 \n" + EncryptAES256 + "movups %%xmm0, (%[out]) \n" + "movups %%xmm0, (%[iv]) \n" + : + : [iv]"r"(&m_LastBlock), [sched]"r"(m_ECBEncryption.GetKeySchedule ()), + [in]"r"(in), [out]"r"(out) + : "%xmm0", "%xmm1", "memory" + ); +#else + Encrypt (1, (const ChipherBlock *)in, (ChipherBlock *)out); +#endif + } + void CBCDecryption::Decrypt (int numBlocks, const ChipherBlock * in, ChipherBlock * out) { #ifdef __x86_64__ @@ -245,6 +266,27 @@ namespace crypto Decrypt (d.quot, (const ChipherBlock *)in, (ChipherBlock *)out); return true; } + + void CBCDecryption::Decrypt (const uint8_t * in, uint8_t * out) + { +#ifdef __x86_64__ + __asm__ + ( + "movups (%[iv]), %%xmm1 \n" + "movups (%[in]), %%xmm0 \n" + "movups %%xmm0, (%[iv]) \n" + DecryptAES256 + "pxor %%xmm1, %%xmm0 \n" + "movups %%xmm0, (%[out]) \n" + : + : [iv]"r"(&m_IV), [sched]"r"(m_ECBDecryption.GetKeySchedule ()), + [in]"r"(in), [out]"r"(out) + : "%xmm0", "%xmm1", "memory" + ); +#else + Decrypt (1, (const ChipherBlock *)in, (ChipherBlock *)out); +#endif + } } } diff --git a/aes.h b/aes.h index 5e3fcf4b..3cd905b6 100644 --- a/aes.h +++ b/aes.h @@ -111,6 +111,7 @@ namespace crypto void Encrypt (int numBlocks, const ChipherBlock * in, ChipherBlock * out); bool Encrypt (const uint8_t * in, std::size_t len, uint8_t * out); + void Encrypt (const uint8_t * in, uint8_t * out); // one block private: @@ -130,6 +131,7 @@ namespace crypto void Decrypt (int numBlocks, const ChipherBlock * in, ChipherBlock * out); bool Decrypt (const uint8_t * in, std::size_t len, uint8_t * out); + void Decrypt (const uint8_t * in, uint8_t * out); // one block private: