예제 #1
0
        /// <summary>
        /// Generate the Bytes.
        /// </summary>
        public void Generate()
        {
            while (!ended)
            {
                if (!yield)
                {
                    lock (randomBytes)
                    {
                        if (!ended)
                        {
                            while (randomBytes.Count < queue_size && !ended)
                            {
                                randomBytes.Enqueue((byte)(Key1.GetRandomByte() ^ Key2.GetRandomByte()));
                                if (yield)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }

                if (yield)
                {
                    Thread.Sleep(1000);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Get Encrypted Key 1.
        /// Only works first time.
        /// </summary>
        /// <returns></returns>
        public byte[] GetEncryptedKey1Random()
        {
            byte[] a = (byte[])Key1Random.Clone();

            for (int i = 0; i < a.Length; i++)
            {
                a[i] ^= Key2.GetRandomByte();
            }

            return(a);
        }
        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);
        }
예제 #4
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;
        }
        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(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;
        }
        /// <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;
        }