Beispiel #1
0
 /// <include file='doc\HMACSHA1.uex' path='docs/doc[@for="HMACSHA1.HashCore"]/*' />
 protected override void HashCore(byte[] rgb, int ib, int cb)
 {
     if (_bHashing == false)
     {
         _hash1.TransformBlock(_rgbInner, 0, 64, _rgbInner, 0);
         _bHashing = true;
     }
     _hash1.TransformBlock(rgb, ib, cb, rgb, ib);
 }
Beispiel #2
0
 protected override void HashCore(byte[] rgb, int ibStart, int cbSize)
 {
     if (_impl != null)
     {
         _impl.TransformBlock(rgb, ibStart, cbSize, null, 0);
     }
     else
     {
         _HashData(rgb, ibStart, cbSize);
     }
 }
Beispiel #3
0
 /// <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);
 }
Beispiel #4
0
        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 ();
	}