protected override byte[] HashFinal() { if (_impl != null) { _impl.TransformFinalBlock(Array.Empty <byte>(), 0, 0); return(_impl.Hash); } return(_EndHash()); }
/// <include file='doc\HMACSHA1.uex' path='docs/doc[@for="HMACSHA1.HashFinal"]/*' /> protected override byte[] HashFinal() { if (_bHashing == false) { _hash1.TransformBlock(_rgbInner, 0, 64, _rgbInner, 0); _bHashing = true; } // finalize the original hash _hash1.TransformFinalBlock(new byte[0], 0, 0); // write the outer array _hash2.TransformBlock(_rgbOuter, 0, 64, _rgbOuter, 0); // write the inner hash and finalize the hash _hash2.TransformFinalBlock(_hash1.Hash, 0, _hash1.Hash.Length); _bHashing = false; return(_hash2.Hash); }
public static IEnumerable<Block> Split(Stream stream, SHA1 sha1Provider, bool threadsafe) { byte[] buffer = new byte[Math.Min(Settings.SplitterReadBufferSize, stream.Length)]; int bufferUsed = 0; while(true) { // Fill up the buffer int readCount = stream.Read(buffer, bufferUsed, buffer.Length - bufferUsed); sha1Provider.TransformBlock(buffer, bufferUsed, readCount, buffer, bufferUsed); bufferUsed += readCount; List<Block> blocks = Split(buffer, 0, bufferUsed); if (stream.Position == stream.Length) { // End of stream - flush and exit foreach (Block hashBlock in blocks) { yield return hashBlock; } break; } else { // Send all except the last block. Keep the last block. Block last = blocks[blocks.Count - 1]; blocks.RemoveAt(blocks.Count - 1); foreach (Block hashBlock in blocks) { yield return hashBlock; } if (threadsafe) { buffer = new byte[Math.Min(Settings.SplitterReadBufferSize, stream.Length)]; } // Works fine with overlapping Array.Copy(last.Buffer, last.Offset, buffer, 0, last.Length); bufferUsed = last.Length; } } sha1Provider.TransformFinalBlock(new byte[0], 0, 0); }
public void FIPS186_e (string testName, SHA1 hash, byte[] input, byte[] result) { byte[] copy = new byte [input.Length]; for (int i=0; i < input.Length - 1; i++) hash.TransformBlock (input, i, 1, copy, i); byte[] output = hash.TransformFinalBlock (input, input.Length - 1, 1); // LAMESPEC or FIXME: TransformFinalBlock doesn't return HashValue ! // AssertEquals (testName + ".e.1", result, output); Assert.AreEqual (result, hash.Hash, testName + ".e"); // required or next operation will still return old hash hash.Initialize (); }
public void FIPS186_d (string testName, SHA1 hash, byte[] input, byte[] result) { byte[] output = hash.TransformFinalBlock (input, 0, input.Length); // LAMESPEC or FIXME: TransformFinalBlock doesn't return HashValue ! // AssertEquals( testName + ".d.1", result, output ); Assert.AreEqual (result, hash.Hash, testName + ".d"); // required or next operation will still return old hash hash.Initialize (); }