From 20f708450b9c6e7f64eafa6c2a8eeb25a630c69a Mon Sep 17 00:00:00 2001 From: jakcron Date: Tue, 6 Jun 2017 12:44:12 +0800 Subject: [PATCH] [ctrtool] Fixed seed crypto. --- ctrtool/exefs.c | 4 ++-- ctrtool/exefs.h | 4 ++-- ctrtool/exheader.c | 4 ++-- ctrtool/exheader.h | 4 ++-- ctrtool/ncch.c | 14 +++++++------- ctrtool/ncch.h | 2 +- ctrtool/ncsd.c | 2 +- ctrtool/ncsd.h | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ctrtool/exefs.c b/ctrtool/exefs.c index cca8627..58e344c 100644 --- a/ctrtool/exefs.c +++ b/ctrtool/exefs.c @@ -33,9 +33,9 @@ void exefs_set_usersettings(exefs_context* ctx, settings* usersettings) ctx->usersettings = usersettings; } -void exefs_set_partitionid(exefs_context* ctx, u8 partitionid[8]) +void exefs_set_titleid(exefs_context* ctx, u8 titleid[8]) { - memcpy(ctx->partitionid, partitionid, 8); + memcpy(ctx->titleid, titleid, 8); } void exefs_set_compressedflag(exefs_context* ctx, int compressedflag) diff --git a/ctrtool/exefs.h b/ctrtool/exefs.h index cef22ce..2d1c410 100644 --- a/ctrtool/exefs.h +++ b/ctrtool/exefs.h @@ -27,7 +27,7 @@ typedef struct { FILE* file; settings* usersettings; - u8 partitionid[8]; + u8 titleid[8]; u8 counter[16]; u8 key[2][16]; u64 offset; @@ -45,7 +45,7 @@ void exefs_set_file(exefs_context* ctx, FILE* file); void exefs_set_offset(exefs_context* ctx, u64 offset); void exefs_set_size(exefs_context* ctx, u64 size); void exefs_set_usersettings(exefs_context* ctx, settings* usersettings); -void exefs_set_partitionid(exefs_context* ctx, u8 partitionid[8]); +void exefs_set_titleid(exefs_context* ctx, u8 titleid[8]); void exefs_set_counter(exefs_context* ctx, u8 counter[16]); void exefs_set_compressedflag(exefs_context* ctx, int compressedflag); void exefs_set_keys(exefs_context* ctx, u8 key[16], u8 special_key[16]); diff --git a/ctrtool/exheader.c b/ctrtool/exheader.c index 21473de..86609d8 100644 --- a/ctrtool/exheader.c +++ b/ctrtool/exheader.c @@ -34,9 +34,9 @@ void exheader_set_usersettings(exheader_context* ctx, settings* usersettings) ctx->usersettings = usersettings; } -void exheader_set_partitionid(exheader_context* ctx, u8 partitionid[8]) +void exheader_set_titleid(exheader_context* ctx, u8 titleid[8]) { - memcpy(ctx->partitionid, partitionid, 8); + memcpy(ctx->titleid, titleid, 8); } void exheader_set_programid(exheader_context* ctx, u8 programid[8]) diff --git a/ctrtool/exheader.h b/ctrtool/exheader.h index 09f751e..7f4ce49 100644 --- a/ctrtool/exheader.h +++ b/ctrtool/exheader.h @@ -149,7 +149,7 @@ typedef struct int haveread; FILE* file; settings* usersettings; - u8 partitionid[8]; + u8 titleid[8]; u8 programid[8]; u8 hash[32]; u8 counter[16]; @@ -183,7 +183,7 @@ void exheader_init(exheader_context* ctx); void exheader_set_file(exheader_context* ctx, FILE* file); void exheader_set_offset(exheader_context* ctx, u64 offset); void exheader_set_size(exheader_context* ctx, u64 size); -void exheader_set_partitionid(exheader_context* ctx, u8 partitionid[8]); +void exheader_set_titleid(exheader_context* ctx, u8 titleid[8]); void exheader_set_counter(exheader_context* ctx, u8 counter[16]); void exheader_set_programid(exheader_context* ctx, u8 programid[8]); void exheader_set_hash(exheader_context* ctx, u8 hash[32]); diff --git a/ctrtool/ncch.c b/ctrtool/ncch.c index 09bab9b..14ff9a9 100644 --- a/ctrtool/ncch.c +++ b/ctrtool/ncch.c @@ -50,7 +50,7 @@ void ncch_get_counter(ncch_context* ctx, u8 counter[16], u8 type) { u32 version = getle16(ctx->header.version); u32 mediaunitsize = (u32) ncch_get_mediaunit_size(ctx); - u8* partitionid = ctx->header.partitionid; + u8* titleid = ctx->header.titleid; u32 i; u64 x = 0; @@ -59,7 +59,7 @@ void ncch_get_counter(ncch_context* ctx, u8 counter[16], u8 type) if (version == 2 || version == 0) { for(i=0; i<8; i++) - counter[i] = partitionid[7-i]; + counter[i] = titleid[7-i]; counter[8] = type; } else if (version == 1) @@ -72,7 +72,7 @@ void ncch_get_counter(ncch_context* ctx, u8 counter[16], u8 type) x = getle32(ctx->header.romfsoffset) * mediaunitsize; for(i=0; i<8; i++) - counter[i] = partitionid[i]; + counter[i] = titleid[i]; for(i=0; i<4; i++) counter[12+i] = (u8) (x>>((3-i)*8)); } @@ -350,7 +350,7 @@ void ncch_process(ncch_context* ctx, u32 actions) exheader_set_offset(&ctx->exheader, ncch_get_exheader_offset(ctx) ); exheader_set_size(&ctx->exheader, ncch_get_exheader_size(ctx) ); exheader_set_usersettings(&ctx->exheader, ctx->usersettings); - exheader_set_partitionid(&ctx->exheader, ctx->header.partitionid); + exheader_set_titleid(&ctx->exheader, ctx->header.titleid); exheader_set_programid(&ctx->exheader, ctx->header.programid); exheader_set_hash(&ctx->exheader, ctx->header.extendedheaderhash); exheader_set_counter(&ctx->exheader, exheadercounter); @@ -360,7 +360,7 @@ void ncch_process(ncch_context* ctx, u32 actions) exefs_set_file(&ctx->exefs, ctx->file); exefs_set_offset(&ctx->exefs, ncch_get_exefs_offset(ctx) ); exefs_set_size(&ctx->exefs, ncch_get_exefs_size(ctx) ); - exefs_set_partitionid(&ctx->exefs, ctx->header.partitionid); + exefs_set_titleid(&ctx->exefs, ctx->header.titleid); exefs_set_usersettings(&ctx->exefs, ctx->usersettings); exefs_set_counter(&ctx->exefs, exefscounter); exefs_set_keys(&ctx->exefs, ctx->key[0], ctx->key[1]); @@ -630,7 +630,7 @@ void ncch_determine_key(ncch_context* ctx, u32 actions) // - get keyY if (header->flags[7] & 0x20) { - seed = settings_get_seed(ctx->usersettings, getle64(header->partitionid)); + seed = settings_get_seed(ctx->usersettings, getle64(header->programid)); if (!seed) { fprintf(stderr, "This title uses seed crypto, but no seed is set, unable to decrypt.\n" @@ -735,7 +735,7 @@ void ncch_print(ncch_context* ctx) else memdump(stdout, "Signature (FAIL): ", header->signature, 0x100); fprintf(stdout, "Content size: 0x%08"PRIx64"\n", getle32(header->contentsize)*mediaunitsize); - fprintf(stdout, "Partition id: %016"PRIx64"\n", getle64(header->partitionid)); + fprintf(stdout, "Title id: %016"PRIx64"\n", getle64(header->titleid)); fprintf(stdout, "Maker code: %.2s\n", header->makercode); fprintf(stdout, "Version: %d\n", getle16(header->version)); fprintf(stdout, "Title seed check: %08x\n", getle32(header->seedcheck)); diff --git a/ctrtool/ncch.h b/ctrtool/ncch.h index d480ed6..94d2968 100644 --- a/ctrtool/ncch.h +++ b/ctrtool/ncch.h @@ -33,7 +33,7 @@ typedef struct u8 signature[0x100]; u8 magic[4]; u8 contentsize[4]; - u8 partitionid[8]; + u8 titleid[8]; u8 makercode[2]; u8 version[2]; u8 seedcheck[4]; diff --git a/ctrtool/ncsd.c b/ctrtool/ncsd.c index 4a7d928..ab9fae8 100644 --- a/ctrtool/ncsd.c +++ b/ctrtool/ncsd.c @@ -147,7 +147,7 @@ void ncsd_print(ncsd_context* ctx) if (partitionsize != 0) { fprintf(stdout, "Partition %d \n", i); - memdump(stdout, " Id: ", header->partitionid+i*8, 8); + memdump(stdout, " Id: ", header->titleid+i*8, 8); fprintf(stdout, " Area: 0x%08X-0x%08X\n", partitionoffset, partitionoffset+partitionsize); fprintf(stdout, " Filesystem: %02X\n", header->partitionfstype[i]); fprintf(stdout, " Encryption: %02X\n", header->partitioncrypttype[i]); diff --git a/ctrtool/ncsd.h b/ctrtool/ncsd.h index afd895a..2d6ee53 100644 --- a/ctrtool/ncsd.h +++ b/ctrtool/ncsd.h @@ -25,7 +25,7 @@ typedef struct u8 additionalheadersize[4]; u8 sectorzerooffset[4]; u8 flags[8]; - u8 partitionid[0x40]; + u8 titleid[0x40]; u8 reserved[0x30]; } ctr_ncsdheader;