diff --git a/bootloader/hos/hos.c b/bootloader/hos/hos.c index 8a19950..934c33f 100644 --- a/bootloader/hos/hos.c +++ b/bootloader/hos/hos.c @@ -1071,7 +1071,7 @@ int hos_launch(ini_sec_t *cfg) } // Rebuild and encrypt package2. - pkg2_build_encrypt((void *)PKG2_LOAD_ADDR, &ctxt, &kip1_info); + pkg2_build_encrypt((void *)PKG2_LOAD_ADDR, &ctxt, &kip1_info, is_exo); // Configure Exosphere if secmon is replaced. if (is_exo) diff --git a/bootloader/hos/pkg2.c b/bootloader/hos/pkg2.c index 2954ec7..51809b1 100644 --- a/bootloader/hos/pkg2.c +++ b/bootloader/hos/pkg2.c @@ -742,7 +742,7 @@ DPRINTF("adding kip1 '%s' @ %08X (%08X)\n", ki->kip1->name, (u32)ki->kip1, ki->s return ini1_size; } -void pkg2_build_encrypt(void *dst, void *hos_ctxt, link_t *kips_info) +void pkg2_build_encrypt(void *dst, void *hos_ctxt, link_t *kips_info, bool is_exo) { u8 *pdst = (u8 *)dst; launch_ctxt_t * ctxt = (launch_ctxt_t *)hos_ctxt; @@ -807,13 +807,16 @@ DPRINTF("kernel encrypted\n"); ini1_size = _pkg2_ini1_build(pdst, hdr, kips_info, false); DPRINTF("INI1 encrypted\n"); - // Calculate SHA256 over encrypted Kernel and INI1. - u8 *pk2_hash_data = (u8 *)dst + 0x100 + sizeof(pkg2_hdr_t); - se_calc_sha256_oneshot(&hdr->sec_sha256[0x20 * PKG2_SEC_KERNEL], - (void *)pk2_hash_data, hdr->sec_size[PKG2_SEC_KERNEL]); - pk2_hash_data += hdr->sec_size[PKG2_SEC_KERNEL]; - se_calc_sha256_oneshot(&hdr->sec_sha256[0x20 * PKG2_SEC_INI1], - (void *)pk2_hash_data, hdr->sec_size[PKG2_SEC_INI1]); + if (!is_exo) // Not needed on Exosphere 1.0.0 and up. + { + // Calculate SHA256 over encrypted Kernel and INI1. + u8 *pk2_hash_data = (u8 *)dst + 0x100 + sizeof(pkg2_hdr_t); + se_calc_sha256_oneshot(&hdr->sec_sha256[SE_SHA_256_SIZE * PKG2_SEC_KERNEL], + (void *)pk2_hash_data, hdr->sec_size[PKG2_SEC_KERNEL]); + pk2_hash_data += hdr->sec_size[PKG2_SEC_KERNEL]; + se_calc_sha256_oneshot(&hdr->sec_sha256[SE_SHA_256_SIZE * PKG2_SEC_INI1], + (void *)pk2_hash_data, hdr->sec_size[PKG2_SEC_INI1]); + } // Encrypt header. *(u32 *)hdr->ctr = 0x100 + sizeof(pkg2_hdr_t) + kernel_size + ini1_size; diff --git a/bootloader/hos/pkg2.h b/bootloader/hos/pkg2.h index a163677..321d5ab 100644 --- a/bootloader/hos/pkg2.h +++ b/bootloader/hos/pkg2.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2018 naehrwert - * Copyright (c) 2018-2020 CTCaer + * Copyright (c) 2018-2022 CTCaer * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -156,6 +156,6 @@ const char* pkg2_patch_kips(link_t *info, char* patchNames); const pkg2_kernel_id_t *pkg2_identify(u8 *hash); pkg2_hdr_t *pkg2_decrypt(void *data, u8 kb, bool is_exo); -void pkg2_build_encrypt(void *dst, void *hos_ctxt, link_t *kips_info); +void pkg2_build_encrypt(void *dst, void *hos_ctxt, link_t *kips_info, bool is_exo); #endif