Esempio n. 1
0
        private static void secp256k1_ecmult_odd_multiples_table(int n, GeJ[] prej, Fe[] zr, GeJ a)
        {
            var r1 = new GeJ();

            Group.secp256k1_gej_double_var(r1, a, (Fe)null);
            var b = new Ge();

            b.X        = r1.X.Clone();
            b.Y        = r1.Y.Clone();
            b.Infinity = false;
            var r2 = new Ge();

            Group.secp256k1_ge_set_gej_zinv(r2, a, r1.Z);
            prej[0].X        = r2.X.Clone();
            prej[0].Y        = r2.Y.Clone();
            prej[0].Z        = a.Z.Clone();
            prej[0].Infinity = false;
            zr[0]            = r1.Z.Clone();
            for (var index = 1; index < n; ++index)
            {
                Group.secp256k1_gej_add_ge_var(prej[index], prej[index - 1], b, zr[index]);
            }
            Field.Mul(prej[n - 1].Z, prej[n - 1].Z, r1.Z);
        }
Esempio n. 2
0
        public static void ContextBuild(EcmultGenContext ctx, EventHandler <Callback> cb)
        {
            var r1   = new Ge[1024];
            var r2   = new GeJ();
            var geJ1 = new GeJ();

            if (ctx.Prec != null)
            {
                return;
            }
            ctx.PrecInit();
            Group.secp256k1_gej_set_ge(r2, Group.Secp256K1GeConstG);
            var bytes = Encoding.UTF8.GetBytes("The scalar for this x is unknown");
            var fe    = new Fe();
            var ge    = new Ge();

            Field.SetB32(fe, bytes);
            Group.secp256k1_ge_set_xo_var(ge, fe, false);
            Group.secp256k1_gej_set_ge(geJ1, ge);
            Group.secp256k1_gej_add_ge_var(geJ1, geJ1, Group.Secp256K1GeConstG, (Fe)null);
            var a = new GeJ[1024];

            for (var index = 0; index < a.Length; ++index)
            {
                a[index] = new GeJ();
            }
            var geJ2 = r2.Clone();
            var geJ3 = geJ1.Clone();

            for (var index1 = 0; index1 < 64; ++index1)
            {
                a[index1 * 16] = geJ3.Clone();
                for (var index2 = 1; index2 < 16; ++index2)
                {
                    Group.secp256k1_gej_add_var(a[index1 * 16 + index2], a[index1 * 16 + index2 - 1], geJ2, (Fe)null);
                }
                for (var index2 = 0; index2 < 4; ++index2)
                {
                    Group.secp256k1_gej_double_var(geJ2, geJ2, (Fe)null);
                }
                Group.secp256k1_gej_double_var(geJ3, geJ3, (Fe)null);
                if (index1 == 62)
                {
                    Group.secp256k1_gej_neg(geJ3, geJ3);
                    Group.secp256k1_gej_add_var(geJ3, geJ3, geJ1, (Fe)null);
                }
            }
            for (var index = 0; index < r1.Length; ++index)
            {
                r1[index] = new Ge();
            }
            Group.secp256k1_ge_set_all_gej_var(r1, a, 1024, cb);
            for (var index1 = 0; index1 < 64; ++index1)
            {
                for (var index2 = 0; index2 < 16; ++index2)
                {
                    Group.ToStorage(ctx.Prec[index1][index2], r1[index1 * 16 + index2]);
                }
            }
            EcMultGen.Blind(ctx, (byte[])null);
        }