From 54ed439ccefcce8abe04a1479ce562b2c77d08d7 Mon Sep 17 00:00:00 2001 From: shchmue Date: Wed, 9 Feb 2022 10:52:21 -0700 Subject: [PATCH] Use size abbreviations --- bdk/libs/nx_savedata/header.h | 4 ++-- bdk/libs/nx_savedata/remap_storage.h | 2 +- bdk/libs/nx_savedata/save_fs_list.c | 2 +- source/keys/keys.c | 14 +++++++------- source/keys/keys.h | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/bdk/libs/nx_savedata/header.h b/bdk/libs/nx_savedata/header.h index 3d65d83..4a6e259 100644 --- a/bdk/libs/nx_savedata/header.h +++ b/bdk/libs/nx_savedata/header.h @@ -61,7 +61,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define VERSION_RMAP 0x10000 #define VERSION_IVFC 0x20000 -#define SAVE_BLOCK_SIZE_DEFAULT 0x4000 +#define SAVE_BLOCK_SIZE_DEFAULT SZ_16K #define SAVE_NUM_HEADERS 2 @@ -232,6 +232,6 @@ typedef struct { }; } save_header_t; -static_assert(sizeof(save_header_t) == 0x4000, "Save header size is wrong!"); +static_assert(sizeof(save_header_t) == SZ_16K, "Save header size is wrong!"); #endif diff --git a/bdk/libs/nx_savedata/remap_storage.h b/bdk/libs/nx_savedata/remap_storage.h index 2f67e04..2917775 100644 --- a/bdk/libs/nx_savedata/remap_storage.h +++ b/bdk/libs/nx_savedata/remap_storage.h @@ -41,7 +41,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #define RMAP_ALIGN_SMALL 0x200 -#define RMAP_ALIGN_LARGE 0x4000 +#define RMAP_ALIGN_LARGE SZ_16K typedef struct { uint32_t magic; /* RMAP */ diff --git a/bdk/libs/nx_savedata/save_fs_list.c b/bdk/libs/nx_savedata/save_fs_list.c index 78e2abe..69cc915 100644 --- a/bdk/libs/nx_savedata/save_fs_list.c +++ b/bdk/libs/nx_savedata/save_fs_list.c @@ -250,7 +250,7 @@ uint32_t save_fs_list_allocate_entry(save_filesystem_list_ctx_t *ctx) { if (capacity == 0 || length >= capacity) { uint64_t current_size, new_size; save_allocation_table_storage_get_size(&ctx->storage, ¤t_size); - if (!save_allocation_table_storage_set_size(&ctx->storage, current_size + 0x4000)) + if (!save_allocation_table_storage_set_size(&ctx->storage, current_size + SZ_16K)) return 0; save_allocation_table_storage_get_size(&ctx->storage, &new_size); if (!save_fs_list_set_capacity(ctx, (uint32_t)(new_size / sizeof(save_fs_list_entry_t)))) diff --git a/source/keys/keys.c b/source/keys/keys.c index dd6f8e4..ae165aa 100644 --- a/source/keys/keys.c +++ b/source/keys/keys.c @@ -140,8 +140,8 @@ static void _derive_keyblob_keys(key_derivation_ctx_t *keys) { bool have_keyblobs = true; if (FUSE(FUSE_PRIVATE_KEY0) == 0xFFFFFFFF) { - u8 *aes_keys = (u8 *)calloc(0x1000, 1); - se_get_aes_keys(aes_keys + 0x800, aes_keys, AES_128_KEY_SIZE); + u8 *aes_keys = (u8 *)calloc(SZ_4K, 1); + se_get_aes_keys(aes_keys + SZ_2K, aes_keys, AES_128_KEY_SIZE); memcpy(keys->sbk, aes_keys + 14 * AES_128_KEY_SIZE, AES_128_KEY_SIZE); free(aes_keys); } else { @@ -424,7 +424,7 @@ static bool _derive_sd_seed(key_derivation_ctx_t *keys) { } u8 read_buf[0x20] __attribute__((aligned(4))) = {0}; - for (u32 i = 0x8000; i < f_size(&fp); i += 0x4000) { + for (u32 i = SZ_32K; i < f_size(&fp); i += SZ_16K) { if (f_lseek(&fp, i) || f_read(&fp, read_buf, 0x20, &read_bytes) || read_bytes != 0x20) break; if (!memcmp(keys->temp_key, read_buf, sizeof(keys->temp_key))) { @@ -493,7 +493,7 @@ static bool _derive_titlekeys(key_derivation_ctx_t *keys, titlekey_buffer_t *tit se_rsa_key_set(0, rsa_keypair.modulus, sizeof(rsa_keypair.modulus), rsa_keypair.private_exponent, sizeof(rsa_keypair.private_exponent)); - const u32 buf_size = 0x4000; + const u32 buf_size = SZ_16K; _get_titlekeys_from_save(buf_size, keys->save_mac_key, titlekey_buffer, NULL); _get_titlekeys_from_save(buf_size, keys->save_mac_key, titlekey_buffer, &rsa_keypair); @@ -639,7 +639,7 @@ static void _save_keys_to_sd(key_derivation_ctx_t *keys, titlekey_buffer_t *titl return; } - u32 text_buffer_size = MAX(_titlekey_count * sizeof(titlekey_text_buffer_t) + 1, 0x4000); + u32 text_buffer_size = MAX(_titlekey_count * sizeof(titlekey_text_buffer_t) + 1, SZ_16K); text_buffer = (char *)calloc(1, text_buffer_size); SAVE_KEY(aes_kek_generation_source); @@ -816,8 +816,8 @@ static void _derive_keys() { return; } - u8 *aes_keys = (u8 *)calloc(0x1000, 1); - se_get_aes_keys(aes_keys + 0x800, aes_keys, AES_128_KEY_SIZE); + u8 *aes_keys = (u8 *)calloc(SZ_4K, 1); + se_get_aes_keys(aes_keys + SZ_2K, aes_keys, AES_128_KEY_SIZE); memcpy(&dev_keys.tsec_root_key, aes_keys + 11 * AES_128_KEY_SIZE, AES_128_KEY_SIZE); memcpy(keys->tsec_key, aes_keys + 12 * AES_128_KEY_SIZE, AES_128_KEY_SIZE); memcpy(&prod_keys.tsec_root_key, aes_keys + 13 * AES_128_KEY_SIZE, AES_128_KEY_SIZE); diff --git a/source/keys/keys.h b/source/keys/keys.h index d264851..97a9309 100644 --- a/source/keys/keys.h +++ b/source/keys/keys.h @@ -58,9 +58,9 @@ typedef struct { } ticket_record_t; typedef struct { - u8 read_buffer[0x40000]; - u8 rights_ids[0x40000 / 0x10][0x10]; - u8 titlekeys[0x40000 / 0x10][0x10]; + u8 read_buffer[SZ_256K]; + u8 rights_ids[SZ_256K / 0x10][0x10]; + u8 titlekeys[SZ_256K / 0x10][0x10]; } titlekey_buffer_t; typedef struct {