private static void Test(IStreamCrypto crypto, int originSize, string hex, string hex2) { Assert.AreEqual(@"RC4", crypto.Name); Span <byte> h1 = hex.FromHex(); Span <byte> h2 = hex2.FromHex(); Span <byte> i = new byte[originSize]; Span <byte> o = stackalloc byte[i.Length]; crypto.Update(i, o); Assert.IsTrue(o.SequenceEqual(h1)); crypto.Update(i, o); Assert.IsTrue(o.SequenceEqual(h2)); crypto.Reset(); crypto.Update(h1, o); Assert.IsTrue(o.SequenceEqual(i)); crypto.Update(h2, o); Assert.IsTrue(o.SequenceEqual(i)); crypto.Dispose(); }
private static void Test(IStreamCrypto crypto, Span <byte> origin) { Span <byte> o = stackalloc byte[origin.Length]; crypto.Update(origin, o); crypto.Dispose(); }
private static void Test(IStreamCrypto crypto, string hex, string hex2) { Assert.AreEqual(@"AES-CFB", crypto.Name); Span <byte> h1 = hex.FromHex(); Span <byte> h2 = hex2.FromHex(); Span <byte> o = stackalloc byte[h1.Length]; crypto.Update(h1, o); Assert.IsTrue(o.SequenceEqual(h2)); crypto.Reset(); crypto.Update(h1[..73], o);
private const int Step = 1 * 1024 * 1024; // 1 MB public static void Test(IStreamCrypto crypto) { ReadOnlySpan <byte> i = new byte[Step]; Span <byte> o = new byte[Step]; var sw = Stopwatch.StartNew(); var length = 0ul; do { crypto.Update(i, o); ++length; } while (sw.ElapsedMilliseconds < 2000); sw.Stop(); crypto.Dispose(); var result = length * Step / sw.Elapsed.TotalSeconds / 1024.0 / 1024.0; Console.WriteLine($@"{result:F2} MB/s"); }
public void Test(IStreamCrypto crypto) { Span <byte> o = new byte[_step]; ulong length = 0ul; double totalSeconds = 0.0; do { ReadOnlySpan <byte> i = RandomNumberGenerator.GetBytes(_step); Stopwatch sw = Stopwatch.StartNew(); crypto.Update(i, o); sw.Stop(); totalSeconds += sw.Elapsed.TotalSeconds; ++length; } while (totalSeconds < _duration); crypto.Dispose(); double result = length * (ulong)_step / totalSeconds / 1024.0 / 1024.0; Console.WriteLine($@"{result:F2} MB/s"); }
protected virtual void UpdateStream(IStreamCrypto crypto, ReadOnlySpan <byte> source, Span <byte> destination) { crypto.Update(source, destination); }