public bool Test() { bool enc = false, dec = false; byte[] ciphertext = null; byte[] plaintext = null; using (Streamcipher cipher = new Streamcipher(Cipher, _key.Length*8)) { cipher.SetKey(_key, null); ciphertext = new byte[_plaintext.Length]; cipher.Update(_plaintext, ciphertext); enc = CipherMatch(ciphertext); cipher.SetKey(_key, null); plaintext = new byte[_ciphertext.Length]; cipher.Update(_ciphertext, plaintext); dec = PlainMatch(plaintext); } return enc && dec; }
public new bool Test() { bool enc = false, dec = false, dec2 = false; byte[] ciphertext = null; byte[] plaintext = null; using (Streamcipher cipher = new Streamcipher(Cipher, Mode)) { cipher.SetKey(_iv ,_key); ciphertext = new byte[_plaintext.Length]; byte[] c = new byte[64]; byte[] p = new byte[64]; /* test byte-for-byte updating */ for (int s = 0; s < _plaintext.Length; ++s) { System.Buffer.BlockCopy(_plaintext, s, p, 0, 1); cipher.Update(p, c, 1); System.Buffer.BlockCopy(c, 0, ciphertext, s, 1); } enc = CipherMatch(ciphertext); cipher.SetKey(_iv ,_key); plaintext = new byte[_ciphertext.Length]; cipher.Update(_ciphertext, plaintext); dec = PlainMatch(plaintext); /* test mix-sized block updating */ if (_ciphertext.Length > 48) { cipher.SetKey(_iv ,_key); System.Buffer.BlockCopy(_ciphertext, 0, c, 0, 24); cipher.Update(c, p, 24); System.Buffer.BlockCopy(p, 0, plaintext, 0, 24); System.Buffer.BlockCopy(_ciphertext, 24, c, 0, 6); cipher.Update(c, p, 6); System.Buffer.BlockCopy(p, 0, plaintext, 24, 6); System.Buffer.BlockCopy(_ciphertext, 30, c, 0, 5); cipher.Update(c, p, 5); System.Buffer.BlockCopy(p, 0, plaintext, 30, 5); System.Buffer.BlockCopy(_ciphertext, 35, c, 0, 12); cipher.Update(c, p, 12); System.Buffer.BlockCopy(p, 0, plaintext, 35, 12); int remaining = _ciphertext.Length - 6 - 24 - 5 - 12; for (int s = 0; s < remaining; ++s) { System.Buffer.BlockCopy(_ciphertext, s+6+24+5+12, c, 0, 1); cipher.Update(c, p, 1); System.Buffer.BlockCopy(p, 0, plaintext, s+6+24+5+12, 1); } dec2 = PlainMatch(plaintext); } else dec2 = true; } return enc && dec && dec2; }
public double Run() { PerfWatch t = new PerfWatch(); byte[] key = new byte[(keybits + 7) / 8]; byte[] input = new byte[megabytes * 1048576]; byte[] output = new byte[megabytes * 1048576]; t.Start(); t.Stop(); using (Streamcipher sc = new Streamcipher(cipherkind, keybits)) { sc.SetKey(key, null); sc.Update(input, output); GC.Collect(); t.Start(); sc.Update(input, output); t.Stop(); } GC.Collect(); return megabytes / t.seconds(); }