public Init ( bool forEncryption, ICipherParameters parameters ) : void | ||
forEncryption | bool | |
parameters | ICipherParameters | |
Результат | void |
public void Init(
bool forEncryption,
ICipherParameters parameters)
{
/*
* Salsa20 encryption and decryption is completely
* symmetrical, so the 'forEncryption' is
* irrelevant. (Like 90% of stream ciphers)
*/
ParametersWithIV ivParams = parameters as ParametersWithIV;
if (ivParams == null)
throw new ArgumentException("Salsa20 Init requires an IV", "parameters");
byte[] iv = ivParams.GetIV();
if (iv == null || iv.Length != 8)
throw new ArgumentException("Salsa20 requires exactly 8 bytes of IV");
KeyParameter key = ivParams.Parameters as KeyParameter;
if (key == null)
throw new ArgumentException("Salsa20 Init requires a key", "parameters");
workingKey = key.GetKey();
workingIV = iv;
setKey(workingKey, workingIV);
}
private void salsa20Test2( ICipherParameters parameters, string v0, string v65472, string v65536) { IStreamCipher salsa = new Salsa20Engine(); byte[] buf = new byte[64]; salsa.Init(true, parameters); for (int i = 0; i != 1025; i++) { salsa.ProcessBytes(zeroes, 0, 64, buf, 0); switch (i) { case 0: if (!AreEqual(buf, Hex.Decode(v0))) { mismatch("v0", v0, buf); } break; case 1023: if (!AreEqual(buf, Hex.Decode(v65472))) { mismatch("v65472", v65472, buf); } break; case 1024: if (!AreEqual(buf, Hex.Decode(v65536))) { mismatch("v65536", v65536, buf); } break; default: // ignore break; } } }