8 #include <botan/xtea_simd.h>
9 #include <botan/loadstor.h>
10 #include <botan/internal/simd_32.h>
16 void xtea_encrypt_8(
const byte in[64],
byte out[64],
const u32bit EK[64])
23 SIMD_32::transpose(L0, R0, L1, R1);
25 for(
size_t i = 0; i != 32; i += 2)
28 SIMD_32 K1(EK[2*i+1]);
29 SIMD_32 K2(EK[2*i+2]);
30 SIMD_32 K3(EK[2*i+3]);
32 L0 += (((R0 << 4) ^ (R0 >> 5)) +
R0) ^ K0;
33 L1 += (((R1 << 4) ^ (R1 >> 5)) +
R1) ^ K0;
35 R0 += (((L0 << 4) ^ (L0 >> 5)) + L0) ^ K1;
36 R1 += (((L1 << 4) ^ (L1 >> 5)) + L1) ^ K1;
38 L0 += (((R0 << 4) ^ (R0 >> 5)) +
R0) ^ K2;
39 L1 += (((R1 << 4) ^ (R1 >> 5)) +
R1) ^ K2;
41 R0 += (((L0 << 4) ^ (L0 >> 5)) + L0) ^ K3;
42 R1 += (((L1 << 4) ^ (L1 >> 5)) + L1) ^ K3;
45 SIMD_32::transpose(L0, R0, L1, R1);
48 R0.store_be(out + 16);
49 L1.store_be(out + 32);
50 R1.store_be(out + 48);
53 void xtea_decrypt_8(
const byte in[64],
byte out[64],
const u32bit EK[64])
60 SIMD_32::transpose(L0, R0, L1, R1);
62 for(
size_t i = 0; i != 32; i += 2)
64 SIMD_32 K0(EK[63 - 2*i]);
65 SIMD_32 K1(EK[62 - 2*i]);
66 SIMD_32 K2(EK[61 - 2*i]);
67 SIMD_32 K3(EK[60 - 2*i]);
69 R0 -= (((L0 << 4) ^ (L0 >> 5)) + L0) ^ K0;
70 R1 -= (((L1 << 4) ^ (L1 >> 5)) + L1) ^ K0;
72 L0 -= (((R0 << 4) ^ (R0 >> 5)) +
R0) ^ K1;
73 L1 -= (((R1 << 4) ^ (R1 >> 5)) +
R1) ^ K1;
75 R0 -= (((L0 << 4) ^ (L0 >> 5)) + L0) ^ K2;
76 R1 -= (((L1 << 4) ^ (L1 >> 5)) + L1) ^ K2;
78 L0 -= (((R0 << 4) ^ (R0 >> 5)) +
R0) ^ K3;
79 L1 -= (((R1 << 4) ^ (R1 >> 5)) +
R1) ^ K3;
82 SIMD_32::transpose(L0, R0, L1, R1);
85 R0.store_be(out + 16);
86 L1.store_be(out + 32);
87 R1.store_be(out + 48);
101 xtea_encrypt_8(in, out, KS);
120 xtea_decrypt_8(in, out, KS);
void encrypt_n(const byte in[], byte out[], size_t blocks) const
T load_be(const byte in[], size_t off)
void decrypt_n(const byte in[], byte out[], size_t blocks) const
void decrypt_n(const byte in[], byte out[], size_t blocks) const
void encrypt_n(const byte in[], byte out[], size_t blocks) const
const SecureVector< u32bit > & get_EK() const