コード例 #1
0
ファイル: sha1managed.cs プロジェクト: wwkkww1983/ZJCredit
        private static unsafe void SHATransform(uint *expandedBuffer, uint *state, byte *block)
        {
            uint num1 = *state;
            uint num2 = *(uint *)((IntPtr)state + 4);
            uint num3 = state[2];
            uint num4 = state[3];
            uint num5 = state[4];

            Utils.DWORDFromBigEndian(expandedBuffer, 16, block);
            SHA1Managed.SHAExpand(expandedBuffer);
            int index = 0;

            while (index < 20)
            {
                uint num6  = num5 + (uint)(((int)num1 << 5 | (int)(num1 >> 27)) + ((int)num4 ^ (int)num2 & ((int)num3 ^ (int)num4)) + (int)expandedBuffer[index] + 1518500249);
                uint num7  = num2 << 30 | num2 >> 2;
                uint num8  = num4 + (uint)(((int)num6 << 5 | (int)(num6 >> 27)) + ((int)num3 ^ (int)num1 & ((int)num7 ^ (int)num3)) + (int)expandedBuffer[index + 1] + 1518500249);
                uint num9  = num1 << 30 | num1 >> 2;
                uint num10 = num3 + (uint)(((int)num8 << 5 | (int)(num8 >> 27)) + ((int)num7 ^ (int)num6 & ((int)num9 ^ (int)num7)) + (int)expandedBuffer[index + 2] + 1518500249);
                num5   = num6 << 30 | num6 >> 2;
                num2   = num7 + (uint)(((int)num10 << 5 | (int)(num10 >> 27)) + ((int)num9 ^ (int)num8 & ((int)num5 ^ (int)num9)) + (int)expandedBuffer[index + 3] + 1518500249);
                num4   = num8 << 30 | num8 >> 2;
                num1   = num9 + (uint)(((int)num2 << 5 | (int)(num2 >> 27)) + ((int)num5 ^ (int)num10 & ((int)num4 ^ (int)num5)) + (int)expandedBuffer[index + 4] + 1518500249);
                num3   = num10 << 30 | num10 >> 2;
                index += 5;
            }
            while (index < 40)
            {
                uint num6  = num5 + (uint)(((int)num1 << 5 | (int)(num1 >> 27)) + ((int)num2 ^ (int)num3 ^ (int)num4) + (int)expandedBuffer[index] + 1859775393);
                uint num7  = num2 << 30 | num2 >> 2;
                uint num8  = num4 + (uint)(((int)num6 << 5 | (int)(num6 >> 27)) + ((int)num1 ^ (int)num7 ^ (int)num3) + (int)expandedBuffer[index + 1] + 1859775393);
                uint num9  = num1 << 30 | num1 >> 2;
                uint num10 = num3 + (uint)(((int)num8 << 5 | (int)(num8 >> 27)) + ((int)num6 ^ (int)num9 ^ (int)num7) + (int)expandedBuffer[index + 2] + 1859775393);
                num5   = num6 << 30 | num6 >> 2;
                num2   = num7 + (uint)(((int)num10 << 5 | (int)(num10 >> 27)) + ((int)num8 ^ (int)num5 ^ (int)num9) + (int)expandedBuffer[index + 3] + 1859775393);
                num4   = num8 << 30 | num8 >> 2;
                num1   = num9 + (uint)(((int)num2 << 5 | (int)(num2 >> 27)) + ((int)num10 ^ (int)num4 ^ (int)num5) + (int)expandedBuffer[index + 4] + 1859775393);
                num3   = num10 << 30 | num10 >> 2;
                index += 5;
            }
            while (index < 60)
            {
                uint num6  = num5 + (uint)(((int)num1 << 5 | (int)(num1 >> 27)) + ((int)num2 & (int)num3 | (int)num4 & ((int)num2 | (int)num3)) + (int)expandedBuffer[index] - 1894007588);
                uint num7  = num2 << 30 | num2 >> 2;
                uint num8  = num4 + (uint)(((int)num6 << 5 | (int)(num6 >> 27)) + ((int)num1 & (int)num7 | (int)num3 & ((int)num1 | (int)num7)) + (int)expandedBuffer[index + 1] - 1894007588);
                uint num9  = num1 << 30 | num1 >> 2;
                uint num10 = num3 + (uint)(((int)num8 << 5 | (int)(num8 >> 27)) + ((int)num6 & (int)num9 | (int)num7 & ((int)num6 | (int)num9)) + (int)expandedBuffer[index + 2] - 1894007588);
                num5   = num6 << 30 | num6 >> 2;
                num2   = num7 + (uint)(((int)num10 << 5 | (int)(num10 >> 27)) + ((int)num8 & (int)num5 | (int)num9 & ((int)num8 | (int)num5)) + (int)expandedBuffer[index + 3] - 1894007588);
                num4   = num8 << 30 | num8 >> 2;
                num1   = num9 + (uint)(((int)num2 << 5 | (int)(num2 >> 27)) + ((int)num10 & (int)num4 | (int)num5 & ((int)num10 | (int)num4)) + (int)expandedBuffer[index + 4] - 1894007588);
                num3   = num10 << 30 | num10 >> 2;
                index += 5;
            }
            while (index < 80)
            {
                uint num6  = num5 + (uint)(((int)num1 << 5 | (int)(num1 >> 27)) + ((int)num2 ^ (int)num3 ^ (int)num4) + (int)expandedBuffer[index] - 899497514);
                uint num7  = num2 << 30 | num2 >> 2;
                uint num8  = num4 + (uint)(((int)num6 << 5 | (int)(num6 >> 27)) + ((int)num1 ^ (int)num7 ^ (int)num3) + (int)expandedBuffer[index + 1] - 899497514);
                uint num9  = num1 << 30 | num1 >> 2;
                uint num10 = num3 + (uint)(((int)num8 << 5 | (int)(num8 >> 27)) + ((int)num6 ^ (int)num9 ^ (int)num7) + (int)expandedBuffer[index + 2] - 899497514);
                num5   = num6 << 30 | num6 >> 2;
                num2   = num7 + (uint)(((int)num10 << 5 | (int)(num10 >> 27)) + ((int)num8 ^ (int)num5 ^ (int)num9) + (int)expandedBuffer[index + 3] - 899497514);
                num4   = num8 << 30 | num8 >> 2;
                num1   = num9 + (uint)(((int)num2 << 5 | (int)(num2 >> 27)) + ((int)num10 ^ (int)num4 ^ (int)num5) + (int)expandedBuffer[index + 4] - 899497514);
                num3   = num10 << 30 | num10 >> 2;
                index += 5;
            }
            uint *numPtr = state;
            int   num11  = (int)*numPtr + (int)num1;

            *      numPtr = (uint)num11;
            IntPtr num12  = (IntPtr)state + 4;
            int    num13  = (int)*(uint *)num12 + (int)num2;

            *(int *)num12 = num13;
            IntPtr num14 = (IntPtr)(state + 2);
            int    num15 = (int)*(uint *)num14 + (int)num3;

            *(int *)num14 = num15;
            IntPtr num16 = (IntPtr)(state + 3);
            int    num17 = (int)*(uint *)num16 + (int)num4;

            *(int *)num16 = num17;
            IntPtr num18 = (IntPtr)(state + 4);
            int    num19 = (int)*(uint *)num18 + (int)num5;

            *(int *)num18 = num19;
        }
コード例 #2
0
        private unsafe static void SHATransform(uint *expandedBuffer, uint *state, byte *block)
        {
            uint num  = *state;
            uint num2 = state[1];
            uint num3 = state[2];
            uint num4 = state[3];
            uint num5 = state[4];

            Utils.DWORDFromBigEndian(expandedBuffer, 16, block);
            SHA1Managed.SHAExpand(expandedBuffer);
            int i;

            for (i = 0; i < 20; i += 5)
            {
                num5 += (num << 5 | num >> 27) + (num4 ^ (num2 & (num3 ^ num4))) + expandedBuffer[i] + 1518500249U;
                num2  = (num2 << 30 | num2 >> 2);
                num4 += (num5 << 5 | num5 >> 27) + (num3 ^ (num & (num2 ^ num3))) + expandedBuffer[i + 1] + 1518500249U;
                num   = (num << 30 | num >> 2);
                num3 += (num4 << 5 | num4 >> 27) + (num2 ^ (num5 & (num ^ num2))) + expandedBuffer[i + 2] + 1518500249U;
                num5  = (num5 << 30 | num5 >> 2);
                num2 += (num3 << 5 | num3 >> 27) + (num ^ (num4 & (num5 ^ num))) + expandedBuffer[i + 3] + 1518500249U;
                num4  = (num4 << 30 | num4 >> 2);
                num  += (num2 << 5 | num2 >> 27) + (num5 ^ (num3 & (num4 ^ num5))) + expandedBuffer[i + 4] + 1518500249U;
                num3  = (num3 << 30 | num3 >> 2);
            }
            while (i < 40)
            {
                num5 += (num << 5 | num >> 27) + (num2 ^ num3 ^ num4) + expandedBuffer[i] + 1859775393U;
                num2  = (num2 << 30 | num2 >> 2);
                num4 += (num5 << 5 | num5 >> 27) + (num ^ num2 ^ num3) + expandedBuffer[i + 1] + 1859775393U;
                num   = (num << 30 | num >> 2);
                num3 += (num4 << 5 | num4 >> 27) + (num5 ^ num ^ num2) + expandedBuffer[i + 2] + 1859775393U;
                num5  = (num5 << 30 | num5 >> 2);
                num2 += (num3 << 5 | num3 >> 27) + (num4 ^ num5 ^ num) + expandedBuffer[i + 3] + 1859775393U;
                num4  = (num4 << 30 | num4 >> 2);
                num  += (num2 << 5 | num2 >> 27) + (num3 ^ num4 ^ num5) + expandedBuffer[i + 4] + 1859775393U;
                num3  = (num3 << 30 | num3 >> 2);
                i    += 5;
            }
            while (i < 60)
            {
                num5 += (num << 5 | num >> 27) + ((num2 & num3) | (num4 & (num2 | num3))) + expandedBuffer[i] + 2400959708U;
                num2  = (num2 << 30 | num2 >> 2);
                num4 += (num5 << 5 | num5 >> 27) + ((num & num2) | (num3 & (num | num2))) + expandedBuffer[i + 1] + 2400959708U;
                num   = (num << 30 | num >> 2);
                num3 += (num4 << 5 | num4 >> 27) + ((num5 & num) | (num2 & (num5 | num))) + expandedBuffer[i + 2] + 2400959708U;
                num5  = (num5 << 30 | num5 >> 2);
                num2 += (num3 << 5 | num3 >> 27) + ((num4 & num5) | (num & (num4 | num5))) + expandedBuffer[i + 3] + 2400959708U;
                num4  = (num4 << 30 | num4 >> 2);
                num  += (num2 << 5 | num2 >> 27) + ((num3 & num4) | (num5 & (num3 | num4))) + expandedBuffer[i + 4] + 2400959708U;
                num3  = (num3 << 30 | num3 >> 2);
                i    += 5;
            }
            while (i < 80)
            {
                num5 += (num << 5 | num >> 27) + (num2 ^ num3 ^ num4) + expandedBuffer[i] + 3395469782U;
                num2  = (num2 << 30 | num2 >> 2);
                num4 += (num5 << 5 | num5 >> 27) + (num ^ num2 ^ num3) + expandedBuffer[i + 1] + 3395469782U;
                num   = (num << 30 | num >> 2);
                num3 += (num4 << 5 | num4 >> 27) + (num5 ^ num ^ num2) + expandedBuffer[i + 2] + 3395469782U;
                num5  = (num5 << 30 | num5 >> 2);
                num2 += (num3 << 5 | num3 >> 27) + (num4 ^ num5 ^ num) + expandedBuffer[i + 3] + 3395469782U;
                num4  = (num4 << 30 | num4 >> 2);
                num  += (num2 << 5 | num2 >> 27) + (num3 ^ num4 ^ num5) + expandedBuffer[i + 4] + 3395469782U;
                num3  = (num3 << 30 | num3 >> 2);
                i    += 5;
            }
            *state += num;
            state[1] += num2;
            state[2] += num3;
            state[3] += num4;
            state[4] += num5;
        }