Example #1
0
        public static double Run(ECMQV ecmqv, int loop)
        {
            Stopwatch sw         = new Stopwatch();
            int       keyDataLen = 20;

            byte[] otherPublicKey1 = ecmqv.Parameters.KeyPair1.PublicKey;
            byte[] otherPublicKey2 = ecmqv.Parameters.KeyPair2.PublicKey;

            // re-generate key
            ecmqv.Parameters.KeyPair1.PrivateKey = null;
            ecmqv.Parameters.KeyPair2.PrivateKey = null;

            ecmqv.PerformKeyAgreement(otherPublicKey1, otherPublicKey2, keyDataLen);
            sw.Reset(); sw.Start();
            for (int i = 0; i < loop; i++)
            {
                ecmqv.PerformKeyAgreement(otherPublicKey1, otherPublicKey2, keyDataLen);
            }
            sw.Stop();
            return(sw.Elapsed.TotalMilliseconds / (double)loop);
        }
Example #2
0
        public void Test_Random()
        {
            ECDomainNames name = ECDomainNames.secp256r1;

            for (int i = 0; i < 10; i++)
            {
                ECMQV ecmqv1     = new ECMQV(name);
                ECMQV ecmqv2     = new ECMQV(name);
                int   keyDataLen = 20;

                byte[] key1 = ecmqv1.PerformKeyAgreement(ecmqv2.Parameters.KeyPair1.PublicKey, ecmqv2.Parameters.KeyPair2.PublicKey, keyDataLen);
                byte[] key2 = ecmqv2.PerformKeyAgreement(ecmqv1.Parameters.KeyPair1.PublicKey, ecmqv1.Parameters.KeyPair2.PublicKey, keyDataLen);
                Assert.AreEqual(key1, key2);
            }
        }
Example #3
0
        public void Test_MQV()
        {
            ECDomainNames name       = ECDomainNames.secp160r1;
            ECMQV         ecmqv1     = new ECMQV(name);
            ECMQV         ecmqv2     = new ECMQV(name);
            int           keyDataLen = 20;
            int           keyBytes   = 20;

            ecmqv1.Parameters.KeyPair1.PrivateKey = Number.Parse("971761939728640320549601132085879836204587084162", 10).ToByteArray(keyBytes, false);
            ecmqv1.Parameters.KeyPair2.PrivateKey = Number.Parse("117720748206090884214100397070943062470184499100", 10).ToByteArray(keyBytes, false);
            ecmqv2.Parameters.KeyPair1.PrivateKey = Number.Parse("399525573676508631577122671218044116107572676710", 10).ToByteArray(keyBytes, false);
            ecmqv2.Parameters.KeyPair2.PrivateKey = Number.Parse("141325380784931851783969312377642205317371311134", 10).ToByteArray(keyBytes, false);

            byte[] key1 = ecmqv1.PerformKeyAgreement(ecmqv2.Parameters.KeyPair1.PublicKey, ecmqv2.Parameters.KeyPair2.PublicKey, keyDataLen);
            byte[] key2 = ecmqv2.PerformKeyAgreement(ecmqv1.Parameters.KeyPair1.PublicKey, ecmqv1.Parameters.KeyPair2.PublicKey, keyDataLen);

            Assert.AreEqual(key1, key2, "#1");
            Assert.AreEqual(key1, Number.Parse("C06763F8C3D2452C1CC5D29BD61918FB485063F6", 16).ToByteArray(keyDataLen, false), "#2");
        }
Example #4
0
        public void Test_Random_with_SharedInfo()
        {
            ECDomainNames name = ECDomainNames.secp256r1;

            for (int i = 0; i < 10; i++)
            {
                ECMQV ecmqv1     = new ECMQV(name);
                ECMQV ecmqv2     = new ECMQV(name);
                int   keyDataLen = 20;

                byte[] sharedInfo = RNG.GetBytes(RNG.GetBytes(1)[0] + 1);
                ecmqv1.SharedInfo = sharedInfo;
                ecmqv2.SharedInfo = sharedInfo;

                byte[] key1 = ecmqv1.PerformKeyAgreement(ecmqv2.Parameters.KeyPair1.PublicKey, ecmqv2.Parameters.KeyPair2.PublicKey, keyDataLen);
                byte[] key2 = ecmqv2.PerformKeyAgreement(ecmqv1.Parameters.KeyPair1.PublicKey, ecmqv1.Parameters.KeyPair2.PublicKey, keyDataLen);
                Assert.AreEqual(key1, key2);
            }
        }