10 #if !defined(NDEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
11 void ThreeWay_TestInstantiations()
18 static const word32 START_E = 0x0b0b;
19 static const word32 START_D = 0xb1b1;
20 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
21 static const word32 RC_MODULUS = 0x11011;
24 static inline word32 reverseBits(word32 a)
26 a = ((a & 0xAAAAAAAA) >> 1) | ((a & 0x55555555) << 1);
27 a = ((a & 0xCCCCCCCC) >> 2) | ((a & 0x33333333) << 2);
28 return ((a & 0xF0F0F0F0) >> 4) | ((a & 0x0F0F0F0F) << 4);
31 #define mu(a0, a1, a2) \
33 a1 = reverseBits(a1); \
34 word32 t = reverseBits(a0); \
35 a0 = reverseBits(a2); \
39 #define pi_gamma_pi(a0, a1, a2) \
42 b2 = rotlFixed(a2, 1U); \
43 b0 = rotlFixed(a0, 22U); \
44 a0 = rotlFixed(b0 ^ (a1|(~b2)), 1U); \
45 a2 = rotlFixed(b2 ^ (b0|(~a1)), 22U);\
50 #define theta(a0, a1, a2) \
54 c = rotlFixed(c, 16U) ^ rotlFixed(c, 8U); \
55 b0 = (a0 << 24) ^ (a2 >> 8) ^ (a1 << 8) ^ (a0 >> 24); \
56 b1 = (a1 << 24) ^ (a0 >> 8) ^ (a2 << 8) ^ (a1 >> 24); \
59 a2 ^= c ^ (b0 >> 16) ^ (b1 << 16); \
62 #define rho(a0, a1, a2) \
65 pi_gamma_pi(a0, a1, a2); \
68 void ThreeWay::Base::UncheckedSetKey(
const byte *uk,
unsigned int length,
const NameValuePairs ¶ms)
70 AssertValidKeyLength(length);
72 m_rounds = GetRoundsAndThrowIfInvalid(params,
this);
74 for (
unsigned int i=0; i<3; i++)
75 m_k[i] = (word32)uk[4*i+3] | ((word32)uk[4*i+2]<<8) | ((word32)uk[4*i+1]<<16) | ((word32)uk[4*i]<<24);
77 if (!IsForwardTransformation())
79 theta(m_k[0], m_k[1], m_k[2]);
80 mu(m_k[0], m_k[1], m_k[2]);
87 void ThreeWay::Enc::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock,
byte *outBlock)
const
92 Block::Get(inBlock)(a0)(a1)(a2);
96 for(
unsigned i=0; i<m_rounds; i++)
98 a0 ^= m_k[0] ^ (rc<<16);
104 if (rc&0x10000) rc ^= 0x11011;
106 a0 ^= m_k[0] ^ (rc<<16);
114 void ThreeWay::Dec::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock,
byte *outBlock)
const
119 Block::Get(inBlock)(a0)(a1)(a2);
124 for(
unsigned i=0; i<m_rounds; i++)
126 a0 ^= m_k[0] ^ (rc<<16);
132 if (rc&0x10000) rc ^= 0x11011;
134 a0 ^= m_k[0] ^ (rc<<16);