예제 #1
0
        private void NextTest()
        {
            PBPRng rng = CreateRng();

            if (!Evaluate.True(rng.Next(1) < 2))
            {
                throw new Exception("PBPRng: next random test failed!");
            }
            if (!Evaluate.True(rng.Next(1) >= 0))
            {
                throw new Exception("PBPRng: next random test failed!");
            }
            if (!Evaluate.True(rng.Next(8) < 256))
            {
                throw new Exception("PBPRng: next random test failed!");
            }
            if (!Evaluate.True(rng.Next(8) >= 0))
            {
                throw new Exception("PBPRng: next random test failed!");
            }
            if (!Evaluate.True(rng.Next(11) < 2048))
            {
                throw new Exception("PBPRng: next random test failed!");
            }
            if (!Evaluate.True(rng.Next(11) >= 0))
            {
                throw new Exception("PBPRng: next random test failed!");
            }
            if (!Evaluate.True(rng.Next(31) >= 0))
            {
                throw new Exception("PBPRng: next random test failed!");
            }
        }
예제 #2
0
 /// <summary>
 /// Generates an encryption key pair using a passphrase based prng.
 /// <para>Invoking this method with the same passphrase and salt will always return the same key pair.</para>
 /// </summary>
 ///
 /// <param name="Passphrase">The passphrase</param>
 /// <param name="Salt">Salt for the passphrase; can be <c>null</c> but this is strongly discouraged</param>
 ///
 /// <returns>A populated IAsymmetricKeyPair</returns>
 public IAsymmetricKeyPair GenerateKeyPair(byte[] Passphrase, byte[] Salt)
 {
     using (IDigest dgt = GetDigest(m_rlweParams.Digest))
     {
         using (IRandom rnd = new PBPRng(dgt, Passphrase, Salt, 10000, false))
             return(GenerateKeyPair());
     }
 }
예제 #3
0
        /// <summary>
        /// Generates an encryption key pair using a passphrase based drbg.
        /// <para>Invoking this method with the same passphrase and salt will always return the same key pair.</para>
        /// </summary>
        ///
        /// <param name="Passphrase">The passphrase</param>
        /// <param name="Salt">Salt for the passphrase; can be <c>null</c> but this is strongly discouraged</param>
        ///
        /// <returns>A populated IAsymmetricKeyPair</returns>
        public IAsymmetricKeyPair GenerateKeyPair(byte[] Passphrase, byte[] Salt)
        {
            _dgtEngine.Reset();

            using (IRandom rnd = new PBPRng(_dgtEngine, Passphrase, Salt, 10000, false))
            {
                IRandom rng2 = ((PBPRng)rnd).CreateBranch(_dgtEngine);
                return(GenerateKeyPair(rnd, rng2));
            }
        }
예제 #4
0
 /// <summary>
 /// Generates an encryption key pair using a passphrase based prng.
 /// <para>Invoking this method with the same passphrase and salt will always return the same key pair.</para>
 /// </summary>
 ///
 /// <param name="Passphrase">The passphrase</param>
 /// <param name="Salt">Salt for the passphrase; can be <c>null</c> but this is strongly discouraged</param>
 ///
 /// <returns>A populated IAsymmetricKeyPair</returns>
 public IAsymmetricKeyPair GenerateKeyPair(byte[] Passphrase, byte[] Salt)
 {
     using (IDigest dgt = GetDigest(m_ntruParams.Digest))
     {
         using (IRandom rnd = new PBPRng(dgt, Passphrase, Salt, 10000, false))
         {
             IRandom rng2 = ((PBPRng)rnd).CreateBranch(dgt);
             return(GenerateKeyPair(rnd, rng2));
         }
     }
 }
예제 #5
0
 /// <summary>
 /// Generates an encryption key pair using a passphrase based prng.
 /// <para>Invoking this method with the same passphrase and salt will always return the same key pair.</para>
 /// </summary>
 /// <param name="Passphrase">The passphrase</param>
 /// <param name="Salt">Salt for the passphrase; can be <c>null</c> but this is strongly discouraged</param>
 /// <returns>A populated IAsymmetricKeyPair</returns>
 public IAsymmetricKeyPair GenerateKeyPair(byte[] Passphrase, byte[] Salt)
 {
     using (var dgt = this.GetDigest(this.m_ntruParams.Digest))
     {
         // Changes 10000 to 100 and false to true
         using (IRandom rnd = new PBPRng(dgt, Passphrase, Salt, 100, true))
         {
             IRandom rng2 = ((PBPRng)rnd).CreateBranch(dgt);
             return(this.GenerateKeyPair(rnd, rng2));
         }
     }
 }
예제 #6
0
        private void CreateBranch()
        {
            PBPRng rng1 = CreateRng();
            PBPRng rng2 = rng1.CreateBranch(new SHA512());

            byte[] data1 = new byte[32];
            rng2.GetBytes(data1);

            rng1 = CreateRng();
            rng2 = rng1.CreateBranch(new SHA512());
            byte[] data2 = new byte[32];
            rng2.GetBytes(data2);
            // should be equal
            if (!Evaluate.AreEqual(data1, data2))
            {
                throw new Exception("PBPRng: create branch test failed!");
            }
        }