aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/block/xtea_sse2/xtea_sse2.cpp58
1 files changed, 47 insertions, 11 deletions
diff --git a/src/block/xtea_sse2/xtea_sse2.cpp b/src/block/xtea_sse2/xtea_sse2.cpp
index db7775103..5d9c7dd05 100644
--- a/src/block/xtea_sse2/xtea_sse2.cpp
+++ b/src/block/xtea_sse2/xtea_sse2.cpp
@@ -1,5 +1,5 @@
/*
-* XTEA SSE2
+* XTEA in SIMD
* (C) 2009 Jack Lloyd
*
* Distributed under the terms of the Botan license
@@ -24,7 +24,10 @@ void xtea_encrypt_8(const byte in[64], byte out[64], const u32bit EK[64])
for(u32bit i = 0; i != 32; i += 2)
{
- SIMD_32 K0(EK[2*i]), K1(EK[2*i+1]), K2(EK[2*i+2]), K3(EK[2*i+3]);
+ SIMD_32 K0(EK[2*i ]);
+ SIMD_32 K1(EK[2*i+1]);
+ SIMD_32 K2(EK[2*i+2]);
+ SIMD_32 K3(EK[2*i+3]);
L0 += (((R0 << 4) ^ (R0 >> 5)) + R0) ^ K0;
L1 += (((R1 << 4) ^ (R1 >> 5)) + R1) ^ K0;
@@ -47,6 +50,43 @@ void xtea_encrypt_8(const byte in[64], byte out[64], const u32bit EK[64])
R1.store_be(out + 48);
}
+void xtea_decrypt_8(const byte in[64], byte out[64], const u32bit EK[64])
+ {
+ SIMD_32 L0 = SIMD_32::load_be(in );
+ SIMD_32 R0 = SIMD_32::load_be(in + 16);
+ SIMD_32 L1 = SIMD_32::load_be(in + 32);
+ SIMD_32 R1 = SIMD_32::load_be(in + 48);
+
+ SIMD_32::transpose(L0, R0, L1, R1);
+
+ for(u32bit i = 0; i != 32; i += 2)
+ {
+ SIMD_32 K0(EK[63 - 2*i]);
+ SIMD_32 K1(EK[62 - 2*i]);
+ SIMD_32 K2(EK[61 - 2*i]);
+ SIMD_32 K3(EK[60 - 2*i]);
+
+ R0 -= (((L0 << 4) ^ (L0 >> 5)) + L0) ^ K0;
+ R1 -= (((L1 << 4) ^ (L1 >> 5)) + L1) ^ K0;
+
+ L0 -= (((R0 << 4) ^ (R0 >> 5)) + R0) ^ K1;
+ L1 -= (((R1 << 4) ^ (R1 >> 5)) + R1) ^ K1;
+
+ R0 -= (((L0 << 4) ^ (L0 >> 5)) + L0) ^ K2;
+ R1 -= (((L1 << 4) ^ (L1 >> 5)) + L1) ^ K2;
+
+ L0 -= (((R0 << 4) ^ (R0 >> 5)) + R0) ^ K3;
+ L1 -= (((R1 << 4) ^ (R1 >> 5)) + R1) ^ K3;
+ }
+
+ SIMD_32::transpose(L0, R0, L1, R1);
+
+ L0.store_be(out);
+ R0.store_be(out + 16);
+ L1.store_be(out + 32);
+ R1.store_be(out + 48);
+ }
+
}
/*
@@ -54,8 +94,6 @@ void xtea_encrypt_8(const byte in[64], byte out[64], const u32bit EK[64])
*/
void XTEA_SSE2::encrypt_n(const byte in[], byte out[], u32bit blocks) const
{
- memset(out, 0, blocks * BLOCK_SIZE);
-
while(blocks >= 8)
{
xtea_encrypt_8(in, out, this->EK);
@@ -72,15 +110,13 @@ void XTEA_SSE2::encrypt_n(const byte in[], byte out[], u32bit blocks) const
*/
void XTEA_SSE2::decrypt_n(const byte in[], byte out[], u32bit blocks) const
{
-#if 0
- while(blocks >= 4)
+ while(blocks >= 8)
{
- xtea_decrypt_4(in, out, this->EK);
- in += 4 * BLOCK_SIZE;
- out += 4 * BLOCK_SIZE;
- blocks -= 4;
+ xtea_decrypt_8(in, out, this->EK);
+ in += 8 * BLOCK_SIZE;
+ out += 8 * BLOCK_SIZE;
+ blocks -= 8;
}
-#endif
XTEA::decrypt_n(in, out, blocks);
}