2018-04-24 05:24:20 +00:00
|
|
|
#pragma once
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
|
|
#include <fnd/types.h>
|
|
|
|
#include <crypto/aes.h>
|
|
|
|
#include <crypto/rsa.h>
|
|
|
|
#include <nx/nca.h>
|
|
|
|
|
|
|
|
static const size_t kMasterKeyNum = 0x20;
|
|
|
|
static const size_t kNcaKeakNum = nx::nca::kKeyAreaEncryptionKeyNum;
|
|
|
|
|
2018-06-03 08:48:12 +00:00
|
|
|
enum IFileOwnershipMode
|
|
|
|
{
|
|
|
|
SHARED_IFILE = false,
|
|
|
|
OWN_IFILE = true
|
|
|
|
};
|
2018-04-24 05:24:20 +00:00
|
|
|
|
|
|
|
enum FileType
|
|
|
|
{
|
|
|
|
FILE_XCI,
|
2018-05-22 02:30:31 +00:00
|
|
|
FILE_NSP,
|
2018-04-24 05:24:20 +00:00
|
|
|
FILE_PARTITIONFS,
|
|
|
|
FILE_ROMFS,
|
|
|
|
FILE_NCA,
|
|
|
|
FILE_NPDM,
|
2018-05-12 15:02:53 +00:00
|
|
|
FILE_CNMT,
|
2018-05-27 12:34:10 +00:00
|
|
|
FILE_NSO,
|
2018-06-09 15:32:35 +00:00
|
|
|
FILE_NRO,
|
2018-06-11 15:01:54 +00:00
|
|
|
FILE_NACP,
|
2018-08-06 09:11:15 +00:00
|
|
|
FILE_PKI_CERT,
|
2018-06-29 16:14:19 +00:00
|
|
|
FILE_ES_TIK,
|
2018-06-10 15:48:04 +00:00
|
|
|
FILE_HB_ASSET,
|
2018-04-24 05:24:20 +00:00
|
|
|
FILE_INVALID = -1,
|
|
|
|
};
|
|
|
|
|
2018-06-18 15:30:19 +00:00
|
|
|
enum CliOutputModeFlag
|
2018-04-24 05:24:20 +00:00
|
|
|
{
|
2018-06-18 15:30:19 +00:00
|
|
|
OUTPUT_BASIC,
|
|
|
|
OUTPUT_LAYOUT,
|
|
|
|
OUTPUT_KEY_DATA,
|
|
|
|
OUTPUT_EXTENDED
|
2018-04-24 05:24:20 +00:00
|
|
|
};
|
|
|
|
|
2018-06-18 15:30:19 +00:00
|
|
|
typedef byte_t CliOutputMode;
|
|
|
|
|
2018-04-24 05:24:20 +00:00
|
|
|
template <typename T>
|
|
|
|
struct sOptional
|
|
|
|
{
|
|
|
|
bool isSet;
|
|
|
|
T var;
|
2018-06-03 07:10:47 +00:00
|
|
|
inline sOptional() : isSet(false) {}
|
2018-04-24 05:24:20 +00:00
|
|
|
inline const T& operator=(const T& other) { isSet = true; var = other; return var; }
|
|
|
|
inline const sOptional<T>& operator=(const sOptional<T>& other)
|
|
|
|
{
|
|
|
|
isSet = other.isSet;
|
|
|
|
if (isSet) {
|
|
|
|
var = other.var;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
inline T& operator*() { return var; }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sKeyset
|
|
|
|
{
|
|
|
|
crypto::rsa::sRsa2048Key acid_sign_key;
|
|
|
|
crypto::aes::sAes128Key package1_key[kMasterKeyNum];
|
|
|
|
crypto::rsa::sRsa2048Key package2_sign_key;
|
|
|
|
crypto::aes::sAes128Key package2_key[kMasterKeyNum];
|
|
|
|
|
|
|
|
struct sNcaData
|
|
|
|
{
|
|
|
|
crypto::rsa::sRsa2048Key header_sign_key;
|
|
|
|
crypto::aes::sAesXts128Key header_key;
|
|
|
|
crypto::aes::sAes128Key key_area_key[kNcaKeakNum][kMasterKeyNum];
|
|
|
|
|
2018-05-11 09:51:14 +00:00
|
|
|
crypto::aes::sAes128Key manual_title_key_aesctr;
|
|
|
|
crypto::aes::sAesXts128Key manual_title_key_aesxts;
|
2018-04-24 05:24:20 +00:00
|
|
|
crypto::aes::sAes128Key manual_body_key_aesctr;
|
|
|
|
crypto::aes::sAesXts128Key manual_body_key_aesxts;
|
|
|
|
} nca;
|
|
|
|
|
|
|
|
struct sXciData
|
|
|
|
{
|
|
|
|
crypto::rsa::sRsa2048Key header_sign_key;
|
|
|
|
crypto::aes::sAes128Key header_key;
|
|
|
|
} xci;
|
2018-07-29 20:21:19 +00:00
|
|
|
|
2018-04-24 05:24:20 +00:00
|
|
|
struct sTicketData
|
|
|
|
{
|
|
|
|
crypto::rsa::sRsa2048Key sign_key;
|
|
|
|
crypto::aes::sAes128Key titlekey_kek[kMasterKeyNum];
|
|
|
|
} ticket;
|
2018-07-29 20:42:46 +00:00
|
|
|
|
|
|
|
struct sPkiData
|
|
|
|
{
|
|
|
|
crypto::rsa::sRsa4096Key root_sign_key;
|
|
|
|
} pki;
|
2018-04-24 05:24:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline byte_t charToByte(char chr)
|
|
|
|
{
|
|
|
|
if (chr >= 'a' && chr <= 'f')
|
|
|
|
return (chr - 'a') + 0xa;
|
|
|
|
else if (chr >= 'A' && chr <= 'F')
|
|
|
|
return (chr - 'A') + 0xa;
|
|
|
|
else if (chr >= '0' && chr <= '9')
|
|
|
|
return chr - '0';
|
|
|
|
return 0;
|
|
|
|
}
|