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!");
            }
        }
Exemple #2
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;
        }