7 NAMESPACE_BEGIN(CryptoPP)
11 AssertValidKeyLength(keylen);
13 r = GetRoundsAndThrowIfInvalid(params,
this);
16 static const RC5_WORD MAGIC_P = 0xb7e15163L;
17 static const RC5_WORD MAGIC_Q = 0x9e3779b9L;
18 static const int U=
sizeof(RC5_WORD);
20 const unsigned int c = STDMAX((keylen+U-1)/U, 1U);
23 GetUserKey(LITTLE_ENDIAN_ORDER, l.begin(), c, k, keylen);
26 for (
unsigned j=1; j<sTable.size();j++)
27 sTable[j] = sTable[j-1] + MAGIC_Q;
30 const unsigned n = 3*STDMAX((
unsigned int)sTable.size(), c);
32 for (
unsigned h=0; h < n; h++)
34 a = sTable[h % sTable.size()] = rotlFixed((sTable[h % sTable.size()] + a + b), 3);
35 b = l[h % c] = rotlMod((l[h % c] + a + b), (a+b));
41 void RC5::Enc::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const
43 const RC5_WORD *sptr = sTable;
46 Block::Get(inBlock)(a)(b);
51 for(
unsigned i=0; i<r; i++)
53 a = rotlMod(a^b,b) + sptr[2*i+0];
54 b = rotlMod(a^b,a) + sptr[2*i+1];
60 void RC5::Dec::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const
62 const RC5_WORD *sptr = sTable.end();
65 Block::Get(inBlock)(a)(b);
67 for (
unsigned i=0; i<r; i++)
70 b = rotrMod(b-sptr[1], a) ^ a;
71 a = rotrMod(a-sptr[0], b) ^ b;
interface for retrieving values given their names