Exemplo n.º 1
0
        public override void doUpdate(byte[] i, int inOffset, int len)
        {
            byte[] data;
            if (nonProcessed != null)
            {
                int totalLen = len + nonProcessed.Length;
                data = new byte[totalLen];
                ConversionUtils.arraycopy(nonProcessed, 0, data, 0, nonProcessed.Length);
                ConversionUtils.arraycopy(i, inOffset, data, nonProcessed.Length, len);
            }
            else
            {
                data = new byte[len];
                ConversionUtils.arraycopy(i, inOffset, data, 0, len);
            }
            int count = 0;

            while (count < data.Length - 0x10)
            {
                byte[] aux = new byte[0x10];
                ConversionUtils.arraycopy(data, count, aux, 0, aux.Length);
                ToolsImpl.XOR(aux, aux, previous);
                ToolsImpl.aesecbEncrypt(key, aux, 0, previous, 0, aux.Length);
                count += 0x10;
            }
            nonProcessed = new byte[data.Length - count];
            ConversionUtils.arraycopy(data, count, nonProcessed, 0, nonProcessed.Length);
        }
Exemplo n.º 2
0
        public override void doUpdate(byte[] i, int inOffset, int len)
        {
            byte[] buffer;
            if (this.nonProcessed != null)
            {
                int num = len + this.nonProcessed.Length;
                buffer = new byte[num];
                ConversionUtils.arraycopy(this.nonProcessed, 0, buffer, 0L, this.nonProcessed.Length);
                ConversionUtils.arraycopy(i, inOffset, buffer, (long)this.nonProcessed.Length, len);
            }
            else
            {
                buffer = new byte[len];
                ConversionUtils.arraycopy(i, inOffset, buffer, 0L, len);
            }
            int srcPos = 0;

            while (srcPos < (buffer.Length - 0x10))
            {
                byte[] dest = new byte[0x10];
                ConversionUtils.arraycopy(buffer, srcPos, dest, 0L, dest.Length);
                ToolsImpl.XOR(dest, dest, this.previous);
                ToolsImpl.aesecbEncrypt(this.key, dest, 0, this.previous, 0, dest.Length);
                srcPos += 0x10;
            }
            this.nonProcessed = new byte[buffer.Length - srcPos];
            ConversionUtils.arraycopy(buffer, srcPos, this.nonProcessed, 0L, this.nonProcessed.Length);
        }
Exemplo n.º 3
0
 private byte[] createNPDHash2(byte[] klicensee, byte[] npd)
 {
     byte[] output = new byte[0x10];
     ToolsImpl.XOR(output, klicensee, EDATKeys.npdrm_omac_key2);
     byte[] src = ToolsImpl.CMAC128(output, npd, 0, 0x60);
     ConversionUtils.arraycopy(src, 0, npd, 0x60L, 0x10);
     if (this.compareBytes(src, 0, npd, 0x60, 0x10))
     {
         return(src);
     }
     return(null);
 }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        private byte[] createNPDHash2(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);
            ConversionUtils.arraycopy(calculated, 0, npd, 0x60, 0x10);
            bool result2 = compareBytes(calculated, 0, npd, 0x60, 0x10);

            if (result2)
            {
                return(calculated);
            }
            return(null);
        }
Exemplo n.º 7
0
 public override bool doFinal(byte[] generateHash)
 {
     byte[] dest = new byte[0x10];
     ConversionUtils.arraycopy(this.nonProcessed, 0, dest, 0L, this.nonProcessed.Length);
     if (this.nonProcessed.Length == 0x10)
     {
         ToolsImpl.XOR(dest, dest, this.K1);
     }
     else
     {
         dest[this.nonProcessed.Length] = 0x80;
         ToolsImpl.XOR(dest, dest, this.K2);
     }
     ToolsImpl.XOR(dest, dest, this.previous);
     ToolsImpl.aesecbEncrypt(this.key, dest, 0, generateHash, 0, dest.Length);
     return(true);
 }
Exemplo n.º 8
0
 public override bool doFinal(byte[] generateHash)
 {
     byte[] aux = new byte[0x10];
     ConversionUtils.arraycopy(nonProcessed, 0, aux, 0, nonProcessed.Length);
     if (nonProcessed.Length == 0x10)
     {
         ToolsImpl.XOR(aux, aux, K1);
     }
     else
     {
         aux[nonProcessed.Length] = (byte)0x80;
         ToolsImpl.XOR(aux, aux, K2);
     }
     ToolsImpl.XOR(aux, aux, previous);
     ToolsImpl.aesecbEncrypt(key, aux, 0, generateHash, 0, aux.Length);
     return(true);
 }
Exemplo n.º 9
0
 public override bool doFinal(byte[] expectedhash, int hashOffset, bool hashDebug)
 {
     byte[] dest = new byte[0x10];
     ConversionUtils.arraycopy(this.nonProcessed, 0, dest, 0L, this.nonProcessed.Length);
     if (this.nonProcessed.Length == 0x10)
     {
         ToolsImpl.XOR(dest, dest, this.K1);
     }
     else
     {
         dest[this.nonProcessed.Length] = 0x80;
         ToolsImpl.XOR(dest, dest, this.K2);
     }
     ToolsImpl.XOR(dest, dest, this.previous);
     byte[] o = new byte[0x10];
     ToolsImpl.aesecbEncrypt(this.key, dest, 0, o, 0, dest.Length);
     return(hashDebug || base.compareBytes(expectedhash, hashOffset, o, 0, this.hashLen));
 }
Exemplo n.º 10
0
 public override bool doFinal(byte[] expectedhash, int hashOffset, bool hashDebug)
 {
     byte[] aux = new byte[0x10];
     ConversionUtils.arraycopy(nonProcessed, 0, aux, 0, nonProcessed.Length);
     if (nonProcessed.Length == 0x10)
     {
         ToolsImpl.XOR(aux, aux, K1);
     }
     else
     {
         aux[nonProcessed.Length] = (byte)0x80;
         ToolsImpl.XOR(aux, aux, K2);
     }
     ToolsImpl.XOR(aux, aux, previous);
     byte[] calculatedhash = new byte[0x10];
     ToolsImpl.aesecbEncrypt(key, aux, 0, calculatedhash, 0, aux.Length);
     return(hashDebug || compareBytes(expectedhash, hashOffset, calculatedhash, 0, hashLen));
 }
Exemplo n.º 11
0
 private byte[] getKey(NPD npd, EDATData data, byte[] devKLic, byte[] keyFromRif)
 {
     byte[] output = null;
     if ((data.getFlags() & FLAG_SDAT) != 0L)
     {
         output = new byte[0x10];
         ToolsImpl.XOR(output, npd.getDevHash(), EDATKeys.SDATKEY);
         return(output);
     }
     if (npd.getLicense() == 3L)
     {
         return(devKLic);
     }
     if (npd.getLicense() == 2L)
     {
         output = keyFromRif;
     }
     return(output);
 }
Exemplo n.º 12
0
 private byte[] getKey(NPD npd, EDATData data, byte[] devKLic, byte[] keyFromRif)
 {
     byte[] result = null;
     if ((data.getFlags() & FLAG_SDAT) != 0)
     {
         //Case SDAT
         result = new byte[0x10];
         ToolsImpl.XOR(result, npd.getDevHash(), EDATKeys.SDATKEY);
     }
     else
     {
         //Case EDAT
         if (npd.getLicense() == 0x03)
         {
             result = devKLic;
         }
         else if (npd.getLicense() == 0x02)
         {
             result = keyFromRif;
         }
     }
     return(result);
 }