8 NAMESPACE_BEGIN(CryptoPP)
10 void ThreeWay_TestInstantiations()
16 static const word32 START_E = 0x0b0b;
17 static const word32 START_D = 0xb1b1;
18 static const word32 RC_MODULUS = 0x11011;
20 static inline word32 reverseBits(word32 a)
22 a = ((a & 0xAAAAAAAA) >> 1) | ((a & 0x55555555) << 1);
23 a = ((a & 0xCCCCCCCC) >> 2) | ((a & 0x33333333) << 2);
24 return ((a & 0xF0F0F0F0) >> 4) | ((a & 0x0F0F0F0F) << 4);
27 #define mu(a0, a1, a2) \
29 a1 = reverseBits(a1); \
30 word32 t = reverseBits(a0); \
31 a0 = reverseBits(a2); \
35 #define pi_gamma_pi(a0, a1, a2) \
38 b2 = rotlFixed(a2, 1U); \
39 b0 = rotlFixed(a0, 22U); \
40 a0 = rotlFixed(b0 ^ (a1|(~b2)), 1U); \
41 a2 = rotlFixed(b2 ^ (b0|(~a1)), 22U);\
46 #define theta(a0, a1, a2) \
50 c = rotlFixed(c, 16U) ^ rotlFixed(c, 8U); \
51 b0 = (a0 << 24) ^ (a2 >> 8) ^ (a1 << 8) ^ (a0 >> 24); \
52 b1 = (a1 << 24) ^ (a0 >> 8) ^ (a2 << 8) ^ (a1 >> 24); \
55 a2 ^= c ^ (b0 >> 16) ^ (b1 << 16); \
58 #define rho(a0, a1, a2) \
61 pi_gamma_pi(a0, a1, a2); \
64 void ThreeWay::Base::UncheckedSetKey(
const byte *uk,
unsigned int length,
const NameValuePairs ¶ms)
66 AssertValidKeyLength(length);
68 m_rounds = GetRoundsAndThrowIfInvalid(params,
this);
70 for (
unsigned int i=0; i<3; i++)
71 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);
73 if (!IsForwardTransformation())
75 theta(m_k[0], m_k[1], m_k[2]);
76 mu(m_k[0], m_k[1], m_k[2]);
77 m_k[0] = ByteReverse(m_k[0]);
78 m_k[1] = ByteReverse(m_k[1]);
79 m_k[2] = ByteReverse(m_k[2]);
83 void ThreeWay::Enc::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const
88 Block::Get(inBlock)(a0)(a1)(a2);
92 for(
unsigned i=0; i<m_rounds; i++)
94 a0 ^= m_k[0] ^ (rc<<16);
100 if (rc&0x10000) rc ^= 0x11011;
102 a0 ^= m_k[0] ^ (rc<<16);
110 void ThreeWay::Dec::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const
115 Block::Get(inBlock)(a0)(a1)(a2);
120 for(
unsigned i=0; i<m_rounds; i++)
122 a0 ^= m_k[0] ^ (rc<<16);
128 if (rc&0x10000) rc ^= 0x11011;
130 a0 ^= m_k[0] ^ (rc<<16);
interface for retrieving values given their names