public void ComputeBlocksViaReuse() { int dataLength = 23; byte[] data = new byte[dataLength]; using (SHA1Managed sha1 = new SHA1Managed()) using (SHA1Reuse reuse = new SHA1Reuse()) { SHA1Reuse hash0 = (SHA1Reuse)reuse.Clone(); sha1.TransformBlock(data, 0, dataLength, data, 0); reuse.TransformBlock(data, 0, dataLength, data, 0); hash0.TransformBlock(data, 0, dataLength, data, 0); SHA1Reuse hash1 = (SHA1Reuse)reuse.Clone(); sha1.TransformBlock(data, 0, dataLength, data, 0); reuse.TransformBlock(data, 0, dataLength, data, 0); hash0.TransformBlock(data, 0, dataLength, data, 0); hash1.TransformBlock(data, 0, dataLength, data, 0); SHA1Reuse hash2 = (SHA1Reuse)reuse.Clone(); sha1.TransformBlock(data, 0, dataLength, data, 0); reuse.TransformBlock(data, 0, dataLength, data, 0); hash0.TransformBlock(data, 0, dataLength, data, 0); hash1.TransformBlock(data, 0, dataLength, data, 0); hash2.TransformBlock(data, 0, dataLength, data, 0); SHA1Reuse hash3 = (SHA1Reuse)reuse.Clone(); sha1.TransformFinalBlock(data, dataLength, 0); reuse.TransformFinalBlock(data, dataLength, 0); hash0.TransformFinalBlock(data, dataLength, 0); hash1.TransformFinalBlock(data, dataLength, 0); hash2.TransformFinalBlock(data, dataLength, 0); hash3.TransformFinalBlock(data, dataLength, 0); Assert.IsTrue(sha1.Hash.SequenceEqual(reuse.Hash)); Assert.IsTrue(sha1.Hash.SequenceEqual(hash0.Hash)); Assert.IsTrue(sha1.Hash.SequenceEqual(hash1.Hash)); Assert.IsTrue(sha1.Hash.SequenceEqual(hash2.Hash)); Assert.IsTrue(sha1.Hash.SequenceEqual(hash3.Hash)); } }
public void ComputeBlocksByEmptyBlockSize() { int dataLength = 0; byte[] data = new byte[dataLength]; using (SHA1Managed sha1 = new SHA1Managed()) using (SHA1Reuse reuse = new SHA1Reuse()) { for (int i = 0; i < 10; ++i) { sha1.TransformBlock(data, 0, dataLength, data, 0); reuse.TransformBlock(data, 0, dataLength, data, 0); } sha1.TransformFinalBlock(data, dataLength, 0); reuse.TransformFinalBlock(data, dataLength, 0); Assert.IsTrue(sha1.Hash.SequenceEqual(reuse.Hash)); } }
public void ComputeBlocksWithBlockSize([Values(1, 1024, 324734)] int dataLength) { byte[] data = new byte[dataLength]; using (SHA1Managed sha1 = new SHA1Managed()) using (SHA1Reuse reuse = new SHA1Reuse()) { for (int i = 0; i < 10; ++i) { sha1.TransformBlock(data, 0, dataLength, data, 0); reuse.TransformBlock(data, 0, dataLength, data, 0); } sha1.TransformFinalBlock(data, dataLength, 0); reuse.TransformFinalBlock(data, dataLength, 0); Assert.IsTrue(sha1.Hash.SequenceEqual(reuse.Hash)); } }
public void ComputeBlocksViaClone() { int dataLength = 23; byte[] data = new byte[dataLength]; using (SHA1Managed sha1 = new SHA1Managed()) using (SHA1Managed sha1_1 = new SHA1Managed()) using (SHA1Reuse reuse = new SHA1Reuse()) using (SHA1Reuse hash0 = (SHA1Reuse)reuse.Clone()) { for (int i = 0; i < 100; i++) { sha1.TransformBlock(data, 0, dataLength, data, 0); sha1_1.TransformBlock(data, 0, dataLength, data, 0); reuse.TransformBlock(data, 0, dataLength, data, 0); hash0.TransformBlock(data, 0, dataLength, data, 0); } using (var hash1 = hash0.Clone() as HashAlgorithm) using (var hash2 = hash0.Clone() as HashAlgorithm) using (var hash3 = hash0.Clone() as HashAlgorithm) { sha1.TransformFinalBlock(data, dataLength, 0); reuse.TransformFinalBlock(data, dataLength, 0); hash0.TransformFinalBlock(data, dataLength, 0); Assert.That(sha1.Hash, Is.EqualTo(reuse.Hash)); Assert.That(sha1.Hash, Is.EqualTo(hash0.Hash)); for (int i = 0; i < 100; i++) { sha1_1.TransformBlock(data, 0, dataLength, data, 0); hash1.TransformBlock(data, 0, dataLength, data, 0); hash2.TransformBlock(data, 0, dataLength, data, 0); hash3.TransformBlock(data, 0, dataLength, data, 0); } hash1.TransformFinalBlock(data, dataLength, 0); hash2.TransformFinalBlock(data, dataLength, 0); hash3.TransformFinalBlock(data, dataLength, 0); sha1_1.TransformFinalBlock(data, dataLength, 0); Assert.That(sha1_1.Hash, Is.EqualTo(hash1.Hash)); Assert.That(sha1_1.Hash, Is.EqualTo(hash2.Hash)); Assert.That(sha1_1.Hash, Is.EqualTo(hash3.Hash)); } } }
public void ComputeBlocksByEmptyBlockSize() { int dataLength = 0; byte[] data = new byte[dataLength]; using (SHA1Managed sha1 = new SHA1Managed()) using (SHA1Reuse reuse = new SHA1Reuse()) { for (int i = 0; i < 10; ++i) { sha1.TransformBlock(data, 0, dataLength, data, 0); reuse.TransformBlock(data, 0, dataLength, data, 0); } sha1.TransformFinalBlock(data, dataLength, 0); reuse.TransformFinalBlock(data, dataLength, 0); Assert.IsTrue(sha1.Hash.SequenceEqual(reuse.Hash)); } }
public void ComputeBlocksWithBlockSize([Values(1, 1024, 324734)]int dataLength) { byte[] data = new byte[dataLength]; using (SHA1Managed sha1 = new SHA1Managed()) using (SHA1Reuse reuse = new SHA1Reuse()) { for (int i = 0; i < 10; ++i) { sha1.TransformBlock(data, 0, dataLength, data, 0); reuse.TransformBlock(data, 0, dataLength, data, 0); } sha1.TransformFinalBlock(data, dataLength, 0); reuse.TransformFinalBlock(data, dataLength, 0); Assert.IsTrue(sha1.Hash.SequenceEqual(reuse.Hash)); } }
public void ComputeBlocksViaClone() { int dataLength = 23; byte[] data = new byte[dataLength]; using (SHA1Managed sha1 = new SHA1Managed()) using (SHA1Managed sha1_1 = new SHA1Managed()) using (SHA1Reuse reuse = new SHA1Reuse()) using (SHA1Reuse hash0 = (SHA1Reuse)reuse.Clone()) { for (int i = 0; i < 100; i++) { sha1.TransformBlock(data, 0, dataLength, data, 0); sha1_1.TransformBlock(data, 0, dataLength, data, 0); reuse.TransformBlock(data, 0, dataLength, data, 0); hash0.TransformBlock(data, 0, dataLength, data, 0); } using(var hash1 = hash0.Clone() as HashAlgorithm) using(var hash2 = hash0.Clone() as HashAlgorithm) using(var hash3 = hash0.Clone() as HashAlgorithm) { sha1.TransformFinalBlock(data, dataLength, 0); reuse.TransformFinalBlock(data, dataLength, 0); hash0.TransformFinalBlock(data, dataLength, 0); Assert.That(sha1.Hash, Is.EqualTo(reuse.Hash)); Assert.That(sha1.Hash, Is.EqualTo(hash0.Hash)); for (int i = 0; i < 100; i++) { sha1_1.TransformBlock(data, 0, dataLength, data, 0); hash1.TransformBlock(data, 0, dataLength, data, 0); hash2.TransformBlock(data, 0, dataLength, data, 0); hash3.TransformBlock(data, 0, dataLength, data, 0); } hash1.TransformFinalBlock(data, dataLength, 0); hash2.TransformFinalBlock(data, dataLength, 0); hash3.TransformFinalBlock(data, dataLength, 0); sha1_1.TransformFinalBlock(data, dataLength, 0); Assert.That(sha1_1.Hash, Is.EqualTo(hash1.Hash)); Assert.That(sha1_1.Hash, Is.EqualTo(hash2.Hash)); Assert.That(sha1_1.Hash, Is.EqualTo(hash3.Hash)); } } }
public void ComputeBlocksViaReuse() { int dataLength = 23; byte[] data = new byte[dataLength]; using (SHA1Managed sha1 = new SHA1Managed()) using (SHA1Reuse reuse = new SHA1Reuse()) { SHA1Reuse hash0 = (SHA1Reuse)reuse.Clone(); sha1.TransformBlock(data, 0, dataLength, data, 0); reuse.TransformBlock(data, 0, dataLength, data, 0); hash0.TransformBlock(data, 0, dataLength, data, 0); SHA1Reuse hash1 = (SHA1Reuse)reuse.Clone(); sha1.TransformBlock(data, 0, dataLength, data, 0); reuse.TransformBlock(data, 0, dataLength, data, 0); hash0.TransformBlock(data, 0, dataLength, data, 0); hash1.TransformBlock(data, 0, dataLength, data, 0); SHA1Reuse hash2 = (SHA1Reuse)reuse.Clone(); sha1.TransformBlock(data, 0, dataLength, data, 0); reuse.TransformBlock(data, 0, dataLength, data, 0); hash0.TransformBlock(data, 0, dataLength, data, 0); hash1.TransformBlock(data, 0, dataLength, data, 0); hash2.TransformBlock(data, 0, dataLength, data, 0); SHA1Reuse hash3 = (SHA1Reuse)reuse.Clone(); sha1.TransformFinalBlock(data, dataLength, 0); reuse.TransformFinalBlock(data, dataLength, 0); hash0.TransformFinalBlock(data, dataLength, 0); hash1.TransformFinalBlock(data, dataLength, 0); hash2.TransformFinalBlock(data, dataLength, 0); hash3.TransformFinalBlock(data, dataLength, 0); Assert.IsTrue(sha1.Hash.SequenceEqual(reuse.Hash)); Assert.IsTrue(sha1.Hash.SequenceEqual(hash0.Hash)); Assert.IsTrue(sha1.Hash.SequenceEqual(hash1.Hash)); Assert.IsTrue(sha1.Hash.SequenceEqual(hash2.Hash)); Assert.IsTrue(sha1.Hash.SequenceEqual(hash3.Hash)); } }