Пример #1
0
        private void TestSign(GMSSParameters CipherParam)
        {
            GMSSKeyGenerator mkgen = new GMSSKeyGenerator(CipherParam);
            IAsymmetricKeyPair akp = mkgen.GenerateKeyPair();
            byte[] data = new byte[200];
            new VTDev.Libraries.CEXEngine.Crypto.Prng.CSPRng().GetBytes(data);

            using (GMSSSign sgn = new GMSSSign(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!");

                // get the next available key (private sub-key is used only once)
                GMSSPrivateKey nk = ((GMSSPrivateKey)akp.PrivateKey).NextKey();
                sgn.Initialize(nk);
                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!");
            }
        }
Пример #2
0
        static double KeyGenerator(int Iterations, GMSSParameters Param)
        {
            // new SP20Prng(SeedGenerators.CSPRsg, 16384, 32, 10) // salsa20
            GMSSKeyGenerator mkgen = new GMSSKeyGenerator(Param);
            IAsymmetricKeyPair akp;
            Stopwatch runTimer = new Stopwatch();

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

            return runTimer.Elapsed.TotalMilliseconds;
        }
Пример #3
0
        private void TestEncode()
        {
            GMSSParameters mpar = GMSSParamSets.FromName(GMSSParamSets.GMSSParamNames.N2P10);
            GMSSKeyGenerator mkgen = new GMSSKeyGenerator(mpar);
            IAsymmetricKeyPair akp = mkgen.GenerateKeyPair();

            GMSSPublicKey pub = (GMSSPublicKey)akp.PublicKey;
            byte[] enc = pub.ToBytes();
            using (GMSSPublicKey pub2 = GMSSPublicKey.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 (GMSSPublicKey pub2 = GMSSPublicKey.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"));

            GMSSPrivateKey pri = (GMSSPrivateKey)akp.PrivateKey;
            enc = pri.ToBytes();
            using (GMSSPrivateKey pri2 = GMSSPrivateKey.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 (GMSSPrivateKey pri2 = GMSSPrivateKey.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();
        }
Пример #4
0
        static double SignTest(int Iterations, GMSSParameters Param, bool Sign = true)
        {
            Stopwatch runTimer = new Stopwatch();
            byte[] code;
            GMSSKeyGenerator mkgen = new GMSSKeyGenerator(Param);
            IAsymmetricKeyPair akp = mkgen.GenerateKeyPair();
            byte[] data = new byte[200];
            new CSPRng().GetBytes(data);

            using (GMSSSign sgn = new GMSSSign(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;
        }