Ejemplo n.º 1
0
        public void init()
        {
            this.enc_mask = this.dec_mask = uint.MaxValue;
            DES_cblock key = new DES_cblock();

            key.init();
            DES_set_key(key, this.m_schedule);
        }
Ejemplo n.º 2
0
        public void ResetKey(byte[] key, byte index)
        {
            this.enc_mask = this.dec_mask = uint.MaxValue;
            DES_cblock _cblock = new DES_cblock();

            _cblock.reset(key, index);
            DES_set_key(_cblock, this.m_schedule);
        }
Ejemplo n.º 3
0
        public void DES_set_key(DES_cblock key, DES_key_schedule schedule)
        {
            int[] numArray = new int[] { 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0 };
            uint  l        = 0;
            uint  num2     = 0;
            uint  t        = 0;
            uint  num4     = 0;
            uint  a        = 0;

            func_c2l_first(key.arrBlock, ref l);
            func_c2l_second(key.arrBlock, ref num2);
            func_PERM_OP(ref num2, ref l, ref t, 4, 0xf0f0f0f);
            func_HPERM_OP(ref l, ref t, -2, 0xcccc0000);
            func_HPERM_OP(ref num2, ref t, -2, 0xcccc0000);
            func_PERM_OP(ref num2, ref l, ref t, 1, 0x55555555);
            func_PERM_OP(ref l, ref num2, ref t, 8, 0xff00ff);
            func_PERM_OP(ref num2, ref l, ref t, 1, 0x55555555);
            num2 = (uint)(((((num2 & 0xff) << 0x10) | (num2 & 0xff00)) | ((num2 & 0xff0000) >> 0x10)) | ((l & 0xf0000000) >> 4));
            l   &= 0xfffffff;
            for (int i = 0; i < 0x10L; i++)
            {
                if (numArray[i] > 0)
                {
                    l    = (l >> 2) | (l << 0x1a);
                    num2 = (num2 >> 2) | (num2 << 0x1a);
                }
                else
                {
                    l    = (l >> 1) | (l << 0x1b);
                    num2 = (num2 >> 1) | (num2 << 0x1b);
                }
                l    &= 0xfffffff;
                num2 &= 0xfffffff;
                num4  = ((des_skb[0, (int)((IntPtr)(l & 0x3f))] | des_skb[1, (int)((IntPtr)(((l >> 6) & 3) | ((l >> 7) & 60)))]) | des_skb[2, (int)((IntPtr)(((l >> 13) & 15) | ((l >> 14) & 0x30)))]) | des_skb[3, (int)((IntPtr)((((l >> 20) & 1) | ((l >> 0x15) & 6)) | ((l >> 0x16) & 0x38)))];
                t     = ((des_skb[4, (int)((IntPtr)(num2 & 0x3f))] | des_skb[5, (int)((IntPtr)(((num2 >> 7) & 3) | ((num2 >> 8) & 60)))]) | des_skb[6, (int)((IntPtr)((num2 >> 15) & 0x3f))]) | des_skb[7, (int)((IntPtr)(((num2 >> 0x15) & 15) | ((num2 >> 0x16) & 0x30)))];
                a     = ((t << 0x10) | (num4 & 0xffff)) & uint.MaxValue;
                schedule.arrKeys[2 * i] = func_ROTATE(ref a, 30) & uint.MaxValue;
                a = (num4 >> 0x10) | (t & 0xffff0000);
                schedule.arrKeys[(2 * i) + 1] = func_ROTATE(ref a, 0x1a) & uint.MaxValue;
            }
        }