2019-06-21 08:36:00 +00:00
|
|
|
/*
|
2021-10-04 19:59:10 +00:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2019-06-21 08:36:00 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
2021-10-10 19:57:24 +00:00
|
|
|
|
2019-06-21 08:36:00 +00:00
|
|
|
#pragma once
|
2021-10-10 19:57:24 +00:00
|
|
|
#include <stratosphere/spl/spl_types.hpp>
|
2019-06-21 08:36:00 +00:00
|
|
|
|
2019-10-24 09:30:10 +00:00
|
|
|
namespace ams::spl::impl {
|
2019-06-21 08:36:00 +00:00
|
|
|
|
2021-10-10 19:57:24 +00:00
|
|
|
constexpr inline s32 AesKeySlotMin = 16;
|
|
|
|
constexpr inline s32 AesKeySlotCount = 9;
|
|
|
|
constexpr inline s32 AesKeySlotMax = AesKeySlotMin + AesKeySlotCount - 1;
|
|
|
|
|
2019-06-21 08:36:00 +00:00
|
|
|
/* Initialization. */
|
|
|
|
void Initialize();
|
|
|
|
|
|
|
|
/* General. */
|
2021-10-10 19:57:24 +00:00
|
|
|
Result GetConfig(u64 *out, spl::ConfigItem key);
|
2020-07-08 00:07:23 +00:00
|
|
|
Result ModularExponentiate(void *out, size_t out_size, const void *base, size_t base_size, const void *exp, size_t exp_size, const void *mod, size_t mod_size);
|
2021-10-10 19:57:24 +00:00
|
|
|
Result SetConfig(spl::ConfigItem key, u64 value);
|
2019-06-21 08:36:00 +00:00
|
|
|
Result GenerateRandomBytes(void *out, size_t size);
|
|
|
|
Result IsDevelopment(bool *out);
|
|
|
|
Result SetBootReason(BootReasonValue boot_reason);
|
|
|
|
Result GetBootReason(BootReasonValue *out);
|
|
|
|
|
2021-10-10 19:57:24 +00:00
|
|
|
ALWAYS_INLINE bool GetConfigBool(spl::ConfigItem key) {
|
|
|
|
u64 v;
|
|
|
|
R_ABORT_UNLESS(::ams::spl::impl::GetConfig(std::addressof(v), key));
|
|
|
|
return v != 0;
|
|
|
|
}
|
|
|
|
|
2019-06-21 08:36:00 +00:00
|
|
|
/* Crypto. */
|
|
|
|
Result GenerateAesKek(AccessKey *out_access_key, const KeySource &key_source, u32 generation, u32 option);
|
2021-10-10 19:57:24 +00:00
|
|
|
Result LoadAesKey(s32 keyslot, const AccessKey &access_key, const KeySource &key_source);
|
2019-06-21 08:36:00 +00:00
|
|
|
Result GenerateAesKey(AesKey *out_key, const AccessKey &access_key, const KeySource &key_source);
|
|
|
|
Result DecryptAesKey(AesKey *out_key, const KeySource &key_source, u32 generation, u32 option);
|
2021-10-10 19:57:24 +00:00
|
|
|
Result ComputeCtr(void *dst, size_t dst_size, s32 keyslot, const void *src, size_t src_size, const IvCtr &iv_ctr);
|
|
|
|
Result ComputeCmac(Cmac *out_cmac, s32 keyslot, const void *data, size_t size);
|
|
|
|
|
|
|
|
Result AllocateAesKeySlot(s32 *out_keyslot);
|
|
|
|
Result DeallocateAesKeySlot(s32 keyslot);
|
|
|
|
Result TestAesKeySlot(s32 *out_index, s32 keyslot);
|
|
|
|
|
|
|
|
os::SystemEvent *GetAesKeySlotAvailableEvent();
|
2019-06-21 08:36:00 +00:00
|
|
|
|
|
|
|
/* RSA. */
|
2020-07-08 00:07:23 +00:00
|
|
|
Result DecryptDeviceUniqueData(void *dst, size_t dst_size, const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source, u32 option);
|
2019-06-21 08:36:00 +00:00
|
|
|
|
|
|
|
/* SSL */
|
2020-07-08 00:07:23 +00:00
|
|
|
Result DecryptAndStoreSslClientCertKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source);
|
|
|
|
Result ModularExponentiateWithSslClientCertKey(void *out, size_t out_size, const void *base, size_t base_size, const void *mod, size_t mod_size);
|
2019-06-21 08:36:00 +00:00
|
|
|
|
|
|
|
/* ES */
|
2020-07-08 00:07:23 +00:00
|
|
|
Result LoadEsDeviceKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source, u32 option);
|
|
|
|
Result PrepareEsTitleKey(AccessKey *out_access_key, const void *base, size_t base_size, const void *mod, size_t mod_size, const void *label_digest, size_t label_digest_size, u32 generation);
|
|
|
|
Result PrepareCommonEsTitleKey(AccessKey *out_access_key, const KeySource &key_source, u32 generation);
|
|
|
|
Result DecryptAndStoreDrmDeviceCertKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source);
|
|
|
|
Result ModularExponentiateWithDrmDeviceCertKey(void *out, size_t out_size, const void *base, size_t base_size, const void *mod, size_t mod_size);
|
|
|
|
Result PrepareEsArchiveKey(AccessKey *out_access_key, const void *base, size_t base_size, const void *mod, size_t mod_size, const void *label_digest, size_t label_digest_size, u32 generation);
|
2021-10-10 19:57:24 +00:00
|
|
|
Result LoadPreparedAesKey(s32 keyslot, const AccessKey &access_key);
|
2019-06-21 08:36:00 +00:00
|
|
|
|
|
|
|
/* FS */
|
2020-07-08 00:07:23 +00:00
|
|
|
Result DecryptAndStoreGcKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source, u32 option);
|
|
|
|
Result DecryptGcMessage(u32 *out_size, void *dst, size_t dst_size, const void *base, size_t base_size, const void *mod, size_t mod_size, const void *label_digest, size_t label_digest_size);
|
2019-06-21 08:36:00 +00:00
|
|
|
Result GenerateSpecificAesKey(AesKey *out_key, const KeySource &key_source, u32 generation, u32 which);
|
2021-10-10 19:57:24 +00:00
|
|
|
Result LoadPreparedAesKey(s32 keyslot, const AccessKey &access_key);
|
2019-06-21 08:36:00 +00:00
|
|
|
Result GetPackage2Hash(void *dst, const size_t size);
|
|
|
|
|
|
|
|
/* Manu. */
|
2020-07-08 00:07:23 +00:00
|
|
|
Result ReencryptDeviceUniqueData(void *dst, size_t dst_size, const void *src, size_t src_size, const AccessKey &access_key_dec, const KeySource &source_dec, const AccessKey &access_key_enc, const KeySource &source_enc, u32 option);
|
2019-06-21 08:36:00 +00:00
|
|
|
|
|
|
|
}
|