10 void RC5::Base::UncheckedSetKey(
const byte *k,
unsigned int keylen,
const NameValuePairs ¶ms)
12 AssertValidKeyLength(keylen);
14 r = GetRoundsAndThrowIfInvalid(params,
this);
17 static const RC5_WORD MAGIC_P = 0xb7e15163L;
18 static const RC5_WORD MAGIC_Q = 0x9e3779b9L;
19 static const int U=
sizeof(RC5_WORD);
21 const unsigned int c =
STDMAX((keylen+U-1)/U, 1U);
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()] = rotlConstant<3>((sTable[h % sTable.size()] + a + b));
36 b = l[h % c] =
rotlMod((l[h % c] + a + b), (a+b));
42 void RC5::Enc::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock,
byte *outBlock)
const
44 const RC5_WORD *sptr = sTable;
47 Block::Get(inBlock)(a)(b);
52 for(
unsigned i=0; i<r; i++)
54 a =
rotlMod(a^b,b) + sptr[2*i+0];
55 b =
rotlMod(a^b,a) + sptr[2*i+1];
61 void RC5::Dec::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock,
byte *outBlock)
const
63 const RC5_WORD *sptr = sTable.end();
66 Block::Get(inBlock)(a)(b);
68 for (
unsigned i=0; i<r; i++)