Ejemplo n.º 1
0
        public static byte[] GetHash(byte[] input, int offset, int length)
        {
            if (null == input)
            {
                throw new System.ArgumentNullException("input", "Unable to calculate hash over null input data");
            }

            //Initial values defined in RFC 1321
            ABCDStruct abcd = new ABCDStruct();

            abcd.A = 0x67452301;
            abcd.B = 0xefcdab89;
            abcd.C = 0x98badcfe;
            abcd.D = 0x10325476;

            //We pass in the input array by block, the final block of data must be handled specially for padding & length embedding
            int startIndex = offset;

            while (startIndex <= length - 64)
            {
                MD5Core.GetHashBlock(input, ref abcd, startIndex);
                startIndex += 64;
            }
            // The final data block.
            return(MD5Core.GetHashFinalBlock(input, startIndex, length - startIndex, abcd, (Int64)length * 8));
        }
Ejemplo n.º 2
0
            public byte[] TransformFinalBlock()
            {
                ThrowNotSupportedExceptionForNonThreadSafeMethod();

                totalLength += remainingCount;
                return(MD5Core.GetHashFinalBlock(remainingBuffer, 0, remainingCount, abcdStruct, (Int64)totalLength * 8));
            }
Ejemplo n.º 3
0
        public static byte[] GetHash(byte[] input)
        {
            if (null == input)
            {
                throw new System.ArgumentNullException("input", "Unable to calculate hash over null input data");
            }

            //Initial values defined in RFC 1321
            var abcd = GetInitialStruct();

            //We pass in the input array by block, the final block of data must be handled specially for padding & length embedding
            int startIndex = 0;

            while (startIndex <= input.Length - 64)
            {
                MD5Core.GetHashBlock(input, ref abcd, startIndex);
                startIndex += 64;
            }
            // The final data block.
            return(MD5Core.GetHashFinalBlock(input, startIndex, input.Length - startIndex, abcd, (Int64)input.Length * 8));
        }
Ejemplo n.º 4
0
            public void TransformBlock(byte[] bytes, int offset, int length)
            {
                ThrowNotSupportedExceptionForNonThreadSafeMethod();

                int start = offset;

                if (remainingCount > 0)
                {
                    if (remainingCount + length < BufferSize)
                    {
                        // just append to remaining buffer
                        Buffer.BlockCopy(bytes, offset, remainingBuffer, remainingCount, length);
                        remainingCount += length;
                        return;
                    }

                    // fill up buffer
                    Buffer.BlockCopy(bytes, offset, remainingBuffer, remainingCount, BufferSize - remainingCount);
                    start += BufferSize - remainingCount;
                    // now we have 64 bytes in buffer
                    MD5Core.GetHashBlock(remainingBuffer, ref abcdStruct, 0);
                    totalLength   += BufferSize;
                    remainingCount = 0;
                }

                // while has 64 bytes blocks
                while (start <= length - BufferSize)
                {
                    MD5Core.GetHashBlock(bytes, ref abcdStruct, start);
                    totalLength += BufferSize;
                    start       += BufferSize;
                }

                // save rest (if any)
                if (start != length)
                {
                    remainingCount = length - start;
                    Buffer.BlockCopy(bytes, start, remainingBuffer, 0, remainingCount);
                }
            }
Ejemplo n.º 5
0
            public byte[] Compute16(byte[] bytes)
            {
                if (bytes.Length < 512)
                {
                    return(MD5Core.GetHash(bytes));
                }

                MD5 algorithm = null;

                try
                {
                    algorithm = this.md5Pool.Allocate();
                    return(ComputeHashInternal(algorithm, bytes));
                }
                finally
                {
                    if (algorithm != null)
                    {
                        this.md5Pool.Free(algorithm);
                    }
                }
            }
Ejemplo n.º 6
0
 public byte[] Compute16(byte[] bytes, int offset, int length)
 {
     return(MD5Core.GetHash(bytes, offset, length));
 }
Ejemplo n.º 7
0
 public byte[] Compute16(byte[] bytes)
 {
     return(MD5Core.GetHash(bytes));
 }