8 NAMESPACE_BEGIN(CryptoPP)
12 AssertValidKeyLength(keylen);
14 r = GetRoundsAndThrowIfInvalid(params,
this);
17 static const RC6_WORD MAGIC_P = 0xb7e15163L;
18 static const RC6_WORD MAGIC_Q = 0x9e3779b9L;
19 static const int U=
sizeof(RC6_WORD);
21 const unsigned int c = STDMAX((keylen+U-1)/U, 1U);
24 GetUserKey(LITTLE_ENDIAN_ORDER, l.begin(), c, k, keylen);
27 for (
unsigned j=1; j<sTable.size();j++)
28 sTable[j] = sTable[j-1] + MAGIC_Q;
31 const unsigned n = 3*STDMAX((
unsigned int)sTable.size(), c);
33 for (
unsigned h=0; h < n; h++)
35 a = sTable[h % sTable.size()] = rotlFixed((sTable[h % sTable.size()] + a + b), 3);
36 b = l[h % c] = rotlMod((l[h % c] + a + b), (a+b));
42 void RC6::Enc::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const
44 const RC6_WORD *sptr = sTable;
45 RC6_WORD a, b, c, d, t, u;
47 Block::Get(inBlock)(a)(b)(c)(d);
52 for(
unsigned i=0; i<r; i++)
54 t = rotlFixed(b*(2*b+1), 5);
55 u = rotlFixed(d*(2*d+1), 5);
56 a = rotlMod(a^t,u) + sptr[0];
57 c = rotlMod(c^u,t) + sptr[1];
58 t = a; a = b; b = c; c = d; d = t;
68 void RC6::Dec::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const
70 const RC6_WORD *sptr = sTable.end();
71 RC6_WORD a, b, c, d, t, u;
73 Block::Get(inBlock)(a)(b)(c)(d);
79 for (
unsigned i=0; i < r; i++)
82 t = a; a = d; d = c; c = b; b = t;
83 u = rotlFixed(d*(2*d+1), 5);
84 t = rotlFixed(b*(2*b+1), 5);
85 c = rotrMod(c-sptr[1], t) ^ u;
86 a = rotrMod(a-sptr[0], u) ^ t;
interface for retrieving values given their names