Beispiel #1
0
        internal static void ChachaCore(int rounds, uint[] input, uint[] x)
        {
            if (input.Length != 16)
            {
                throw new ArgumentException();
            }
            if (x.Length != 16)
            {
                throw new ArgumentException();
            }
            if (rounds % 2 != 0)
            {
                throw new ArgumentException("Number of rounds must be even");
            }
            uint num   = input[0];
            uint num2  = input[1];
            uint num3  = input[2];
            uint num4  = input[3];
            uint num5  = input[4];
            uint num6  = input[5];
            uint num7  = input[6];
            uint num8  = input[7];
            uint num9  = input[8];
            uint num10 = input[9];
            uint num11 = input[10];
            uint num12 = input[11];
            uint num13 = input[12];
            uint num14 = input[13];
            uint num15 = input[14];
            uint num16 = input[15];

            for (int i = rounds; i > 0; i -= 2)
            {
                num   += num5;
                num13  = Salsa20Engine.R(num13 ^ num, 16);
                num9  += num13;
                num5   = Salsa20Engine.R(num5 ^ num9, 12);
                num   += num5;
                num13  = Salsa20Engine.R(num13 ^ num, 8);
                num9  += num13;
                num5   = Salsa20Engine.R(num5 ^ num9, 7);
                num2  += num6;
                num14  = Salsa20Engine.R(num14 ^ num2, 16);
                num10 += num14;
                num6   = Salsa20Engine.R(num6 ^ num10, 12);
                num2  += num6;
                num14  = Salsa20Engine.R(num14 ^ num2, 8);
                num10 += num14;
                num6   = Salsa20Engine.R(num6 ^ num10, 7);
                num3  += num7;
                num15  = Salsa20Engine.R(num15 ^ num3, 16);
                num11 += num15;
                num7   = Salsa20Engine.R(num7 ^ num11, 12);
                num3  += num7;
                num15  = Salsa20Engine.R(num15 ^ num3, 8);
                num11 += num15;
                num7   = Salsa20Engine.R(num7 ^ num11, 7);
                num4  += num8;
                num16  = Salsa20Engine.R(num16 ^ num4, 16);
                num12 += num16;
                num8   = Salsa20Engine.R(num8 ^ num12, 12);
                num4  += num8;
                num16  = Salsa20Engine.R(num16 ^ num4, 8);
                num12 += num16;
                num8   = Salsa20Engine.R(num8 ^ num12, 7);
                num   += num6;
                num16  = Salsa20Engine.R(num16 ^ num, 16);
                num11 += num16;
                num6   = Salsa20Engine.R(num6 ^ num11, 12);
                num   += num6;
                num16  = Salsa20Engine.R(num16 ^ num, 8);
                num11 += num16;
                num6   = Salsa20Engine.R(num6 ^ num11, 7);
                num2  += num7;
                num13  = Salsa20Engine.R(num13 ^ num2, 16);
                num12 += num13;
                num7   = Salsa20Engine.R(num7 ^ num12, 12);
                num2  += num7;
                num13  = Salsa20Engine.R(num13 ^ num2, 8);
                num12 += num13;
                num7   = Salsa20Engine.R(num7 ^ num12, 7);
                num3  += num8;
                num14  = Salsa20Engine.R(num14 ^ num3, 16);
                num9  += num14;
                num8   = Salsa20Engine.R(num8 ^ num9, 12);
                num3  += num8;
                num14  = Salsa20Engine.R(num14 ^ num3, 8);
                num9  += num14;
                num8   = Salsa20Engine.R(num8 ^ num9, 7);
                num4  += num5;
                num15  = Salsa20Engine.R(num15 ^ num4, 16);
                num10 += num15;
                num5   = Salsa20Engine.R(num5 ^ num10, 12);
                num4  += num5;
                num15  = Salsa20Engine.R(num15 ^ num4, 8);
                num10 += num15;
                num5   = Salsa20Engine.R(num5 ^ num10, 7);
            }
            x[0]  = num + input[0];
            x[1]  = num2 + input[1];
            x[2]  = num3 + input[2];
            x[3]  = num4 + input[3];
            x[4]  = num5 + input[4];
            x[5]  = num6 + input[5];
            x[6]  = num7 + input[6];
            x[7]  = num8 + input[7];
            x[8]  = num9 + input[8];
            x[9]  = num10 + input[9];
            x[10] = num11 + input[10];
            x[11] = num12 + input[11];
            x[12] = num13 + input[12];
            x[13] = num14 + input[13];
            x[14] = num15 + input[14];
            x[15] = num16 + input[15];
        }
        internal static void SalsaCore(int rounds, uint[] input, uint[] x)
        {
            if (input.Length != 16)
            {
                throw new ArgumentException();
            }
            if (x.Length != 16)
            {
                throw new ArgumentException();
            }
            if (rounds % 2 != 0)
            {
                throw new ArgumentException("Number of rounds must be even");
            }
            uint num   = input[0];
            uint num2  = input[1];
            uint num3  = input[2];
            uint num4  = input[3];
            uint num5  = input[4];
            uint num6  = input[5];
            uint num7  = input[6];
            uint num8  = input[7];
            uint num9  = input[8];
            uint num10 = input[9];
            uint num11 = input[10];
            uint num12 = input[11];
            uint num13 = input[12];
            uint num14 = input[13];
            uint num15 = input[14];
            uint num16 = input[15];

            for (int i = rounds; i > 0; i -= 2)
            {
                num5  ^= Salsa20Engine.R(num + num13, 7);
                num9  ^= Salsa20Engine.R(num5 + num, 9);
                num13 ^= Salsa20Engine.R(num9 + num5, 13);
                num   ^= Salsa20Engine.R(num13 + num9, 18);
                num10 ^= Salsa20Engine.R(num6 + num2, 7);
                num14 ^= Salsa20Engine.R(num10 + num6, 9);
                num2  ^= Salsa20Engine.R(num14 + num10, 13);
                num6  ^= Salsa20Engine.R(num2 + num14, 18);
                num15 ^= Salsa20Engine.R(num11 + num7, 7);
                num3  ^= Salsa20Engine.R(num15 + num11, 9);
                num7  ^= Salsa20Engine.R(num3 + num15, 13);
                num11 ^= Salsa20Engine.R(num7 + num3, 18);
                num4  ^= Salsa20Engine.R(num16 + num12, 7);
                num8  ^= Salsa20Engine.R(num4 + num16, 9);
                num12 ^= Salsa20Engine.R(num8 + num4, 13);
                num16 ^= Salsa20Engine.R(num12 + num8, 18);
                num2  ^= Salsa20Engine.R(num + num4, 7);
                num3  ^= Salsa20Engine.R(num2 + num, 9);
                num4  ^= Salsa20Engine.R(num3 + num2, 13);
                num   ^= Salsa20Engine.R(num4 + num3, 18);
                num7  ^= Salsa20Engine.R(num6 + num5, 7);
                num8  ^= Salsa20Engine.R(num7 + num6, 9);
                num5  ^= Salsa20Engine.R(num8 + num7, 13);
                num6  ^= Salsa20Engine.R(num5 + num8, 18);
                num12 ^= Salsa20Engine.R(num11 + num10, 7);
                num9  ^= Salsa20Engine.R(num12 + num11, 9);
                num10 ^= Salsa20Engine.R(num9 + num12, 13);
                num11 ^= Salsa20Engine.R(num10 + num9, 18);
                num13 ^= Salsa20Engine.R(num16 + num15, 7);
                num14 ^= Salsa20Engine.R(num13 + num16, 9);
                num15 ^= Salsa20Engine.R(num14 + num13, 13);
                num16 ^= Salsa20Engine.R(num15 + num14, 18);
            }
            x[0]  = num + input[0];
            x[1]  = num2 + input[1];
            x[2]  = num3 + input[2];
            x[3]  = num4 + input[3];
            x[4]  = num5 + input[4];
            x[5]  = num6 + input[5];
            x[6]  = num7 + input[6];
            x[7]  = num8 + input[7];
            x[8]  = num9 + input[8];
            x[9]  = num10 + input[9];
            x[10] = num11 + input[10];
            x[11] = num12 + input[11];
            x[12] = num13 + input[12];
            x[13] = num14 + input[13];
            x[14] = num15 + input[14];
            x[15] = num16 + input[15];
        }
Beispiel #3
0
        internal static void ChachaCore(int rounds, uint[] input, uint[] x)
        {
            //IL_0007: Unknown result type (might be due to invalid IL or missing references)
            //IL_0014: Unknown result type (might be due to invalid IL or missing references)
            //IL_0024: Unknown result type (might be due to invalid IL or missing references)
            if (input.Length != 16)
            {
                throw new ArgumentException();
            }
            if (x.Length != 16)
            {
                throw new ArgumentException();
            }
            if (rounds % 2 != 0)
            {
                throw new ArgumentException("Number of rounds must be even");
            }
            uint num   = input[0];
            uint num2  = input[1];
            uint num3  = input[2];
            uint num4  = input[3];
            uint num5  = input[4];
            uint num6  = input[5];
            uint num7  = input[6];
            uint num8  = input[7];
            uint num9  = input[8];
            uint num10 = input[9];
            uint num11 = input[10];
            uint num12 = input[11];
            uint num13 = input[12];
            uint num14 = input[13];
            uint num15 = input[14];
            uint num16 = input[15];

            for (int num17 = rounds; num17 > 0; num17 -= 2)
            {
                num   += num5;
                num13  = Salsa20Engine.R(num13 ^ num, 16);
                num9  += num13;
                num5   = Salsa20Engine.R(num5 ^ num9, 12);
                num   += num5;
                num13  = Salsa20Engine.R(num13 ^ num, 8);
                num9  += num13;
                num5   = Salsa20Engine.R(num5 ^ num9, 7);
                num2  += num6;
                num14  = Salsa20Engine.R(num14 ^ num2, 16);
                num10 += num14;
                num6   = Salsa20Engine.R(num6 ^ num10, 12);
                num2  += num6;
                num14  = Salsa20Engine.R(num14 ^ num2, 8);
                num10 += num14;
                num6   = Salsa20Engine.R(num6 ^ num10, 7);
                num3  += num7;
                num15  = Salsa20Engine.R(num15 ^ num3, 16);
                num11 += num15;
                num7   = Salsa20Engine.R(num7 ^ num11, 12);
                num3  += num7;
                num15  = Salsa20Engine.R(num15 ^ num3, 8);
                num11 += num15;
                num7   = Salsa20Engine.R(num7 ^ num11, 7);
                num4  += num8;
                num16  = Salsa20Engine.R(num16 ^ num4, 16);
                num12 += num16;
                num8   = Salsa20Engine.R(num8 ^ num12, 12);
                num4  += num8;
                num16  = Salsa20Engine.R(num16 ^ num4, 8);
                num12 += num16;
                num8   = Salsa20Engine.R(num8 ^ num12, 7);
                num   += num6;
                num16  = Salsa20Engine.R(num16 ^ num, 16);
                num11 += num16;
                num6   = Salsa20Engine.R(num6 ^ num11, 12);
                num   += num6;
                num16  = Salsa20Engine.R(num16 ^ num, 8);
                num11 += num16;
                num6   = Salsa20Engine.R(num6 ^ num11, 7);
                num2  += num7;
                num13  = Salsa20Engine.R(num13 ^ num2, 16);
                num12 += num13;
                num7   = Salsa20Engine.R(num7 ^ num12, 12);
                num2  += num7;
                num13  = Salsa20Engine.R(num13 ^ num2, 8);
                num12 += num13;
                num7   = Salsa20Engine.R(num7 ^ num12, 7);
                num3  += num8;
                num14  = Salsa20Engine.R(num14 ^ num3, 16);
                num9  += num14;
                num8   = Salsa20Engine.R(num8 ^ num9, 12);
                num3  += num8;
                num14  = Salsa20Engine.R(num14 ^ num3, 8);
                num9  += num14;
                num8   = Salsa20Engine.R(num8 ^ num9, 7);
                num4  += num5;
                num15  = Salsa20Engine.R(num15 ^ num4, 16);
                num10 += num15;
                num5   = Salsa20Engine.R(num5 ^ num10, 12);
                num4  += num5;
                num15  = Salsa20Engine.R(num15 ^ num4, 8);
                num10 += num15;
                num5   = Salsa20Engine.R(num5 ^ num10, 7);
            }
            x[0]  = num + input[0];
            x[1]  = num2 + input[1];
            x[2]  = num3 + input[2];
            x[3]  = num4 + input[3];
            x[4]  = num5 + input[4];
            x[5]  = num6 + input[5];
            x[6]  = num7 + input[6];
            x[7]  = num8 + input[7];
            x[8]  = num9 + input[8];
            x[9]  = num10 + input[9];
            x[10] = num11 + input[10];
            x[11] = num12 + input[11];
            x[12] = num13 + input[12];
            x[13] = num14 + input[13];
            x[14] = num15 + input[14];
            x[15] = num16 + input[15];
        }