Beispiel #1
0
        public SessionConnectionData(ConnectionType type)
        {
            IssacClient = new ISAAC(type == ConnectionType.Login ? ISAAC.ClientSeed : ISAAC.WorldClientSeed);
            IssacServer = new ISAAC(type == ConnectionType.Login ? ISAAC.ServerSeed : ISAAC.WorldServerSeed);

            ServerTime = WorldManager.PortalYearTicks;
        }
Beispiel #2
0
        public SessionConnectionData()
        {
            IssacClient = new ISAAC(ISAAC.ClientSeed);
            IssacServer = new ISAAC(ISAAC.ServerSeed);

            ServerTime = WorldManager.PortalYearTicks;
        }
Beispiel #3
0
        public Card pullCard(int cardset = 0)
        {
            if (cc == noOfCards)//noOfPlayers * handSize)//)
            {
                cc       = 0;
                rndmflag = false;
            }
            var seed   = new byte[256];
            var crypto = new System.Security.Cryptography.RNGCryptoServiceProvider();

            crypto.GetBytes(seed);
            //RummyHand.crypto.GetBytes(RummyHand.seed);
            // now initialize our ISAAC with the seed
            var random = new ISAAC(seed);
            // get random card (from a deck of 52 cards)
            int randomCard = random.Random(noOfCards);

            //return d[cc++];

            switch (cardset)
            {
            case 0:

                while (randomvalues.Contains(randomCard))
                {
                    if (randomCard == 0 && rndmflag == false)
                    {
                        rndmflag = true;
                        break;
                    }
                    else
                    {
                        randomCard = random.Random(noOfCards);
                    }
                }
                randomvalues[cc] = randomCard;
                break;
            }
            cc++;
            return(d[randomCard]);
        }
Beispiel #4
0
        public SessionConnectionData()
        {
            // since the network processor is single threaded this can instantiate the .NET Core System.Random class without locking
            Random rand = new Random();

            // the client and server seeds determine where on the 32 bit wheel the stream cipher begins
            // by picking a random initialization vector it makes it more difficult for an adversary to forge packets
            ClientSeed = new byte[4];
            ServerSeed = new byte[4];

            rand.NextBytes(ClientSeed);
            rand.NextBytes(ServerSeed);

            CryptoClient = new CryptoSystem(ClientSeed);
            IssacServer  = new ISAAC(ServerSeed);

            byte[] bytes = new byte[8];
            rand.NextBytes(bytes);
            ConnectionCookie = BitConverter.ToUInt64(bytes, 0);

            PacketSequence = new UIntSequence(false);
        }
Beispiel #5
0
 public SessionConnectionData(ConnectionType type)
 {
     IssacClient = new ISAAC(type == ConnectionType.Login ? ISAAC.ClientSeed : ISAAC.WorldClientSeed);
     IssacServer = new ISAAC(type == ConnectionType.Login ? ISAAC.ServerSeed : ISAAC.WorldServerSeed);
 }
Beispiel #6
0
        public override byte[] ExtractData()
        {
            string pass = base.password;

            if (pass != null && pass.Length > 0)
            {
                csprng = SteganographyProvider.PrepareISAAC(Encoding.UTF8.GetBytes(pass));
            }

            byte[] len  = new byte[4];
            int    temp = 0;
            int    j    = 0;

            for (int i = 0; i < 4; i++)
            {
                len[i] |= (byte)(BitmapData[j] & 3);
                IterateChannel(ref temp, ref j);

                len[i] |= (byte)((BitmapData[j] & 3) << 2);
                IterateChannel(ref temp, ref j);

                len[i] |= (byte)((BitmapData[j] & 3) << 4);
                IterateChannel(ref temp, ref j);

                len[i] |= (byte)((BitmapData[j] & 3) << 6);
                IterateChannel(ref temp, ref j);
            }

            int isaac = 0;

            if (csprng != null)
            {
                for (int k = 0; k < len.Length; k++, isaac++)
                {
                    len[k] = (byte)(len[k] ^ csprng.rsl[isaac]);
                }
            }

            int ilen = BitConverter.ToInt32(len, 0);

            ulong maxsize = (ulong)Math.Floor(((double)BitmapDimensions.Width * (double)BitmapDimensions.Height * 3d * 2d) / 8d);

            if (ilen < 1 || (ulong)ilen > maxsize)
            {
                throw new InvalidPasswordException();
            }

            byte[] data = new byte[ilen];

            for (int i = 0; i < ilen && j < BitmapData.Length; i++)
            {
                data[i] |= (byte)(BitmapData[j] & 3);
                IterateChannel(ref temp, ref j);

                data[i] |= (byte)((BitmapData[j] & 3) << 2);
                IterateChannel(ref temp, ref j);

                data[i] |= (byte)((BitmapData[j] & 3) << 4);
                IterateChannel(ref temp, ref j);

                data[i] |= (byte)((BitmapData[j] & 3) << 6);
                IterateChannel(ref temp, ref j);
            }

            if (csprng != null)
            {
                for (int i = 0; i < data.Length; i++, isaac++)
                {
                    if (isaac >= ISAAC.SIZE)
                    {
                        isaac = 0;
                        csprng.Isaac();
                    }

                    data[i] = (byte)(data[i] ^ csprng.rsl[isaac]);
                }
            }

            return(data);
        }
Beispiel #7
0
        public override void ImprintData(byte[] data)
        {
            string pass = base.password;

            if (pass != null && pass.Length > 0)
            {
                csprng = SteganographyProvider.PrepareISAAC(Encoding.UTF8.GetBytes(pass));
            }

            ulong maxsize = (ulong)Math.Floor(((double)BitmapDimensions.Width * (double)BitmapDimensions.Height * 3d * 2d) / 8d);

            if ((ulong)data.LongLength + 4 > maxsize)
            {
                throw new NotEnoughSpaceException("Not enough space for graphical injection, maximum data size for this image is " + (int)Math.Floor(maxsize / 1024d) + "KB");
            }

            List <byte> tdata = new List <byte>(data);

            byte[] len = BitConverter.GetBytes(data.Length);
            tdata.InsertRange(0, len);
            data  = tdata.ToArray();
            tdata = null;

            if (csprng != null)
            {
                for (int i = 0, isaac = 0; i < data.Length; i++, isaac++)
                {
                    if (isaac >= ISAAC.SIZE)
                    {
                        isaac = 0;
                        csprng.Isaac();
                    }

                    data[i] = (byte)(data[i] ^ csprng.rsl[isaac]);
                }
            }

            int temp = 0;

            for (int i = 0, j = 0; i < data.Length && j < BitmapData.Length; i++)
            {
                byte mask1 = (byte)(data[i] & 3);
                byte mask2 = (byte)((data[i] & 12) >> 2);
                byte mask3 = (byte)((data[i] & 48) >> 4);
                byte mask4 = (byte)((data[i] & 192) >> 6);

                BitmapData[j] &= 252;
                BitmapData[j] |= mask1;
                IterateChannel(ref temp, ref j);

                BitmapData[j] &= 252;
                BitmapData[j] |= mask2;
                IterateChannel(ref temp, ref j);

                BitmapData[j] &= 252;
                BitmapData[j] |= mask3;
                IterateChannel(ref temp, ref j);

                BitmapData[j] &= 252;
                BitmapData[j] |= mask4;
                IterateChannel(ref temp, ref j);
            }
        }
        public static MemoryStream ReadEntry(
            Stream input,
            ArchiveFile.Entry entry,
            ArchiveCompressionMode mode,
            Endian endian)
        {
            switch (mode)
            {
            case ArchiveCompressionMode.Bogocrypt1:
            {
                var  output    = new MemoryStream();
                var  key       = entry.BogocryptKey;
                long remaining = entry.Length;
                var  block     = new byte[1024];
                while (remaining > 0)
                {
                    var blockLength       = (int)Math.Min(block.Length, remaining + 3 & ~3);
                    var actualBlockLength = (int)Math.Min(block.Length, remaining);
                    if (blockLength == 0)
                    {
                        throw new InvalidOperationException();
                    }

                    if (input.Read(block, 0, blockLength) < actualBlockLength)
                    {
                        throw new EndOfStreamException();
                    }

                    key = ArchiveFile.Bogocrypt1(block, 0, blockLength, key);

                    output.Write(block, 0, actualBlockLength);
                    remaining -= blockLength;
                }
                output.Position = 0;
                return(output);
            }

            case ArchiveCompressionMode.LZW:
            {
                var output = new MemoryStream();
                LZW.Decompress(input, entry.Length, output, endian);
                output.Position = 0;
                return(output);
            }

            case ArchiveCompressionMode.MiniZ:
            {
                ISAAC isaac        = null;
                var   outputBytes  = new byte[entry.Length];
                var   outputOffset = 0;
                var   blockBytes   = new byte[0x800];
                long  remaining    = entry.Length;

                bool isCompressed = true;
                bool isLastBlock;
                do
                {
                    var blockFlags  = input.ReadValueU32(endian);
                    var blockLength = (int)(blockFlags & ~0x80000000u);
                    isLastBlock = (blockFlags & 0x80000000u) != 0;

                    if (blockLength > blockBytes.Length)
                    {
                        throw new InvalidOperationException();
                    }

                    if (input.Read(blockBytes, 0, blockLength) != blockLength)
                    {
                        throw new EndOfStreamException();
                    }

                    if (isCompressed == false || (isLastBlock == false && blockLength == 1024))
                    {
                        isCompressed = false;
                        if (isaac == null)
                        {
                            isaac = entry.GetISAAC();
                        }

                        int seed = 0;
                        for (int o = 0; o < blockLength; o++)
                        {
                            if ((o & 3) != 0)
                            {
                                seed >>= 8;
                            }
                            else
                            {
                                seed = isaac.Value();
                            }

                            blockBytes[o] ^= (byte)seed;
                        }

                        Array.Copy(blockBytes, 0, outputBytes, outputOffset, blockLength);

                        outputOffset += blockLength;
                        remaining    -= blockLength;
                    }
                    else
                    {
                        using (var temp = new MemoryStream(blockBytes, false))
                        {
                            var zlib = new InflaterInputStream(temp, new Inflater(true));
                            var read = zlib.Read(outputBytes, outputOffset, (int)Math.Min(remaining, 1024));
                            outputOffset += read;
                            remaining    -= read;
                        }
                    }
                }while (isLastBlock == false);

                return(new MemoryStream(outputBytes));
            }

            case ArchiveCompressionMode.Bogocrypt2:
            {
                var blockBytes = new byte[1024];

                var  output    = new MemoryStream();
                long remaining = entry.Length;
                while (remaining >= 4)
                {
                    var blockLength = (int)Math.Min(blockBytes.Length, remaining);
                    if (input.Read(blockBytes, 0, blockLength) != blockLength)
                    {
                        throw new EndOfStreamException();
                    }

                    ArchiveFile.Bogocrypt2(blockBytes, 0, blockLength);
                    output.Write(blockBytes, 0, blockLength);
                    remaining -= blockLength;
                }

                if (remaining > 0)
                {
                    output.WriteFromStream(input, remaining);
                }

                output.Position = 0;
                return(output);
            }

            default:
            {
                throw new NotSupportedException();
            }
            }
        }
Beispiel #9
0
 public SessionConnectionData()
 {
     IssacClient    = new ISAAC(ISAAC.ClientSeed);
     IssacServer    = new ISAAC(ISAAC.ServerSeed);
     PacketSequence = new UIntSequence(false);
 }
Beispiel #10
0
        public override byte[] ExtractData()
        {
            string pass = SteganographyProvider.AskPassword();
            if (pass != null && pass.Length > 0)
                csprng = SteganographyProvider.PrepareISAAC(Encoding.UTF8.GetBytes(pass));

            byte[] len = new byte[4];
            int temp = 0;
            int j = 0;
            for (int i = 0; i < 4; i++)
            {
                len[i] |= (byte)(BitmapData[j] & 3);
                IterateChannel(ref temp, ref j);

                len[i] |= (byte)((BitmapData[j] & 3) << 2);
                IterateChannel(ref temp, ref j);

                len[i] |= (byte)((BitmapData[j] & 3) << 4);
                IterateChannel(ref temp, ref j);

                len[i] |= (byte)((BitmapData[j] & 3) << 6);
                IterateChannel(ref temp, ref j);
            }

            int isaac = 0;
            if(csprng != null)
                for (int k = 0; k < len.Length; k++, isaac++)
                    len[k] = (byte)(len[k] ^ csprng.rsl[isaac]);

            int ilen = BitConverter.ToInt32(len, 0);

            ulong maxsize = (ulong)Math.Floor(((double)BitmapDimensions.Width * (double)BitmapDimensions.Height * 3d * 2d) / 8d);
            if (ilen < 1 || (ulong)ilen > maxsize) throw new InvalidPasswordException();

            byte[] data = new byte[ilen];

            for (int i = 0; i < ilen && j < BitmapData.Length; i++)
            {
                data[i] |= (byte)(BitmapData[j] & 3);
                IterateChannel(ref temp, ref j);

                data[i] |= (byte)((BitmapData[j] & 3) << 2);
                IterateChannel(ref temp, ref j);

                data[i] |= (byte)((BitmapData[j] & 3) << 4);
                IterateChannel(ref temp, ref j);

                data[i] |= (byte)((BitmapData[j] & 3) << 6);
                IterateChannel(ref temp, ref j);
            }

            if (csprng != null)
                for (int i = 0; i < data.Length; i++, isaac++)
                {
                    if (isaac >= ISAAC.SIZE)
                    {
                        isaac = 0;
                        csprng.Isaac();
                    }

                    data[i] = (byte)(data[i] ^ csprng.rsl[isaac]);
                }

            return data;
        }
Beispiel #11
0
        public override void ImprintData(byte[] data)
        {
            string pass = SteganographyProvider.AskPassword();
            if (pass != null && pass.Length > 0)
                csprng = SteganographyProvider.PrepareISAAC(Encoding.UTF8.GetBytes(pass));

            ulong maxsize = (ulong)Math.Floor(((double)BitmapDimensions.Width * (double)BitmapDimensions.Height * 3d * 2d) / 8d);
            if ((ulong)data.LongLength + 4 > maxsize) throw new NotEnoughSpaceException("Not enough space for graphical injection, maximum data size for this image is " + (int)Math.Floor(maxsize / 1024d) + "KB");

            List<byte> tdata = new List<byte>(data);
            byte[] len = BitConverter.GetBytes(data.Length);
            tdata.InsertRange(0, len);
            data = tdata.ToArray();
            tdata = null;

            if(csprng != null)
                for (int i = 0, isaac = 0; i < data.Length; i++, isaac++)
                {
                    if (isaac >= ISAAC.SIZE)
                    {
                        isaac = 0;
                        csprng.Isaac();
                    }

                    data[i] = (byte)(data[i] ^ csprng.rsl[isaac]);
                }

            int temp = 0;
            for (int i = 0, j = 0; i < data.Length && j < BitmapData.Length; i++)
            {
                byte mask1 = (byte)(data[i] & 3);
                byte mask2 = (byte)((data[i] & 12) >> 2);
                byte mask3 = (byte)((data[i] & 48) >> 4);
                byte mask4 = (byte)((data[i] & 192) >> 6);

                BitmapData[j] &= 252;
                BitmapData[j] |= mask1;
                IterateChannel(ref temp, ref j);

                BitmapData[j] &= 252;
                BitmapData[j] |= mask2;
                IterateChannel(ref temp, ref j);

                BitmapData[j] &= 252;
                BitmapData[j] |= mask3;
                IterateChannel(ref temp, ref j);

                BitmapData[j] &= 252;
                BitmapData[j] |= mask4;
                IterateChannel(ref temp, ref j);
            }
        }