コード例 #1
0
        public static bool EcPubKeyCreate(Context ctx, PubKey pubkey, byte[] seckey)
        {
            GeJ    r      = new GeJ();
            Ge     ge     = new Ge();
            Scalar scalar = new Scalar();
            int    num    = !Scalar.SetB32(scalar, seckey) & !Scalar.IsZero(scalar) ? 1 : 0;

            if (num != 0)
            {
                EcMultGen.secp256k1_ecmult_gen(ctx.EcMultGenCtx, out r, scalar);
                Group.SetGeJ(ge, r);
                Secp256K1T.SavePubKey(pubkey, ge);
            }
            Scalar.Clear(scalar);
            return(num != 0);
        }
コード例 #2
0
        public static void Blind(EcmultGenContext ctx, byte[] seed32)
        {
            Scalar             scalar = new Scalar();
            Fe                 fe     = new Fe();
            Rfc6979HmacSha256T rng    = new Rfc6979HmacSha256T();

            byte[] numArray = new byte[64];
            if (seed32 == null)
            {
                Group.secp256k1_gej_set_ge(ctx.Initial, Group.Secp256K1GeConstG);
                Group.secp256k1_gej_neg(ctx.Initial, ctx.Initial);
                ctx.Blind.SetInt(1U);
            }
            byte[] b32 = Scalar.GetB32(ctx.Blind);
            Util.Memcpy((Array)b32, 0, (Array)numArray, 0, 32);
            if (seed32 != null)
            {
                Util.Memcpy((Array)seed32, 0, (Array)numArray, 32, 32);
            }
            Hash.Rfc6979HmacSha256Initialize(rng, numArray, seed32 != null ? 64U : 32U);
            Util.MemSet(numArray, (byte)0, numArray.Length);
            bool overflow;

            do
            {
                Hash.Rfc6979HmacSha256Generate(rng, b32, 32);
                overflow = !Field.SetB32(fe, b32) | Field.IsZero(fe);
            }while (overflow);
            Group.secp256k1_gej_rescale(ctx.Initial, fe);
            Field.Clear(fe);
            do
            {
                Hash.Rfc6979HmacSha256Generate(rng, b32, 32);
                Scalar.SetB32(scalar, b32, ref overflow);
                overflow |= Scalar.IsZero(scalar);
            }while (overflow);
            Hash.Rfc6979HmacSha256Finalize(rng);
            Util.MemSet(b32, (byte)0, 32);
            GeJ r;

            EcMultGen.secp256k1_ecmult_gen(ctx, out r, scalar);
            Scalar.Negate(scalar, scalar);
            ctx.Blind   = scalar.Clone();
            ctx.Initial = r.Clone();
            Scalar.Clear(scalar);
            Group.secp256k1_gej_clear(r);
        }
コード例 #3
0
        public static bool EcPubKeyCreate(Context ctx, PubKey pubkey, byte[] seckey)
        {
            GeJ pj  = new GeJ();
            Ge  p   = new Ge();
            var sec = new Scalar();

            var overflow = Scalar.SetB32(sec, seckey);
            var ret      = !overflow & !Scalar.IsZero(sec);

            if (ret)
            {
                EcMultGen.secp256k1_ecmult_gen(ctx.EcMultGenCtx, out pj, sec);
                Group.SetGeJ(p, pj);
                SavePubKey(pubkey, p);
            }
            Scalar.Clear(sec);
            return(ret);
        }