Exemplo n.º 1
0
        /// <summary>
        /// Creates a new Passphrase rng whose output differs but is a
        /// function of this rng's internal state.
        /// </summary>
        ///
        /// <param name="Digest">The digest instance</param>
        ///
        /// <returns>Returns a PassphrasePrng instance</returns>
        public PBPRng CreateBranch(IDigest Digest)
        {
            PBPRng branch = new PBPRng();

            try
            {
                branch.m_digest = Digest;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }

            branch.m_rndData = (byte[])m_rndData.Clone();
            branch.m_rndData[0]++;

            return(branch);
        }
Exemplo n.º 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(_ntruParams.Digest))
     {
         using (IRandom rnd = new PBPRng(dgt, Passphrase, Salt, 10000, false))
         {
             IRandom rng2 = ((PBPRng)rnd).CreateBranch(dgt);
             return GenerateKeyPair(rnd, rng2);
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new Passphrase rng whose output differs but is a
        /// function of this rng's internal state.
        /// </summary>
        /// 
        /// <param name="Digest">The digest instance</param>
        /// 
        /// <returns>Returns a PassphrasePrng instance</returns>
        public PBPRng CreateBranch(IDigest Digest)
        {
            PBPRng branch = new PBPRng();

            try
            {
                branch._digest = Digest;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }

            branch._rndData = (byte[])_rndData.Clone();
            branch._rndData[0]++;

            return branch;
        }
Exemplo n.º 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(_mpkcParams.Digest))
     {
         using (IRandom rnd = new PBPRng(dgt, Passphrase, Salt, 10000, false))
             return GenerateKeyPair();
     }
 }
Exemplo n.º 5
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);
            }
        }