Exemple #1
0
        /*
         * h = f * 121666
         * Can overlap h with f.
         *
         * Preconditions:
         |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
         *
         * Postconditions:
         |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
         */

        public static void fe_mul121666(out FieldElement h, ref FieldElement f)
        {
            int f0 = f.x0;
            int f1 = f.x1;
            int f2 = f.x2;
            int f3 = f.x3;
            int f4 = f.x4;
            int f5 = f.x5;
            int f6 = f.x6;
            int f7 = f.x7;
            int f8 = f.x8;
            int f9 = f.x9;

            var h0 = f0 * 121666L;
            var h1 = f1 * 121666L;
            var h2 = f2 * 121666L;
            var h3 = f3 * 121666L;
            var h4 = f4 * 121666L;
            var h5 = f5 * 121666L;
            var h6 = f6 * 121666L;
            var h7 = f7 * 121666L;
            var h8 = f8 * 121666L;
            var h9 = f9 * 121666L;

            var carry9 = (h9 + (1 << 24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25;
            var carry1 = (h1 + (1 << 24)) >> 25; h2 += carry1; h1 -= carry1 << 25;
            var carry3 = (h3 + (1 << 24)) >> 25; h4 += carry3; h3 -= carry3 << 25;
            var carry5 = (h5 + (1 << 24)) >> 25; h6 += carry5; h5 -= carry5 << 25;
            var carry7 = (h7 + (1 << 24)) >> 25; h8 += carry7; h7 -= carry7 << 25;

            var carry0 = (h0 + (1 << 25)) >> 26; h1 += carry0; h0 -= carry0 << 26;
            var carry2 = (h2 + (1 << 25)) >> 26; h3 += carry2; h2 -= carry2 << 26;
            var carry4 = (h4 + (1 << 25)) >> 26; h5 += carry4; h4 -= carry4 << 26;
            var carry6 = (h6 + (1 << 25)) >> 26; h7 += carry6; h6 -= carry6 << 26;
            var carry8 = (h8 + (1 << 25)) >> 26; h9 += carry8; h8 -= carry8 << 26;

            h.x0 = (int)h0;
            h.x1 = (int)h1;
            h.x2 = (int)h2;
            h.x3 = (int)h3;
            h.x4 = (int)h4;
            h.x5 = (int)h5;
            h.x6 = (int)h6;
            h.x7 = (int)h7;
            h.x8 = (int)h8;
            h.x9 = (int)h9;
        }
Exemple #2
0
        /*
         * h = f - g
         * Can overlap h with f or g.
         *
         * Preconditions:
         |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
         |g| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
         *
         * Postconditions:
         |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
         */

        internal static void fe_sub(out FieldElement h, ref FieldElement f, ref FieldElement g)
        {
            int f0 = f.x0;
            int f1 = f.x1;
            int f2 = f.x2;
            int f3 = f.x3;
            int f4 = f.x4;
            int f5 = f.x5;
            int f6 = f.x6;
            int f7 = f.x7;
            int f8 = f.x8;
            int f9 = f.x9;

            int g0 = g.x0;
            int g1 = g.x1;
            int g2 = g.x2;
            int g3 = g.x3;
            int g4 = g.x4;
            int g5 = g.x5;
            int g6 = g.x6;
            int g7 = g.x7;
            int g8 = g.x8;
            int g9 = g.x9;

            int h0 = f0 - g0;
            int h1 = f1 - g1;
            int h2 = f2 - g2;
            int h3 = f3 - g3;
            int h4 = f4 - g4;
            int h5 = f5 - g5;
            int h6 = f6 - g6;
            int h7 = f7 - g7;
            int h8 = f8 - g8;
            int h9 = f9 - g9;

            h.x0 = h0;
            h.x1 = h1;
            h.x2 = h2;
            h.x3 = h3;
            h.x4 = h4;
            h.x5 = h5;
            h.x6 = h6;
            h.x7 = h7;
            h.x8 = h8;
            h.x9 = h9;
        }
Exemple #3
0
        /*
         * h = f + g
         * Can overlap h with f or g.
         *
         * Preconditions:
         |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
         |g| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
         *
         * Postconditions:
         |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
         */
        //void fe_add(fe h,const fe f,const fe g)
        internal static void fe_add(out FieldElement h, ref FieldElement f, ref FieldElement g)
        {
            int f0 = f.x0;
            int f1 = f.x1;
            int f2 = f.x2;
            int f3 = f.x3;
            int f4 = f.x4;
            int f5 = f.x5;
            int f6 = f.x6;
            int f7 = f.x7;
            int f8 = f.x8;
            int f9 = f.x9;
            int g0 = g.x0;
            int g1 = g.x1;
            int g2 = g.x2;
            int g3 = g.x3;
            int g4 = g.x4;
            int g5 = g.x5;
            int g6 = g.x6;
            int g7 = g.x7;
            int g8 = g.x8;
            int g9 = g.x9;
            int h0 = f0 + g0;
            int h1 = f1 + g1;
            int h2 = f2 + g2;
            int h3 = f3 + g3;
            int h4 = f4 + g4;
            int h5 = f5 + g5;
            int h6 = f6 + g6;
            int h7 = f7 + g7;
            int h8 = f8 + g8;
            int h9 = f9 + g9;

            h.x0 = h0;
            h.x1 = h1;
            h.x2 = h2;
            h.x3 = h3;
            h.x4 = h4;
            h.x5 = h5;
            h.x6 = h6;
            h.x7 = h7;
            h.x8 = h8;
            h.x9 = h9;
        }
Exemple #4
0
        /*
         * return 1 if f == 0
         * return 0 if f != 0
         *
         * Preconditions:
         |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
         */
        // Todo: Discuss this with upstream
        // Above comment is from the original code. But I believe the original code returned
        //   0 if f == 0
        //  -1 if f != 0
        // This code actually returns 0 if f==0 and 1 if f != 0
        internal static int fe_isnonzero(ref FieldElement f)
        {
            FieldElement fr;

            fe_reduce(out fr, ref f);
            int differentBits = 0;

            differentBits |= fr.x0;
            differentBits |= fr.x1;
            differentBits |= fr.x2;
            differentBits |= fr.x3;
            differentBits |= fr.x4;
            differentBits |= fr.x5;
            differentBits |= fr.x6;
            differentBits |= fr.x7;
            differentBits |= fr.x8;
            differentBits |= fr.x9;
            return((int)((unchecked ((uint)differentBits - 1) >> 31) ^ 1));
        }
Exemple #5
0
        // does NOT ignore top bit
        internal static void fe_frombytes2(out FieldElement h, byte[] data, int offset)
        {
            var h0 = load_4(data, offset);
            var h1 = load_3(data, offset + 4) << 6;
            var h2 = load_3(data, offset + 7) << 5;
            var h3 = load_3(data, offset + 10) << 3;
            var h4 = load_3(data, offset + 13) << 2;
            var h5 = load_4(data, offset + 16);
            var h6 = load_3(data, offset + 20) << 7;
            var h7 = load_3(data, offset + 23) << 5;
            var h8 = load_3(data, offset + 26) << 4;
            var h9 = load_3(data, offset + 29) << 2;

            var carry9 = (h9 + (1 << 24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25;
            var carry1 = (h1 + (1 << 24)) >> 25; h2 += carry1; h1 -= carry1 << 25;
            var carry3 = (h3 + (1 << 24)) >> 25; h4 += carry3; h3 -= carry3 << 25;
            var carry5 = (h5 + (1 << 24)) >> 25; h6 += carry5; h5 -= carry5 << 25;
            var carry7 = (h7 + (1 << 24)) >> 25; h8 += carry7; h7 -= carry7 << 25;

            var carry0 = (h0 + (1 << 25)) >> 26; h1 += carry0; h0 -= carry0 << 26;
            var carry2 = (h2 + (1 << 25)) >> 26; h3 += carry2; h2 -= carry2 << 26;
            var carry4 = (h4 + (1 << 25)) >> 26; h5 += carry4; h4 -= carry4 << 26;
            var carry6 = (h6 + (1 << 25)) >> 26; h7 += carry6; h6 -= carry6 << 26;
            var carry8 = (h8 + (1 << 25)) >> 26; h9 += carry8; h8 -= carry8 << 26;

            h.x0 = (int)h0;
            h.x1 = (int)h1;
            h.x2 = (int)h2;
            h.x3 = (int)h3;
            h.x4 = (int)h4;
            h.x5 = (int)h5;
            h.x6 = (int)h6;
            h.x7 = (int)h7;
            h.x8 = (int)h8;
            h.x9 = (int)h9;
        }
Exemple #6
0
        internal static void fe_invert(out FieldElement result, ref FieldElement z)
        {
            FieldElement t0, t1, t2, t3;
            int          i;

            /* qhasm: z2 = z1^2^1 */
            /* asm 1: fe_sq(>z2=fe#1,<z1=fe#11); for (i = 1;i < 1;++i) fe_sq(>z2=fe#1,>z2=fe#1); */
            /* asm 2: fe_sq(>z2=t0,<z1=z); for (i = 1;i < 1;++i) fe_sq(>z2=t0,>z2=t0); */
            fe_sq(out t0, ref z);             //for (i = 1; i < 1; ++i) fe_sq(out t0, ref t0);

            /* qhasm: z8 = z2^2^2 */
            /* asm 1: fe_sq(>z8=fe#2,<z2=fe#1); for (i = 1;i < 2;++i) fe_sq(>z8=fe#2,>z8=fe#2); */
            /* asm 2: fe_sq(>z8=t1,<z2=t0); for (i = 1;i < 2;++i) fe_sq(>z8=t1,>z8=t1); */
            fe_sq(out t1, ref t0); for (i = 1; i < 2; ++i)
            {
                fe_sq(out t1, ref t1);
            }

            /* qhasm: z9 = z1*z8 */
            /* asm 1: fe_mul(>z9=fe#2,<z1=fe#11,<z8=fe#2); */
            /* asm 2: fe_mul(>z9=t1,<z1=z,<z8=t1); */
            fe_mul(out t1, ref z, ref t1);

            /* qhasm: z11 = z2*z9 */
            /* asm 1: fe_mul(>z11=fe#1,<z2=fe#1,<z9=fe#2); */
            /* asm 2: fe_mul(>z11=t0,<z2=t0,<z9=t1); */
            fe_mul(out t0, ref t0, ref t1);

            /* qhasm: z22 = z11^2^1 */
            /* asm 1: fe_sq(>z22=fe#3,<z11=fe#1); for (i = 1;i < 1;++i) fe_sq(>z22=fe#3,>z22=fe#3); */
            /* asm 2: fe_sq(>z22=t2,<z11=t0); for (i = 1;i < 1;++i) fe_sq(>z22=t2,>z22=t2); */
            fe_sq(out t2, ref t0);             //for (i = 1; i < 1; ++i) fe_sq(out t2, ref t2);

            /* qhasm: z_5_0 = z9*z22 */
            /* asm 1: fe_mul(>z_5_0=fe#2,<z9=fe#2,<z22=fe#3); */
            /* asm 2: fe_mul(>z_5_0=t1,<z9=t1,<z22=t2); */
            fe_mul(out t1, ref t1, ref t2);

            /* qhasm: z_10_5 = z_5_0^2^5 */
            /* asm 1: fe_sq(>z_10_5=fe#3,<z_5_0=fe#2); for (i = 1;i < 5;++i) fe_sq(>z_10_5=fe#3,>z_10_5=fe#3); */
            /* asm 2: fe_sq(>z_10_5=t2,<z_5_0=t1); for (i = 1;i < 5;++i) fe_sq(>z_10_5=t2,>z_10_5=t2); */
            fe_sq(out t2, ref t1); for (i = 1; i < 5; ++i)
            {
                fe_sq(out t2, ref t2);
            }

            /* qhasm: z_10_0 = z_10_5*z_5_0 */
            /* asm 1: fe_mul(>z_10_0=fe#2,<z_10_5=fe#3,<z_5_0=fe#2); */
            /* asm 2: fe_mul(>z_10_0=t1,<z_10_5=t2,<z_5_0=t1); */
            fe_mul(out t1, ref t2, ref t1);

            /* qhasm: z_20_10 = z_10_0^2^10 */
            /* asm 1: fe_sq(>z_20_10=fe#3,<z_10_0=fe#2); for (i = 1;i < 10;++i) fe_sq(>z_20_10=fe#3,>z_20_10=fe#3); */
            /* asm 2: fe_sq(>z_20_10=t2,<z_10_0=t1); for (i = 1;i < 10;++i) fe_sq(>z_20_10=t2,>z_20_10=t2); */
            fe_sq(out t2, ref t1); for (i = 1; i < 10; ++i)
            {
                fe_sq(out t2, ref t2);
            }

            /* qhasm: z_20_0 = z_20_10*z_10_0 */
            /* asm 1: fe_mul(>z_20_0=fe#3,<z_20_10=fe#3,<z_10_0=fe#2); */
            /* asm 2: fe_mul(>z_20_0=t2,<z_20_10=t2,<z_10_0=t1); */
            fe_mul(out t2, ref t2, ref t1);

            /* qhasm: z_40_20 = z_20_0^2^20 */
            /* asm 1: fe_sq(>z_40_20=fe#4,<z_20_0=fe#3); for (i = 1;i < 20;++i) fe_sq(>z_40_20=fe#4,>z_40_20=fe#4); */
            /* asm 2: fe_sq(>z_40_20=t3,<z_20_0=t2); for (i = 1;i < 20;++i) fe_sq(>z_40_20=t3,>z_40_20=t3); */
            fe_sq(out t3, ref t2); for (i = 1; i < 20; ++i)
            {
                fe_sq(out t3, ref t3);
            }

            /* qhasm: z_40_0 = z_40_20*z_20_0 */
            /* asm 1: fe_mul(>z_40_0=fe#3,<z_40_20=fe#4,<z_20_0=fe#3); */
            /* asm 2: fe_mul(>z_40_0=t2,<z_40_20=t3,<z_20_0=t2); */
            fe_mul(out t2, ref t3, ref t2);

            /* qhasm: z_50_10 = z_40_0^2^10 */
            /* asm 1: fe_sq(>z_50_10=fe#3,<z_40_0=fe#3); for (i = 1;i < 10;++i) fe_sq(>z_50_10=fe#3,>z_50_10=fe#3); */
            /* asm 2: fe_sq(>z_50_10=t2,<z_40_0=t2); for (i = 1;i < 10;++i) fe_sq(>z_50_10=t2,>z_50_10=t2); */
            fe_sq(out t2, ref t2); for (i = 1; i < 10; ++i)
            {
                fe_sq(out t2, ref t2);
            }

            /* qhasm: z_50_0 = z_50_10*z_10_0 */
            /* asm 1: fe_mul(>z_50_0=fe#2,<z_50_10=fe#3,<z_10_0=fe#2); */
            /* asm 2: fe_mul(>z_50_0=t1,<z_50_10=t2,<z_10_0=t1); */
            fe_mul(out t1, ref t2, ref t1);

            /* qhasm: z_100_50 = z_50_0^2^50 */
            /* asm 1: fe_sq(>z_100_50=fe#3,<z_50_0=fe#2); for (i = 1;i < 50;++i) fe_sq(>z_100_50=fe#3,>z_100_50=fe#3); */
            /* asm 2: fe_sq(>z_100_50=t2,<z_50_0=t1); for (i = 1;i < 50;++i) fe_sq(>z_100_50=t2,>z_100_50=t2); */
            fe_sq(out t2, ref t1); for (i = 1; i < 50; ++i)
            {
                fe_sq(out t2, ref t2);
            }

            /* qhasm: z_100_0 = z_100_50*z_50_0 */
            /* asm 1: fe_mul(>z_100_0=fe#3,<z_100_50=fe#3,<z_50_0=fe#2); */
            /* asm 2: fe_mul(>z_100_0=t2,<z_100_50=t2,<z_50_0=t1); */
            fe_mul(out t2, ref t2, ref t1);

            /* qhasm: z_200_100 = z_100_0^2^100 */
            /* asm 1: fe_sq(>z_200_100=fe#4,<z_100_0=fe#3); for (i = 1;i < 100;++i) fe_sq(>z_200_100=fe#4,>z_200_100=fe#4); */
            /* asm 2: fe_sq(>z_200_100=t3,<z_100_0=t2); for (i = 1;i < 100;++i) fe_sq(>z_200_100=t3,>z_200_100=t3); */
            fe_sq(out t3, ref t2); for (i = 1; i < 100; ++i)
            {
                fe_sq(out t3, ref t3);
            }

            /* qhasm: z_200_0 = z_200_100*z_100_0 */
            /* asm 1: fe_mul(>z_200_0=fe#3,<z_200_100=fe#4,<z_100_0=fe#3); */
            /* asm 2: fe_mul(>z_200_0=t2,<z_200_100=t3,<z_100_0=t2); */
            fe_mul(out t2, ref t3, ref t2);

            /* qhasm: z_250_50 = z_200_0^2^50 */
            /* asm 1: fe_sq(>z_250_50=fe#3,<z_200_0=fe#3); for (i = 1;i < 50;++i) fe_sq(>z_250_50=fe#3,>z_250_50=fe#3); */
            /* asm 2: fe_sq(>z_250_50=t2,<z_200_0=t2); for (i = 1;i < 50;++i) fe_sq(>z_250_50=t2,>z_250_50=t2); */
            fe_sq(out t2, ref t2); for (i = 1; i < 50; ++i)
            {
                fe_sq(out t2, ref t2);
            }

            /* qhasm: z_250_0 = z_250_50*z_50_0 */
            /* asm 1: fe_mul(>z_250_0=fe#2,<z_250_50=fe#3,<z_50_0=fe#2); */
            /* asm 2: fe_mul(>z_250_0=t1,<z_250_50=t2,<z_50_0=t1); */
            fe_mul(out t1, ref t2, ref t1);

            /* qhasm: z_255_5 = z_250_0^2^5 */
            /* asm 1: fe_sq(>z_255_5=fe#2,<z_250_0=fe#2); for (i = 1;i < 5;++i) fe_sq(>z_255_5=fe#2,>z_255_5=fe#2); */
            /* asm 2: fe_sq(>z_255_5=t1,<z_250_0=t1); for (i = 1;i < 5;++i) fe_sq(>z_255_5=t1,>z_255_5=t1); */
            fe_sq(out t1, ref t1); for (i = 1; i < 5; ++i)
            {
                fe_sq(out t1, ref t1);
            }

            /* qhasm: z_255_21 = z_255_5*z11 */
            /* asm 1: fe_mul(>z_255_21=fe#12,<z_255_5=fe#2,<z11=fe#1); */
            /* asm 2: fe_mul(>z_255_21=out,<z_255_5=t1,<z11=t0); */
            fe_mul(out result, ref t1, ref t0);

            /* qhasm: return */


            return;
        }
Exemple #7
0
        /*
         * h = f * f
         * Can overlap h with f.
         *
         * Preconditions:
         |f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.
         *
         * Postconditions:
         |h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc.
         */

        /*
         * See fe_mul.c for discussion of implementation strategy.
         */
        internal static void fe_sq(out FieldElement h, ref FieldElement f)
        {
            int f0 = f.x0;
            int f1 = f.x1;
            int f2 = f.x2;
            int f3 = f.x3;
            int f4 = f.x4;
            int f5 = f.x5;
            int f6 = f.x6;
            int f7 = f.x7;
            int f8 = f.x8;
            int f9 = f.x9;

            int f0_2  = 2 * f0;
            int f1_2  = 2 * f1;
            int f2_2  = 2 * f2;
            int f3_2  = 2 * f3;
            int f4_2  = 2 * f4;
            int f5_2  = 2 * f5;
            int f6_2  = 2 * f6;
            int f7_2  = 2 * f7;
            int f5_38 = 38 * f5; /* 1.959375*2^30 */
            int f6_19 = 19 * f6; /* 1.959375*2^30 */
            int f7_38 = 38 * f7; /* 1.959375*2^30 */
            int f8_19 = 19 * f8; /* 1.959375*2^30 */
            int f9_38 = 38 * f9; /* 1.959375*2^30 */

            var f0f0    = f0 * (long)f0;
            var f0f1_2  = f0_2 * (long)f1;
            var f0f2_2  = f0_2 * (long)f2;
            var f0f3_2  = f0_2 * (long)f3;
            var f0f4_2  = f0_2 * (long)f4;
            var f0f5_2  = f0_2 * (long)f5;
            var f0f6_2  = f0_2 * (long)f6;
            var f0f7_2  = f0_2 * (long)f7;
            var f0f8_2  = f0_2 * (long)f8;
            var f0f9_2  = f0_2 * (long)f9;
            var f1f1_2  = f1_2 * (long)f1;
            var f1f2_2  = f1_2 * (long)f2;
            var f1f3_4  = f1_2 * (long)f3_2;
            var f1f4_2  = f1_2 * (long)f4;
            var f1f5_4  = f1_2 * (long)f5_2;
            var f1f6_2  = f1_2 * (long)f6;
            var f1f7_4  = f1_2 * (long)f7_2;
            var f1f8_2  = f1_2 * (long)f8;
            var f1f9_76 = f1_2 * (long)f9_38;
            var f2f2    = f2 * (long)f2;
            var f2f3_2  = f2_2 * (long)f3;
            var f2f4_2  = f2_2 * (long)f4;
            var f2f5_2  = f2_2 * (long)f5;
            var f2f6_2  = f2_2 * (long)f6;
            var f2f7_2  = f2_2 * (long)f7;
            var f2f8_38 = f2_2 * (long)f8_19;
            var f2f9_38 = f2 * (long)f9_38;
            var f3f3_2  = f3_2 * (long)f3;
            var f3f4_2  = f3_2 * (long)f4;
            var f3f5_4  = f3_2 * (long)f5_2;
            var f3f6_2  = f3_2 * (long)f6;
            var f3f7_76 = f3_2 * (long)f7_38;
            var f3f8_38 = f3_2 * (long)f8_19;
            var f3f9_76 = f3_2 * (long)f9_38;
            var f4f4    = f4 * (long)f4;
            var f4f5_2  = f4_2 * (long)f5;
            var f4f6_38 = f4_2 * (long)f6_19;
            var f4f7_38 = f4 * (long)f7_38;
            var f4f8_38 = f4_2 * (long)f8_19;
            var f4f9_38 = f4 * (long)f9_38;
            var f5f5_38 = f5 * (long)f5_38;
            var f5f6_38 = f5_2 * (long)f6_19;
            var f5f7_76 = f5_2 * (long)f7_38;
            var f5f8_38 = f5_2 * (long)f8_19;
            var f5f9_76 = f5_2 * (long)f9_38;
            var f6f6_19 = f6 * (long)f6_19;
            var f6f7_38 = f6 * (long)f7_38;
            var f6f8_38 = f6_2 * (long)f8_19;
            var f6f9_38 = f6 * (long)f9_38;
            var f7f7_38 = f7 * (long)f7_38;
            var f7f8_38 = f7_2 * (long)f8_19;
            var f7f9_76 = f7_2 * (long)f9_38;
            var f8f8_19 = f8 * (long)f8_19;
            var f8f9_38 = f8 * (long)f9_38;
            var f9f9_38 = f9 * (long)f9_38;

            var h0 = f0f0 + f1f9_76 + f2f8_38 + f3f7_76 + f4f6_38 + f5f5_38;
            var h1 = f0f1_2 + f2f9_38 + f3f8_38 + f4f7_38 + f5f6_38;
            var h2 = f0f2_2 + f1f1_2 + f3f9_76 + f4f8_38 + f5f7_76 + f6f6_19;
            var h3 = f0f3_2 + f1f2_2 + f4f9_38 + f5f8_38 + f6f7_38;
            var h4 = f0f4_2 + f1f3_4 + f2f2 + f5f9_76 + f6f8_38 + f7f7_38;
            var h5 = f0f5_2 + f1f4_2 + f2f3_2 + f6f9_38 + f7f8_38;
            var h6 = f0f6_2 + f1f5_4 + f2f4_2 + f3f3_2 + f7f9_76 + f8f8_19;
            var h7 = f0f7_2 + f1f6_2 + f2f5_2 + f3f4_2 + f8f9_38;
            var h8 = f0f8_2 + f1f7_4 + f2f6_2 + f3f5_4 + f4f4 + f9f9_38;
            var h9 = f0f9_2 + f1f8_2 + f2f7_2 + f3f6_2 + f4f5_2;

            var carry0 = (h0 + (1 << 25)) >> 26; h1 += carry0; h0 -= carry0 << 26;
            var carry4 = (h4 + (1 << 25)) >> 26; h5 += carry4; h4 -= carry4 << 26;
            var carry1 = (h1 + (1 << 24)) >> 25; h2 += carry1; h1 -= carry1 << 25;
            var carry5 = (h5 + (1 << 24)) >> 25; h6 += carry5; h5 -= carry5 << 25;
            var carry2 = (h2 + (1 << 25)) >> 26; h3 += carry2; h2 -= carry2 << 26;
            var carry6 = (h6 + (1 << 25)) >> 26; h7 += carry6; h6 -= carry6 << 26;
            var carry3 = (h3 + (1 << 24)) >> 25; h4 += carry3; h3 -= carry3 << 25;
            var carry7 = (h7 + (1 << 24)) >> 25; h8 += carry7; h7 -= carry7 << 25;

            carry4 = (h4 + (1 << 25)) >> 26; h5 += carry4; h4 -= carry4 << 26;

            var carry8 = (h8 + (1 << 25)) >> 26; h9 += carry8; h8 -= carry8 << 26;
            var carry9 = (h9 + (1 << 24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25;

            carry0 = (h0 + (1 << 25)) >> 26; h1 += carry0; h0 -= carry0 << 26;

            h.x0 = (int)h0;
            h.x1 = (int)h1;
            h.x2 = (int)h2;
            h.x3 = (int)h3;
            h.x4 = (int)h4;
            h.x5 = (int)h5;
            h.x6 = (int)h6;
            h.x7 = (int)h7;
            h.x8 = (int)h8;
            h.x9 = (int)h9;
        }
Exemple #8
0
 public static void fe_0(out FieldElement h)
 {
     h = default(FieldElement);
 }
Exemple #9
0
 public static void fe_1(out FieldElement h)
 {
     h    = default(FieldElement);
     h.x0 = 1;
 }
Exemple #10
0
 public GroupElementPreComp(FieldElement yplusx, FieldElement yminusx, FieldElement xy2d)
 {
     this.yplusx  = yplusx;
     this.yminusx = yminusx;
     this.xy2d    = xy2d;
 }
Exemple #11
0
        /*
         * h = f * g
         * Can overlap h with f or g.
         *
         * Preconditions:
         |f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.
         |g| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.
         *
         * Postconditions:
         |h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc.
         */

        /*
         * Notes on implementation strategy:
         *
         * Using schoolbook multiplication.
         * Karatsuba would save a little in some cost models.
         *
         * Most multiplications by 2 and 19 are 32-bit precomputations;
         * cheaper than 64-bit postcomputations.
         *
         * There is one remaining multiplication by 19 in the carry chain;
         * one *19 precomputation can be merged into this,
         * but the resulting data flow is considerably less clean.
         *
         * There are 12 carries below.
         * 10 of them are 2-way parallelizable and vectorizable.
         * Can get away with 11 carries, but then data flow is much deeper.
         *
         * With tighter constraints on inputs can squeeze carries into int32.
         */

        internal static void fe_mul(out FieldElement h, ref FieldElement f, ref FieldElement g)
        {
            int f0 = f.x0;
            int f1 = f.x1;
            int f2 = f.x2;
            int f3 = f.x3;
            int f4 = f.x4;
            int f5 = f.x5;
            int f6 = f.x6;
            int f7 = f.x7;
            int f8 = f.x8;
            int f9 = f.x9;
            int g0 = g.x0;
            int g1 = g.x1;
            int g2 = g.x2;
            int g3 = g.x3;
            int g4 = g.x4;
            int g5 = g.x5;
            int g6 = g.x6;
            int g7 = g.x7;
            int g8 = g.x8;
            int g9 = g.x9;

            int g1_19 = 19 * g1; /* 1.959375*2^29 */
            int g2_19 = 19 * g2; /* 1.959375*2^30; still ok */
            int g3_19 = 19 * g3;
            int g4_19 = 19 * g4;
            int g5_19 = 19 * g5;
            int g6_19 = 19 * g6;
            int g7_19 = 19 * g7;
            int g8_19 = 19 * g8;
            int g9_19 = 19 * g9;

            int f1_2 = 2 * f1;
            int f3_2 = 2 * f3;
            int f5_2 = 2 * f5;
            int f7_2 = 2 * f7;
            int f9_2 = 2 * f9;

            long f0g0    = f0 * (long)g0;
            long f0g1    = f0 * (long)g1;
            long f0g2    = f0 * (long)g2;
            long f0g3    = f0 * (long)g3;
            long f0g4    = f0 * (long)g4;
            long f0g5    = f0 * (long)g5;
            long f0g6    = f0 * (long)g6;
            long f0g7    = f0 * (long)g7;
            long f0g8    = f0 * (long)g8;
            long f0g9    = f0 * (long)g9;
            long f1g0    = f1 * (long)g0;
            long f1g1_2  = f1_2 * (long)g1;
            long f1g2    = f1 * (long)g2;
            long f1g3_2  = f1_2 * (long)g3;
            long f1g4    = f1 * (long)g4;
            long f1g5_2  = f1_2 * (long)g5;
            long f1g6    = f1 * (long)g6;
            long f1g7_2  = f1_2 * (long)g7;
            long f1g8    = f1 * (long)g8;
            long f1g9_38 = f1_2 * (long)g9_19;
            long f2g0    = f2 * (long)g0;
            long f2g1    = f2 * (long)g1;
            long f2g2    = f2 * (long)g2;
            long f2g3    = f2 * (long)g3;
            long f2g4    = f2 * (long)g4;
            long f2g5    = f2 * (long)g5;
            long f2g6    = f2 * (long)g6;
            long f2g7    = f2 * (long)g7;
            long f2g8_19 = f2 * (long)g8_19;
            long f2g9_19 = f2 * (long)g9_19;
            long f3g0    = f3 * (long)g0;
            long f3g1_2  = f3_2 * (long)g1;
            long f3g2    = f3 * (long)g2;
            long f3g3_2  = f3_2 * (long)g3;
            long f3g4    = f3 * (long)g4;
            long f3g5_2  = f3_2 * (long)g5;
            long f3g6    = f3 * (long)g6;
            long f3g7_38 = f3_2 * (long)g7_19;
            long f3g8_19 = f3 * (long)g8_19;
            long f3g9_38 = f3_2 * (long)g9_19;
            long f4g0    = f4 * (long)g0;
            long f4g1    = f4 * (long)g1;
            long f4g2    = f4 * (long)g2;
            long f4g3    = f4 * (long)g3;
            long f4g4    = f4 * (long)g4;
            long f4g5    = f4 * (long)g5;
            long f4g6_19 = f4 * (long)g6_19;
            long f4g7_19 = f4 * (long)g7_19;
            long f4g8_19 = f4 * (long)g8_19;
            long f4g9_19 = f4 * (long)g9_19;
            long f5g0    = f5 * (long)g0;
            long f5g1_2  = f5_2 * (long)g1;
            long f5g2    = f5 * (long)g2;
            long f5g3_2  = f5_2 * (long)g3;
            long f5g4    = f5 * (long)g4;
            long f5g5_38 = f5_2 * (long)g5_19;
            long f5g6_19 = f5 * (long)g6_19;
            long f5g7_38 = f5_2 * (long)g7_19;
            long f5g8_19 = f5 * (long)g8_19;
            long f5g9_38 = f5_2 * (long)g9_19;
            long f6g0    = f6 * (long)g0;
            long f6g1    = f6 * (long)g1;
            long f6g2    = f6 * (long)g2;
            long f6g3    = f6 * (long)g3;
            long f6g4_19 = f6 * (long)g4_19;
            long f6g5_19 = f6 * (long)g5_19;
            long f6g6_19 = f6 * (long)g6_19;
            long f6g7_19 = f6 * (long)g7_19;
            long f6g8_19 = f6 * (long)g8_19;
            long f6g9_19 = f6 * (long)g9_19;
            long f7g0    = f7 * (long)g0;
            long f7g1_2  = f7_2 * (long)g1;
            long f7g2    = f7 * (long)g2;
            long f7g3_38 = f7_2 * (long)g3_19;
            long f7g4_19 = f7 * (long)g4_19;
            long f7g5_38 = f7_2 * (long)g5_19;
            long f7g6_19 = f7 * (long)g6_19;
            long f7g7_38 = f7_2 * (long)g7_19;
            long f7g8_19 = f7 * (long)g8_19;
            long f7g9_38 = f7_2 * (long)g9_19;
            long f8g0    = f8 * (long)g0;
            long f8g1    = f8 * (long)g1;
            long f8g2_19 = f8 * (long)g2_19;
            long f8g3_19 = f8 * (long)g3_19;
            long f8g4_19 = f8 * (long)g4_19;
            long f8g5_19 = f8 * (long)g5_19;
            long f8g6_19 = f8 * (long)g6_19;
            long f8g7_19 = f8 * (long)g7_19;
            long f8g8_19 = f8 * (long)g8_19;
            long f8g9_19 = f8 * (long)g9_19;
            long f9g0    = f9 * (long)g0;
            long f9g1_38 = f9_2 * (long)g1_19;
            long f9g2_19 = f9 * (long)g2_19;
            long f9g3_38 = f9_2 * (long)g3_19;
            long f9g4_19 = f9 * (long)g4_19;
            long f9g5_38 = f9_2 * (long)g5_19;
            long f9g6_19 = f9 * (long)g6_19;
            long f9g7_38 = f9_2 * (long)g7_19;
            long f9g8_19 = f9 * (long)g8_19;
            long f9g9_38 = f9_2 * (long)g9_19;

            long h0 = f0g0 + f1g9_38 + f2g8_19 + f3g7_38 + f4g6_19 + f5g5_38 + f6g4_19 + f7g3_38 + f8g2_19 + f9g1_38;
            long h1 = f0g1 + f1g0 + f2g9_19 + f3g8_19 + f4g7_19 + f5g6_19 + f6g5_19 + f7g4_19 + f8g3_19 + f9g2_19;
            long h2 = f0g2 + f1g1_2 + f2g0 + f3g9_38 + f4g8_19 + f5g7_38 + f6g6_19 + f7g5_38 + f8g4_19 + f9g3_38;
            long h3 = f0g3 + f1g2 + f2g1 + f3g0 + f4g9_19 + f5g8_19 + f6g7_19 + f7g6_19 + f8g5_19 + f9g4_19;
            long h4 = f0g4 + f1g3_2 + f2g2 + f3g1_2 + f4g0 + f5g9_38 + f6g8_19 + f7g7_38 + f8g6_19 + f9g5_38;
            long h5 = f0g5 + f1g4 + f2g3 + f3g2 + f4g1 + f5g0 + f6g9_19 + f7g8_19 + f8g7_19 + f9g6_19;
            long h6 = f0g6 + f1g5_2 + f2g4 + f3g3_2 + f4g2 + f5g1_2 + f6g0 + f7g9_38 + f8g8_19 + f9g7_38;
            long h7 = f0g7 + f1g6 + f2g5 + f3g4 + f4g3 + f5g2 + f6g1 + f7g0 + f8g9_19 + f9g8_19;
            long h8 = f0g8 + f1g7_2 + f2g6 + f3g5_2 + f4g4 + f5g3_2 + f6g2 + f7g1_2 + f8g0 + f9g9_38;
            long h9 = f0g9 + f1g8 + f2g7 + f3g6 + f4g5 + f5g4 + f6g3 + f7g2 + f8g1 + f9g0;

            long carry0;
            long carry1;
            long carry2;
            long carry3;
            long carry4;
            long carry5;
            long carry6;
            long carry7;
            long carry8;
            long carry9;

            /*
             |h0| <= (1.65*1.65*2^52*(1+19+19+19+19)+1.65*1.65*2^50*(38+38+38+38+38))
             * i.e. |h0| <= 1.4*2^60; narrower ranges for h2, h4, h6, h8
             |h1| <= (1.65*1.65*2^51*(1+1+19+19+19+19+19+19+19+19))
             * i.e. |h1| <= 1.7*2^59; narrower ranges for h3, h5, h7, h9
             */

            carry0 = (h0 + (long)(1 << 25)) >> 26; h1 += carry0; h0 -= carry0 << 26;
            carry4 = (h4 + (long)(1 << 25)) >> 26; h5 += carry4; h4 -= carry4 << 26;
            /* |h0| <= 2^25 */
            /* |h4| <= 2^25 */
            /* |h1| <= 1.71*2^59 */
            /* |h5| <= 1.71*2^59 */

            carry1 = (h1 + (long)(1 << 24)) >> 25; h2 += carry1; h1 -= carry1 << 25;
            carry5 = (h5 + (long)(1 << 24)) >> 25; h6 += carry5; h5 -= carry5 << 25;
            /* |h1| <= 2^24; from now on fits into int32 */
            /* |h5| <= 2^24; from now on fits into int32 */
            /* |h2| <= 1.41*2^60 */
            /* |h6| <= 1.41*2^60 */

            carry2 = (h2 + (long)(1 << 25)) >> 26; h3 += carry2; h2 -= carry2 << 26;
            carry6 = (h6 + (long)(1 << 25)) >> 26; h7 += carry6; h6 -= carry6 << 26;
            /* |h2| <= 2^25; from now on fits into int32 unchanged */
            /* |h6| <= 2^25; from now on fits into int32 unchanged */
            /* |h3| <= 1.71*2^59 */
            /* |h7| <= 1.71*2^59 */

            carry3 = (h3 + (long)(1 << 24)) >> 25; h4 += carry3; h3 -= carry3 << 25;
            carry7 = (h7 + (long)(1 << 24)) >> 25; h8 += carry7; h7 -= carry7 << 25;
            /* |h3| <= 2^24; from now on fits into int32 unchanged */
            /* |h7| <= 2^24; from now on fits into int32 unchanged */
            /* |h4| <= 1.72*2^34 */
            /* |h8| <= 1.41*2^60 */

            carry4 = (h4 + (long)(1 << 25)) >> 26; h5 += carry4; h4 -= carry4 << 26;
            carry8 = (h8 + (long)(1 << 25)) >> 26; h9 += carry8; h8 -= carry8 << 26;
            /* |h4| <= 2^25; from now on fits into int32 unchanged */
            /* |h8| <= 2^25; from now on fits into int32 unchanged */
            /* |h5| <= 1.01*2^24 */
            /* |h9| <= 1.71*2^59 */

            carry9 = (h9 + (long)(1 << 24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25;
            /* |h9| <= 2^24; from now on fits into int32 unchanged */
            /* |h0| <= 1.1*2^39 */

            carry0 = (h0 + (long)(1 << 25)) >> 26; h1 += carry0; h0 -= carry0 << 26;
            /* |h0| <= 2^25; from now on fits into int32 unchanged */
            /* |h1| <= 1.01*2^24 */

            h.x0 = (int)h0;
            h.x1 = (int)h1;
            h.x2 = (int)h2;
            h.x3 = (int)h3;
            h.x4 = (int)h4;
            h.x5 = (int)h5;
            h.x6 = (int)h6;
            h.x7 = (int)h7;
            h.x8 = (int)h8;
            h.x9 = (int)h9;
        }
Exemple #12
0
        internal static void scalarmult(
            out FieldElement q,
            byte[] n, int noffset,
            ref FieldElement p)
        {
            byte[]       e = new byte[32];      //ToDo: remove allocation
            FieldElement x1, x2, x3;
            FieldElement z2, z3;
            FieldElement tmp0, tmp1;

            for (int i = 0; i < 32; ++i)
            {
                e[i] = n[noffset + i];
            }
            ScalarOperations.sc_clamp(e, 0);
            x1 = p;
            FieldOperations.fe_1(out x2);
            FieldOperations.fe_0(out z2);
            x3 = x1;
            FieldOperations.fe_1(out z3);

            uint swap = 0;

            for (int pos = 254; pos >= 0; --pos)
            {
                uint b = (uint)(e[pos / 8] >> (pos & 7));
                b    &= 1;
                swap ^= b;
                FieldOperations.fe_cswap(ref x2, ref x3, swap);
                FieldOperations.fe_cswap(ref z2, ref z3, swap);
                swap = b;

                /* qhasm: enter ladder */

                /* qhasm: D = X3-Z3 */
                /* asm 1: fe_sub(>D=fe#5,<X3=fe#3,<Z3=fe#4); */
                /* asm 2: fe_sub(>D=tmp0,<X3=x3,<Z3=z3); */
                FieldOperations.fe_sub(out tmp0, ref x3, ref z3);

                /* qhasm: B = X2-Z2 */
                /* asm 1: fe_sub(>B=fe#6,<X2=fe#1,<Z2=fe#2); */
                /* asm 2: fe_sub(>B=tmp1,<X2=x2,<Z2=z2); */
                FieldOperations.fe_sub(out tmp1, ref x2, ref z2);

                /* qhasm: A = X2+Z2 */
                /* asm 1: fe_add(>A=fe#1,<X2=fe#1,<Z2=fe#2); */
                /* asm 2: fe_add(>A=x2,<X2=x2,<Z2=z2); */
                FieldOperations.fe_add(out x2, ref x2, ref z2);

                /* qhasm: C = X3+Z3 */
                /* asm 1: fe_add(>C=fe#2,<X3=fe#3,<Z3=fe#4); */
                /* asm 2: fe_add(>C=z2,<X3=x3,<Z3=z3); */
                FieldOperations.fe_add(out z2, ref x3, ref z3);

                /* qhasm: DA = D*A */
                /* asm 1: fe_mul(>DA=fe#4,<D=fe#5,<A=fe#1); */
                /* asm 2: fe_mul(>DA=z3,<D=tmp0,<A=x2); */
                FieldOperations.fe_mul(out z3, ref tmp0, ref x2);

                /* qhasm: CB = C*B */
                /* asm 1: fe_mul(>CB=fe#2,<C=fe#2,<B=fe#6); */
                /* asm 2: fe_mul(>CB=z2,<C=z2,<B=tmp1); */
                FieldOperations.fe_mul(out z2, ref z2, ref tmp1);

                /* qhasm: BB = B^2 */
                /* asm 1: fe_sq(>BB=fe#5,<B=fe#6); */
                /* asm 2: fe_sq(>BB=tmp0,<B=tmp1); */
                FieldOperations.fe_sq(out tmp0, ref tmp1);

                /* qhasm: AA = A^2 */
                /* asm 1: fe_sq(>AA=fe#6,<A=fe#1); */
                /* asm 2: fe_sq(>AA=tmp1,<A=x2); */
                FieldOperations.fe_sq(out tmp1, ref x2);

                /* qhasm: t0 = DA+CB */
                /* asm 1: fe_add(>t0=fe#3,<DA=fe#4,<CB=fe#2); */
                /* asm 2: fe_add(>t0=x3,<DA=z3,<CB=z2); */
                FieldOperations.fe_add(out x3, ref z3, ref z2);

                /* qhasm: assign x3 to t0 */

                /* qhasm: t1 = DA-CB */
                /* asm 1: fe_sub(>t1=fe#2,<DA=fe#4,<CB=fe#2); */
                /* asm 2: fe_sub(>t1=z2,<DA=z3,<CB=z2); */
                FieldOperations.fe_sub(out z2, ref z3, ref z2);

                /* qhasm: X4 = AA*BB */
                /* asm 1: fe_mul(>X4=fe#1,<AA=fe#6,<BB=fe#5); */
                /* asm 2: fe_mul(>X4=x2,<AA=tmp1,<BB=tmp0); */
                FieldOperations.fe_mul(out x2, ref tmp1, ref tmp0);

                /* qhasm: E = AA-BB */
                /* asm 1: fe_sub(>E=fe#6,<AA=fe#6,<BB=fe#5); */
                /* asm 2: fe_sub(>E=tmp1,<AA=tmp1,<BB=tmp0); */
                FieldOperations.fe_sub(out tmp1, ref tmp1, ref tmp0);

                /* qhasm: t2 = t1^2 */
                /* asm 1: fe_sq(>t2=fe#2,<t1=fe#2); */
                /* asm 2: fe_sq(>t2=z2,<t1=z2); */
                FieldOperations.fe_sq(out z2, ref z2);

                /* qhasm: t3 = a24*E */
                /* asm 1: fe_mul121666(>t3=fe#4,<E=fe#6); */
                /* asm 2: fe_mul121666(>t3=z3,<E=tmp1); */
                FieldOperations.fe_mul121666(out z3, ref tmp1);

                /* qhasm: X5 = t0^2 */
                /* asm 1: fe_sq(>X5=fe#3,<t0=fe#3); */
                /* asm 2: fe_sq(>X5=x3,<t0=x3); */
                FieldOperations.fe_sq(out x3, ref x3);

                /* qhasm: t4 = BB+t3 */
                /* asm 1: fe_add(>t4=fe#5,<BB=fe#5,<t3=fe#4); */
                /* asm 2: fe_add(>t4=tmp0,<BB=tmp0,<t3=z3); */
                FieldOperations.fe_add(out tmp0, ref tmp0, ref z3);

                /* qhasm: Z5 = X1*t2 */
                /* asm 1: fe_mul(>Z5=fe#4,x1,<t2=fe#2); */
                /* asm 2: fe_mul(>Z5=z3,x1,<t2=z2); */
                FieldOperations.fe_mul(out z3, ref x1, ref z2);

                /* qhasm: Z4 = E*t4 */
                /* asm 1: fe_mul(>Z4=fe#2,<E=fe#6,<t4=fe#5); */
                /* asm 2: fe_mul(>Z4=z2,<E=tmp1,<t4=tmp0); */
                FieldOperations.fe_mul(out z2, ref tmp1, ref tmp0);

                /* qhasm: return */
            }
            FieldOperations.fe_cswap(ref x2, ref x3, swap);
            FieldOperations.fe_cswap(ref z2, ref z3, swap);

            FieldOperations.fe_invert(out z2, ref z2);
            FieldOperations.fe_mul(out x2, ref x2, ref z2);
            q = x2;
            CryptoBytes.Wipe(e);
        }
Exemple #13
0
        /*
         * Replace (f,g) with (g,f) if b == 1;
         * replace (f,g) with (f,g) if b == 0.
         *
         * Preconditions: b in {0,1}.
         */
        public static void fe_cswap(ref FieldElement f, ref FieldElement g, uint b)
        {
            int f0 = f.x0;
            int f1 = f.x1;
            int f2 = f.x2;
            int f3 = f.x3;
            int f4 = f.x4;
            int f5 = f.x5;
            int f6 = f.x6;
            int f7 = f.x7;
            int f8 = f.x8;
            int f9 = f.x9;
            int g0 = g.x0;
            int g1 = g.x1;
            int g2 = g.x2;
            int g3 = g.x3;
            int g4 = g.x4;
            int g5 = g.x5;
            int g6 = g.x6;
            int g7 = g.x7;
            int g8 = g.x8;
            int g9 = g.x9;
            int x0 = f0 ^ g0;
            int x1 = f1 ^ g1;
            int x2 = f2 ^ g2;
            int x3 = f3 ^ g3;
            int x4 = f4 ^ g4;
            int x5 = f5 ^ g5;
            int x6 = f6 ^ g6;
            int x7 = f7 ^ g7;
            int x8 = f8 ^ g8;
            int x9 = f9 ^ g9;

            int negb = unchecked ((int)-b);

            x0  &= negb;
            x1  &= negb;
            x2  &= negb;
            x3  &= negb;
            x4  &= negb;
            x5  &= negb;
            x6  &= negb;
            x7  &= negb;
            x8  &= negb;
            x9  &= negb;
            f.x0 = f0 ^ x0;
            f.x1 = f1 ^ x1;
            f.x2 = f2 ^ x2;
            f.x3 = f3 ^ x3;
            f.x4 = f4 ^ x4;
            f.x5 = f5 ^ x5;
            f.x6 = f6 ^ x6;
            f.x7 = f7 ^ x7;
            f.x8 = f8 ^ x8;
            f.x9 = f9 ^ x9;
            g.x0 = g0 ^ x0;
            g.x1 = g1 ^ x1;
            g.x2 = g2 ^ x2;
            g.x3 = g3 ^ x3;
            g.x4 = g4 ^ x4;
            g.x5 = g5 ^ x5;
            g.x6 = g6 ^ x6;
            g.x7 = g7 ^ x7;
            g.x8 = g8 ^ x8;
            g.x9 = g9 ^ x9;
        }