Esempio n. 1
0
        public override void SetParameter(Octets param)
        {
            Octets k_ipad = new Octets(64);
            int keylen = param.size();

            if (keylen > 64)
            {
                Octets key = MD5Hash.Digest(param);
                k_ipad.replace(key);
                k_opad.replace(key);
                keylen = key.size();
            }
            else
            {
                k_ipad.replace(param);
                k_opad.replace(param);
            }

            int i = 0;
            for (; i < keylen; i++)
            {
                k_ipad.setByte(i, (byte)(k_ipad.getByte(i) ^ 0x36));
                k_opad.setByte(i, (byte)(k_opad.getByte(i) ^ 0x5c));
            }
            for (; i < 64; i++)
            {
                k_ipad.setByte(i, (byte)0x36);
                k_opad.setByte(i, (byte)0x5c);
            }
            k_ipad.resize(64);
            k_opad.resize(64);            
            md5hash.Update(k_ipad);
        }
Esempio n. 2
0
	    internal bool Output(Octets data)
	    {
		    if (data.size() + obuffer.size() > obuffer.capacity())
                return false;
            osec.Update(data);
		    obuffer.insert(obuffer.size(), data);
		    return true;
	    }
Esempio n. 3
0
 public override Octets Update(Octets o)
 {
     int len = o.size();
     for (int i = 0; i < len; i++)
     {
         index2 += perm[(++index1) & 0xff];
         byte k = perm[index1 & 0xff]; perm[index1 & 0xff] = perm[index2 & 0xff]; perm[index2 & 0xff] = k;
         byte j = (byte)(perm[index1 & 0xff] + perm[index2 & 0xff]);
         o.setByte(i, (byte)(o.getByte(i) ^ perm[j & 0xff]));
     }
     return o;
 }
Esempio n. 4
0
 public override void SetParameter(Octets o)
 {
     int keylen = o.size();
     byte j = 0;
     for (int i = 0; i < 256; i++) perm[i] = (byte)i;
     for (int i = 0; i < 256; i++)
     {
         j += perm[i];
         j += o.getByte(i % keylen);
         byte k; k = perm[i]; perm[i] = perm[j & 0xff]; perm[j & 0xff] = k;
     }
     index1 = index2 = 0;
 }
Esempio n. 5
0
 public OctetsStream marshal(Octets o)
 {
     compact_sint32(o.size());
     insert(size(), o);
     return this;
 }
Esempio n. 6
0
            internal Octets Final(Octets oin)
            {
                if (oin.size() == 0 && legacy_in == 0)
                    return oin;

                Octets oout = Update(oin);
                int osize = oout.size();
                oout.reserve(osize + (int)legacy_in * 9 / 8 + 6);
                byte[] obuf = oout.buffer();
                uint opos = (uint)osize;
                compress_block(obuf, ref opos, legacy_in);
                oout.resize((int)opos);
                return oin.swap(oout);
            }
Esempio n. 7
0
            internal Octets Update(Octets oin)
            {
                Octets oout = new Octets();
                uint ipos = 0, opos = 0;
                byte[] ibuf = oin.buffer();
                uint isize = (uint)oin.size();
                uint remain = (uint)MPPC.MPPC_HIST_LEN - histptr - legacy_in;

                if (isize >= remain)
                {
                    oout.resize((int)(isize + legacy_in) * 9 / 8 + 6);
                    byte[] obuf = oout.buffer();
                    Array.Copy(ibuf, ipos, history, histptr + legacy_in, remain);
                    isize -= remain;
                    ipos += remain;
                    compress_block(obuf, ref opos, remain + legacy_in);
                    histptr = 0;

                    for (; isize >= (uint)MPPC.MPPC_HIST_LEN;
                        isize -= (uint)MPPC.MPPC_HIST_LEN, ipos += (uint)MPPC.MPPC_HIST_LEN)
                    {
                        Array.Copy(ibuf, ipos, history, histptr, (int)MPPC.MPPC_HIST_LEN);
                        compress_block(obuf, ref opos, (uint)MPPC.MPPC_HIST_LEN);
                        histptr = 0;
                    }
                    oout.resize((int)opos);
                }

                Array.Copy(ibuf, ipos, history, histptr + legacy_in, isize);
                legacy_in += isize;
                return oin.swap(oout);
            }
Esempio n. 8
0
File: Octets.cs Progetto: fengqk/Art
 public Octets insert(int from, Octets data)
 {
     return insert(from, data._buffer, 0, data.size());
 }
Esempio n. 9
0
        public static Command DecodeCommand(Octets content)
        {
            MemoryStream ms = new MemoryStream(content.buffer());
            BinaryReader br = new BinaryReader(ms);
            short type = 0;
            Command cmd = null;

            try
            {
                type = br.ReadInt16();
                cmd = CommandList.CreateS2CCommand(type);
                if (cmd == null)
                {
                    Debug.Log(string.Format("Command instance not found, type: {0}", (S2C.S2C_COMMAND)type));
                    return null;
                }

                cmd.ReceivedSize = content.size();
                cmd.unmarshal(br);
                if (br.BaseStream.Position != content.size())
                {
                    Debug.LogWarning(string.Format("Command decode BufferLength don't match, type: {0}", (S2C.S2C_COMMAND)type));

                }
            }
            catch (System.Exception)
            {
                Debug.LogWarning(string.Format("Command decode error, type: {0}", (S2C.S2C_COMMAND)type));
                cmd = null;
            }

            return cmd;
        }