ctrtool: Add support for inline decryption

This commit is contained in:
Michael Scire
2017-05-19 08:34:50 -07:00
parent 7dcc166403
commit 4c63561224
17 changed files with 502 additions and 148 deletions
+19 -5
View File
@@ -2,6 +2,7 @@
#include <string.h>
#include <stdlib.h>
#include "aes_keygen.h"
#include "tik.h"
#include "ctr.h"
#include "utils.h"
@@ -31,9 +32,9 @@ void tik_set_usersettings(tik_context* ctx, settings* usersettings)
ctx->usersettings = usersettings;
}
void tik_get_decrypted_titlekey(tik_context* ctx, u8 decryptedkey[0x10])
void tik_get_titlekey(tik_context* ctx, u8 key[0x10])
{
memcpy(decryptedkey, ctx->titlekey, 16);
memcpy(ctx->titlekey, key, 16);
}
void tik_get_titleid(tik_context* ctx, u8 titleid[8])
@@ -50,16 +51,29 @@ void tik_get_iv(tik_context* ctx, u8 iv[16])
void tik_decrypt_titlekey(tik_context* ctx, u8 decryptedkey[0x10])
{
u8 iv[16];
u8* key = settings_get_common_key(ctx->usersettings);
u8* keyX = settings_get_common_keyX(ctx->usersettings);
const u8 keyYs[6][16] = {
// application titles (eShop titles)
{0xd0, 0x7b, 0x33, 0x7f, 0x9c, 0xa4, 0x38, 0x59, 0x32, 0xa2, 0xe2, 0x57, 0x23, 0x23, 0x2e, 0xb9},
// system titles
{0x0c, 0x76, 0x72, 0x30, 0xf0, 0x99, 0x8f, 0x1c, 0x46, 0x82, 0x82, 0x02, 0xfa, 0xac, 0xbe, 0x4c},
// these are unused
{0xc4, 0x75, 0xcb, 0x3a, 0xb8, 0xc7, 0x88, 0xbb, 0x57, 0x5e, 0x12, 0xa1, 0x09, 0x07, 0xb8, 0xa4},
{0xe4, 0x86, 0xee, 0xe3, 0xd0, 0xc0, 0x9c, 0x90, 0x2f, 0x66, 0x86, 0xd4, 0xc0, 0x6f, 0x64, 0x9f},
{0xed, 0x31, 0xba, 0x9c, 0x04, 0xb0, 0x67, 0x50, 0x6c, 0x44, 0x97, 0xa3, 0x5b, 0x78, 0x04, 0xfc},
{0x5e, 0x66, 0x99, 0x8a, 0xb4, 0xe8, 0x93, 0x16, 0x06, 0x85, 0x0f, 0xd7, 0xa1, 0x6d, 0xd7, 0x55},
};
u8 key[16];
memset(decryptedkey, 0, 0x10);
if (!key)
if (!keyX)
{
fprintf(stdout, "Warning, could not read common key.\n");
}
else
{
ctr_aes_keygen(keyX, keyYs[(ctx->tik.title_id[3] & 0x10) ? 1 : 0], key);
memset(iv, 0, 0x10);
memcpy(iv, ctx->tik.title_id, 8);
@@ -108,7 +122,7 @@ void tik_print(tik_context* ctx)
memdump(stdout, "Encrypted Titlekey: ", tik->encrypted_title_key, 0x10);
if (settings_get_common_key(ctx->usersettings))
if (settings_get_common_keyX(ctx->usersettings))
memdump(stdout, "Decrypted Titlekey: ", ctx->titlekey, 0x10);
memdump(stdout, "Ticket ID: ", tik->ticket_id, 0x08);