2018-04-21 09:23:55 +00:00
|
|
|
#pragma once
|
2018-04-07 08:01:11 +00:00
|
|
|
#include <fnd/types.h>
|
2018-08-07 08:35:03 +00:00
|
|
|
#include <fnd/aes.h>
|
|
|
|
#include <fnd/sha.h>
|
|
|
|
#include <fnd/rsa.h>
|
2018-10-22 13:30:49 +00:00
|
|
|
#include <nn/hac/define/macro.h>
|
2018-04-07 08:01:11 +00:00
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
namespace nn
|
|
|
|
{
|
|
|
|
namespace hac
|
2018-04-07 08:01:11 +00:00
|
|
|
{
|
|
|
|
namespace nca
|
|
|
|
{
|
2018-06-29 07:10:10 +00:00
|
|
|
static const uint32_t kNca2StructMagic = _MAKE_STRUCT_MAGIC_U32("NCA2");
|
|
|
|
static const uint32_t kNca3StructMagic = _MAKE_STRUCT_MAGIC_U32("NCA3");
|
2018-04-07 08:01:11 +00:00
|
|
|
static const size_t kSectorSize = 0x200;
|
|
|
|
static const size_t kPartitionNum = 4;
|
|
|
|
static const size_t kHeaderSectorNum = 6;
|
|
|
|
static const size_t kHeaderSize = kSectorSize * kHeaderSectorNum;
|
|
|
|
static const size_t kRightsIdLen = 0x10;
|
2018-10-25 12:25:31 +00:00
|
|
|
static const size_t kKeyAreaSize = 0x100;
|
|
|
|
static const size_t kKeyAreaKeyNum = kKeyAreaSize / fnd::aes::kAes128KeySize;
|
2018-04-21 09:23:55 +00:00
|
|
|
static const size_t kKeyAreaEncryptionKeyNum = 3;
|
2018-05-20 13:57:38 +00:00
|
|
|
static const size_t kFsHeaderHashSuperblockLen = 0x138;
|
2018-05-11 09:44:41 +00:00
|
|
|
static const uint16_t kDefaultFsHeaderVersion = 2;
|
2018-04-21 09:23:55 +00:00
|
|
|
|
2018-10-25 12:25:31 +00:00
|
|
|
enum HeaderFormatVersion
|
2018-04-21 09:23:55 +00:00
|
|
|
{
|
2018-10-25 12:25:31 +00:00
|
|
|
FORMAT_NCA2 = 2,
|
|
|
|
FORMAT_NCA3 = 3
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ProgramContentPartitionIndex
|
|
|
|
{
|
|
|
|
PARTITION_CODE = 0,
|
|
|
|
PARTITION_DATA = 1,
|
|
|
|
PARTITION_LOGO = 2,
|
2018-04-21 09:23:55 +00:00
|
|
|
};
|
2018-04-07 08:01:11 +00:00
|
|
|
|
|
|
|
enum DistributionType
|
|
|
|
{
|
|
|
|
DIST_DOWNLOAD,
|
|
|
|
DIST_GAME_CARD
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ContentType
|
|
|
|
{
|
|
|
|
TYPE_PROGRAM,
|
|
|
|
TYPE_META,
|
|
|
|
TYPE_CONTROL,
|
|
|
|
TYPE_MANUAL,
|
|
|
|
TYPE_DATA,
|
2018-05-11 09:44:41 +00:00
|
|
|
TYPE_PUBLIC_DATA
|
2018-04-07 08:01:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum KeyBankIndex
|
|
|
|
{
|
|
|
|
KEY_AESXTS_0,
|
|
|
|
KEY_AESXTS_1,
|
|
|
|
KEY_AESCTR,
|
|
|
|
KEY_UNUSED_3,
|
|
|
|
KEY_AESCTR_HW
|
|
|
|
};
|
|
|
|
|
|
|
|
enum KeyAreaEncryptionKeyIndex
|
|
|
|
{
|
|
|
|
KAEK_IDX_APPLICATION,
|
|
|
|
KAEK_IDX_OCEAN,
|
|
|
|
KAEK_IDX_SYSTEM
|
|
|
|
};
|
|
|
|
|
|
|
|
enum FormatType
|
|
|
|
{
|
|
|
|
FORMAT_ROMFS,
|
|
|
|
FORMAT_PFS0
|
|
|
|
};
|
|
|
|
|
|
|
|
enum HashType
|
|
|
|
{
|
|
|
|
HASH_AUTO,
|
2018-05-11 09:44:41 +00:00
|
|
|
HASH_NONE,
|
2018-04-07 08:01:11 +00:00
|
|
|
HASH_HIERARCHICAL_SHA256,
|
2018-04-21 09:23:55 +00:00
|
|
|
HASH_HIERARCHICAL_INTERGRITY // IVFC
|
2018-04-07 08:01:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum EncryptionType
|
|
|
|
{
|
|
|
|
CRYPT_AUTO,
|
|
|
|
CRYPT_NONE,
|
|
|
|
CRYPT_AESXTS,
|
|
|
|
CRYPT_AESCTR,
|
2018-05-11 09:44:41 +00:00
|
|
|
CRYPT_AESCTREX
|
2018-10-25 12:25:31 +00:00
|
|
|
};
|
2018-04-07 08:01:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma pack(push,1)
|
2018-10-25 12:25:31 +00:00
|
|
|
struct sContentArchiveHeader
|
2018-04-07 08:01:11 +00:00
|
|
|
{
|
2018-06-26 04:23:40 +00:00
|
|
|
le_uint32_t st_magic;
|
2018-04-07 08:01:11 +00:00
|
|
|
byte_t distribution_type;
|
|
|
|
byte_t content_type;
|
2018-04-25 14:58:45 +00:00
|
|
|
byte_t key_generation;
|
2018-04-07 08:01:11 +00:00
|
|
|
byte_t key_area_encryption_key_index;
|
|
|
|
le_uint64_t content_size;
|
|
|
|
le_uint64_t program_id;
|
|
|
|
le_uint32_t content_index;
|
|
|
|
le_uint32_t sdk_addon_version;
|
|
|
|
byte_t key_generation_2;
|
|
|
|
byte_t reserved_2[0xf];
|
|
|
|
byte_t rights_id[nca::kRightsIdLen];
|
2018-10-25 12:25:31 +00:00
|
|
|
struct sPartitionEntry
|
2018-04-07 08:01:11 +00:00
|
|
|
{
|
2018-10-25 12:25:31 +00:00
|
|
|
le_uint32_t start_blk; // block units
|
|
|
|
le_uint32_t end_blk; // block units
|
2018-04-07 08:01:11 +00:00
|
|
|
byte_t enabled;
|
|
|
|
byte_t reserved[7];
|
2018-10-25 12:25:31 +00:00
|
|
|
} partition_entry[nca::kPartitionNum];
|
|
|
|
fnd::sha::sSha256Hash fs_header_hash[nca::kPartitionNum];
|
|
|
|
byte_t key_area[nca::kKeyAreaSize];
|
2018-04-07 08:01:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct sNcaFsHeader
|
|
|
|
{
|
2018-05-11 09:44:41 +00:00
|
|
|
le_uint16_t version;
|
|
|
|
byte_t format_type;
|
|
|
|
byte_t hash_type;
|
|
|
|
byte_t encryption_type;
|
|
|
|
byte_t reserved_0[3];
|
2018-05-20 13:57:38 +00:00
|
|
|
byte_t hash_superblock[nca::kFsHeaderHashSuperblockLen];
|
|
|
|
byte_t aes_ctr_upper[8];
|
2018-05-11 09:44:41 +00:00
|
|
|
byte_t reserved_1[0xB8];
|
2018-04-07 08:01:11 +00:00
|
|
|
};
|
|
|
|
|
2018-10-25 12:25:31 +00:00
|
|
|
struct sContentArchiveHeaderBlock
|
2018-04-07 08:01:11 +00:00
|
|
|
{
|
2018-08-07 08:35:03 +00:00
|
|
|
byte_t signature_main[fnd::rsa::kRsa2048Size];
|
|
|
|
byte_t signature_acid[fnd::rsa::kRsa2048Size];
|
2018-10-25 12:25:31 +00:00
|
|
|
sContentArchiveHeader header;
|
2018-08-07 07:17:51 +00:00
|
|
|
sNcaFsHeader fs_header[nn::hac::nca::kPartitionNum];
|
2018-04-07 08:01:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#pragma pack(pop)
|
|
|
|
}
|
2018-08-07 07:17:51 +00:00
|
|
|
}
|