hactool/pki.h

244 lines
14 KiB
C

#ifndef NCATOOL_PKI_H
#define NCATOOL_PKI_H
#include <string.h>
#include "types.h"
#include "settings.h"
#define ZEROES_KEY {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
#define ZEROES_XTS_KEY {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
#define ZEROES_KAEKS {ZEROES_KEY, ZEROES_KEY, ZEROES_KEY}
/* TODO: Design consideration -- should I store the master keys and derive */
/* the titlekeks and the body kaeks? Worth considering... */
const nca_keyset_t nca_keys_retail = {
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, 0xDF, 0x27, 0x68, 0x3C, 0xC1, 0xA0,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nca_keys_dev = {
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, 0x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x4B,
0x26, 0x8C, 0x0C, 0x3E, 0x03, 0xD2, 0xA3, 0x55, 0x5C, 0x7D, 0xC0, 0x5D, 0x9D, 0xFF, 0x13, 0x2F,
0xFD, 0x19, 0xBF, 0xED, 0x44, 0xC3, 0x8C, 0xA7, 0x28, 0xCB, 0xE5, 0xE0, 0xB1, 0xA7, 0x9C, 0x33,
0x8D, 0xB8, 0x6E, 0xDE, 0x87, 0x18, 0x22, 0x60, 0xC4, 0xAE, 0xF2, 0x87, 0x9F, 0xCE, 0x09, 0x5C,
0xB5, 0x99, 0xA5, 0x9F, 0x49, 0xF2, 0xD7, 0x58, 0xFA, 0xF9, 0xC0, 0x25, 0x7D, 0xD6, 0xCB, 0xF3,
0xD8, 0x6C, 0xA2, 0x69, 0x91, 0x68, 0x73, 0xB1, 0x94, 0x6F, 0xA3, 0xF3, 0xB9, 0x7D, 0xF8, 0xE0,
0x72, 0x9E, 0x93, 0x7B, 0x7A, 0xA2, 0x57, 0x60, 0xB7, 0x5B, 0xA9, 0x84, 0xAE, 0x64, 0x88, 0x69
}
};
static inline 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;
}
}
#endif