git subrepo clone https://github.com/Atmosphere-NX/Atmosphere-libs libraries
subrepo: subdir: "libraries" merged: "07af583b" upstream: origin: "https://github.com/Atmosphere-NX/Atmosphere-libs" branch: "master" commit: "07af583b" git-subrepo: version: "0.4.0" origin: "https://github.com/ingydotnet/git-subrepo" commit: "5d6aba9"
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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 "../spl_types.hpp"
|
||||
|
||||
namespace ams::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);
|
||||
|
||||
/* Atmosphere functions. */
|
||||
Result AtmosphereCopyToIram(uintptr_t iram_dst, const void *dram_src, size_t size);
|
||||
Result AtmosphereCopyFromIram(void *dram_dst, uintptr_t iram_src, size_t size);
|
||||
Result AtmosphereReadWriteRegister(uint64_t address, uint32_t mask, uint32_t value, uint32_t *out_value);
|
||||
Result AtmosphereWriteAddress(void *dst, const void *src, size_t size);
|
||||
Result AtmosphereGetEmummcConfig(void *out_config, void *out_paths, u32 storage_id);
|
||||
|
||||
/* Helpers. */
|
||||
inline Result SetConfig(SplConfigItem which, const u64 value) {
|
||||
return SetConfig(which, &value, 1);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline Result AtmosphereWriteAddress(void *dst, const T value) {
|
||||
static_assert(std::is_integral<T>::value && sizeof(T) <= 8 && (sizeof(T) & (sizeof(T) - 1)) == 0, "AtmosphereWriteAddress requires integral type.");
|
||||
return AtmosphereWriteAddress(dst, &value, sizeof(T));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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 "spl_types.hpp"
|
||||
|
||||
namespace ams::spl {
|
||||
|
||||
HardwareType GetHardwareType();
|
||||
MemoryArrangement GetMemoryArrangement();
|
||||
bool IsDevelopmentHardware();
|
||||
bool IsDevelopmentFunctionEnabled();
|
||||
bool IsMariko();
|
||||
bool IsRecoveryBoot();
|
||||
|
||||
}
|
||||
192
libraries/libstratosphere/include/stratosphere/spl/spl_types.hpp
Normal file
192
libraries/libstratosphere/include/stratosphere/spl/spl_types.hpp
Normal file
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
* 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 <vapours.hpp>
|
||||
|
||||
namespace ams::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,
|
||||
|
||||
/* Atmosphere functions. */
|
||||
AtmosphereIramCopy = 0xF0000201,
|
||||
AtmosphereReadWriteRegister = 0xF0000002,
|
||||
AtmosphereWriteAddress = 0xF0000003,
|
||||
AtmosphereGetEmummcConfig = 0xF0000404,
|
||||
};
|
||||
|
||||
enum class Result {
|
||||
Success = 0,
|
||||
NotImplemented = 1,
|
||||
InvalidArgument = 2,
|
||||
InProgress = 3,
|
||||
NoAsyncOperation = 4,
|
||||
InvalidAsyncOperation = 5,
|
||||
NotPermitted = 6,
|
||||
};
|
||||
|
||||
constexpr inline ::ams::Result ConvertResult(Result smc_result) {
|
||||
/* smc::Result::Success becomes ResultSuccess() directly. */
|
||||
R_UNLESS(smc_result != Result::Success, ResultSuccess());
|
||||
|
||||
/* Convert to the list of known SecureMonitorErrors. */
|
||||
const auto converted = R_MAKE_NAMESPACE_RESULT(::ams::spl, static_cast<u32>(smc_result));
|
||||
if (spl::ResultSecureMonitorError::Includes(converted)) {
|
||||
return converted;
|
||||
}
|
||||
|
||||
return spl::ResultUnknownSecureMonitorError();
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
enum class HardwareType {
|
||||
Icosa = 0,
|
||||
Copper = 1,
|
||||
Hoag = 2,
|
||||
Iowa = 3,
|
||||
};
|
||||
|
||||
enum MemoryArrangement {
|
||||
MemoryArrangement_Standard = 0,
|
||||
MemoryArrangement_StandardForAppletDev = 1,
|
||||
MemoryArrangement_StandardForSystemDev = 2,
|
||||
MemoryArrangement_Expanded = 3,
|
||||
MemoryArrangement_ExpandedForAppletDev = 4,
|
||||
|
||||
/* Note: MemoryArrangement_Dynamic is not official. */
|
||||
/* Atmosphere uses it to maintain compatibility with firmwares prior to 6.0.0, */
|
||||
/* which removed the explicit retrieval of memory arrangement from PM. */
|
||||
MemoryArrangement_Dynamic = 5,
|
||||
MemoryArrangement_Count,
|
||||
};
|
||||
|
||||
struct BootReasonValue {
|
||||
union {
|
||||
struct {
|
||||
u8 power_intr;
|
||||
u8 rtc_intr;
|
||||
u8 nv_erc;
|
||||
u8 boot_reason;
|
||||
};
|
||||
u32 value;
|
||||
};
|
||||
};
|
||||
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)
|
||||
|
||||
}
|
||||
|
||||
/* Extensions to libnx spl config item enum. */
|
||||
constexpr inline SplConfigItem SplConfigItem_ExosphereApiVersion = static_cast<SplConfigItem>(65000);
|
||||
constexpr inline SplConfigItem SplConfigItem_ExosphereNeedsReboot = static_cast<SplConfigItem>(65001);
|
||||
constexpr inline SplConfigItem SplConfigItem_ExosphereNeedsShutdown = static_cast<SplConfigItem>(65002);
|
||||
constexpr inline SplConfigItem SplConfigItem_ExosphereGitCommitHash = static_cast<SplConfigItem>(65003);
|
||||
constexpr inline SplConfigItem SplConfigItem_ExosphereHasRcmBugPatch = static_cast<SplConfigItem>(65004);
|
||||
Reference in New Issue
Block a user