public FileMutatedBKG(BasylKeyGenerator keyGen, Stream stream)
        {
            this.generator = keyGen;
            this.cipher = new BESCipher(keyGen);

            byte[] extra = new byte[100];
            byte[] extra2 = new byte[64];

            int amount = 65536;
            while (amount != 0)
            {
                byte[] buffer = new byte[amount];
                while (stream.Position + amount < stream.Length)
                {
                    stream.Read(buffer, 0, amount);
                    cipher.EncryptRight(ref buffer);
                    cipher.EncryptLeft(ref extra);
                    cipher.EncryptRight(ref extra2);
                }
                cipher.EncryptLeft(ref extra2);
                cipher.Shuffle(2);
                amount /= 2;
            }

            prg = new PseudoRandomGenerator(256 * 256, "MutatedBKG", 500);
            prg.ExpandKey(1);
            prg.SetSeedKey(extra);
            prg.SetSHA(extra2);
            prg.Recycle();

            stream.Close();
        }
Example #2
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;
        }
Example #3
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;
        }
        public static byte[] BasylHashUno(Stream stream, string pass, int hashSize, int keySize, int rounds, int skipOver, string additionalPass)
        {
            PseudoRandomGenerator prng = new PseudoRandomGenerator(keySize, pass, rounds);

            prng.SetRecycleKey(additionalPass);

            BESCipher cipher = new BESCipher(new BasylWeakKeyGenerator(prng));

            prng.Recycle();

            byte[] buff = new byte[65536];
            while (stream.Position + 65536 < stream.Length)
            {
                stream.Read(buff, 0, 65536);
                cipher.EncryptLeft(ref buff);
            }

            int x = stream.ReadByte();

            while (x != -1)
            {
                byte z = (byte)x;
                cipher.EncryptLeft(ref z);
                x = stream.ReadByte();
            }


            for (int i = 0; i < skipOver; i++)
            {
                prng.GetRandomInt();
            }

            int max = prng.GetRandomByte() * prng.GetRandomByte() + prng.GetRandomByte();

            for (int i = 0; i < max; i++)
            {
                prng.GetRandomInt();
            }

            byte[] BHU = new byte[hashSize];
            prng.FillBytes(BHU);

            for (int i = 0; i < hashSize; i++)
            {
                BHU[i] ^= prng.GetRandomByte();
                cipher.EncryptRight(ref BHU);
            }

            return(BHU);
        }
        public static byte[] BasylHashUno(String str, string pass, int hashSize, int keySize, int rounds, int skipOver, string additionalPass)
        {
            PseudoRandomGenerator prng = new PseudoRandomGenerator(keySize, pass, rounds);

            prng.SetRecycleKey(additionalPass);

            IBasylKeyGenerator wk     = new BasylWeakKeyGenerator(prng);
            BESCipher          cipher = new BESCipher(wk);

            prng.Recycle();

            foreach (char n in str)
            {
                byte q = (byte)n;
                cipher.EncryptLeft(ref q);
            }


            for (int i = 0; i < skipOver; i++)
            {
                for (int x = 0; x < 4; x++)
                {
                    prng.GetRandomByte();
                }
            }

            int max = prng.GetRandomByte() * prng.GetRandomByte() + prng.GetRandomByte();

            for (int i = 0; i < max; i++)
            {
                for (int x = 0; x < 4; x++)
                {
                    prng.GetRandomByte();
                }
            }

            byte[] BHU = new byte[hashSize];
            wk.FillBytes(BHU, 0, BHU.Length);

            for (int i = 0; i < hashSize; i++)
            {
                BHU[i] ^= prng.GetRandomByte();
                cipher.EncryptRight(ref BHU);
            }

            return(BHU);
        }
        public static byte[] BasylHashUno(Stream stream, string pass, int hashSize, int keySize, int rounds, int skipOver, string additionalPass)
        {
            PseudoRandomGenerator prng = new PseudoRandomGenerator(keySize, pass, rounds);
            prng.SetRecycleKey(additionalPass);

            BESCipher cipher = new BESCipher(new BasylWeakKeyGenerator(prng));
            prng.Recycle();

            byte[] buff = new byte[65536];
            while(stream.Position + 65536 < stream.Length)
            {
                stream.Read(buff, 0, 65536);
                cipher.EncryptLeft(ref buff);
            }

            int x = stream.ReadByte();
            while(x != -1)
            {
                byte z = (byte)x;
                cipher.EncryptLeft(ref z);
                x = stream.ReadByte();
            }

            for(int i = 0; i < skipOver; i++)
            {
                prng.GetRandomInt();
            }

            int max  =  prng.GetRandomByte() * prng.GetRandomByte() + prng.GetRandomByte();
            for (int i = 0; i < max; i++)
            {
                prng.GetRandomInt();
            }

            byte[] BHU = new byte[hashSize];
            prng.FillBytes(BHU);

            for (int i = 0; i < hashSize; i++)
            {
                BHU[i] ^= prng.GetRandomByte();
                cipher.EncryptRight(ref BHU);
            }

            return BHU;
        }
        public static byte[] BasylHashUno(String str, string pass, int hashSize, int keySize, int rounds, int skipOver, string additionalPass)
        {
            PseudoRandomGenerator prng = new PseudoRandomGenerator(keySize, pass, rounds);
            prng.SetRecycleKey(additionalPass);

            IBasylKeyGenerator wk = new BasylWeakKeyGenerator(prng);
            BESCipher cipher = new BESCipher(wk);
            prng.Recycle();

            foreach(char n in str)
            {
                byte q = (byte)n;
                cipher.EncryptLeft(ref q);
            }

            for (int i = 0; i < skipOver; i++)
            {
                for (int x = 0; x < 4; x++ )
                    prng.GetRandomByte();
            }

            int max = prng.GetRandomByte() * prng.GetRandomByte() + prng.GetRandomByte();
            for (int i = 0; i < max; i++)
            {
                for (int x = 0; x < 4; x++)
                    prng.GetRandomByte();
            }

            byte[] BHU = new byte[hashSize];
            wk.FillBytes(BHU, 0, BHU.Length);

            for (int i = 0; i < hashSize; i++)
            {
                BHU[i] ^= prng.GetRandomByte();
                cipher.EncryptRight(ref BHU);
            }

            return BHU;
        }
Example #8
0
 /// <summary>
 /// Forces the Writer to recycle the keys.
 /// </summary>
 public void ForceRecycle()
 {
     Key1.Recycle();
     Key2.Recycle();
 }
        /// <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;
        }