Example #1
0
        private bool checkNPDHash2(byte[] klicensee, byte[] npd)
        {
            byte[] xoredKey = new byte[0x10];
            ToolsImpl.XOR(xoredKey, klicensee, EDATKeys.npdrm_omac_key2);
            byte[] calculated = ToolsImpl.CMAC128(xoredKey, npd, 0, 0x60);
            bool   result2    = compareBytes(calculated, 0, npd, 0x60, 0x10);

            if (result2)
            {
                Console.WriteLine("NPD hash 2 is valid (" + ConversionUtils.getHexString(calculated) + ")");
            }
            return(result2);
        }
Example #2
0
        private bool checkNPDHash2(byte[] klicensee, byte[] npd)
        {
            byte[] output = new byte[0x10];
            ToolsImpl.XOR(output, klicensee, EDATKeys.npdrm_omac_key2);
            byte[] buffer2 = ToolsImpl.CMAC128(output, npd, 0, 0x60);
            bool   flag    = this.compareBytes(buffer2, 0, npd, 0x60, 0x10);

            if (flag)
            {
                Console.WriteLine("NPD hash 2 is valid (" + ConversionUtils.getHexString(buffer2) + ")");
            }
            return(flag);
        }
Example #3
0
        /* KDSBEST END */

        public int decryptFile(String inFile, String outFile, byte[] devKLic, byte[] keyFromRif)
        {
            FileStream fin = File.Open(inFile, FileMode.Open);

            string[] fn = fin.Name.Split('\\');
            //string[] fn = fin.Name.Split('/');
            Console.WriteLine(fn[fn.Length - 1]);

            NPD[] ptr    = new NPD[1];                                        //Ptr to Ptr
            int   result = validateNPD(fn[fn.Length - 1], devKLic, ptr, fin); //Validate NPD hashes

            if (result < 0)
            {
                fin.Close();
                return(result);
            }
            NPD      npd  = ptr[0];
            EDATData data = getEDATData(fin);                       //Get flags, blocksize and file len

            byte[] rifkey = getKey(npd, data, devKLic, keyFromRif); //Obtain the key for decryption (result of sc471 or sdatkey)
            if (rifkey == null)
            {
                Console.WriteLine("ERROR: Key for decryption is missing");
                fin.Close();
                return(STATUS_ERROR_MISSINGKEY);
            }
            else
            {
                Console.WriteLine("DECRYPTION KEY: " + ConversionUtils.getHexString(rifkey));
            }
            result = checkHeader(rifkey, data, npd, fin);
            if (result < 0)
            {
                fin.Close();
                return(result);
            }
            FileStream o = File.Open(outFile, FileMode.Create);

            result = decryptData(fin, o, npd, data, rifkey);
            if (result < 0)
            {
                fin.Close();
                return(result);
            }
            fin.Close();
            o.Close();
            Console.WriteLine("COMPLETE: File Written to disk");
            return(STATUS_OK);
        }
Example #4
0
 public void doInit(int hashFlag, int cryptoFlag, byte[] key, byte[] iv, byte[] hashKey)
 {
     byte[] calculatedKey  = new byte[key.Length];
     byte[] calculatedIV   = new byte[iv.Length];
     byte[] calculatedHash = new byte[hashKey.Length];
     this.getCryptoKeys(cryptoFlag, calculatedKey, calculatedIV, key, iv);
     this.getHashKeys(hashFlag, calculatedHash, hashKey);
     this.setDecryptor(cryptoFlag);
     this.setHash(hashFlag);
     Debug.WriteLine("ERK:  " + ConversionUtils.getHexString(calculatedKey));
     Debug.WriteLine("IV:   " + ConversionUtils.getHexString(calculatedIV));
     Debug.WriteLine("HASH: " + ConversionUtils.getHexString(calculatedHash));
     this.dec.doInit(calculatedKey, calculatedIV);
     this.hash.doInit(calculatedHash);
 }
Example #5
0
        private bool checkNPDHash1(String filename, byte[] npd)
        {
            byte[] fileBytes = ConversionUtils.charsToByte(filename.ToCharArray());
            byte[] data1     = new byte[0x30 + fileBytes.Length];
            ConversionUtils.arraycopy(npd, 0x10, data1, 0, 0x30);
            ConversionUtils.arraycopy(fileBytes, 0x00, data1, 0x30, fileBytes.Length);
            byte[] hash1   = ToolsImpl.CMAC128(EDATKeys.npdrm_omac_key3, data1, 0, data1.Length);
            bool   result1 = compareBytes(hash1, 0, npd, 0x50, 0x10);

            if (result1)
            {
                Console.WriteLine("NPD hash 1 is valid (" + ConversionUtils.getHexString(hash1) + ")");
            }
            return(result1);
        }
Example #6
0
        private bool checkNPDHash1(string filename, byte[] npd)
        {
            byte[] src  = ConversionUtils.charsToByte(filename.ToCharArray());
            byte[] dest = new byte[0x30 + src.Length];
            ConversionUtils.arraycopy(npd, 0x10, dest, 0L, 0x30);
            ConversionUtils.arraycopy(src, 0, dest, 0x30L, src.Length);
            byte[] buffer3 = ToolsImpl.CMAC128(EDATKeys.npdrm_omac_key3, dest, 0, dest.Length);
            bool   flag    = this.compareBytes(buffer3, 0, npd, 80, 0x10);

            if (flag)
            {
                Console.WriteLine("NPD hash 1 is valid (" + ConversionUtils.getHexString(buffer3) + ")");
            }
            return(flag);
        }
Example #7
0
        public int decryptFile(string inFile, string outFile, byte[] devKLic, byte[] keyFromRif)
        {
            FileStream i = File.Open(inFile, FileMode.Open);

            string[] strArray = i.Name.Split(new char[] { '\\' });
            Console.WriteLine(strArray[strArray.Length - 1]);
            NPD[] npdPtr = new NPD[1];
            int   num    = this.validateNPD(strArray[strArray.Length - 1], devKLic, npdPtr, i);

            if (num < 0)
            {
                i.Close();
                return(num);
            }
            NPD      npd  = npdPtr[0];
            EDATData data = this.getEDATData(i);

            byte[] raw = this.getKey(npd, data, devKLic, keyFromRif);
            if (raw == null)
            {
                Console.WriteLine("ERROR: Key for decryption is missing");
                i.Close();
                return(STATUS_ERROR_MISSINGKEY);
            }
            Console.WriteLine("DECRYPTION KEY: " + ConversionUtils.getHexString(raw));
            num = this.checkHeader(raw, data, npd, i);
            if (num < 0)
            {
                i.Close();
                return(num);
            }
            FileStream o = File.Open(outFile, FileMode.Create);

            num = this.decryptData(i, o, npd, data, raw);
            if (num < 0)
            {
                i.Close();
                return(num);
            }
            i.Close();
            o.Close();
            Console.WriteLine("COMPLETE: File Written to disk");
            return(STATUS_OK);
        }