10 #if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING) 11 void ThreeWay_TestInstantiations()
20 const word32 START_E = 0x0b0b;
21 const word32 START_D = 0xb1b1;
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 = rotlConstant<1>(a2); \ 43 b0 = rotlConstant<22>(a0); \ 44 a0 = rotlConstant<1>(b0 ^ (a1|(~b2))); \ 45 a2 = rotlConstant<22>(b2 ^ (b0|(~a1))); \ 50 #define theta(a0, a1, a2) \ 54 c = rotlConstant<16>(c) ^ rotlConstant<8>(c); \ 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);
Utility functions for the Crypto++ library.
Access a block of memory.
Classes for the 3-Way block cipher.
Access a block of memory.
Crypto++ library namespace.
byte ByteReverse(byte value)
Reverses bytes in a 8-bit value.
Interface for retrieving values given their names.