diff --git a/stratosphere/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_service_object.hpp b/stratosphere/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_service_object.hpp index 2de93fb87..31b0657a9 100644 --- a/stratosphere/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_service_object.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_service_object.hpp @@ -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 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; diff --git a/stratosphere/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_server_message_processor.hpp b/stratosphere/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_server_message_processor.hpp index 4bc1fdb05..e77b06118 100644 --- a/stratosphere/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_server_message_processor.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_server_message_processor.hpp @@ -30,7 +30,7 @@ namespace sts::sf::cmif { /* Used to enabled templated message processors. */ 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 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; diff --git a/stratosphere/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp b/stratosphere/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp index d6056b2c6..b9d3dc207 100644 --- a/stratosphere/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp @@ -300,7 +300,7 @@ namespace sts::sf::impl { static constexpr void StableSort(std::array &map, const std::array &values) { /* 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 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 :( */ /* TODO: std::swap(map[j], map[j-1]); */ const size_t tmp = map[j]; @@ -686,7 +686,7 @@ namespace sts::sf::impl { template struct HipcCommandProcessor : public sf::cmif::ServerMessageProcessor { 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; bool is_request_valid = true; is_request_valid &= meta.send_pid == CommandMeta::HasInProcessIdHolder; @@ -789,7 +789,7 @@ namespace sts::sf::impl { }(); template> - 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::max(), "Invalid Index From Buffer Index"); constexpr auto Info = CommandMeta::ArgumentSerializationInfos[Index]; constexpr auto Attributes = CommandMeta::BufferAttributes[BufferIndex]; @@ -824,7 +824,7 @@ namespace sts::sf::impl { pointer_buffer_head = util::AlignDown(pointer_buffer_head - size, 0x10); buffer = cmif::PointerAndSize(pointer_buffer_head, size); } else { - const u16 *recv_pointer_sizes = reinterpret_cast(reinterpret_cast(ctx.request.data.data_words) + CommandMeta::InDataRawUnfixedOutPointerSizeOffset); + const u16 *recv_pointer_sizes = reinterpret_cast(reinterpret_cast(ctx.request.data.data_words) + in_headers_size + CommandMeta::InDataRawUnfixedOutPointerSizeOffset); const size_t size = size_t(recv_pointer_sizes[Info.unfixed_recv_pointer_index]); pointer_buffer_head = util::AlignDown(pointer_buffer_head - size, 0x10); buffer = cmif::PointerAndSize(pointer_buffer_head, size); @@ -894,11 +894,11 @@ namespace sts::sf::impl { } } public: - NX_CONSTEXPR Result ProcessBuffers(const cmif::ServiceDispatchContext &ctx, BufferArrayType &buffers, std::array &is_buffer_map_alias) { + NX_CONSTEXPR Result ProcessBuffers(const cmif::ServiceDispatchContext &ctx, BufferArrayType &buffers, std::array &is_buffer_map_alias, size_t in_headers_size) { bool map_alias_buffers_valid = true; size_t pointer_buffer_tail = ctx.pointer_buffer.GetAddress(); 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(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(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(1); _SF_IMPL_PROCESSOR_PROCESS_BUFFER_IMPL(2); @@ -1010,7 +1010,7 @@ namespace sts::sf::impl { return ResultSuccess; } - template::ClassType> + template constexpr Result InvokeServiceCommandImpl(CmifOutHeader **out_header_ptr, cmif::ServiceDispatchContext &ctx, const cmif::PointerAndSize &in_raw_data) { using CommandMeta = CommandMetaInfo; using ImplProcessorType = HipcCommandProcessor; @@ -1018,7 +1018,7 @@ namespace sts::sf::impl { using OutHandleHolderType = OutHandleHolder; using OutRawHolderType = OutRawHolder; using InOutObjectHolderType = InOutObjectHolder; - static_assert(std::is_base_of::value, "InvokeServiceCommandImpl: Invalid Override ClassType"); + using ClassType = typename CommandMeta::ClassType; static_assert(std::is_base_of::value, "InvokeServiceCommandImpl: Service Commands must be ServiceObject member functions"); /* Create a processor for us to work with. */ @@ -1032,7 +1032,8 @@ namespace sts::sf::impl { } /* 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. */ BufferArrayType buffers; @@ -1042,7 +1043,7 @@ namespace sts::sf::impl { InOutObjectHolderType in_out_objects_holder; /* 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. */ R_TRY(in_out_objects_holder.GetInObjects(ctx.processor)); @@ -1095,16 +1096,16 @@ namespace sts::sf::impl { namespace sts::sf { - template + template inline static constexpr cmif::ServiceCommandMeta MakeServiceCommandMeta() { return { .hosver_low = Low, .hosver_high = High, .cmd_id = static_cast(CommandId), - .handler = ::sts::sf::impl::InvokeServiceCommandImpl, + .handler = ::sts::sf::impl::InvokeServiceCommandImpl, }; } } -#define MAKE_SERVICE_COMMAND_META(Name, ...) ::sts::sf::MakeServiceCommandMeta() +#define MAKE_SERVICE_COMMAND_META(Name, ...) ::sts::sf::MakeServiceCommandMeta() diff --git a/stratosphere/spl/source/spl_api_impl.cpp b/stratosphere/spl/source/spl_api_impl.cpp index 9bd2b5938..509652228 100644 --- a/stratosphere/spl/source/spl_api_impl.cpp +++ b/stratosphere/spl/source/spl_api_impl.cpp @@ -45,7 +45,7 @@ namespace sts::spl::impl { /* Max Keyslots helper. */ inline size_t GetMaxKeyslots() { - return (GetRuntimeFirmwareVersion() >= FirmwareVersion_600) ? MaxAesKeyslots : MaxAesKeyslotsDeprecated; + return (hos::GetVersion() >= hos::Version_600) ? MaxAesKeyslots : MaxAesKeyslotsDeprecated; } /* Type definitions. */ @@ -289,7 +289,7 @@ namespace sts::spl::impl { if (keyslot >= GetMaxKeyslots()) { 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 ResultSuccess; @@ -353,7 +353,7 @@ namespace sts::spl::impl { armDCacheFlush(layout, sizeof(*layout)); 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(option)); } else { 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) { - if (GetRuntimeFirmwareVersion() <= FirmwareVersion_100) { + if (hos::GetVersion() <= hos::Version_100) { /* On 1.0.0, keyslots were kind of a wild west. */ *out_keyslot = 0; return ResultSuccess; @@ -722,7 +722,7 @@ namespace sts::spl::impl { } 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. */ return ResultSuccess; } @@ -758,9 +758,9 @@ namespace sts::spl::impl { smc::Result smc_res; size_t copy_size = 0; - if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) { + if (hos::GetVersion() >= hos::Version_500) { 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(option)); } else { smc_res = smc::DecryptRsaPrivateKey(©_size, layout->data, src_size, access_key, key_source, option); copy_size = std::min(dst_size, copy_size); @@ -785,8 +785,8 @@ namespace sts::spl::impl { /* ES */ Result ImportEsKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source, u32 option) { - if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) { - return ImportSecureExpModKey(src, src_size, access_key, key_source, static_cast(smc::DecryptOrImportMode::ImportEsKey)); + if (hos::GetVersion() >= hos::Version_500) { + return ImportSecureExpModKey(src, src_size, access_key, key_source, option); } else { struct ImportEsKeyLayout { u8 data[RsaPrivateKeyMetaSize + 2 * RsaPrivateKeySize + 0x10]; @@ -832,9 +832,6 @@ namespace sts::spl::impl { /* FS */ 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(smc::DecryptOrImportMode::ImportLotusKey); - } return ImportSecureExpModKey(src, src_size, access_key, key_source, option); } diff --git a/stratosphere/spl/source/spl_crypto_service.cpp b/stratosphere/spl/source/spl_crypto_service.cpp index 8dacd4ba6..322e25414 100644 --- a/stratosphere/spl/source/spl_crypto_service.cpp +++ b/stratosphere/spl/source/spl_crypto_service.cpp @@ -27,7 +27,7 @@ namespace sts::spl { impl::FreeAesKeyslots(this); } - Result CryptoService::GenerateAesKek(Out out_access_key, KeySource key_source, u32 generation, u32 option) { + Result CryptoService::GenerateAesKek(sf::Out out_access_key, KeySource key_source, u32 generation, u32 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); } - Result CryptoService::GenerateAesKey(Out out_key, AccessKey access_key, KeySource key_source) { + Result CryptoService::GenerateAesKey(sf::Out out_key, AccessKey access_key, KeySource key_source) { return impl::GenerateAesKey(out_key.GetPointer(), access_key, key_source); } - Result CryptoService::DecryptAesKey(Out out_key, KeySource key_source, u32 generation, u32 option) { + Result CryptoService::DecryptAesKey(sf::Out out_key, KeySource key_source, u32 generation, u32 option) { return impl::DecryptAesKey(out_key.GetPointer(), key_source, generation, option); } - Result CryptoService::CryptAesCtr(OutBuffer out_buf, u32 keyslot, 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); + Result CryptoService::CryptAesCtr(const sf::OutNonSecureBuffer &out_buf, u32 keyslot, const sf::InNonSecureBuffer &in_buf, IvCtr 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 out_cmac, u32 keyslot, InPointer in_buf) { - return impl::ComputeCmac(out_cmac.GetPointer(), keyslot, this, in_buf.pointer, in_buf.num_elements); + Result CryptoService::ComputeCmac(sf::Out out_cmac, u32 keyslot, const sf::InPointerBuffer &in_buf) { + return impl::ComputeCmac(out_cmac.GetPointer(), keyslot, this, in_buf.GetPointer(), in_buf.GetSize()); } - Result CryptoService::AllocateAesKeyslot(Out out_keyslot) { + Result CryptoService::AllocateAesKeyslot(sf::Out out_keyslot) { return impl::AllocateAesKeyslot(out_keyslot.GetPointer(), this); } @@ -59,7 +59,7 @@ namespace sts::spl { return impl::FreeAesKeyslot(keyslot, this); } - void CryptoService::GetAesKeyslotAvailableEvent(Out out_hnd) { + void CryptoService::GetAesKeyslotAvailableEvent(sf::OutCopyHandle out_hnd) { out_hnd.SetValue(impl::GetAesKeyslotAvailableEventHandle()); } diff --git a/stratosphere/spl/source/spl_crypto_service.hpp b/stratosphere/spl/source/spl_crypto_service.hpp index b118aae65..361959922 100644 --- a/stratosphere/spl/source/spl_crypto_service.hpp +++ b/stratosphere/spl/source/spl_crypto_service.hpp @@ -29,33 +29,33 @@ namespace sts::spl { virtual ~CryptoService(); protected: /* Actual commands. */ - virtual Result GenerateAesKek(Out out_access_key, KeySource key_source, u32 generation, u32 option); + virtual Result GenerateAesKek(sf::Out out_access_key, KeySource key_source, u32 generation, u32 option); virtual Result LoadAesKey(u32 keyslot, AccessKey access_key, KeySource key_source); - virtual Result GenerateAesKey(Out out_key, AccessKey access_key, KeySource key_source); - virtual Result DecryptAesKey(Out out_key, KeySource key_source, u32 generation, u32 option); - virtual Result CryptAesCtr(OutBuffer out_buf, u32 keyslot, InBuffer in_buf, IvCtr iv_ctr); - virtual Result ComputeCmac(Out out_cmac, u32 keyslot, InPointer in_buf); - virtual Result AllocateAesKeyslot(Out out_keyslot); + virtual Result GenerateAesKey(sf::Out out_key, AccessKey access_key, KeySource key_source); + virtual Result DecryptAesKey(sf::Out out_key, KeySource key_source, u32 generation, u32 option); + virtual Result CryptAesCtr(const sf::OutNonSecureBuffer &out_buf, u32 keyslot, const sf::InNonSecureBuffer &in_buf, IvCtr iv_ctr); + virtual Result ComputeCmac(sf::Out out_cmac, u32 keyslot, const sf::InPointerBuffer &in_buf); + virtual Result AllocateAesKeyslot(sf::Out out_keyslot); virtual Result FreeAesKeyslot(u32 keyslot); - virtual void GetAesKeyslotAvailableEvent(Out out_hnd); + virtual void GetAesKeyslotAvailableEvent(sf::OutCopyHandle out_hnd); public: DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(CryptoService, GetConfig), - MAKE_SERVICE_COMMAND_META(CryptoService, ExpMod), - MAKE_SERVICE_COMMAND_META(CryptoService, SetConfig), - MAKE_SERVICE_COMMAND_META(CryptoService, GenerateRandomBytes), - MAKE_SERVICE_COMMAND_META(CryptoService, IsDevelopment), - MAKE_SERVICE_COMMAND_META(CryptoService, SetBootReason, FirmwareVersion_300), - MAKE_SERVICE_COMMAND_META(CryptoService, GetBootReason, FirmwareVersion_300), - MAKE_SERVICE_COMMAND_META(CryptoService, GenerateAesKek), - MAKE_SERVICE_COMMAND_META(CryptoService, LoadAesKey), - MAKE_SERVICE_COMMAND_META(CryptoService, GenerateAesKey), - MAKE_SERVICE_COMMAND_META(CryptoService, DecryptAesKey), - MAKE_SERVICE_COMMAND_META(CryptoService, CryptAesCtr), - MAKE_SERVICE_COMMAND_META(CryptoService, ComputeCmac), - MAKE_SERVICE_COMMAND_META(CryptoService, AllocateAesKeyslot, FirmwareVersion_200), - MAKE_SERVICE_COMMAND_META(CryptoService, FreeAesKeyslot, FirmwareVersion_200), - MAKE_SERVICE_COMMAND_META(CryptoService, GetAesKeyslotAvailableEvent, FirmwareVersion_200), + MAKE_SERVICE_COMMAND_META(GetConfig), + MAKE_SERVICE_COMMAND_META(ExpMod), + MAKE_SERVICE_COMMAND_META(SetConfig), + MAKE_SERVICE_COMMAND_META(GenerateRandomBytes), + MAKE_SERVICE_COMMAND_META(IsDevelopment), + MAKE_SERVICE_COMMAND_META(SetBootReason, hos::Version_300), + MAKE_SERVICE_COMMAND_META(GetBootReason, hos::Version_300), + MAKE_SERVICE_COMMAND_META(GenerateAesKek), + MAKE_SERVICE_COMMAND_META(LoadAesKey), + MAKE_SERVICE_COMMAND_META(GenerateAesKey), + MAKE_SERVICE_COMMAND_META(DecryptAesKey), + MAKE_SERVICE_COMMAND_META(CryptAesCtr), + MAKE_SERVICE_COMMAND_META(ComputeCmac), + MAKE_SERVICE_COMMAND_META(AllocateAesKeyslot, hos::Version_200), + MAKE_SERVICE_COMMAND_META(FreeAesKeyslot, hos::Version_200), + MAKE_SERVICE_COMMAND_META(GetAesKeyslotAvailableEvent, hos::Version_200), }; }; diff --git a/stratosphere/spl/source/spl_deprecated_service.cpp b/stratosphere/spl/source/spl_deprecated_service.cpp index 21bcff2e6..674e2120c 100644 --- a/stratosphere/spl/source/spl_deprecated_service.cpp +++ b/stratosphere/spl/source/spl_deprecated_service.cpp @@ -22,15 +22,15 @@ namespace sts::spl { - Result DeprecatedService::GetConfig(Out out, u32 which) { + Result DeprecatedService::GetConfig(sf::Out out, u32 which) { return impl::GetConfig(out.GetPointer(), static_cast(which)); } - Result DeprecatedService::ExpMod(OutPointerWithClientSize out, InPointer base, InPointer exp, InPointer mod) { - return impl::ExpMod(out.pointer, out.num_elements, base.pointer, base.num_elements, exp.pointer, exp.num_elements, mod.pointer, mod.num_elements); + Result DeprecatedService::ExpMod(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &exp, const sf::InPointerBuffer &mod) { + return impl::ExpMod(out.GetPointer(), out.GetSize(), base.GetPointer(), base.GetSize(), exp.GetPointer(), exp.GetSize(), mod.GetPointer(), mod.GetSize()); } - Result DeprecatedService::GenerateAesKek(Out out_access_key, KeySource key_source, u32 generation, u32 option) { + Result DeprecatedService::GenerateAesKek(sf::Out out_access_key, KeySource key_source, u32 generation, u32 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); } - Result DeprecatedService::GenerateAesKey(Out out_key, AccessKey access_key, KeySource key_source) { + Result DeprecatedService::GenerateAesKey(sf::Out out_key, AccessKey access_key, KeySource key_source) { return impl::GenerateAesKey(out_key.GetPointer(), access_key, key_source); } @@ -46,63 +46,71 @@ namespace sts::spl { return impl::SetConfig(static_cast(which), value); } - Result DeprecatedService::GenerateRandomBytes(OutPointerWithClientSize out) { - return impl::GenerateRandomBytes(out.pointer, out.num_elements); + Result DeprecatedService::GenerateRandomBytes(const sf::OutPointerBuffer &out) { + return impl::GenerateRandomBytes(out.GetPointer(), out.GetSize()); } - Result DeprecatedService::ImportLotusKey(InPointer src, AccessKey access_key, KeySource key_source, u32 option) { - return impl::ImportLotusKey(src.pointer, src.num_elements, access_key, key_source, option); + Result DeprecatedService::ImportLotusKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option) { + return impl::ImportLotusKey(src.GetPointer(), src.GetSize(), access_key, key_source, option); } - Result DeprecatedService::DecryptLotusMessage(Out out_size, OutPointerWithClientSize out, InPointer base, InPointer mod, InPointer 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); + Result DeprecatedService::DecryptLotusMessage(sf::Out 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 DeprecatedService::IsDevelopment(Out is_dev) { + Result DeprecatedService::IsDevelopment(sf::Out is_dev) { return impl::IsDevelopment(is_dev.GetPointer()); } - Result DeprecatedService::GenerateSpecificAesKey(Out out_key, KeySource key_source, u32 generation, u32 which) { + Result DeprecatedService::GenerateSpecificAesKey(sf::Out out_key, KeySource key_source, u32 generation, u32 which) { return impl::GenerateSpecificAesKey(out_key.GetPointer(), key_source, generation, which); } - Result DeprecatedService::DecryptRsaPrivateKey(OutPointerWithClientSize dst, InPointer 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); + Result DeprecatedService::DecryptRsaPrivateKey(const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option) { + return impl::DecryptRsaPrivateKey(dst.GetPointer(), dst.GetSize(), src.GetPointer(), src.GetSize(), access_key, key_source, option); } - Result DeprecatedService::DecryptAesKey(Out out_key, KeySource key_source, u32 generation, u32 option) { + Result DeprecatedService::DecryptAesKey(sf::Out out_key, KeySource key_source, u32 generation, u32 option) { return impl::DecryptAesKey(out_key.GetPointer(), key_source, generation, option); } - Result DeprecatedService::CryptAesCtrDeprecated(OutBuffer out_buf, u32 keyslot, 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); + Result DeprecatedService::CryptAesCtrDeprecated(const sf::OutBuffer &out_buf, u32 keyslot, const sf::InBuffer &in_buf, IvCtr 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 out_buf, u32 keyslot, 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); + Result DeprecatedService::CryptAesCtr(const sf::OutNonSecureBuffer &out_buf, u32 keyslot, const sf::InNonSecureBuffer &in_buf, IvCtr 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 out_cmac, u32 keyslot, InPointer in_buf) { - return impl::ComputeCmac(out_cmac.GetPointer(), keyslot, this, in_buf.pointer, in_buf.num_elements); + Result DeprecatedService::ComputeCmac(sf::Out out_cmac, u32 keyslot, const sf::InPointerBuffer &in_buf) { + return impl::ComputeCmac(out_cmac.GetPointer(), keyslot, this, in_buf.GetPointer(), in_buf.GetSize()); } - Result DeprecatedService::ImportEsKey(InPointer src, AccessKey access_key, KeySource key_source, u32 option) { - return impl::ImportEsKey(src.pointer, src.num_elements, access_key, key_source, option); + Result DeprecatedService::ImportEsKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option) { + return impl::ImportEsKey(src.GetPointer(), src.GetSize(), access_key, key_source, option); } - Result DeprecatedService::UnwrapTitleKey(Out out_access_key, InPointer base, InPointer mod, InPointer label_digest, u32 generation) { - 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); + Result DeprecatedService::UnwrapTitleKeyDeprecated(sf::Out out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest) { + 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 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) { return impl::LoadTitleKey(keyslot, this, access_key); } - Result DeprecatedService::UnwrapCommonTitleKey(Out out_access_key, KeySource key_source, u32 generation) { + Result DeprecatedService::UnwrapCommonTitleKeyDeprecated(sf::Out out_access_key, KeySource key_source) { + return impl::UnwrapCommonTitleKey(out_access_key.GetPointer(), key_source, 0); + } + + Result DeprecatedService::UnwrapCommonTitleKey(sf::Out out_access_key, KeySource key_source, u32 generation) { return impl::UnwrapCommonTitleKey(out_access_key.GetPointer(), key_source, generation); } - Result DeprecatedService::AllocateAesKeyslot(Out out_keyslot) { + Result DeprecatedService::AllocateAesKeyslot(sf::Out out_keyslot) { return impl::AllocateAesKeyslot(out_keyslot.GetPointer(), this); } @@ -110,7 +118,7 @@ namespace sts::spl { return impl::FreeAesKeyslot(keyslot, this); } - void DeprecatedService::GetAesKeyslotAvailableEvent(Out out_hnd) { + void DeprecatedService::GetAesKeyslotAvailableEvent(sf::OutCopyHandle out_hnd) { out_hnd.SetValue(impl::GetAesKeyslotAvailableEventHandle()); } @@ -118,7 +126,7 @@ namespace sts::spl { return impl::SetBootReason(boot_reason); } - Result DeprecatedService::GetBootReason(Out out) { + Result DeprecatedService::GetBootReason(sf::Out out) { return impl::GetBootReason(out.GetPointer()); } diff --git a/stratosphere/spl/source/spl_deprecated_service.hpp b/stratosphere/spl/source/spl_deprecated_service.hpp index e9e97cb14..577bfd23d 100644 --- a/stratosphere/spl/source/spl_deprecated_service.hpp +++ b/stratosphere/spl/source/spl_deprecated_service.hpp @@ -21,7 +21,7 @@ namespace sts::spl { - class DeprecatedService : public IServiceObject { + class DeprecatedService : public sf::IServiceObject { protected: enum class CommandId { /* 1.0.0+ */ @@ -43,10 +43,12 @@ namespace sts::spl { CryptAesCtr = 15, ComputeCmac = 16, ImportEsKey = 17, + UnwrapTitleKeyDeprecated = 18, UnwrapTitleKey = 18, LoadTitleKey = 19, /* 2.0.0+ */ + UnwrapCommonTitleKeyDeprecated = 20, UnwrapCommonTitleKey = 20, AllocateAesKeyslot = 21, FreeAesKeyslot = 22, @@ -61,58 +63,69 @@ namespace sts::spl { virtual ~DeprecatedService() { /* ... */ } protected: /* Actual commands. */ - virtual Result GetConfig(Out out, u32 which); - virtual Result ExpMod(OutPointerWithClientSize out, InPointer base, InPointer exp, InPointer mod); - virtual Result GenerateAesKek(Out out_access_key, KeySource key_source, u32 generation, u32 option); + virtual Result GetConfig(sf::Out out, u32 which); + virtual Result ExpMod(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &exp, const sf::InPointerBuffer &mod); + virtual Result GenerateAesKek(sf::Out out_access_key, KeySource key_source, u32 generation, u32 option); virtual Result LoadAesKey(u32 keyslot, AccessKey access_key, KeySource key_source); - virtual Result GenerateAesKey(Out out_key, AccessKey access_key, KeySource key_source); + virtual Result GenerateAesKey(sf::Out out_key, AccessKey access_key, KeySource key_source); virtual Result SetConfig(u32 which, u64 value); - virtual Result GenerateRandomBytes(OutPointerWithClientSize out); - virtual Result ImportLotusKey(InPointer src, AccessKey access_key, KeySource key_source, u32 option); - virtual Result DecryptLotusMessage(Out out_size, OutPointerWithClientSize out, InPointer base, InPointer mod, InPointer label_digest); - virtual Result IsDevelopment(Out is_dev); - virtual Result GenerateSpecificAesKey(Out out_key, KeySource key_source, u32 generation, u32 which); - virtual Result DecryptRsaPrivateKey(OutPointerWithClientSize dst, InPointer src, AccessKey access_key, KeySource key_source, u32 option); - virtual Result DecryptAesKey(Out out_key, KeySource key_source, u32 generation, u32 option); - virtual Result CryptAesCtrDeprecated(OutBuffer out_buf, u32 keyslot, InBuffer in_buf, IvCtr iv_ctr); - virtual Result CryptAesCtr(OutBuffer out_buf, u32 keyslot, InBuffer in_buf, IvCtr iv_ctr); - virtual Result ComputeCmac(Out out_cmac, u32 keyslot, InPointer in_buf); - virtual Result ImportEsKey(InPointer src, AccessKey access_key, KeySource key_source, u32 option); - virtual Result UnwrapTitleKey(Out out_access_key, InPointer base, InPointer mod, InPointer label_digest, u32 generation); + virtual Result GenerateRandomBytes(const sf::OutPointerBuffer &out); + virtual Result ImportLotusKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option); + virtual Result DecryptLotusMessage(sf::Out out_size, const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest); + virtual Result IsDevelopment(sf::Out is_dev); + virtual Result GenerateSpecificAesKey(sf::Out out_key, KeySource key_source, u32 generation, u32 which); + virtual Result DecryptRsaPrivateKey(const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option); + virtual Result DecryptAesKey(sf::Out out_key, KeySource key_source, u32 generation, u32 option); + virtual Result CryptAesCtrDeprecated(const sf::OutBuffer &out_buf, u32 keyslot, const sf::InBuffer &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(sf::Out out_cmac, u32 keyslot, const sf::InPointerBuffer &in_buf); + virtual Result ImportEsKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option); + virtual Result UnwrapTitleKeyDeprecated(sf::Out out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest); + virtual Result UnwrapTitleKey(sf::Out 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 UnwrapCommonTitleKey(Out out_access_key, KeySource key_source, u32 generation); - virtual Result AllocateAesKeyslot(Out out_keyslot); + virtual Result UnwrapCommonTitleKeyDeprecated(sf::Out out_access_key, KeySource key_source); + virtual Result UnwrapCommonTitleKey(sf::Out out_access_key, KeySource key_source, u32 generation); + virtual Result AllocateAesKeyslot(sf::Out out_keyslot); virtual Result FreeAesKeyslot(u32 keyslot); - virtual void GetAesKeyslotAvailableEvent(Out out_hnd); + virtual void GetAesKeyslotAvailableEvent(sf::OutCopyHandle out_hnd); virtual Result SetBootReason(BootReasonValue boot_reason); - virtual Result GetBootReason(Out out); + virtual Result GetBootReason(sf::Out out); public: DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(DeprecatedService, GetConfig), - MAKE_SERVICE_COMMAND_META(DeprecatedService, ExpMod), - MAKE_SERVICE_COMMAND_META(DeprecatedService, GenerateAesKek), - MAKE_SERVICE_COMMAND_META(DeprecatedService, LoadAesKey), - MAKE_SERVICE_COMMAND_META(DeprecatedService, GenerateAesKey), - MAKE_SERVICE_COMMAND_META(DeprecatedService, SetConfig), - MAKE_SERVICE_COMMAND_META(DeprecatedService, GenerateRandomBytes), - MAKE_SERVICE_COMMAND_META(DeprecatedService, ImportLotusKey), - MAKE_SERVICE_COMMAND_META(DeprecatedService, DecryptLotusMessage), - MAKE_SERVICE_COMMAND_META(DeprecatedService, IsDevelopment), - MAKE_SERVICE_COMMAND_META(DeprecatedService, GenerateSpecificAesKey), - MAKE_SERVICE_COMMAND_META(DeprecatedService, DecryptRsaPrivateKey), - MAKE_SERVICE_COMMAND_META(DeprecatedService, DecryptAesKey), - MAKE_SERVICE_COMMAND_META(DeprecatedService, CryptAesCtrDeprecated, FirmwareVersion_100, FirmwareVersion_100), - MAKE_SERVICE_COMMAND_META(DeprecatedService, CryptAesCtr, FirmwareVersion_200), - MAKE_SERVICE_COMMAND_META(DeprecatedService, ComputeCmac), - MAKE_SERVICE_COMMAND_META(DeprecatedService, ImportEsKey), - MAKE_SERVICE_COMMAND_META(DeprecatedService, UnwrapTitleKey), - MAKE_SERVICE_COMMAND_META(DeprecatedService, LoadTitleKey), - MAKE_SERVICE_COMMAND_META(DeprecatedService, UnwrapCommonTitleKey, FirmwareVersion_200), - MAKE_SERVICE_COMMAND_META(DeprecatedService, AllocateAesKeyslot, FirmwareVersion_200), - MAKE_SERVICE_COMMAND_META(DeprecatedService, FreeAesKeyslot, FirmwareVersion_200), - MAKE_SERVICE_COMMAND_META(DeprecatedService, GetAesKeyslotAvailableEvent, FirmwareVersion_200), - MAKE_SERVICE_COMMAND_META(DeprecatedService, SetBootReason, FirmwareVersion_300), - MAKE_SERVICE_COMMAND_META(DeprecatedService, GetBootReason, FirmwareVersion_300), + MAKE_SERVICE_COMMAND_META(GetConfig), + MAKE_SERVICE_COMMAND_META(ExpMod), + MAKE_SERVICE_COMMAND_META(GenerateAesKek), + MAKE_SERVICE_COMMAND_META(LoadAesKey), + MAKE_SERVICE_COMMAND_META(GenerateAesKey), + MAKE_SERVICE_COMMAND_META(SetConfig), + MAKE_SERVICE_COMMAND_META(GenerateRandomBytes), + MAKE_SERVICE_COMMAND_META(ImportLotusKey), + MAKE_SERVICE_COMMAND_META(DecryptLotusMessage), + MAKE_SERVICE_COMMAND_META(IsDevelopment), + MAKE_SERVICE_COMMAND_META(GenerateSpecificAesKey), + MAKE_SERVICE_COMMAND_META(DecryptRsaPrivateKey), + MAKE_SERVICE_COMMAND_META(DecryptAesKey), + + MAKE_SERVICE_COMMAND_META(CryptAesCtrDeprecated, hos::Version_100, hos::Version_100), + MAKE_SERVICE_COMMAND_META(CryptAesCtr, hos::Version_200), + + MAKE_SERVICE_COMMAND_META(ComputeCmac), + MAKE_SERVICE_COMMAND_META(ImportEsKey), + + MAKE_SERVICE_COMMAND_META(UnwrapTitleKeyDeprecated, hos::Version_100, hos::Version_200), + MAKE_SERVICE_COMMAND_META(UnwrapTitleKey, hos::Version_300), + + MAKE_SERVICE_COMMAND_META(LoadTitleKey), + + 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), }; }; diff --git a/stratosphere/spl/source/spl_es_service.cpp b/stratosphere/spl/source/spl_es_service.cpp index 96aa8a15b..1b6bdec2c 100644 --- a/stratosphere/spl/source/spl_es_service.cpp +++ b/stratosphere/spl/source/spl_es_service.cpp @@ -22,28 +22,32 @@ namespace sts::spl { - Result EsService::ImportEsKey(InPointer src, AccessKey access_key, KeySource key_source, u32 option) { - return impl::ImportEsKey(src.pointer, src.num_elements, access_key, key_source, option); + Result EsService::ImportEsKeyDeprecated(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option) { + return impl::ImportEsKey(src.GetPointer(), src.GetSize(), access_key, key_source, option); } - Result EsService::UnwrapTitleKey(Out out_access_key, InPointer base, InPointer mod, InPointer label_digest, u32 generation) { - 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); + Result EsService::ImportEsKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source) { + return impl::ImportEsKey(src.GetPointer(), src.GetSize(), access_key, key_source, static_cast(smc::DecryptOrImportMode::ImportEsKey)); } - Result EsService::UnwrapCommonTitleKey(Out out_access_key, KeySource key_source, u32 generation) { + Result EsService::UnwrapTitleKey(sf::Out 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 out_access_key, KeySource key_source, u32 generation) { return impl::UnwrapCommonTitleKey(out_access_key.GetPointer(), key_source, generation); } - Result EsService::ImportDrmKey(InPointer src, AccessKey access_key, KeySource key_source) { - return impl::ImportDrmKey(src.pointer, src.num_elements, access_key, key_source); + Result EsService::ImportDrmKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source) { + return impl::ImportDrmKey(src.GetPointer(), src.GetSize(), access_key, key_source); } - Result EsService::DrmExpMod(OutPointerWithClientSize out, InPointer base, InPointer mod) { - return impl::DrmExpMod(out.pointer, out.num_elements, base.pointer, base.num_elements, mod.pointer, mod.num_elements); + Result EsService::DrmExpMod(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod) { + return impl::DrmExpMod(out.GetPointer(), out.GetSize(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize()); } - Result EsService::UnwrapElicenseKey(Out out_access_key, InPointer base, InPointer mod, InPointer 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); + Result EsService::UnwrapElicenseKey(sf::Out 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.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize(), label_digest.GetPointer(), label_digest.GetSize(), generation); } Result EsService::LoadElicenseKey(u32 keyslot, AccessKey access_key) { diff --git a/stratosphere/spl/source/spl_es_service.hpp b/stratosphere/spl/source/spl_es_service.hpp index 483ce2ead..3d6660802 100644 --- a/stratosphere/spl/source/spl_es_service.hpp +++ b/stratosphere/spl/source/spl_es_service.hpp @@ -29,40 +29,42 @@ namespace sts::spl { virtual ~EsService() { /* ... */} protected: /* Actual commands. */ - virtual Result ImportEsKey(InPointer src, AccessKey access_key, KeySource key_source, u32 option); - virtual Result UnwrapTitleKey(Out out_access_key, InPointer base, InPointer mod, InPointer label_digest, u32 generation); - virtual Result UnwrapCommonTitleKey(Out out_access_key, KeySource key_source, u32 generation); - virtual Result ImportDrmKey(InPointer src, AccessKey access_key, KeySource key_source); - virtual Result DrmExpMod(OutPointerWithClientSize out, InPointer base, InPointer mod); - virtual Result UnwrapElicenseKey(Out out_access_key, InPointer base, InPointer mod, InPointer label_digest, u32 generation); + virtual Result ImportEsKeyDeprecated(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option); + virtual Result ImportEsKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source); + virtual Result UnwrapTitleKey(sf::Out out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest, u32 generation); + virtual Result UnwrapCommonTitleKey(sf::Out out_access_key, KeySource key_source, u32 generation); + virtual Result ImportDrmKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source); + virtual Result DrmExpMod(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod); + virtual Result UnwrapElicenseKey(sf::Out 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); public: DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(EsService, GetConfig), - MAKE_SERVICE_COMMAND_META(EsService, ExpMod), - MAKE_SERVICE_COMMAND_META(EsService, SetConfig), - MAKE_SERVICE_COMMAND_META(EsService, GenerateRandomBytes), - MAKE_SERVICE_COMMAND_META(EsService, IsDevelopment), - MAKE_SERVICE_COMMAND_META(EsService, SetBootReason, FirmwareVersion_300), - MAKE_SERVICE_COMMAND_META(EsService, GetBootReason, FirmwareVersion_300), - MAKE_SERVICE_COMMAND_META(EsService, GenerateAesKek), - MAKE_SERVICE_COMMAND_META(EsService, LoadAesKey), - MAKE_SERVICE_COMMAND_META(EsService, GenerateAesKey), - MAKE_SERVICE_COMMAND_META(EsService, DecryptAesKey), - MAKE_SERVICE_COMMAND_META(EsService, CryptAesCtr), - MAKE_SERVICE_COMMAND_META(EsService, ComputeCmac), - MAKE_SERVICE_COMMAND_META(EsService, AllocateAesKeyslot, FirmwareVersion_200), - MAKE_SERVICE_COMMAND_META(EsService, FreeAesKeyslot, FirmwareVersion_200), - MAKE_SERVICE_COMMAND_META(EsService, GetAesKeyslotAvailableEvent, FirmwareVersion_200), - MAKE_SERVICE_COMMAND_META(EsService, DecryptRsaPrivateKeyDeprecated, FirmwareVersion_400, FirmwareVersion_400), - MAKE_SERVICE_COMMAND_META(EsService, DecryptRsaPrivateKey, FirmwareVersion_500), - MAKE_SERVICE_COMMAND_META(EsService, ImportEsKey), - MAKE_SERVICE_COMMAND_META(EsService, UnwrapTitleKey), - MAKE_SERVICE_COMMAND_META(EsService, UnwrapCommonTitleKey, FirmwareVersion_200), - MAKE_SERVICE_COMMAND_META(EsService, ImportDrmKey, FirmwareVersion_500), - MAKE_SERVICE_COMMAND_META(EsService, DrmExpMod, FirmwareVersion_500), - MAKE_SERVICE_COMMAND_META(EsService, UnwrapElicenseKey, FirmwareVersion_600), - MAKE_SERVICE_COMMAND_META(EsService, LoadElicenseKey, FirmwareVersion_600), + MAKE_SERVICE_COMMAND_META(GetConfig), + MAKE_SERVICE_COMMAND_META(ExpMod), + MAKE_SERVICE_COMMAND_META(SetConfig), + MAKE_SERVICE_COMMAND_META(GenerateRandomBytes), + MAKE_SERVICE_COMMAND_META(IsDevelopment), + MAKE_SERVICE_COMMAND_META(SetBootReason, hos::Version_300), + MAKE_SERVICE_COMMAND_META(GetBootReason, hos::Version_300), + MAKE_SERVICE_COMMAND_META(GenerateAesKek), + MAKE_SERVICE_COMMAND_META(LoadAesKey), + MAKE_SERVICE_COMMAND_META(GenerateAesKey), + MAKE_SERVICE_COMMAND_META(DecryptAesKey), + MAKE_SERVICE_COMMAND_META(CryptAesCtr), + MAKE_SERVICE_COMMAND_META(ComputeCmac), + 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(DecryptRsaPrivateKeyDeprecated, hos::Version_400, hos::Version_400), + MAKE_SERVICE_COMMAND_META(DecryptRsaPrivateKey, hos::Version_500), + MAKE_SERVICE_COMMAND_META(ImportEsKeyDeprecated, hos::Version_400, hos::Version_400), + MAKE_SERVICE_COMMAND_META(ImportEsKey, hos::Version_500), + MAKE_SERVICE_COMMAND_META(UnwrapTitleKey), + MAKE_SERVICE_COMMAND_META(UnwrapCommonTitleKey, hos::Version_200), + MAKE_SERVICE_COMMAND_META(ImportDrmKey, hos::Version_500), + MAKE_SERVICE_COMMAND_META(DrmExpMod, hos::Version_500), + MAKE_SERVICE_COMMAND_META(UnwrapElicenseKey, hos::Version_600), + MAKE_SERVICE_COMMAND_META(LoadElicenseKey, hos::Version_600), }; }; diff --git a/stratosphere/spl/source/spl_fs_service.cpp b/stratosphere/spl/source/spl_fs_service.cpp index a550bdffb..fb6dc2779 100644 --- a/stratosphere/spl/source/spl_fs_service.cpp +++ b/stratosphere/spl/source/spl_fs_service.cpp @@ -22,15 +22,19 @@ namespace sts::spl { - Result FsService::ImportLotusKey(InPointer src, AccessKey access_key, KeySource key_source, u32 option) { - return impl::ImportLotusKey(src.pointer, src.num_elements, access_key, key_source, option); + Result FsService::ImportLotusKeyDeprecated(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option) { + return impl::ImportLotusKey(src.GetPointer(), src.GetSize(), access_key, key_source, option); } - Result FsService::DecryptLotusMessage(Out out_size, OutPointerWithClientSize out, InPointer base, InPointer mod, InPointer 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); + Result FsService::ImportLotusKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source) { + return impl::ImportLotusKey(src.GetPointer(), src.GetSize(), access_key, key_source, static_cast(smc::DecryptOrImportMode::ImportLotusKey)); } - Result FsService::GenerateSpecificAesKey(Out out_key, KeySource key_source, u32 generation, u32 which) { + Result FsService::DecryptLotusMessage(sf::Out 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 out_key, KeySource key_source, u32 generation, u32 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); } - Result FsService::GetPackage2Hash(OutPointerWithClientSize dst) { - return impl::GetPackage2Hash(dst.pointer, dst.num_elements); + Result FsService::GetPackage2Hash(const sf::OutPointerBuffer &dst) { + return impl::GetPackage2Hash(dst.GetPointer(), dst.GetSize()); } } diff --git a/stratosphere/spl/source/spl_fs_service.hpp b/stratosphere/spl/source/spl_fs_service.hpp index 69746c45e..e326dacc4 100644 --- a/stratosphere/spl/source/spl_fs_service.hpp +++ b/stratosphere/spl/source/spl_fs_service.hpp @@ -29,34 +29,36 @@ namespace sts::spl { virtual ~FsService() { /* ... */ } protected: /* Actual commands. */ - virtual Result ImportLotusKey(InPointer src, AccessKey access_key, KeySource key_source, u32 option); - virtual Result DecryptLotusMessage(Out out_size, OutPointerWithClientSize out, InPointer base, InPointer mod, InPointer label_digest); - virtual Result GenerateSpecificAesKey(Out out_key, KeySource key_source, u32 generation, u32 which); + virtual Result ImportLotusKeyDeprecated(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option); + virtual Result ImportLotusKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source); + virtual Result DecryptLotusMessage(sf::Out out_size, const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest); + virtual Result GenerateSpecificAesKey(sf::Out out_key, KeySource key_source, u32 generation, u32 which); virtual Result LoadTitleKey(u32 keyslot, AccessKey access_key); - virtual Result GetPackage2Hash(OutPointerWithClientSize dst); + virtual Result GetPackage2Hash(const sf::OutPointerBuffer &dst); public: DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(FsService, GetConfig), - MAKE_SERVICE_COMMAND_META(FsService, ExpMod), - MAKE_SERVICE_COMMAND_META(FsService, SetConfig), - MAKE_SERVICE_COMMAND_META(FsService, GenerateRandomBytes), - MAKE_SERVICE_COMMAND_META(FsService, IsDevelopment), - MAKE_SERVICE_COMMAND_META(FsService, SetBootReason, FirmwareVersion_300), - MAKE_SERVICE_COMMAND_META(FsService, GetBootReason, FirmwareVersion_300), - MAKE_SERVICE_COMMAND_META(FsService, GenerateAesKek), - MAKE_SERVICE_COMMAND_META(FsService, LoadAesKey), - MAKE_SERVICE_COMMAND_META(FsService, GenerateAesKey), - MAKE_SERVICE_COMMAND_META(FsService, DecryptAesKey), - MAKE_SERVICE_COMMAND_META(FsService, CryptAesCtr), - MAKE_SERVICE_COMMAND_META(FsService, ComputeCmac), - MAKE_SERVICE_COMMAND_META(FsService, AllocateAesKeyslot, FirmwareVersion_200), - MAKE_SERVICE_COMMAND_META(FsService, FreeAesKeyslot, FirmwareVersion_200), - MAKE_SERVICE_COMMAND_META(FsService, GetAesKeyslotAvailableEvent, FirmwareVersion_200), - MAKE_SERVICE_COMMAND_META(FsService, ImportLotusKey), - MAKE_SERVICE_COMMAND_META(FsService, DecryptLotusMessage), - MAKE_SERVICE_COMMAND_META(FsService, GenerateSpecificAesKey), - MAKE_SERVICE_COMMAND_META(FsService, LoadTitleKey), - MAKE_SERVICE_COMMAND_META(FsService, GetPackage2Hash, FirmwareVersion_500), + MAKE_SERVICE_COMMAND_META(GetConfig), + MAKE_SERVICE_COMMAND_META(ExpMod), + MAKE_SERVICE_COMMAND_META(SetConfig), + MAKE_SERVICE_COMMAND_META(GenerateRandomBytes), + MAKE_SERVICE_COMMAND_META(IsDevelopment), + MAKE_SERVICE_COMMAND_META(SetBootReason, hos::Version_300), + MAKE_SERVICE_COMMAND_META(GetBootReason, hos::Version_300), + MAKE_SERVICE_COMMAND_META(GenerateAesKek), + MAKE_SERVICE_COMMAND_META(LoadAesKey), + MAKE_SERVICE_COMMAND_META(GenerateAesKey), + MAKE_SERVICE_COMMAND_META(DecryptAesKey), + MAKE_SERVICE_COMMAND_META(CryptAesCtr), + MAKE_SERVICE_COMMAND_META(ComputeCmac), + 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(ImportLotusKeyDeprecated, hos::Version_400, hos::Version_400), + MAKE_SERVICE_COMMAND_META(ImportLotusKey, hos::Version_500), + MAKE_SERVICE_COMMAND_META(DecryptLotusMessage), + MAKE_SERVICE_COMMAND_META(GenerateSpecificAesKey), + MAKE_SERVICE_COMMAND_META(LoadTitleKey), + MAKE_SERVICE_COMMAND_META(GetPackage2Hash, hos::Version_500), }; }; diff --git a/stratosphere/spl/source/spl_general_service.cpp b/stratosphere/spl/source/spl_general_service.cpp index fc70c7ae9..517f5bedd 100644 --- a/stratosphere/spl/source/spl_general_service.cpp +++ b/stratosphere/spl/source/spl_general_service.cpp @@ -22,23 +22,23 @@ namespace sts::spl { - Result GeneralService::GetConfig(Out out, u32 which) { + Result GeneralService::GetConfig(sf::Out out, u32 which) { return impl::GetConfig(out.GetPointer(), static_cast(which)); } - Result GeneralService::ExpMod(OutPointerWithClientSize out, InPointer base, InPointer exp, InPointer mod) { - return impl::ExpMod(out.pointer, out.num_elements, base.pointer, base.num_elements, exp.pointer, exp.num_elements, mod.pointer, mod.num_elements); + Result GeneralService::ExpMod(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &exp, const sf::InPointerBuffer &mod) { + 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) { return impl::SetConfig(static_cast(which), value); } - Result GeneralService::GenerateRandomBytes(OutPointerWithClientSize out) { - return impl::GenerateRandomBytes(out.pointer, out.num_elements); + Result GeneralService::GenerateRandomBytes(const sf::OutPointerBuffer &out) { + return impl::GenerateRandomBytes(out.GetPointer(), out.GetSize()); } - Result GeneralService::IsDevelopment(Out is_dev) { + Result GeneralService::IsDevelopment(sf::Out is_dev) { return impl::IsDevelopment(is_dev.GetPointer()); } @@ -46,7 +46,7 @@ namespace sts::spl { return impl::SetBootReason(boot_reason); } - Result GeneralService::GetBootReason(Out out) { + Result GeneralService::GetBootReason(sf::Out out) { return impl::GetBootReason(out.GetPointer()); } diff --git a/stratosphere/spl/source/spl_general_service.hpp b/stratosphere/spl/source/spl_general_service.hpp index daa263600..872b078f1 100644 --- a/stratosphere/spl/source/spl_general_service.hpp +++ b/stratosphere/spl/source/spl_general_service.hpp @@ -21,7 +21,7 @@ namespace sts::spl { - class GeneralService : public IServiceObject { + class GeneralService : public sf::IServiceObject { protected: enum class CommandId { /* 1.0.0+ */ @@ -32,6 +32,7 @@ namespace sts::spl { GenerateAesKey = 4, SetConfig = 5, GenerateRandomBytes = 7, + ImportLotusKeyDeprecated = 9, ImportLotusKey = 9, DecryptLotusMessage = 10, IsDevelopment = 11, @@ -41,6 +42,7 @@ namespace sts::spl { DecryptAesKey = 14, CryptAesCtr = 15, ComputeCmac = 16, + ImportEsKeyDeprecated = 17, ImportEsKey = 17, UnwrapTitleKey = 18, LoadTitleKey = 19, @@ -72,22 +74,22 @@ namespace sts::spl { virtual ~GeneralService() { /* ... */ } protected: /* Actual commands. */ - virtual Result GetConfig(Out out, u32 which); - virtual Result ExpMod(OutPointerWithClientSize out, InPointer base, InPointer exp, InPointer mod); + virtual Result GetConfig(sf::Out out, u32 which); + 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 GenerateRandomBytes(OutPointerWithClientSize out); - virtual Result IsDevelopment(Out is_dev); + virtual Result GenerateRandomBytes(const sf::OutPointerBuffer &out); + virtual Result IsDevelopment(sf::Out is_dev); virtual Result SetBootReason(BootReasonValue boot_reason); - virtual Result GetBootReason(Out out); + virtual Result GetBootReason(sf::Out out); public: DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(GeneralService, GetConfig), - MAKE_SERVICE_COMMAND_META(GeneralService, ExpMod), - MAKE_SERVICE_COMMAND_META(GeneralService, SetConfig), - MAKE_SERVICE_COMMAND_META(GeneralService, GenerateRandomBytes), - MAKE_SERVICE_COMMAND_META(GeneralService, IsDevelopment), - MAKE_SERVICE_COMMAND_META(GeneralService, SetBootReason, FirmwareVersion_300), - MAKE_SERVICE_COMMAND_META(GeneralService, GetBootReason, FirmwareVersion_300), + MAKE_SERVICE_COMMAND_META(GetConfig), + MAKE_SERVICE_COMMAND_META(ExpMod), + MAKE_SERVICE_COMMAND_META(SetConfig), + MAKE_SERVICE_COMMAND_META(GenerateRandomBytes), + MAKE_SERVICE_COMMAND_META(IsDevelopment), + MAKE_SERVICE_COMMAND_META(SetBootReason, hos::Version_300), + MAKE_SERVICE_COMMAND_META(GetBootReason, hos::Version_300), }; }; diff --git a/stratosphere/spl/source/spl_main.cpp b/stratosphere/spl/source/spl_main.cpp index b3a9b22f9..d372891ff 100644 --- a/stratosphere/spl/source/spl_main.cpp +++ b/stratosphere/spl/source/spl_main.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #include @@ -73,8 +72,10 @@ void __libnx_initheap(void) { fake_heap_end = (char*)addr + size; } +using namespace sts; + void __appInit(void) { - SetFirmwareVersionForLibnx(); + hos::SetVersionForLibnx(); /* SPL doesn't really access any services... */ } @@ -83,37 +84,69 @@ void __appExit(void) { /* SPL doesn't really access any services... */ } -struct SplServerOptions { - static constexpr size_t PointerBufferSize = 0x800; - static constexpr size_t MaxDomains = 0; - static constexpr size_t MaxDomainObjects = 0; -}; +namespace { + + struct SplServerOptions { + 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 g_server_manager; + +} int main(int argc, char **argv) { /* Initialize global context. */ - sts::spl::impl::Initialize(); - - /* Create server manager. */ - static auto s_server_manager = WaitableManager(1); + spl::impl::Initialize(); /* Create services. */ - s_server_manager.AddWaitable(new ServiceServer("csrng", 3)); - if (GetRuntimeFirmwareVersion() >= FirmwareVersion_400) { - s_server_manager.AddWaitable(new ServiceServer("spl:", 9)); - s_server_manager.AddWaitable(new ServiceServer("spl:mig", 6)); - s_server_manager.AddWaitable(new ServiceServer("spl:ssl", 2)); - s_server_manager.AddWaitable(new ServiceServer("spl:es", 2)); - s_server_manager.AddWaitable(new ServiceServer("spl:fs", 3)); - if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) { - s_server_manager.AddWaitable(new ServiceServer("spl:manu", 1)); + R_ASSERT(g_server_manager.RegisterServer(RandomServiceName, RandomMaxSessions)); + if (hos::GetVersion() >= hos::Version_400) { + R_ASSERT(g_server_manager.RegisterServer(GeneralServiceName, GeneralMaxSessions)); + R_ASSERT(g_server_manager.RegisterServer(CryptoServiceName, CryptoMaxSessions)); + R_ASSERT(g_server_manager.RegisterServer(SslServiceName, SslMaxSessions)); + R_ASSERT(g_server_manager.RegisterServer(EsServiceName, EsMaxSessions)); + R_ASSERT(g_server_manager.RegisterServer(FsServiceName, FsMaxSessions)); + if (hos::GetVersion() >= hos::Version_500) { + R_ASSERT(g_server_manager.RegisterServer(ManuServiceName, ManuMaxSessions)); } } else { - s_server_manager.AddWaitable(new ServiceServer("spl:", 12)); + R_ASSERT(g_server_manager.RegisterServer(DeprecatedServiceName, DeprecatedMaxSessions)); } /* Loop forever, servicing our services. */ - s_server_manager.Process(); + g_server_manager.LoopProcess(); return 0; -} +} \ No newline at end of file diff --git a/stratosphere/spl/source/spl_manu_service.cpp b/stratosphere/spl/source/spl_manu_service.cpp index 1ee4bfccc..aaa26a2e7 100644 --- a/stratosphere/spl/source/spl_manu_service.cpp +++ b/stratosphere/spl/source/spl_manu_service.cpp @@ -22,8 +22,8 @@ namespace sts::spl { - Result ManuService::ReEncryptRsaPrivateKey(OutPointerWithClientSize out, InPointer 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); + 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.GetPointer(), out.GetSize(), src.GetPointer(), src.GetSize(), access_key_dec, source_dec, access_key_enc, source_enc, option); } } diff --git a/stratosphere/spl/source/spl_manu_service.hpp b/stratosphere/spl/source/spl_manu_service.hpp index cc17a5e2d..328573a13 100644 --- a/stratosphere/spl/source/spl_manu_service.hpp +++ b/stratosphere/spl/source/spl_manu_service.hpp @@ -30,28 +30,28 @@ namespace sts::spl { virtual ~ManuService() { /* ... */ } protected: /* Actual commands. */ - virtual Result ReEncryptRsaPrivateKey(OutPointerWithClientSize out, InPointer 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: DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(ManuService, GetConfig), - MAKE_SERVICE_COMMAND_META(ManuService, ExpMod), - MAKE_SERVICE_COMMAND_META(ManuService, SetConfig), - MAKE_SERVICE_COMMAND_META(ManuService, GenerateRandomBytes), - MAKE_SERVICE_COMMAND_META(ManuService, IsDevelopment), - MAKE_SERVICE_COMMAND_META(ManuService, SetBootReason, FirmwareVersion_300), - MAKE_SERVICE_COMMAND_META(ManuService, GetBootReason, FirmwareVersion_300), - MAKE_SERVICE_COMMAND_META(ManuService, GenerateAesKek), - MAKE_SERVICE_COMMAND_META(ManuService, LoadAesKey), - MAKE_SERVICE_COMMAND_META(ManuService, GenerateAesKey), - MAKE_SERVICE_COMMAND_META(ManuService, DecryptAesKey), - MAKE_SERVICE_COMMAND_META(ManuService, CryptAesCtr), - MAKE_SERVICE_COMMAND_META(ManuService, ComputeCmac), - MAKE_SERVICE_COMMAND_META(ManuService, AllocateAesKeyslot, FirmwareVersion_200), - MAKE_SERVICE_COMMAND_META(ManuService, FreeAesKeyslot, FirmwareVersion_200), - MAKE_SERVICE_COMMAND_META(ManuService, GetAesKeyslotAvailableEvent, FirmwareVersion_200), - MAKE_SERVICE_COMMAND_META(ManuService, DecryptRsaPrivateKeyDeprecated, FirmwareVersion_400, FirmwareVersion_400), - MAKE_SERVICE_COMMAND_META(ManuService, DecryptRsaPrivateKey, FirmwareVersion_500), - MAKE_SERVICE_COMMAND_META(ManuService, ReEncryptRsaPrivateKey, FirmwareVersion_500), + MAKE_SERVICE_COMMAND_META(GetConfig), + MAKE_SERVICE_COMMAND_META(ExpMod), + MAKE_SERVICE_COMMAND_META(SetConfig), + MAKE_SERVICE_COMMAND_META(GenerateRandomBytes), + MAKE_SERVICE_COMMAND_META(IsDevelopment), + MAKE_SERVICE_COMMAND_META(SetBootReason, hos::Version_300), + MAKE_SERVICE_COMMAND_META(GetBootReason, hos::Version_300), + MAKE_SERVICE_COMMAND_META(GenerateAesKek), + MAKE_SERVICE_COMMAND_META(LoadAesKey), + MAKE_SERVICE_COMMAND_META(GenerateAesKey), + MAKE_SERVICE_COMMAND_META(DecryptAesKey), + MAKE_SERVICE_COMMAND_META(CryptAesCtr), + MAKE_SERVICE_COMMAND_META(ComputeCmac), + 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(DecryptRsaPrivateKeyDeprecated, hos::Version_400, hos::Version_400), + MAKE_SERVICE_COMMAND_META(DecryptRsaPrivateKey, hos::Version_500), + MAKE_SERVICE_COMMAND_META(ReEncryptRsaPrivateKey, hos::Version_500), }; }; diff --git a/stratosphere/spl/source/spl_random_service.cpp b/stratosphere/spl/source/spl_random_service.cpp index 9127209d9..6e980a16a 100644 --- a/stratosphere/spl/source/spl_random_service.cpp +++ b/stratosphere/spl/source/spl_random_service.cpp @@ -22,8 +22,8 @@ namespace sts::spl { - Result RandomService::GenerateRandomBytes(OutBuffer out) { - return impl::GenerateRandomBytes(out.buffer, out.num_elements); + Result RandomService::GenerateRandomBytes(const sf::OutBuffer &out) { + return impl::GenerateRandomBytes(out.GetPointer(), out.GetSize()); } } diff --git a/stratosphere/spl/source/spl_random_service.hpp b/stratosphere/spl/source/spl_random_service.hpp index 3f8b7724c..be014f66d 100644 --- a/stratosphere/spl/source/spl_random_service.hpp +++ b/stratosphere/spl/source/spl_random_service.hpp @@ -21,7 +21,7 @@ namespace sts::spl { - class RandomService final : public IServiceObject { + class RandomService final : public sf::IServiceObject { protected: enum class CommandId { GenerateRandomBytes = 0, @@ -31,10 +31,10 @@ namespace sts::spl { virtual ~RandomService() { /* ... */ } private: /* Actual commands. */ - virtual Result GenerateRandomBytes(OutBuffer out); + virtual Result GenerateRandomBytes(const sf::OutBuffer &out); public: DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(RandomService, GenerateRandomBytes), + MAKE_SERVICE_COMMAND_META(GenerateRandomBytes), }; }; diff --git a/stratosphere/spl/source/spl_rsa_service.cpp b/stratosphere/spl/source/spl_rsa_service.cpp index e075fa7da..dd5d3668f 100644 --- a/stratosphere/spl/source/spl_rsa_service.cpp +++ b/stratosphere/spl/source/spl_rsa_service.cpp @@ -22,12 +22,12 @@ namespace sts::spl { - Result RsaService::DecryptRsaPrivateKeyDeprecated(OutPointerWithClientSize dst, InPointer 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); + Result RsaService::DecryptRsaPrivateKeyDeprecated(const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option) { + return impl::DecryptRsaPrivateKey(dst.GetPointer(), dst.GetSize(), src.GetPointer(), src.GetSize(), access_key, key_source, option); } - Result RsaService::DecryptRsaPrivateKey(OutPointerWithClientSize dst, InPointer 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(smc::DecryptOrImportMode::DecryptRsaPrivateKey)); + Result RsaService::DecryptRsaPrivateKey(const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source) { + return impl::DecryptRsaPrivateKey(dst.GetPointer(), dst.GetSize(), src.GetPointer(), src.GetSize(), access_key, key_source, static_cast(smc::DecryptOrImportMode::DecryptRsaPrivateKey)); } } diff --git a/stratosphere/spl/source/spl_rsa_service.hpp b/stratosphere/spl/source/spl_rsa_service.hpp index a41bf7f79..385224082 100644 --- a/stratosphere/spl/source/spl_rsa_service.hpp +++ b/stratosphere/spl/source/spl_rsa_service.hpp @@ -29,8 +29,8 @@ namespace sts::spl { virtual ~RsaService() { /* ... */ } protected: /* Actual commands. */ - virtual Result DecryptRsaPrivateKeyDeprecated(OutPointerWithClientSize dst, InPointer src, AccessKey access_key, KeySource key_source, u32 option); - virtual Result DecryptRsaPrivateKey(OutPointerWithClientSize dst, InPointer src, AccessKey access_key, KeySource key_source); + virtual Result DecryptRsaPrivateKeyDeprecated(const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &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); }; } diff --git a/stratosphere/spl/source/spl_ssl_service.cpp b/stratosphere/spl/source/spl_ssl_service.cpp index 3c6d1a399..15117c808 100644 --- a/stratosphere/spl/source/spl_ssl_service.cpp +++ b/stratosphere/spl/source/spl_ssl_service.cpp @@ -22,12 +22,12 @@ namespace sts::spl { - Result SslService::ImportSslKey(InPointer src, AccessKey access_key, KeySource key_source) { - return impl::ImportSslKey(src.pointer, src.num_elements, access_key, key_source); + Result SslService::ImportSslKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source) { + return impl::ImportSslKey(src.GetPointer(), src.GetSize(), access_key, key_source); } - Result SslService::SslExpMod(OutPointerWithClientSize out, InPointer base, InPointer mod) { - return impl::SslExpMod(out.pointer, out.num_elements, base.pointer, base.num_elements, mod.pointer, mod.num_elements); + Result SslService::SslExpMod(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod) { + return impl::SslExpMod(out.GetPointer(), out.GetSize(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize()); } } diff --git a/stratosphere/spl/source/spl_ssl_service.hpp b/stratosphere/spl/source/spl_ssl_service.hpp index db09bfa12..1d2ce2d6d 100644 --- a/stratosphere/spl/source/spl_ssl_service.hpp +++ b/stratosphere/spl/source/spl_ssl_service.hpp @@ -29,30 +29,30 @@ namespace sts::spl { virtual ~SslService() { /* ... */ } protected: /* Actual commands. */ - virtual Result ImportSslKey(InPointer src, AccessKey access_key, KeySource key_source); - virtual Result SslExpMod(OutPointerWithClientSize out, InPointer base, InPointer mod); + virtual Result ImportSslKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source); + virtual Result SslExpMod(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod); public: DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(SslService, GetConfig), - MAKE_SERVICE_COMMAND_META(SslService, ExpMod), - MAKE_SERVICE_COMMAND_META(SslService, SetConfig), - MAKE_SERVICE_COMMAND_META(SslService, GenerateRandomBytes), - MAKE_SERVICE_COMMAND_META(SslService, IsDevelopment), - MAKE_SERVICE_COMMAND_META(SslService, SetBootReason, FirmwareVersion_300), - MAKE_SERVICE_COMMAND_META(SslService, GetBootReason, FirmwareVersion_300), - MAKE_SERVICE_COMMAND_META(SslService, GenerateAesKek), - MAKE_SERVICE_COMMAND_META(SslService, LoadAesKey), - MAKE_SERVICE_COMMAND_META(SslService, GenerateAesKey), - MAKE_SERVICE_COMMAND_META(SslService, DecryptAesKey), - MAKE_SERVICE_COMMAND_META(SslService, CryptAesCtr), - MAKE_SERVICE_COMMAND_META(SslService, ComputeCmac), - MAKE_SERVICE_COMMAND_META(SslService, AllocateAesKeyslot, FirmwareVersion_200), - MAKE_SERVICE_COMMAND_META(SslService, FreeAesKeyslot, FirmwareVersion_200), - MAKE_SERVICE_COMMAND_META(SslService, GetAesKeyslotAvailableEvent, FirmwareVersion_200), - MAKE_SERVICE_COMMAND_META(SslService, DecryptRsaPrivateKeyDeprecated, FirmwareVersion_400, FirmwareVersion_400), - MAKE_SERVICE_COMMAND_META(SslService, DecryptRsaPrivateKey, FirmwareVersion_500), - MAKE_SERVICE_COMMAND_META(SslService, ImportSslKey, FirmwareVersion_500), - MAKE_SERVICE_COMMAND_META(SslService, SslExpMod, FirmwareVersion_500), + MAKE_SERVICE_COMMAND_META(GetConfig), + MAKE_SERVICE_COMMAND_META(ExpMod), + MAKE_SERVICE_COMMAND_META(SetConfig), + MAKE_SERVICE_COMMAND_META(GenerateRandomBytes), + MAKE_SERVICE_COMMAND_META(IsDevelopment), + MAKE_SERVICE_COMMAND_META(SetBootReason, hos::Version_300), + MAKE_SERVICE_COMMAND_META(GetBootReason, hos::Version_300), + MAKE_SERVICE_COMMAND_META(GenerateAesKek), + MAKE_SERVICE_COMMAND_META(LoadAesKey), + MAKE_SERVICE_COMMAND_META(GenerateAesKey), + MAKE_SERVICE_COMMAND_META(DecryptAesKey), + MAKE_SERVICE_COMMAND_META(CryptAesCtr), + MAKE_SERVICE_COMMAND_META(ComputeCmac), + 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(DecryptRsaPrivateKeyDeprecated, hos::Version_400, hos::Version_400), + MAKE_SERVICE_COMMAND_META(DecryptRsaPrivateKey, hos::Version_500), + MAKE_SERVICE_COMMAND_META(ImportSslKey, hos::Version_500), + MAKE_SERVICE_COMMAND_META(SslExpMod, hos::Version_500), }; };