private void DerivePerConsoleKeys() { var kek = new byte[0x10]; // Derive the device key if (!PerConsoleKeySource.IsEmpty() && !KeyblobKeys[0].IsEmpty()) { Crypto.DecryptEcb(KeyblobKeys[0], PerConsoleKeySource, DeviceKey, 0x10); } // Derive save key if (!SaveMacKekSource.IsEmpty() && !SaveMacKeySource.IsEmpty() && !DeviceKey.IsEmpty()) { Crypto.GenerateKek(DeviceKey, SaveMacKekSource, kek, AesKekGenerationSource, null); Crypto.DecryptEcb(kek, SaveMacKeySource, SaveMacKey, 0x10); } // Derive BIS keys if (DeviceKey.IsEmpty() || BisKekSource.IsEmpty() || AesKekGenerationSource.IsEmpty() || AesKeyGenerationSource.IsEmpty() || RetailSpecificAesKeySource.IsEmpty()) { return; } // If the user doesn't provide bis_key_source_03 we can assume it's the same as bis_key_source_02 if (BisKeySource[3].IsEmpty() && !BisKeySource[2].IsEmpty()) { Array.Copy(BisKeySource[2], BisKeySource[3], 0x20); } Crypto.DecryptEcb(DeviceKey, RetailSpecificAesKeySource, kek, 0x10); if (!BisKeySource[0].IsEmpty()) { Crypto.DecryptEcb(kek, BisKeySource[0], BisKeys[0], 0x20); } Crypto.GenerateKek(DeviceKey, BisKekSource, kek, AesKekGenerationSource, AesKeyGenerationSource); for (int i = 1; i < 4; i++) { if (!BisKeySource[i].IsEmpty()) { Crypto.DecryptEcb(kek, BisKeySource[i], BisKeys[i], 0x20); } } }
private void DerivePerConsoleKeys() { var kek = new byte[0x10]; // Derive the device key if (!PerConsoleKeySource.IsEmpty() && !KeyblobKeys[0].IsEmpty()) { Crypto.DecryptEcb(KeyblobKeys[0], PerConsoleKeySource, DeviceKey, 0x10); } // Derive save key if (!SaveMacKekSource.IsEmpty() && !SaveMacKeySource.IsEmpty() && !DeviceKey.IsEmpty()) { Crypto.GenerateKek(DeviceKey, SaveMacKekSource, kek, AesKekGenerationSource, null); Crypto.DecryptEcb(kek, SaveMacKeySource, SaveMacKey, 0x10); } // Derive BIS keys if (DeviceKey.IsEmpty() || BisKeySource[0].IsEmpty() || BisKeySource[1].IsEmpty() || BisKeySource[2].IsEmpty() || BisKekSource.IsEmpty() || AesKekGenerationSource.IsEmpty() || AesKeyGenerationSource.IsEmpty() || RetailSpecificAesKeySource.IsEmpty()) { return; } Crypto.DecryptEcb(DeviceKey, RetailSpecificAesKeySource, kek, 0x10); Crypto.DecryptEcb(kek, BisKeySource[0], BisKeys[0], 0x20); Crypto.GenerateKek(DeviceKey, BisKekSource, kek, AesKekGenerationSource, AesKeyGenerationSource); Crypto.DecryptEcb(kek, BisKeySource[1], BisKeys[1], 0x20); Crypto.DecryptEcb(kek, BisKeySource[2], BisKeys[2], 0x20); // BIS keys 2 and 3 are the same Array.Copy(BisKeys[2], BisKeys[3], 0x20); }