Ejemplo n.º 1
0
        static double KeyGenerator(int Iterations, RNBWParameters Param)
        {
            // new SP20Prng(SeedGenerators.CSPRsg, 16384, 32, 10) // salsa20
            RNBWKeyGenerator mkgen = new RNBWKeyGenerator(Param, new CTRPrng(BlockCiphers.RDX, SeedGenerators.CSPRsg, 16384, 16));
            IAsymmetricKeyPair akp;
            Stopwatch runTimer = new Stopwatch();

            runTimer.Start();
            for (int i = 0; i < Iterations; i++)
                akp = mkgen.GenerateKeyPair();
            runTimer.Stop();

            return runTimer.Elapsed.TotalMilliseconds;
        }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
0
        static double SignTest(int Iterations, RNBWParameters Param, bool Sign = true)
        {
            Stopwatch runTimer = new Stopwatch();
            byte[] code;
            RNBWKeyGenerator mkgen = new RNBWKeyGenerator(Param, new CTRPrng(BlockCiphers.RDX, SeedGenerators.CSPRsg, 16384, 16));
            IAsymmetricKeyPair akp = mkgen.GenerateKeyPair();
            byte[] data = new byte[200];
            new CSPRng().GetBytes(data);

            using (RNBWSign sgn = new RNBWSign(Param))
            {
                if (Sign)
                {
                    sgn.Initialize(akp.PrivateKey);

                    runTimer.Start();
                    for (int i = 0; i < Iterations; i++)
                        code = sgn.Sign(data, 0, data.Length);
                    runTimer.Stop();
                }
                else
                {
                    // sign the array first
                    sgn.Initialize(akp.PrivateKey);
                    code = sgn.Sign(data, 0, data.Length);
                    // init for verify
                    sgn.Initialize(akp.PublicKey);

                    runTimer.Start();
                    for (int i = 0; i < Iterations; i++)
                        sgn.Verify(data, 0, data.Length, code);
                    runTimer.Stop();
                }
            }

            return runTimer.Elapsed.TotalMilliseconds;
        }
Ejemplo n.º 4
0
        private void TestSign(RNBWParameters CipherParam)
        {
            RNBWKeyGenerator mkgen = new RNBWKeyGenerator(CipherParam);
            IAsymmetricKeyPair akp = mkgen.GenerateKeyPair();
            byte[] data = new byte[200];
            new VTDev.Libraries.CEXEngine.Crypto.Prng.CSPRng().GetBytes(data);

            using (RNBWSign sgn = new RNBWSign(CipherParam))
            {
                // sign the array
                sgn.Initialize(akp.PrivateKey);
                byte[] code = sgn.Sign(data, 0, data.Length);
                // verify the signature
                sgn.Initialize(akp.PublicKey);
                if (!sgn.Verify(data, 0, data.Length, code))
                    throw new Exception("RLWESignTest: Sign operation failed!");

                // sign and test stream ctor
                sgn.Initialize(akp.PrivateKey);
                code = sgn.Sign(new MemoryStream(data));
                // verify the signature
                sgn.Initialize(akp.PublicKey);
                if (!sgn.Verify(new MemoryStream(data), code))
                    throw new Exception("RLWESignTest: Verify test failed!");
            }
        }