Exemplo n.º 1
0
		private void btnStartECDSA_Click (object sender, EventArgs e)
		{
			byte[] hash = new byte[160 >> 3];
			Stopwatch sw = new Stopwatch ();
			double ocSignTime, ocVerifyTime, bcSignTime, bcVerifyTime;
			{
				ECDSA ecdsa = new ECDSA (ECDomainNames.secp192r1);
				ecdsa.ToXmlString (false);
				sw.Reset ();
				sw.Start ();
				byte[] ecdsaSign = ecdsa.SignHash (hash);
				sw.Stop ();
				ocSignTime = sw.Elapsed.TotalSeconds;
				sw.Reset ();
				sw.Start ();
				ecdsa.VerifyHash (hash, ecdsaSign);
				sw.Stop ();
				ocVerifyTime = sw.Elapsed.TotalSeconds;
			}

			{
				ECDsaSigner ecdsa = new ECDsaSigner ();
				X9ECParameters SEC_P192r1 = SecNamedCurves.GetByName ("secp192r1");
				BigInteger key = new BigInteger (SEC_P192r1.N.BitCount, new Random ());
				ECDomainParameters domain = new ECDomainParameters (SEC_P192r1.Curve, SEC_P192r1.G, SEC_P192r1.N);
				ECPrivateKeyParameters privateKey = new ECPrivateKeyParameters (key, domain);
				ECPoint publicKeyPoint = SEC_P192r1.G.Multiply (key);
				ECPublicKeyParameters publicKey = new ECPublicKeyParameters (publicKeyPoint, domain);
				ecdsa.Init (true, privateKey);

				sw.Reset ();
				sw.Start ();
				BigInteger[] sign = ecdsa.GenerateSignature (hash);
				sw.Stop ();
				bcSignTime = sw.Elapsed.TotalSeconds;

				ecdsa.Init (false, publicKey);
				sw.Reset ();
				sw.Start ();
				ecdsa.VerifySignature (hash, sign[0], sign[1]);
				sw.Stop ();
				bcVerifyTime = sw.Elapsed.TotalSeconds;
			}

			double scale = 1000;
			bcSignTime *= scale;
			bcVerifyTime *= scale;
			ocSignTime *= scale;
			ocVerifyTime *= scale;

			lblBCSign.Text = "Sign (" + bcSignTime.ToString ("f2") + "ms)";
			lblBCVerify.Text = "Verify (" + bcVerifyTime.ToString ("f2") + "ms)";
			lblOCSign.Text = "Sign (" + ocSignTime.ToString ("f2") + "ms)";
			lblOCVerify.Text = "Verify (" + ocVerifyTime.ToString ("f2") + "ms)";

			double max = Math.Max (ocSignTime, Math.Max (ocVerifyTime, Math.Max (bcSignTime, bcVerifyTime)));			
			max *= 1.1;

			pbEcdsaSignBC.Maximum = pbEcdsaVerifyBC.Maximum = pbEcdsaSignOC.Maximum = pbEcdsaVerifyOC.Maximum = (int)max;
			pbEcdsaSignBC.Value = (int)bcSignTime;
			pbEcdsaVerifyBC.Value = (int)bcVerifyTime;
			pbEcdsaSignOC.Value = (int)ocSignTime;
			pbEcdsaVerifyOC.Value = (int)ocVerifyTime;
		}
Exemplo n.º 2
0
        private void btnStartECDSA_Click(object sender, EventArgs e)
        {
            byte[]    hash = new byte[160 >> 3];
            Stopwatch sw = new Stopwatch();
            double    ocSignTime, ocVerifyTime, bcSignTime, bcVerifyTime;
            {
                ECDSA ecdsa = new ECDSA(ECDomainNames.secp192r1);
                ecdsa.ToXmlString(false);
                sw.Reset();
                sw.Start();
                byte[] ecdsaSign = ecdsa.SignHash(hash);
                sw.Stop();
                ocSignTime = sw.Elapsed.TotalSeconds;
                sw.Reset();
                sw.Start();
                ecdsa.VerifyHash(hash, ecdsaSign);
                sw.Stop();
                ocVerifyTime = sw.Elapsed.TotalSeconds;
            }

            {
                ECDsaSigner            ecdsa      = new ECDsaSigner();
                X9ECParameters         SEC_P192r1 = SecNamedCurves.GetByName("secp192r1");
                BigInteger             key        = new BigInteger(SEC_P192r1.N.BitCount, new Random());
                ECDomainParameters     domain     = new ECDomainParameters(SEC_P192r1.Curve, SEC_P192r1.G, SEC_P192r1.N);
                ECPrivateKeyParameters privateKey = new ECPrivateKeyParameters(key, domain);
                ECPoint publicKeyPoint            = SEC_P192r1.G.Multiply(key);
                ECPublicKeyParameters publicKey   = new ECPublicKeyParameters(publicKeyPoint, domain);
                ecdsa.Init(true, privateKey);

                sw.Reset();
                sw.Start();
                BigInteger[] sign = ecdsa.GenerateSignature(hash);
                sw.Stop();
                bcSignTime = sw.Elapsed.TotalSeconds;

                ecdsa.Init(false, publicKey);
                sw.Reset();
                sw.Start();
                ecdsa.VerifySignature(hash, sign[0], sign[1]);
                sw.Stop();
                bcVerifyTime = sw.Elapsed.TotalSeconds;
            }

            double scale = 1000;

            bcSignTime   *= scale;
            bcVerifyTime *= scale;
            ocSignTime   *= scale;
            ocVerifyTime *= scale;

            lblBCSign.Text   = "Sign (" + bcSignTime.ToString("f2") + "ms)";
            lblBCVerify.Text = "Verify (" + bcVerifyTime.ToString("f2") + "ms)";
            lblOCSign.Text   = "Sign (" + ocSignTime.ToString("f2") + "ms)";
            lblOCVerify.Text = "Verify (" + ocVerifyTime.ToString("f2") + "ms)";

            double max = Math.Max(ocSignTime, Math.Max(ocVerifyTime, Math.Max(bcSignTime, bcVerifyTime)));

            max *= 1.1;

            pbEcdsaSignBC.Maximum = pbEcdsaVerifyBC.Maximum = pbEcdsaSignOC.Maximum = pbEcdsaVerifyOC.Maximum = (int)max;
            pbEcdsaSignBC.Value   = (int)bcSignTime;
            pbEcdsaVerifyBC.Value = (int)bcVerifyTime;
            pbEcdsaSignOC.Value   = (int)ocSignTime;
            pbEcdsaVerifyOC.Value = (int)ocVerifyTime;
        }