Esempio n. 1
0
        public byte[] Decrypt(byte[] cw, byte[] data, int len)
        {
            // bypassed bitwise operation, not sure if it works
            // it seems to set alen to length from start of packet to end of last 8 byte block, leaving residue untouched
            // can probably do it in a more .NET way
            //uint alen = len & unchecked((uint)~0x7);

            int alen = len;  //TODO: implement length checking, this is only good for 184 byte packets (or multiples of 8 bytes)

            CSAKeyStruct ks = new CSAKeyStruct(cw);

            int i;

            if (len < 8)
            {
                return(data);
            }

            // perform stream decipher

            if (_enableStream)
            {
                // dvbcsa_stream_xor(key->cws, data, data + 8, len - 8);
            }

            // perform block decipher

            if (_enableBlock)
            {
                CSABlockDecryptor enc = new CSABlockDecryptor(ks, data, len);

                enc.CSABlockDecrypt(0);

                for (i = 8; i < 183; i += 8) // this needs a look
                {
                    enc.CSAXor64(i);
                    enc.CSABlockDecrypt(i);
                }
            }

            return(data);
        }
        public byte[] Decrypt(byte[] cw, byte[] data, int len)
        {
            // bypassed bitwise operation, not sure if it works
            // it seems to set alen to length from start of packet to end of last 8 byte block, leaving residue untouched
            // can probably do it in a more .NET way
            //uint alen = len & unchecked((uint)~0x7);

            int alen = len;  //TODO: implement length checking, this is only good for 184 byte packets (or multiples of 8 bytes)

            CSAKeyStruct ks = new CSAKeyStruct(cw);

            int i;

            if (len < 8)
                return data;

            // perform stream decipher

            if (_enableStream)
            {
                // dvbcsa_stream_xor(key->cws, data, data + 8, len - 8);
            }

            // perform block decipher

            if (_enableBlock)
            {
                CSABlockDecryptor enc = new CSABlockDecryptor(ks, data, len);

                enc.CSABlockDecrypt(0);

                for (i = 8; i < 183; i += 8) // this needs a look
                {
                    enc.CSAXor64(i);
                    enc.CSABlockDecrypt(i);
                }
            }

            return data;
        }