Ejemplo n.º 1
0
        // tests key pair generation from a passphrase
        private void GenerateKeyPair()
        {
            NTRUParameters param = (NTRUParameters)NTRUParamSets.EES1087EP2FAST.DeepCopy();

            byte[] passphrase = Encoding.Unicode.GetBytes("password123");
            byte[] salt       = new CSPPrng().GetBytes(16);

            NTRUKeyPair kp1;

            using (NTRUKeyGenerator kg = new NTRUKeyGenerator(param, false)) // note: parallel must be turned off with passphrase prng
                kp1 = (NTRUKeyPair)kg.GenerateKeyPair(passphrase, salt);
            NTRUKeyPair kp2;

            using (NTRUKeyGenerator kg = new NTRUKeyGenerator(param, false))
                kp2 = (NTRUKeyPair)kg.GenerateKeyPair(passphrase, salt);

            NTRUEncrypt ntru  = new NTRUEncrypt(param);
            NTRUEncrypt ntru2 = new NTRUEncrypt(NTRUParamSets.EES1087EP2FAST);

            if (!kp1.Equals(kp2))
            {
                throw new Exception("NtruEncryptTest: key pair generation test failed!");
            }

            salt = ntru.GenerateSalt();
            NTRUKeyPair kp3;

            using (NTRUKeyGenerator kg = new NTRUKeyGenerator(param, false))
                kp3 = (NTRUKeyPair)kg.GenerateKeyPair(passphrase, salt);

            if (!Evaluate.False(kp1.Equals(kp3)))
            {
                throw new Exception("NtruEncryptTest: key pair generation test failed!");
            }
        }