Implement support for parsing/interacting with NCAs. (#942)

* fs: implement support for interacting with ncas.

* spl: extend to use virtual keyslots
This commit is contained in:
SciresM
2020-05-11 15:04:51 -07:00
committed by GitHub
parent 3a1ccdd919
commit 81f91803ec
118 changed files with 13301 additions and 405 deletions

View File

@@ -15,19 +15,83 @@
*/
#pragma once
#include "spl_types.hpp"
#include <stratosphere/spl/spl_types.hpp>
namespace ams::spl {
HardwareType GetHardwareType();
MemoryArrangement GetMemoryArrangement();
bool IsDisabledProgramVerification();
bool IsDevelopmentHardware();
bool IsDevelopmentFunctionEnabled();
bool IsMariko();
bool IsRecoveryBoot();
void Initialize();
void InitializeForCrypto();
void InitializeForSsl();
void InitializeForEs();
void InitializeForFs();
void InitializeForManu();
Result GenerateAesKek(AccessKey *access_key, const void *key_source, size_t key_source_size, u32 generation, u32 option);
void Finalize();
Result AllocateAesKeySlot(s32 *out_slot);
Result DeallocateAesKeySlot(s32 slot);
Result GenerateAesKek(AccessKey *access_key, const void *key_source, size_t key_source_size, s32 generation, u32 option);
Result LoadAesKey(s32 slot, const AccessKey &access_key, const void *key_source, size_t key_source_size);
Result GenerateAesKey(void *dst, size_t dst_size, const AccessKey &access_key, const void *key_source, size_t key_source_size);
Result GenerateSpecificAesKey(void *dst, size_t dst_size, const void *key_source, size_t key_source_size, s32 generation, u32 option);
Result ComputeCtr(void *dst, size_t dst_size, s32 slot, const void *src, size_t src_size, const void *iv, size_t iv_size);
Result DecryptAesKey(void *dst, size_t dst_size, const void *src, size_t src_size, s32 generation, u32 option);
Result GetConfig(u64 *out, ConfigItem item);
bool IsDevelopment();
MemoryArrangement GetMemoryArrangement();
inline bool GetConfigBool(ConfigItem item) {
u64 v;
R_ABORT_UNLESS(::ams::spl::GetConfig(std::addressof(v), item));
return v != 0;
}
inline HardwareType GetHardwareType() {
u64 v;
R_ABORT_UNLESS(::ams::spl::GetConfig(std::addressof(v), ::ams::spl::ConfigItem::HardwareType));
return static_cast<HardwareType>(v);
}
inline HardwareState GetHardwareState() {
u64 v;
R_ABORT_UNLESS(::ams::spl::GetConfig(std::addressof(v), ::ams::spl::ConfigItem::HardwareState));
return static_cast<HardwareState>(v);
}
inline u64 GetDeviceIdLow() {
u64 v;
R_ABORT_UNLESS(::ams::spl::GetConfig(std::addressof(v), ::ams::spl::ConfigItem::DeviceId));
return v;
}
inline bool IsRecoveryBoot() {
return ::ams::spl::GetConfigBool(::ams::spl::ConfigItem::IsRecoveryBoot);
}
inline bool IsDevelopmentFunctionEnabled() {
return ::ams::spl::GetConfigBool(::ams::spl::ConfigItem::IsDevelopmentFunctionEnabled);
}
inline bool IsDisabledProgramVerification() {
return ::ams::spl::GetConfigBool(::ams::spl::ConfigItem::DisableProgramVerification);
}
Result SetBootReason(BootReasonValue boot_reason);
Result GetBootReason(BootReasonValue *out);
inline BootReasonValue GetBootReason() {
BootReasonValue br;
R_ABORT_UNLESS(::ams::spl::GetBootReason(std::addressof(br)));
return br;
}
SocType GetSocType();
Result GetPackage2Hash(void *dst, size_t dst_size);
Result GenerateRandomBytes(void *out, size_t buffer_size);
Result LoadPreparedAesKey(s32 slot, const AccessKey &access_key);
}

View File

@@ -112,6 +112,17 @@ namespace ams::spl {
Hoag = 2,
Iowa = 3,
Calcio = 4,
_Five_ = 5,
};
enum SocType {
SocType_Erista = 0,
SocType_Mariko = 1,
};
enum HardwareState {
HardwareState_Development = 0,
HardwareState_Production = 1,
};
enum MemoryArrangement {
@@ -185,23 +196,23 @@ namespace ams::spl {
enum class ConfigItem : u32 {
/* Standard config items. */
DisableProgramVerification = 1,
DramId = 2,
SecurityEngineIrqNumber = 3,
Version = 4,
HardwareType = 5,
IsRetail = 6,
IsRecoveryBoot = 7,
DeviceId = 8,
BootReason = 9,
MemoryMode = 10,
IsDebugMode = 11,
KernelConfiguration = 12,
IsChargerHiZModeEnabled = 13,
IsQuest = 14,
RegulatorType = 15,
DeviceUniqueKeyGeneration = 16,
Package2Hash = 17,
DisableProgramVerification = 1,
DramId = 2,
SecurityEngineIrqNumber = 3,
FuseVersion = 4,
HardwareType = 5,
HardwareState = 6,
IsRecoveryBoot = 7,
DeviceId = 8,
BootReason = 9,
MemoryMode = 10,
IsDevelopmentFunctionEnabled = 11,
KernelConfiguration = 12,
IsChargerHiZModeEnabled = 13,
IsQuest = 14,
RegulatorType = 15,
DeviceUniqueKeyGeneration = 16,
Package2Hash = 17,
/* Extension config items for exosphere. */
ExosphereApiVersion = 65000,