public RC2Transform (RC2 rc2Algo, bool encryption, byte[] key, byte[] iv)
: base (rc2Algo, encryption, iv)
{
#if ONLY_1_1
if (key == null)
throw new ArgumentNullException ("key");
#endif
int t1 = rc2Algo.EffectiveKeySize;
if (key == null) {
key = KeyBuilder.Key (rc2Algo.KeySize >> 3);
} else {
key = (byte[]) key.Clone ();
t1 = Math.Min (t1, key.Length << 3);
}
int t = key.Length;
if (!KeySizes.IsLegalKeySize (rc2Algo.LegalKeySizes, (t << 3))) {
string msg = Locale.GetText ("Key is too small ({0} bytes), it should be between {1} and {2} bytes long.",
t, 5, 16);
throw new CryptographicException (msg);
}
// Expand key into a byte array, then convert to word
// array since we always access the key in 16bit chunks.
byte[] L = new byte [128];
int t8 = ((t1 + 7) >> 3); // divide by 8
int tm = 255 % (2 << (8 + t1 - (t8 << 3) - 1));
for (int i=0; i < t; i++)
L [i] = key [i];
for (int i=t; i < 128; i++)
L [i] = (byte) (pitable [(L [i-1] + L [i-t]) & 0xff]);
L [128-t8] = pitable [L [128-t8] & tm];
for (int i=127-t8; i >= 0; i--)
L [i] = pitable [L [i+1] ^ L [i+t8]];
K = new UInt16 [64];
int pos = 0;
for (int i=0; i < 64; i++)
K [i] = (UInt16) (L [pos++] + (L [pos++] << 8));
}