Exemplo n.º 1
0
        public bool SingVer(byte[] H, string sing, EllipticCurve_Point Q)
        {
            int        midl    = Maths.Length(this.curv.N) / 4;
            string     Rvector = sing.Substring(0, midl);
            string     Svector = sing.Substring(midl, midl);
            BigInteger r       = BigInteger.Parse(SupportEDS.DecStringFromHexString(Rvector));
            BigInteger s       = BigInteger.Parse(SupportEDS.DecStringFromHexString(Svector));

            if ((r < 1) || (r > (this.curv.N - 1)) || (s < 1) || (s > (this.curv.N - 1)))
            {
                return(false);
            }
            BigInteger alpha = BigInteger.Parse(SupportEDS.DecStringFromByteArray(H));
            BigInteger e     = alpha % this.curv.N;

            if (e == 0)
            {
                e = 1;
            }
            BigInteger          v  = Maths.GetInverse(e, this.curv.N);
            BigInteger          z1 = (s * v) % this.curv.N;
            BigInteger          z2 = this.curv.N + ((-(r * v)) % this.curv.N);
            EllipticCurve_Point A  = new EllipticCurve_Point();
            EllipticCurve_Point B  = new EllipticCurve_Point();
            EllipticCurve_Point C  = new EllipticCurve_Point();

            curv.Mult(z1, this.curv.G, ref A);
            curv.Mult(z2, Q, ref B);
            curv.Sum(A, B, ref C);
            BigInteger R = C.X % this.curv.N;

            if (R == r)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }