Esempio n. 1
0
        /// <summary>
        /// Validates MAC
        /// </summary>
        /// <param name="outBuf"></param>
        /// <param name="vkey"></param>
        /// <returns>0, if MAC is valid</returns>
        private long Final(byte[] outBuf, byte[] vkey)
        {
            var tmp = new byte[0x10];

            var type = _mac_type;
            var res  = PrivateFinal(tmp, vkey);

            if (res != 0)
            {
                return(res);
            }

            //decrypt bbmac
            if (type == 3)
            {
                Array.Copy(outBuf, 0, _kirk_buf, 0x14, 0x10);
                Kirk.DecryptWith0(_kirk_buf, 0x10, 0x63);
            }
            else
            {
                Array.Copy(outBuf, 0, _kirk_buf, 0, 0x10);
            }

            for (int i = 0; i < 0x10; i++)
            {
                if (_kirk_buf[i] != tmp[i])
                {
                    return(0x80510300);
                }
            }

            return(0);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets MAC Key from MAC and range of bytes
        /// </summary>
        /// <param name="bbmac"></param>
        /// <returns></returns>
        public byte[] GetKey(byte[] range, byte[] bbmac)
        {
            var result = Update(range, range.Length);

            if (result != 0)
            {
                return(null);
            }

            var tmp  = new byte[0x10];
            var tmp1 = new byte[0x10];

            var type = _mac_type;
            var res  = PrivateFinal(tmp, null);

            if (res != 0)
            {
                return(null);
            }

            //decrypt bbmac
            if (type == 3)
            {
                Array.Copy(bbmac, 0, _kirk_buf, 0x14, 0x10);
                Kirk.DecryptWith0(_kirk_buf, 0x10, 0x63);
            }
            else
            {
                Array.Copy(bbmac, 0, _kirk_buf, 0, 0x10);
            }

            Array.Copy(_kirk_buf, 0, tmp1, 0, 0x10);
            Array.Copy(tmp1, 0, _kirk_buf, 0x14, 0x10);

            var code = type == 2 ? 0x3A : 0x38;

            Kirk.DecryptWith0(_kirk_buf, 0x10, code);

            var vkey = new byte[0x10];

            for (int i = 0; i < 0x10; i++)
            {
                vkey[i] = (byte)(tmp[i] ^ _kirk_buf[i]);
            }

            return(vkey);
        }