From c04ae4c7c0a17f3122efa76b464e99647a3fce7b Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Sun, 9 Sep 2018 17:10:03 -0500 Subject: [PATCH] Make GenerateKek signature match similar functions' --- LibHac/Crypto.cs | 7 ++++--- LibHac/Keyset.cs | 12 ++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/LibHac/Crypto.cs b/LibHac/Crypto.cs index 8a37a1d2..ea4309a0 100644 --- a/LibHac/Crypto.cs +++ b/LibHac/Crypto.cs @@ -76,16 +76,17 @@ namespace LibHac public static void EncryptCbc(byte[] key, byte[] iv, byte[] src, byte[] dest, int length) => EncryptCbc(key, iv, src, 0, dest, 0, length); - public static void GenerateKek(byte[] dst, byte[] src, byte[] masterKey, byte[] kekSeed, byte[] keySeed) + public static void GenerateKek(byte[] key, byte[] src, byte[] dest, byte[] kekSeed, byte[] keySeed) { var kek = new byte[Aes128Size]; var srcKek = new byte[Aes128Size]; - DecryptEcb(masterKey, kekSeed, kek, Aes128Size); + + DecryptEcb(key, kekSeed, kek, Aes128Size); DecryptEcb(kek, src, srcKek, Aes128Size); if (keySeed != null) { - DecryptEcb(srcKek, keySeed, dst, Aes128Size); + DecryptEcb(srcKek, keySeed, dest, Aes128Size); } } diff --git a/LibHac/Keyset.cs b/LibHac/Keyset.cs index d67b12ad..32f54728 100644 --- a/LibHac/Keyset.cs +++ b/LibHac/Keyset.cs @@ -172,7 +172,7 @@ namespace LibHac Crypto.DecryptEcb(device_key, retail_specific_aes_key_source, kek, 0x10); Crypto.DecryptEcb(kek, bis_key_source[0], bis_keys[0], 0x20); - Crypto.GenerateKek(kek, bis_kek_source, device_key, aes_kek_generation_source, aes_key_generation_source); + Crypto.GenerateKek(device_key, bis_kek_source, kek, aes_kek_generation_source, aes_key_generation_source); Crypto.DecryptEcb(kek, bis_key_source[1], bis_keys[1], 0x20); Crypto.DecryptEcb(kek, bis_key_source[2], bis_keys[2], 0x20); @@ -198,19 +198,19 @@ namespace LibHac if (haveKakSource0) { - Crypto.GenerateKek(key_area_keys[i][0], key_area_key_application_source, master_keys[i], + Crypto.GenerateKek(master_keys[i], key_area_key_application_source, key_area_keys[i][0], aes_kek_generation_source, aes_key_generation_source); } if (haveKakSource1) { - Crypto.GenerateKek(key_area_keys[i][1], key_area_key_ocean_source, master_keys[i], + Crypto.GenerateKek(master_keys[i], key_area_key_ocean_source, key_area_keys[i][1], aes_kek_generation_source, aes_key_generation_source); } if (haveKakSource2) { - Crypto.GenerateKek(key_area_keys[i][2], key_area_key_system_source, master_keys[i], + Crypto.GenerateKek(master_keys[i], key_area_key_system_source, key_area_keys[i][2], aes_kek_generation_source, aes_key_generation_source); } @@ -232,7 +232,7 @@ namespace LibHac var headerKek = new byte[0x10]; - Crypto.GenerateKek(headerKek, header_kek_source, master_keys[0], aes_kek_generation_source, + Crypto.GenerateKek(master_keys[0], header_kek_source, headerKek, aes_kek_generation_source, aes_key_generation_source); Crypto.DecryptEcb(headerKek, header_key_source, header_key, 0x20); } @@ -240,7 +240,7 @@ namespace LibHac private void DeriveSdCardKeys() { var sdKek = new byte[0x10]; - Crypto.GenerateKek(sdKek, sd_card_kek_source, master_keys[0], aes_kek_generation_source, aes_key_generation_source); + Crypto.GenerateKek(master_keys[0], sd_card_kek_source, sdKek, aes_kek_generation_source, aes_key_generation_source); for (int k = 0; k < sd_card_key_sources.Length; k++) {