// Plain PGD handling functions. public virtual sbyte[] DecryptPGD(sbyte[] inbuf, int size, sbyte[] key, int seed) { // Setup the crypto and keygen modes and initialize both context structs. int sdEncMode = 1; int sdGenMode = 2; pgdMacContext = new AMCTRL.BBMac_Ctx(); pgdCipherContext = new AMCTRL.BBCipher_Ctx(); // Align the buffers to 16-bytes. int alignedSize = ((size + 0xF) >> 4) << 4; sbyte[] outbuf = new sbyte[alignedSize - 0x10]; sbyte[] dataBuf = new sbyte[alignedSize]; // Fully copy the contents of the encrypted file. Array.Copy(inbuf, 0, dataBuf, 0, size); amctrl.hleDrmBBMacInit(pgdMacContext, sdEncMode); amctrl.hleDrmBBCipherInit(pgdCipherContext, sdEncMode, sdGenMode, dataBuf, key, seed); amctrl.hleDrmBBMacUpdate(pgdMacContext, dataBuf, 0x10); Array.Copy(dataBuf, 0x10, outbuf, 0, alignedSize - 0x10); amctrl.hleDrmBBMacUpdate(pgdMacContext, outbuf, alignedSize - 0x10); amctrl.hleDrmBBCipherUpdate(pgdCipherContext, outbuf, alignedSize - 0x10); return(outbuf); }
/* * 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)); }