Beispiel #1
0
        public static void RunECDHE(int iterations)
        {
            Console.WriteLine("Running " + iterations + " diffie hellman key exchanges");

            Stopwatch watch = new Stopwatch();

            for (int i = 0; i < iterations; i++)
            {
                watch.Start();

                // Both create their instances
                ECDiffieHellman serverDiffie = new ECDiffieHellman();
                ECDiffieHellman clientDiffie = new ECDiffieHellman();

                // Exchange publics

                /* START TRANSMISSION */
                byte[] serverPublic = serverDiffie.GetPublicKey();
                byte[] clientPublic = clientDiffie.GetPublicKey();
                /* END TRANSMISSION */

                // Calculate shared
                byte[] key1 = serverDiffie.GetSharedSecretRaw(clientPublic);
                byte[] key2 = clientDiffie.GetSharedSecretRaw(serverPublic);

                watch.Stop();

                if (key1.Length != key2.Length)
                {
                    Console.WriteLine("CRITICAL: LENGTH MISSMATCH");
                    continue;
                }

                for (int x = 0; x < key1.Length; x++)
                {
                    if (key1[x] != key2[x])
                    {
                        Console.WriteLine("CRITICAL: MISSMATCH");
                        break;
                    }
                }
            }

            Console.WriteLine("Completed in " + watch.ElapsedMilliseconds + " ms, " + (watch.ElapsedMilliseconds / iterations) + " ms per exchange");
        }