10 #if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING) 11 void ThreeWay_TestInstantiations()
20 const word32 START_E = 0x0b0b;
21 const word32 START_D = 0xb1b1;
22 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 23 const word32 RC_MODULUS = 0x11011;
27 static inline word32 reverseBits(word32 a)
29 a = ((a & 0xAAAAAAAA) >> 1) | ((a & 0x55555555) << 1);
30 a = ((a & 0xCCCCCCCC) >> 2) | ((a & 0x33333333) << 2);
31 return ((a & 0xF0F0F0F0) >> 4) | ((a & 0x0F0F0F0F) << 4);
34 #define mu(a0, a1, a2) \ 36 a1 = reverseBits(a1); \ 37 word32 t = reverseBits(a0); \ 38 a0 = reverseBits(a2); \ 42 #define pi_gamma_pi(a0, a1, a2) \ 45 b2 = rotlFixed(a2, 1U); \ 46 b0 = rotlFixed(a0, 22U); \ 47 a0 = rotlFixed(b0 ^ (a1|(~b2)), 1U); \ 48 a2 = rotlFixed(b2 ^ (b0|(~a1)), 22U);\ 53 #define theta(a0, a1, a2) \ 57 c = rotlFixed(c, 16U) ^ rotlFixed(c, 8U); \ 58 b0 = (a0 << 24) ^ (a2 >> 8) ^ (a1 << 8) ^ (a0 >> 24); \ 59 b1 = (a1 << 24) ^ (a0 >> 8) ^ (a2 << 8) ^ (a1 >> 24); \ 62 a2 ^= c ^ (b0 >> 16) ^ (b1 << 16); \ 65 #define rho(a0, a1, a2) \ 68 pi_gamma_pi(a0, a1, a2); \ 71 void ThreeWay::Base::UncheckedSetKey(
const byte *uk,
unsigned int length,
const NameValuePairs ¶ms)
73 AssertValidKeyLength(length);
75 m_rounds = GetRoundsAndThrowIfInvalid(params,
this);
77 for (
unsigned int i=0; i<3; i++)
78 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);
80 if (!IsForwardTransformation())
82 theta(m_k[0], m_k[1], m_k[2]);
83 mu(m_k[0], m_k[1], m_k[2]);
90 void ThreeWay::Enc::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const 95 Block::Get(inBlock)(a0)(a1)(a2);
99 for(
unsigned i=0; i<m_rounds; i++)
101 a0 ^= m_k[0] ^ (rc<<16);
107 if (rc&0x10000) rc ^= 0x11011;
109 a0 ^= m_k[0] ^ (rc<<16);
117 void ThreeWay::Dec::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const 122 Block::Get(inBlock)(a0)(a1)(a2);
127 for(
unsigned i=0; i<m_rounds; i++)
129 a0 ^= m_k[0] ^ (rc<<16);
135 if (rc&0x10000) rc ^= 0x11011;
137 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.