GetHashBlock() static private method

static private GetHashBlock ( byte input, ABCDStruct, &ABCDValue, int ibStart ) : void
input byte
ABCDValue ABCDStruct,
ibStart int
return void
コード例 #1
0
ファイル: MD5Core.cs プロジェクト: Makzz90/VKClient_re
 internal static byte[] GetHashFinalBlock(byte[] input, int ibStart, int cbSize, ABCDStruct ABCD, long len)
 {
     byte[] input1 = new byte[64];
     byte[] bytes  = BitConverter.GetBytes(len);
     Array.Copy((Array)input, ibStart, (Array)input1, 0, cbSize);
     input1[cbSize] = (byte)128;
     if (cbSize < 56)
     {
         Array.Copy((Array)bytes, 0, (Array)input1, 56, 8);
         MD5Core.GetHashBlock(input1, ref ABCD, 0);
     }
     else
     {
         MD5Core.GetHashBlock(input1, ref ABCD, 0);
         byte[] input2 = new byte[64];
         Array.Copy((Array)bytes, 0, (Array)input2, 56, 8);
         MD5Core.GetHashBlock(input2, ref ABCD, 0);
     }
     byte[] numArray = new byte[16];
     Array.Copy((Array)BitConverter.GetBytes(ABCD.A), 0, (Array)numArray, 0, 4);
     Array.Copy((Array)BitConverter.GetBytes(ABCD.B), 0, (Array)numArray, 4, 4);
     Array.Copy((Array)BitConverter.GetBytes(ABCD.C), 0, (Array)numArray, 8, 4);
     Array.Copy((Array)BitConverter.GetBytes(ABCD.D), 0, (Array)numArray, 12, 4);
     return(numArray);
 }
コード例 #2
0
    public static byte[] GetHash(byte[] input)
    {
        if (null == input)
        {
            throw new System.ArgumentNullException("input", "Unable to calculate hash over null input data");
        }

        //Intitial 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 specialy for padding & length embeding
        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));
    }
コード例 #3
0
        protected override void HashCore(byte[] array, int ibStart, int cbSize)
        {
            int startIndex       = ibStart;
            int totalArrayLength = _dataSize + cbSize;

            if (totalArrayLength >= 64)
            {
                Array.Copy(array, startIndex, _data, _dataSize, 64 - _dataSize);
                // Process message of 64 bytes (512 bits)
                MD5Core.GetHashBlock(_data, ref _abcd, 0);
                startIndex       += 64 - _dataSize;
                totalArrayLength -= 64;
                while (totalArrayLength >= 64)
                {
                    Array.Copy(array, startIndex, _data, 0, 64);
                    MD5Core.GetHashBlock(array, ref _abcd, startIndex);
                    totalArrayLength -= 64;
                    startIndex       += 64;
                }
                _dataSize = totalArrayLength;
                Array.Copy(array, startIndex, _data, 0, totalArrayLength);
            }
            else
            {
                Array.Copy(array, startIndex, _data, _dataSize, cbSize);
                _dataSize = totalArrayLength;
            }
            _totalLength += cbSize;
        }
コード例 #4
0
ファイル: MD5Core.cs プロジェクト: Makzz90/VKClient_re
    public static byte[] GetHash(byte[] input)
    {
        if (input == null)
        {
            throw new ArgumentNullException("input", "Unable to calculate hash over null input data");
        }
        ABCDStruct ABCDValue = new ABCDStruct();

        ABCDValue.A = 1732584193U;
        ABCDValue.B = 4023233417U;
        ABCDValue.C = 2562383102U;
        ABCDValue.D = 271733878U;
        int ibStart = 0;

        while (ibStart <= input.Length - 64)
        {
            MD5Core.GetHashBlock(input, ref ABCDValue, ibStart);
            ibStart += 64;
        }
        return(MD5Core.GetHashFinalBlock(input, ibStart, input.Length - ibStart, ABCDValue, (long)input.Length * 8L));
    }
コード例 #5
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);
                }
            }
コード例 #6
0
ファイル: FipsEncryptor.cs プロジェクト: stvoidmain/ravendb
            public void TransformBlock(byte[] bytes, int offset, int length)
            {
                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;
                    }
                    else
                    {
                        // 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);
                }
            }