boot/spl: update for spl-in-libstrat

This commit is contained in:
Michael Scire 2019-06-22 12:23:46 -07:00
parent 804e5d49bb
commit d0d4888184
39 changed files with 105 additions and 720 deletions

View file

@ -14,10 +14,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stratosphere/spl.hpp>
#include "boot_boot_reason.hpp" #include "boot_boot_reason.hpp"
#include "boot_pmic_driver.hpp" #include "boot_pmic_driver.hpp"
#include "boot_rtc_driver.hpp" #include "boot_rtc_driver.hpp"
#include "boot_spl_utils.hpp"
namespace sts::boot { namespace sts::boot {

View file

@ -15,11 +15,11 @@
*/ */
#include <stratosphere/reg.hpp> #include <stratosphere/reg.hpp>
#include <stratosphere/spl.hpp>
#include "boot_display.hpp" #include "boot_display.hpp"
#include "boot_i2c_utils.hpp" #include "boot_i2c_utils.hpp"
#include "boot_pmc_wrapper.hpp" #include "boot_pmc_wrapper.hpp"
#include "boot_spl_utils.hpp"
#include "boot_registers_clkrst.hpp" #include "boot_registers_clkrst.hpp"
#include "boot_registers_di.hpp" #include "boot_registers_di.hpp"

View file

@ -14,8 +14,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stratosphere/spl.hpp>
#include "boot_fan_enable.hpp" #include "boot_fan_enable.hpp"
#include "boot_spl_utils.hpp"
#include "gpio/gpio_utils.hpp" #include "gpio/gpio_utils.hpp"

View file

@ -22,6 +22,7 @@
#include <switch.h> #include <switch.h>
#include <atmosphere.h> #include <atmosphere.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include <stratosphere/spl.hpp>
#include "boot_boot_reason.hpp" #include "boot_boot_reason.hpp"
#include "boot_change_voltage.hpp" #include "boot_change_voltage.hpp"
@ -37,7 +38,6 @@
#include "pinmux/pinmux_initial_configuration.hpp" #include "pinmux/pinmux_initial_configuration.hpp"
#include "boot_power_utils.hpp" #include "boot_power_utils.hpp"
#include "boot_spl_utils.hpp"
using namespace sts; using namespace sts;

View file

@ -14,9 +14,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stratosphere/spl.hpp>
#include "boot_power_utils.hpp" #include "boot_power_utils.hpp"
#include "boot_repair_boot_images.hpp" #include "boot_repair_boot_images.hpp"
#include "boot_spl_utils.hpp"
#include "updater/updater_api.hpp" #include "updater/updater_api.hpp"

View file

@ -1,47 +0,0 @@
/*
* Copyright (c) 2018-2019 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "boot_spl_utils.hpp"
namespace sts::spl {
spl::HardwareType GetHardwareType() {
u64 out_val = 0;
R_ASSERT(splGetConfig(SplConfigItem_HardwareType, &out_val));
return static_cast<spl::HardwareType>(out_val);
}
bool IsRecoveryBoot() {
u64 val = 0;
R_ASSERT(splGetConfig(SplConfigItem_IsRecoveryBoot, &val));
return val != 0;
}
bool IsMariko() {
const auto hw_type = GetHardwareType();
switch (hw_type) {
case spl::HardwareType::Icosa:
case spl::HardwareType::Copper:
return false;
case spl::HardwareType::Hoag:
case spl::HardwareType::Iowa:
return true;
default:
std::abort();
}
}
}

View file

@ -1,35 +0,0 @@
/*
* Copyright (c) 2018-2019 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <switch.h>
#include <stratosphere.hpp>
namespace sts::spl {
enum class HardwareType {
Icosa = 0,
Copper = 1,
Hoag = 2,
Iowa = 3,
};
/* SPL Utilities. */
HardwareType GetHardwareType();
bool IsRecoveryBoot();
bool IsMariko();
}

View file

@ -14,8 +14,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stratosphere/spl.hpp>
#include "boot_pmc_wrapper.hpp" #include "boot_pmc_wrapper.hpp"
#include "boot_spl_utils.hpp"
#include "boot_wake_pins.hpp" #include "boot_wake_pins.hpp"
#include "boot_registers_pmc.hpp" #include "boot_registers_pmc.hpp"

View file

@ -14,12 +14,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stratosphere/spl.hpp>
#include "gpio_initial_configuration.hpp" #include "gpio_initial_configuration.hpp"
#include "gpio_utils.hpp" #include "gpio_utils.hpp"
/* TODO: Better way? */
#include "../boot_spl_utils.hpp"
namespace sts::gpio { namespace sts::gpio {
namespace { namespace {

View file

@ -14,13 +14,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stratosphere/spl.hpp>
#include "pinmux_initial_configuration.hpp" #include "pinmux_initial_configuration.hpp"
#include "pinmux_utils.hpp" #include "pinmux_utils.hpp"
/* TODO: Better way? */
#include "../boot_spl_utils.hpp"
namespace sts::pinmux { namespace sts::pinmux {
namespace { namespace {

View file

@ -17,6 +17,7 @@
#pragma once #pragma once
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include <stratosphere/spl/spl_types.hpp>
#include "updater_types.hpp" #include "updater_types.hpp"

View file

@ -18,9 +18,6 @@
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
/* TODO: Better way to do this? */
#include "../boot_spl_utils.hpp"
namespace sts::updater { namespace sts::updater {
/* Types. */ /* Types. */

@ -1 +1 @@
Subproject commit 13e3f517cb5db1053e01fb21ec189728d5b9d6db Subproject commit ca344e1d19267779a59b6a212683792538bb76af

View file

@ -16,13 +16,13 @@
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include <stratosphere/spl.hpp>
#include "spl_api.hpp" #include "spl_api_impl.hpp"
#include "spl_smc.hpp"
#include "spl_ctr_drbg.hpp" #include "spl_ctr_drbg.hpp"
namespace sts::spl { namespace sts::spl::impl {
namespace { namespace {
@ -59,7 +59,7 @@ namespace sts::spl {
} }
~ScopedAesKeyslot() { ~ScopedAesKeyslot() {
if (has_slot) { if (has_slot) {
spl::FreeAesKeyslot(slot, this); FreeAesKeyslot(slot, this);
} }
} }
@ -68,7 +68,7 @@ namespace sts::spl {
} }
Result Allocate() { Result Allocate() {
R_TRY(spl::AllocateAesKeyslot(&this->slot, this)); R_TRY(AllocateAesKeyslot(&this->slot, this));
this->has_slot = true; this->has_slot = true;
return ResultSuccess; return ResultSuccess;
} }

View file

@ -17,10 +17,9 @@
#pragma once #pragma once
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include <stratosphere/spl/spl_types.hpp>
#include "spl_types.hpp" namespace sts::spl::impl {
namespace sts::spl {
/* Initialization. */ /* Initialization. */
void Initialize(); void Initialize();

View file

@ -17,50 +17,50 @@
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include "spl_api_impl.hpp"
#include "spl_crypto_service.hpp" #include "spl_crypto_service.hpp"
#include "spl_api.hpp"
namespace sts::spl { namespace sts::spl {
CryptoService::~CryptoService() { CryptoService::~CryptoService() {
/* Free any keyslots this service is using. */ /* Free any keyslots this service is using. */
spl::FreeAesKeyslots(this); impl::FreeAesKeyslots(this);
} }
Result CryptoService::GenerateAesKek(Out<AccessKey> out_access_key, KeySource key_source, u32 generation, u32 option) { Result CryptoService::GenerateAesKek(Out<AccessKey> out_access_key, KeySource key_source, u32 generation, u32 option) {
return spl::GenerateAesKek(out_access_key.GetPointer(), key_source, generation, option); return impl::GenerateAesKek(out_access_key.GetPointer(), key_source, generation, option);
} }
Result CryptoService::LoadAesKey(u32 keyslot, AccessKey access_key, KeySource key_source) { Result CryptoService::LoadAesKey(u32 keyslot, AccessKey access_key, KeySource key_source) {
return spl::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(Out<AesKey> out_key, AccessKey access_key, KeySource key_source) {
return spl::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(Out<AesKey> out_key, KeySource key_source, u32 generation, u32 option) {
return spl::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(OutBuffer<u8, BufferType_Type1> out_buf, u32 keyslot, InBuffer<u8, BufferType_Type1> in_buf, IvCtr iv_ctr) {
return spl::CryptAesCtr(out_buf.buffer, out_buf.num_elements, keyslot, this, in_buf.buffer, in_buf.num_elements, 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::ComputeCmac(Out<Cmac> out_cmac, u32 keyslot, InPointer<u8> in_buf) { Result CryptoService::ComputeCmac(Out<Cmac> out_cmac, u32 keyslot, InPointer<u8> in_buf) {
return spl::ComputeCmac(out_cmac.GetPointer(), keyslot, this, in_buf.pointer, in_buf.num_elements); return impl::ComputeCmac(out_cmac.GetPointer(), keyslot, this, in_buf.pointer, in_buf.num_elements);
} }
Result CryptoService::AllocateAesKeyslot(Out<u32> out_keyslot) { Result CryptoService::AllocateAesKeyslot(Out<u32> out_keyslot) {
return spl::AllocateAesKeyslot(out_keyslot.GetPointer(), this); return impl::AllocateAesKeyslot(out_keyslot.GetPointer(), this);
} }
Result CryptoService::FreeAesKeyslot(u32 keyslot) { Result CryptoService::FreeAesKeyslot(u32 keyslot) {
return spl::FreeAesKeyslot(keyslot, this); return impl::FreeAesKeyslot(keyslot, this);
} }
void CryptoService::GetAesKeyslotAvailableEvent(Out<CopiedHandle> out_hnd) { void CryptoService::GetAesKeyslotAvailableEvent(Out<CopiedHandle> out_hnd) {
out_hnd.SetValue(spl::GetAesKeyslotAvailableEventHandle()); out_hnd.SetValue(impl::GetAesKeyslotAvailableEventHandle());
} }
} }

View file

@ -17,8 +17,8 @@
#pragma once #pragma once
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include <stratosphere/spl/spl_types.hpp>
#include "spl_types.hpp"
#include "spl_general_service.hpp" #include "spl_general_service.hpp"
namespace sts::spl { namespace sts::spl {

View file

@ -16,8 +16,8 @@
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include <stratosphere/spl/spl_types.hpp>
#include "spl_types.hpp"
#include "spl_ctr_drbg.hpp" #include "spl_ctr_drbg.hpp"
namespace sts::spl { namespace sts::spl {

View file

@ -17,8 +17,7 @@
#pragma once #pragma once
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include <stratosphere/spl/spl_types.hpp>
#include "spl_types.hpp"
namespace sts::spl { namespace sts::spl {

View file

@ -17,109 +17,109 @@
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include "spl_api_impl.hpp"
#include "spl_deprecated_service.hpp" #include "spl_deprecated_service.hpp"
#include "spl_api.hpp"
namespace sts::spl { namespace sts::spl {
Result DeprecatedService::GetConfig(Out<u64> out, u32 which) { Result DeprecatedService::GetConfig(Out<u64> out, u32 which) {
return spl::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(OutPointerWithClientSize<u8> out, InPointer<u8> base, InPointer<u8> exp, InPointer<u8> mod) {
return spl::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.pointer, out.num_elements, base.pointer, base.num_elements, exp.pointer, exp.num_elements, mod.pointer, mod.num_elements);
} }
Result DeprecatedService::GenerateAesKek(Out<AccessKey> out_access_key, KeySource key_source, u32 generation, u32 option) { Result DeprecatedService::GenerateAesKek(Out<AccessKey> out_access_key, KeySource key_source, u32 generation, u32 option) {
return spl::GenerateAesKek(out_access_key.GetPointer(), key_source, generation, option); return impl::GenerateAesKek(out_access_key.GetPointer(), key_source, generation, option);
} }
Result DeprecatedService::LoadAesKey(u32 keyslot, AccessKey access_key, KeySource key_source) { Result DeprecatedService::LoadAesKey(u32 keyslot, AccessKey access_key, KeySource key_source) {
return spl::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(Out<AesKey> out_key, AccessKey access_key, KeySource key_source) {
return spl::GenerateAesKey(out_key.GetPointer(), access_key, key_source); return impl::GenerateAesKey(out_key.GetPointer(), access_key, key_source);
} }
Result DeprecatedService::SetConfig(u32 which, u64 value) { Result DeprecatedService::SetConfig(u32 which, u64 value) {
return spl::SetConfig(static_cast<SplConfigItem>(which), value); return impl::SetConfig(static_cast<SplConfigItem>(which), value);
} }
Result DeprecatedService::GenerateRandomBytes(OutPointerWithClientSize<u8> out) { Result DeprecatedService::GenerateRandomBytes(OutPointerWithClientSize<u8> out) {
return spl::GenerateRandomBytes(out.pointer, out.num_elements); return impl::GenerateRandomBytes(out.pointer, out.num_elements);
} }
Result DeprecatedService::ImportLotusKey(InPointer<u8> src, AccessKey access_key, KeySource key_source, u32 option) { Result DeprecatedService::ImportLotusKey(InPointer<u8> src, AccessKey access_key, KeySource key_source, u32 option) {
return spl::ImportLotusKey(src.pointer, src.num_elements, access_key, key_source, option); return impl::ImportLotusKey(src.pointer, src.num_elements, 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(Out<u32> out_size, OutPointerWithClientSize<u8> out, InPointer<u8> base, InPointer<u8> mod, InPointer<u8> label_digest) {
return spl::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.pointer, out.num_elements, base.pointer, base.num_elements, mod.pointer, mod.num_elements, label_digest.pointer, label_digest.num_elements);
} }
Result DeprecatedService::IsDevelopment(Out<bool> is_dev) { Result DeprecatedService::IsDevelopment(Out<bool> is_dev) {
return spl::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(Out<AesKey> out_key, KeySource key_source, u32 generation, u32 which) {
return spl::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(OutPointerWithClientSize<u8> dst, InPointer<u8> src, AccessKey access_key, KeySource key_source, u32 option) {
return spl::DecryptRsaPrivateKey(dst.pointer, dst.num_elements, src.pointer, src.num_elements, access_key, key_source, option); return impl::DecryptRsaPrivateKey(dst.pointer, dst.num_elements, src.pointer, src.num_elements, access_key, key_source, option);
} }
Result DeprecatedService::DecryptAesKey(Out<AesKey> out_key, KeySource key_source, u32 generation, u32 option) { Result DeprecatedService::DecryptAesKey(Out<AesKey> out_key, KeySource key_source, u32 generation, u32 option) {
return spl::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(OutBuffer<u8> out_buf, u32 keyslot, InBuffer<u8> in_buf, IvCtr iv_ctr) {
return spl::CryptAesCtr(out_buf.buffer, out_buf.num_elements, keyslot, this, in_buf.buffer, in_buf.num_elements, 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(OutBuffer<u8, BufferType_Type1> out_buf, u32 keyslot, InBuffer<u8, BufferType_Type1> in_buf, IvCtr iv_ctr) { Result DeprecatedService::CryptAesCtr(OutBuffer<u8, BufferType_Type1> out_buf, u32 keyslot, InBuffer<u8, BufferType_Type1> in_buf, IvCtr iv_ctr) {
return spl::CryptAesCtr(out_buf.buffer, out_buf.num_elements, keyslot, this, in_buf.buffer, in_buf.num_elements, 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::ComputeCmac(Out<Cmac> out_cmac, u32 keyslot, InPointer<u8> in_buf) { Result DeprecatedService::ComputeCmac(Out<Cmac> out_cmac, u32 keyslot, InPointer<u8> in_buf) {
return spl::ComputeCmac(out_cmac.GetPointer(), keyslot, this, in_buf.pointer, in_buf.num_elements); return impl::ComputeCmac(out_cmac.GetPointer(), keyslot, this, in_buf.pointer, in_buf.num_elements);
} }
Result DeprecatedService::ImportEsKey(InPointer<u8> src, AccessKey access_key, KeySource key_source, u32 option) { Result DeprecatedService::ImportEsKey(InPointer<u8> src, AccessKey access_key, KeySource key_source, u32 option) {
return spl::ImportEsKey(src.pointer, src.num_elements, access_key, key_source, option); return impl::ImportEsKey(src.pointer, src.num_elements, 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::UnwrapTitleKey(Out<AccessKey> out_access_key, InPointer<u8> base, InPointer<u8> mod, InPointer<u8> label_digest, u32 generation) {
return spl::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.pointer, base.num_elements, mod.pointer, mod.num_elements, label_digest.pointer, label_digest.num_elements, generation);
} }
Result DeprecatedService::LoadTitleKey(u32 keyslot, AccessKey access_key) { Result DeprecatedService::LoadTitleKey(u32 keyslot, AccessKey access_key) {
return spl::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::UnwrapCommonTitleKey(Out<AccessKey> out_access_key, KeySource key_source, u32 generation) {
return spl::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(Out<u32> out_keyslot) {
return spl::AllocateAesKeyslot(out_keyslot.GetPointer(), this); return impl::AllocateAesKeyslot(out_keyslot.GetPointer(), this);
} }
Result DeprecatedService::FreeAesKeyslot(u32 keyslot) { Result DeprecatedService::FreeAesKeyslot(u32 keyslot) {
return spl::FreeAesKeyslot(keyslot, this); return impl::FreeAesKeyslot(keyslot, this);
} }
void DeprecatedService::GetAesKeyslotAvailableEvent(Out<CopiedHandle> out_hnd) { void DeprecatedService::GetAesKeyslotAvailableEvent(Out<CopiedHandle> out_hnd) {
out_hnd.SetValue(spl::GetAesKeyslotAvailableEventHandle()); out_hnd.SetValue(impl::GetAesKeyslotAvailableEventHandle());
} }
Result DeprecatedService::SetBootReason(BootReasonValue boot_reason) { Result DeprecatedService::SetBootReason(BootReasonValue boot_reason) {
return spl::SetBootReason(boot_reason); return impl::SetBootReason(boot_reason);
} }
Result DeprecatedService::GetBootReason(Out<BootReasonValue> out) { Result DeprecatedService::GetBootReason(Out<BootReasonValue> out) {
return spl::GetBootReason(out.GetPointer()); return impl::GetBootReason(out.GetPointer());
} }
} }

View file

@ -17,8 +17,7 @@
#pragma once #pragma once
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include <stratosphere/spl/spl_types.hpp>
#include "spl_types.hpp"
namespace sts::spl { namespace sts::spl {

View file

@ -17,37 +17,37 @@
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include "spl_api_impl.hpp"
#include "spl_es_service.hpp" #include "spl_es_service.hpp"
#include "spl_api.hpp"
namespace sts::spl { namespace sts::spl {
Result EsService::ImportEsKey(InPointer<u8> src, AccessKey access_key, KeySource key_source, u32 option) { Result EsService::ImportEsKey(InPointer<u8> src, AccessKey access_key, KeySource key_source, u32 option) {
return spl::ImportEsKey(src.pointer, src.num_elements, access_key, key_source, option); return impl::ImportEsKey(src.pointer, src.num_elements, 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::UnwrapTitleKey(Out<AccessKey> out_access_key, InPointer<u8> base, InPointer<u8> mod, InPointer<u8> label_digest, u32 generation) {
return spl::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.pointer, base.num_elements, mod.pointer, mod.num_elements, label_digest.pointer, label_digest.num_elements, generation);
} }
Result EsService::UnwrapCommonTitleKey(Out<AccessKey> out_access_key, KeySource key_source, u32 generation) { Result EsService::UnwrapCommonTitleKey(Out<AccessKey> out_access_key, KeySource key_source, u32 generation) {
return spl::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(InPointer<u8> src, AccessKey access_key, KeySource key_source) {
return spl::ImportDrmKey(src.pointer, src.num_elements, access_key, key_source); return impl::ImportDrmKey(src.pointer, src.num_elements, access_key, key_source);
} }
Result EsService::DrmExpMod(OutPointerWithClientSize<u8> out, InPointer<u8> base, InPointer<u8> mod) { Result EsService::DrmExpMod(OutPointerWithClientSize<u8> out, InPointer<u8> base, InPointer<u8> mod) {
return spl::DrmExpMod(out.pointer, out.num_elements, base.pointer, base.num_elements, mod.pointer, mod.num_elements); return impl::DrmExpMod(out.pointer, out.num_elements, base.pointer, base.num_elements, mod.pointer, mod.num_elements);
} }
Result EsService::UnwrapElicenseKey(Out<AccessKey> out_access_key, InPointer<u8> base, InPointer<u8> mod, InPointer<u8> label_digest, u32 generation) { Result EsService::UnwrapElicenseKey(Out<AccessKey> out_access_key, InPointer<u8> base, InPointer<u8> mod, InPointer<u8> label_digest, u32 generation) {
return spl::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.pointer, base.num_elements, mod.pointer, mod.num_elements, label_digest.pointer, label_digest.num_elements, generation);
} }
Result EsService::LoadElicenseKey(u32 keyslot, AccessKey access_key) { Result EsService::LoadElicenseKey(u32 keyslot, AccessKey access_key) {
return spl::LoadElicenseKey(keyslot, this, access_key); return impl::LoadElicenseKey(keyslot, this, access_key);
} }
} }

View file

@ -17,8 +17,8 @@
#pragma once #pragma once
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include <stratosphere/spl/spl_types.hpp>
#include "spl_types.hpp"
#include "spl_rsa_service.hpp" #include "spl_rsa_service.hpp"
namespace sts::spl { namespace sts::spl {

View file

@ -17,29 +17,29 @@
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include "spl_api_impl.hpp"
#include "spl_fs_service.hpp" #include "spl_fs_service.hpp"
#include "spl_api.hpp"
namespace sts::spl { namespace sts::spl {
Result FsService::ImportLotusKey(InPointer<u8> src, AccessKey access_key, KeySource key_source, u32 option) { Result FsService::ImportLotusKey(InPointer<u8> src, AccessKey access_key, KeySource key_source, u32 option) {
return spl::ImportLotusKey(src.pointer, src.num_elements, access_key, key_source, option); return impl::ImportLotusKey(src.pointer, src.num_elements, 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::DecryptLotusMessage(Out<u32> out_size, OutPointerWithClientSize<u8> out, InPointer<u8> base, InPointer<u8> mod, InPointer<u8> label_digest) {
return spl::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.pointer, out.num_elements, base.pointer, base.num_elements, mod.pointer, mod.num_elements, label_digest.pointer, label_digest.num_elements);
} }
Result FsService::GenerateSpecificAesKey(Out<AesKey> out_key, KeySource key_source, u32 generation, u32 which) { Result FsService::GenerateSpecificAesKey(Out<AesKey> out_key, KeySource key_source, u32 generation, u32 which) {
return spl::GenerateSpecificAesKey(out_key.GetPointer(), key_source, generation, which); return impl::GenerateSpecificAesKey(out_key.GetPointer(), key_source, generation, which);
} }
Result FsService::LoadTitleKey(u32 keyslot, AccessKey access_key) { Result FsService::LoadTitleKey(u32 keyslot, AccessKey access_key) {
return spl::LoadTitleKey(keyslot, this, access_key); return impl::LoadTitleKey(keyslot, this, access_key);
} }
Result FsService::GetPackage2Hash(OutPointerWithClientSize<u8> dst) { Result FsService::GetPackage2Hash(OutPointerWithClientSize<u8> dst) {
return spl::GetPackage2Hash(dst.pointer, dst.num_elements); return impl::GetPackage2Hash(dst.pointer, dst.num_elements);
} }
} }

View file

@ -17,8 +17,8 @@
#pragma once #pragma once
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include <stratosphere/spl/spl_types.hpp>
#include "spl_types.hpp"
#include "spl_crypto_service.hpp" #include "spl_crypto_service.hpp"
namespace sts::spl { namespace sts::spl {

View file

@ -17,37 +17,37 @@
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include "spl_api_impl.hpp"
#include "spl_general_service.hpp" #include "spl_general_service.hpp"
#include "spl_api.hpp"
namespace sts::spl { namespace sts::spl {
Result GeneralService::GetConfig(Out<u64> out, u32 which) { Result GeneralService::GetConfig(Out<u64> out, u32 which) {
return spl::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(OutPointerWithClientSize<u8> out, InPointer<u8> base, InPointer<u8> exp, InPointer<u8> mod) {
return spl::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.pointer, out.num_elements, base.pointer, base.num_elements, exp.pointer, exp.num_elements, mod.pointer, mod.num_elements);
} }
Result GeneralService::SetConfig(u32 which, u64 value) { Result GeneralService::SetConfig(u32 which, u64 value) {
return spl::SetConfig(static_cast<SplConfigItem>(which), value); return impl::SetConfig(static_cast<SplConfigItem>(which), value);
} }
Result GeneralService::GenerateRandomBytes(OutPointerWithClientSize<u8> out) { Result GeneralService::GenerateRandomBytes(OutPointerWithClientSize<u8> out) {
return spl::GenerateRandomBytes(out.pointer, out.num_elements); return impl::GenerateRandomBytes(out.pointer, out.num_elements);
} }
Result GeneralService::IsDevelopment(Out<bool> is_dev) { Result GeneralService::IsDevelopment(Out<bool> is_dev) {
return spl::IsDevelopment(is_dev.GetPointer()); return impl::IsDevelopment(is_dev.GetPointer());
} }
Result GeneralService::SetBootReason(BootReasonValue boot_reason) { Result GeneralService::SetBootReason(BootReasonValue boot_reason) {
return spl::SetBootReason(boot_reason); return impl::SetBootReason(boot_reason);
} }
Result GeneralService::GetBootReason(Out<BootReasonValue> out) { Result GeneralService::GetBootReason(Out<BootReasonValue> out) {
return spl::GetBootReason(out.GetPointer()); return impl::GetBootReason(out.GetPointer());
} }
} }

View file

@ -17,8 +17,7 @@
#pragma once #pragma once
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include <stratosphere/spl/spl_types.hpp>
#include "spl_types.hpp"
namespace sts::spl { namespace sts::spl {

View file

@ -22,6 +22,8 @@
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include "spl_api_impl.hpp"
#include "spl_random_service.hpp" #include "spl_random_service.hpp"
#include "spl_general_service.hpp" #include "spl_general_service.hpp"
#include "spl_crypto_service.hpp" #include "spl_crypto_service.hpp"
@ -32,8 +34,6 @@
#include "spl_deprecated_service.hpp" #include "spl_deprecated_service.hpp"
#include "spl_api.hpp"
extern "C" { extern "C" {
extern u32 __start__; extern u32 __start__;
@ -91,7 +91,7 @@ struct SplServerOptions {
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
/* Initialize global context. */ /* Initialize global context. */
sts::spl::Initialize(); sts::spl::impl::Initialize();
/* Create server manager. */ /* Create server manager. */
static auto s_server_manager = WaitableManager<SplServerOptions>(1); static auto s_server_manager = WaitableManager<SplServerOptions>(1);

View file

@ -17,13 +17,13 @@
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include "spl_api_impl.hpp"
#include "spl_manu_service.hpp" #include "spl_manu_service.hpp"
#include "spl_api.hpp"
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(OutPointerWithClientSize<u8> out, InPointer<u8> src, AccessKey access_key_dec, KeySource source_dec, AccessKey access_key_enc, KeySource source_enc, u32 option) {
return spl::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.pointer, out.num_elements, src.pointer, src.num_elements, access_key_dec, source_dec, access_key_enc, source_enc, option);
} }
} }

View file

@ -17,8 +17,8 @@
#pragma once #pragma once
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include <stratosphere/spl/spl_types.hpp>
#include "spl_types.hpp"
#include "spl_rsa_service.hpp" #include "spl_rsa_service.hpp"
namespace sts::spl { namespace sts::spl {

View file

@ -17,13 +17,13 @@
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include "spl_api_impl.hpp"
#include "spl_random_service.hpp" #include "spl_random_service.hpp"
#include "spl_api.hpp"
namespace sts::spl { namespace sts::spl {
Result RandomService::GenerateRandomBytes(OutBuffer<u8> out) { Result RandomService::GenerateRandomBytes(OutBuffer<u8> out) {
return spl::GenerateRandomBytes(out.buffer, out.num_elements); return impl::GenerateRandomBytes(out.buffer, out.num_elements);
} }
} }

View file

@ -17,8 +17,7 @@
#pragma once #pragma once
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include <stratosphere/spl/spl_types.hpp>
#include "spl_types.hpp"
namespace sts::spl { namespace sts::spl {

View file

@ -17,17 +17,17 @@
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include "spl_api_impl.hpp"
#include "spl_rsa_service.hpp" #include "spl_rsa_service.hpp"
#include "spl_api.hpp"
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(OutPointerWithClientSize<u8> dst, InPointer<u8> src, AccessKey access_key, KeySource key_source, u32 option) {
return spl::DecryptRsaPrivateKey(dst.pointer, dst.num_elements, src.pointer, src.num_elements, access_key, key_source, option); return impl::DecryptRsaPrivateKey(dst.pointer, dst.num_elements, src.pointer, src.num_elements, access_key, key_source, option);
} }
Result RsaService::DecryptRsaPrivateKey(OutPointerWithClientSize<u8> dst, InPointer<u8> src, AccessKey access_key, KeySource key_source) { Result RsaService::DecryptRsaPrivateKey(OutPointerWithClientSize<u8> dst, InPointer<u8> src, AccessKey access_key, KeySource key_source) {
return spl::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.pointer, dst.num_elements, src.pointer, src.num_elements, access_key, key_source, static_cast<u32>(smc::DecryptOrImportMode::DecryptRsaPrivateKey));
} }
} }

View file

@ -17,8 +17,8 @@
#pragma once #pragma once
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include <stratosphere/spl/spl_types.hpp>
#include "spl_types.hpp"
#include "spl_crypto_service.hpp" #include "spl_crypto_service.hpp"
namespace sts::spl { namespace sts::spl {

View file

@ -1,313 +0,0 @@
/*
* Copyright (c) 2018-2019 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <switch.h>
#include <stratosphere.hpp>
#include "spl_smc.hpp"
namespace sts::spl::smc {
Result SetConfig(SplConfigItem which, const u64 *value, size_t num_qwords) {
SecmonArgs args;
args.X[0] = static_cast<u64>(FunctionId::SetConfig);
args.X[1] = which;
args.X[2] = 0;
for (size_t i = 0; i < std::min(size_t(4), num_qwords); i++) {
args.X[3 + i] = value[i];
}
svcCallSecureMonitor(&args);
return static_cast<Result>(args.X[0]);
}
Result GetConfig(u64 *out, size_t num_qwords, SplConfigItem which) {
SecmonArgs args;
args.X[0] = static_cast<u64>(FunctionId::GetConfig);
args.X[1] = which;
svcCallSecureMonitor(&args);
for (size_t i = 0; i < std::min(size_t(4), num_qwords); i++) {
out[i] = args.X[1 + i];
}
return static_cast<Result>(args.X[0]);
}
Result CheckStatus(Result *out, AsyncOperationKey op) {
SecmonArgs args;
args.X[0] = static_cast<u64>(FunctionId::CheckStatus);
args.X[1] = op.value;
svcCallSecureMonitor(&args);
*out = static_cast<Result>(args.X[1]);
return static_cast<Result>(args.X[0]);
}
Result GetResult(Result *out, void *out_buf, size_t out_buf_size, AsyncOperationKey op) {
SecmonArgs args;
args.X[0] = static_cast<u64>(FunctionId::GetResult);
args.X[1] = op.value;
args.X[2] = reinterpret_cast<u64>(out_buf);
args.X[3] = out_buf_size;
svcCallSecureMonitor(&args);
*out = static_cast<Result>(args.X[1]);
return static_cast<Result>(args.X[0]);
}
Result ExpMod(AsyncOperationKey *out_op, const void *base, const void *exp, size_t exp_size, const void *mod) {
SecmonArgs args;
args.X[0] = static_cast<u64>(FunctionId::ExpMod);
args.X[1] = reinterpret_cast<u64>(base);
args.X[2] = reinterpret_cast<u64>(exp);
args.X[3] = reinterpret_cast<u64>(mod);
args.X[4] = exp_size;
svcCallSecureMonitor(&args);
out_op->value = args.X[1];
return static_cast<Result>(args.X[0]);
}
Result GenerateRandomBytes(void *out, size_t size) {
SecmonArgs args;
args.X[0] = static_cast<u64>(FunctionId::GenerateRandomBytes);
args.X[1] = size;
svcCallSecureMonitor(&args);
if (args.X[0] == static_cast<u64>(Result::Success) && (size <= sizeof(args) - sizeof(args.X[0]))) {
std::memcpy(out, &args.X[1], size);
}
return static_cast<Result>(args.X[0]);
}
Result GenerateAesKek(AccessKey *out, const KeySource &source, u32 generation, u32 option) {
SecmonArgs args;
args.X[0] = static_cast<u64>(FunctionId::GenerateAesKek);
args.X[1] = source.data64[0];
args.X[2] = source.data64[1];
args.X[3] = generation;
args.X[4] = option;
svcCallSecureMonitor(&args);
out->data64[0] = args.X[1];
out->data64[1] = args.X[2];
return static_cast<Result>(args.X[0]);
}
Result LoadAesKey(u32 keyslot, const AccessKey &access_key, const KeySource &source) {
SecmonArgs args;
args.X[0] = static_cast<u64>(FunctionId::LoadAesKey);
args.X[1] = keyslot;
args.X[2] = access_key.data64[0];
args.X[3] = access_key.data64[1];
args.X[4] = source.data64[0];
args.X[5] = source.data64[1];
svcCallSecureMonitor(&args);
return static_cast<Result>(args.X[0]);
}
Result CryptAes(AsyncOperationKey *out_op, u32 mode, const IvCtr &iv_ctr, u32 dst_addr, u32 src_addr, size_t size) {
SecmonArgs args;
args.X[0] = static_cast<u64>(FunctionId::CryptAes);
args.X[1] = mode;
args.X[2] = iv_ctr.data64[0];
args.X[3] = iv_ctr.data64[1];
args.X[4] = src_addr;
args.X[5] = dst_addr;
args.X[6] = size;
svcCallSecureMonitor(&args);
out_op->value = args.X[1];
return static_cast<Result>(args.X[0]);
}
Result GenerateSpecificAesKey(AesKey *out_key, const KeySource &source, u32 generation, u32 which) {
SecmonArgs args;
args.X[0] = static_cast<u64>(FunctionId::GenerateSpecificAesKey);
args.X[1] = source.data64[0];
args.X[2] = source.data64[1];
args.X[3] = generation;
args.X[4] = which;
svcCallSecureMonitor(&args);
out_key->data64[0] = args.X[1];
out_key->data64[1] = args.X[2];
return static_cast<Result>(args.X[0]);
}
Result ComputeCmac(Cmac *out_mac, u32 keyslot, const void *data, size_t size) {
SecmonArgs args;
args.X[0] = static_cast<u64>(FunctionId::ComputeCmac);
args.X[1] = keyslot;
args.X[2] = reinterpret_cast<u64>(data);
args.X[3] = size;
svcCallSecureMonitor(&args);
out_mac->data64[0] = args.X[1];
out_mac->data64[1] = args.X[2];
return static_cast<Result>(args.X[0]);
}
Result ReEncryptRsaPrivateKey(void *data, size_t size, const AccessKey &access_key_dec, const KeySource &source_dec, const AccessKey &access_key_enc, const KeySource &source_enc, u32 option) {
SecmonArgs args;
args.X[0] = static_cast<u64>(FunctionId::ReEncryptRsaPrivateKey);
args.X[1] = reinterpret_cast<u64>(&access_key_dec);
args.X[2] = reinterpret_cast<u64>(&access_key_enc);
args.X[3] = option;
args.X[4] = reinterpret_cast<u64>(data);
args.X[5] = size;
args.X[6] = reinterpret_cast<u64>(&source_dec);
args.X[7] = reinterpret_cast<u64>(&source_enc);
svcCallSecureMonitor(&args);
return static_cast<Result>(args.X[0]);
}
Result DecryptOrImportRsaPrivateKey(void *data, size_t size, const AccessKey &access_key, const KeySource &source, DecryptOrImportMode mode) {
SecmonArgs args;
args.X[0] = static_cast<u64>(FunctionId::DecryptOrImportRsaPrivateKey);
args.X[1] = access_key.data64[0];
args.X[2] = access_key.data64[1];
args.X[3] = static_cast<u32>(mode);
args.X[4] = reinterpret_cast<u64>(data);
args.X[5] = size;
args.X[6] = source.data64[0];
args.X[7] = source.data64[1];
svcCallSecureMonitor(&args);
return static_cast<Result>(args.X[0]);
}
Result SecureExpMod(AsyncOperationKey *out_op, const void *base, const void *mod, SecureExpModMode mode) {
SecmonArgs args;
args.X[0] = static_cast<u64>(FunctionId::SecureExpMod);
args.X[1] = reinterpret_cast<u64>(base);
args.X[2] = reinterpret_cast<u64>(mod);
args.X[3] = static_cast<u32>(mode);
svcCallSecureMonitor(&args);
out_op->value = args.X[1];
return static_cast<Result>(args.X[0]);
}
Result UnwrapTitleKey(AsyncOperationKey *out_op, const void *base, const void *mod, const void *label_digest, size_t label_digest_size, u32 option) {
SecmonArgs args;
args.X[0] = static_cast<u64>(FunctionId::UnwrapTitleKey);
args.X[1] = reinterpret_cast<u64>(base);
args.X[2] = reinterpret_cast<u64>(mod);
std::memset(&args.X[3], 0, 4 * sizeof(args.X[3]));
std::memcpy(&args.X[3], label_digest, std::min(size_t(4 * sizeof(args.X[3])), label_digest_size));
args.X[7] = option;
svcCallSecureMonitor(&args);
out_op->value = args.X[1];
return static_cast<Result>(args.X[0]);
}
Result LoadTitleKey(u32 keyslot, const AccessKey &access_key) {
SecmonArgs args;
args.X[0] = static_cast<u64>(FunctionId::LoadTitleKey);
args.X[1] = keyslot;
args.X[2] = access_key.data64[0];
args.X[3] = access_key.data64[1];
svcCallSecureMonitor(&args);
return static_cast<Result>(args.X[0]);
}
Result UnwrapCommonTitleKey(AccessKey *out, const KeySource &source, u32 generation) {
SecmonArgs args;
args.X[0] = static_cast<u64>(FunctionId::UnwrapCommonTitleKey);
args.X[1] = source.data64[0];
args.X[2] = source.data64[1];
args.X[3] = generation;
svcCallSecureMonitor(&args);
out->data64[0] = args.X[1];
out->data64[1] = args.X[2];
return static_cast<Result>(args.X[0]);
}
/* Deprecated functions. */
Result ImportEsKey(const void *data, size_t size, const AccessKey &access_key, const KeySource &source, u32 option) {
SecmonArgs args;
args.X[0] = static_cast<u64>(FunctionId::ImportEsKey);
args.X[1] = access_key.data64[0];
args.X[2] = access_key.data64[1];
args.X[3] = option;
args.X[4] = reinterpret_cast<u64>(data);
args.X[5] = size;
args.X[6] = source.data64[0];
args.X[7] = source.data64[1];
svcCallSecureMonitor(&args);
return static_cast<Result>(args.X[0]);
}
Result DecryptRsaPrivateKey(size_t *out_size, void *data, size_t size, const AccessKey &access_key, const KeySource &source, u32 option) {
SecmonArgs args;
args.X[0] = static_cast<u64>(FunctionId::DecryptRsaPrivateKey);
args.X[1] = access_key.data64[0];
args.X[2] = access_key.data64[1];
args.X[3] = option;
args.X[4] = reinterpret_cast<u64>(data);
args.X[5] = size;
args.X[6] = source.data64[0];
args.X[7] = source.data64[1];
svcCallSecureMonitor(&args);
*out_size = static_cast<size_t>(args.X[1]);
return static_cast<Result>(args.X[0]);
}
Result ImportSecureExpModKey(const void *data, size_t size, const AccessKey &access_key, const KeySource &source, u32 option) {
SecmonArgs args;
args.X[0] = static_cast<u64>(FunctionId::ImportSecureExpModKey);
args.X[1] = access_key.data64[0];
args.X[2] = access_key.data64[1];
args.X[3] = option;
args.X[4] = reinterpret_cast<u64>(data);
args.X[5] = size;
args.X[6] = source.data64[0];
args.X[7] = source.data64[1];
svcCallSecureMonitor(&args);
return static_cast<Result>(args.X[0]);
}
}

View file

@ -1,58 +0,0 @@
/*
* Copyright (c) 2018-2019 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <switch.h>
#include <stratosphere.hpp>
#include "spl_types.hpp"
namespace sts::spl::smc {
/* Helpers for converting arguments. */
inline u32 GetCryptAesMode(CipherMode mode, u32 keyslot) {
return static_cast<u32>((static_cast<u32>(mode) << 4) | (keyslot & 7));
}
inline u32 GetUnwrapEsKeyOption(EsKeyType type, u32 generation) {
return static_cast<u32>((static_cast<u32>(type) << 6) | (generation & 0x3F));
}
/* Functions. */
Result SetConfig(SplConfigItem which, const u64 *value, size_t num_qwords);
Result GetConfig(u64 *out, size_t num_qwords, SplConfigItem which);
Result CheckStatus(Result *out, AsyncOperationKey op);
Result GetResult(Result *out, void *out_buf, size_t out_buf_size, AsyncOperationKey op);
Result ExpMod(AsyncOperationKey *out_op, const void *base, const void *exp, size_t exp_size, const void *mod);
Result GenerateRandomBytes(void *out, size_t size);
Result GenerateAesKek(AccessKey *out, const KeySource &source, u32 generation, u32 option);
Result LoadAesKey(u32 keyslot, const AccessKey &access_key, const KeySource &source);
Result CryptAes(AsyncOperationKey *out_op, u32 mode, const IvCtr &iv_ctr, u32 dst_addr, u32 src_addr, size_t size);
Result GenerateSpecificAesKey(AesKey *out_key, const KeySource &source, u32 generation, u32 which);
Result ComputeCmac(Cmac *out_mac, u32 keyslot, const void *data, size_t size);
Result ReEncryptRsaPrivateKey(void *data, size_t size, const AccessKey &access_key_dec, const KeySource &source_dec, const AccessKey &access_key_enc, const KeySource &source_enc, u32 option);
Result DecryptOrImportRsaPrivateKey(void *data, size_t size, const AccessKey &access_key, const KeySource &source, DecryptOrImportMode mode);
Result SecureExpMod(AsyncOperationKey *out_op, const void *base, const void *mod, SecureExpModMode mode);
Result UnwrapTitleKey(AsyncOperationKey *out_op, const void *base, const void *mod, const void *label_digest, size_t label_digest_size, u32 option);
Result LoadTitleKey(u32 keyslot, const AccessKey &access_key);
Result UnwrapCommonTitleKey(AccessKey *out, const KeySource &source, u32 generation);
/* Deprecated functions. */
Result ImportEsKey(const void *data, size_t size, const AccessKey &access_key, const KeySource &source, u32 option);
Result DecryptRsaPrivateKey(size_t *out_size, void *data, size_t size, const AccessKey &access_key, const KeySource &source, u32 option);
Result ImportSecureExpModKey(const void *data, size_t size, const AccessKey &access_key, const KeySource &source, u32 option);
}

View file

@ -17,17 +17,17 @@
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include "spl_api_impl.hpp"
#include "spl_ssl_service.hpp" #include "spl_ssl_service.hpp"
#include "spl_api.hpp"
namespace sts::spl { namespace sts::spl {
Result SslService::ImportSslKey(InPointer<u8> src, AccessKey access_key, KeySource key_source) { Result SslService::ImportSslKey(InPointer<u8> src, AccessKey access_key, KeySource key_source) {
return spl::ImportSslKey(src.pointer, src.num_elements, access_key, key_source); return impl::ImportSslKey(src.pointer, src.num_elements, access_key, key_source);
} }
Result SslService::SslExpMod(OutPointerWithClientSize<u8> out, InPointer<u8> base, InPointer<u8> mod) { Result SslService::SslExpMod(OutPointerWithClientSize<u8> out, InPointer<u8> base, InPointer<u8> mod) {
return spl::SslExpMod(out.pointer, out.num_elements, base.pointer, base.num_elements, mod.pointer, mod.num_elements); return impl::SslExpMod(out.pointer, out.num_elements, base.pointer, base.num_elements, mod.pointer, mod.num_elements);
} }
} }

View file

@ -17,8 +17,8 @@
#pragma once #pragma once
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include <stratosphere/spl/spl_types.hpp>
#include "spl_types.hpp"
#include "spl_rsa_service.hpp" #include "spl_rsa_service.hpp"
namespace sts::spl { namespace sts::spl {

View file

@ -1,156 +0,0 @@
/*
* Copyright (c) 2018-2019 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <switch.h>
#include <stratosphere.hpp>
namespace sts::spl {
namespace smc {
enum class FunctionId : u32 {
SetConfig = 0xC3000401,
GetConfig = 0xC3000002,
CheckStatus = 0xC3000003,
GetResult = 0xC3000404,
ExpMod = 0xC3000E05,
GenerateRandomBytes = 0xC3000006,
GenerateAesKek = 0xC3000007,
LoadAesKey = 0xC3000008,
CryptAes = 0xC3000009,
GenerateSpecificAesKey = 0xC300000A,
ComputeCmac = 0xC300040B,
ReEncryptRsaPrivateKey = 0xC300D60C,
DecryptOrImportRsaPrivateKey = 0xC300100D,
SecureExpMod = 0xC300060F,
UnwrapTitleKey = 0xC3000610,
LoadTitleKey = 0xC3000011,
UnwrapCommonTitleKey = 0xC3000012,
/* Deprecated functions. */
ImportEsKey = 0xC300100C,
DecryptRsaPrivateKey = 0xC300100D,
ImportSecureExpModKey = 0xC300100E,
};
enum class Result {
Success = 0,
NotImplemented = 1,
InvalidArgument = 2,
InProgress = 3,
NoAsyncOperation = 4,
InvalidAsyncOperation = 5,
Blacklisted = 6,
Max = 99,
};
inline ::Result ConvertResult(Result result) {
if (result == Result::Success) {
return ResultSuccess;
}
if (result < Result::Max) {
return MAKERESULT(Module_Spl, static_cast<u32>(result));
}
return ResultSplUnknownSmcResult;
}
enum class CipherMode {
CbcEncrypt = 0,
CbcDecrypt = 1,
Ctr = 2,
};
enum class DecryptOrImportMode {
DecryptRsaPrivateKey = 0,
ImportLotusKey = 1,
ImportEsKey = 2,
ImportSslKey = 3,
ImportDrmKey = 4,
};
enum class SecureExpModMode {
Lotus = 0,
Ssl = 1,
Drm = 2,
};
enum class EsKeyType {
TitleKey = 0,
ElicenseKey = 1,
};
struct AsyncOperationKey {
u64 value;
};
}
struct BootReasonValue {
u8 power_intr;
u8 rtc_intr;
u8 nv_erc;
u8 boot_reason;
};
static_assert(sizeof(BootReasonValue) == sizeof(u32), "BootReasonValue definition!");
#pragma pack(push, 1)
struct AesKey {
union {
u8 data[AES_128_KEY_SIZE];
u64 data64[AES_128_KEY_SIZE / sizeof(u64)];
};
};
static_assert(alignof(AesKey) == alignof(u8), "AesKey definition!");
struct IvCtr {
union {
u8 data[AES_128_KEY_SIZE];
u64 data64[AES_128_KEY_SIZE / sizeof(u64)];
};
};
static_assert(alignof(IvCtr) == alignof(u8), "IvCtr definition!");
struct Cmac {
union {
u8 data[AES_128_KEY_SIZE];
u64 data64[AES_128_KEY_SIZE / sizeof(u64)];
};
};
static_assert(alignof(Cmac) == alignof(u8), "Cmac definition!");
struct AccessKey {
union {
u8 data[AES_128_KEY_SIZE];
u64 data64[AES_128_KEY_SIZE / sizeof(u64)];
};
};
static_assert(alignof(AccessKey) == alignof(u8), "AccessKey definition!");
struct KeySource {
union {
u8 data[AES_128_KEY_SIZE];
u64 data64[AES_128_KEY_SIZE / sizeof(u64)];
};
};
static_assert(alignof(AccessKey) == alignof(u8), "KeySource definition!");
#pragma pack(pop)
}