Beispiel #1
0
        private void TestParams()
        {
            RNBWParameters mpar = RNBWParamSets.FromName(RNBWParamSets.RNBWParamNames.N33L5);

            byte[] enc = mpar.ToBytes();

            using (RNBWParameters mpar2 = RNBWParameters.From(enc))
            {
                if (!mpar.Equals(mpar2))
                {
                    throw new Exception("Parameters: public key comparison test failed!");
                }
                if (mpar.GetHashCode() != mpar2.GetHashCode())
                {
                    throw new Exception("Parameters: parameters hash test failed!");
                }
            }
            OnProgress(new TestEventArgs("Passed parameters byte serialization"));

            MemoryStream mstr = mpar.ToStream();

            using (RNBWParameters mpar2 = RNBWParameters.From(mstr))
            {
                if (!mpar.Equals(mpar2))
                {
                    throw new Exception("Parameters: public key comparison test failed!");
                }
                if (mpar.GetHashCode() != mpar2.GetHashCode())
                {
                    throw new Exception("Parameters: parameters hash test failed!");
                }
            }
            OnProgress(new TestEventArgs("Passed parameters stream serialization"));
        }
Beispiel #2
0
        /// <summary>
        /// Tests the validity of the RNBWSign implementation
        /// </summary>
        ///
        /// <returns>State</returns>
        public string Run()
        {
            try
            {
                TestSign(RNBWParamSets.FromName(RNBWParamSets.RNBWParamNames.N33L5));
                OnProgress(new TestEventArgs("N33L5 params Passed Key Generation, Sign, and Verify Tests.."));

                if (!System.Diagnostics.Debugger.IsAttached)
                {
                    TestSign(RNBWParamSets.FromName(RNBWParamSets.RNBWParamNames.N49L5));
                    OnProgress(new TestEventArgs("N49L5 params Passed Key Generation, Sign, and Verify Tests.."));
                    TestSign(RNBWParamSets.FromName(RNBWParamSets.RNBWParamNames.N54L5));
                    OnProgress(new TestEventArgs("N54L5 params Passed Key Generation, Sign, and Verify Tests.."));
                    TestSign(RNBWParamSets.FromName(RNBWParamSets.RNBWParamNames.N58L5));
                    OnProgress(new TestEventArgs("N58L5 params Passed Key Generation, Sign, and Verify Tests.."));
                    TestSign(RNBWParamSets.FromName(RNBWParamSets.RNBWParamNames.N60L5));
                    OnProgress(new TestEventArgs("N60L5 params Passed Key Generation, Sign, and Verify Tests.."));

                    /*TestSign(RNBWParamSets.FromName(RNBWParamSets.RNBWParamNames.N63L5));
                     * OnProgress(new TestEventArgs("N63L5 params Passed Key Generation, Sign, and Verify Tests.."));
                     * TestSign(RNBWParamSets.FromName(RNBWParamSets.RNBWParamNames.N66L5));
                     * OnProgress(new TestEventArgs("N66L5 params Passed Key Generation, Sign, and Verify Tests.."));*/
                }

                return(SUCCESS);
            }
            catch (Exception Ex)
            {
                string message = Ex.Message == null ? "" : Ex.Message;
                throw new Exception(FAILURE + message);
            }
        }
Beispiel #3
0
        static void SignSpeed(int Iterations = 10)
        {
            Console.WriteLine(string.Format("N | L: Sign and Verify operations time over {0} passes:", Iterations));

            double elapsed = SignTest(Iterations, RNBWParamSets.FromName(RNBWParamSets.RNBWParamNames.N33L5));

            Console.WriteLine(string.Format("N33 L5: messages signed avg. {0} ms", elapsed / Iterations, Iterations));
            Console.WriteLine(string.Format("{0} messages signed in: {1} ms", Iterations, elapsed));
            Console.WriteLine(string.Format("Sign Rate is {0} per second", (int)(1000.0 / (elapsed / Iterations))));
            Console.WriteLine("");
            elapsed = SignTest(Iterations, RNBWParamSets.FromName(RNBWParamSets.RNBWParamNames.N33L5), false);
            Console.WriteLine(string.Format("N33 L5: messages verified avg. {0} ms", elapsed / Iterations, Iterations));
            Console.WriteLine(string.Format("{0} messages verified in: {1} ms", Iterations, elapsed));
            Console.WriteLine(string.Format("Verify Rate is {0} per second", (int)(1000.0 / (elapsed / Iterations))));
            Console.WriteLine("");
            elapsed = SignTest(Iterations, RNBWParamSets.FromName(RNBWParamSets.RNBWParamNames.N49L5));
            Console.WriteLine(string.Format("N49 L5: messages signed avg. {0} ms", elapsed / Iterations, Iterations));
            Console.WriteLine(string.Format("{0} messages signed in: {1} ms", Iterations, elapsed));
            Console.WriteLine(string.Format("Sign Rate is {0} per second", (int)(1000.0 / (elapsed / Iterations))));
            Console.WriteLine("");
            elapsed = SignTest(Iterations, RNBWParamSets.FromName(RNBWParamSets.RNBWParamNames.N49L5), false);
            Console.WriteLine(string.Format("N49 L5: messages verified avg. {0} ms", elapsed / Iterations, Iterations));
            Console.WriteLine(string.Format("{0} messages verified in: {1} ms", Iterations, elapsed));
            Console.WriteLine(string.Format("Verify Rate is {0} per second", (int)(1000.0 / (elapsed / Iterations))));
            Console.WriteLine("");
        }
        private void TestEncode()
        {
            RNBWParameters     mpar  = RNBWParamSets.FromName(RNBWParamSets.RNBWParamNames.N33L5);
            RNBWKeyGenerator   mkgen = new RNBWKeyGenerator(mpar);
            IAsymmetricKeyPair akp   = mkgen.GenerateKeyPair();

            RNBWPublicKey pub = (RNBWPublicKey)akp.PublicKey;

            byte[] enc = pub.ToBytes();
            using (RNBWPublicKey pub2 = RNBWPublicKey.From(enc))
            {
                if (!pub.Equals(pub2))
                {
                    throw new Exception("EncryptionKey: public key comparison test failed!");
                }
            }
            OnProgress(new TestEventArgs("Passed public key serialization"));

            MemoryStream pubstr = pub.ToStream();

            using (RNBWPublicKey pub2 = RNBWPublicKey.From(pubstr))
            {
                if (!pub.Equals(pub2))
                {
                    throw new Exception("EncryptionKey: public key comparison test failed!");
                }
            }
            pubstr.Dispose();
            OnProgress(new TestEventArgs("Passed public key stream test"));

            RNBWPrivateKey pri = (RNBWPrivateKey)akp.PrivateKey;

            enc = pri.ToBytes();
            using (RNBWPrivateKey pri2 = RNBWPrivateKey.From(enc))
            {
                if (!pri.Equals(pri2))
                {
                    throw new Exception("EncryptionKey: private key comparison test failed!");
                }
            }
            OnProgress(new TestEventArgs("Passed private key serialization"));

            MemoryStream pristr = pri.ToStream();

            using (RNBWPrivateKey pri2 = RNBWPrivateKey.From(pristr))
            {
                if (!pri.Equals(pri2))
                {
                    throw new Exception("EncryptionKey: private key comparison test failed!");
                }
            }
            pristr.Dispose();
            OnProgress(new TestEventArgs("Passed private key stream test"));


            pri.Dispose();
            pub.Dispose();
        }
Beispiel #5
0
        static void KeyGenSpeed(int Iterations = 4)
        {
            Console.WriteLine(string.Format("N | L: Key creation average time over {0} passes:", Iterations));
            Stopwatch runTimer = new Stopwatch();

            double elapsed = KeyGenerator(Iterations, RNBWParamSets.FromName(RNBWParamSets.RNBWParamNames.N33L5));

            Console.WriteLine(string.Format("N33 L5: avg. {0} ms", elapsed / Iterations, Iterations));
            Console.WriteLine(string.Format("{0} keys created in: {1} ms", Iterations, elapsed));
            Console.WriteLine(string.Format("Creation Rate is {0} keys per second", (int)(1000.0 / (elapsed / Iterations))));
            Console.WriteLine("");
        }