Exemplo n.º 1
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.CSPPrng().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!");
                }
            }
        }
Exemplo n.º 2
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);
        }