mirror of
https://github.com/SciresM/hactool
synced 2024-11-10 06:34:14 +00:00
383 lines
No EOL
20 KiB
C
383 lines
No EOL
20 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "aes.h"
|
|
#include "pki.h"
|
|
|
|
const nca_keyset_t nca_keys_retail = {
|
|
{
|
|
ZEROES_KEY, /* Master Key 00 */
|
|
ZEROES_KEY, /* Master Key 01 */
|
|
ZEROES_KEY, /* Master Key 02 */
|
|
ZEROES_KEY, /* Master Key 03 */
|
|
ZEROES_KEY, /* Master Key 04 */
|
|
ZEROES_KEY, /* Master Key 05 */
|
|
ZEROES_KEY, /* Master Key 06 */
|
|
ZEROES_KEY, /* Master Key 07 */
|
|
ZEROES_KEY, /* Master Key 08 */
|
|
ZEROES_KEY, /* Master Key 09 */
|
|
ZEROES_KEY, /* Master Key 10 */
|
|
ZEROES_KEY, /* Master Key 11 */
|
|
ZEROES_KEY, /* Master Key 12 */
|
|
ZEROES_KEY, /* Master Key 13 */
|
|
ZEROES_KEY, /* Master Key 14 */
|
|
ZEROES_KEY, /* Master Key 15 */
|
|
ZEROES_KEY, /* Master Key 16 */
|
|
ZEROES_KEY, /* Master Key 17 */
|
|
ZEROES_KEY, /* Master Key 18 */
|
|
ZEROES_KEY, /* Master Key 19 */
|
|
ZEROES_KEY, /* Master Key 20 */
|
|
ZEROES_KEY, /* Master Key 21 */
|
|
ZEROES_KEY, /* Master Key 22 */
|
|
ZEROES_KEY, /* Master Key 23 */
|
|
ZEROES_KEY, /* Master Key 24 */
|
|
ZEROES_KEY, /* Master Key 25 */
|
|
ZEROES_KEY, /* Master Key 26 */
|
|
ZEROES_KEY, /* Master Key 27 */
|
|
ZEROES_KEY, /* Master Key 28 */
|
|
ZEROES_KEY, /* Master Key 29 */
|
|
ZEROES_KEY, /* Master Key 30 */
|
|
ZEROES_KEY /* Master Key 31 */
|
|
},
|
|
ZEROES_KEY, /* Generate Aes Kek Source */
|
|
ZEROES_KEY, /* Generate Aes Key Source */
|
|
ZEROES_KEY, /* Key Area Encryption Key Source Application */
|
|
ZEROES_KEY, /* Key Area Encryption Key Source Ocean */
|
|
ZEROES_KEY, /* Key Area Encryption Key Source System */
|
|
ZEROES_KEY, /* Titlekek Source */
|
|
ZEROES_KEY, /* Headerkek Source */
|
|
ZEROES_XTS_KEY, /* Encrypted Header Key */
|
|
ZEROES_XTS_KEY, /* Header key */
|
|
{
|
|
ZEROES_KEY, /* Titlekek 00 */
|
|
ZEROES_KEY, /* Titlekek 01 */
|
|
ZEROES_KEY, /* Titlekek 02 */
|
|
ZEROES_KEY, /* Titlekek 03 */
|
|
ZEROES_KEY, /* Titlekek 04 */
|
|
ZEROES_KEY, /* Titlekek 05 */
|
|
ZEROES_KEY, /* Titlekek 06 */
|
|
ZEROES_KEY, /* Titlekek 07 */
|
|
ZEROES_KEY, /* Titlekek 08 */
|
|
ZEROES_KEY, /* Titlekek 09 */
|
|
ZEROES_KEY, /* Titlekek 10 */
|
|
ZEROES_KEY, /* Titlekek 11 */
|
|
ZEROES_KEY, /* Titlekek 12 */
|
|
ZEROES_KEY, /* Titlekek 13 */
|
|
ZEROES_KEY, /* Titlekek 14 */
|
|
ZEROES_KEY, /* Titlekek 15 */
|
|
ZEROES_KEY, /* Titlekek 16 */
|
|
ZEROES_KEY, /* Titlekek 17 */
|
|
ZEROES_KEY, /* Titlekek 18 */
|
|
ZEROES_KEY, /* Titlekek 19 */
|
|
ZEROES_KEY, /* Titlekek 20 */
|
|
ZEROES_KEY, /* Titlekek 21 */
|
|
ZEROES_KEY, /* Titlekek 22 */
|
|
ZEROES_KEY, /* Titlekek 23 */
|
|
ZEROES_KEY, /* Titlekek 24 */
|
|
ZEROES_KEY, /* Titlekek 25 */
|
|
ZEROES_KEY, /* Titlekek 26 */
|
|
ZEROES_KEY, /* Titlekek 27 */
|
|
ZEROES_KEY, /* Titlekek 28 */
|
|
ZEROES_KEY, /* Titlekek 29 */
|
|
ZEROES_KEY, /* Titlekek 30 */
|
|
ZEROES_KEY /* Titlekek 31 */
|
|
},
|
|
{
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 00 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 01 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 02 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 03 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 04 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 05 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 06 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 07 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 08 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 09 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 10 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 11 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 12 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 13 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 14 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 15 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 16 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 17 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 18 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 19 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 20 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 21 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 22 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 23 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 24 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 25 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 26 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 27 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 28 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 29 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 30 */
|
|
ZEROES_KAEKS /* Key Area Encryption Keyset 31 */
|
|
},
|
|
{ /* Fixed RSA key used to validate NCA signature 0. */
|
|
0xBF, 0xBE, 0x40, 0x6C, 0xF4, 0xA7, 0x80, 0xE9, 0xF0, 0x7D, 0x0C, 0x99, 0x61, 0x1D, 0x77, 0x2F,
|
|
0x96, 0xBC, 0x4B, 0x9E, 0x58, 0x38, 0x1B, 0x03, 0xAB, 0xB1, 0x75, 0x49, 0x9F, 0x2B, 0x4D, 0x58,
|
|
0x34, 0xB0, 0x05, 0xA3, 0x75, 0x22, 0xBE, 0x1A, 0x3F, 0x03, 0x73, 0xAC, 0x70, 0x68, 0xD1, 0x16,
|
|
0xB9, 0x04, 0x46, 0x5E, 0xB7, 0x07, 0x91, 0x2F, 0x07, 0x8B, 0x26, 0xDE, 0xF6, 0x00, 0x07, 0xB2,
|
|
0xB4, 0x51, 0xF8, 0x0D, 0x0A, 0x5E, 0x58, 0xAD, 0xEB, 0xBC, 0x9A, 0xD6, 0x49, 0xB9, 0x64, 0xEF,
|
|
0xA7, 0x82, 0xB5, 0xCF, 0x6D, 0x70, 0x13, 0xB0, 0x0F, 0x85, 0xF6, 0xA9, 0x08, 0xAA, 0x4D, 0x67,
|
|
0x66, 0x87, 0xFA, 0x89, 0xFF, 0x75, 0x90, 0x18, 0x1E, 0x6B, 0x3D, 0xE9, 0x8A, 0x68, 0xC9, 0x26,
|
|
0x04, 0xD9, 0x80, 0xCE, 0x3F, 0x5E, 0x92, 0xCE, 0x01, 0xFF, 0x06, 0x3B, 0xF2, 0xC1, 0xA9, 0x0C,
|
|
0xCE, 0x02, 0x6F, 0x16, 0xBC, 0x92, 0x42, 0x0A, 0x41, 0x64, 0xCD, 0x52, 0xB6, 0x34, 0x4D, 0xAE,
|
|
0xC0, 0x2E, 0xDE, 0xA4, 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9F, 0x10, 0x61, 0xCD, 0x7B,
|
|
0x5B, 0x32, 0x4C, 0x37, 0xEF, 0xB1, 0x71, 0x68, 0x53, 0x0A, 0xED, 0x51, 0x7D, 0x35, 0x22, 0xFD
|
|
}
|
|
};
|
|
|
|
const nca_keyset_t nca_keys_dev = {
|
|
{
|
|
ZEROES_KEY, /* Master Key 00 */
|
|
ZEROES_KEY, /* Master Key 01 */
|
|
ZEROES_KEY, /* Master Key 02 */
|
|
ZEROES_KEY, /* Master Key 03 */
|
|
ZEROES_KEY, /* Master Key 04 */
|
|
ZEROES_KEY, /* Master Key 05 */
|
|
ZEROES_KEY, /* Master Key 06 */
|
|
ZEROES_KEY, /* Master Key 07 */
|
|
ZEROES_KEY, /* Master Key 08 */
|
|
ZEROES_KEY, /* Master Key 09 */
|
|
ZEROES_KEY, /* Master Key 10 */
|
|
ZEROES_KEY, /* Master Key 11 */
|
|
ZEROES_KEY, /* Master Key 12 */
|
|
ZEROES_KEY, /* Master Key 13 */
|
|
ZEROES_KEY, /* Master Key 14 */
|
|
ZEROES_KEY, /* Master Key 15 */
|
|
ZEROES_KEY, /* Master Key 16 */
|
|
ZEROES_KEY, /* Master Key 17 */
|
|
ZEROES_KEY, /* Master Key 18 */
|
|
ZEROES_KEY, /* Master Key 19 */
|
|
ZEROES_KEY, /* Master Key 20 */
|
|
ZEROES_KEY, /* Master Key 21 */
|
|
ZEROES_KEY, /* Master Key 22 */
|
|
ZEROES_KEY, /* Master Key 23 */
|
|
ZEROES_KEY, /* Master Key 24 */
|
|
ZEROES_KEY, /* Master Key 25 */
|
|
ZEROES_KEY, /* Master Key 26 */
|
|
ZEROES_KEY, /* Master Key 27 */
|
|
ZEROES_KEY, /* Master Key 28 */
|
|
ZEROES_KEY, /* Master Key 29 */
|
|
ZEROES_KEY, /* Master Key 30 */
|
|
ZEROES_KEY /* Master Key 31 */
|
|
},
|
|
ZEROES_KEY, /* Generate Aes Kek Source */
|
|
ZEROES_KEY, /* Generate Aes Key Source */
|
|
ZEROES_KEY, /* Key Area Encryption Key Source Application */
|
|
ZEROES_KEY, /* Key Area Encryption Key Source Ocean */
|
|
ZEROES_KEY, /* Key Area Encryption Key Source System */
|
|
ZEROES_KEY, /* Titlekek Source */
|
|
ZEROES_KEY, /* Headerkek Source */
|
|
ZEROES_XTS_KEY, /* Encrypted Header Key */
|
|
ZEROES_XTS_KEY, /* Header key */
|
|
{
|
|
ZEROES_KEY, /* Titlekek 00 */
|
|
ZEROES_KEY, /* Titlekek 01 */
|
|
ZEROES_KEY, /* Titlekek 02 */
|
|
ZEROES_KEY, /* Titlekek 03 */
|
|
ZEROES_KEY, /* Titlekek 04 */
|
|
ZEROES_KEY, /* Titlekek 05 */
|
|
ZEROES_KEY, /* Titlekek 06 */
|
|
ZEROES_KEY, /* Titlekek 07 */
|
|
ZEROES_KEY, /* Titlekek 08 */
|
|
ZEROES_KEY, /* Titlekek 09 */
|
|
ZEROES_KEY, /* Titlekek 10 */
|
|
ZEROES_KEY, /* Titlekek 11 */
|
|
ZEROES_KEY, /* Titlekek 12 */
|
|
ZEROES_KEY, /* Titlekek 13 */
|
|
ZEROES_KEY, /* Titlekek 14 */
|
|
ZEROES_KEY, /* Titlekek 15 */
|
|
ZEROES_KEY, /* Titlekek 16 */
|
|
ZEROES_KEY, /* Titlekek 17 */
|
|
ZEROES_KEY, /* Titlekek 18 */
|
|
ZEROES_KEY, /* Titlekek 19 */
|
|
ZEROES_KEY, /* Titlekek 20 */
|
|
ZEROES_KEY, /* Titlekek 21 */
|
|
ZEROES_KEY, /* Titlekek 22 */
|
|
ZEROES_KEY, /* Titlekek 23 */
|
|
ZEROES_KEY, /* Titlekek 24 */
|
|
ZEROES_KEY, /* Titlekek 25 */
|
|
ZEROES_KEY, /* Titlekek 26 */
|
|
ZEROES_KEY, /* Titlekek 27 */
|
|
ZEROES_KEY, /* Titlekek 28 */
|
|
ZEROES_KEY, /* Titlekek 29 */
|
|
ZEROES_KEY, /* Titlekek 30 */
|
|
ZEROES_KEY /* Titlekek 31 */
|
|
},
|
|
{
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 00 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 01 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 02 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 03 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 04 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 05 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 06 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 07 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 08 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 09 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 10 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 11 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 12 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 13 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 14 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 15 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 16 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 17 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 18 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 19 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 20 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 21 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 22 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 23 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 24 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 25 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 26 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 27 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 28 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 29 */
|
|
ZEROES_KAEKS, /* Key Area Encryption Keyset 30 */
|
|
ZEROES_KAEKS /* Key Area Encryption Keyset 31 */
|
|
},
|
|
{
|
|
0xD8, 0xF1, 0x18, 0xEF, 0x32, 0x72, 0x4C, 0xA7, 0x47, 0x4C, 0xB9, 0xEA, 0xB3, 0x04, 0xA8, 0xA4,
|
|
0xAC, 0x99, 0x08, 0x08, 0x04, 0xBF, 0x68, 0x57, 0xB8, 0x43, 0x94, 0x2B, 0xC7, 0xB9, 0x66, 0x49,
|
|
0x85, 0xE5, 0x8A, 0x9B, 0xC1, 0x00, 0x9A, 0x6A, 0x8D, 0xD0, 0xEF, 0xCE, 0xFF, 0x86, 0xC8, 0x5C,
|
|
0x5D, 0xE9, 0x53, 0x7B, 0x19, 0x2A, 0xA8, 0xC0, 0x22, 0xD1, 0xF3, 0x22, 0x0A, 0x50, 0xF2, 0x2B,
|
|
0x65, 0x05, 0x1B, 0x9E, 0xEC, 0x61, 0xB5, 0x63, 0xA3, 0x6F, 0x3B, 0xBA, 0x63, 0x3A, 0x53, 0xF4,
|
|
0x49, 0x2F, 0xCF, 0x03, 0xCC, 0xD7, 0x50, 0x82, 0x1B, 0x29, 0x4F, 0x08, 0xDE, 0x1B, 0x6D, 0x47,
|
|
0x4F, 0xA8, 0xB6, 0x6A, 0x26, 0xA0, 0x83, 0x3F, 0x1A, 0xAF, 0x83, 0x8F, 0x0E, 0x17, 0x3F, 0xFE,
|
|
0x44, 0x1C, 0x56, 0x94, 0x2E, 0x49, 0x83, 0x83, 0x03, 0xE9, 0xB6, 0xAD, 0xD5, 0xDE, 0xE3, 0x2D,
|
|
0xA1, 0xD9, 0x66, 0x20, 0x5D, 0x1F, 0x5E, 0x96, 0x5D, 0x5B, 0x55, 0x0D, 0xD4, 0xB4, 0x77, 0x6E,
|
|
0xAE, 0x1B, 0x69, 0xF3, 0xA6, 0x61, 0x0E, 0x51, 0x62, 0x39, 0x28, 0x63, 0x75, 0x76, 0xBF, 0xB0,
|
|
0xD2, 0x22, 0xEF, 0x98, 0x25, 0x02, 0x05, 0xC0, 0xD7, 0x6A, 0x06, 0x2C, 0xA5, 0xD8, 0x5A, 0x9D,
|
|
0x7A, 0xA4, 0x21, 0x55, 0x9F, 0xF9, 0x3E, 0xBF, 0x16, 0xF6, 0x07, 0xC2, 0xB9, 0x6E, 0x87, 0x9E,
|
|
0xB5, 0x1C, 0xBE, 0x97, 0xFA, 0x82, 0x7E, 0xED, 0x30, 0xD4, 0x66, 0x3F, 0xDE, 0xD8, 0x1B, 0x4B,
|
|
0x15, 0xD9, 0xFB, 0x2F, 0x50, 0xF0, 0x9D, 0x1D, 0x52, 0x4C, 0x1C, 0x4D, 0x8D, 0xAE, 0x85, 0x1E,
|
|
0xEA, 0x7F, 0x86, 0xF3, 0x0B, 0x7B, 0x87, 0x81, 0x98, 0x23, 0x80, 0x63, 0x4F, 0x2F, 0xB0, 0x62,
|
|
0xCC, 0x6E, 0xD2, 0x46, 0x13, 0x65, 0x2B, 0xD6, 0x44, 0x33, 0x59, 0xB5, 0x8F, 0xB9, 0x4A, 0xA9
|
|
},
|
|
{ /* Fixed RSA key used to validate ACID signatures. */
|
|
0xD6, 0x34, 0xA5, 0x78, 0x6C, 0x68, 0xCE, 0x5A, 0xC2, 0x37, 0x17, 0xF3, 0x82, 0x45, 0xC6, 0x89,
|
|
0xE1, 0x2D, 0x06, 0x67, 0xBF, 0xB4, 0x06, 0x19, 0x55, 0x6B, 0x27, 0x66, 0x0C, 0xA4, 0xB5, 0x87,
|
|
0x81, 0x25, 0xF4, 0x30, 0xBC, 0x53, 0x08, 0x68, 0xA2, 0x48, 0x49, 0x8C, 0x3F, 0x38, 0x40, 0x9C,
|
|
0xC4, 0x26, 0xF4, 0x79, 0xE2, 0xA1, 0x85, 0xF5, 0x5C, 0x7F, 0x58, 0xBA, 0xA6, 0x1C, 0xA0, 0x8B,
|
|
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7D, 0xF8, 0xE0,
|
|
0x72, 0x9E, 0x93, 0x7B, 0x7A, 0xA2, 0x57, 0x60, 0xB7, 0x5B, 0xA9, 0x84, 0xAE, 0x64, 0x88, 0x69
|
|
}
|
|
};
|
|
|
|
|
|
void generate_kek(unsigned char *dst, const unsigned char *src, const unsigned char *master_key, const unsigned char *kek_seed, const unsigned char *key_seed) {
|
|
unsigned char kek[0x10];
|
|
unsigned char src_kek[0x10];
|
|
aes_ctx_t *master_ctx = new_aes_ctx(master_key, 0x10, AES_MODE_ECB);
|
|
aes_decrypt(master_ctx, kek, kek_seed, 0x10);
|
|
free_aes_ctx(master_ctx);
|
|
|
|
aes_ctx_t *kek_ctx = new_aes_ctx(kek, 0x10, AES_MODE_ECB);
|
|
aes_decrypt(kek_ctx, src_kek, src, 0x10);
|
|
free_aes_ctx(kek_ctx);
|
|
|
|
if (key_seed != NULL) {
|
|
aes_ctx_t *key_ctx = new_aes_ctx(src_kek, 0x10, AES_MODE_ECB);
|
|
aes_decrypt(key_ctx, dst, key_seed, 0x10);
|
|
free_aes_ctx(key_ctx);
|
|
} else {
|
|
memcpy(dst, src_kek, 0x10);
|
|
}
|
|
}
|
|
|
|
void pki_derive_keys(nca_keyset_t *keyset) {
|
|
unsigned char zeroes[0x100];
|
|
memset(zeroes, 0, 0x100);
|
|
/* Derive keys as necessary. */
|
|
for (unsigned int i = 0; i < 0x20; i++) {
|
|
if (memcmp(&keyset->master_keys[i], zeroes, 0x10) == 0) {
|
|
continue;
|
|
}
|
|
|
|
aes_ctx_t *master_ctx = new_aes_ctx(&keyset->master_keys[i], 0x10, AES_MODE_ECB);
|
|
|
|
/* Derive Key Area Encryption Keys */
|
|
if (memcmp(keyset->key_area_key_application_source, zeroes, 0x10) != 0) {
|
|
generate_kek(keyset->key_area_keys[i][0], keyset->key_area_key_application_source, keyset->master_keys[i], keyset->aes_kek_generation_source, keyset->aes_key_generation_source);
|
|
}
|
|
if (memcmp(keyset->key_area_key_ocean_source, zeroes, 0x10) != 0) {
|
|
generate_kek(keyset->key_area_keys[i][1], keyset->key_area_key_ocean_source, keyset->master_keys[i], keyset->aes_kek_generation_source, keyset->aes_key_generation_source);
|
|
}
|
|
if (memcmp(keyset->key_area_key_system_source, zeroes, 0x10) != 0) {
|
|
generate_kek(keyset->key_area_keys[i][2], keyset->key_area_key_system_source, keyset->master_keys[i], keyset->aes_kek_generation_source, keyset->aes_key_generation_source);
|
|
}
|
|
|
|
/* Derive Titlekek */
|
|
if (memcmp(keyset->titlekek_source, zeroes, 0x10) != 0) {
|
|
aes_decrypt(master_ctx, &keyset->titlekeks[i], keyset->titlekek_source, 0x10);
|
|
}
|
|
|
|
/* Derive Header Key */
|
|
if (i == 0 && memcmp(keyset->header_kek_source, zeroes, 0x10) != 0 && memcmp(keyset->encrypted_header_key, zeroes, 0x20) != 0) {
|
|
unsigned char header_kek[0x10];
|
|
generate_kek(header_kek, keyset->header_kek_source, keyset->master_keys[i], keyset->aes_kek_generation_source, keyset->aes_key_generation_source);
|
|
aes_ctx_t *header_ctx = new_aes_ctx(header_kek, 0x10, AES_MODE_ECB);
|
|
aes_decrypt(header_ctx, keyset->header_key, keyset->encrypted_header_key, 0x20);
|
|
free_aes_ctx(header_ctx);
|
|
}
|
|
|
|
free_aes_ctx(master_ctx);
|
|
}
|
|
|
|
}
|
|
|
|
void pki_initialize_keyset(nca_keyset_t *keyset, keyset_variant_t variant) {
|
|
switch (variant) {
|
|
case KEYSET_DEV:
|
|
memcpy(keyset, &nca_keys_dev, sizeof(*keyset));
|
|
break;
|
|
case KEYSET_RETAIL:
|
|
memcpy(keyset, &nca_keys_retail, sizeof(*keyset));
|
|
break;
|
|
default:
|
|
memset(keyset, 0, sizeof(*keyset));
|
|
break;
|
|
}
|
|
|
|
pki_derive_keys(keyset);
|
|
|
|
} |