1
0
Fork 0
mirror of https://github.com/DarkMatterCore/nxdumptool.git synced 2024-11-22 18:26:39 +00:00
nxdumptool/source/keys.h

66 lines
2.8 KiB
C
Raw Normal View History

2019-06-05 23:44:18 +01:00
#pragma once
#ifndef __KEYS_H__
#define __KEYS_H__
#include <switch.h>
#include "nca.h"
2019-06-09 02:36:21 +01:00
#define FS_TID (u64)0x0100000000000000
#define SEG_TEXT BIT(0)
#define SEG_RODATA BIT(1)
#define SEG_DATA BIT(2)
2020-03-30 22:10:07 +01:00
#define ETICKET_DEVKEY_RSA_CTR_SIZE 0x10
#define ETICKET_DEVKEY_RSA_OFFSET ETICKET_DEVKEY_RSA_CTR_SIZE
#define ETICKET_DEVKEY_RSA_SIZE 0x230
2019-06-05 23:44:18 +01:00
2019-06-09 02:36:21 +01:00
#define SIGTYPE_RSA2048_SHA1 (u32)0x10001
#define SIGTYPE_RSA2048_SHA256 (u32)0x10004
2019-06-05 23:44:18 +01:00
typedef struct {
u64 titleID;
u8 mask;
u8 *data;
u64 dataSize;
2020-03-30 22:10:07 +01:00
} keyLocation;
2019-06-05 23:44:18 +01:00
typedef struct {
char name[128];
2019-10-17 21:15:35 +01:00
u8 hash[SHA256_HASH_SIZE];
2019-06-05 23:44:18 +01:00
u64 size;
2020-03-30 22:10:07 +01:00
} keyInfo;
2019-06-05 23:44:18 +01:00
typedef struct {
2019-06-09 02:36:21 +01:00
u16 memory_key_cnt; /* Key counter for keys retrieved from memory. */
u16 ext_key_cnt; /* Key counter for keys retrieved from keysfile. */
u32 total_key_cnt; /* Total key counter. */
// Needed to decrypt the NCA header using AES-128-XTS
2019-11-06 18:22:40 +00:00
u8 header_kek_source[0x10]; /* Seed for header kek. Retrieved from the .rodata section in the FS sysmodule. */
u8 header_key_source[0x20]; /* Seed for NCA header key. Retrieved from the .data section in the FS sysmodule. */
u8 header_kek[0x10]; /* NCA header kek. Generated from header_kek_source. */
u8 header_key[0x20]; /* NCA header key. Generated from header_kek and header_key_source. */
2019-06-09 02:36:21 +01:00
2019-11-06 18:22:40 +00:00
// Needed to derive the KAEK used to decrypt the NCA key area
u8 key_area_key_application_source[0x10]; /* Seed for kaek 0. Retrieved from the .rodata section in the FS sysmodule. */
u8 key_area_key_ocean_source[0x10]; /* Seed for kaek 1. Retrieved from the .rodata section in the FS sysmodule. */
u8 key_area_key_system_source[0x10]; /* Seed for kaek 2. Retrieved from the .rodata section in the FS sysmodule. */
2019-06-09 02:36:21 +01:00
2019-11-06 18:22:40 +00:00
// Needed to decrypt the title key block from an eTicket. Retrieved from the Lockpick_RCM keys file.
2019-06-09 02:36:21 +01:00
u8 eticket_rsa_kek[0x10]; /* eTicket RSA kek. */
u8 titlekeks[0x20][0x10]; /* Title key encryption keys. */
2019-11-06 18:22:40 +00:00
// Needed to reencrypt the NCA key area for tik-less NSP dumps. Retrieved from the Lockpick_RCM keys file.
2019-06-09 02:36:21 +01:00
u8 key_area_keys[0x20][3][0x10]; /* Key area encryption keys. */
2020-03-30 22:10:07 +01:00
} nca_keyset_t;
2019-06-05 23:44:18 +01:00
2019-06-20 04:56:14 +01:00
bool loadMemoryKeys();
2019-06-05 23:44:18 +01:00
bool decryptNcaKeyArea(nca_header_t *dec_nca_header, u8 *out);
2019-06-20 04:56:14 +01:00
bool loadExternalKeys();
2019-11-06 18:22:40 +00:00
int retrieveNcaTikTitleKey(nca_header_t *dec_nca_header, u8 *out_tik, u8 *out_enc_key, u8 *out_dec_key);
2019-06-09 02:36:21 +01:00
bool generateEncryptedNcaKeyAreaWithTitlekey(nca_header_t *dec_nca_header, u8 *decrypted_nca_keys);
2019-06-05 23:44:18 +01:00
#endif