hos: refactor ctr/hash vars in pkg2 header

This commit is contained in:
CTCaer
2026-01-15 17:32:00 +02:00
parent 3af777f839
commit 116d4042c2
5 changed files with 17 additions and 17 deletions

View File

@@ -2,7 +2,7 @@
* Copyright (c) 2018 naehrwert * Copyright (c) 2018 naehrwert
* Copyright (c) 2018 st4rk * Copyright (c) 2018 st4rk
* Copyright (c) 2018 Ced2911 * Copyright (c) 2018 Ced2911
* Copyright (c) 2018-2025 CTCaer * Copyright (c) 2018-2026 CTCaer
* Copyright (c) 2018 balika011 * Copyright (c) 2018 balika011
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
@@ -1008,14 +1008,14 @@ void hos_launch(ini_sec_t *cfg)
{ {
EHPRINTFARGS("Failed to apply '%s'!", failed_patch); EHPRINTFARGS("Failed to apply '%s'!", failed_patch);
bool emmc_patch_failed = !strcmp(failed_patch, "emummc"); bool emu_patch_failed = !strcmp(failed_patch, "emummc");
if (!emmc_patch_failed) if (!emu_patch_failed)
{ {
gfx_puts("\nPress POWER to continue.\nPress VOL to go to the menu.\n"); gfx_puts("\nPress POWER to continue.\nPress VOL to go to the menu.\n");
display_backlight_brightness(h_cfg.backlight, 1000); display_backlight_brightness(h_cfg.backlight, 1000);
} }
if (emmc_patch_failed || !(btn_wait() & BTN_POWER)) if (emu_patch_failed || !(btn_wait() & BTN_POWER))
goto error; // MUST stop here, because if user requests 'nogc' but it's not applied, their GC controller gets updated! goto error; // MUST stop here, because if user requests 'nogc' but it's not applied, their GC controller gets updated!
} }

View File

@@ -1,6 +1,6 @@
/* /*
* Copyright (c) 2018 naehrwert * Copyright (c) 2018 naehrwert
* Copyright (c) 2018-2025 CTCaer * Copyright (c) 2018-2026 CTCaer
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License, * under the terms and conditions of the GNU General Public License,
@@ -730,7 +730,7 @@ DPRINTF("sec %d has size %08X\n", i, hdr->sec_size[i]);
if (!hdr->sec_size[i]) if (!hdr->sec_size[i])
continue; continue;
se_aes_crypt_ctr(pkg2_keyslot, pdata, pdata, hdr->sec_size[i], &hdr->sec_ctr[i * SE_AES_IV_SIZE]); se_aes_crypt_ctr(pkg2_keyslot, pdata, pdata, hdr->sec_size[i], hdr->sec_ctr[i]);
pdata += hdr->sec_size[i]; pdata += hdr->sec_size[i];
} }
@@ -776,7 +776,7 @@ DPRINTF("adding kip1 '%s' @ %08X (%08X)\n", (char *)ki->kip1->name, (u32)ki->kip
{ {
hdr->sec_size[PKG2_SEC_INI1] = ini1_size; hdr->sec_size[PKG2_SEC_INI1] = ini1_size;
hdr->sec_off[PKG2_SEC_INI1] = 0x14080000; hdr->sec_off[PKG2_SEC_INI1] = 0x14080000;
se_aes_crypt_ctr(8, ini1, ini1, ini1_size, &hdr->sec_ctr[PKG2_SEC_INI1 * SE_AES_IV_SIZE]); se_aes_crypt_ctr(8, ini1, ini1, ini1_size, hdr->sec_ctr[PKG2_SEC_INI1]);
} }
else else
{ {
@@ -854,7 +854,7 @@ DPRINTF("%s @ %08X (%08X)\n", is_meso ? "Mesosphere": "kernel",(u32)ctxt->kernel
kernel_size += ini1_size; kernel_size += ini1_size;
} }
hdr->sec_size[PKG2_SEC_KERNEL] = kernel_size; hdr->sec_size[PKG2_SEC_KERNEL] = kernel_size;
se_aes_crypt_ctr(pkg2_keyslot, pdst, pdst, kernel_size, &hdr->sec_ctr[PKG2_SEC_KERNEL * SE_AES_IV_SIZE]); se_aes_crypt_ctr(pkg2_keyslot, pdst, pdst, kernel_size, hdr->sec_ctr[PKG2_SEC_KERNEL]);
pdst += kernel_size; pdst += kernel_size;
DPRINTF("kernel encrypted\n"); DPRINTF("kernel encrypted\n");
@@ -870,7 +870,7 @@ DPRINTF("INI1 encrypted\n");
u8 *pk2_hash_data = (u8 *)dst + 0x100 + sizeof(pkg2_hdr_t); u8 *pk2_hash_data = (u8 *)dst + 0x100 + sizeof(pkg2_hdr_t);
for (u32 i = PKG2_SEC_KERNEL; i <= PKG2_SEC_UNUSED; i++) for (u32 i = PKG2_SEC_KERNEL; i <= PKG2_SEC_UNUSED; i++)
{ {
se_sha_hash_256_oneshot(&hdr->sec_sha256[SE_SHA_256_SIZE * i], (void *)pk2_hash_data, hdr->sec_size[i]); se_sha_hash_256_oneshot(hdr->sec_sha256[i], (void *)pk2_hash_data, hdr->sec_size[i]);
pk2_hash_data += hdr->sec_size[i]; pk2_hash_data += hdr->sec_size[i];
} }
} }

View File

@@ -1,6 +1,6 @@
/* /*
* Copyright (c) 2018 naehrwert * Copyright (c) 2018 naehrwert
* Copyright (c) 2018-2025 CTCaer * Copyright (c) 2018-2026 CTCaer
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License, * under the terms and conditions of the GNU General Public License,
@@ -71,7 +71,7 @@ enum
typedef struct _pkg2_hdr_t typedef struct _pkg2_hdr_t
{ {
/* 0x000 */ u8 ctr[0x10]; /* 0x000 */ u8 ctr[0x10];
/* 0x010 */ u8 sec_ctr[0x40]; /* 0x010 */ u8 sec_ctr[4][SE_AES_IV_SIZE];
/* 0x050 */ u32 magic; /* 0x050 */ u32 magic;
/* 0x054 */ u32 base; /* 0x054 */ u32 base;
/* 0x058 */ u32 pad0; /* 0x058 */ u32 pad0;
@@ -80,7 +80,7 @@ typedef struct _pkg2_hdr_t
/* 0x05E */ u16 pad1; /* 0x05E */ u16 pad1;
/* 0x060 */ u32 sec_size[4]; /* 0x060 */ u32 sec_size[4];
/* 0x070 */ u32 sec_off[4]; /* 0x070 */ u32 sec_off[4];
/* 0x080 */ u8 sec_sha256[0x80]; /* 0x080 */ u8 sec_sha256[4][SE_SHA_256_SIZE];
/* 0x100 */ u8 data[]; /* 0x100 */ u8 data[];
} pkg2_hdr_t; } pkg2_hdr_t;

View File

@@ -1,6 +1,6 @@
/* /*
* Copyright (c) 2018 naehrwert * Copyright (c) 2018 naehrwert
* Copyright (c) 2018-2025 CTCaer * Copyright (c) 2018-2026 CTCaer
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License, * under the terms and conditions of the GNU General Public License,
@@ -209,7 +209,7 @@ DPRINTF("sec %d has size %08X\n", i, hdr->sec_size[i]);
if (!hdr->sec_size[i]) if (!hdr->sec_size[i])
continue; continue;
se_aes_crypt_ctr(pkg2_keyslot, pdata, pdata, hdr->sec_size[i], &hdr->sec_ctr[i * SE_AES_IV_SIZE]); se_aes_crypt_ctr(pkg2_keyslot, pdata, pdata, hdr->sec_size[i], hdr->sec_ctr[i]);
pdata += hdr->sec_size[i]; pdata += hdr->sec_size[i];
} }

View File

@@ -1,6 +1,6 @@
/* /*
* Copyright (c) 2018 naehrwert * Copyright (c) 2018 naehrwert
* Copyright (c) 2018-2025 CTCaer * Copyright (c) 2018-2026 CTCaer
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License, * under the terms and conditions of the GNU General Public License,
@@ -39,7 +39,7 @@ extern u32 pkg2_newkern_ini1_end;
typedef struct _pkg2_hdr_t typedef struct _pkg2_hdr_t
{ {
/* 0x000 */ u8 ctr[0x10]; /* 0x000 */ u8 ctr[0x10];
/* 0x010 */ u8 sec_ctr[0x40]; /* 0x010 */ u8 sec_ctr[4][SE_AES_IV_SIZE];
/* 0x050 */ u32 magic; /* 0x050 */ u32 magic;
/* 0x054 */ u32 base; /* 0x054 */ u32 base;
/* 0x058 */ u32 pad0; /* 0x058 */ u32 pad0;
@@ -48,7 +48,7 @@ typedef struct _pkg2_hdr_t
/* 0x05E */ u16 pad1; /* 0x05E */ u16 pad1;
/* 0x060 */ u32 sec_size[4]; /* 0x060 */ u32 sec_size[4];
/* 0x070 */ u32 sec_off[4]; /* 0x070 */ u32 sec_off[4];
/* 0x080 */ u8 sec_sha256[0x80]; /* 0x080 */ u8 sec_sha256[4][SE_SHA_256_SIZE];
/* 0x100 */ u8 data[]; /* 0x100 */ u8 data[];
} pkg2_hdr_t; } pkg2_hdr_t;