Пример #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);
        }
Пример #2
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);
            }