[ctrtool] Fixed seed crypto.

This commit is contained in:
jakcron
2017-06-06 12:44:12 +08:00
parent 4cba5c83df
commit 20f708450b
8 changed files with 18 additions and 18 deletions
+2 -2
View File
@@ -33,9 +33,9 @@ void exefs_set_usersettings(exefs_context* ctx, settings* usersettings)
ctx->usersettings = 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) void exefs_set_compressedflag(exefs_context* ctx, int compressedflag)
+2 -2
View File
@@ -27,7 +27,7 @@ typedef struct
{ {
FILE* file; FILE* file;
settings* usersettings; settings* usersettings;
u8 partitionid[8]; u8 titleid[8];
u8 counter[16]; u8 counter[16];
u8 key[2][16]; u8 key[2][16];
u64 offset; 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_offset(exefs_context* ctx, u64 offset);
void exefs_set_size(exefs_context* ctx, u64 size); void exefs_set_size(exefs_context* ctx, u64 size);
void exefs_set_usersettings(exefs_context* ctx, settings* usersettings); 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_counter(exefs_context* ctx, u8 counter[16]);
void exefs_set_compressedflag(exefs_context* ctx, int compressedflag); void exefs_set_compressedflag(exefs_context* ctx, int compressedflag);
void exefs_set_keys(exefs_context* ctx, u8 key[16], u8 special_key[16]); void exefs_set_keys(exefs_context* ctx, u8 key[16], u8 special_key[16]);
+2 -2
View File
@@ -34,9 +34,9 @@ void exheader_set_usersettings(exheader_context* ctx, settings* usersettings)
ctx->usersettings = 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]) void exheader_set_programid(exheader_context* ctx, u8 programid[8])
+2 -2
View File
@@ -149,7 +149,7 @@ typedef struct
int haveread; int haveread;
FILE* file; FILE* file;
settings* usersettings; settings* usersettings;
u8 partitionid[8]; u8 titleid[8];
u8 programid[8]; u8 programid[8];
u8 hash[32]; u8 hash[32];
u8 counter[16]; 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_file(exheader_context* ctx, FILE* file);
void exheader_set_offset(exheader_context* ctx, u64 offset); void exheader_set_offset(exheader_context* ctx, u64 offset);
void exheader_set_size(exheader_context* ctx, u64 size); 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_counter(exheader_context* ctx, u8 counter[16]);
void exheader_set_programid(exheader_context* ctx, u8 programid[8]); void exheader_set_programid(exheader_context* ctx, u8 programid[8]);
void exheader_set_hash(exheader_context* ctx, u8 hash[32]); void exheader_set_hash(exheader_context* ctx, u8 hash[32]);
+7 -7
View File
@@ -50,7 +50,7 @@ void ncch_get_counter(ncch_context* ctx, u8 counter[16], u8 type)
{ {
u32 version = getle16(ctx->header.version); u32 version = getle16(ctx->header.version);
u32 mediaunitsize = (u32) ncch_get_mediaunit_size(ctx); u32 mediaunitsize = (u32) ncch_get_mediaunit_size(ctx);
u8* partitionid = ctx->header.partitionid; u8* titleid = ctx->header.titleid;
u32 i; u32 i;
u64 x = 0; u64 x = 0;
@@ -59,7 +59,7 @@ void ncch_get_counter(ncch_context* ctx, u8 counter[16], u8 type)
if (version == 2 || version == 0) if (version == 2 || version == 0)
{ {
for(i=0; i<8; i++) for(i=0; i<8; i++)
counter[i] = partitionid[7-i]; counter[i] = titleid[7-i];
counter[8] = type; counter[8] = type;
} }
else if (version == 1) 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; x = getle32(ctx->header.romfsoffset) * mediaunitsize;
for(i=0; i<8; i++) for(i=0; i<8; i++)
counter[i] = partitionid[i]; counter[i] = titleid[i];
for(i=0; i<4; i++) for(i=0; i<4; i++)
counter[12+i] = (u8) (x>>((3-i)*8)); 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_offset(&ctx->exheader, ncch_get_exheader_offset(ctx) );
exheader_set_size(&ctx->exheader, ncch_get_exheader_size(ctx) ); exheader_set_size(&ctx->exheader, ncch_get_exheader_size(ctx) );
exheader_set_usersettings(&ctx->exheader, ctx->usersettings); 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_programid(&ctx->exheader, ctx->header.programid);
exheader_set_hash(&ctx->exheader, ctx->header.extendedheaderhash); exheader_set_hash(&ctx->exheader, ctx->header.extendedheaderhash);
exheader_set_counter(&ctx->exheader, exheadercounter); 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_file(&ctx->exefs, ctx->file);
exefs_set_offset(&ctx->exefs, ncch_get_exefs_offset(ctx) ); exefs_set_offset(&ctx->exefs, ncch_get_exefs_offset(ctx) );
exefs_set_size(&ctx->exefs, ncch_get_exefs_size(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_usersettings(&ctx->exefs, ctx->usersettings);
exefs_set_counter(&ctx->exefs, exefscounter); exefs_set_counter(&ctx->exefs, exefscounter);
exefs_set_keys(&ctx->exefs, ctx->key[0], ctx->key[1]); 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 // - get keyY
if (header->flags[7] & 0x20) 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) if (!seed)
{ {
fprintf(stderr, "This title uses seed crypto, but no seed is set, unable to decrypt.\n" 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 else
memdump(stdout, "Signature (FAIL): ", header->signature, 0x100); memdump(stdout, "Signature (FAIL): ", header->signature, 0x100);
fprintf(stdout, "Content size: 0x%08"PRIx64"\n", getle32(header->contentsize)*mediaunitsize); 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, "Maker code: %.2s\n", header->makercode);
fprintf(stdout, "Version: %d\n", getle16(header->version)); fprintf(stdout, "Version: %d\n", getle16(header->version));
fprintf(stdout, "Title seed check: %08x\n", getle32(header->seedcheck)); fprintf(stdout, "Title seed check: %08x\n", getle32(header->seedcheck));
+1 -1
View File
@@ -33,7 +33,7 @@ typedef struct
u8 signature[0x100]; u8 signature[0x100];
u8 magic[4]; u8 magic[4];
u8 contentsize[4]; u8 contentsize[4];
u8 partitionid[8]; u8 titleid[8];
u8 makercode[2]; u8 makercode[2];
u8 version[2]; u8 version[2];
u8 seedcheck[4]; u8 seedcheck[4];
+1 -1
View File
@@ -147,7 +147,7 @@ void ncsd_print(ncsd_context* ctx)
if (partitionsize != 0) if (partitionsize != 0)
{ {
fprintf(stdout, "Partition %d \n", i); 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, " Area: 0x%08X-0x%08X\n", partitionoffset, partitionoffset+partitionsize);
fprintf(stdout, " Filesystem: %02X\n", header->partitionfstype[i]); fprintf(stdout, " Filesystem: %02X\n", header->partitionfstype[i]);
fprintf(stdout, " Encryption: %02X\n", header->partitioncrypttype[i]); fprintf(stdout, " Encryption: %02X\n", header->partitioncrypttype[i]);
+1 -1
View File
@@ -25,7 +25,7 @@ typedef struct
u8 additionalheadersize[4]; u8 additionalheadersize[4];
u8 sectorzerooffset[4]; u8 sectorzerooffset[4];
u8 flags[8]; u8 flags[8];
u8 partitionid[0x40]; u8 titleid[0x40];
u8 reserved[0x30]; u8 reserved[0x30];
} ctr_ncsdheader; } ctr_ncsdheader;