Exemple #1
0
        // Encrypt with AESCBC128 using keys from table.
        private int executeKIRKCmd5(ByteBuffer @out, ByteBuffer @in, int size)
        {
            // Return an error if the crypto engine hasn't been initialized.
            if (!CryptoEngine.CryptoEngineStatus)
            {
                return(PSP_KIRK_NOT_INIT);
            }

            int outPosition = @out.position();

            // Read in the CMD4 format header.
            AES128_CBC_Header header = new AES128_CBC_Header(@in);

            if (header.mode != PSP_KIRK_CMD_MODE_ENCRYPT_CBC)
            {
                return(PSP_KIRK_INVALID_MODE);                // Only valid for mode ENCRYPT_CBC.
            }

            if (header.dataSize == 0)
            {
                return(PSP_KIRK_DATA_SIZE_IS_ZERO);
            }

            sbyte[] key = null;
            if (header.keySeed == 0x100)
            {
                key = priv_iv;
            }
            else
            {
                return(PSP_KIRK_INVALID_SIZE);                // Dummy.
            }

            sbyte[] encKey = new sbyte[16];
            for (int i = 0; i < encKey.Length; i++)
            {
                encKey[i] = (sbyte)key[i];
            }

            AES128 aes = new AES128("AES/CBC/NoPadding");

            sbyte[] inBuf = new sbyte[header.dataSize];
            @in.get(inBuf, 0, header.dataSize);
            sbyte[] outBuf = aes.encrypt(inBuf, encKey, priv_iv);

            @out.position(outPosition);
            // The header is kept in the output and the header.mode is even updated from
            // PSP_KIRK_CMD_MODE_ENCRYPT_CBC to PSP_KIRK_CMD_MODE_DECRYPT_CBC.
            @out.putInt(PSP_KIRK_CMD_MODE_DECRYPT_CBC);
            @out.putInt(header.unk1);
            @out.putInt(header.unk2);
            @out.putInt(header.keySeed);
            @out.putInt(header.dataSize);
            @out.put(outBuf);
            @in.clear();

            return(0);
        }
Exemple #2
0
        public virtual sbyte[] GetConsoleKey(sbyte[] openPSID)
        {
            AES128 aes = new AES128("AES/ECB/NoPadding");

            sbyte[] actdatKey = new sbyte[KeyVault.drmActdatKey.Length];
            for (int i = 0; i < KeyVault.drmActdatKey.Length; i++)
            {
                actdatKey[i] = unchecked ((sbyte)(KeyVault.drmActdatKey[i] & 0xFF));
            }

            return(aes.encrypt(openPSID, actdatKey, iv));
        }
Exemple #3
0
        /*
         * sceNpDrm - npdrm.prx
         */
        public virtual sbyte[] hleNpDrmGetFixedKey(sbyte[] hash, sbyte[] data, int mode)
        {
            // Setup the crypto and keygen modes and initialize both context structs.
            AMCTRL.BBMac_Ctx bbctx = new AMCTRL.BBMac_Ctx();
            AES128           aes   = new AES128("AES/CBC/NoPadding");

            // Get the encryption key.
            sbyte[] encKey = new sbyte[0x10];
            if ((mode & 0x1) == 0x1)
            {
                for (int i = 0; i < 0x10; i++)
                {
                    encKey[i] = unchecked ((sbyte)(KeyVault.drmEncKey1[i] & 0xFF));
                }
            }
            else if ((mode & 0x2) == 0x2)
            {
                for (int i = 0; i < 0x10; i++)
                {
                    encKey[i] = unchecked ((sbyte)(KeyVault.drmEncKey2[i] & 0xFF));
                }
            }
            else if ((mode & 0x3) == 0x3)
            {
                for (int i = 0; i < 0x10; i++)
                {
                    encKey[i] = unchecked ((sbyte)(KeyVault.drmEncKey3[i] & 0xFF));
                }
            }
            else
            {
                return(null);
            }

            // Get the fixed key.
            sbyte[] fixedKey = new sbyte[0x10];
            for (int i = 0; i < 0x10; i++)
            {
                fixedKey[i] = unchecked ((sbyte)(KeyVault.drmFixedKey[i] & 0xFF));
            }

            // Call the BBMac functions.
            amctrl.hleDrmBBMacInit(bbctx, 1);
            amctrl.hleDrmBBMacUpdate(bbctx, data, data.Length);
            amctrl.hleDrmBBMacFinal(bbctx, hash, fixedKey);

            // Encrypt and return the hash.
            return(aes.encrypt(hash, encKey, iv));
        }