mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
aes key expansion
This commit is contained in:
parent
6bf5d98c4d
commit
527ac413b1
70
aes.cpp
70
aes.cpp
@ -5,6 +5,76 @@ namespace i2p
|
||||
{
|
||||
namespace crypto
|
||||
{
|
||||
|
||||
#ifdef __x86_64__
|
||||
|
||||
#define KeyExpansion256 \
|
||||
"pshufd $0xff, %%xmm2, %%xmm2 \n" \
|
||||
"movaps %%xmm1, %%xmm4 \n" \
|
||||
"pslldq $4, %%xmm4 \n" \
|
||||
"pxor %%xmm4, %%xmm1 \n" \
|
||||
"pslldq $4, %%xmm4 \n" \
|
||||
"pxor %%xmm4, %%xmm1 \n" \
|
||||
"pslldq $4, %%xmm4 \n" \
|
||||
"pxor %%xmm4, %%xmm1 \n" \
|
||||
"pxor %%xmm2, %%xmm1 \n" \
|
||||
"movups %%xmm1, (%%rcx) \n" \
|
||||
"aeskeygenassist $0, %%xmm1, %%xmm4 \n" \
|
||||
"pshufd $0xaa, %%xmm4, %%xmm2 \n" \
|
||||
"movaps %%xmm3, %%xmm4 \n" \
|
||||
"pslldq $4, %%xmm4 \n" \
|
||||
"pxor %%xmm4, %%xmm3 \n" \
|
||||
"pslldq $4, %%xmm4 \n" \
|
||||
"pxor %%xmm4, %%xmm3 \n" \
|
||||
"pslldq $4, %%xmm4 \n" \
|
||||
"pxor %%xmm4, %%xmm3 \n" \
|
||||
"pxor %%xmm2, %%xmm3 \n" \
|
||||
"movups %%xmm3, 16(%%rcx) \n" \
|
||||
"add $32, %%rcx \n"
|
||||
|
||||
|
||||
void ECNEncryptionAESNI::SetKey (const uint8_t * key)
|
||||
{
|
||||
__asm__
|
||||
(
|
||||
"movups (%%rsi), %%xmm1 \n"
|
||||
"movups 16(%%rsi), %%xmm3 \n"
|
||||
"movups %%xmm1, (%%rdi) \n"
|
||||
"movups %%xmm3, 16(%%rdi) \n"
|
||||
"lea 32(%%rdi), %%rcx \n"
|
||||
"aeskeygenassist $1, %%xmm3, %%xmm2 \n"
|
||||
KeyExpansion256
|
||||
"aeskeygenassist $2, %%xmm3, %%xmm2 \n"
|
||||
KeyExpansion256
|
||||
"aeskeygenassist $4, %%xmm3, %%xmm2 \n"
|
||||
KeyExpansion256
|
||||
"aeskeygenassist $8, %%xmm3, %%xmm2 \n"
|
||||
KeyExpansion256
|
||||
"aeskeygenassist $10, %%xmm3, %%xmm2 \n"
|
||||
KeyExpansion256
|
||||
"aeskeygenassist $20, %%xmm3, %%xmm2 \n"
|
||||
KeyExpansion256
|
||||
"aeskeygenassist $40, %%xmm3, %%xmm2 \n"
|
||||
// key expansion final
|
||||
"pshufd $0xff, %%xmm2, %%xmm2 \n"
|
||||
"movaps %%xmm1, %%xmm4 \n"
|
||||
"pslldq $4, %%xmm4 \n"
|
||||
"pxor %%xmm4, %%xmm1 \n"
|
||||
"pslldq $4, %%xmm4 \n"
|
||||
"pxor %%xmm4, %%xmm1 \n"
|
||||
"pslldq $4, %%xmm4 \n"
|
||||
"pxor %%xmm4, %%xmm1 \n"
|
||||
"pxor %%xmm2, %%xmm1 \n"
|
||||
"movups %%xmm1, (%%rcx) \n"
|
||||
: // output
|
||||
: "S" (key), "D" (m_KeySchedule) // input
|
||||
: "%rcx" // modified
|
||||
);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
void CBCEncryption::Encrypt (int numBlocks, const ChipherBlock * in, ChipherBlock * out)
|
||||
{
|
||||
for (int i = 0; i < numBlocks; i++)
|
||||
|
Loading…
Reference in New Issue
Block a user