Пример #1
0
        public void Test_ECDH(PrimeFieldCurve Curve1, PrimeFieldCurve Curve2)
        {
            int n;

            for (n = 0; n < 100; n++)
            {
                byte[] Key1 = Curve1.GetSharedKey(Curve2.PublicKey, Hashes.ComputeSHA256Hash);
                byte[] Key2 = Curve2.GetSharedKey(Curve1.PublicKey, Hashes.ComputeSHA256Hash);

                Assert.AreEqual(Hashes.BinaryToString(Key1), Hashes.BinaryToString(Key2));

                Curve1.GenerateKeys();
                Curve2.GenerateKeys();
            }
        }
Пример #2
0
        public void Test_Signature(PrimeFieldCurve Curve1, PrimeFieldCurve Curve2)
        {
            int n;
            int Ok     = 0;
            int Errors = 0;

            using (RandomNumberGenerator rnd = RandomNumberGenerator.Create())
            {
                for (n = 0; n < 100; n++)
                {
                    byte[] Data = new byte[1024];

                    rnd.GetBytes(Data);

                    try
                    {
                        byte[] Signature = Curve1.Sign(Data);
                        bool   Valid     = Curve2.Verify(Data, Curve1.PublicKey, Signature);

                        if (Valid)
                        {
                            Ok++;
                        }
                        else
                        {
                            Errors++;
                        }
                    }
                    catch (Exception)
                    {
                        Errors++;
                    }

                    Curve1.GenerateKeys();
                    Curve2.GenerateKeys();
                }
            }

            Assert.AreEqual(0, Errors);
        }