spl: update for new-ipc (fixes two bugs in sf)

This commit is contained in:
Michael Scire 2019-10-16 12:50:04 -07:00 committed by SciresM
parent 59140d8dfa
commit 635ae4e3da
23 changed files with 377 additions and 311 deletions

View file

@ -43,7 +43,7 @@ namespace sts::sf::cmif {
} }
} }
virtual Result PrepareForProcess(const ServiceDispatchContext &ctx, const size_t headers_size) const override final; virtual Result PrepareForProcess(const ServiceDispatchContext &ctx, size_t &headers_size) const override final;
virtual Result GetInObjects(ServiceObjectHolder *in_objects) const override final; virtual Result GetInObjects(ServiceObjectHolder *in_objects) const override final;
virtual HipcRequest PrepareForReply(const cmif::ServiceDispatchContext &ctx, PointerAndSize &out_raw_data, const size_t headers_size, size_t &num_out_object_handles) override final; virtual HipcRequest PrepareForReply(const cmif::ServiceDispatchContext &ctx, PointerAndSize &out_raw_data, const size_t headers_size, size_t &num_out_object_handles) override final;
virtual void PrepareForErrorReply(const cmif::ServiceDispatchContext &ctx, PointerAndSize &out_raw_data, const size_t headers_size) override final; virtual void PrepareForErrorReply(const cmif::ServiceDispatchContext &ctx, PointerAndSize &out_raw_data, const size_t headers_size) override final;

View file

@ -30,7 +30,7 @@ namespace sts::sf::cmif {
/* Used to enabled templated message processors. */ /* Used to enabled templated message processors. */
virtual void SetImplementationProcessor(ServerMessageProcessor *impl) { /* ... */ } virtual void SetImplementationProcessor(ServerMessageProcessor *impl) { /* ... */ }
virtual Result PrepareForProcess(const ServiceDispatchContext &ctx, const size_t headers_size) const = 0; virtual Result PrepareForProcess(const ServiceDispatchContext &ctx, size_t &headers_size) const = 0;
virtual Result GetInObjects(ServiceObjectHolder *in_objects) const = 0; virtual Result GetInObjects(ServiceObjectHolder *in_objects) const = 0;
virtual HipcRequest PrepareForReply(const cmif::ServiceDispatchContext &ctx, PointerAndSize &out_raw_data, const size_t headers_size, size_t &num_out_object_handles) = 0; virtual HipcRequest PrepareForReply(const cmif::ServiceDispatchContext &ctx, PointerAndSize &out_raw_data, const size_t headers_size, size_t &num_out_object_handles) = 0;
virtual void PrepareForErrorReply(const cmif::ServiceDispatchContext &ctx, PointerAndSize &out_raw_data, const size_t headers_size) = 0; virtual void PrepareForErrorReply(const cmif::ServiceDispatchContext &ctx, PointerAndSize &out_raw_data, const size_t headers_size) = 0;

View file

@ -300,7 +300,7 @@ namespace sts::sf::impl {
static constexpr void StableSort(std::array<size_t, sizeof...(Ts)> &map, const std::array<size_t, sizeof...(Ts)> &values) { static constexpr void StableSort(std::array<size_t, sizeof...(Ts)> &map, const std::array<size_t, sizeof...(Ts)> &values) {
/* Use insertion sort, which is stable and optimal for small numbers of parameters. */ /* Use insertion sort, which is stable and optimal for small numbers of parameters. */
for (size_t i = 1; i < sizeof...(Ts); i++) { for (size_t i = 1; i < sizeof...(Ts); i++) {
for (size_t j = i; j > 0 && values[j-1] > values[j]; j--) { for (size_t j = i; j > 0 && values[map[j-1]] > values[map[j]]; j--) {
/* std::swap is not constexpr until c++20 :( */ /* std::swap is not constexpr until c++20 :( */
/* TODO: std::swap(map[j], map[j-1]); */ /* TODO: std::swap(map[j], map[j-1]); */
const size_t tmp = map[j]; const size_t tmp = map[j];
@ -686,7 +686,7 @@ namespace sts::sf::impl {
template<typename CommandMeta> template<typename CommandMeta>
struct HipcCommandProcessor : public sf::cmif::ServerMessageProcessor { struct HipcCommandProcessor : public sf::cmif::ServerMessageProcessor {
public: public:
virtual Result PrepareForProcess(const cmif::ServiceDispatchContext &ctx, const size_t headers_size) const override final { virtual Result PrepareForProcess(const cmif::ServiceDispatchContext &ctx, size_t &headers_size) const override final {
const auto &meta = ctx.request.meta; const auto &meta = ctx.request.meta;
bool is_request_valid = true; bool is_request_valid = true;
is_request_valid &= meta.send_pid == CommandMeta::HasInProcessIdHolder; is_request_valid &= meta.send_pid == CommandMeta::HasInProcessIdHolder;
@ -789,7 +789,7 @@ namespace sts::sf::impl {
}(); }();
template<size_t BufferIndex, size_t Index = GetIndexFromBufferIndex<BufferIndex>> template<size_t BufferIndex, size_t Index = GetIndexFromBufferIndex<BufferIndex>>
NX_CONSTEXPR void ProcessBufferImpl(const cmif::ServiceDispatchContext &ctx, cmif::PointerAndSize &buffer, bool &is_buffer_map_alias, bool &map_alias_buffers_valid, size_t &pointer_buffer_head, size_t &pointer_buffer_tail) { NX_CONSTEXPR void ProcessBufferImpl(const cmif::ServiceDispatchContext &ctx, cmif::PointerAndSize &buffer, bool &is_buffer_map_alias, bool &map_alias_buffers_valid, size_t &pointer_buffer_head, size_t &pointer_buffer_tail, size_t in_headers_size) {
static_assert(Index != std::numeric_limits<size_t>::max(), "Invalid Index From Buffer Index"); static_assert(Index != std::numeric_limits<size_t>::max(), "Invalid Index From Buffer Index");
constexpr auto Info = CommandMeta::ArgumentSerializationInfos[Index]; constexpr auto Info = CommandMeta::ArgumentSerializationInfos[Index];
constexpr auto Attributes = CommandMeta::BufferAttributes[BufferIndex]; constexpr auto Attributes = CommandMeta::BufferAttributes[BufferIndex];
@ -824,7 +824,7 @@ namespace sts::sf::impl {
pointer_buffer_head = util::AlignDown(pointer_buffer_head - size, 0x10); pointer_buffer_head = util::AlignDown(pointer_buffer_head - size, 0x10);
buffer = cmif::PointerAndSize(pointer_buffer_head, size); buffer = cmif::PointerAndSize(pointer_buffer_head, size);
} else { } else {
const u16 *recv_pointer_sizes = reinterpret_cast<const u16 *>(reinterpret_cast<uintptr_t>(ctx.request.data.data_words) + CommandMeta::InDataRawUnfixedOutPointerSizeOffset); const u16 *recv_pointer_sizes = reinterpret_cast<const u16 *>(reinterpret_cast<uintptr_t>(ctx.request.data.data_words) + in_headers_size + CommandMeta::InDataRawUnfixedOutPointerSizeOffset);
const size_t size = size_t(recv_pointer_sizes[Info.unfixed_recv_pointer_index]); const size_t size = size_t(recv_pointer_sizes[Info.unfixed_recv_pointer_index]);
pointer_buffer_head = util::AlignDown(pointer_buffer_head - size, 0x10); pointer_buffer_head = util::AlignDown(pointer_buffer_head - size, 0x10);
buffer = cmif::PointerAndSize(pointer_buffer_head, size); buffer = cmif::PointerAndSize(pointer_buffer_head, size);
@ -894,11 +894,11 @@ namespace sts::sf::impl {
} }
} }
public: public:
NX_CONSTEXPR Result ProcessBuffers(const cmif::ServiceDispatchContext &ctx, BufferArrayType &buffers, std::array<bool, CommandMeta::NumBuffers> &is_buffer_map_alias) { NX_CONSTEXPR Result ProcessBuffers(const cmif::ServiceDispatchContext &ctx, BufferArrayType &buffers, std::array<bool, CommandMeta::NumBuffers> &is_buffer_map_alias, size_t in_headers_size) {
bool map_alias_buffers_valid = true; bool map_alias_buffers_valid = true;
size_t pointer_buffer_tail = ctx.pointer_buffer.GetAddress(); size_t pointer_buffer_tail = ctx.pointer_buffer.GetAddress();
size_t pointer_buffer_head = pointer_buffer_tail + ctx.pointer_buffer.GetSize(); size_t pointer_buffer_head = pointer_buffer_tail + ctx.pointer_buffer.GetSize();
#define _SF_IMPL_PROCESSOR_PROCESS_BUFFER_IMPL(n) do { if constexpr (CommandMeta::NumBuffers > n) { ProcessBufferImpl<n>(ctx, buffers[n], is_buffer_map_alias[n], map_alias_buffers_valid, pointer_buffer_head, pointer_buffer_tail); } } while (0) #define _SF_IMPL_PROCESSOR_PROCESS_BUFFER_IMPL(n) do { if constexpr (CommandMeta::NumBuffers > n) { ProcessBufferImpl<n>(ctx, buffers[n], is_buffer_map_alias[n], map_alias_buffers_valid, pointer_buffer_head, pointer_buffer_tail, in_headers_size); } } while (0)
_SF_IMPL_PROCESSOR_PROCESS_BUFFER_IMPL(0); _SF_IMPL_PROCESSOR_PROCESS_BUFFER_IMPL(0);
_SF_IMPL_PROCESSOR_PROCESS_BUFFER_IMPL(1); _SF_IMPL_PROCESSOR_PROCESS_BUFFER_IMPL(1);
_SF_IMPL_PROCESSOR_PROCESS_BUFFER_IMPL(2); _SF_IMPL_PROCESSOR_PROCESS_BUFFER_IMPL(2);
@ -1010,7 +1010,7 @@ namespace sts::sf::impl {
return ResultSuccess; return ResultSuccess;
} }
template<auto ServiceCommandImpl, typename ClassType = typename CommandMetaInfo<ServiceCommandImpl>::ClassType> template<auto ServiceCommandImpl>
constexpr Result InvokeServiceCommandImpl(CmifOutHeader **out_header_ptr, cmif::ServiceDispatchContext &ctx, const cmif::PointerAndSize &in_raw_data) { constexpr Result InvokeServiceCommandImpl(CmifOutHeader **out_header_ptr, cmif::ServiceDispatchContext &ctx, const cmif::PointerAndSize &in_raw_data) {
using CommandMeta = CommandMetaInfo<ServiceCommandImpl>; using CommandMeta = CommandMetaInfo<ServiceCommandImpl>;
using ImplProcessorType = HipcCommandProcessor<CommandMeta>; using ImplProcessorType = HipcCommandProcessor<CommandMeta>;
@ -1018,7 +1018,7 @@ namespace sts::sf::impl {
using OutHandleHolderType = OutHandleHolder<CommandMeta::NumOutMoveHandles, CommandMeta::NumOutCopyHandles>; using OutHandleHolderType = OutHandleHolder<CommandMeta::NumOutMoveHandles, CommandMeta::NumOutCopyHandles>;
using OutRawHolderType = OutRawHolder<CommandMeta::OutDataSize, CommandMeta::OutDataAlign>; using OutRawHolderType = OutRawHolder<CommandMeta::OutDataSize, CommandMeta::OutDataAlign>;
using InOutObjectHolderType = InOutObjectHolder<CommandMeta::NumInObjects, CommandMeta::NumOutObjects>; using InOutObjectHolderType = InOutObjectHolder<CommandMeta::NumInObjects, CommandMeta::NumOutObjects>;
static_assert(std::is_base_of<typename CommandMeta::ClassType, ClassType>::value, "InvokeServiceCommandImpl: Invalid Override ClassType"); using ClassType = typename CommandMeta::ClassType;
static_assert(std::is_base_of<sf::IServiceObject, ClassType>::value, "InvokeServiceCommandImpl: Service Commands must be ServiceObject member functions"); static_assert(std::is_base_of<sf::IServiceObject, ClassType>::value, "InvokeServiceCommandImpl: Service Commands must be ServiceObject member functions");
/* Create a processor for us to work with. */ /* Create a processor for us to work with. */
@ -1032,7 +1032,8 @@ namespace sts::sf::impl {
} }
/* Validate the metadata has the expected counts. */ /* Validate the metadata has the expected counts. */
R_TRY(ctx.processor->PrepareForProcess(ctx, sizeof(CmifInHeader))); size_t in_headers_size = sizeof(CmifInHeader);
R_TRY(ctx.processor->PrepareForProcess(ctx, in_headers_size));
/* Storage for output. */ /* Storage for output. */
BufferArrayType buffers; BufferArrayType buffers;
@ -1042,7 +1043,7 @@ namespace sts::sf::impl {
InOutObjectHolderType in_out_objects_holder; InOutObjectHolderType in_out_objects_holder;
/* Process buffers. */ /* Process buffers. */
R_TRY(ImplProcessorType::ProcessBuffers(ctx, buffers, is_buffer_map_alias)); R_TRY(ImplProcessorType::ProcessBuffers(ctx, buffers, is_buffer_map_alias, in_headers_size));
/* Process input/output objects. */ /* Process input/output objects. */
R_TRY(in_out_objects_holder.GetInObjects(ctx.processor)); R_TRY(in_out_objects_holder.GetInObjects(ctx.processor));
@ -1095,16 +1096,16 @@ namespace sts::sf::impl {
namespace sts::sf { namespace sts::sf {
template <auto CommandId, auto CommandImpl, typename OverrideClassType, hos::Version Low = hos::Version_Min, hos::Version High = hos::Version_Max> template <auto CommandId, auto CommandImpl, hos::Version Low = hos::Version_Min, hos::Version High = hos::Version_Max>
inline static constexpr cmif::ServiceCommandMeta MakeServiceCommandMeta() { inline static constexpr cmif::ServiceCommandMeta MakeServiceCommandMeta() {
return { return {
.hosver_low = Low, .hosver_low = Low,
.hosver_high = High, .hosver_high = High,
.cmd_id = static_cast<u32>(CommandId), .cmd_id = static_cast<u32>(CommandId),
.handler = ::sts::sf::impl::InvokeServiceCommandImpl<CommandImpl, OverrideClassType>, .handler = ::sts::sf::impl::InvokeServiceCommandImpl<CommandImpl>,
}; };
} }
} }
#define MAKE_SERVICE_COMMAND_META(Name, ...) ::sts::sf::MakeServiceCommandMeta<ServiceImpl::CommandId::Name, &ServiceImpl::Name, ServiceImpl, ##__VA_ARGS__>() #define MAKE_SERVICE_COMMAND_META(Name, ...) ::sts::sf::MakeServiceCommandMeta<ServiceImpl::CommandId::Name, &ServiceImpl::Name, ##__VA_ARGS__>()

View file

@ -45,7 +45,7 @@ namespace sts::spl::impl {
/* Max Keyslots helper. */ /* Max Keyslots helper. */
inline size_t GetMaxKeyslots() { inline size_t GetMaxKeyslots() {
return (GetRuntimeFirmwareVersion() >= FirmwareVersion_600) ? MaxAesKeyslots : MaxAesKeyslotsDeprecated; return (hos::GetVersion() >= hos::Version_600) ? MaxAesKeyslots : MaxAesKeyslotsDeprecated;
} }
/* Type definitions. */ /* Type definitions. */
@ -289,7 +289,7 @@ namespace sts::spl::impl {
if (keyslot >= GetMaxKeyslots()) { if (keyslot >= GetMaxKeyslots()) {
return ResultSplInvalidKeyslot; return ResultSplInvalidKeyslot;
} }
if (g_keyslot_owners[keyslot] != owner && GetRuntimeFirmwareVersion() > FirmwareVersion_100) { if (g_keyslot_owners[keyslot] != owner && hos::GetVersion() > hos::Version_100) {
return ResultSplInvalidKeyslot; return ResultSplInvalidKeyslot;
} }
return ResultSuccess; return ResultSuccess;
@ -353,7 +353,7 @@ namespace sts::spl::impl {
armDCacheFlush(layout, sizeof(*layout)); armDCacheFlush(layout, sizeof(*layout));
smc::Result smc_res; smc::Result smc_res;
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) { if (hos::GetVersion() >= hos::Version_500) {
smc_res = smc::DecryptOrImportRsaPrivateKey(layout->data, src_size, access_key, key_source, static_cast<smc::DecryptOrImportMode>(option)); smc_res = smc::DecryptOrImportRsaPrivateKey(layout->data, src_size, access_key, key_source, static_cast<smc::DecryptOrImportMode>(option));
} else { } else {
smc_res = smc::ImportSecureExpModKey(layout->data, src_size, access_key, key_source, option); smc_res = smc::ImportSecureExpModKey(layout->data, src_size, access_key, key_source, option);
@ -703,7 +703,7 @@ namespace sts::spl::impl {
} }
Result AllocateAesKeyslot(u32 *out_keyslot, const void *owner) { Result AllocateAesKeyslot(u32 *out_keyslot, const void *owner) {
if (GetRuntimeFirmwareVersion() <= FirmwareVersion_100) { if (hos::GetVersion() <= hos::Version_100) {
/* On 1.0.0, keyslots were kind of a wild west. */ /* On 1.0.0, keyslots were kind of a wild west. */
*out_keyslot = 0; *out_keyslot = 0;
return ResultSuccess; return ResultSuccess;
@ -722,7 +722,7 @@ namespace sts::spl::impl {
} }
Result FreeAesKeyslot(u32 keyslot, const void *owner) { Result FreeAesKeyslot(u32 keyslot, const void *owner) {
if (GetRuntimeFirmwareVersion() <= FirmwareVersion_100) { if (hos::GetVersion() <= hos::Version_100) {
/* On 1.0.0, keyslots were kind of a wild west. */ /* On 1.0.0, keyslots were kind of a wild west. */
return ResultSuccess; return ResultSuccess;
} }
@ -758,9 +758,9 @@ namespace sts::spl::impl {
smc::Result smc_res; smc::Result smc_res;
size_t copy_size = 0; size_t copy_size = 0;
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) { if (hos::GetVersion() >= hos::Version_500) {
copy_size = std::min(dst_size, src_size - RsaPrivateKeyMetaSize); copy_size = std::min(dst_size, src_size - RsaPrivateKeyMetaSize);
smc_res = smc::DecryptOrImportRsaPrivateKey(layout->data, src_size, access_key, key_source, smc::DecryptOrImportMode::DecryptRsaPrivateKey); smc_res = smc::DecryptOrImportRsaPrivateKey(layout->data, src_size, access_key, key_source, static_cast<smc::DecryptOrImportMode>(option));
} else { } else {
smc_res = smc::DecryptRsaPrivateKey(&copy_size, layout->data, src_size, access_key, key_source, option); smc_res = smc::DecryptRsaPrivateKey(&copy_size, layout->data, src_size, access_key, key_source, option);
copy_size = std::min(dst_size, copy_size); copy_size = std::min(dst_size, copy_size);
@ -785,8 +785,8 @@ namespace sts::spl::impl {
/* ES */ /* ES */
Result ImportEsKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source, u32 option) { Result ImportEsKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source, u32 option) {
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) { if (hos::GetVersion() >= hos::Version_500) {
return ImportSecureExpModKey(src, src_size, access_key, key_source, static_cast<u32>(smc::DecryptOrImportMode::ImportEsKey)); return ImportSecureExpModKey(src, src_size, access_key, key_source, option);
} else { } else {
struct ImportEsKeyLayout { struct ImportEsKeyLayout {
u8 data[RsaPrivateKeyMetaSize + 2 * RsaPrivateKeySize + 0x10]; u8 data[RsaPrivateKeyMetaSize + 2 * RsaPrivateKeySize + 0x10];
@ -832,9 +832,6 @@ namespace sts::spl::impl {
/* FS */ /* FS */
Result ImportLotusKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source, u32 option) { Result ImportLotusKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source, u32 option) {
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) {
option = static_cast<u32>(smc::DecryptOrImportMode::ImportLotusKey);
}
return ImportSecureExpModKey(src, src_size, access_key, key_source, option); return ImportSecureExpModKey(src, src_size, access_key, key_source, option);
} }

View file

@ -27,7 +27,7 @@ namespace sts::spl {
impl::FreeAesKeyslots(this); impl::FreeAesKeyslots(this);
} }
Result CryptoService::GenerateAesKek(Out<AccessKey> out_access_key, KeySource key_source, u32 generation, u32 option) { Result CryptoService::GenerateAesKek(sf::Out<AccessKey> out_access_key, KeySource key_source, u32 generation, u32 option) {
return impl::GenerateAesKek(out_access_key.GetPointer(), key_source, generation, option); return impl::GenerateAesKek(out_access_key.GetPointer(), key_source, generation, option);
} }
@ -35,23 +35,23 @@ namespace sts::spl {
return impl::LoadAesKey(keyslot, this, access_key, key_source); return impl::LoadAesKey(keyslot, this, access_key, key_source);
} }
Result CryptoService::GenerateAesKey(Out<AesKey> out_key, AccessKey access_key, KeySource key_source) { Result CryptoService::GenerateAesKey(sf::Out<AesKey> out_key, AccessKey access_key, KeySource key_source) {
return impl::GenerateAesKey(out_key.GetPointer(), access_key, key_source); return impl::GenerateAesKey(out_key.GetPointer(), access_key, key_source);
} }
Result CryptoService::DecryptAesKey(Out<AesKey> out_key, KeySource key_source, u32 generation, u32 option) { Result CryptoService::DecryptAesKey(sf::Out<AesKey> out_key, KeySource key_source, u32 generation, u32 option) {
return impl::DecryptAesKey(out_key.GetPointer(), key_source, generation, option); return impl::DecryptAesKey(out_key.GetPointer(), key_source, generation, option);
} }
Result CryptoService::CryptAesCtr(OutBuffer<u8, BufferType_Type1> out_buf, u32 keyslot, InBuffer<u8, BufferType_Type1> in_buf, IvCtr iv_ctr) { Result CryptoService::CryptAesCtr(const sf::OutNonSecureBuffer &out_buf, u32 keyslot, const sf::InNonSecureBuffer &in_buf, IvCtr iv_ctr) {
return impl::CryptAesCtr(out_buf.buffer, out_buf.num_elements, keyslot, this, in_buf.buffer, in_buf.num_elements, iv_ctr); return impl::CryptAesCtr(out_buf.GetPointer(), out_buf.GetSize(), keyslot, this, in_buf.GetPointer(), in_buf.GetSize(), iv_ctr);
} }
Result CryptoService::ComputeCmac(Out<Cmac> out_cmac, u32 keyslot, InPointer<u8> in_buf) { Result CryptoService::ComputeCmac(sf::Out<Cmac> out_cmac, u32 keyslot, const sf::InPointerBuffer &in_buf) {
return impl::ComputeCmac(out_cmac.GetPointer(), keyslot, this, in_buf.pointer, in_buf.num_elements); return impl::ComputeCmac(out_cmac.GetPointer(), keyslot, this, in_buf.GetPointer(), in_buf.GetSize());
} }
Result CryptoService::AllocateAesKeyslot(Out<u32> out_keyslot) { Result CryptoService::AllocateAesKeyslot(sf::Out<u32> out_keyslot) {
return impl::AllocateAesKeyslot(out_keyslot.GetPointer(), this); return impl::AllocateAesKeyslot(out_keyslot.GetPointer(), this);
} }
@ -59,7 +59,7 @@ namespace sts::spl {
return impl::FreeAesKeyslot(keyslot, this); return impl::FreeAesKeyslot(keyslot, this);
} }
void CryptoService::GetAesKeyslotAvailableEvent(Out<CopiedHandle> out_hnd) { void CryptoService::GetAesKeyslotAvailableEvent(sf::OutCopyHandle out_hnd) {
out_hnd.SetValue(impl::GetAesKeyslotAvailableEventHandle()); out_hnd.SetValue(impl::GetAesKeyslotAvailableEventHandle());
} }

View file

@ -29,33 +29,33 @@ namespace sts::spl {
virtual ~CryptoService(); virtual ~CryptoService();
protected: protected:
/* Actual commands. */ /* Actual commands. */
virtual Result GenerateAesKek(Out<AccessKey> out_access_key, KeySource key_source, u32 generation, u32 option); virtual Result GenerateAesKek(sf::Out<AccessKey> out_access_key, KeySource key_source, u32 generation, u32 option);
virtual Result LoadAesKey(u32 keyslot, AccessKey access_key, KeySource key_source); virtual Result LoadAesKey(u32 keyslot, AccessKey access_key, KeySource key_source);
virtual Result GenerateAesKey(Out<AesKey> out_key, AccessKey access_key, KeySource key_source); virtual Result GenerateAesKey(sf::Out<AesKey> out_key, AccessKey access_key, KeySource key_source);
virtual Result DecryptAesKey(Out<AesKey> out_key, KeySource key_source, u32 generation, u32 option); virtual Result DecryptAesKey(sf::Out<AesKey> out_key, KeySource key_source, u32 generation, u32 option);
virtual Result CryptAesCtr(OutBuffer<u8, BufferType_Type1> out_buf, u32 keyslot, InBuffer<u8, BufferType_Type1> in_buf, IvCtr iv_ctr); virtual Result CryptAesCtr(const sf::OutNonSecureBuffer &out_buf, u32 keyslot, const sf::InNonSecureBuffer &in_buf, IvCtr iv_ctr);
virtual Result ComputeCmac(Out<Cmac> out_cmac, u32 keyslot, InPointer<u8> in_buf); virtual Result ComputeCmac(sf::Out<Cmac> out_cmac, u32 keyslot, const sf::InPointerBuffer &in_buf);
virtual Result AllocateAesKeyslot(Out<u32> out_keyslot); virtual Result AllocateAesKeyslot(sf::Out<u32> out_keyslot);
virtual Result FreeAesKeyslot(u32 keyslot); virtual Result FreeAesKeyslot(u32 keyslot);
virtual void GetAesKeyslotAvailableEvent(Out<CopiedHandle> out_hnd); virtual void GetAesKeyslotAvailableEvent(sf::OutCopyHandle out_hnd);
public: public:
DEFINE_SERVICE_DISPATCH_TABLE { DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(CryptoService, GetConfig), MAKE_SERVICE_COMMAND_META(GetConfig),
MAKE_SERVICE_COMMAND_META(CryptoService, ExpMod), MAKE_SERVICE_COMMAND_META(ExpMod),
MAKE_SERVICE_COMMAND_META(CryptoService, SetConfig), MAKE_SERVICE_COMMAND_META(SetConfig),
MAKE_SERVICE_COMMAND_META(CryptoService, GenerateRandomBytes), MAKE_SERVICE_COMMAND_META(GenerateRandomBytes),
MAKE_SERVICE_COMMAND_META(CryptoService, IsDevelopment), MAKE_SERVICE_COMMAND_META(IsDevelopment),
MAKE_SERVICE_COMMAND_META(CryptoService, SetBootReason, FirmwareVersion_300), MAKE_SERVICE_COMMAND_META(SetBootReason, hos::Version_300),
MAKE_SERVICE_COMMAND_META(CryptoService, GetBootReason, FirmwareVersion_300), MAKE_SERVICE_COMMAND_META(GetBootReason, hos::Version_300),
MAKE_SERVICE_COMMAND_META(CryptoService, GenerateAesKek), MAKE_SERVICE_COMMAND_META(GenerateAesKek),
MAKE_SERVICE_COMMAND_META(CryptoService, LoadAesKey), MAKE_SERVICE_COMMAND_META(LoadAesKey),
MAKE_SERVICE_COMMAND_META(CryptoService, GenerateAesKey), MAKE_SERVICE_COMMAND_META(GenerateAesKey),
MAKE_SERVICE_COMMAND_META(CryptoService, DecryptAesKey), MAKE_SERVICE_COMMAND_META(DecryptAesKey),
MAKE_SERVICE_COMMAND_META(CryptoService, CryptAesCtr), MAKE_SERVICE_COMMAND_META(CryptAesCtr),
MAKE_SERVICE_COMMAND_META(CryptoService, ComputeCmac), MAKE_SERVICE_COMMAND_META(ComputeCmac),
MAKE_SERVICE_COMMAND_META(CryptoService, AllocateAesKeyslot, FirmwareVersion_200), MAKE_SERVICE_COMMAND_META(AllocateAesKeyslot, hos::Version_200),
MAKE_SERVICE_COMMAND_META(CryptoService, FreeAesKeyslot, FirmwareVersion_200), MAKE_SERVICE_COMMAND_META(FreeAesKeyslot, hos::Version_200),
MAKE_SERVICE_COMMAND_META(CryptoService, GetAesKeyslotAvailableEvent, FirmwareVersion_200), MAKE_SERVICE_COMMAND_META(GetAesKeyslotAvailableEvent, hos::Version_200),
}; };
}; };

View file

@ -22,15 +22,15 @@
namespace sts::spl { namespace sts::spl {
Result DeprecatedService::GetConfig(Out<u64> out, u32 which) { Result DeprecatedService::GetConfig(sf::Out<u64> out, u32 which) {
return impl::GetConfig(out.GetPointer(), static_cast<SplConfigItem>(which)); return impl::GetConfig(out.GetPointer(), static_cast<SplConfigItem>(which));
} }
Result DeprecatedService::ExpMod(OutPointerWithClientSize<u8> out, InPointer<u8> base, InPointer<u8> exp, InPointer<u8> mod) { Result DeprecatedService::ExpMod(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &exp, const sf::InPointerBuffer &mod) {
return impl::ExpMod(out.pointer, out.num_elements, base.pointer, base.num_elements, exp.pointer, exp.num_elements, mod.pointer, mod.num_elements); return impl::ExpMod(out.GetPointer(), out.GetSize(), base.GetPointer(), base.GetSize(), exp.GetPointer(), exp.GetSize(), mod.GetPointer(), mod.GetSize());
} }
Result DeprecatedService::GenerateAesKek(Out<AccessKey> out_access_key, KeySource key_source, u32 generation, u32 option) { Result DeprecatedService::GenerateAesKek(sf::Out<AccessKey> out_access_key, KeySource key_source, u32 generation, u32 option) {
return impl::GenerateAesKek(out_access_key.GetPointer(), key_source, generation, option); return impl::GenerateAesKek(out_access_key.GetPointer(), key_source, generation, option);
} }
@ -38,7 +38,7 @@ namespace sts::spl {
return impl::LoadAesKey(keyslot, this, access_key, key_source); return impl::LoadAesKey(keyslot, this, access_key, key_source);
} }
Result DeprecatedService::GenerateAesKey(Out<AesKey> out_key, AccessKey access_key, KeySource key_source) { Result DeprecatedService::GenerateAesKey(sf::Out<AesKey> out_key, AccessKey access_key, KeySource key_source) {
return impl::GenerateAesKey(out_key.GetPointer(), access_key, key_source); return impl::GenerateAesKey(out_key.GetPointer(), access_key, key_source);
} }
@ -46,63 +46,71 @@ namespace sts::spl {
return impl::SetConfig(static_cast<SplConfigItem>(which), value); return impl::SetConfig(static_cast<SplConfigItem>(which), value);
} }
Result DeprecatedService::GenerateRandomBytes(OutPointerWithClientSize<u8> out) { Result DeprecatedService::GenerateRandomBytes(const sf::OutPointerBuffer &out) {
return impl::GenerateRandomBytes(out.pointer, out.num_elements); return impl::GenerateRandomBytes(out.GetPointer(), out.GetSize());
} }
Result DeprecatedService::ImportLotusKey(InPointer<u8> src, AccessKey access_key, KeySource key_source, u32 option) { Result DeprecatedService::ImportLotusKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option) {
return impl::ImportLotusKey(src.pointer, src.num_elements, access_key, key_source, option); return impl::ImportLotusKey(src.GetPointer(), src.GetSize(), access_key, key_source, option);
} }
Result DeprecatedService::DecryptLotusMessage(Out<u32> out_size, OutPointerWithClientSize<u8> out, InPointer<u8> base, InPointer<u8> mod, InPointer<u8> label_digest) { Result DeprecatedService::DecryptLotusMessage(sf::Out<u32> out_size, const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest) {
return impl::DecryptLotusMessage(out_size.GetPointer(), out.pointer, out.num_elements, base.pointer, base.num_elements, mod.pointer, mod.num_elements, label_digest.pointer, label_digest.num_elements); return impl::DecryptLotusMessage(out_size.GetPointer(), out.GetPointer(), out.GetSize(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize(), label_digest.GetPointer(), label_digest.GetSize());
} }
Result DeprecatedService::IsDevelopment(Out<bool> is_dev) { Result DeprecatedService::IsDevelopment(sf::Out<bool> is_dev) {
return impl::IsDevelopment(is_dev.GetPointer()); return impl::IsDevelopment(is_dev.GetPointer());
} }
Result DeprecatedService::GenerateSpecificAesKey(Out<AesKey> out_key, KeySource key_source, u32 generation, u32 which) { Result DeprecatedService::GenerateSpecificAesKey(sf::Out<AesKey> out_key, KeySource key_source, u32 generation, u32 which) {
return impl::GenerateSpecificAesKey(out_key.GetPointer(), key_source, generation, which); return impl::GenerateSpecificAesKey(out_key.GetPointer(), key_source, generation, which);
} }
Result DeprecatedService::DecryptRsaPrivateKey(OutPointerWithClientSize<u8> dst, InPointer<u8> src, AccessKey access_key, KeySource key_source, u32 option) { Result DeprecatedService::DecryptRsaPrivateKey(const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option) {
return impl::DecryptRsaPrivateKey(dst.pointer, dst.num_elements, src.pointer, src.num_elements, access_key, key_source, option); return impl::DecryptRsaPrivateKey(dst.GetPointer(), dst.GetSize(), src.GetPointer(), src.GetSize(), access_key, key_source, option);
} }
Result DeprecatedService::DecryptAesKey(Out<AesKey> out_key, KeySource key_source, u32 generation, u32 option) { Result DeprecatedService::DecryptAesKey(sf::Out<AesKey> out_key, KeySource key_source, u32 generation, u32 option) {
return impl::DecryptAesKey(out_key.GetPointer(), key_source, generation, option); return impl::DecryptAesKey(out_key.GetPointer(), key_source, generation, option);
} }
Result DeprecatedService::CryptAesCtrDeprecated(OutBuffer<u8> out_buf, u32 keyslot, InBuffer<u8> in_buf, IvCtr iv_ctr) { Result DeprecatedService::CryptAesCtrDeprecated(const sf::OutBuffer &out_buf, u32 keyslot, const sf::InBuffer &in_buf, IvCtr iv_ctr) {
return impl::CryptAesCtr(out_buf.buffer, out_buf.num_elements, keyslot, this, in_buf.buffer, in_buf.num_elements, iv_ctr); return impl::CryptAesCtr(out_buf.GetPointer(), out_buf.GetSize(), keyslot, this, in_buf.GetPointer(), in_buf.GetSize(), iv_ctr);
} }
Result DeprecatedService::CryptAesCtr(OutBuffer<u8, BufferType_Type1> out_buf, u32 keyslot, InBuffer<u8, BufferType_Type1> in_buf, IvCtr iv_ctr) { Result DeprecatedService::CryptAesCtr(const sf::OutNonSecureBuffer &out_buf, u32 keyslot, const sf::InNonSecureBuffer &in_buf, IvCtr iv_ctr) {
return impl::CryptAesCtr(out_buf.buffer, out_buf.num_elements, keyslot, this, in_buf.buffer, in_buf.num_elements, iv_ctr); return impl::CryptAesCtr(out_buf.GetPointer(), out_buf.GetSize(), keyslot, this, in_buf.GetPointer(), in_buf.GetSize(), iv_ctr);
} }
Result DeprecatedService::ComputeCmac(Out<Cmac> out_cmac, u32 keyslot, InPointer<u8> in_buf) { Result DeprecatedService::ComputeCmac(sf::Out<Cmac> out_cmac, u32 keyslot, const sf::InPointerBuffer &in_buf) {
return impl::ComputeCmac(out_cmac.GetPointer(), keyslot, this, in_buf.pointer, in_buf.num_elements); return impl::ComputeCmac(out_cmac.GetPointer(), keyslot, this, in_buf.GetPointer(), in_buf.GetSize());
} }
Result DeprecatedService::ImportEsKey(InPointer<u8> src, AccessKey access_key, KeySource key_source, u32 option) { Result DeprecatedService::ImportEsKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option) {
return impl::ImportEsKey(src.pointer, src.num_elements, access_key, key_source, option); return impl::ImportEsKey(src.GetPointer(), src.GetSize(), access_key, key_source, option);
} }
Result DeprecatedService::UnwrapTitleKey(Out<AccessKey> out_access_key, InPointer<u8> base, InPointer<u8> mod, InPointer<u8> label_digest, u32 generation) { Result DeprecatedService::UnwrapTitleKeyDeprecated(sf::Out<AccessKey> out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest) {
return impl::UnwrapTitleKey(out_access_key.GetPointer(), base.pointer, base.num_elements, mod.pointer, mod.num_elements, label_digest.pointer, label_digest.num_elements, generation); return impl::UnwrapTitleKey(out_access_key.GetPointer(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize(), label_digest.GetPointer(), label_digest.GetSize(), 0);
}
Result DeprecatedService::UnwrapTitleKey(sf::Out<AccessKey> out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest, u32 generation) {
return impl::UnwrapTitleKey(out_access_key.GetPointer(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize(), label_digest.GetPointer(), label_digest.GetSize(), generation);
} }
Result DeprecatedService::LoadTitleKey(u32 keyslot, AccessKey access_key) { Result DeprecatedService::LoadTitleKey(u32 keyslot, AccessKey access_key) {
return impl::LoadTitleKey(keyslot, this, access_key); return impl::LoadTitleKey(keyslot, this, access_key);
} }
Result DeprecatedService::UnwrapCommonTitleKey(Out<AccessKey> out_access_key, KeySource key_source, u32 generation) { Result DeprecatedService::UnwrapCommonTitleKeyDeprecated(sf::Out<AccessKey> out_access_key, KeySource key_source) {
return impl::UnwrapCommonTitleKey(out_access_key.GetPointer(), key_source, 0);
}
Result DeprecatedService::UnwrapCommonTitleKey(sf::Out<AccessKey> out_access_key, KeySource key_source, u32 generation) {
return impl::UnwrapCommonTitleKey(out_access_key.GetPointer(), key_source, generation); return impl::UnwrapCommonTitleKey(out_access_key.GetPointer(), key_source, generation);
} }
Result DeprecatedService::AllocateAesKeyslot(Out<u32> out_keyslot) { Result DeprecatedService::AllocateAesKeyslot(sf::Out<u32> out_keyslot) {
return impl::AllocateAesKeyslot(out_keyslot.GetPointer(), this); return impl::AllocateAesKeyslot(out_keyslot.GetPointer(), this);
} }
@ -110,7 +118,7 @@ namespace sts::spl {
return impl::FreeAesKeyslot(keyslot, this); return impl::FreeAesKeyslot(keyslot, this);
} }
void DeprecatedService::GetAesKeyslotAvailableEvent(Out<CopiedHandle> out_hnd) { void DeprecatedService::GetAesKeyslotAvailableEvent(sf::OutCopyHandle out_hnd) {
out_hnd.SetValue(impl::GetAesKeyslotAvailableEventHandle()); out_hnd.SetValue(impl::GetAesKeyslotAvailableEventHandle());
} }
@ -118,7 +126,7 @@ namespace sts::spl {
return impl::SetBootReason(boot_reason); return impl::SetBootReason(boot_reason);
} }
Result DeprecatedService::GetBootReason(Out<BootReasonValue> out) { Result DeprecatedService::GetBootReason(sf::Out<BootReasonValue> out) {
return impl::GetBootReason(out.GetPointer()); return impl::GetBootReason(out.GetPointer());
} }

View file

@ -21,7 +21,7 @@
namespace sts::spl { namespace sts::spl {
class DeprecatedService : public IServiceObject { class DeprecatedService : public sf::IServiceObject {
protected: protected:
enum class CommandId { enum class CommandId {
/* 1.0.0+ */ /* 1.0.0+ */
@ -43,10 +43,12 @@ namespace sts::spl {
CryptAesCtr = 15, CryptAesCtr = 15,
ComputeCmac = 16, ComputeCmac = 16,
ImportEsKey = 17, ImportEsKey = 17,
UnwrapTitleKeyDeprecated = 18,
UnwrapTitleKey = 18, UnwrapTitleKey = 18,
LoadTitleKey = 19, LoadTitleKey = 19,
/* 2.0.0+ */ /* 2.0.0+ */
UnwrapCommonTitleKeyDeprecated = 20,
UnwrapCommonTitleKey = 20, UnwrapCommonTitleKey = 20,
AllocateAesKeyslot = 21, AllocateAesKeyslot = 21,
FreeAesKeyslot = 22, FreeAesKeyslot = 22,
@ -61,58 +63,69 @@ namespace sts::spl {
virtual ~DeprecatedService() { /* ... */ } virtual ~DeprecatedService() { /* ... */ }
protected: protected:
/* Actual commands. */ /* Actual commands. */
virtual Result GetConfig(Out<u64> out, u32 which); virtual Result GetConfig(sf::Out<u64> out, u32 which);
virtual Result ExpMod(OutPointerWithClientSize<u8> out, InPointer<u8> base, InPointer<u8> exp, InPointer<u8> mod); virtual Result ExpMod(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &exp, const sf::InPointerBuffer &mod);
virtual Result GenerateAesKek(Out<AccessKey> out_access_key, KeySource key_source, u32 generation, u32 option); virtual Result GenerateAesKek(sf::Out<AccessKey> out_access_key, KeySource key_source, u32 generation, u32 option);
virtual Result LoadAesKey(u32 keyslot, AccessKey access_key, KeySource key_source); virtual Result LoadAesKey(u32 keyslot, AccessKey access_key, KeySource key_source);
virtual Result GenerateAesKey(Out<AesKey> out_key, AccessKey access_key, KeySource key_source); virtual Result GenerateAesKey(sf::Out<AesKey> out_key, AccessKey access_key, KeySource key_source);
virtual Result SetConfig(u32 which, u64 value); virtual Result SetConfig(u32 which, u64 value);
virtual Result GenerateRandomBytes(OutPointerWithClientSize<u8> out); virtual Result GenerateRandomBytes(const sf::OutPointerBuffer &out);
virtual Result ImportLotusKey(InPointer<u8> src, AccessKey access_key, KeySource key_source, u32 option); virtual Result ImportLotusKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option);
virtual Result DecryptLotusMessage(Out<u32> out_size, OutPointerWithClientSize<u8> out, InPointer<u8> base, InPointer<u8> mod, InPointer<u8> label_digest); virtual Result DecryptLotusMessage(sf::Out<u32> out_size, const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest);
virtual Result IsDevelopment(Out<bool> is_dev); virtual Result IsDevelopment(sf::Out<bool> is_dev);
virtual Result GenerateSpecificAesKey(Out<AesKey> out_key, KeySource key_source, u32 generation, u32 which); virtual Result GenerateSpecificAesKey(sf::Out<AesKey> out_key, KeySource key_source, u32 generation, u32 which);
virtual Result DecryptRsaPrivateKey(OutPointerWithClientSize<u8> dst, InPointer<u8> src, AccessKey access_key, KeySource key_source, u32 option); virtual Result DecryptRsaPrivateKey(const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option);
virtual Result DecryptAesKey(Out<AesKey> out_key, KeySource key_source, u32 generation, u32 option); virtual Result DecryptAesKey(sf::Out<AesKey> out_key, KeySource key_source, u32 generation, u32 option);
virtual Result CryptAesCtrDeprecated(OutBuffer<u8> out_buf, u32 keyslot, InBuffer<u8> in_buf, IvCtr iv_ctr); virtual Result CryptAesCtrDeprecated(const sf::OutBuffer &out_buf, u32 keyslot, const sf::InBuffer &in_buf, IvCtr iv_ctr);
virtual Result CryptAesCtr(OutBuffer<u8, BufferType_Type1> out_buf, u32 keyslot, InBuffer<u8, BufferType_Type1> in_buf, IvCtr iv_ctr); virtual Result CryptAesCtr(const sf::OutNonSecureBuffer &out_buf, u32 keyslot, const sf::InNonSecureBuffer &in_buf, IvCtr iv_ctr);
virtual Result ComputeCmac(Out<Cmac> out_cmac, u32 keyslot, InPointer<u8> in_buf); virtual Result ComputeCmac(sf::Out<Cmac> out_cmac, u32 keyslot, const sf::InPointerBuffer &in_buf);
virtual Result ImportEsKey(InPointer<u8> src, AccessKey access_key, KeySource key_source, u32 option); virtual Result ImportEsKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option);
virtual Result UnwrapTitleKey(Out<AccessKey> out_access_key, InPointer<u8> base, InPointer<u8> mod, InPointer<u8> label_digest, u32 generation); virtual Result UnwrapTitleKeyDeprecated(sf::Out<AccessKey> out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest);
virtual Result UnwrapTitleKey(sf::Out<AccessKey> out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest, u32 generation);
virtual Result LoadTitleKey(u32 keyslot, AccessKey access_key); virtual Result LoadTitleKey(u32 keyslot, AccessKey access_key);
virtual Result UnwrapCommonTitleKey(Out<AccessKey> out_access_key, KeySource key_source, u32 generation); virtual Result UnwrapCommonTitleKeyDeprecated(sf::Out<AccessKey> out_access_key, KeySource key_source);
virtual Result AllocateAesKeyslot(Out<u32> out_keyslot); virtual Result UnwrapCommonTitleKey(sf::Out<AccessKey> out_access_key, KeySource key_source, u32 generation);
virtual Result AllocateAesKeyslot(sf::Out<u32> out_keyslot);
virtual Result FreeAesKeyslot(u32 keyslot); virtual Result FreeAesKeyslot(u32 keyslot);
virtual void GetAesKeyslotAvailableEvent(Out<CopiedHandle> out_hnd); virtual void GetAesKeyslotAvailableEvent(sf::OutCopyHandle out_hnd);
virtual Result SetBootReason(BootReasonValue boot_reason); virtual Result SetBootReason(BootReasonValue boot_reason);
virtual Result GetBootReason(Out<BootReasonValue> out); virtual Result GetBootReason(sf::Out<BootReasonValue> out);
public: public:
DEFINE_SERVICE_DISPATCH_TABLE { DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(DeprecatedService, GetConfig), MAKE_SERVICE_COMMAND_META(GetConfig),
MAKE_SERVICE_COMMAND_META(DeprecatedService, ExpMod), MAKE_SERVICE_COMMAND_META(ExpMod),
MAKE_SERVICE_COMMAND_META(DeprecatedService, GenerateAesKek), MAKE_SERVICE_COMMAND_META(GenerateAesKek),
MAKE_SERVICE_COMMAND_META(DeprecatedService, LoadAesKey), MAKE_SERVICE_COMMAND_META(LoadAesKey),
MAKE_SERVICE_COMMAND_META(DeprecatedService, GenerateAesKey), MAKE_SERVICE_COMMAND_META(GenerateAesKey),
MAKE_SERVICE_COMMAND_META(DeprecatedService, SetConfig), MAKE_SERVICE_COMMAND_META(SetConfig),
MAKE_SERVICE_COMMAND_META(DeprecatedService, GenerateRandomBytes), MAKE_SERVICE_COMMAND_META(GenerateRandomBytes),
MAKE_SERVICE_COMMAND_META(DeprecatedService, ImportLotusKey), MAKE_SERVICE_COMMAND_META(ImportLotusKey),
MAKE_SERVICE_COMMAND_META(DeprecatedService, DecryptLotusMessage), MAKE_SERVICE_COMMAND_META(DecryptLotusMessage),
MAKE_SERVICE_COMMAND_META(DeprecatedService, IsDevelopment), MAKE_SERVICE_COMMAND_META(IsDevelopment),
MAKE_SERVICE_COMMAND_META(DeprecatedService, GenerateSpecificAesKey), MAKE_SERVICE_COMMAND_META(GenerateSpecificAesKey),
MAKE_SERVICE_COMMAND_META(DeprecatedService, DecryptRsaPrivateKey), MAKE_SERVICE_COMMAND_META(DecryptRsaPrivateKey),
MAKE_SERVICE_COMMAND_META(DeprecatedService, DecryptAesKey), MAKE_SERVICE_COMMAND_META(DecryptAesKey),
MAKE_SERVICE_COMMAND_META(DeprecatedService, CryptAesCtrDeprecated, FirmwareVersion_100, FirmwareVersion_100),
MAKE_SERVICE_COMMAND_META(DeprecatedService, CryptAesCtr, FirmwareVersion_200), MAKE_SERVICE_COMMAND_META(CryptAesCtrDeprecated, hos::Version_100, hos::Version_100),
MAKE_SERVICE_COMMAND_META(DeprecatedService, ComputeCmac), MAKE_SERVICE_COMMAND_META(CryptAesCtr, hos::Version_200),
MAKE_SERVICE_COMMAND_META(DeprecatedService, ImportEsKey),
MAKE_SERVICE_COMMAND_META(DeprecatedService, UnwrapTitleKey), MAKE_SERVICE_COMMAND_META(ComputeCmac),
MAKE_SERVICE_COMMAND_META(DeprecatedService, LoadTitleKey), MAKE_SERVICE_COMMAND_META(ImportEsKey),
MAKE_SERVICE_COMMAND_META(DeprecatedService, UnwrapCommonTitleKey, FirmwareVersion_200),
MAKE_SERVICE_COMMAND_META(DeprecatedService, AllocateAesKeyslot, FirmwareVersion_200), MAKE_SERVICE_COMMAND_META(UnwrapTitleKeyDeprecated, hos::Version_100, hos::Version_200),
MAKE_SERVICE_COMMAND_META(DeprecatedService, FreeAesKeyslot, FirmwareVersion_200), MAKE_SERVICE_COMMAND_META(UnwrapTitleKey, hos::Version_300),
MAKE_SERVICE_COMMAND_META(DeprecatedService, GetAesKeyslotAvailableEvent, FirmwareVersion_200),
MAKE_SERVICE_COMMAND_META(DeprecatedService, SetBootReason, FirmwareVersion_300), MAKE_SERVICE_COMMAND_META(LoadTitleKey),
MAKE_SERVICE_COMMAND_META(DeprecatedService, GetBootReason, FirmwareVersion_300),
MAKE_SERVICE_COMMAND_META(UnwrapCommonTitleKeyDeprecated, hos::Version_200, hos::Version_200),
MAKE_SERVICE_COMMAND_META(UnwrapCommonTitleKey, hos::Version_300),
MAKE_SERVICE_COMMAND_META(AllocateAesKeyslot, hos::Version_200),
MAKE_SERVICE_COMMAND_META(FreeAesKeyslot, hos::Version_200),
MAKE_SERVICE_COMMAND_META(GetAesKeyslotAvailableEvent, hos::Version_200),
MAKE_SERVICE_COMMAND_META(SetBootReason, hos::Version_300),
MAKE_SERVICE_COMMAND_META(GetBootReason, hos::Version_300),
}; };
}; };

View file

@ -22,28 +22,32 @@
namespace sts::spl { namespace sts::spl {
Result EsService::ImportEsKey(InPointer<u8> src, AccessKey access_key, KeySource key_source, u32 option) { Result EsService::ImportEsKeyDeprecated(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option) {
return impl::ImportEsKey(src.pointer, src.num_elements, access_key, key_source, option); return impl::ImportEsKey(src.GetPointer(), src.GetSize(), access_key, key_source, option);
} }
Result EsService::UnwrapTitleKey(Out<AccessKey> out_access_key, InPointer<u8> base, InPointer<u8> mod, InPointer<u8> label_digest, u32 generation) { Result EsService::ImportEsKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source) {
return impl::UnwrapTitleKey(out_access_key.GetPointer(), base.pointer, base.num_elements, mod.pointer, mod.num_elements, label_digest.pointer, label_digest.num_elements, generation); return impl::ImportEsKey(src.GetPointer(), src.GetSize(), access_key, key_source, static_cast<u32>(smc::DecryptOrImportMode::ImportEsKey));
} }
Result EsService::UnwrapCommonTitleKey(Out<AccessKey> out_access_key, KeySource key_source, u32 generation) { Result EsService::UnwrapTitleKey(sf::Out<AccessKey> out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest, u32 generation) {
return impl::UnwrapTitleKey(out_access_key.GetPointer(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize(), label_digest.GetPointer(), label_digest.GetSize(), generation);
}
Result EsService::UnwrapCommonTitleKey(sf::Out<AccessKey> out_access_key, KeySource key_source, u32 generation) {
return impl::UnwrapCommonTitleKey(out_access_key.GetPointer(), key_source, generation); return impl::UnwrapCommonTitleKey(out_access_key.GetPointer(), key_source, generation);
} }
Result EsService::ImportDrmKey(InPointer<u8> src, AccessKey access_key, KeySource key_source) { Result EsService::ImportDrmKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source) {
return impl::ImportDrmKey(src.pointer, src.num_elements, access_key, key_source); return impl::ImportDrmKey(src.GetPointer(), src.GetSize(), access_key, key_source);
} }
Result EsService::DrmExpMod(OutPointerWithClientSize<u8> out, InPointer<u8> base, InPointer<u8> mod) { Result EsService::DrmExpMod(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod) {
return impl::DrmExpMod(out.pointer, out.num_elements, base.pointer, base.num_elements, mod.pointer, mod.num_elements); return impl::DrmExpMod(out.GetPointer(), out.GetSize(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize());
} }
Result EsService::UnwrapElicenseKey(Out<AccessKey> out_access_key, InPointer<u8> base, InPointer<u8> mod, InPointer<u8> label_digest, u32 generation) { Result EsService::UnwrapElicenseKey(sf::Out<AccessKey> out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest, u32 generation) {
return impl::UnwrapElicenseKey(out_access_key.GetPointer(), base.pointer, base.num_elements, mod.pointer, mod.num_elements, label_digest.pointer, label_digest.num_elements, generation); return impl::UnwrapElicenseKey(out_access_key.GetPointer(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize(), label_digest.GetPointer(), label_digest.GetSize(), generation);
} }
Result EsService::LoadElicenseKey(u32 keyslot, AccessKey access_key) { Result EsService::LoadElicenseKey(u32 keyslot, AccessKey access_key) {

View file

@ -29,40 +29,42 @@ namespace sts::spl {
virtual ~EsService() { /* ... */} virtual ~EsService() { /* ... */}
protected: protected:
/* Actual commands. */ /* Actual commands. */
virtual Result ImportEsKey(InPointer<u8> src, AccessKey access_key, KeySource key_source, u32 option); virtual Result ImportEsKeyDeprecated(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option);
virtual Result UnwrapTitleKey(Out<AccessKey> out_access_key, InPointer<u8> base, InPointer<u8> mod, InPointer<u8> label_digest, u32 generation); virtual Result ImportEsKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source);
virtual Result UnwrapCommonTitleKey(Out<AccessKey> out_access_key, KeySource key_source, u32 generation); virtual Result UnwrapTitleKey(sf::Out<AccessKey> out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest, u32 generation);
virtual Result ImportDrmKey(InPointer<u8> src, AccessKey access_key, KeySource key_source); virtual Result UnwrapCommonTitleKey(sf::Out<AccessKey> out_access_key, KeySource key_source, u32 generation);
virtual Result DrmExpMod(OutPointerWithClientSize<u8> out, InPointer<u8> base, InPointer<u8> mod); virtual Result ImportDrmKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source);
virtual Result UnwrapElicenseKey(Out<AccessKey> out_access_key, InPointer<u8> base, InPointer<u8> mod, InPointer<u8> label_digest, u32 generation); virtual Result DrmExpMod(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod);
virtual Result UnwrapElicenseKey(sf::Out<AccessKey> out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest, u32 generation);
virtual Result LoadElicenseKey(u32 keyslot, AccessKey access_key); virtual Result LoadElicenseKey(u32 keyslot, AccessKey access_key);
public: public:
DEFINE_SERVICE_DISPATCH_TABLE { DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(EsService, GetConfig), MAKE_SERVICE_COMMAND_META(GetConfig),
MAKE_SERVICE_COMMAND_META(EsService, ExpMod), MAKE_SERVICE_COMMAND_META(ExpMod),
MAKE_SERVICE_COMMAND_META(EsService, SetConfig), MAKE_SERVICE_COMMAND_META(SetConfig),
MAKE_SERVICE_COMMAND_META(EsService, GenerateRandomBytes), MAKE_SERVICE_COMMAND_META(GenerateRandomBytes),
MAKE_SERVICE_COMMAND_META(EsService, IsDevelopment), MAKE_SERVICE_COMMAND_META(IsDevelopment),
MAKE_SERVICE_COMMAND_META(EsService, SetBootReason, FirmwareVersion_300), MAKE_SERVICE_COMMAND_META(SetBootReason, hos::Version_300),
MAKE_SERVICE_COMMAND_META(EsService, GetBootReason, FirmwareVersion_300), MAKE_SERVICE_COMMAND_META(GetBootReason, hos::Version_300),
MAKE_SERVICE_COMMAND_META(EsService, GenerateAesKek), MAKE_SERVICE_COMMAND_META(GenerateAesKek),
MAKE_SERVICE_COMMAND_META(EsService, LoadAesKey), MAKE_SERVICE_COMMAND_META(LoadAesKey),
MAKE_SERVICE_COMMAND_META(EsService, GenerateAesKey), MAKE_SERVICE_COMMAND_META(GenerateAesKey),
MAKE_SERVICE_COMMAND_META(EsService, DecryptAesKey), MAKE_SERVICE_COMMAND_META(DecryptAesKey),
MAKE_SERVICE_COMMAND_META(EsService, CryptAesCtr), MAKE_SERVICE_COMMAND_META(CryptAesCtr),
MAKE_SERVICE_COMMAND_META(EsService, ComputeCmac), MAKE_SERVICE_COMMAND_META(ComputeCmac),
MAKE_SERVICE_COMMAND_META(EsService, AllocateAesKeyslot, FirmwareVersion_200), MAKE_SERVICE_COMMAND_META(AllocateAesKeyslot, hos::Version_200),
MAKE_SERVICE_COMMAND_META(EsService, FreeAesKeyslot, FirmwareVersion_200), MAKE_SERVICE_COMMAND_META(FreeAesKeyslot, hos::Version_200),
MAKE_SERVICE_COMMAND_META(EsService, GetAesKeyslotAvailableEvent, FirmwareVersion_200), MAKE_SERVICE_COMMAND_META(GetAesKeyslotAvailableEvent, hos::Version_200),
MAKE_SERVICE_COMMAND_META(EsService, DecryptRsaPrivateKeyDeprecated, FirmwareVersion_400, FirmwareVersion_400), MAKE_SERVICE_COMMAND_META(DecryptRsaPrivateKeyDeprecated, hos::Version_400, hos::Version_400),
MAKE_SERVICE_COMMAND_META(EsService, DecryptRsaPrivateKey, FirmwareVersion_500), MAKE_SERVICE_COMMAND_META(DecryptRsaPrivateKey, hos::Version_500),
MAKE_SERVICE_COMMAND_META(EsService, ImportEsKey), MAKE_SERVICE_COMMAND_META(ImportEsKeyDeprecated, hos::Version_400, hos::Version_400),
MAKE_SERVICE_COMMAND_META(EsService, UnwrapTitleKey), MAKE_SERVICE_COMMAND_META(ImportEsKey, hos::Version_500),
MAKE_SERVICE_COMMAND_META(EsService, UnwrapCommonTitleKey, FirmwareVersion_200), MAKE_SERVICE_COMMAND_META(UnwrapTitleKey),
MAKE_SERVICE_COMMAND_META(EsService, ImportDrmKey, FirmwareVersion_500), MAKE_SERVICE_COMMAND_META(UnwrapCommonTitleKey, hos::Version_200),
MAKE_SERVICE_COMMAND_META(EsService, DrmExpMod, FirmwareVersion_500), MAKE_SERVICE_COMMAND_META(ImportDrmKey, hos::Version_500),
MAKE_SERVICE_COMMAND_META(EsService, UnwrapElicenseKey, FirmwareVersion_600), MAKE_SERVICE_COMMAND_META(DrmExpMod, hos::Version_500),
MAKE_SERVICE_COMMAND_META(EsService, LoadElicenseKey, FirmwareVersion_600), MAKE_SERVICE_COMMAND_META(UnwrapElicenseKey, hos::Version_600),
MAKE_SERVICE_COMMAND_META(LoadElicenseKey, hos::Version_600),
}; };
}; };

View file

@ -22,15 +22,19 @@
namespace sts::spl { namespace sts::spl {
Result FsService::ImportLotusKey(InPointer<u8> src, AccessKey access_key, KeySource key_source, u32 option) { Result FsService::ImportLotusKeyDeprecated(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option) {
return impl::ImportLotusKey(src.pointer, src.num_elements, access_key, key_source, option); return impl::ImportLotusKey(src.GetPointer(), src.GetSize(), access_key, key_source, option);
} }
Result FsService::DecryptLotusMessage(Out<u32> out_size, OutPointerWithClientSize<u8> out, InPointer<u8> base, InPointer<u8> mod, InPointer<u8> label_digest) { Result FsService::ImportLotusKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source) {
return impl::DecryptLotusMessage(out_size.GetPointer(), out.pointer, out.num_elements, base.pointer, base.num_elements, mod.pointer, mod.num_elements, label_digest.pointer, label_digest.num_elements); return impl::ImportLotusKey(src.GetPointer(), src.GetSize(), access_key, key_source, static_cast<u32>(smc::DecryptOrImportMode::ImportLotusKey));
} }
Result FsService::GenerateSpecificAesKey(Out<AesKey> out_key, KeySource key_source, u32 generation, u32 which) { Result FsService::DecryptLotusMessage(sf::Out<u32> out_size, const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest) {
return impl::DecryptLotusMessage(out_size.GetPointer(), out.GetPointer(), out.GetSize(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize(), label_digest.GetPointer(), label_digest.GetSize());
}
Result FsService::GenerateSpecificAesKey(sf::Out<AesKey> out_key, KeySource key_source, u32 generation, u32 which) {
return impl::GenerateSpecificAesKey(out_key.GetPointer(), key_source, generation, which); return impl::GenerateSpecificAesKey(out_key.GetPointer(), key_source, generation, which);
} }
@ -38,8 +42,8 @@ namespace sts::spl {
return impl::LoadTitleKey(keyslot, this, access_key); return impl::LoadTitleKey(keyslot, this, access_key);
} }
Result FsService::GetPackage2Hash(OutPointerWithClientSize<u8> dst) { Result FsService::GetPackage2Hash(const sf::OutPointerBuffer &dst) {
return impl::GetPackage2Hash(dst.pointer, dst.num_elements); return impl::GetPackage2Hash(dst.GetPointer(), dst.GetSize());
} }
} }

View file

@ -29,34 +29,36 @@ namespace sts::spl {
virtual ~FsService() { /* ... */ } virtual ~FsService() { /* ... */ }
protected: protected:
/* Actual commands. */ /* Actual commands. */
virtual Result ImportLotusKey(InPointer<u8> src, AccessKey access_key, KeySource key_source, u32 option); virtual Result ImportLotusKeyDeprecated(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option);
virtual Result DecryptLotusMessage(Out<u32> out_size, OutPointerWithClientSize<u8> out, InPointer<u8> base, InPointer<u8> mod, InPointer<u8> label_digest); virtual Result ImportLotusKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source);
virtual Result GenerateSpecificAesKey(Out<AesKey> out_key, KeySource key_source, u32 generation, u32 which); virtual Result DecryptLotusMessage(sf::Out<u32> out_size, const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest);
virtual Result GenerateSpecificAesKey(sf::Out<AesKey> out_key, KeySource key_source, u32 generation, u32 which);
virtual Result LoadTitleKey(u32 keyslot, AccessKey access_key); virtual Result LoadTitleKey(u32 keyslot, AccessKey access_key);
virtual Result GetPackage2Hash(OutPointerWithClientSize<u8> dst); virtual Result GetPackage2Hash(const sf::OutPointerBuffer &dst);
public: public:
DEFINE_SERVICE_DISPATCH_TABLE { DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(FsService, GetConfig), MAKE_SERVICE_COMMAND_META(GetConfig),
MAKE_SERVICE_COMMAND_META(FsService, ExpMod), MAKE_SERVICE_COMMAND_META(ExpMod),
MAKE_SERVICE_COMMAND_META(FsService, SetConfig), MAKE_SERVICE_COMMAND_META(SetConfig),
MAKE_SERVICE_COMMAND_META(FsService, GenerateRandomBytes), MAKE_SERVICE_COMMAND_META(GenerateRandomBytes),
MAKE_SERVICE_COMMAND_META(FsService, IsDevelopment), MAKE_SERVICE_COMMAND_META(IsDevelopment),
MAKE_SERVICE_COMMAND_META(FsService, SetBootReason, FirmwareVersion_300), MAKE_SERVICE_COMMAND_META(SetBootReason, hos::Version_300),
MAKE_SERVICE_COMMAND_META(FsService, GetBootReason, FirmwareVersion_300), MAKE_SERVICE_COMMAND_META(GetBootReason, hos::Version_300),
MAKE_SERVICE_COMMAND_META(FsService, GenerateAesKek), MAKE_SERVICE_COMMAND_META(GenerateAesKek),
MAKE_SERVICE_COMMAND_META(FsService, LoadAesKey), MAKE_SERVICE_COMMAND_META(LoadAesKey),
MAKE_SERVICE_COMMAND_META(FsService, GenerateAesKey), MAKE_SERVICE_COMMAND_META(GenerateAesKey),
MAKE_SERVICE_COMMAND_META(FsService, DecryptAesKey), MAKE_SERVICE_COMMAND_META(DecryptAesKey),
MAKE_SERVICE_COMMAND_META(FsService, CryptAesCtr), MAKE_SERVICE_COMMAND_META(CryptAesCtr),
MAKE_SERVICE_COMMAND_META(FsService, ComputeCmac), MAKE_SERVICE_COMMAND_META(ComputeCmac),
MAKE_SERVICE_COMMAND_META(FsService, AllocateAesKeyslot, FirmwareVersion_200), MAKE_SERVICE_COMMAND_META(AllocateAesKeyslot, hos::Version_200),
MAKE_SERVICE_COMMAND_META(FsService, FreeAesKeyslot, FirmwareVersion_200), MAKE_SERVICE_COMMAND_META(FreeAesKeyslot, hos::Version_200),
MAKE_SERVICE_COMMAND_META(FsService, GetAesKeyslotAvailableEvent, FirmwareVersion_200), MAKE_SERVICE_COMMAND_META(GetAesKeyslotAvailableEvent, hos::Version_200),
MAKE_SERVICE_COMMAND_META(FsService, ImportLotusKey), MAKE_SERVICE_COMMAND_META(ImportLotusKeyDeprecated, hos::Version_400, hos::Version_400),
MAKE_SERVICE_COMMAND_META(FsService, DecryptLotusMessage), MAKE_SERVICE_COMMAND_META(ImportLotusKey, hos::Version_500),
MAKE_SERVICE_COMMAND_META(FsService, GenerateSpecificAesKey), MAKE_SERVICE_COMMAND_META(DecryptLotusMessage),
MAKE_SERVICE_COMMAND_META(FsService, LoadTitleKey), MAKE_SERVICE_COMMAND_META(GenerateSpecificAesKey),
MAKE_SERVICE_COMMAND_META(FsService, GetPackage2Hash, FirmwareVersion_500), MAKE_SERVICE_COMMAND_META(LoadTitleKey),
MAKE_SERVICE_COMMAND_META(GetPackage2Hash, hos::Version_500),
}; };
}; };

View file

@ -22,23 +22,23 @@
namespace sts::spl { namespace sts::spl {
Result GeneralService::GetConfig(Out<u64> out, u32 which) { Result GeneralService::GetConfig(sf::Out<u64> out, u32 which) {
return impl::GetConfig(out.GetPointer(), static_cast<SplConfigItem>(which)); return impl::GetConfig(out.GetPointer(), static_cast<SplConfigItem>(which));
} }
Result GeneralService::ExpMod(OutPointerWithClientSize<u8> out, InPointer<u8> base, InPointer<u8> exp, InPointer<u8> mod) { Result GeneralService::ExpMod(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &exp, const sf::InPointerBuffer &mod) {
return impl::ExpMod(out.pointer, out.num_elements, base.pointer, base.num_elements, exp.pointer, exp.num_elements, mod.pointer, mod.num_elements); return impl::ExpMod(out.GetPointer(), out.GetSize(), base.GetPointer(), base.GetSize(), exp.GetPointer(), exp.GetSize(), mod.GetPointer(), mod.GetSize());
} }
Result GeneralService::SetConfig(u32 which, u64 value) { Result GeneralService::SetConfig(u32 which, u64 value) {
return impl::SetConfig(static_cast<SplConfigItem>(which), value); return impl::SetConfig(static_cast<SplConfigItem>(which), value);
} }
Result GeneralService::GenerateRandomBytes(OutPointerWithClientSize<u8> out) { Result GeneralService::GenerateRandomBytes(const sf::OutPointerBuffer &out) {
return impl::GenerateRandomBytes(out.pointer, out.num_elements); return impl::GenerateRandomBytes(out.GetPointer(), out.GetSize());
} }
Result GeneralService::IsDevelopment(Out<bool> is_dev) { Result GeneralService::IsDevelopment(sf::Out<bool> is_dev) {
return impl::IsDevelopment(is_dev.GetPointer()); return impl::IsDevelopment(is_dev.GetPointer());
} }
@ -46,7 +46,7 @@ namespace sts::spl {
return impl::SetBootReason(boot_reason); return impl::SetBootReason(boot_reason);
} }
Result GeneralService::GetBootReason(Out<BootReasonValue> out) { Result GeneralService::GetBootReason(sf::Out<BootReasonValue> out) {
return impl::GetBootReason(out.GetPointer()); return impl::GetBootReason(out.GetPointer());
} }

View file

@ -21,7 +21,7 @@
namespace sts::spl { namespace sts::spl {
class GeneralService : public IServiceObject { class GeneralService : public sf::IServiceObject {
protected: protected:
enum class CommandId { enum class CommandId {
/* 1.0.0+ */ /* 1.0.0+ */
@ -32,6 +32,7 @@ namespace sts::spl {
GenerateAesKey = 4, GenerateAesKey = 4,
SetConfig = 5, SetConfig = 5,
GenerateRandomBytes = 7, GenerateRandomBytes = 7,
ImportLotusKeyDeprecated = 9,
ImportLotusKey = 9, ImportLotusKey = 9,
DecryptLotusMessage = 10, DecryptLotusMessage = 10,
IsDevelopment = 11, IsDevelopment = 11,
@ -41,6 +42,7 @@ namespace sts::spl {
DecryptAesKey = 14, DecryptAesKey = 14,
CryptAesCtr = 15, CryptAesCtr = 15,
ComputeCmac = 16, ComputeCmac = 16,
ImportEsKeyDeprecated = 17,
ImportEsKey = 17, ImportEsKey = 17,
UnwrapTitleKey = 18, UnwrapTitleKey = 18,
LoadTitleKey = 19, LoadTitleKey = 19,
@ -72,22 +74,22 @@ namespace sts::spl {
virtual ~GeneralService() { /* ... */ } virtual ~GeneralService() { /* ... */ }
protected: protected:
/* Actual commands. */ /* Actual commands. */
virtual Result GetConfig(Out<u64> out, u32 which); virtual Result GetConfig(sf::Out<u64> out, u32 which);
virtual Result ExpMod(OutPointerWithClientSize<u8> out, InPointer<u8> base, InPointer<u8> exp, InPointer<u8> mod); virtual Result ExpMod(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &exp, const sf::InPointerBuffer &mod);
virtual Result SetConfig(u32 which, u64 value); virtual Result SetConfig(u32 which, u64 value);
virtual Result GenerateRandomBytes(OutPointerWithClientSize<u8> out); virtual Result GenerateRandomBytes(const sf::OutPointerBuffer &out);
virtual Result IsDevelopment(Out<bool> is_dev); virtual Result IsDevelopment(sf::Out<bool> is_dev);
virtual Result SetBootReason(BootReasonValue boot_reason); virtual Result SetBootReason(BootReasonValue boot_reason);
virtual Result GetBootReason(Out<BootReasonValue> out); virtual Result GetBootReason(sf::Out<BootReasonValue> out);
public: public:
DEFINE_SERVICE_DISPATCH_TABLE { DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(GeneralService, GetConfig), MAKE_SERVICE_COMMAND_META(GetConfig),
MAKE_SERVICE_COMMAND_META(GeneralService, ExpMod), MAKE_SERVICE_COMMAND_META(ExpMod),
MAKE_SERVICE_COMMAND_META(GeneralService, SetConfig), MAKE_SERVICE_COMMAND_META(SetConfig),
MAKE_SERVICE_COMMAND_META(GeneralService, GenerateRandomBytes), MAKE_SERVICE_COMMAND_META(GenerateRandomBytes),
MAKE_SERVICE_COMMAND_META(GeneralService, IsDevelopment), MAKE_SERVICE_COMMAND_META(IsDevelopment),
MAKE_SERVICE_COMMAND_META(GeneralService, SetBootReason, FirmwareVersion_300), MAKE_SERVICE_COMMAND_META(SetBootReason, hos::Version_300),
MAKE_SERVICE_COMMAND_META(GeneralService, GetBootReason, FirmwareVersion_300), MAKE_SERVICE_COMMAND_META(GetBootReason, hos::Version_300),
}; };
}; };

View file

@ -17,7 +17,6 @@
#include <cstdlib> #include <cstdlib>
#include <cstdint> #include <cstdint>
#include <cstring> #include <cstring>
#include <malloc.h>
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
@ -73,8 +72,10 @@ void __libnx_initheap(void) {
fake_heap_end = (char*)addr + size; fake_heap_end = (char*)addr + size;
} }
using namespace sts;
void __appInit(void) { void __appInit(void) {
SetFirmwareVersionForLibnx(); hos::SetVersionForLibnx();
/* SPL doesn't really access any services... */ /* SPL doesn't really access any services... */
} }
@ -83,37 +84,69 @@ void __appExit(void) {
/* SPL doesn't really access any services... */ /* SPL doesn't really access any services... */
} }
struct SplServerOptions { namespace {
static constexpr size_t PointerBufferSize = 0x800;
static constexpr size_t MaxDomains = 0; struct SplServerOptions {
static constexpr size_t MaxDomainObjects = 0; static constexpr size_t PointerBufferSize = 0x800;
}; static constexpr size_t MaxDomains = 0;
static constexpr size_t MaxDomainObjects = 0;
};
constexpr sm::ServiceName RandomServiceName = sm::ServiceName::Encode("csrng");
constexpr size_t RandomMaxSessions = 3;
constexpr sm::ServiceName DeprecatedServiceName = sm::ServiceName::Encode("spl:");
constexpr size_t DeprecatedMaxSessions = 12;
constexpr sm::ServiceName GeneralServiceName = sm::ServiceName::Encode("spl:");
constexpr size_t GeneralMaxSessions = 6;
constexpr sm::ServiceName CryptoServiceName = sm::ServiceName::Encode("spl:mig");
constexpr size_t CryptoMaxSessions = 6;
constexpr sm::ServiceName SslServiceName = sm::ServiceName::Encode("spl:ssl");
constexpr size_t SslMaxSessions = 2;
constexpr sm::ServiceName EsServiceName = sm::ServiceName::Encode("spl:es");
constexpr size_t EsMaxSessions = 2;
constexpr sm::ServiceName FsServiceName = sm::ServiceName::Encode("spl:fs");
constexpr size_t FsMaxSessions = 3;
constexpr sm::ServiceName ManuServiceName = sm::ServiceName::Encode("spl:manu");
constexpr size_t ManuMaxSessions = 1;
/* csrng, spl:, spl:mig, spl:ssl, spl:es, spl:fs, spl:manu. */
/* TODO: Consider max sessions enforcement? */
constexpr size_t NumServers = 7;
constexpr size_t ModernMaxSessions = GeneralMaxSessions + CryptoMaxSessions + SslMaxSessions + EsMaxSessions + FsMaxSessions + ManuMaxSessions;
constexpr size_t NumSessions = RandomMaxSessions + std::max(DeprecatedMaxSessions, ModernMaxSessions) + 1;
sf::hipc::ServerManager<NumServers, SplServerOptions, NumSessions> g_server_manager;
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
/* Initialize global context. */ /* Initialize global context. */
sts::spl::impl::Initialize(); spl::impl::Initialize();
/* Create server manager. */
static auto s_server_manager = WaitableManager<SplServerOptions>(1);
/* Create services. */ /* Create services. */
s_server_manager.AddWaitable(new ServiceServer<sts::spl::RandomService>("csrng", 3)); R_ASSERT(g_server_manager.RegisterServer<spl::RandomService>(RandomServiceName, RandomMaxSessions));
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_400) { if (hos::GetVersion() >= hos::Version_400) {
s_server_manager.AddWaitable(new ServiceServer<sts::spl::GeneralService>("spl:", 9)); R_ASSERT(g_server_manager.RegisterServer<spl::GeneralService>(GeneralServiceName, GeneralMaxSessions));
s_server_manager.AddWaitable(new ServiceServer<sts::spl::CryptoService>("spl:mig", 6)); R_ASSERT(g_server_manager.RegisterServer<spl::CryptoService>(CryptoServiceName, CryptoMaxSessions));
s_server_manager.AddWaitable(new ServiceServer<sts::spl::SslService>("spl:ssl", 2)); R_ASSERT(g_server_manager.RegisterServer<spl::SslService>(SslServiceName, SslMaxSessions));
s_server_manager.AddWaitable(new ServiceServer<sts::spl::EsService>("spl:es", 2)); R_ASSERT(g_server_manager.RegisterServer<spl::EsService>(EsServiceName, EsMaxSessions));
s_server_manager.AddWaitable(new ServiceServer<sts::spl::FsService>("spl:fs", 3)); R_ASSERT(g_server_manager.RegisterServer<spl::FsService>(FsServiceName, FsMaxSessions));
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) { if (hos::GetVersion() >= hos::Version_500) {
s_server_manager.AddWaitable(new ServiceServer<sts::spl::ManuService>("spl:manu", 1)); R_ASSERT(g_server_manager.RegisterServer<spl::ManuService>(ManuServiceName, ManuMaxSessions));
} }
} else { } else {
s_server_manager.AddWaitable(new ServiceServer<sts::spl::DeprecatedService>("spl:", 12)); R_ASSERT(g_server_manager.RegisterServer<spl::DeprecatedService>(DeprecatedServiceName, DeprecatedMaxSessions));
} }
/* Loop forever, servicing our services. */ /* Loop forever, servicing our services. */
s_server_manager.Process(); g_server_manager.LoopProcess();
return 0; return 0;
} }

View file

@ -22,8 +22,8 @@
namespace sts::spl { namespace sts::spl {
Result ManuService::ReEncryptRsaPrivateKey(OutPointerWithClientSize<u8> out, InPointer<u8> src, AccessKey access_key_dec, KeySource source_dec, AccessKey access_key_enc, KeySource source_enc, u32 option) { Result ManuService::ReEncryptRsaPrivateKey(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &src, AccessKey access_key_dec, KeySource source_dec, AccessKey access_key_enc, KeySource source_enc, u32 option) {
return impl::ReEncryptRsaPrivateKey(out.pointer, out.num_elements, src.pointer, src.num_elements, access_key_dec, source_dec, access_key_enc, source_enc, option); return impl::ReEncryptRsaPrivateKey(out.GetPointer(), out.GetSize(), src.GetPointer(), src.GetSize(), access_key_dec, source_dec, access_key_enc, source_enc, option);
} }
} }

View file

@ -30,28 +30,28 @@ namespace sts::spl {
virtual ~ManuService() { /* ... */ } virtual ~ManuService() { /* ... */ }
protected: protected:
/* Actual commands. */ /* Actual commands. */
virtual Result ReEncryptRsaPrivateKey(OutPointerWithClientSize<u8> out, InPointer<u8> src, AccessKey access_key_dec, KeySource source_dec, AccessKey access_key_enc, KeySource source_enc, u32 option); virtual Result ReEncryptRsaPrivateKey(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &src, AccessKey access_key_dec, KeySource source_dec, AccessKey access_key_enc, KeySource source_enc, u32 option);
public: public:
DEFINE_SERVICE_DISPATCH_TABLE { DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(ManuService, GetConfig), MAKE_SERVICE_COMMAND_META(GetConfig),
MAKE_SERVICE_COMMAND_META(ManuService, ExpMod), MAKE_SERVICE_COMMAND_META(ExpMod),
MAKE_SERVICE_COMMAND_META(ManuService, SetConfig), MAKE_SERVICE_COMMAND_META(SetConfig),
MAKE_SERVICE_COMMAND_META(ManuService, GenerateRandomBytes), MAKE_SERVICE_COMMAND_META(GenerateRandomBytes),
MAKE_SERVICE_COMMAND_META(ManuService, IsDevelopment), MAKE_SERVICE_COMMAND_META(IsDevelopment),
MAKE_SERVICE_COMMAND_META(ManuService, SetBootReason, FirmwareVersion_300), MAKE_SERVICE_COMMAND_META(SetBootReason, hos::Version_300),
MAKE_SERVICE_COMMAND_META(ManuService, GetBootReason, FirmwareVersion_300), MAKE_SERVICE_COMMAND_META(GetBootReason, hos::Version_300),
MAKE_SERVICE_COMMAND_META(ManuService, GenerateAesKek), MAKE_SERVICE_COMMAND_META(GenerateAesKek),
MAKE_SERVICE_COMMAND_META(ManuService, LoadAesKey), MAKE_SERVICE_COMMAND_META(LoadAesKey),
MAKE_SERVICE_COMMAND_META(ManuService, GenerateAesKey), MAKE_SERVICE_COMMAND_META(GenerateAesKey),
MAKE_SERVICE_COMMAND_META(ManuService, DecryptAesKey), MAKE_SERVICE_COMMAND_META(DecryptAesKey),
MAKE_SERVICE_COMMAND_META(ManuService, CryptAesCtr), MAKE_SERVICE_COMMAND_META(CryptAesCtr),
MAKE_SERVICE_COMMAND_META(ManuService, ComputeCmac), MAKE_SERVICE_COMMAND_META(ComputeCmac),
MAKE_SERVICE_COMMAND_META(ManuService, AllocateAesKeyslot, FirmwareVersion_200), MAKE_SERVICE_COMMAND_META(AllocateAesKeyslot, hos::Version_200),
MAKE_SERVICE_COMMAND_META(ManuService, FreeAesKeyslot, FirmwareVersion_200), MAKE_SERVICE_COMMAND_META(FreeAesKeyslot, hos::Version_200),
MAKE_SERVICE_COMMAND_META(ManuService, GetAesKeyslotAvailableEvent, FirmwareVersion_200), MAKE_SERVICE_COMMAND_META(GetAesKeyslotAvailableEvent, hos::Version_200),
MAKE_SERVICE_COMMAND_META(ManuService, DecryptRsaPrivateKeyDeprecated, FirmwareVersion_400, FirmwareVersion_400), MAKE_SERVICE_COMMAND_META(DecryptRsaPrivateKeyDeprecated, hos::Version_400, hos::Version_400),
MAKE_SERVICE_COMMAND_META(ManuService, DecryptRsaPrivateKey, FirmwareVersion_500), MAKE_SERVICE_COMMAND_META(DecryptRsaPrivateKey, hos::Version_500),
MAKE_SERVICE_COMMAND_META(ManuService, ReEncryptRsaPrivateKey, FirmwareVersion_500), MAKE_SERVICE_COMMAND_META(ReEncryptRsaPrivateKey, hos::Version_500),
}; };
}; };

View file

@ -22,8 +22,8 @@
namespace sts::spl { namespace sts::spl {
Result RandomService::GenerateRandomBytes(OutBuffer<u8> out) { Result RandomService::GenerateRandomBytes(const sf::OutBuffer &out) {
return impl::GenerateRandomBytes(out.buffer, out.num_elements); return impl::GenerateRandomBytes(out.GetPointer(), out.GetSize());
} }
} }

View file

@ -21,7 +21,7 @@
namespace sts::spl { namespace sts::spl {
class RandomService final : public IServiceObject { class RandomService final : public sf::IServiceObject {
protected: protected:
enum class CommandId { enum class CommandId {
GenerateRandomBytes = 0, GenerateRandomBytes = 0,
@ -31,10 +31,10 @@ namespace sts::spl {
virtual ~RandomService() { /* ... */ } virtual ~RandomService() { /* ... */ }
private: private:
/* Actual commands. */ /* Actual commands. */
virtual Result GenerateRandomBytes(OutBuffer<u8> out); virtual Result GenerateRandomBytes(const sf::OutBuffer &out);
public: public:
DEFINE_SERVICE_DISPATCH_TABLE { DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(RandomService, GenerateRandomBytes), MAKE_SERVICE_COMMAND_META(GenerateRandomBytes),
}; };
}; };

View file

@ -22,12 +22,12 @@
namespace sts::spl { namespace sts::spl {
Result RsaService::DecryptRsaPrivateKeyDeprecated(OutPointerWithClientSize<u8> dst, InPointer<u8> src, AccessKey access_key, KeySource key_source, u32 option) { Result RsaService::DecryptRsaPrivateKeyDeprecated(const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option) {
return impl::DecryptRsaPrivateKey(dst.pointer, dst.num_elements, src.pointer, src.num_elements, access_key, key_source, option); return impl::DecryptRsaPrivateKey(dst.GetPointer(), dst.GetSize(), src.GetPointer(), src.GetSize(), access_key, key_source, option);
} }
Result RsaService::DecryptRsaPrivateKey(OutPointerWithClientSize<u8> dst, InPointer<u8> src, AccessKey access_key, KeySource key_source) { Result RsaService::DecryptRsaPrivateKey(const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source) {
return impl::DecryptRsaPrivateKey(dst.pointer, dst.num_elements, src.pointer, src.num_elements, access_key, key_source, static_cast<u32>(smc::DecryptOrImportMode::DecryptRsaPrivateKey)); return impl::DecryptRsaPrivateKey(dst.GetPointer(), dst.GetSize(), src.GetPointer(), src.GetSize(), access_key, key_source, static_cast<u32>(smc::DecryptOrImportMode::DecryptRsaPrivateKey));
} }
} }

View file

@ -29,8 +29,8 @@ namespace sts::spl {
virtual ~RsaService() { /* ... */ } virtual ~RsaService() { /* ... */ }
protected: protected:
/* Actual commands. */ /* Actual commands. */
virtual Result DecryptRsaPrivateKeyDeprecated(OutPointerWithClientSize<u8> dst, InPointer<u8> src, AccessKey access_key, KeySource key_source, u32 option); virtual Result DecryptRsaPrivateKeyDeprecated(const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option);
virtual Result DecryptRsaPrivateKey(OutPointerWithClientSize<u8> dst, InPointer<u8> src, AccessKey access_key, KeySource key_source); virtual Result DecryptRsaPrivateKey(const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source);
}; };
} }

View file

@ -22,12 +22,12 @@
namespace sts::spl { namespace sts::spl {
Result SslService::ImportSslKey(InPointer<u8> src, AccessKey access_key, KeySource key_source) { Result SslService::ImportSslKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source) {
return impl::ImportSslKey(src.pointer, src.num_elements, access_key, key_source); return impl::ImportSslKey(src.GetPointer(), src.GetSize(), access_key, key_source);
} }
Result SslService::SslExpMod(OutPointerWithClientSize<u8> out, InPointer<u8> base, InPointer<u8> mod) { Result SslService::SslExpMod(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod) {
return impl::SslExpMod(out.pointer, out.num_elements, base.pointer, base.num_elements, mod.pointer, mod.num_elements); return impl::SslExpMod(out.GetPointer(), out.GetSize(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize());
} }
} }

View file

@ -29,30 +29,30 @@ namespace sts::spl {
virtual ~SslService() { /* ... */ } virtual ~SslService() { /* ... */ }
protected: protected:
/* Actual commands. */ /* Actual commands. */
virtual Result ImportSslKey(InPointer<u8> src, AccessKey access_key, KeySource key_source); virtual Result ImportSslKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source);
virtual Result SslExpMod(OutPointerWithClientSize<u8> out, InPointer<u8> base, InPointer<u8> mod); virtual Result SslExpMod(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod);
public: public:
DEFINE_SERVICE_DISPATCH_TABLE { DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(SslService, GetConfig), MAKE_SERVICE_COMMAND_META(GetConfig),
MAKE_SERVICE_COMMAND_META(SslService, ExpMod), MAKE_SERVICE_COMMAND_META(ExpMod),
MAKE_SERVICE_COMMAND_META(SslService, SetConfig), MAKE_SERVICE_COMMAND_META(SetConfig),
MAKE_SERVICE_COMMAND_META(SslService, GenerateRandomBytes), MAKE_SERVICE_COMMAND_META(GenerateRandomBytes),
MAKE_SERVICE_COMMAND_META(SslService, IsDevelopment), MAKE_SERVICE_COMMAND_META(IsDevelopment),
MAKE_SERVICE_COMMAND_META(SslService, SetBootReason, FirmwareVersion_300), MAKE_SERVICE_COMMAND_META(SetBootReason, hos::Version_300),
MAKE_SERVICE_COMMAND_META(SslService, GetBootReason, FirmwareVersion_300), MAKE_SERVICE_COMMAND_META(GetBootReason, hos::Version_300),
MAKE_SERVICE_COMMAND_META(SslService, GenerateAesKek), MAKE_SERVICE_COMMAND_META(GenerateAesKek),
MAKE_SERVICE_COMMAND_META(SslService, LoadAesKey), MAKE_SERVICE_COMMAND_META(LoadAesKey),
MAKE_SERVICE_COMMAND_META(SslService, GenerateAesKey), MAKE_SERVICE_COMMAND_META(GenerateAesKey),
MAKE_SERVICE_COMMAND_META(SslService, DecryptAesKey), MAKE_SERVICE_COMMAND_META(DecryptAesKey),
MAKE_SERVICE_COMMAND_META(SslService, CryptAesCtr), MAKE_SERVICE_COMMAND_META(CryptAesCtr),
MAKE_SERVICE_COMMAND_META(SslService, ComputeCmac), MAKE_SERVICE_COMMAND_META(ComputeCmac),
MAKE_SERVICE_COMMAND_META(SslService, AllocateAesKeyslot, FirmwareVersion_200), MAKE_SERVICE_COMMAND_META(AllocateAesKeyslot, hos::Version_200),
MAKE_SERVICE_COMMAND_META(SslService, FreeAesKeyslot, FirmwareVersion_200), MAKE_SERVICE_COMMAND_META(FreeAesKeyslot, hos::Version_200),
MAKE_SERVICE_COMMAND_META(SslService, GetAesKeyslotAvailableEvent, FirmwareVersion_200), MAKE_SERVICE_COMMAND_META(GetAesKeyslotAvailableEvent, hos::Version_200),
MAKE_SERVICE_COMMAND_META(SslService, DecryptRsaPrivateKeyDeprecated, FirmwareVersion_400, FirmwareVersion_400), MAKE_SERVICE_COMMAND_META(DecryptRsaPrivateKeyDeprecated, hos::Version_400, hos::Version_400),
MAKE_SERVICE_COMMAND_META(SslService, DecryptRsaPrivateKey, FirmwareVersion_500), MAKE_SERVICE_COMMAND_META(DecryptRsaPrivateKey, hos::Version_500),
MAKE_SERVICE_COMMAND_META(SslService, ImportSslKey, FirmwareVersion_500), MAKE_SERVICE_COMMAND_META(ImportSslKey, hos::Version_500),
MAKE_SERVICE_COMMAND_META(SslService, SslExpMod, FirmwareVersion_500), MAKE_SERVICE_COMMAND_META(SslExpMod, hos::Version_500),
}; };
}; };