示例#1
0
        /// <summary>
        /// This creates a Basyl Key Generator from the arguments..
        /// </summary>
        /// <param name="pass"></param>
        /// <param name="initial"></param>
        /// <param name="rounds"></param>
        /// <param name="leftoff"></param>
        /// <param name="expansion"></param>
        /// <param name="additionalKey"></param>
        /// <param name="sha"></param>
        /// <param name="Key1Random"></param>
        /// <param name="Key2Random"></param>
        /// <param name="encryptedKey1"></param>
        /// <param name="adaptor"></param>
        public BasylKeyGenerator(string pass, int initial, int rounds, int leftoff, int expansion, string additionalKey, byte[] sha, byte[] Key1Random, byte[] Key2Random, bool encryptedKey1, BasylPseudoAdaptor adaptor)
        {
            if (adaptor == null)
            {
                adaptor = new BasylPseudoAdaptor();
            }
            this.sha        = sha;
            this.Key2Random = Key2Random;

            PseudoRandomGenerator Key1 = new PseudoRandomGenerator(initial, pass, rounds, adaptor);

            Key2 = new PseudoRandomGenerator(1024 * 40, pass, 400, adaptor);

            //Set the left off
            Key1.SetLeftoff(leftoff);
            Key2.SetLeftoff(80);

            //Set String Recycle Key
            Key1.SetRecycleKey(additionalKey);
            Key2.SetRecycleKey(additionalKey);

            //Expand the Keys
            Key1.ExpandKey((uint)expansion);
            Key2.ExpandKey(5);

            //Set SHA
            Key1.SetSHA(sha);
            Key2.SetSHA(sha);


            //Add randomness.
            Key2.SetSeedKey(Key2Random);


            //Recycle Key 2
            Key2.Recycle();

            //Stop Recycling Key 2
            //Key2.StopRecycling();


            //Add Key 1 Randomness

            if (encryptedKey1)
            {
                for (int i = 0; i < Key1Random.Length; i++)
                {
                    Key1Random[i] ^= Key2.GetRandomByte();
                }
            }
            this.Key1Random = Key1Random;
            Key1.SetSeedKey(Key1Random);

            //Recycle Key 1
            Key1.Recycle();

            //this.Key1 = new FilePseudoRandomGenerator(File.Open("Key1", FileMode.Create), Key1, additionalKey, Key1Random, sha, leftoff);
            this.Key1 = Key1;
        }
示例#2
0
        /// <summary>
        /// This is mainly used by the Basyl Writer.
        /// Creates a Basyl Key Generator from the arguments.
        /// </summary>
        /// <param name="pass"></param>
        /// <param name="initial"></param>
        /// <param name="rounds"></param>
        /// <param name="leftoff"></param>
        /// <param name="expansion"></param>
        /// <param name="additionalKey"></param>
        /// <param name="sha"></param>
        ///<param name="adaptor"></param>
        public BasylKeyGenerator(string pass, int initial, int rounds, int leftoff, int expansion, string additionalKey, byte[] sha, BasylPseudoAdaptor adaptor)
        {
            if (adaptor == null)
            {
                adaptor = new BasylPseudoAdaptor();
            }
            RNGCryptoServiceProvider random = new RNGCryptoServiceProvider();

            PseudoRandomGenerator Key1 = new PseudoRandomGenerator(initial, pass, rounds, adaptor);

            Key2 = new PseudoRandomGenerator(1024 * 40, pass, 400, adaptor);

            Key1Random = new byte[4];
            Key2Random = new byte[4];

            //Set the left off
            Key1.SetLeftoff(leftoff);
            Key2.SetLeftoff(80);


            //Set String Recycle Key
            Key1.SetRecycleKey(additionalKey);
            Key2.SetRecycleKey(additionalKey);

            //Expand the Keys
            Key1.ExpandKey((uint)expansion);
            Key2.ExpandKey(5);


            //Generate Randomness
            random.GetBytes(Key1Random);
            random.GetBytes(Key2Random);

            //Add randomness.
            Key1.SetSeedKey(Key1Random);
            Key2.SetSeedKey(Key2Random);

            //if sha exists
            if (sha != null)
            {
                this.sha = sha;
                //Set SHA
                Key1.SetSHA(sha);
                Key2.SetSHA(sha);
            }

            //Recycle the Keys
            Key1.Recycle();
            Key2.Recycle();

            //this.Key1 = new FilePseudoRandomGenerator(File.Open("Key1", FileMode.Create), Key1, additionalKey, Key1Random, sha, leftoff);
            this.Key1 = Key1;
        }
        /// <summary>
        /// This creates a Basyl Key Generator from the arguments..
        /// </summary>
        /// <param name="pass"></param>
        /// <param name="initial"></param>
        /// <param name="rounds"></param>
        /// <param name="leftoff"></param>
        /// <param name="expansion"></param>
        /// <param name="additionalKey"></param>
        /// <param name="sha"></param>
        /// <param name="Key1Random"></param>
        /// <param name="Key2Random"></param>
        /// <param name="encryptedKey1"></param>
        /// <param name="adaptor"></param>
        public BasylKeyGenerator(string pass, int initial, int rounds, int leftoff, int expansion, string additionalKey, byte[] sha, byte[] Key1Random, byte[] Key2Random, bool encryptedKey1, BasylPseudoAdaptor adaptor)
        {
            if (adaptor == null) adaptor = new BasylPseudoAdaptor();
            this.sha = sha;
            this.Key2Random = Key2Random;

            PseudoRandomGenerator Key1 = new PseudoRandomGenerator(initial, pass, rounds, adaptor);
            Key2 = new PseudoRandomGenerator(1024 * 40, pass, 400, adaptor);

            //Set the left off
            Key1.SetLeftoff(leftoff);
            Key2.SetLeftoff(80);

            //Set String Recycle Key
            Key1.SetRecycleKey(additionalKey);
            Key2.SetRecycleKey(additionalKey);

            //Expand the Keys
            Key1.ExpandKey((uint)expansion);
            Key2.ExpandKey(5);

            //Set SHA
            Key1.SetSHA(sha);
            Key2.SetSHA(sha);

            //Add randomness.
            Key2.SetSeedKey(Key2Random);

            //Recycle Key 2
            Key2.Recycle();

            //Stop Recycling Key 2
            //Key2.StopRecycling();

            //Add Key 1 Randomness

            if(encryptedKey1)
            for (int i = 0; i < Key1Random.Length; i++)
            {
                Key1Random[i] ^= Key2.GetRandomByte();
            }
            this.Key1Random = Key1Random;
            Key1.SetSeedKey(Key1Random);

            //Recycle Key 1
            Key1.Recycle();

            //this.Key1 = new FilePseudoRandomGenerator(File.Open("Key1", FileMode.Create), Key1, additionalKey, Key1Random, sha, leftoff);
            this.Key1 = Key1;
        }
        /// <summary>
        /// This is mainly used by the Basyl Writer.
        /// Creates a Basyl Key Generator from the arguments.
        /// </summary>
        /// <param name="pass"></param>
        /// <param name="initial"></param>
        /// <param name="rounds"></param>
        /// <param name="leftoff"></param>
        /// <param name="expansion"></param>
        /// <param name="additionalKey"></param>
        /// <param name="sha"></param>
        ///<param name="adaptor"></param>
        public BasylKeyGenerator(string pass, int initial, int rounds, int leftoff, int expansion, string additionalKey, byte[] sha, BasylPseudoAdaptor adaptor)
        {
            if (adaptor == null) adaptor = new BasylPseudoAdaptor();
            RNGCryptoServiceProvider random = new RNGCryptoServiceProvider();

            PseudoRandomGenerator Key1 = new PseudoRandomGenerator(initial, pass, rounds, adaptor);
            Key2 = new PseudoRandomGenerator(1024 * 40, pass, 400, adaptor);

            Key1Random = new byte[4];
            Key2Random = new byte[4];

            //Set the left off
            Key1.SetLeftoff(leftoff);
            Key2.SetLeftoff(80);

            //Set String Recycle Key
            Key1.SetRecycleKey(additionalKey);
            Key2.SetRecycleKey(additionalKey);

            //Expand the Keys
            Key1.ExpandKey((uint)expansion);
            Key2.ExpandKey(5);

            //Generate Randomness
            random.GetBytes(Key1Random);
            random.GetBytes(Key2Random);

            //Add randomness.
            Key1.SetSeedKey(Key1Random);
            Key2.SetSeedKey(Key2Random);

            //if sha exists
            if (sha != null)
            {
                this.sha = sha;
                //Set SHA
                Key1.SetSHA(sha);
                Key2.SetSHA(sha);
            }

            //Recycle the Keys
            Key1.Recycle();
            Key2.Recycle();

            //this.Key1 = new FilePseudoRandomGenerator(File.Open("Key1", FileMode.Create), Key1, additionalKey, Key1Random, sha, leftoff);
            this.Key1 = Key1;
        }