示例#1
0
 private void Button_cr_keys_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         EDS.LoadScheme(this.db.Schemes.Where(sh => sh.Name == this.select_scheme_textblock.Text).First());
         EDS.Key_length = Convert.ToInt32(this.key_lenght_textbox.Text);
         int bits = Maths.Length(EDS.curv.P);
         if (EDS.Key_length > bits)
         {
             MessageBox.Show(String.Format("Разрядность ключа не должна превышать разрядность p ({0})!", bits), "Внимание");
             return;
         }
         EDS.CreateKeys();
         if (!EDS.VerifyKeys())
         {
             MessageBox.Show("Ключи диссациативны, желательно их пересоздать.", "Внимание");
         }
         this.public_key_d_textbox.Text   = EDS.D.ToString();
         this.private_key_qx_textbox.Text = EDS.Q.X.ToString();
         this.private_key_qy_textbox.Text = EDS.Q.Y.ToString();
     }
     catch (Exception excp)
     {
         MessageBox.Show(excp.Message);
     }
 }
示例#2
0
        public string SingGen(byte[] h, BigInteger d)
        {
            BigInteger alpha = BigInteger.Parse(SupportEDS.DecStringFromByteArray(h));
            BigInteger e     = alpha % this.curv.N;

            if (e == 0)
            {
                e = 1;
            }
            BigInteger          k = new BigInteger();
            EllipticCurve_Point C = new EllipticCurve_Point();
            BigInteger          r = new BigInteger();
            BigInteger          s = new BigInteger();

            do
            {
                Random rnd = new Random();
                do
                {
                    k = Maths.RandBigInteger(Maths.Length(this.curv.N), rnd);
                }while ((k < 0) || (k > this.curv.N));
                curv.Mult(k, this.curv.G, ref C);
                r = C.X % this.curv.N;
                s = ((r * d) + (k * e)) % this.curv.N;
            }while ((r == 0) || (s == 0));
            int    midl    = Maths.Length(this.curv.N) / 4;
            string Rvector = SupportEDS.Add0PaddingToString(r.ToString("X"), midl);
            string Svector = SupportEDS.Add0PaddingToString(s.ToString("X"), midl);

            return(Rvector + Svector);
        }
示例#3
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);
            }
        }
示例#4
0
 public static int ProtectionLevel(BigInteger n)
 {
     return(Maths.Length(n) / 8);
 }