From b2ca9c881d2059f9fa4c925b317e16f856bc55a6 Mon Sep 17 00:00:00 2001 From: shchmue Date: Tue, 10 Sep 2019 14:17:27 -0600 Subject: [PATCH] Fix bis key generation for newer hardware --- source/KeyCollection.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/source/KeyCollection.cpp b/source/KeyCollection.cpp index c1829b8..48ca9d9 100644 --- a/source/KeyCollection.cpp +++ b/source/KeyCollection.cpp @@ -402,16 +402,28 @@ void KeyCollection::derive_keys() { splCryptoExit(); } - if (bis_key_source_00.found() && bis_key_source_01.found() && bis_key_source_02.found()) { + u64 key_generation = 0; + SetSysFirmwareVersion ver; + + setsysInitialize(); + setsysGetFirmwareVersion(&ver); + setsysExit(); + + Result rc = 0; + if (ver.major >= 5) { + rc = splGetConfig(SplConfigItem_NewKeyGeneration, &key_generation); + } + + if (R_SUCCEEDED(rc) && bis_key_source_00.found() && bis_key_source_01.found() && bis_key_source_02.found()) { u8 tempbiskek[0x10], tempbiskey[0x20]; splFsInitialize(); - splFsGenerateSpecificAesKey(bis_key_source_00.key.data() + 0x00, 0, 0, tempbiskey + 0x00); - splFsGenerateSpecificAesKey(bis_key_source_00.key.data() + 0x10, 0, 0, tempbiskey + 0x10); + splFsGenerateSpecificAesKey(bis_key_source_00.key.data() + 0x00, key_generation, 0, tempbiskey + 0x00); + splFsGenerateSpecificAesKey(bis_key_source_00.key.data() + 0x10, key_generation, 0, tempbiskey + 0x10); bis_key.push_back(Key {"bis_key_00", 0x20, byte_vector(tempbiskey, tempbiskey + 0x20)}); splFsExit(); splCryptoInitialize(); - splCryptoGenerateAesKek(bis_kek_source.key.data(), 0, 1, tempbiskek); + splCryptoGenerateAesKek(bis_kek_source.key.data(), key_generation, 1, tempbiskek); splCryptoGenerateAesKey(tempbiskek, bis_key_source_01.key.data() + 0x00, tempbiskey + 0x00); splCryptoGenerateAesKey(tempbiskek, bis_key_source_01.key.data() + 0x10, tempbiskey + 0x10); bis_key.push_back(Key {"bis_key_01", 0x20, byte_vector(tempbiskey, tempbiskey + 0x20)});