Revert "hoc-clk: add live vdd2, live boost clock and basic pwm dimming"

This reverts commit 15b7df8ef1.
This commit is contained in:
souldbminersmwc
2025-11-09 16:14:52 -05:00
parent 22ec140738
commit 21a3f953d7
3804 changed files with 435 additions and 570162 deletions

View File

@@ -1,41 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/literals.hpp>
#include <vapours/allocator.hpp>
#include <vapours/device_code.hpp>
#include <vapours/timespan.hpp>
#include <vapours/span.hpp>
#include <vapours/util.hpp>
#include <vapours/results.hpp>
#include <vapours/reg.hpp>
#if defined(ATMOSPHERE_BOARD_NINTENDO_NX)
#include <vapours/tegra.hpp>
#endif
#include <vapours/crypto.hpp>
#include <vapours/svc.hpp>
#include <vapours/ams/ams_fatal_error_context.hpp>
#include <vapours/dd.hpp>
#include <vapours/sdmmc.hpp>

View File

@@ -1,60 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
namespace ams {
constexpr inline size_t DefaultAlignment = /*alignof(max_align_t)*/ 0x8;
using AllocateFunction = void *(*)(size_t);
using AllocateFunctionWithUserData = void *(*)(size_t, void *);
using AlignedAllocateFunction = void *(*)(size_t, size_t);
using AlignedAllocateFunctionWithUserData = void *(*)(size_t, size_t, void *);
using DeallocateFunction = void (*)(void *, size_t);
using FreeFunction = void (*)(void *);
using FreeFunctionWithUserData = void (*)(void *, void *);
class MemoryResource {
public:
ALWAYS_INLINE void *allocate(size_t size, size_t alignment = DefaultAlignment) {
return this->AllocateImpl(size, alignment);
}
ALWAYS_INLINE void deallocate(void *buffer, size_t size, size_t alignment = DefaultAlignment) {
this->DeallocateImpl(buffer, size, alignment);
}
ALWAYS_INLINE bool is_equal(const MemoryResource &resource) const {
return this->IsEqualImpl(resource);
}
ALWAYS_INLINE void *Allocate(size_t size, size_t alignment = DefaultAlignment) {
return this->AllocateImpl(size, alignment);
}
ALWAYS_INLINE void Deallocate(void *buffer, size_t size, size_t alignment = DefaultAlignment) {
this->DeallocateImpl(buffer, size, alignment);
}
ALWAYS_INLINE bool IsEqual(const MemoryResource &resource) const {
return this->IsEqualImpl(resource);
}
public:
constexpr ~MemoryResource() = default;
protected:
virtual void *AllocateImpl(size_t size, size_t alignment) = 0;
virtual void DeallocateImpl(void *buffer, size_t size, size_t alignment) = 0;
virtual bool IsEqualImpl(const MemoryResource &resource) const = 0;
};
}

View File

@@ -1,26 +0,0 @@
/*
* Copyright (c) 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
#define ATMOSPHERE_RELEASE_VERSION_MAJOR 1
#define ATMOSPHERE_RELEASE_VERSION_MINOR 9
#define ATMOSPHERE_RELEASE_VERSION_MICRO 5
#define ATMOSPHERE_RELEASE_VERSION ATMOSPHERE_RELEASE_VERSION_MAJOR, ATMOSPHERE_RELEASE_VERSION_MINOR, ATMOSPHERE_RELEASE_VERSION_MICRO
#define ATMOSPHERE_SUPPORTED_HOS_VERSION_MAJOR 20
#define ATMOSPHERE_SUPPORTED_HOS_VERSION_MINOR 5
#define ATMOSPHERE_SUPPORTED_HOS_VERSION_MICRO 0

View File

@@ -1,66 +0,0 @@
/*
* Copyright (c) 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/includes.hpp>
#include <vapours/defines.hpp>
namespace ams::impl {
struct FatalErrorContext {
static constexpr size_t MaxStackTrace = 0x20;
static constexpr size_t MaxStackDumpSize = 0x100;
static constexpr size_t ThreadLocalSize = 0x100;
static constexpr size_t NumGprs = 29;
static constexpr uintptr_t StdAbortMagicAddress = 0x8;
static constexpr u64 StdAbortMagicValue = 0xA55AF00DDEADCAFEul;
static constexpr u32 StdAbortErrorDesc = 0xFFE;
static constexpr u32 StackOverflowErrorDesc = 0xFFD;
static constexpr u32 KernelPanicDesc = 0xF00;
static constexpr u32 DataAbortErrorDesc = 0x101;
static constexpr u32 Magic = util::FourCC<'A', 'F', 'E', '2'>::Code;
u32 magic;
u32 error_desc;
u64 program_id;
union {
u64 gprs[32];
struct {
u64 _gprs[29];
u64 fp;
u64 lr;
u64 sp;
};
};
u64 pc;
u64 module_base;
u32 pstate;
u32 afsr0;
u32 afsr1;
u32 esr;
u64 far;
u64 report_identifier; /* Normally just system tick. */
u64 stack_trace_size;
u64 stack_dump_size;
u64 stack_trace[MaxStackTrace];
u8 stack_dump[MaxStackDumpSize];
u8 tls[ThreadLocalSize];
};
static_assert(sizeof(FatalErrorContext) == 0x450);
static_assert(std::is_standard_layout<FatalErrorContext>::value);
static_assert(std::is_trivial<FatalErrorContext>::value);
}

View File

@@ -1,194 +0,0 @@
/*
* Copyright (c) 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
#define ATMOSPHERE_TARGET_FIRMWARE_WITH_REVISION(major, minor, micro, rev) ((major << 24) | (minor << 16) | (micro << 8) | (rev))
#define ATMOSPHERE_TARGET_FIRMWARE(major, minor, micro) ATMOSPHERE_TARGET_FIRMWARE_WITH_REVISION(major, minor, micro, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_1_0_0 ATMOSPHERE_TARGET_FIRMWARE( 1, 0, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_2_0_0 ATMOSPHERE_TARGET_FIRMWARE( 2, 0, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_2_1_0 ATMOSPHERE_TARGET_FIRMWARE( 2, 1, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_2_2_0 ATMOSPHERE_TARGET_FIRMWARE( 2, 2, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_2_3_0 ATMOSPHERE_TARGET_FIRMWARE( 2, 3, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_3_0_0 ATMOSPHERE_TARGET_FIRMWARE( 3, 0, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_3_0_1 ATMOSPHERE_TARGET_FIRMWARE( 3, 0, 1)
#define ATMOSPHERE_TARGET_FIRMWARE_3_0_2 ATMOSPHERE_TARGET_FIRMWARE( 3, 0, 2)
#define ATMOSPHERE_TARGET_FIRMWARE_4_0_0 ATMOSPHERE_TARGET_FIRMWARE( 4, 0, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_4_0_1 ATMOSPHERE_TARGET_FIRMWARE( 4, 0, 1)
#define ATMOSPHERE_TARGET_FIRMWARE_4_1_0 ATMOSPHERE_TARGET_FIRMWARE( 4, 1, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_5_0_0 ATMOSPHERE_TARGET_FIRMWARE( 5, 0, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_5_0_1 ATMOSPHERE_TARGET_FIRMWARE( 5, 0, 1)
#define ATMOSPHERE_TARGET_FIRMWARE_5_0_2 ATMOSPHERE_TARGET_FIRMWARE( 5, 0, 2)
#define ATMOSPHERE_TARGET_FIRMWARE_5_1_0 ATMOSPHERE_TARGET_FIRMWARE( 5, 1, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_6_0_0 ATMOSPHERE_TARGET_FIRMWARE( 6, 0, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_6_0_1 ATMOSPHERE_TARGET_FIRMWARE( 6, 0, 1)
#define ATMOSPHERE_TARGET_FIRMWARE_6_1_0 ATMOSPHERE_TARGET_FIRMWARE( 6, 1, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_6_2_0 ATMOSPHERE_TARGET_FIRMWARE( 6, 2, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_7_0_0 ATMOSPHERE_TARGET_FIRMWARE( 7, 0, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_7_0_1 ATMOSPHERE_TARGET_FIRMWARE( 7, 0, 1)
#define ATMOSPHERE_TARGET_FIRMWARE_8_0_0 ATMOSPHERE_TARGET_FIRMWARE( 8, 0, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_8_0_1 ATMOSPHERE_TARGET_FIRMWARE( 8, 0, 1)
#define ATMOSPHERE_TARGET_FIRMWARE_8_1_0 ATMOSPHERE_TARGET_FIRMWARE( 8, 1, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_8_1_1 ATMOSPHERE_TARGET_FIRMWARE( 8, 1, 1)
#define ATMOSPHERE_TARGET_FIRMWARE_9_0_0 ATMOSPHERE_TARGET_FIRMWARE( 9, 0, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_9_0_1 ATMOSPHERE_TARGET_FIRMWARE( 9, 0, 1)
#define ATMOSPHERE_TARGET_FIRMWARE_9_1_0 ATMOSPHERE_TARGET_FIRMWARE( 9, 1, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_9_2_0 ATMOSPHERE_TARGET_FIRMWARE( 9, 2, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_10_0_0 ATMOSPHERE_TARGET_FIRMWARE(10, 0, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_10_0_1 ATMOSPHERE_TARGET_FIRMWARE(10, 0, 1)
#define ATMOSPHERE_TARGET_FIRMWARE_10_0_2 ATMOSPHERE_TARGET_FIRMWARE(10, 0, 2)
#define ATMOSPHERE_TARGET_FIRMWARE_10_0_3 ATMOSPHERE_TARGET_FIRMWARE(10, 0, 3)
#define ATMOSPHERE_TARGET_FIRMWARE_10_0_4 ATMOSPHERE_TARGET_FIRMWARE(10, 0, 4)
#define ATMOSPHERE_TARGET_FIRMWARE_10_1_0 ATMOSPHERE_TARGET_FIRMWARE(10, 1, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_10_1_1 ATMOSPHERE_TARGET_FIRMWARE(10, 1, 1)
#define ATMOSPHERE_TARGET_FIRMWARE_10_2_0 ATMOSPHERE_TARGET_FIRMWARE(10, 2, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_11_0_0 ATMOSPHERE_TARGET_FIRMWARE(11, 0, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_11_0_1 ATMOSPHERE_TARGET_FIRMWARE(11, 0, 1)
#define ATMOSPHERE_TARGET_FIRMWARE_12_0_0 ATMOSPHERE_TARGET_FIRMWARE(12, 0, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_12_0_1 ATMOSPHERE_TARGET_FIRMWARE(12, 0, 1)
#define ATMOSPHERE_TARGET_FIRMWARE_12_0_2 ATMOSPHERE_TARGET_FIRMWARE(12, 0, 2)
#define ATMOSPHERE_TARGET_FIRMWARE_12_0_3 ATMOSPHERE_TARGET_FIRMWARE(12, 0, 3)
#define ATMOSPHERE_TARGET_FIRMWARE_12_1_0 ATMOSPHERE_TARGET_FIRMWARE(12, 1, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_13_0_0 ATMOSPHERE_TARGET_FIRMWARE(13, 0, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_13_1_0 ATMOSPHERE_TARGET_FIRMWARE(13, 1, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_13_2_0 ATMOSPHERE_TARGET_FIRMWARE(13, 2, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_13_2_1 ATMOSPHERE_TARGET_FIRMWARE(13, 2, 1)
#define ATMOSPHERE_TARGET_FIRMWARE_14_0_0 ATMOSPHERE_TARGET_FIRMWARE(14, 0, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_14_1_0 ATMOSPHERE_TARGET_FIRMWARE(14, 1, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_14_1_1 ATMOSPHERE_TARGET_FIRMWARE(14, 1, 1)
#define ATMOSPHERE_TARGET_FIRMWARE_14_1_2 ATMOSPHERE_TARGET_FIRMWARE(14, 1, 2)
#define ATMOSPHERE_TARGET_FIRMWARE_15_0_0 ATMOSPHERE_TARGET_FIRMWARE(15, 0, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_15_0_1 ATMOSPHERE_TARGET_FIRMWARE(15, 0, 1)
#define ATMOSPHERE_TARGET_FIRMWARE_16_0_0 ATMOSPHERE_TARGET_FIRMWARE(16, 0, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_16_0_1 ATMOSPHERE_TARGET_FIRMWARE(16, 0, 1)
#define ATMOSPHERE_TARGET_FIRMWARE_16_0_2 ATMOSPHERE_TARGET_FIRMWARE(16, 0, 2)
#define ATMOSPHERE_TARGET_FIRMWARE_16_0_3 ATMOSPHERE_TARGET_FIRMWARE(16, 0, 3)
#define ATMOSPHERE_TARGET_FIRMWARE_16_1_0 ATMOSPHERE_TARGET_FIRMWARE(16, 1, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_17_0_0 ATMOSPHERE_TARGET_FIRMWARE(17, 0, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_17_0_1 ATMOSPHERE_TARGET_FIRMWARE(17, 0, 1)
#define ATMOSPHERE_TARGET_FIRMWARE_18_0_0 ATMOSPHERE_TARGET_FIRMWARE(18, 0, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_18_0_1 ATMOSPHERE_TARGET_FIRMWARE(18, 0, 1)
#define ATMOSPHERE_TARGET_FIRMWARE_18_1_0 ATMOSPHERE_TARGET_FIRMWARE(18, 1, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_19_0_0 ATMOSPHERE_TARGET_FIRMWARE(19, 0, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_19_0_1 ATMOSPHERE_TARGET_FIRMWARE(19, 0, 1)
#define ATMOSPHERE_TARGET_FIRMWARE_20_0_0 ATMOSPHERE_TARGET_FIRMWARE(20, 0, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_20_0_1 ATMOSPHERE_TARGET_FIRMWARE(20, 0, 1)
#define ATMOSPHERE_TARGET_FIRMWARE_20_1_0 ATMOSPHERE_TARGET_FIRMWARE(20, 1, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_20_1_1 ATMOSPHERE_TARGET_FIRMWARE(20, 1, 1)
#define ATMOSPHERE_TARGET_FIRMWARE_20_1_5 ATMOSPHERE_TARGET_FIRMWARE(20, 1, 5)
#define ATMOSPHERE_TARGET_FIRMWARE_20_2_0 ATMOSPHERE_TARGET_FIRMWARE(20, 2, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_20_3_0 ATMOSPHERE_TARGET_FIRMWARE(20, 3, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_20_4_0 ATMOSPHERE_TARGET_FIRMWARE(20, 4, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_20_5_0 ATMOSPHERE_TARGET_FIRMWARE(20, 5, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_CURRENT ATMOSPHERE_TARGET_FIRMWARE_20_5_0
#define ATMOSPHERE_TARGET_FIRMWARE_MIN ATMOSPHERE_TARGET_FIRMWARE(0, 0, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_MAX ATMOSPHERE_TARGET_FIRMWARE_CURRENT
#ifdef __cplusplus
namespace ams {
enum TargetFirmware : u32 {
TargetFirmware_Min = ATMOSPHERE_TARGET_FIRMWARE_MIN,
TargetFirmware_1_0_0 = ATMOSPHERE_TARGET_FIRMWARE_1_0_0,
TargetFirmware_2_0_0 = ATMOSPHERE_TARGET_FIRMWARE_2_0_0,
TargetFirmware_2_1_0 = ATMOSPHERE_TARGET_FIRMWARE_2_1_0,
TargetFirmware_2_2_0 = ATMOSPHERE_TARGET_FIRMWARE_2_2_0,
TargetFirmware_2_3_0 = ATMOSPHERE_TARGET_FIRMWARE_2_3_0,
TargetFirmware_3_0_0 = ATMOSPHERE_TARGET_FIRMWARE_3_0_0,
TargetFirmware_3_0_1 = ATMOSPHERE_TARGET_FIRMWARE_3_0_1,
TargetFirmware_3_0_2 = ATMOSPHERE_TARGET_FIRMWARE_3_0_2,
TargetFirmware_4_0_0 = ATMOSPHERE_TARGET_FIRMWARE_4_0_0,
TargetFirmware_4_0_1 = ATMOSPHERE_TARGET_FIRMWARE_4_0_1,
TargetFirmware_4_1_0 = ATMOSPHERE_TARGET_FIRMWARE_4_1_0,
TargetFirmware_5_0_0 = ATMOSPHERE_TARGET_FIRMWARE_5_0_0,
TargetFirmware_5_0_1 = ATMOSPHERE_TARGET_FIRMWARE_5_0_1,
TargetFirmware_5_0_2 = ATMOSPHERE_TARGET_FIRMWARE_5_0_2,
TargetFirmware_5_1_0 = ATMOSPHERE_TARGET_FIRMWARE_5_1_0,
TargetFirmware_6_0_0 = ATMOSPHERE_TARGET_FIRMWARE_6_0_0,
TargetFirmware_6_0_1 = ATMOSPHERE_TARGET_FIRMWARE_6_0_1,
TargetFirmware_6_1_0 = ATMOSPHERE_TARGET_FIRMWARE_6_1_0,
TargetFirmware_6_2_0 = ATMOSPHERE_TARGET_FIRMWARE_6_2_0,
TargetFirmware_7_0_0 = ATMOSPHERE_TARGET_FIRMWARE_7_0_0,
TargetFirmware_7_0_1 = ATMOSPHERE_TARGET_FIRMWARE_7_0_1,
TargetFirmware_8_0_0 = ATMOSPHERE_TARGET_FIRMWARE_8_0_0,
TargetFirmware_8_0_1 = ATMOSPHERE_TARGET_FIRMWARE_8_0_1,
TargetFirmware_8_1_0 = ATMOSPHERE_TARGET_FIRMWARE_8_1_0,
TargetFirmware_8_1_1 = ATMOSPHERE_TARGET_FIRMWARE_8_1_1,
TargetFirmware_9_0_0 = ATMOSPHERE_TARGET_FIRMWARE_9_0_0,
TargetFirmware_9_0_1 = ATMOSPHERE_TARGET_FIRMWARE_9_0_1,
TargetFirmware_9_1_0 = ATMOSPHERE_TARGET_FIRMWARE_9_1_0,
TargetFirmware_9_2_0 = ATMOSPHERE_TARGET_FIRMWARE_9_2_0,
TargetFirmware_10_0_0 = ATMOSPHERE_TARGET_FIRMWARE_10_0_0,
TargetFirmware_10_0_1 = ATMOSPHERE_TARGET_FIRMWARE_10_0_1,
TargetFirmware_10_0_2 = ATMOSPHERE_TARGET_FIRMWARE_10_0_2,
TargetFirmware_10_0_3 = ATMOSPHERE_TARGET_FIRMWARE_10_0_3,
TargetFirmware_10_0_4 = ATMOSPHERE_TARGET_FIRMWARE_10_0_4,
TargetFirmware_10_1_0 = ATMOSPHERE_TARGET_FIRMWARE_10_1_0,
TargetFirmware_10_1_1 = ATMOSPHERE_TARGET_FIRMWARE_10_1_1,
TargetFirmware_10_2_0 = ATMOSPHERE_TARGET_FIRMWARE_10_2_0,
TargetFirmware_11_0_0 = ATMOSPHERE_TARGET_FIRMWARE_11_0_0,
TargetFirmware_11_0_1 = ATMOSPHERE_TARGET_FIRMWARE_11_0_1,
TargetFirmware_12_0_0 = ATMOSPHERE_TARGET_FIRMWARE_12_0_0,
TargetFirmware_12_0_1 = ATMOSPHERE_TARGET_FIRMWARE_12_0_1,
TargetFirmware_12_0_2 = ATMOSPHERE_TARGET_FIRMWARE_12_0_2,
TargetFirmware_12_0_3 = ATMOSPHERE_TARGET_FIRMWARE_12_0_3,
TargetFirmware_12_1_0 = ATMOSPHERE_TARGET_FIRMWARE_12_1_0,
TargetFirmware_13_0_0 = ATMOSPHERE_TARGET_FIRMWARE_13_0_0,
TargetFirmware_13_1_0 = ATMOSPHERE_TARGET_FIRMWARE_13_1_0,
TargetFirmware_13_2_0 = ATMOSPHERE_TARGET_FIRMWARE_13_2_0,
TargetFirmware_13_2_1 = ATMOSPHERE_TARGET_FIRMWARE_13_2_1,
TargetFirmware_14_0_0 = ATMOSPHERE_TARGET_FIRMWARE_14_0_0,
TargetFirmware_14_1_0 = ATMOSPHERE_TARGET_FIRMWARE_14_1_0,
TargetFirmware_14_1_1 = ATMOSPHERE_TARGET_FIRMWARE_14_1_1,
TargetFirmware_14_1_2 = ATMOSPHERE_TARGET_FIRMWARE_14_1_2,
TargetFirmware_15_0_0 = ATMOSPHERE_TARGET_FIRMWARE_15_0_0,
TargetFirmware_15_0_1 = ATMOSPHERE_TARGET_FIRMWARE_15_0_1,
TargetFirmware_16_0_0 = ATMOSPHERE_TARGET_FIRMWARE_16_0_0,
TargetFirmware_16_0_1 = ATMOSPHERE_TARGET_FIRMWARE_16_0_1,
TargetFirmware_16_0_2 = ATMOSPHERE_TARGET_FIRMWARE_16_0_2,
TargetFirmware_16_0_3 = ATMOSPHERE_TARGET_FIRMWARE_16_0_3,
TargetFirmware_16_1_0 = ATMOSPHERE_TARGET_FIRMWARE_16_1_0,
TargetFirmware_17_0_0 = ATMOSPHERE_TARGET_FIRMWARE_17_0_0,
TargetFirmware_17_0_1 = ATMOSPHERE_TARGET_FIRMWARE_17_0_1,
TargetFirmware_18_0_0 = ATMOSPHERE_TARGET_FIRMWARE_18_0_0,
TargetFirmware_18_0_1 = ATMOSPHERE_TARGET_FIRMWARE_18_0_1,
TargetFirmware_18_1_0 = ATMOSPHERE_TARGET_FIRMWARE_18_1_0,
TargetFirmware_19_0_0 = ATMOSPHERE_TARGET_FIRMWARE_19_0_0,
TargetFirmware_19_0_1 = ATMOSPHERE_TARGET_FIRMWARE_19_0_1,
TargetFirmware_20_0_0 = ATMOSPHERE_TARGET_FIRMWARE_20_0_0,
TargetFirmware_20_0_1 = ATMOSPHERE_TARGET_FIRMWARE_20_0_1,
TargetFirmware_20_1_0 = ATMOSPHERE_TARGET_FIRMWARE_20_1_0,
TargetFirmware_20_1_1 = ATMOSPHERE_TARGET_FIRMWARE_20_1_1,
TargetFirmware_20_1_5 = ATMOSPHERE_TARGET_FIRMWARE_20_1_5,
TargetFirmware_20_2_0 = ATMOSPHERE_TARGET_FIRMWARE_20_2_0,
TargetFirmware_20_3_0 = ATMOSPHERE_TARGET_FIRMWARE_20_3_0,
TargetFirmware_20_4_0 = ATMOSPHERE_TARGET_FIRMWARE_20_4_0,
TargetFirmware_20_5_0 = ATMOSPHERE_TARGET_FIRMWARE_20_5_0,
TargetFirmware_Current = ATMOSPHERE_TARGET_FIRMWARE_CURRENT,
TargetFirmware_Max = ATMOSPHERE_TARGET_FIRMWARE_MAX,
};
static_assert(TargetFirmware_Current <= TargetFirmware_Max);
}
#endif

View File

@@ -1,19 +0,0 @@
/*
* Copyright (c) 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 "ams/ams_api_version.h"
#include "ams/ams_target_firmware.h"

View File

@@ -1,133 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
namespace ams {
class Result;
namespace os {
struct UserExceptionInfo;
}
namespace impl {
NORETURN void UnexpectedDefaultImpl(const char *func, const char *file, int line);
}
}
namespace ams::diag {
enum AssertionType {
AssertionType_Audit,
AssertionType_Assert,
};
struct LogMessage;
struct AssertionInfo {
AssertionType type;
const LogMessage *message;
const char *expr;
const char *func;
const char *file;
int line;
};
enum AbortReason {
AbortReason_Audit,
AbortReason_Assert,
AbortReason_Abort,
AbortReason_UnexpectedDefault,
};
struct AbortInfo {
AbortReason reason;
const LogMessage *message;
const char *expr;
const char *func;
const char *file;
int line;
};
void OnAssertionFailure(AssertionType type, const char *expr, const char *func, const char *file, int line, const char *format, ...) __attribute__((format(printf, 6, 7)));
void OnAssertionFailure(AssertionType type, const char *expr, const char *func, const char *file, int line);
NORETURN void AbortImpl(const char *expr, const char *func, const char *file, int line);
NORETURN void AbortImpl(const char *expr, const char *func, const char *file, int line, const char *format, ...) __attribute__((format(printf, 5, 6)));
NORETURN void AbortImpl(const char *expr, const char *func, const char *file, int line, const ::ams::Result *result, const char *format, ...) __attribute__((format(printf, 6, 7)));
NORETURN void AbortImpl(const char *expr, const char *func, const char *file, int line, const ::ams::Result *result, const ::ams::os::UserExceptionInfo *exception_info, const char *fmt, ...) __attribute__((format(printf, 7, 8)));
NORETURN void VAbortImpl(const char *expr, const char *func, const char *file, int line, const ::ams::Result *result, const ::ams::os::UserExceptionInfo *exception_info, const char *fmt, std::va_list vl);
}
#ifdef AMS_ENABLE_DETAILED_ASSERTIONS
#define AMS_CALL_ASSERT_FAIL_IMPL(type, expr, ...) ::ams::diag::OnAssertionFailure(type, expr, __PRETTY_FUNCTION__, __FILE__, __LINE__, ## __VA_ARGS__)
#define AMS_CALL_ABORT_IMPL(expr, ...) ::ams::diag::AbortImpl(expr, __PRETTY_FUNCTION__, __FILE__, __LINE__, ## __VA_ARGS__)
#define AMS_UNREACHABLE_DEFAULT_CASE() default: ::ams::impl::UnexpectedDefaultImpl(__PRETTY_FUNCTION__, __FILE__, __LINE__)
#else
#define AMS_CALL_ASSERT_FAIL_IMPL(type, expr, ...) ::ams::diag::OnAssertionFailure(type, "", "", "", 0)
#define AMS_CALL_ABORT_IMPL(expr, ...) ::ams::diag::AbortImpl("", "", "", 0); AMS_UNUSED(expr, ## __VA_ARGS__)
#define AMS_UNREACHABLE_DEFAULT_CASE() default: ::ams::impl::UnexpectedDefaultImpl("", "", 0)
#endif
#ifdef AMS_ENABLE_ASSERTIONS
#define AMS_ASSERT_IMPL(type, expr, ...) \
{ \
if (std::is_constant_evaluated()) { \
AMS_ASSUME(static_cast<bool>(expr)); \
} else { \
if (const bool __tmp_ams_assert_val = static_cast<bool>(expr); (!__tmp_ams_assert_val)) { \
AMS_CALL_ASSERT_FAIL_IMPL(type, #expr, ## __VA_ARGS__); \
} \
} \
}
#elif defined(AMS_PRESERVE_ASSERTION_EXPRESSIONS)
#define AMS_ASSERT_IMPL(type, expr, ...) AMS_UNUSED(expr, ## __VA_ARGS__)
#else
#define AMS_ASSERT_IMPL(type, expr, ...) static_cast<void>(0)
#endif
#define AMS_ASSERT(expr, ...) AMS_ASSERT_IMPL(::ams::diag::AssertionType_Assert, expr, ## __VA_ARGS__)
#ifdef AMS_BUILD_FOR_AUDITING
#define AMS_AUDIT(expr, ...) AMS_ASSERT_IMPL(::ams::diag::AssertionType_Audit, expr, ## __VA_ARGS__)
#elif defined(AMS_PRESERVE_AUDIT_EXPRESSIONS)
#define AMS_AUDIT(expr, ...) AMS_UNUSED(expr, ## __VA_ARGS__)
#else
#define AMS_AUDIT(expr, ...) static_cast<void>(0)
#endif
#define AMS_ABORT(...) AMS_CALL_ABORT_IMPL("", ## __VA_ARGS__)
#define AMS_ABORT_UNLESS(expr, ...) \
{ \
if (std::is_constant_evaluated()) { \
AMS_ASSUME(static_cast<bool>(expr)); \
} else { \
if (const bool __tmp_ams_assert_val = static_cast<bool>(expr); AMS_UNLIKELY(!__tmp_ams_assert_val)) { \
AMS_CALL_ABORT_IMPL(#expr, ##__VA_ARGS__); \
} \
} \
}

View File

@@ -1,50 +0,0 @@
/*
* Copyright (c) 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/includes.hpp>
#include <vapours/defines.hpp>
#include <vapours/compiler.hpp>
#if defined(AMS_FORCE_DISABLE_DETAILED_ASSERTIONS) && defined(AMS_FORCE_ENABLE_DETAILED_ASSERTIONS)
#error "Invalid detailed assertions state"
#endif
#ifdef AMS_BUILD_FOR_AUDITING
#define AMS_BUILD_FOR_DEBUGGING
#if !defined(AMS_FORCE_DISABLE_DETAILED_ASSERTIONS)
#define AMS_ENABLE_DETAILED_ASSERTIONS
#endif
#endif
#ifdef AMS_BUILD_FOR_DEBUGGING
#define AMS_ENABLE_ASSERTIONS
#if !defined(AMS_ENABLE_DETAILED_ASSERTIONS) && !defined(AMS_FORCE_DISABLE_DETAILED_ASSERTIONS)
#if !defined(ATMOSPHERE_IS_EXOSPHERE) || defined(AMS_FORCE_ENABLE_DETAILED_ASSERTIONS)
#define AMS_ENABLE_DETAILED_ASSERTIONS
#endif
#endif
#endif

View File

@@ -1,24 +0,0 @@
/*
* Copyright (c) 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/includes.hpp>
#include <vapours/defines.hpp>
#if defined(ATMOSPHERE_COMPILER_CLANG)
#include <vapours/impl/compiler_impl.clang.hpp>
#elif defined(ATMOSPHERE_COMPILER_GCC)
#include <vapours/impl/compiler_impl.gcc.hpp>
#endif

View File

@@ -1,41 +0,0 @@
/*
* Copyright (c) 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/defines.hpp>
#include <vapours/crypto/crypto_memory_compare.hpp>
#include <vapours/crypto/crypto_memory_clear.hpp>
#include <vapours/crypto/crypto_md5_generator.hpp>
#include <vapours/crypto/crypto_sha1_generator.hpp>
#include <vapours/crypto/crypto_sha256_generator.hpp>
#include <vapours/crypto/crypto_sha3_generator.hpp>
#include <vapours/crypto/crypto_aes_encryptor.hpp>
#include <vapours/crypto/crypto_aes_decryptor.hpp>
#include <vapours/crypto/crypto_aes_cbc_encryptor_decryptor.hpp>
#include <vapours/crypto/crypto_aes_ccm_encryptor_decryptor.hpp>
#include <vapours/crypto/crypto_aes_ctr_encryptor_decryptor.hpp>
#include <vapours/crypto/crypto_aes_xts_encryptor_decryptor.hpp>
#include <vapours/crypto/crypto_aes_gcm_encryptor.hpp>
#include <vapours/crypto/crypto_aes_128_cmac_generator.hpp>
#include <vapours/crypto/crypto_rsa_pkcs1_sha256_verifier.hpp>
#include <vapours/crypto/crypto_rsa_pss_sha256_verifier.hpp>
#include <vapours/crypto/crypto_rsa_oaep_sha256_decoder.hpp>
#include <vapours/crypto/crypto_rsa_oaep_sha256_decryptor.hpp>
#include <vapours/crypto/crypto_rsa_oaep_sha256_encryptor.hpp>
#include <vapours/crypto/crypto_hmac_sha1_generator.hpp>
#include <vapours/crypto/crypto_hmac_sha256_generator.hpp>
#include <vapours/crypto/crypto_csrng.hpp>

View File

@@ -1,61 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/crypto_aes_encryptor.hpp>
#include <vapours/crypto/crypto_cmac_generator.hpp>
namespace ams::crypto {
class Aes128CmacGenerator {
NON_COPYABLE(Aes128CmacGenerator);
NON_MOVEABLE(Aes128CmacGenerator);
public:
static constexpr size_t MacSize = AesEncryptor128::BlockSize;
private:
AesEncryptor128 m_aes;
CmacGenerator<AesEncryptor128> m_cmac_generator;
public:
Aes128CmacGenerator() { /* ... */ }
void Initialize(const void *key, size_t key_size) {
AMS_ASSERT(key_size == AesEncryptor128::KeySize);
m_aes.Initialize(key, key_size);
m_cmac_generator.Initialize(std::addressof(m_aes));
}
void Update(const void *data, size_t size) {
m_cmac_generator.Update(data, size);
}
void GetMac(void *dst, size_t size) {
m_cmac_generator.GetMac(dst, size);
}
};
ALWAYS_INLINE void GenerateAes128Cmac(void *dst, size_t dst_size, const void *data, size_t data_size, const void *key, size_t key_size) {
Aes128CmacGenerator cmac_generator;
cmac_generator.Initialize(key, key_size);
cmac_generator.Update(data, data_size);
cmac_generator.GetMac(dst, dst_size);
}
}

View File

@@ -1,81 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/crypto_aes_encryptor.hpp>
#include <vapours/crypto/crypto_cbc_encryptor.hpp>
#include <vapours/crypto/crypto_cbc_decryptor.hpp>
namespace ams::crypto {
namespace impl {
template<template<typename> typename _CbcImpl, typename _AesImpl>
class AesCbcCryptor {
NON_COPYABLE(AesCbcCryptor);
NON_MOVEABLE(AesCbcCryptor);
private:
using AesImpl = _AesImpl;
using CbcImpl = _CbcImpl<AesImpl>;
public:
static constexpr size_t KeySize = AesImpl::KeySize;
static constexpr size_t BlockSize = CbcImpl::BlockSize;
static constexpr size_t IvSize = CbcImpl::BlockSize;
private:
AesImpl m_aes_impl;
CbcImpl m_cbc_impl;
public:
AesCbcCryptor() { /* ... */ }
void Initialize(const void *key, size_t key_size, const void *iv, size_t iv_size) {
AMS_ASSERT(key_size == KeySize);
AMS_ASSERT(iv_size == IvSize);
m_aes_impl.Initialize(key, key_size);
m_cbc_impl.Initialize(std::addressof(m_aes_impl), iv, iv_size);
}
size_t Update(void *dst, size_t dst_size, const void *src, size_t src_size) {
return m_cbc_impl.Update(dst, dst_size, src, src_size);
}
size_t GetBufferedDataSize() const {
return m_cbc_impl.GetBufferedDataSize();
}
};
}
using Aes128CbcEncryptor = impl::AesCbcCryptor<CbcEncryptor, AesEncryptor128>;
using Aes192CbcEncryptor = impl::AesCbcCryptor<CbcEncryptor, AesEncryptor192>;
using Aes256CbcEncryptor = impl::AesCbcCryptor<CbcEncryptor, AesEncryptor256>;
using Aes128CbcDecryptor = impl::AesCbcCryptor<CbcDecryptor, AesDecryptor128>;
using Aes192CbcDecryptor = impl::AesCbcCryptor<CbcDecryptor, AesDecryptor192>;
using Aes256CbcDecryptor = impl::AesCbcCryptor<CbcDecryptor, AesDecryptor256>;
size_t EncryptAes128Cbc(void *dst, size_t dst_size, const void *key, size_t key_size, const void *iv, size_t iv_size, const void *src, size_t src_size);
size_t EncryptAes192Cbc(void *dst, size_t dst_size, const void *key, size_t key_size, const void *iv, size_t iv_size, const void *src, size_t src_size);
size_t EncryptAes256Cbc(void *dst, size_t dst_size, const void *key, size_t key_size, const void *iv, size_t iv_size, const void *src, size_t src_size);
size_t DecryptAes128Cbc(void *dst, size_t dst_size, const void *key, size_t key_size, const void *iv, size_t iv_size, const void *src, size_t src_size);
size_t DecryptAes192Cbc(void *dst, size_t dst_size, const void *key, size_t key_size, const void *iv, size_t iv_size, const void *src, size_t src_size);
size_t DecryptAes256Cbc(void *dst, size_t dst_size, const void *key, size_t key_size, const void *iv, size_t iv_size, const void *src, size_t src_size);
}

View File

@@ -1,115 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/crypto_aes_encryptor.hpp>
#include <vapours/crypto/crypto_ccm_encryptor.hpp>
#include <vapours/crypto/crypto_ccm_decryptor.hpp>
namespace ams::crypto {
namespace impl {
template<template<typename> typename _CcmImpl, typename _AesImpl>
class AesCcmCryptor {
NON_COPYABLE(AesCcmCryptor);
NON_MOVEABLE(AesCcmCryptor);
private:
using AesImpl = _AesImpl;
using CcmImpl = _CcmImpl<AesImpl>;
public:
static constexpr size_t KeySize = CcmImpl::KeySize;
static constexpr size_t BlockSize = CcmImpl::BlockSize;
static constexpr size_t MaxMacSize = CcmImpl::MaxMacSize;
static constexpr size_t MaxNonceSize = CcmImpl::MaxNonceSize;
private:
AesImpl m_aes_impl;
CcmImpl m_ccm_impl;
public:
AesCcmCryptor() { /* ... */ }
void Initialize(const void *key, size_t key_size, const void *nonce, size_t nonce_size, s64 aad_size, s64 data_size, size_t mac_size) {
AMS_ASSERT(key_size == KeySize);
AMS_ASSERT(nonce_size <= MaxNonceSize);
AMS_ASSERT(mac_size <= MaxMacSize);
m_aes_impl.Initialize(key, key_size);
m_ccm_impl.Initialize(std::addressof(m_aes_impl), nonce, nonce_size, aad_size, data_size, mac_size);
}
size_t Update(void *dst, size_t dst_size, const void *src, size_t src_size) {
return m_ccm_impl.Update(dst, dst_size, src, src_size);
}
void UpdateAad(const void *aad, size_t aad_size) {
return m_ccm_impl.UpdateAad(aad, aad_size);
}
void GetMac(void *dst, size_t dst_size) {
return m_ccm_impl.GetMac(dst, dst_size);
}
};
}
using Aes128CcmEncryptor = impl::AesCcmCryptor<CcmEncryptor, AesEncryptor128>;
using Aes128CcmDecryptor = impl::AesCcmCryptor<CcmDecryptor, AesEncryptor128>;
inline size_t EncryptAes128Ccm(void *dst, size_t dst_size, void *mac, size_t mac_buf_size, const void *key, size_t key_size, const void *nonce, size_t nonce_size, const void *src, size_t src_size, const void *aad, size_t aad_size, size_t mac_size) {
/* Create encryptor. */
Aes128CcmEncryptor ccm;
ccm.Initialize(key, key_size, nonce, nonce_size, aad_size, src_size, mac_size);
/* Process aad. */
if (aad_size > 0) {
ccm.UpdateAad(aad, aad_size);
}
/* Process data. */
size_t processed = 0;
if (src_size > 0) {
processed = ccm.Update(dst, dst_size, src, src_size);
}
/* Get mac. */
ccm.GetMac(mac, mac_buf_size);
return processed;
}
inline size_t DecryptAes128Ccm(void *dst, size_t dst_size, void *mac, size_t mac_buf_size, const void *key, size_t key_size, const void *nonce, size_t nonce_size, const void *src, size_t src_size, const void *aad, size_t aad_size, size_t mac_size) {
/* Create decryptor. */
Aes128CcmDecryptor ccm;
ccm.Initialize(key, key_size, nonce, nonce_size, aad_size, src_size, mac_size);
/* Process aad. */
if (aad_size > 0) {
ccm.UpdateAad(aad, aad_size);
}
/* Process data. */
size_t processed = 0;
if (src_size > 0) {
processed = ccm.Update(dst, dst_size, src, src_size);
}
/* Get mac. */
ccm.GetMac(mac, mac_buf_size);
return processed;
}
}

View File

@@ -1,94 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/crypto_aes_encryptor.hpp>
#include <vapours/crypto/crypto_ctr_encryptor.hpp>
#include <vapours/crypto/crypto_ctr_decryptor.hpp>
namespace ams::crypto {
namespace impl {
template<template<typename> typename _CtrImpl, typename _AesImpl>
class AesCtrCryptor {
NON_COPYABLE(AesCtrCryptor);
NON_MOVEABLE(AesCtrCryptor);
private:
using AesImpl = _AesImpl;
using CtrImpl = _CtrImpl<AesImpl>;
public:
static constexpr size_t KeySize = AesImpl::KeySize;
static constexpr size_t BlockSize = CtrImpl::BlockSize;
static constexpr size_t IvSize = CtrImpl::BlockSize;
private:
AesImpl m_aes_impl;
CtrImpl m_ctr_impl;
public:
AesCtrCryptor() { /* ... */ }
void Initialize(const void *key, size_t key_size, const void *iv, size_t iv_size) {
this->Initialize(key, key_size, iv, iv_size, 0);
}
void Initialize(const void *key, size_t key_size, const void *iv, size_t iv_size, s64 offset) {
AMS_ASSERT(key_size == KeySize);
AMS_ASSERT(iv_size == IvSize);
AMS_ASSERT(offset >= 0);
m_aes_impl.Initialize(key, key_size);
m_ctr_impl.Initialize(std::addressof(m_aes_impl), iv, iv_size, offset);
}
void SwitchMessage(const void *iv, size_t iv_size) {
return m_ctr_impl.SwitchMessage(iv, iv_size);
}
size_t Update(void *dst, size_t dst_size, const void *src, size_t src_size) {
return m_ctr_impl.Update(dst, dst_size, src, src_size);
}
};
}
using Aes128CtrEncryptor = impl::AesCtrCryptor<CtrEncryptor, AesEncryptor128>;
using Aes192CtrEncryptor = impl::AesCtrCryptor<CtrEncryptor, AesEncryptor192>;
using Aes256CtrEncryptor = impl::AesCtrCryptor<CtrEncryptor, AesEncryptor256>;
using Aes128CtrDecryptor = impl::AesCtrCryptor<CtrDecryptor, AesEncryptor128>;
using Aes192CtrDecryptor = impl::AesCtrCryptor<CtrDecryptor, AesEncryptor192>;
using Aes256CtrDecryptor = impl::AesCtrCryptor<CtrDecryptor, AesEncryptor256>;
size_t EncryptAes128Ctr(void *dst, size_t dst_size, const void *key, size_t key_size, const void *iv, size_t iv_size, const void *src, size_t src_size);
size_t EncryptAes192Ctr(void *dst, size_t dst_size, const void *key, size_t key_size, const void *iv, size_t iv_size, const void *src, size_t src_size);
size_t EncryptAes256Ctr(void *dst, size_t dst_size, const void *key, size_t key_size, const void *iv, size_t iv_size, const void *src, size_t src_size);
size_t DecryptAes128Ctr(void *dst, size_t dst_size, const void *key, size_t key_size, const void *iv, size_t iv_size, const void *src, size_t src_size);
size_t DecryptAes192Ctr(void *dst, size_t dst_size, const void *key, size_t key_size, const void *iv, size_t iv_size, const void *src, size_t src_size);
size_t DecryptAes256Ctr(void *dst, size_t dst_size, const void *key, size_t key_size, const void *iv, size_t iv_size, const void *src, size_t src_size);
size_t EncryptAes128CtrPartial(void *dst, size_t dst_size, const void *key, size_t key_size, const void *iv, size_t iv_size, s64 offset, const void *src, size_t src_size);
size_t EncryptAes192CtrPartial(void *dst, size_t dst_size, const void *key, size_t key_size, const void *iv, size_t iv_size, s64 offset, const void *src, size_t src_size);
size_t EncryptAes256CtrPartial(void *dst, size_t dst_size, const void *key, size_t key_size, const void *iv, size_t iv_size, s64 offset, const void *src, size_t src_size);
size_t DecryptAes128CtrPartial(void *dst, size_t dst_size, const void *key, size_t key_size, const void *iv, size_t iv_size, s64 offset, const void *src, size_t src_size);
size_t DecryptAes192CtrPartial(void *dst, size_t dst_size, const void *key, size_t key_size, const void *iv, size_t iv_size, s64 offset, const void *src, size_t src_size);
size_t DecryptAes256CtrPartial(void *dst, size_t dst_size, const void *key, size_t key_size, const void *iv, size_t iv_size, s64 offset, const void *src, size_t src_size);
}

View File

@@ -1,57 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_aes_impl.hpp>
namespace ams::crypto {
template<size_t _KeySize>
class AesDecryptor {
NON_COPYABLE(AesDecryptor);
NON_MOVEABLE(AesDecryptor);
private:
using Impl = impl::AesImpl<_KeySize>;
public:
static constexpr size_t KeySize = Impl::KeySize;
static constexpr size_t BlockSize = Impl::BlockSize;
static constexpr size_t RoundKeySize = Impl::RoundKeySize;
private:
Impl m_impl;
public:
AesDecryptor() { /* ... */ }
void Initialize(const void *key, size_t key_size) {
m_impl.Initialize(key, key_size, false);
}
void DecryptBlock(void *dst, size_t dst_size, const void *src, size_t src_size) const {
return m_impl.DecryptBlock(dst, dst_size, src, src_size);
}
const u8 *GetRoundKey() const {
return m_impl.GetRoundKey();
}
};
using AesDecryptor128 = AesDecryptor<16>;
using AesDecryptor192 = AesDecryptor<24>;
using AesDecryptor256 = AesDecryptor<32>;
}

View File

@@ -1,57 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_aes_impl.hpp>
namespace ams::crypto {
template<size_t _KeySize>
class AesEncryptor {
NON_COPYABLE(AesEncryptor);
NON_MOVEABLE(AesEncryptor);
private:
using Impl = impl::AesImpl<_KeySize>;
public:
static constexpr size_t KeySize = Impl::KeySize;
static constexpr size_t BlockSize = Impl::BlockSize;
static constexpr size_t RoundKeySize = Impl::RoundKeySize;
private:
Impl m_impl;
public:
AesEncryptor() { /* ... */ }
void Initialize(const void *key, size_t key_size) {
m_impl.Initialize(key, key_size, true);
}
void EncryptBlock(void *dst, size_t dst_size, const void *src, size_t src_size) const {
return m_impl.EncryptBlock(dst, dst_size, src, src_size);
}
const u8 *GetRoundKey() const {
return m_impl.GetRoundKey();
}
};
using AesEncryptor128 = AesEncryptor<16>;
using AesEncryptor192 = AesEncryptor<24>;
using AesEncryptor256 = AesEncryptor<32>;
}

View File

@@ -1,73 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/crypto_aes_encryptor.hpp>
#include <vapours/crypto/crypto_gcm_encryptor.hpp>
namespace ams::crypto {
namespace impl {
template<typename _AesImpl>
class AesGcmEncryptor {
NON_COPYABLE(AesGcmEncryptor);
NON_MOVEABLE(AesGcmEncryptor);
private:
using AesImpl = _AesImpl;
using GcmImpl = GcmEncryptor<AesImpl>;
public:
static constexpr size_t KeySize = AesImpl::KeySize;
static constexpr size_t BlockSize = AesImpl::BlockSize;
static constexpr size_t MacSize = AesImpl::BlockSize;
private:
AesImpl m_aes_impl;
GcmImpl m_gcm_impl;
public:
AesGcmEncryptor() { /* ... */ }
void Initialize(const void *key, size_t key_size, const void *iv, size_t iv_size) {
m_aes_impl.Initialize(key, key_size);
m_gcm_impl.Initialize(std::addressof(m_aes_impl), iv, iv_size);
}
void Reset(const void *iv, size_t iv_size) {
m_gcm_impl.Reset(iv, iv_size);
}
size_t Update(void *dst, size_t dst_size, const void *src, size_t src_size) {
return m_gcm_impl.Update(dst, dst_size, src, src_size);
}
void UpdateAad(const void *aad, size_t aad_size) {
return m_gcm_impl.UpdateAad(aad, aad_size);
}
void GetMac(void *dst, size_t dst_size) {
return m_gcm_impl.GetMac(dst, dst_size);
}
};
}
using Aes128GcmEncryptor = impl::AesGcmEncryptor<AesEncryptor128>;
/* TODO: Validate AAD/GMAC is same for non-128 bit key using Aes192GcmEncryptor = impl::AesGcmEncryptor<AesEncryptor192>; */
/* TODO: Validate AAD/GMAC is same for non-128 bit key using Aes256GcmEncryptor = impl::AesGcmEncryptor<AesEncryptor256>; */
}

View File

@@ -1,169 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/crypto_aes_encryptor.hpp>
#include <vapours/crypto/crypto_xts_encryptor.hpp>
#include <vapours/crypto/crypto_xts_decryptor.hpp>
namespace ams::crypto {
namespace impl {
template<template<typename> typename _XtsImpl, typename _AesImpl1, typename _AesImpl2>
class AesXtsCryptor {
NON_COPYABLE(AesXtsCryptor);
NON_MOVEABLE(AesXtsCryptor);
private:
using AesImpl1 = _AesImpl1;
using AesImpl2 = _AesImpl2;
using XtsImpl = _XtsImpl<AesImpl1>;
public:
static constexpr size_t KeySize = AesImpl1::KeySize;
static constexpr size_t BlockSize = AesImpl1::BlockSize;
static constexpr size_t IvSize = AesImpl1::BlockSize;
static_assert(AesImpl1::KeySize == AesImpl2::KeySize);
static_assert(AesImpl1::BlockSize == AesImpl2::BlockSize);
private:
AesImpl1 m_aes_impl_1;
AesImpl2 m_aes_impl_2;
XtsImpl m_xts_impl;
public:
AesXtsCryptor() { /* ... */ }
void Initialize(const void *key1, const void *key2, size_t key_size, const void *iv, size_t iv_size) {
AMS_ASSERT(key_size == KeySize);
AMS_ASSERT(iv_size == IvSize);
m_aes_impl_1.Initialize(key1, key_size);
m_aes_impl_2.Initialize(key2, key_size);
m_xts_impl.Initialize(std::addressof(m_aes_impl_1), std::addressof(m_aes_impl_2), iv, iv_size);
}
size_t Update(void *dst, size_t dst_size, const void *src, size_t src_size) {
return m_xts_impl.Update(dst, dst_size, src, src_size);
}
size_t Finalize(void *dst, size_t dst_size) {
return m_xts_impl.Finalize(dst, dst_size);
}
};
}
using Aes128XtsEncryptor = impl::AesXtsCryptor<XtsEncryptor, AesEncryptor128, AesEncryptor128>;
using Aes192XtsEncryptor = impl::AesXtsCryptor<XtsEncryptor, AesEncryptor192, AesEncryptor192>;
using Aes256XtsEncryptor = impl::AesXtsCryptor<XtsEncryptor, AesEncryptor256, AesEncryptor256>;
using Aes128XtsDecryptor = impl::AesXtsCryptor<XtsDecryptor, AesDecryptor128, AesEncryptor128>;
using Aes192XtsDecryptor = impl::AesXtsCryptor<XtsDecryptor, AesDecryptor192, AesEncryptor192>;
using Aes256XtsDecryptor = impl::AesXtsCryptor<XtsDecryptor, AesDecryptor256, AesEncryptor256>;
inline size_t EncryptAes128Xts(void *dst, size_t dst_size, const void *key1, const void *key2, size_t key_size, const void *iv, size_t iv_size, const void *src, size_t src_size) {
u8 *dst_u8 = static_cast<u8 *>(dst);
const u8 *src_u8 = static_cast<const u8 *>(src);
Aes128XtsEncryptor xts;
xts.Initialize(key1, key2, key_size, iv, iv_size);
size_t processed = xts.Update(dst_u8, dst_size, src_u8, src_size);
dst_u8 += processed;
dst_size -= processed;
processed += xts.Finalize(dst_u8, dst_size);
return processed;
}
inline size_t EncryptAes192Xts(void *dst, size_t dst_size, const void *key1, const void *key2, size_t key_size, const void *iv, size_t iv_size, const void *src, size_t src_size) {
u8 *dst_u8 = static_cast<u8 *>(dst);
const u8 *src_u8 = static_cast<const u8 *>(src);
Aes192XtsEncryptor xts;
xts.Initialize(key1, key2, key_size, iv, iv_size);
size_t processed = xts.Update(dst_u8, dst_size, src_u8, src_size);
dst_u8 += processed;
dst_size -= processed;
processed += xts.Finalize(dst_u8, dst_size);
return processed;
}
inline size_t EncryptAes256Xts(void *dst, size_t dst_size, const void *key1, const void *key2, size_t key_size, const void *iv, size_t iv_size, const void *src, size_t src_size) {
u8 *dst_u8 = static_cast<u8 *>(dst);
const u8 *src_u8 = static_cast<const u8 *>(src);
Aes256XtsEncryptor xts;
xts.Initialize(key1, key2, key_size, iv, iv_size);
size_t processed = xts.Update(dst_u8, dst_size, src_u8, src_size);
dst_u8 += processed;
dst_size -= processed;
processed += xts.Finalize(dst_u8, dst_size);
return processed;
}
inline size_t DecryptAes128Xts(void *dst, size_t dst_size, const void *key1, const void *key2, size_t key_size, const void *iv, size_t iv_size, const void *src, size_t src_size) {
u8 *dst_u8 = static_cast<u8 *>(dst);
const u8 *src_u8 = static_cast<const u8 *>(src);
Aes128XtsDecryptor xts;
xts.Initialize(key1, key2, key_size, iv, iv_size);
size_t processed = xts.Update(dst_u8, dst_size, src_u8, src_size);
dst_u8 += processed;
dst_size -= processed;
processed += xts.Finalize(dst_u8, dst_size);
return processed;
}
inline size_t DecryptAes192Xts(void *dst, size_t dst_size, const void *key1, const void *key2, size_t key_size, const void *iv, size_t iv_size, const void *src, size_t src_size) {
u8 *dst_u8 = static_cast<u8 *>(dst);
const u8 *src_u8 = static_cast<const u8 *>(src);
Aes192XtsDecryptor xts;
xts.Initialize(key1, key2, key_size, iv, iv_size);
size_t processed = xts.Update(dst_u8, dst_size, src_u8, src_size);
dst_u8 += processed;
dst_size -= processed;
processed += xts.Finalize(dst_u8, dst_size);
return processed;
}
inline size_t DecryptAes256Xts(void *dst, size_t dst_size, const void *key1, const void *key2, size_t key_size, const void *iv, size_t iv_size, const void *src, size_t src_size) {
u8 *dst_u8 = static_cast<u8 *>(dst);
const u8 *src_u8 = static_cast<const u8 *>(src);
Aes256XtsDecryptor xts;
xts.Initialize(key1, key2, key_size, iv, iv_size);
size_t processed = xts.Update(dst_u8, dst_size, src_u8, src_size);
dst_u8 += processed;
dst_size -= processed;
processed += xts.Finalize(dst_u8, dst_size);
return processed;
}
}

View File

@@ -1,55 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_cbc_mode_impl.hpp>
namespace ams::crypto {
/* TODO: C++20 BlockCipher concept */
template<typename BlockCipher>
class CbcDecryptor {
NON_COPYABLE(CbcDecryptor);
NON_MOVEABLE(CbcDecryptor);
private:
using Impl = impl::CbcModeImpl<BlockCipher>;
public:
static constexpr size_t KeySize = Impl::KeySize;
static constexpr size_t BlockSize = Impl::BlockSize;
static constexpr size_t IvSize = Impl::IvSize;
private:
Impl m_impl;
public:
CbcDecryptor() { /* ... */ }
void Initialize(const BlockCipher *cipher, const void *iv, size_t iv_size) {
m_impl.Initialize(cipher, iv, iv_size);
}
size_t Update(void *dst, size_t dst_size, const void *src, size_t src_size) {
return m_impl.UpdateDecryption(dst, dst_size, src, src_size);
}
size_t GetBufferedDataSize() const {
return m_impl.GetBufferedDataSize();
}
};
}

View File

@@ -1,55 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_cbc_mode_impl.hpp>
namespace ams::crypto {
/* TODO: C++20 BlockCipher concept */
template<typename BlockCipher>
class CbcEncryptor {
NON_COPYABLE(CbcEncryptor);
NON_MOVEABLE(CbcEncryptor);
private:
using Impl = impl::CbcModeImpl<BlockCipher>;
public:
static constexpr size_t KeySize = Impl::KeySize;
static constexpr size_t BlockSize = Impl::BlockSize;
static constexpr size_t IvSize = Impl::IvSize;
private:
Impl m_impl;
public:
CbcEncryptor() { /* ... */ }
void Initialize(const BlockCipher *cipher, const void *iv, size_t iv_size) {
m_impl.Initialize(cipher, iv, iv_size);
}
size_t Update(void *dst, size_t dst_size, const void *src, size_t src_size) {
return m_impl.UpdateEncryption(dst, dst_size, src, src_size);
}
size_t GetBufferedDataSize() const {
return m_impl.GetBufferedDataSize();
}
};
}

View File

@@ -1,58 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_ccm_mode_impl.hpp>
namespace ams::crypto {
template<typename BlockCipher>
class CcmDecryptor {
NON_COPYABLE(CcmDecryptor);
NON_MOVEABLE(CcmDecryptor);
private:
using Impl = impl::CcmModeImpl<BlockCipher>;
public:
static constexpr size_t KeySize = Impl::KeySize;
static constexpr size_t BlockSize = Impl::BlockSize;
static constexpr size_t MaxMacSize = BlockSize;
static constexpr size_t MaxNonceSize = 13;
private:
Impl m_impl;
public:
CcmDecryptor() { /* ... */ }
void Initialize(const BlockCipher *cipher, const void *nonce, size_t nonce_size, s64 aad_size, s64 data_size, size_t mac_size) {
m_impl.Initialize(cipher, nonce, nonce_size, aad_size, data_size, mac_size);
}
size_t Update(void *dst, size_t dst_size, const void *src, size_t src_size) {
return m_impl.UpdateDecryption(dst, dst_size, src, src_size);
}
void UpdateAad(const void *aad, size_t aad_size) {
return m_impl.UpdateAad(aad, aad_size);
}
void GetMac(void *dst, size_t dst_size) {
return m_impl.GetMac(dst, dst_size);
}
};
}

View File

@@ -1,58 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_ccm_mode_impl.hpp>
namespace ams::crypto {
template<typename BlockCipher>
class CcmEncryptor {
NON_COPYABLE(CcmEncryptor);
NON_MOVEABLE(CcmEncryptor);
private:
using Impl = impl::CcmModeImpl<BlockCipher>;
public:
static constexpr size_t KeySize = Impl::KeySize;
static constexpr size_t BlockSize = Impl::BlockSize;
static constexpr size_t MaxMacSize = BlockSize;
static constexpr size_t MaxNonceSize = 13;
private:
Impl m_impl;
public:
CcmEncryptor() { /* ... */ }
void Initialize(const BlockCipher *cipher, const void *nonce, size_t nonce_size, s64 aad_size, s64 data_size, size_t mac_size) {
m_impl.Initialize(cipher, nonce, nonce_size, aad_size, data_size, mac_size);
}
size_t Update(void *dst, size_t dst_size, const void *src, size_t src_size) {
return m_impl.UpdateEncryption(dst, dst_size, src, src_size);
}
void UpdateAad(const void *aad, size_t aad_size) {
return m_impl.UpdateAad(aad, aad_size);
}
void GetMac(void *dst, size_t dst_size) {
return m_impl.GetMac(dst, dst_size);
}
};
}

View File

@@ -1,51 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_cmac_impl.hpp>
namespace ams::crypto {
template<typename BlockCipher>
class CmacGenerator {
NON_COPYABLE(CmacGenerator);
NON_MOVEABLE(CmacGenerator);
private:
using Impl = impl::CmacImpl<BlockCipher>;
public:
static constexpr size_t MacSize = BlockCipher::BlockSize;
private:
Impl m_impl;
public:
CmacGenerator() { /* ... */ }
void Initialize(const BlockCipher *cipher) {
return m_impl.Initialize(cipher);
}
void Update(const void *data, size_t size) {
return m_impl.Update(data, size);
}
void GetMac(void *dst, size_t dst_size) {
return m_impl.GetMac(dst, dst_size);
}
};
}

View File

@@ -1,26 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
namespace ams::crypto {
void GenerateCryptographicallyRandomBytes(void *dst, size_t dst_size);
}

View File

@@ -1,59 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_ctr_mode_impl.hpp>
namespace ams::crypto {
/* TODO: C++20 BlockCipher concept */
template<typename BlockCipher>
class CtrDecryptor {
NON_COPYABLE(CtrDecryptor);
NON_MOVEABLE(CtrDecryptor);
private:
using Impl = impl::CtrModeImpl<BlockCipher>;
public:
static constexpr size_t KeySize = Impl::KeySize;
static constexpr size_t BlockSize = Impl::BlockSize;
static constexpr size_t IvSize = Impl::IvSize;
private:
Impl m_impl;
public:
CtrDecryptor() { /* ... */ }
void Initialize(const BlockCipher *cipher, const void *iv, size_t iv_size) {
m_impl.Initialize(cipher, iv, iv_size);
}
void Initialize(const BlockCipher *cipher, const void *iv, size_t iv_size, s64 offset) {
m_impl.Initialize(cipher, iv, iv_size, offset);
}
void SwitchMessage(const void *iv, size_t iv_size) {
m_impl.SwitchMessage(iv, iv_size);
}
size_t Update(void *dst, size_t dst_size, const void *src, size_t src_size) {
return m_impl.Update(dst, dst_size, src, src_size);
}
};
}

View File

@@ -1,59 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_ctr_mode_impl.hpp>
namespace ams::crypto {
/* TODO: C++20 BlockCipher concept */
template<typename BlockCipher>
class CtrEncryptor {
NON_COPYABLE(CtrEncryptor);
NON_MOVEABLE(CtrEncryptor);
private:
using Impl = impl::CtrModeImpl<BlockCipher>;
public:
static constexpr size_t KeySize = Impl::KeySize;
static constexpr size_t BlockSize = Impl::BlockSize;
static constexpr size_t IvSize = Impl::IvSize;
private:
Impl m_impl;
public:
CtrEncryptor() { /* ... */ }
void Initialize(const BlockCipher *cipher, const void *iv, size_t iv_size) {
m_impl.Initialize(cipher, iv, iv_size);
}
void Initialize(const BlockCipher *cipher, const void *iv, size_t iv_size, s64 offset) {
m_impl.Initialize(cipher, iv, iv_size, offset);
}
void SwitchMessage(const void *iv, size_t iv_size) {
m_impl.SwitchMessage(iv, iv_size);
}
size_t Update(void *dst, size_t dst_size, const void *src, size_t src_size) {
return m_impl.Update(dst, dst_size, src, src_size);
}
};
}

View File

@@ -1,64 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_gcm_mode_impl.hpp>
namespace ams::crypto {
/* TODO: C++20 BlockCipher concept */
template<typename BlockCipher>
class GcmEncryptor {
NON_COPYABLE(GcmEncryptor);
NON_MOVEABLE(GcmEncryptor);
private:
using Impl = impl::GcmModeImpl<BlockCipher>;
public:
static constexpr size_t KeySize = Impl::KeySize;
static constexpr size_t BlockSize = Impl::BlockSize;
static constexpr size_t MacSize = Impl::MacSize;
private:
Impl m_impl;
public:
GcmEncryptor() { /* ... */ }
void Initialize(const BlockCipher *cipher, const void *iv, size_t iv_size) {
m_impl.Initialize(cipher);
m_impl.Reset(iv, iv_size);
}
void Reset(const void *iv, size_t iv_size) {
m_impl.Reset(iv, iv_size);
}
size_t Update(void *dst, size_t dst_size, const void *src, size_t src_size) {
return m_impl.Update(dst, dst_size, src, src_size);
}
void UpdateAad(const void *aad, size_t aad_size) {
return m_impl.UpdateAad(aad, aad_size);
}
void GetMac(void *dst, size_t dst_size) {
return m_impl.GetMac(dst, dst_size);
}
};
}

View File

@@ -1,51 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_hmac_impl.hpp>
namespace ams::crypto {
template<typename Hash> /* requires HashFunction<Hash> */
class HmacGenerator {
NON_COPYABLE(HmacGenerator);
NON_MOVEABLE(HmacGenerator);
private:
using Impl = impl::HmacImpl<Hash>;
public:
static constexpr size_t HashSize = Impl::HashSize;
static constexpr size_t BlockSize = Impl::BlockSize;
private:
Impl m_impl;
public:
HmacGenerator() { /* ... */ }
void Initialize(const void *key, size_t key_size) {
return m_impl.Initialize(key, key_size);
}
void Update(const void *data, size_t size) {
return m_impl.Update(data, size);
}
void GetMac(void *dst, size_t dst_size) {
return m_impl.GetMac(dst, dst_size);
}
};
}

View File

@@ -1,31 +0,0 @@
/*
* Copyright (c) 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/crypto/crypto_sha1_generator.hpp>
#include <vapours/crypto/crypto_hmac_generator.hpp>
namespace ams::crypto {
using HmacSha1Generator = HmacGenerator<Sha1Generator>;
void GenerateHmacSha1(void *dst, size_t dst_size, const void *data, size_t data_size, const void *key, size_t key_size);
ALWAYS_INLINE void GenerateHmacSha1Mac(void *dst, size_t dst_size, const void *data, size_t data_size, const void *key, size_t key_size) {
return GenerateHmacSha1(dst, dst_size, data, data_size, key, key_size);
}
}

View File

@@ -1,31 +0,0 @@
/*
* Copyright (c) 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/crypto/crypto_sha256_generator.hpp>
#include <vapours/crypto/crypto_hmac_generator.hpp>
namespace ams::crypto {
using HmacSha256Generator = HmacGenerator<Sha256Generator>;
void GenerateHmacSha256(void *dst, size_t dst_size, const void *data, size_t data_size, const void *key, size_t key_size);
ALWAYS_INLINE void GenerateHmacSha256Mac(void *dst, size_t dst_size, const void *data, size_t data_size, const void *key, size_t key_size) {
return GenerateHmacSha256(dst, dst_size, data, data_size, key, key_size);
}
}

View File

@@ -1,67 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_md5_impl.hpp>
namespace ams::crypto {
class Md5Generator {
NON_COPYABLE(Md5Generator);
NON_MOVEABLE(Md5Generator);
private:
using Impl = impl::Md5Impl;
public:
static constexpr size_t HashSize = Impl::HashSize;
static constexpr size_t BlockSize = Impl::BlockSize;
static constexpr inline const u8 Asn1Identifier[] = {
0x30, 0x20, /* Sequence, size 0x20 */
0x30, 0x0C, /* Sequence, size 0x0C */
0x06, 0x08, /* Object Identifier */
0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05, /* MD5 */
0x05, 0x00, /* Null */
0x04, 0x10, /* Octet string, size 0x10 */
};
static constexpr size_t Asn1IdentifierSize = util::size(Asn1Identifier);
private:
Impl m_impl;
public:
Md5Generator() { /* ... */ }
void Initialize() {
m_impl.Initialize();
}
void Update(const void *data, size_t size) {
m_impl.Update(data, size);
}
void GetHash(void *dst, size_t size) {
m_impl.GetHash(dst, size);
}
};
void GenerateMd5(void *dst, size_t dst_size, const void *src, size_t src_size);
ALWAYS_INLINE void GenerateMd5Hash(void *dst, size_t dst_size, const void *src, size_t src_size) {
return GenerateMd5(dst, dst_size, src, src_size);
}
}

View File

@@ -1,26 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
namespace ams::crypto {
void ClearMemory(void *mem, size_t size);
}

View File

@@ -1,26 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
namespace ams::crypto {
bool IsSameBytes(const void *lhs, const void *rhs, size_t size);
}

View File

@@ -1,60 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_bignum.hpp>
namespace ams::crypto {
template<size_t ModulusSize, size_t ExponentSize>
class RsaCalculator {
NON_COPYABLE(RsaCalculator);
NON_MOVEABLE(RsaCalculator);
public:
static constexpr inline size_t RequiredWorkBufferSize = 0x10 * ModulusSize;
private:
impl::StaticBigNum<ModulusSize * BITSIZEOF(u8)> m_modulus;
impl::StaticBigNum<ExponentSize * BITSIZEOF(u8)> m_exponent;
public:
RsaCalculator() { /* ... */ }
~RsaCalculator() { m_exponent.ClearToZero(); }
bool Initialize(const void *mod, size_t mod_size, const void *exp, size_t exp_size) {
if (!m_modulus.Import(mod, mod_size) || m_modulus.IsZero()) {
return false;
}
if (!m_exponent.Import(exp, exp_size) || m_exponent.IsZero()) {
return false;
}
return true;
}
bool ExpMod(void *dst, const void *src, size_t size, void *work_buf, size_t work_buf_size) {
AMS_ASSERT(work_buf_size >= RequiredWorkBufferSize);
return m_modulus.ExpMod(dst, src, size, m_exponent, static_cast<u32 *>(work_buf), work_buf_size);
}
bool ExpMod(void *dst, const void *src, size_t size) {
u32 work_buf[RequiredWorkBufferSize / sizeof(u32)];
return this->ExpMod(dst, src, size, work_buf, sizeof(work_buf));
}
};
}

View File

@@ -1,140 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/crypto_rsa_calculator.hpp>
#include <vapours/crypto/impl/crypto_rsa_oaep_impl.hpp>
namespace ams::crypto {
template<size_t ModulusSize, typename Hash> requires impl::HashFunction<Hash>
class RsaOaepDecryptor {
NON_COPYABLE(RsaOaepDecryptor);
NON_MOVEABLE(RsaOaepDecryptor);
public:
static constexpr size_t HashSize = Hash::HashSize;
static constexpr size_t BlockSize = ModulusSize;
static constexpr size_t MaximumExponentSize = ModulusSize;
static constexpr size_t RequiredWorkBufferSize = RsaCalculator<ModulusSize, MaximumExponentSize>::RequiredWorkBufferSize;
private:
enum class State {
None,
Initialized,
Done,
};
private:
RsaCalculator<ModulusSize, MaximumExponentSize> m_calculator;
Hash m_hash;
bool m_set_label_digest;
u8 m_label_digest[HashSize];
State m_state;
public:
RsaOaepDecryptor() : m_set_label_digest(false), m_state(State::None) { std::memset(m_label_digest, 0, sizeof(m_label_digest)); }
~RsaOaepDecryptor() {
ClearMemory(m_label_digest, sizeof(m_label_digest));
}
bool Initialize(const void *mod, size_t mod_size, const void *exp, size_t exp_size) {
m_hash.Initialize();
m_set_label_digest = false;
if (m_calculator.Initialize(mod, mod_size, exp, exp_size)) {
m_state = State::Initialized;
return true;
} else {
return false;
}
}
void UpdateLabel(const void *data, size_t size) {
AMS_ASSERT(m_state == State::Initialized);
m_hash.Update(data, size);
}
void SetLabelDigest(const void *digest, size_t digest_size) {
AMS_ASSERT(m_state == State::Initialized);
AMS_ABORT_UNLESS(digest_size == sizeof(m_label_digest));
std::memcpy(m_label_digest, digest, digest_size);
m_set_label_digest = true;
}
size_t Decrypt(void *dst, size_t dst_size, const void *src, size_t src_size) {
AMS_ASSERT(m_state == State::Initialized);
impl::RsaOaepImpl<Hash> impl;
u8 message[BlockSize];
ON_SCOPE_EXIT { ClearMemory(message, sizeof(message)); };
if (!m_calculator.ExpMod(message, src, src_size)) {
std::memset(dst, 0, dst_size);
return false;
}
if (!m_set_label_digest) {
m_hash.GetHash(m_label_digest, sizeof(m_label_digest));
}
ON_SCOPE_EXIT { m_state = State::Done; };
return impl.Decode(dst, dst_size, m_label_digest, sizeof(m_label_digest), message, sizeof(message));
}
size_t Decrypt(void *dst, size_t dst_size, const void *src, size_t src_size, void *work_buf, size_t work_buf_size) {
AMS_ASSERT(m_state == State::Initialized);
ON_SCOPE_EXIT { m_state = State::Done; };
impl::RsaOaepImpl<Hash> impl;
u8 message[BlockSize];
ON_SCOPE_EXIT { ClearMemory(message, sizeof(message)); };
if (!m_calculator.ExpMod(message, src, src_size, work_buf, work_buf_size)) {
return false;
}
if (!m_set_label_digest) {
m_hash.GetHash(m_label_digest, sizeof(m_label_digest));
m_set_label_digest = true;
}
return impl.Decode(dst, dst_size, m_label_digest, sizeof(m_label_digest), message, sizeof(message));
}
static size_t Decrypt(void *dst, size_t dst_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size, const void *lab, size_t lab_size) {
RsaOaepDecryptor<ModulusSize, Hash> crypt;
if (!crypt.Initialize(mod, mod_size, exp, exp_size)) {
return 0;
}
crypt.UpdateLabel(lab, lab_size);
return crypt.Decrypt(dst, dst_size, msg, msg_size);
}
static size_t Decrypt(void *dst, size_t dst_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size, const void *lab, size_t lab_size, void *work_buf, size_t work_buf_size) {
RsaOaepDecryptor<ModulusSize, Hash> crypt;
if (!crypt.Initialize(mod, mod_size, exp, exp_size)) {
return 0;
}
crypt.UpdateLabel(lab, lab_size);
return crypt.Decrypt(dst, dst_size, msg, msg_size, work_buf, work_buf_size);
}
};
}

View File

@@ -1,137 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/crypto_rsa_calculator.hpp>
#include <vapours/crypto/impl/crypto_rsa_oaep_impl.hpp>
namespace ams::crypto {
template<size_t ModulusSize, typename Hash> requires impl::HashFunction<Hash>
class RsaOaepEncryptor {
NON_COPYABLE(RsaOaepEncryptor);
NON_MOVEABLE(RsaOaepEncryptor);
public:
static constexpr size_t HashSize = Hash::HashSize;
static constexpr size_t BlockSize = ModulusSize;
static constexpr size_t MaximumExponentSize = 3;
static constexpr size_t RequiredWorkBufferSize = RsaCalculator<ModulusSize, MaximumExponentSize>::RequiredWorkBufferSize;
private:
enum class State {
None,
Initialized,
Done,
};
private:
RsaCalculator<ModulusSize, MaximumExponentSize> m_calculator;
Hash m_hash;
bool m_set_label_digest;
u8 m_label_digest[HashSize];
State m_state;
public:
RsaOaepEncryptor() : m_set_label_digest(false), m_state(State::None) { std::memset(m_label_digest, 0, sizeof(m_label_digest)); }
~RsaOaepEncryptor() {
ClearMemory(m_label_digest, sizeof(m_label_digest));
}
bool Initialize(const void *mod, size_t mod_size, const void *exp, size_t exp_size) {
m_hash.Initialize();
m_set_label_digest = false;
if (m_calculator.Initialize(mod, mod_size, exp, exp_size)) {
m_state = State::Initialized;
return true;
} else {
return false;
}
}
void UpdateLabel(const void *data, size_t size) {
AMS_ASSERT(m_state == State::Initialized);
m_hash.Update(data, size);
}
void SetLabelDigest(const void *digest, size_t digest_size) {
AMS_ASSERT(m_state == State::Initialized);
AMS_ABORT_UNLESS(digest_size == sizeof(m_label_digest));
std::memcpy(m_label_digest, digest, digest_size);
m_set_label_digest = true;
}
bool Encrypt(void *dst, size_t dst_size, const void *src, size_t src_size, const void *salt, size_t salt_size) {
AMS_ASSERT(m_state == State::Initialized);
impl::RsaOaepImpl<Hash> impl;
if (!m_set_label_digest) {
m_hash.GetHash(m_label_digest, sizeof(m_label_digest));
}
impl.Encode(dst, dst_size, m_label_digest, sizeof(m_label_digest), src, src_size, salt, salt_size);
if (!m_calculator.ExpMod(dst, dst, dst_size)) {
std::memset(dst, 0, dst_size);
return false;
}
m_state = State::Done;
return true;
}
bool Encrypt(void *dst, size_t dst_size, const void *src, size_t src_size, const void *salt, size_t salt_size, void *work, size_t work_size) {
AMS_ASSERT(m_state == State::Initialized);
impl::RsaOaepImpl<Hash> impl;
if (!m_set_label_digest) {
m_hash.GetHash(m_label_digest, sizeof(m_label_digest));
}
impl.Encode(dst, dst_size, m_label_digest, sizeof(m_label_digest), src, src_size, salt, salt_size);
if (!m_calculator.ExpMod(dst, dst, dst_size, work, work_size)) {
std::memset(dst, 0, dst_size);
return false;
}
m_state = State::Done;
return true;
}
static bool Encrypt(void *dst, size_t dst_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size, const void *seed, size_t seed_size, const void *lab, size_t lab_size) {
RsaOaepEncryptor<ModulusSize, Hash> oaep;
if (!oaep.Initialize(mod, mod_size, exp, exp_size)) {
return false;
}
oaep.UpdateLabel(lab, lab_size);
return oaep.Encrypt(dst, dst_size, msg, msg_size, seed, seed_size);
}
static bool Encrypt(void *dst, size_t dst_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size, const void *seed, size_t seed_size, const void *lab, size_t lab_size, void *work, size_t work_size) {
RsaOaepEncryptor<ModulusSize, Hash> oaep;
if (!oaep.Initialize(mod, mod_size, exp, exp_size)) {
return false;
}
oaep.UpdateLabel(lab, lab_size);
return oaep.Encrypt(dst, dst_size, msg, msg_size, seed, seed_size, work, work_size);
}
};
}

View File

@@ -1,50 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_rsa_oaep_impl.hpp>
#include <vapours/crypto/crypto_sha256_generator.hpp>
namespace ams::crypto {
inline size_t DecodeRsa2048OaepSha256(void *dst, size_t dst_size, const void *label_digest, size_t label_digest_size, const void *src, size_t src_size) {
constexpr size_t BlockSize = 2048 / BITSIZEOF(u8);
AMS_ABORT_UNLESS(src_size == BlockSize);
impl::RsaOaepImpl<Sha256Generator> oaep;
u8 enc[BlockSize];
ON_SCOPE_EXIT { ClearMemory(enc, sizeof(enc)); };
std::memcpy(enc, src, src_size);
return oaep.Decode(dst, dst_size, label_digest, label_digest_size, enc, sizeof(enc));
}
inline size_t DecodeRsa4096OaepSha256(void *dst, size_t dst_size, const void *label_digest, size_t label_digest_size, const void *src, size_t src_size) {
constexpr size_t BlockSize = 4096 / BITSIZEOF(u8);
AMS_ABORT_UNLESS(src_size == BlockSize);
impl::RsaOaepImpl<Sha256Generator> oaep;
u8 enc[BlockSize];
ON_SCOPE_EXIT { ClearMemory(enc, sizeof(enc)); };
std::memcpy(enc, src, src_size);
return oaep.Decode(dst, dst_size, label_digest, label_digest_size, enc, sizeof(enc));
}
}

View File

@@ -1,53 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/crypto_rsa_calculator.hpp>
#include <vapours/crypto/crypto_rsa_oaep_decryptor.hpp>
#include <vapours/crypto/crypto_sha256_generator.hpp>
namespace ams::crypto {
namespace impl {
template<size_t Bits>
using RsaNOaepSha256Decryptor = ::ams::crypto::RsaOaepDecryptor<Bits / BITSIZEOF(u8), ::ams::crypto::Sha256Generator>;
}
using Rsa2048OaepSha256Decryptor = ::ams::crypto::impl::RsaNOaepSha256Decryptor<2048>;
using Rsa4096OaepSha256Decryptor = ::ams::crypto::impl::RsaNOaepSha256Decryptor<4096>;
inline size_t DecryptRsa2048OaepSha256(void *dst, size_t dst_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size, const void *lab, size_t lab_size) {
return Rsa2048OaepSha256Decryptor::Decrypt(dst, dst_size, mod, mod_size, exp, exp_size, msg, msg_size, lab, lab_size);
}
inline size_t DecryptRsa2048OaepSha256(void *dst, size_t dst_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size, const void *lab, size_t lab_size, void *work_buf, size_t work_buf_size) {
return Rsa2048OaepSha256Decryptor::Decrypt(dst, dst_size, mod, mod_size, exp, exp_size, msg, msg_size, lab, lab_size, work_buf, work_buf_size);
}
inline size_t DecryptRsa4096OaepSha256(void *dst, size_t dst_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size, const void *lab, size_t lab_size) {
return Rsa4096OaepSha256Decryptor::Decrypt(dst, dst_size, mod, mod_size, exp, exp_size, msg, msg_size, lab, lab_size);
}
inline size_t DecryptRsa4096OaepSha256(void *dst, size_t dst_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size, const void *lab, size_t lab_size, void *work_buf, size_t work_buf_size) {
return Rsa4096OaepSha256Decryptor::Decrypt(dst, dst_size, mod, mod_size, exp, exp_size, msg, msg_size, lab, lab_size, work_buf, work_buf_size);
}
}

View File

@@ -1,53 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/crypto_rsa_calculator.hpp>
#include <vapours/crypto/crypto_rsa_oaep_encryptor.hpp>
#include <vapours/crypto/crypto_sha256_generator.hpp>
namespace ams::crypto {
namespace impl {
template<size_t Bits>
using RsaNOaepSha256Encryptor = ::ams::crypto::RsaOaepEncryptor<Bits / BITSIZEOF(u8), ::ams::crypto::Sha256Generator>;
}
using Rsa2048OaepSha256Encryptor = ::ams::crypto::impl::RsaNOaepSha256Encryptor<2048>;
using Rsa4096OaepSha256Encryptor = ::ams::crypto::impl::RsaNOaepSha256Encryptor<4096>;
inline size_t EncryptRsa2048OaepSha256(void *dst, size_t dst_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size, const void *salt, size_t salt_size, const void *lab, size_t lab_size) {
return Rsa2048OaepSha256Encryptor::Encrypt(dst, dst_size, mod, mod_size, exp, exp_size, msg, msg_size, salt, salt_size, lab, lab_size);
}
inline size_t EncryptRsa2048OaepSha256(void *dst, size_t dst_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size, const void *salt, size_t salt_size, const void *lab, size_t lab_size, void *work_buf, size_t work_buf_size) {
return Rsa2048OaepSha256Encryptor::Encrypt(dst, dst_size, mod, mod_size, exp, exp_size, msg, msg_size, salt, salt_size, lab, lab_size, work_buf, work_buf_size);
}
inline size_t EncryptRsa4096OaepSha256(void *dst, size_t dst_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size, const void *salt, size_t salt_size, const void *lab, size_t lab_size) {
return Rsa4096OaepSha256Encryptor::Encrypt(dst, dst_size, mod, mod_size, exp, exp_size, msg, msg_size, salt, salt_size, lab, lab_size);
}
inline size_t EncryptRsa4096OaepSha256(void *dst, size_t dst_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size, const void *salt, size_t salt_size, const void *lab, size_t lab_size, void *work_buf, size_t work_buf_size) {
return Rsa4096OaepSha256Encryptor::Encrypt(dst, dst_size, mod, mod_size, exp, exp_size, msg, msg_size, salt, salt_size, lab, lab_size, work_buf, work_buf_size);
}
}

View File

@@ -1,53 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/crypto_rsa_calculator.hpp>
#include <vapours/crypto/crypto_rsa_pkcs1_verifier.hpp>
#include <vapours/crypto/crypto_sha256_generator.hpp>
namespace ams::crypto {
namespace impl {
template<size_t Bits>
using RsaNPkcs1Sha256Verifier = ::ams::crypto::RsaPkcs1Verifier<Bits / BITSIZEOF(u8), ::ams::crypto::Sha256Generator>;
}
using Rsa2048Pkcs1Sha256Verifier = ::ams::crypto::impl::RsaNPkcs1Sha256Verifier<2048>;
using Rsa4096Pkcs1Sha256Verifier = ::ams::crypto::impl::RsaNPkcs1Sha256Verifier<4096>;
inline bool VerifyRsa2048Pkcs1Sha256(const void *sig, size_t sig_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size) {
return Rsa2048Pkcs1Sha256Verifier::Verify(sig, sig_size, mod, mod_size, exp, exp_size, msg, msg_size);
}
inline bool VerifyRsa2048Pkcs1Sha256(const void *sig, size_t sig_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size, void *work_buf, size_t work_buf_size) {
return Rsa2048Pkcs1Sha256Verifier::Verify(sig, sig_size, mod, mod_size, exp, exp_size, msg, msg_size, work_buf, work_buf_size);
}
inline bool VerifyRsa4096Pkcs1Sha256(const void *sig, size_t sig_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size) {
return Rsa4096Pkcs1Sha256Verifier::Verify(sig, sig_size, mod, mod_size, exp, exp_size, msg, msg_size);
}
inline bool VerifyRsa4096Pkcs1Sha256(const void *sig, size_t sig_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size, void *work_buf, size_t work_buf_size) {
return Rsa4096Pkcs1Sha256Verifier::Verify(sig, sig_size, mod, mod_size, exp, exp_size, msg, msg_size, work_buf, work_buf_size);
}
}

View File

@@ -1,115 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/crypto_rsa_calculator.hpp>
#include <vapours/crypto/impl/crypto_rsa_pkcs1_impl.hpp>
namespace ams::crypto {
template<size_t _ModulusSize, impl::HashFunction Hash>
class RsaPkcs1Verifier {
NON_COPYABLE(RsaPkcs1Verifier);
NON_MOVEABLE(RsaPkcs1Verifier);
public:
static constexpr size_t HashSize = Hash::HashSize;
static constexpr size_t ModulusSize = _ModulusSize;
static constexpr size_t SignatureSize = ModulusSize;
static constexpr size_t MaximumExponentSize = 3;
static constexpr size_t RequiredWorkBufferSize = RsaCalculator<ModulusSize, MaximumExponentSize>::RequiredWorkBufferSize;
private:
enum class State {
None,
Initialized,
Done,
};
private:
RsaCalculator<ModulusSize, MaximumExponentSize> m_calculator;
Hash m_hash;
State m_state;
public:
RsaPkcs1Verifier() : m_state(State::None) { /* ... */ }
bool Initialize(const void *mod, size_t mod_size, const void *exp, size_t exp_size) {
m_hash.Initialize();
if (m_calculator.Initialize(mod, mod_size, exp, exp_size)) {
m_state = State::Initialized;
return true;
} else {
return false;
}
}
void Update(const void *data, size_t size) {
AMS_ASSERT(m_state == State::Initialized);
return m_hash.Update(data, size);
}
bool Verify(const void *signature, size_t size) {
AMS_ASSERT(m_state == State::Initialized);
AMS_ASSERT(size == SignatureSize);
AMS_UNUSED(size);
ON_SCOPE_EXIT { m_state = State::Done; };
impl::RsaPkcs1Impl<Hash> impl;
u8 message[SignatureSize];
return m_calculator.ExpMod(message, signature, SignatureSize) && impl.CheckPad(message, sizeof(message), std::addressof(m_hash));
}
bool Verify(const void *signature, size_t size, void *work_buf, size_t work_buf_size) {
AMS_ASSERT(m_state == State::Initialized);
AMS_ASSERT(size == SignatureSize);
AMS_UNUSED(size);
ON_SCOPE_EXIT { m_state = State::Done; };
impl::RsaPkcs1Impl<Hash> impl;
u8 message[SignatureSize];
return m_calculator.ExpMod(message, signature, SignatureSize, work_buf, work_buf_size) && impl.CheckPad(message, sizeof(message), std::addressof(m_hash));
}
void GetHash(void *dst, size_t dst_size) {
AMS_ASSERT(m_state == State::Done);
if (m_state == State::Done) {
m_hash.GetHash(dst, dst_size);
}
}
static bool Verify(const void *sig, size_t sig_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size) {
RsaPkcs1Verifier<ModulusSize, Hash> verifier;
if (!verifier.Initialize(mod, mod_size, exp, exp_size)) {
return false;
}
verifier.Update(msg, msg_size);
return verifier.Verify(sig, sig_size);
}
static bool Verify(const void *sig, size_t sig_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size, void *work_buf, size_t work_buf_size) {
RsaPkcs1Verifier<ModulusSize, Hash> verifier;
if (!verifier.Initialize(mod, mod_size, exp, exp_size)) {
return false;
}
verifier.Update(msg, msg_size);
return verifier.Verify(sig, sig_size, work_buf, work_buf_size);
}
};
}

View File

@@ -1,69 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/crypto_rsa_calculator.hpp>
#include <vapours/crypto/crypto_rsa_pss_verifier.hpp>
#include <vapours/crypto/crypto_sha256_generator.hpp>
namespace ams::crypto {
namespace impl {
template<size_t Bits>
using RsaNPssSha256Verifier = ::ams::crypto::RsaPssVerifier<Bits / BITSIZEOF(u8), ::ams::crypto::Sha256Generator>;
}
using Rsa2048PssSha256Verifier = ::ams::crypto::impl::RsaNPssSha256Verifier<2048>;
using Rsa4096PssSha256Verifier = ::ams::crypto::impl::RsaNPssSha256Verifier<4096>;
inline bool VerifyRsa2048PssSha256(const void *sig, size_t sig_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size) {
return Rsa2048PssSha256Verifier::Verify(sig, sig_size, mod, mod_size, exp, exp_size, msg, msg_size);
}
inline bool VerifyRsa2048PssSha256(const void *sig, size_t sig_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size, void *work_buf, size_t work_buf_size) {
return Rsa2048PssSha256Verifier::Verify(sig, sig_size, mod, mod_size, exp, exp_size, msg, msg_size, work_buf, work_buf_size);
}
inline bool VerifyRsa2048PssSha256WithHash(const void *sig, size_t sig_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *hash, size_t hash_size) {
return Rsa2048PssSha256Verifier::VerifyWithHash(sig, sig_size, mod, mod_size, exp, exp_size, hash, hash_size);
}
inline bool VerifyRsa2048PssSha256WithHash(const void *sig, size_t sig_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *hash, size_t hash_size, void *work_buf, size_t work_buf_size) {
return Rsa2048PssSha256Verifier::VerifyWithHash(sig, sig_size, mod, mod_size, exp, exp_size, hash, hash_size, work_buf, work_buf_size);
}
inline bool VerifyRsa4096PssSha256(const void *sig, size_t sig_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size) {
return Rsa4096PssSha256Verifier::Verify(sig, sig_size, mod, mod_size, exp, exp_size, msg, msg_size);
}
inline bool VerifyRsa4096PssSha256(const void *sig, size_t sig_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size, void *work_buf, size_t work_buf_size) {
return Rsa4096PssSha256Verifier::Verify(sig, sig_size, mod, mod_size, exp, exp_size, msg, msg_size, work_buf, work_buf_size);
}
inline bool VerifyRsa4096PssSha256WithHash(const void *sig, size_t sig_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *hash, size_t hash_size) {
return Rsa4096PssSha256Verifier::VerifyWithHash(sig, sig_size, mod, mod_size, exp, exp_size, hash, hash_size);
}
inline bool VerifyRsa4096PssSha256WithHash(const void *sig, size_t sig_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *hash, size_t hash_size, void *work_buf, size_t work_buf_size) {
return Rsa4096PssSha256Verifier::VerifyWithHash(sig, sig_size, mod, mod_size, exp, exp_size, hash, hash_size, work_buf, work_buf_size);
}
}

View File

@@ -1,177 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/crypto_rsa_calculator.hpp>
#include <vapours/crypto/impl/crypto_rsa_pss_impl.hpp>
namespace ams::crypto {
template<size_t _ModulusSize, typename Hash> requires impl::HashFunction<Hash>
class RsaPssVerifier {
NON_COPYABLE(RsaPssVerifier);
NON_MOVEABLE(RsaPssVerifier);
public:
static constexpr size_t HashSize = Hash::HashSize;
static constexpr size_t SaltSize = Hash::HashSize;
static constexpr size_t ModulusSize = _ModulusSize;
static constexpr size_t SignatureSize = ModulusSize;
static constexpr size_t MaximumExponentSize = 3;
static constexpr size_t RequiredWorkBufferSize = RsaCalculator<ModulusSize, MaximumExponentSize>::RequiredWorkBufferSize;
private:
enum class State {
None,
Initialized,
Done,
};
private:
RsaCalculator<ModulusSize, MaximumExponentSize> m_calculator;
Hash m_hash;
State m_state;
public:
RsaPssVerifier() : m_state(State::None) { /* ... */ }
~RsaPssVerifier() { }
bool Initialize(const void *mod, size_t mod_size, const void *exp, size_t exp_size) {
m_hash.Initialize();
if (m_calculator.Initialize(mod, mod_size, exp, exp_size)) {
m_state = State::Initialized;
return true;
} else {
return false;
}
}
void Update(const void *data, size_t size) {
AMS_ASSERT(m_state == State::Initialized);
return m_hash.Update(data, size);
}
bool Verify(const void *signature, size_t size) {
AMS_ASSERT(m_state == State::Initialized);
AMS_ASSERT(size == SignatureSize);
AMS_UNUSED(size);
ON_SCOPE_EXIT { m_state = State::Done; };
impl::RsaPssImpl<Hash> impl;
u8 message[SignatureSize];
ON_SCOPE_EXIT { ClearMemory(message, sizeof(message)); };
if (!m_calculator.ExpMod(message, signature, SignatureSize)) {
return false;
}
u8 calc_hash[Hash::HashSize];
m_hash.GetHash(calc_hash, sizeof(calc_hash));
ON_SCOPE_EXIT { ClearMemory(calc_hash, sizeof(calc_hash)); };
return impl.Verify(message, sizeof(message), calc_hash, sizeof(calc_hash));
}
bool Verify(const void *signature, size_t size, void *work_buf, size_t work_buf_size) {
AMS_ASSERT(m_state == State::Initialized);
AMS_ASSERT(size == SignatureSize);
AMS_UNUSED(size);
ON_SCOPE_EXIT { m_state = State::Done; };
impl::RsaPssImpl<Hash> impl;
u8 message[SignatureSize];
ON_SCOPE_EXIT { ClearMemory(message, sizeof(message)); };
if (!m_calculator.ExpMod(message, signature, SignatureSize, work_buf, work_buf_size)) {
return false;
}
u8 calc_hash[Hash::HashSize];
m_hash.GetHash(calc_hash, sizeof(calc_hash));
ON_SCOPE_EXIT { ClearMemory(calc_hash, sizeof(calc_hash)); };
return impl.Verify(message, sizeof(message), calc_hash, sizeof(calc_hash));
}
bool VerifyWithHash(const void *signature, size_t size, const void *hash, size_t hash_size) {
AMS_ASSERT(m_state == State::Initialized);
AMS_ASSERT(size == SignatureSize);
AMS_UNUSED(size);
ON_SCOPE_EXIT { m_state = State::Done; };
impl::RsaPssImpl<Hash> impl;
u8 message[SignatureSize];
ON_SCOPE_EXIT { ClearMemory(message, sizeof(message)); };
if (!m_calculator.ExpMod(message, signature, SignatureSize)) {
return false;
}
return impl.Verify(message, sizeof(message), static_cast<const u8 *>(hash), hash_size);
}
bool VerifyWithHash(const void *signature, size_t size, const void *hash, size_t hash_size, void *work_buf, size_t work_buf_size) {
AMS_ASSERT(m_state == State::Initialized);
AMS_ASSERT(size == SignatureSize);
AMS_UNUSED(size);
ON_SCOPE_EXIT { m_state = State::Done; };
impl::RsaPssImpl<Hash> impl;
u8 message[SignatureSize];
ON_SCOPE_EXIT { ClearMemory(message, sizeof(message)); };
if (!m_calculator.ExpMod(message, signature, SignatureSize, work_buf, work_buf_size)) {
return false;
}
return impl.Verify(message, sizeof(message), static_cast<const u8 *>(hash), hash_size);
}
static bool Verify(const void *sig, size_t sig_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size) {
RsaPssVerifier<ModulusSize, Hash> verifier;
if (!verifier.Initialize(mod, mod_size, exp, exp_size)) {
return false;
}
verifier.Update(msg, msg_size);
return verifier.Verify(sig, sig_size);
}
static bool Verify(const void *sig, size_t sig_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size, void *work_buf, size_t work_buf_size) {
RsaPssVerifier<ModulusSize, Hash> verifier;
if (!verifier.Initialize(mod, mod_size, exp, exp_size)) {
return false;
}
verifier.Update(msg, msg_size);
return verifier.Verify(sig, sig_size, work_buf, work_buf_size);
}
static bool VerifyWithHash(const void *sig, size_t sig_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *hash, size_t hash_size) {
RsaPssVerifier<ModulusSize, Hash> verifier;
if (!verifier.Initialize(mod, mod_size, exp, exp_size)) {
return false;
}
return verifier.VerifyWithHash(sig, sig_size, hash, hash_size);
}
static bool VerifyWithHash(const void *sig, size_t sig_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *hash, size_t hash_size, void *work_buf, size_t work_buf_size) {
RsaPssVerifier<ModulusSize, Hash> verifier;
if (!verifier.Initialize(mod, mod_size, exp, exp_size)) {
return false;
}
return verifier.VerifyWithHash(sig, sig_size, hash, hash_size, work_buf, work_buf_size);
}
};
}

View File

@@ -1,67 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_sha1_impl.hpp>
namespace ams::crypto {
class Sha1Generator {
NON_COPYABLE(Sha1Generator);
NON_MOVEABLE(Sha1Generator);
private:
using Impl = impl::Sha1Impl;
public:
static constexpr size_t HashSize = Impl::HashSize;
static constexpr size_t BlockSize = Impl::BlockSize;
static constexpr inline u8 Asn1Identifier[] = {
0x30, 0x21, /* Sequence, size 0x21 */
0x30, 0x09, /* Sequence, size 0x09 */
0x06, 0x05, /* Object Identifier */
0x2B, 0x0E, 0x03, 0x02, 0x1A, /* SHA-1 */
0x05, 0x00, /* Null */
0x04, 0x14, /* Octet string, size 0x14 */
};
static constexpr size_t Asn1IdentifierSize = util::size(Asn1Identifier);
private:
Impl m_impl;
public:
Sha1Generator() { /* ... */ }
void Initialize() {
m_impl.Initialize();
}
void Update(const void *data, size_t size) {
m_impl.Update(data, size);
}
void GetHash(void *dst, size_t size) {
m_impl.GetHash(dst, size);
}
};
void GenerateSha1(void *dst, size_t dst_size, const void *src, size_t src_size);
ALWAYS_INLINE void GenerateSha1Hash(void *dst, size_t dst_size, const void *src, size_t src_size) {
return GenerateSha1(dst, dst_size, src, src_size);
}
}

View File

@@ -1,101 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_sha256_impl.hpp>
#include <vapours/crypto/impl/crypto_sha256_impl_constexpr.hpp>
namespace ams::crypto {
struct Sha256Context {
u32 intermediate_hash[impl::Sha256Impl::HashSize / sizeof(u32)];
u64 bits_consumed;
};
class Sha256Generator {
NON_COPYABLE(Sha256Generator);
NON_MOVEABLE(Sha256Generator);
private:
using Impl = impl::Sha256Impl;
public:
static constexpr size_t HashSize = Impl::HashSize;
static constexpr size_t BlockSize = Impl::BlockSize;
static constexpr inline u8 Asn1Identifier[] = {
0x30, 0x31, /* Sequence, size 0x31 */
0x30, 0x0D, /* Sequence, size 0x0D */
0x06, 0x09, /* Object Identifier */
0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, /* SHA-256 */
0x05, 0x00, /* Null */
0x04, 0x20, /* Octet string, size 0x20 */
};
static constexpr size_t Asn1IdentifierSize = util::size(Asn1Identifier);
private:
Impl m_impl{};
public:
Sha256Generator() = default;
void Initialize() {
m_impl.Initialize();
}
void Update(const void *data, size_t size) {
m_impl.Update(data, size);
}
void GetHash(void *dst, size_t size) {
m_impl.GetHash(dst, size);
}
void InitializeWithContext(const Sha256Context *context) {
m_impl.InitializeWithContext(context);
}
size_t GetContext(Sha256Context *context) const {
return m_impl.GetContext(context);
}
size_t GetBufferedDataSize() const {
return m_impl.GetBufferedDataSize();
}
void GetBufferedData(void *dst, size_t dst_size) const {
return m_impl.GetBufferedData(dst, dst_size);
}
};
void GenerateSha256(void *dst, size_t dst_size, const void *src, size_t src_size);
ALWAYS_INLINE void GenerateSha256Hash(void *dst, size_t dst_size, const void *src, size_t src_size) {
return GenerateSha256(dst, dst_size, src, src_size);
}
template<typename T, typename = typename std::enable_if<std::same_as<T, u8> || std::same_as<T, s8> || std::same_as<T, char> || std::same_as<T, unsigned char>>::type>
constexpr ALWAYS_INLINE void GenerateSha256(u8 *dst, size_t dst_size, const T *src, size_t src_size) {
if (std::is_constant_evaluated()) {
impl::Sha256CompileTimeImpl sha;
sha.Initialize();
sha.Update(src, src_size);
sha.GetHash(dst, dst_size);
} else {
return GenerateSha256(static_cast<void *>(dst), dst_size, static_cast<const void *>(src), src_size);
}
}
}

View File

@@ -1,125 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_sha3_impl.hpp>
namespace ams::crypto {
struct Sha3Context {
u32 hash_size;
u32 buffered_bytes;
u64 internal_state[25];
};
namespace impl {
template<size_t HashSize>
struct Sha3Asn1IdentifierByte;
template<> struct Sha3Asn1IdentifierByte<224 / BITSIZEOF(u8)> { static constexpr u8 Value = 0x07; };
template<> struct Sha3Asn1IdentifierByte<256 / BITSIZEOF(u8)> { static constexpr u8 Value = 0x08; };
template<> struct Sha3Asn1IdentifierByte<384 / BITSIZEOF(u8)> { static constexpr u8 Value = 0x09; };
template<> struct Sha3Asn1IdentifierByte<512 / BITSIZEOF(u8)> { static constexpr u8 Value = 0x0A; };
}
template <size_t _HashSize>
class Sha3Generator {
NON_COPYABLE(Sha3Generator);
NON_MOVEABLE(Sha3Generator);
private:
using Impl = impl::Sha3Impl<_HashSize>;
public:
static constexpr size_t HashSize = Impl::HashSize;
static constexpr size_t BlockSize = Impl::BlockSize;
static constexpr inline u8 Asn1Identifier[] = {
0x30, 0x31, /* Sequence, size 0x31 */
0x30, 0x0D, /* Sequence, size 0x0D */
0x06, 0x09, /* Object Identifier */
0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, impl::Sha3Asn1IdentifierByte<HashSize>::Value, /* SHA3-*** */
0x05, 0x00, /* Null */
0x04, 0x20, /* Octet string, size 0x20 */
};
static constexpr size_t Asn1IdentifierSize = util::size(Asn1Identifier);
private:
Impl m_impl;
public:
Sha3Generator() { /* ... */ }
void Initialize() {
m_impl.Initialize();
}
void Update(const void *data, size_t size) {
m_impl.Update(data, size);
}
void GetHash(void *dst, size_t size) {
m_impl.GetHash(dst, size);
}
void InitializeWithContext(const Sha3Context *context) {
m_impl.InitializeWithContext(context);
}
void GetContext(Sha3Context *context) const {
m_impl.GetContext(context);
}
};
using Sha3224Generator = Sha3Generator<224 / BITSIZEOF(u8)>;
using Sha3256Generator = Sha3Generator<256 / BITSIZEOF(u8)>;
using Sha3384Generator = Sha3Generator<384 / BITSIZEOF(u8)>;
using Sha3512Generator = Sha3Generator<512 / BITSIZEOF(u8)>;
inline void GenerateSha3224(void *dst, size_t dst_size, const void *src, size_t src_size) {
Sha3224Generator generator;
generator.Initialize();
generator.Update(src, src_size);
generator.GetHash(dst, dst_size);
}
inline void GenerateSha3256(void *dst, size_t dst_size, const void *src, size_t src_size) {
Sha3256Generator generator;
generator.Initialize();
generator.Update(src, src_size);
generator.GetHash(dst, dst_size);
}
inline void GenerateSha3384(void *dst, size_t dst_size, const void *src, size_t src_size) {
Sha3384Generator generator;
generator.Initialize();
generator.Update(src, src_size);
generator.GetHash(dst, dst_size);
}
inline void GenerateSha3512(void *dst, size_t dst_size, const void *src, size_t src_size) {
Sha3512Generator generator;
generator.Initialize();
generator.Update(src, src_size);
generator.GetHash(dst, dst_size);
}
}

View File

@@ -1,55 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_xts_mode_impl.hpp>
namespace ams::crypto {
/* TODO: C++20 BlockCipher concept */
template<typename BlockCipher>
class XtsDecryptor {
NON_COPYABLE(XtsDecryptor);
NON_MOVEABLE(XtsDecryptor);
private:
using Impl = impl::XtsModeImpl;
public:
static constexpr size_t BlockSize = Impl::BlockSize;
static constexpr size_t IvSize = Impl::IvSize;
private:
Impl m_impl;
public:
XtsDecryptor() { /* ... */ }
template<typename BlockCipher2>
void Initialize(const BlockCipher *cipher1, const BlockCipher2 *cipher2, const void *iv, size_t iv_size) {
m_impl.InitializeDecryption(cipher1, cipher2, iv, iv_size);
}
size_t Update(void *dst, size_t dst_size, const void *src, size_t src_size) {
return m_impl.template Update<BlockCipher>(dst, dst_size, src, src_size);
}
size_t Finalize(void *dst, size_t dst_size) {
return m_impl.FinalizeDecryption(dst, dst_size);
}
};
}

View File

@@ -1,55 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_xts_mode_impl.hpp>
namespace ams::crypto {
/* TODO: C++20 BlockCipher concept */
template<typename BlockCipher>
class XtsEncryptor {
NON_COPYABLE(XtsEncryptor);
NON_MOVEABLE(XtsEncryptor);
private:
using Impl = impl::XtsModeImpl;
public:
static constexpr size_t BlockSize = Impl::BlockSize;
static constexpr size_t IvSize = Impl::IvSize;
private:
Impl m_impl;
public:
XtsEncryptor() { /* ... */ }
template<typename BlockCipher2>
void Initialize(const BlockCipher *cipher1, const BlockCipher2 *cipher2, const void *iv, size_t iv_size) {
m_impl.InitializeEncryption(cipher1, cipher2, iv, iv_size);
}
size_t Update(void *dst, size_t dst_size, const void *src, size_t src_size) {
return m_impl.template Update<BlockCipher>(dst, dst_size, src, src_size);
}
size_t Finalize(void *dst, size_t dst_size) {
return m_impl.FinalizeEncryption(dst, dst_size);
}
};
}

View File

@@ -1,57 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_block_cipher.hpp>
namespace ams::crypto::impl {
template<size_t _KeySize>
class AesImpl {
public:
static constexpr size_t KeySize = _KeySize;
static constexpr size_t BlockSize = 16;
static constexpr s32 RoundCount = (KeySize / 4) + 6;
static constexpr size_t RoundKeySize = BlockSize * (RoundCount + 1);
private:
#ifdef ATMOSPHERE_IS_EXOSPHERE
int m_slot;
#endif
#ifdef ATMOSPHERE_IS_STRATOSPHERE
u32 m_round_keys[RoundKeySize / sizeof(u32)];
#endif
public:
~AesImpl();
void Initialize(const void *key, size_t key_size, bool is_encrypt);
void EncryptBlock(void *dst, size_t dst_size, const void *src, size_t src_size) const;
void DecryptBlock(void *dst, size_t dst_size, const void *src, size_t src_size) const;
#ifdef ATMOSPHERE_IS_STRATOSPHERE
const u8 *GetRoundKey() const {
return reinterpret_cast<const u8 *>(m_round_keys);
}
#endif
};
static_assert(BlockCipher<AesImpl<16>>);
static_assert(BlockCipher<AesImpl<24>>);
static_assert(BlockCipher<AesImpl<32>>);
}

View File

@@ -1,164 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/crypto_memory_compare.hpp>
#include <vapours/crypto/crypto_memory_clear.hpp>
namespace ams::crypto::impl {
class BigNum {
NON_COPYABLE(BigNum);
NON_MOVEABLE(BigNum);
public:
using HalfWord = u16;
using Word = u32;
using DoubleWord = u64;
static constexpr size_t MaxBits = 4096;
static constexpr size_t BitsPerWord = sizeof(Word) * CHAR_BIT;
static constexpr Word MaxWord = std::numeric_limits<Word>::max();
static constexpr Word MaxHalfWord = std::numeric_limits<HalfWord>::max();
class WordAllocator {
NON_COPYABLE(WordAllocator);
NON_MOVEABLE(WordAllocator);
public:
class Allocation {
NON_COPYABLE(Allocation);
NON_MOVEABLE(Allocation);
private:
friend class WordAllocator;
private:
WordAllocator *m_allocator;
Word *m_buffer;
size_t m_count;
private:
constexpr ALWAYS_INLINE Allocation(WordAllocator *a, Word *w, size_t c) : m_allocator(a), m_buffer(w), m_count(c) { /* ... */ }
public:
ALWAYS_INLINE ~Allocation() { if (m_allocator) { m_allocator->Free(m_buffer, m_count); } }
constexpr ALWAYS_INLINE Word *GetBuffer() const { return m_buffer; }
constexpr ALWAYS_INLINE size_t GetCount() const { return m_count; }
constexpr ALWAYS_INLINE bool IsValid() const { return m_buffer != nullptr; }
};
friend class Allocation;
private:
Word *m_buffer;
size_t m_count;
size_t m_max_count;
size_t m_min_count;
private:
ALWAYS_INLINE void Free(void *words, size_t num) {
m_buffer -= num;
m_count += num;
AMS_ASSERT(words == m_buffer);
AMS_UNUSED(words);
}
public:
constexpr ALWAYS_INLINE WordAllocator(Word *buf, size_t c) : m_buffer(buf), m_count(c), m_max_count(c), m_min_count(c) { /* ... */ }
ALWAYS_INLINE Allocation Allocate(size_t num) {
if (num <= m_count) {
Word *allocated = m_buffer;
m_buffer += num;
m_count -= num;
m_min_count = std::min(m_count, m_min_count);
return Allocation(this, allocated, num);
} else {
return Allocation(nullptr, nullptr, 0);
}
}
constexpr ALWAYS_INLINE size_t GetMaxUsedSize() const {
return (m_max_count - m_min_count) * sizeof(Word);
}
};
private:
Word *m_words;
size_t m_num_words;
size_t m_max_words;
private:
static void ImportImpl(Word *out, size_t out_size, const u8 *src, size_t src_size);
static void ExportImpl(u8 *out, size_t out_size, const Word *src, size_t src_size);
public:
constexpr BigNum() : m_words(), m_num_words(), m_max_words() { /* ... */ }
~BigNum() { /* ... */ }
constexpr void ReserveStatic(Word *buf, size_t capacity) {
m_words = buf;
m_max_words = capacity;
}
bool Import(const void *src, size_t src_size);
void Export(void *dst, size_t dst_size);
size_t GetSize() const;
bool IsZero() const {
return m_num_words == 0;
}
bool ExpMod(void *dst, const void *src, size_t size, const BigNum &exp, u32 *work_buf, size_t work_buf_size) const;
void ClearToZero();
void UpdateCount();
public:
/* Utility. */
static bool IsZero(const Word *w, size_t num_words);
static int Compare(const Word *lhs, const Word *rhs, size_t num_words);
static size_t CountWords(const Word *w, size_t num_words);
static size_t CountSignificantBits(Word w);
static void ClearToZero(Word *w, size_t num_words);
static void SetToWord(Word *w, size_t num_words, Word v);
static void Copy(Word *dst, const Word *src, size_t num_words);
/* Arithmetic. */
static bool ExpMod(Word *dst, const Word *src, const Word *exp, size_t exp_num_words, const Word *mod, size_t mod_num_words, WordAllocator *allocator);
static bool MultMod(Word *dst, const Word *src, const Word *mult, const Word *mod, size_t num_words, WordAllocator *allocator);
static bool Mod(Word *dst, const Word *src, size_t src_words, const Word *mod, size_t mod_words, WordAllocator *allocator);
static bool DivMod(Word *quot, Word *rem, const Word *top, size_t top_words, const Word *bot, size_t bot_words, WordAllocator *allocator);
static bool Mult(Word *dst, const Word *lhs, const Word *rhs, size_t num_words, WordAllocator *allocator);
static Word LeftShift(Word *dst, const Word *w, size_t num_words, const size_t shift);
static Word RightShift(Word *dst, const Word *w, size_t num_words, const size_t shift);
static Word Add(Word *dst, const Word *lhs, const Word *rhs, size_t num_words);
static Word Sub(Word *dst, const Word *lhs, const Word *rhs, size_t num_words);
static Word MultAdd(Word *dst, const Word *w, size_t num_words, Word mult);
static Word MultSub(Word *dst, const Word *w, const Word *v, size_t num_words, Word mult);
};
template<size_t Bits>
class StaticBigNum : public BigNum {
public:
static constexpr size_t NumBits = Bits;
static constexpr size_t NumWords = util::AlignUp(NumBits, BitsPerWord) / BitsPerWord;
static constexpr size_t NumBytes = NumWords * sizeof(Word);
private:
Word m_word_buf[NumWords];
public:
constexpr StaticBigNum() : m_word_buf() {
this->ReserveStatic(m_word_buf, NumWords);
}
};
}

View File

@@ -1,33 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/crypto_memory_compare.hpp>
#include <vapours/crypto/crypto_memory_clear.hpp>
namespace ams::crypto::impl {
template<typename T>
concept BlockCipher = requires(T &t, const void *cv, void *v, size_t sz, bool b) {
{ T::BlockSize } -> std::convertible_to<size_t>;
{ t.EncryptBlock(v, sz, cv, sz) } -> std::same_as<void>;
{ t.DecryptBlock(v, sz, cv, sz) } -> std::same_as<void>;
};
}

View File

@@ -1,103 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/crypto_memory_clear.hpp>
#include <vapours/crypto/crypto_aes_encryptor.hpp>
namespace ams::crypto::impl {
class CbcMacImpl {
NON_COPYABLE(CbcMacImpl);
NON_MOVEABLE(CbcMacImpl);
public:
static constexpr size_t BlockSize = 0x10;
private:
enum State {
State_None,
State_Initialized,
State_Done,
};
private:
u8 m_mac[BlockSize];
u8 m_buffer[BlockSize];
size_t m_buffered_bytes;
const void *m_cipher_context;
void (*m_cipher_function)(void *dst, const void *src, const void *ctx);
State m_state;
public:
CbcMacImpl() : m_buffered_bytes(0), m_state(State_None) { /* ... */ }
~CbcMacImpl() {
ClearMemory(this, sizeof(*this));
}
template<typename BlockCipher>
void Initialize(const BlockCipher *block_cipher) {
static_assert(BlockCipher::BlockSize == BlockSize);
/* Set our context. */
m_cipher_context = block_cipher;
m_cipher_function = &EncryptBlockCallback<BlockCipher>;
m_buffered_bytes = 0;
std::memset(m_mac, 0, sizeof(m_mac));
m_state = State_Initialized;
}
template<typename BlockCipher>
void Update(const void *data, size_t size) {
this->UpdateGeneric(data, size);
}
template<typename BlockCipher>
void ProcessBlocks(const void *data, size_t size) {
this->ProcessBlocksGeneric(data, size);
}
size_t GetBlockSize() const {
return BlockSize;
}
size_t GetBufferedDataSize() const {
return m_buffered_bytes;
}
void UpdateGeneric(const void *data, size_t size);
void ProcessBlocksGeneric(const void *data, size_t num_blocks);
void ProcessPartialData(const void *data, size_t size);
void ProcessRemainingData(const void *data, size_t size);
void GetMac(void *mac, size_t mac_size);
void MaskBufferedData(const void *data, size_t size);
private:
void ProcessBlock(const void *data);
template<typename BlockCipher>
static void EncryptBlockCallback(void *dst, const void *src, const void *cipher) {
static_assert(BlockCipher::BlockSize == BlockSize);
static_cast<const BlockCipher *>(cipher)->EncryptBlock(dst, BlockCipher::BlockSize, src, BlockCipher::BlockSize);
}
};
template<>
void CbcMacImpl::Update<AesEncryptor128>(const void *data, size_t size);
}

View File

@@ -1,200 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/crypto_memory_clear.hpp>
#include <vapours/crypto/crypto_aes_encryptor.hpp>
namespace ams::crypto::impl {
template<typename BlockCipher>
class CbcModeImpl {
NON_COPYABLE(CbcModeImpl);
NON_MOVEABLE(CbcModeImpl);
public:
static constexpr size_t KeySize = BlockCipher::KeySize;
static constexpr size_t BlockSize = BlockCipher::BlockSize;
static constexpr size_t IvSize = BlockCipher::BlockSize;
private:
enum State {
State_None,
State_Initialized,
};
private:
const BlockCipher *m_block_cipher;
u8 m_iv[IvSize];
u8 m_buffer[BlockSize];
size_t m_buffered_bytes;
State m_state;
public:
CbcModeImpl() : m_state(State_None) { /* ... */ }
~CbcModeImpl() {
ClearMemory(this, sizeof(*this));
}
void Initialize(const BlockCipher *block_cipher, const void *iv, size_t iv_size) {
AMS_ASSERT(iv_size == IvSize);
AMS_UNUSED(iv_size);
m_block_cipher = block_cipher;
std::memcpy(m_iv, iv, IvSize);
m_buffered_bytes = 0;
m_state = State_Initialized;
}
size_t GetBufferedDataSize() const {
return m_buffered_bytes;
}
size_t UpdateEncryption(void *dst, size_t dst_size, const void *src, size_t src_size) {
AMS_ASSERT(dst_size >= ((src_size + this->GetBufferedDataSize()) / BlockSize) * BlockSize);
AMS_ASSERT(m_state == State_Initialized);
return this->Update(dst, dst_size, src, src_size, [&] (u8 *d, u8 *i, const u8 *s, size_t n) ALWAYS_INLINE_LAMBDA {
this->EncryptBlocks(d, i, s, n);
});
}
size_t UpdateDecryption(void *dst, size_t dst_size, const void *src, size_t src_size) {
AMS_ASSERT(dst_size >= ((src_size + this->GetBufferedDataSize()) / BlockSize) * BlockSize);
AMS_ASSERT(m_state == State_Initialized);
return this->Update(dst, dst_size, src, src_size, [&] (u8 *d, u8 *i, const u8 *s, size_t n) ALWAYS_INLINE_LAMBDA {
this->DecryptBlocks(d, i, s, n);
});
}
private:
size_t Update(void *_dst, size_t dst_size, const void *_src, size_t src_size, auto ProcessBlocks) {
AMS_UNUSED(dst_size);
u8 *dst = static_cast<u8 *>(_dst);
const u8 *src = static_cast<const u8 *>(_src);
size_t remaining = src_size;
size_t processed = 0;
if (m_buffered_bytes > 0) {
const size_t copy_size = std::min(BlockSize - m_buffered_bytes, remaining);
std::memcpy(m_buffer + m_buffered_bytes, src, copy_size);
src += copy_size;
remaining -= copy_size;
m_buffered_bytes += copy_size;
if (m_buffered_bytes == BlockSize) {
ProcessBlocks(dst, m_iv, m_buffer, 1);
processed += BlockSize;
dst += BlockSize;
m_buffered_bytes = 0;
}
}
if (remaining >= BlockSize) {
const size_t num_blocks = remaining / BlockSize;
ProcessBlocks(dst, m_iv, src, num_blocks);
const size_t processed_size = num_blocks * BlockSize;
dst += processed_size;
src += processed_size;
remaining -= processed_size;
processed += processed_size;
}
if (remaining > 0) {
std::memcpy(m_buffer, src, remaining);
m_buffered_bytes = remaining;
}
return processed;
}
void EncryptBlocks(u8 *dst, u8 *iv, const u8 *src, size_t num_blocks) {
const u8 *cur_iv = iv;
u8 block[BlockSize];
while (num_blocks--) {
for (size_t i = 0; i < BlockSize; ++i) {
block[i] = src[i] ^ cur_iv[i];
}
m_block_cipher->EncryptBlock(dst, BlockSize, block, BlockSize);
cur_iv = dst;
src += BlockSize;
dst += BlockSize;
}
if (iv != cur_iv) {
std::memcpy(iv, cur_iv, BlockSize);
}
}
void DecryptBlocks(u8 *dst, u8 *iv, const u8 *src, size_t num_blocks) {
u8 next_iv[BlockSize];
std::memcpy(next_iv, src + ((num_blocks - 1) * BlockSize), BlockSize);
if (src == dst) {
src = src + ((num_blocks - 1) * BlockSize);
dst = dst + ((num_blocks - 1) * BlockSize);
const u8 *cur_iv = (num_blocks == 1) ? iv : src - BlockSize;
while (num_blocks-- > 1) {
m_block_cipher->DecryptBlock(dst, BlockSize, src, BlockSize);
for (size_t i = 0; i < BlockSize; ++i) {
dst[i] ^= cur_iv[i];
}
cur_iv -= BlockSize;
src -= BlockSize;
dst -= BlockSize;
}
m_block_cipher->DecryptBlock(dst, BlockSize, src, BlockSize);
for (size_t i = 0; i < BlockSize; ++i) {
dst[i] ^= iv[i];
}
} else {
const u8 *cur_iv = iv;
while (num_blocks-- > 0) {
m_block_cipher->DecryptBlock(dst, BlockSize, src, BlockSize);
for (size_t i = 0; i < BlockSize; ++i) {
dst[i] ^= cur_iv[i];
}
cur_iv = src;
src += BlockSize;
dst += BlockSize;
}
}
std::memcpy(iv, next_iv, BlockSize);
}
};
/* TODO: Optimized AES cbc impl specializations. */
}

View File

@@ -1,274 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/crypto_memory_clear.hpp>
#include <vapours/crypto/impl/crypto_ctr_mode_impl.hpp>
#include <vapours/crypto/impl/crypto_cbc_mac_impl.hpp>
namespace ams::crypto::impl {
template<typename BlockCipher>
class CcmModeImpl {
NON_COPYABLE(CcmModeImpl);
NON_MOVEABLE(CcmModeImpl);
public:
static constexpr size_t KeySize = BlockCipher::KeySize;
static constexpr size_t BlockSize = BlockCipher::BlockSize;
private:
enum State {
State_None,
State_ProcessingAad,
State_ProcessingData,
State_DataInputDone,
State_Done,
};
private:
u8 m_mac[BlockSize];
s64 m_given_data_size;
s64 m_given_aad_size;
size_t m_given_mac_size;
s64 m_processed_data_size;
s64 m_processed_aad_size;
State m_state;
CtrModeImpl<BlockCipher> m_ctr_mode_impl;
CbcMacImpl m_cbc_mac_impl;
public:
CcmModeImpl() : m_state(State_None) { /* ... */ }
~CcmModeImpl() {
ClearMemory(this, sizeof(*this));
}
void Initialize(const BlockCipher *cipher, const void *nonce, size_t nonce_size, s64 aad_size, s64 data_size, size_t mac_size) {
/* Check pre-conditions. */
AMS_ASSERT(7 <= nonce_size && nonce_size <= 13);
AMS_ASSERT(4 <= mac_size && mac_size <= 16 && (mac_size % 2) == 0);
AMS_ASSERT(aad_size >= 0);
AMS_ASSERT(data_size >= 0);
if (nonce_size == 7) {
AMS_ASSERT(data_size <= std::numeric_limits<s64>::max());
} else {
AMS_ASSERT(data_size < (INT64_C(1) << ((15 - nonce_size) * 8)));
}
/* Set various size fields. */
m_given_aad_size = aad_size;
m_given_data_size = data_size;
m_given_mac_size = mac_size;
m_processed_aad_size = 0;
m_processed_data_size = 0;
/* Make the initial counter. */
u8 tmp[BlockSize];
MakeInitialCounter(tmp, nonce, nonce_size);
/* Encrypt the block. */
cipher->EncryptBlock(m_mac, BlockSize, tmp, BlockSize);
/* Initialize our ctr mode impl. */
m_ctr_mode_impl.Initialize(cipher, tmp, BlockSize);
m_ctr_mode_impl.IncrementCounter();
/* Make the header block. */
MakeHeaderBlock(tmp, nonce, nonce_size, aad_size, data_size, mac_size);
/* Initialize our cbc mac impl. */
m_cbc_mac_impl.Initialize(cipher);
m_cbc_mac_impl.template Update<BlockCipher>(tmp, BlockSize);
/* Process aad size block. */
if (aad_size > 0) {
this->ProcessEncodedAadSize();
m_state = State_ProcessingAad;
} else {
m_state = State_ProcessingData;
}
}
void UpdateAad(const void *aad, size_t aad_size) {
/* Check pre-conditions. */
AMS_ASSERT(m_state == State_ProcessingAad);
AMS_ASSERT(m_processed_aad_size + static_cast<s64>(aad_size) <= m_given_aad_size);
/* Update on the aad. */
m_cbc_mac_impl.template Update<BlockCipher>(aad, aad_size);
m_processed_aad_size += aad_size;
/* Check if we're done with aad. */
if (m_processed_aad_size == m_given_aad_size) {
/* Pad the aad to block size. */
this->ProcessPadding();
/* Update our state. */
if (m_given_data_size > 0) {
m_state = State_ProcessingData;
} else {
m_state = State_DataInputDone;
}
}
}
size_t UpdateEncryption(void *dst, size_t dst_size, const void *src, size_t src_size) {
/* Check pre-conditions. */
AMS_ASSERT(m_state == State_ProcessingData);
AMS_ASSERT(m_processed_data_size + static_cast<s64>(src_size) <= m_given_data_size);
AMS_ASSERT(dst_size >= src_size);
/* Update mac on decrypted data. */
m_cbc_mac_impl.template Update<BlockCipher>(src, src_size);
/* Encrypt. */
const size_t processed = m_ctr_mode_impl.Update(dst, dst_size, src, src_size);
m_processed_data_size += src_size;
/* Check if we're done with data. */
if (m_processed_data_size == m_given_data_size) {
/* Pad the data to block size. */
this->ProcessPadding();
m_state = State_DataInputDone;
}
return processed;
}
size_t UpdateDecryption(void *dst, size_t dst_size, const void *src, size_t src_size) {
/* Check pre-conditions. */
AMS_ASSERT(m_state == State_ProcessingData);
AMS_ASSERT(m_processed_data_size + static_cast<s64>(src_size) <= m_given_data_size);
AMS_ASSERT(dst_size >= src_size);
/* Decrypt. */
const size_t processed = m_ctr_mode_impl.Update(dst, dst_size, src, src_size);
m_processed_data_size += src_size;
/* Update mac on decrypted data. */
m_cbc_mac_impl.template Update<BlockCipher>(dst, dst_size);
/* Check if we're done with data. */
if (m_processed_data_size == m_given_data_size) {
/* Pad the data to block size. */
this->ProcessPadding();
m_state = State_DataInputDone;
}
return processed;
}
void GetMac(void *mac, size_t mac_size) {
/* Check pre-conditions. */
AMS_ASSERT(m_state == State_DataInputDone || m_state == State_Done);
AMS_ASSERT(mac_size >= m_given_mac_size);
AMS_UNUSED(mac_size);
/* Generate the mac, if we haven't already. */
if (m_state == State_DataInputDone) {
this->GenerateMac();
m_state = State_Done;
}
/* Copy out the mac. */
std::memcpy(mac, m_mac, m_given_mac_size);
}
private:
void MakeInitialCounter(void *dst, const void *nonce, size_t nonce_size) {
/* Clear the counter. */
u8 *ctr = static_cast<u8 *>(dst);
std::memset(ctr, 0, BlockSize);
/* Set the nonce. */
ctr[0] = (((BlockSize - 1 - nonce_size) & 0xFF) - 1) & 0x07;
std::memcpy(ctr + 1, nonce, nonce_size);
}
void MakeHeaderBlock(void *dst, const void *nonce, size_t nonce_size, s64 aad_size, s64 data_size, size_t mac_size) {
/* Clear the block. */
u8 *hdr = static_cast<u8 *>(dst);
std::memset(hdr, 0, BlockSize);
/* Encode the flags. */
hdr[0] = (((BlockSize - 1 - nonce_size) & 0xFF) - 1) & 0x07;
hdr[0] |= (((mac_size - 2) / 2) & 0x07) << 3;
hdr[0] |= (aad_size > 0) ? 0x40 : 0x00;
/* Encode the data size. */
for (size_t i = 0; i < sizeof(s64); ++i) {
hdr[BlockSize - 1 - i] = static_cast<u64>(data_size) >> (BITSIZEOF(u8) * i);
}
/* Copy the nonce. */
std::memcpy(hdr + 1, nonce, nonce_size);
}
void ProcessEncodedAadSize() {
u8 encoded_aad[10];
size_t encoded_aad_size;
if (m_given_aad_size < ((1 << 16) - (1 << 8))) {
encoded_aad[0] = (m_given_aad_size >> (BITSIZEOF(u8) * 1)) & 0xFF;
encoded_aad[1] = (m_given_aad_size >> (BITSIZEOF(u8) * 0)) & 0xFF;
encoded_aad_size = 2;
} else if (m_given_aad_size <= 0xFFFFFFFFu) {
encoded_aad[0] = 0xFF;
encoded_aad[1] = 0xFE;
encoded_aad[2] = (m_given_aad_size >> (BITSIZEOF(u8) * 3)) & 0xFF;
encoded_aad[3] = (m_given_aad_size >> (BITSIZEOF(u8) * 2)) & 0xFF;
encoded_aad[4] = (m_given_aad_size >> (BITSIZEOF(u8) * 1)) & 0xFF;
encoded_aad[5] = (m_given_aad_size >> (BITSIZEOF(u8) * 0)) & 0xFF;
encoded_aad_size = 6;
} else {
encoded_aad[0] = 0xFF;
encoded_aad[1] = 0xFE;
encoded_aad[2] = (static_cast<u64>(m_given_aad_size) >> (BITSIZEOF(u8) * 7)) & 0xFF;
encoded_aad[3] = (static_cast<u64>(m_given_aad_size) >> (BITSIZEOF(u8) * 6)) & 0xFF;
encoded_aad[4] = (static_cast<u64>(m_given_aad_size) >> (BITSIZEOF(u8) * 5)) & 0xFF;
encoded_aad[5] = (static_cast<u64>(m_given_aad_size) >> (BITSIZEOF(u8) * 4)) & 0xFF;
encoded_aad[6] = (static_cast<u64>(m_given_aad_size) >> (BITSIZEOF(u8) * 3)) & 0xFF;
encoded_aad[7] = (static_cast<u64>(m_given_aad_size) >> (BITSIZEOF(u8) * 2)) & 0xFF;
encoded_aad[8] = (static_cast<u64>(m_given_aad_size) >> (BITSIZEOF(u8) * 1)) & 0xFF;
encoded_aad[9] = (static_cast<u64>(m_given_aad_size) >> (BITSIZEOF(u8) * 0)) & 0xFF;
encoded_aad_size = 10;
}
m_cbc_mac_impl.template Update<BlockCipher>(encoded_aad, encoded_aad_size);
}
void ProcessPadding() {
/* Process any remaining padding. */
if (const auto buffered = m_cbc_mac_impl.GetBufferedDataSize(); buffered > 0) {
u8 zeros[BlockSize] = {};
m_cbc_mac_impl.template Update<BlockCipher>(zeros, BlockSize - buffered);
}
}
void GenerateMac() {
/* Get the cbc mac. */
u8 tmp[BlockSize];
m_cbc_mac_impl.GetMac(tmp, BlockSize);
/* Xor into our mac. */
for (size_t i = 0; i < BlockSize; ++i) {
m_mac[i] ^= tmp[i];
}
}
};
}

View File

@@ -1,128 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_hash_function.hpp>
#include <vapours/crypto/impl/crypto_cbc_mac_impl.hpp>
#include <vapours/crypto/crypto_memory_clear.hpp>
namespace ams::crypto::impl {
template<typename BlockCipher>
class CmacImpl {
NON_COPYABLE(CmacImpl);
NON_MOVEABLE(CmacImpl);
public:
static constexpr size_t BlockSize = BlockCipher::BlockSize;
static constexpr size_t MacSize = BlockSize;
static_assert(BlockSize == 0x10); /* TODO: Should this be supported? */
private:
enum State {
State_None = 0,
State_Initialized = 1,
State_Done = 2,
};
private:
CbcMacImpl m_cbc_mac_impl;
u8 m_sub_key[BlockSize];
State m_state;
public:
CmacImpl() : m_state(State_None) { /* ... */ }
~CmacImpl() {
/* Clear everything. */
ClearMemory(this, sizeof(*this));
}
void Initialize(const BlockCipher *cipher);
void Update(const void *data, size_t data_size);
void GetMac(void *dst, size_t dst_size);
private:
static void MultiplyOneOverGF128(u8 *data) {
/* Determine the carry bit. */
const u8 carry = data[0] & 0x80;
/* Shift all bytes by one bit. */
for (size_t i = 0; i < BlockSize - 1; ++i) {
data[i] = (data[i] << 1) | (data[i + 1] >> 7);
}
data[BlockSize - 1] <<= 1;
/* Adjust based on carry. */
if (carry) {
data[BlockSize - 1] ^= 0x87;
}
}
};
template<typename BlockCipher>
inline void CmacImpl<BlockCipher>::Initialize(const BlockCipher *cipher) {
/* Clear the key storage. */
std::memset(m_sub_key, 0, sizeof(m_sub_key));
/* Set the key storage. */
cipher->EncryptBlock(m_sub_key, BlockSize, m_sub_key, BlockSize);
MultiplyOneOverGF128(m_sub_key);
/* Initialize the cbc-mac impl. */
m_cbc_mac_impl.Initialize(cipher);
/* Mark initialized. */
m_state = State_Initialized;
}
template<typename BlockCipher>
inline void CmacImpl<BlockCipher>::Update(const void *data, size_t data_size) {
AMS_ASSERT(m_state == State_Initialized);
m_cbc_mac_impl.template Update<BlockCipher>(data, data_size);
}
template<typename BlockCipher>
inline void CmacImpl<BlockCipher>::GetMac(void *dst, size_t dst_size) {
AMS_ASSERT(m_state == State_Initialized || m_state == State_Done);
AMS_ASSERT(dst_size >= MacSize);
AMS_UNUSED(dst_size);
/* If we're not already finalized, get the final mac. */
if (m_state == State_Initialized) {
/* Process padding as needed. */
if (m_cbc_mac_impl.GetBufferedDataSize() != BlockSize) {
/* Determine the remaining size. */
const size_t remaining = BlockSize - m_cbc_mac_impl.GetBufferedDataSize();
/* Update with padding. */
static constexpr u8 s_padding[BlockSize] = { 0x80, /* ... */ };
m_cbc_mac_impl.template Update<BlockCipher>(s_padding, remaining);
/* Update our subkey. */
MultiplyOneOverGF128(m_sub_key);
}
/* Mask the subkey. */
m_cbc_mac_impl.MaskBufferedData(m_sub_key, BlockSize);
/* Set our state as done. */
m_state = State_Done;
}
/* Get the mac. */
m_cbc_mac_impl.GetMac(dst, dst_size);
}
}

View File

@@ -1,184 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/crypto_memory_clear.hpp>
#include <vapours/crypto/crypto_aes_encryptor.hpp>
namespace ams::crypto::impl {
template<typename BlockCipher>
class CtrModeImpl {
NON_COPYABLE(CtrModeImpl);
NON_MOVEABLE(CtrModeImpl);
public:
static constexpr size_t KeySize = BlockCipher::KeySize;
static constexpr size_t BlockSize = BlockCipher::BlockSize;
static constexpr size_t IvSize = BlockCipher::BlockSize;
private:
enum State {
State_None,
State_Initialized,
};
private:
const BlockCipher *m_block_cipher;
u8 m_counter[IvSize];
u8 m_encrypted_counter[BlockSize];
size_t m_buffer_offset;
State m_state;
public:
CtrModeImpl() : m_state(State_None) { /* ... */ }
~CtrModeImpl() {
ClearMemory(this, sizeof(*this));
}
void Initialize(const BlockCipher *block_cipher, const void *iv, size_t iv_size) {
this->Initialize(block_cipher, iv, iv_size, 0);
}
void Initialize(const BlockCipher *block_cipher, const void *iv, size_t iv_size, s64 offset) {
AMS_ASSERT(iv_size == IvSize);
AMS_ASSERT(offset >= 0);
m_block_cipher = block_cipher;
m_state = State_Initialized;
this->SwitchMessage(iv, iv_size);
if (offset >= 0) {
u64 ctr_offset = offset / BlockSize;
if (ctr_offset > 0) {
this->IncrementCounter(ctr_offset);
}
if (size_t remaining = static_cast<size_t>(offset % BlockSize); remaining != 0) {
m_block_cipher->EncryptBlock(m_encrypted_counter, sizeof(m_encrypted_counter), m_counter, sizeof(m_counter));
this->IncrementCounter();
m_buffer_offset = remaining;
}
}
}
void SwitchMessage(const void *iv, size_t iv_size) {
AMS_ASSERT(m_state == State_Initialized);
AMS_ASSERT(iv_size == IvSize);
std::memcpy(m_counter, iv, iv_size);
m_buffer_offset = 0;
}
void IncrementCounter() {
for (s32 i = IvSize - 1; i >= 0; --i) {
if (++m_counter[i] != 0) {
break;
}
}
}
size_t Update(void *_dst, size_t dst_size, const void *_src, size_t src_size) {
AMS_ASSERT(m_state == State_Initialized);
AMS_ASSERT(dst_size >= src_size);
AMS_UNUSED(dst_size);
u8 *dst = static_cast<u8 *>(_dst);
const u8 *src = static_cast<const u8 *>(_src);
size_t remaining = src_size;
if (m_buffer_offset > 0) {
const size_t xor_size = std::min(BlockSize - m_buffer_offset, remaining);
const u8 *ctr = m_encrypted_counter + m_buffer_offset;
for (size_t i = 0; i < xor_size; i++) {
dst[i] = src[i] ^ ctr[i];
}
src += xor_size;
dst += xor_size;
remaining -= xor_size;
m_buffer_offset += xor_size;
if (m_buffer_offset == BlockSize) {
m_buffer_offset = 0;
}
}
if (remaining >= BlockSize) {
const size_t num_blocks = remaining / BlockSize;
this->ProcessBlocks(dst, src, num_blocks);
const size_t processed_size = num_blocks * BlockSize;
dst += processed_size;
src += processed_size;
remaining -= processed_size;
}
if (remaining > 0) {
this->ProcessBlock(dst, src, remaining);
m_buffer_offset = remaining;
}
return src_size;
}
private:
void IncrementCounter(u64 count) {
u64 _block[IvSize / sizeof(u64)] = {};
util::StoreBigEndian(std::addressof(_block[(IvSize / sizeof(u64)) - 1]), count);
u16 acc = 0;
const u8 *block = reinterpret_cast<const u8 *>(_block);
for (s32 i = IvSize - 1; i >= 0; --i) {
acc += (m_counter[i] + block[i]);
m_counter[i] = acc & 0xFF;
acc >>= 8;
}
}
void ProcessBlock(u8 *dst, const u8 *src, size_t src_size) {
m_block_cipher->EncryptBlock(m_encrypted_counter, BlockSize, m_counter, IvSize);
this->IncrementCounter();
for (size_t i = 0; i < src_size; i++) {
dst[i] = src[i] ^ m_encrypted_counter[i];
}
}
void ProcessBlocks(u8 *dst, const u8 *src, size_t num_blocks);
};
template<typename BlockCipher>
inline void CtrModeImpl<BlockCipher>::ProcessBlocks(u8 *dst, const u8 *src, size_t num_blocks) {
while (num_blocks--) {
this->ProcessBlock(dst, src, BlockSize);
dst += BlockSize;
src += BlockSize;
}
}
template<> void CtrModeImpl<AesEncryptor128>::ProcessBlocks(u8 *dst, const u8 *src, size_t num_blocks);
/* TODO: Optimized x64 CTR-192/256? */
#if defined(ATMOSPHERE_ARCH_ARM64)
template<> void CtrModeImpl<AesEncryptor192>::ProcessBlocks(u8 *dst, const u8 *src, size_t num_blocks);
template<> void CtrModeImpl<AesEncryptor256>::ProcessBlocks(u8 *dst, const u8 *src, size_t num_blocks);
#endif
}

View File

@@ -1,106 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/crypto_memory_clear.hpp>
#include <vapours/crypto/crypto_aes_encryptor.hpp>
namespace ams::crypto::impl {
template<typename BlockCipher>
class GcmModeImpl {
NON_COPYABLE(GcmModeImpl);
NON_MOVEABLE(GcmModeImpl);
public:
static constexpr size_t KeySize = BlockCipher::KeySize;
static constexpr size_t BlockSize = BlockCipher::BlockSize;
static constexpr size_t MacSize = BlockCipher::BlockSize;
private:
enum State {
State_None,
State_Initialized,
State_ProcessingAad,
State_Encrypting,
State_Decrypting,
State_Done,
};
struct Block128 {
u64 hi;
u64 lo;
ALWAYS_INLINE void Clear() {
this->hi = 0;
this->lo = 0;
}
};
static_assert(util::is_pod<Block128>::value);
static_assert(sizeof(Block128) == 0x10);
union Block {
Block128 block_128;
u32 block_32[4];
u8 block_8[16];
};
static_assert(util::is_pod<Block>::value);
static_assert(sizeof(Block) == 0x10);
using CipherFunction = void (*)(void *dst_block, const void *src_block, const void *ctx);
private:
State m_state;
const BlockCipher *m_block_cipher;
CipherFunction m_cipher_func;
u8 m_pad[sizeof(u64)];
Block m_block_x;
Block m_block_y;
Block m_block_ek;
Block m_block_ek0;
Block m_block_tmp;
size_t m_aad_size;
size_t m_msg_size;
u32 m_aad_remaining;
u32 m_msg_remaining;
u32 m_counter;
Block m_h_mult_blocks[16];
public:
GcmModeImpl() : m_state(State_None) { /* ... */ }
~GcmModeImpl() {
ClearMemory(this, sizeof(*this));
}
void Initialize(const BlockCipher *block_cipher);
void Reset(const void *iv, size_t iv_size);
void UpdateAad(const void *aad, size_t aad_size);
size_t UpdateEncrypt(void *dst, size_t dst_size, const void *src, size_t src_size);
size_t UpdateDecrypt(void *dst, size_t dst_size, const void *src, size_t src_size);
void GetMac(void *dst, size_t dst_size);
private:
static void ProcessBlock(void *dst_block, const void *src_block, const void *ctx) {
static_cast<const BlockCipher *>(ctx)->EncryptBlock(dst_block, BlockSize, src_block, BlockSize);
}
void InitializeHashKey();
void ComputeMac(bool encrypt);
};
}

View File

@@ -1,35 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/crypto_memory_compare.hpp>
#include <vapours/crypto/crypto_memory_clear.hpp>
namespace ams::crypto::impl {
template<typename T>
concept HashFunction = requires(T &t, const void *cv, void *v, size_t sz) {
{ T::HashSize } -> std::convertible_to<size_t>;
{ T::BlockSize } -> std::convertible_to<size_t>;
{ t.Initialize() } -> std::same_as<void>;
{ t.Update(cv, sz) } -> std::same_as<void>;
{ t.GetHash(v, sz) } -> std::same_as<void>;
};
}

View File

@@ -1,127 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_hash_function.hpp>
#include <vapours/crypto/crypto_memory_clear.hpp>
namespace ams::crypto::impl {
template<HashFunction Hash>
class HmacImpl {
NON_COPYABLE(HmacImpl);
NON_MOVEABLE(HmacImpl);
public:
static constexpr size_t MacSize = Hash::HashSize;
static constexpr size_t BlockSize = Hash::BlockSize;
private:
static constexpr u32 IpadMagic = 0x36363636;
static constexpr u32 OpadMagic = 0x5c5c5c5c;
static constexpr u32 IpadMagicXorOpadMagic = IpadMagic ^ OpadMagic;
static_assert(IpadMagicXorOpadMagic == 0x6a6a6a6a);
private:
enum State {
State_None = 0,
State_Initialized = 1,
State_Done = 2,
};
private:
Hash m_hash_function;
u32 m_key[BlockSize / sizeof(u32)];
u32 m_mac[MacSize / sizeof(u32)];
State m_state;
public:
HmacImpl() : m_state(State_None) { /* ... */ }
~HmacImpl() {
static_assert(AMS_OFFSETOF(HmacImpl, m_hash_function) == 0);
/* Clear everything except for the hash function. */
ClearMemory(reinterpret_cast<u8 *>(this) + sizeof(m_hash_function), sizeof(*this) - sizeof(m_hash_function));
}
void Initialize(const void *key, size_t key_size);
void Update(const void *data, size_t data_size);
void GetMac(void *dst, size_t dst_size);
};
template<HashFunction Hash>
inline void HmacImpl<Hash>::Initialize(const void *key, size_t key_size) {
/* Clear the key storage. */
std::memset(m_key, 0, sizeof(m_key));
/* Set the key storage. */
if (key_size > BlockSize) {
m_hash_function.Initialize();
m_hash_function.Update(key, key_size);
m_hash_function.GetHash(m_key, m_hash_function.HashSize);
} else {
std::memcpy(m_key, key, key_size);
}
/* Xor the key with the ipad. */
for (size_t i = 0; i < util::size(m_key); i++) {
m_key[i] ^= IpadMagic;
}
/* Update the hash function with the xor'd key. */
m_hash_function.Initialize();
m_hash_function.Update(m_key, BlockSize);
/* Mark initialized. */
m_state = State_Initialized;
}
template<HashFunction Hash>
inline void HmacImpl<Hash>::Update(const void *data, size_t data_size) {
AMS_ASSERT(m_state == State_Initialized);
m_hash_function.Update(data, data_size);
}
template<HashFunction Hash>
inline void HmacImpl<Hash>::GetMac(void *dst, size_t dst_size) {
AMS_ASSERT(m_state == State_Initialized || m_state == State_Done);
AMS_ASSERT(dst_size >= MacSize);
AMS_UNUSED(dst_size);
/* If we're not already finalized, get the final mac. */
if (m_state == State_Initialized) {
/* Get the hash of ((key ^ ipad) || data). */
m_hash_function.GetHash(m_mac, MacSize);
/* Xor the key with the opad. */
for (size_t i = 0; i < util::size(m_key); i++) {
m_key[i] ^= IpadMagicXorOpadMagic;
}
/* Calculate the final mac as hash of ((key ^ opad) || hash((key ^ ipad) || data)) */
m_hash_function.Initialize();
m_hash_function.Update(m_key, BlockSize);
m_hash_function.Update(m_mac, MacSize);
m_hash_function.GetHash(m_mac, MacSize);
/* Set our state as done. */
m_state = State_Done;
}
std::memcpy(dst, m_mac, MacSize);
}
}

View File

@@ -1,61 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_hash_function.hpp>
#include <vapours/crypto/crypto_memory_clear.hpp>
namespace ams::crypto::impl {
class Md5Impl {
public:
static constexpr size_t HashSize = 0x10;
static constexpr size_t BlockSize = 0x40;
private:
enum State {
State_None = 0,
State_Initialized = 1,
State_Done = 2,
};
private:
union {
struct {
u32 a, b, c, d;
} p;
u32 state[4];
} m_x;
alignas(8) u8 m_y[BlockSize];
size_t m_size;
State m_state;
public:
Md5Impl() : m_state(State_None) { /* ... */ }
~Md5Impl() { ClearMemory(this, sizeof(*this)); }
void Initialize();
void Update(const void *data, size_t size);
void GetHash(void *dst, size_t size);
private:
void ProcessBlock();
void ProcessLastBlock();
};
static_assert(HashFunction<Md5Impl>);
}

View File

@@ -1,163 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_hash_function.hpp>
namespace ams::crypto::impl {
template<HashFunction Hash>
class RsaOaepImpl {
NON_COPYABLE(RsaOaepImpl);
NON_MOVEABLE(RsaOaepImpl);
public:
static constexpr size_t HashSize = Hash::HashSize;
private:
static constexpr u8 HeadMagic = 0x00;
private:
static void ComputeHashWithPadding(void *dst, Hash *hash, const void *salt, size_t salt_size) {
/* Initialize our buffer. */
u8 buf[8 + HashSize];
std::memset(buf, 0, 8);
hash->GetHash(buf + 8, HashSize);
ON_SCOPE_EXIT { ClearMemory(buf, sizeof(buf)); };
/* Calculate our hash. */
hash->Initialize();
hash->Update(buf, sizeof(buf));
hash->Update(salt, salt_size);
hash->GetHash(dst, HashSize);
}
static void ApplyMGF1(u8 *dst, size_t dst_size, const void *src, size_t src_size) {
u8 buf[HashSize];
ON_SCOPE_EXIT { ClearMemory(buf, sizeof(buf)); };
const size_t required_iters = (dst_size + HashSize - 1) / HashSize;
for (size_t i = 0; i < required_iters; i++) {
Hash hash;
hash.Initialize();
hash.Update(src, src_size);
const u32 tmp = util::ConvertToBigEndian(static_cast<u32>(i));
hash.Update(std::addressof(tmp), sizeof(tmp));
hash.GetHash(buf, HashSize);
const size_t start = HashSize * i;
const size_t end = std::min(dst_size, start + HashSize);
for (size_t j = start; j < end; j++) {
dst[j] ^= buf[j - start];
}
}
}
public:
RsaOaepImpl() { /* ... */ }
void Encode(void *dst, size_t dst_size, Hash *hash, const void *src, size_t src_size, const void *salt, size_t salt_size) {
u8 label_digest[HashSize];
ON_SCOPE_EXIT { ClearMemory(label_digest, HashSize); };
hash->GetHash(label_digest, HashSize);
return this->Encode(dst, dst_size, label_digest, sizeof(label_digest), src, src_size, salt, salt_size);
}
void Encode(void *dst, size_t dst_size, const void *label_digest, size_t label_digest_size, const void *src, size_t src_size, const void *salt, size_t salt_size) {
/* Check our preconditions. */
AMS_ASSERT(dst_size >= 2 * HashSize + 2 + src_size);
AMS_ASSERT(salt_size > 0);
AMS_ASSERT(salt_size == HashSize);
AMS_ASSERT(label_digest_size == HashSize);
AMS_UNUSED(salt_size, label_digest_size);
u8 *buf = static_cast<u8 *>(dst);
buf[0] = HeadMagic;
u8 *seed = buf + 1;
std::memcpy(seed, salt, HashSize);
u8 *db = seed + HashSize;
std::memcpy(db, label_digest, HashSize);
std::memset(db + HashSize, 0, dst_size - 2 * HashSize - 2 - src_size);
u8 *msg = buf + dst_size - src_size - 1;
*(msg++) = 0x01;
std::memcpy(msg, src, src_size);
ApplyMGF1(db, dst_size - (1 + HashSize), seed, HashSize);
ApplyMGF1(seed, HashSize, db, dst_size - (1 + HashSize));
}
size_t Decode(void *dst, size_t dst_size, const void *label_digest, size_t label_digest_size, u8 *buf, size_t buf_size) {
/* Check our preconditions. */
AMS_ABORT_UNLESS(dst_size > 0);
AMS_ABORT_UNLESS(buf_size >= 2 * HashSize + 3);
AMS_ABORT_UNLESS(label_digest_size == HashSize);
AMS_UNUSED(label_digest_size);
/* Validate sanity byte. */
bool is_valid = buf[0] == HeadMagic;
/* Decrypt seed and masked db. */
size_t db_len = buf_size - HashSize - 1;
u8 *seed = buf + 1;
u8 *db = seed + HashSize;
ApplyMGF1(seed, HashSize, db, db_len);
ApplyMGF1(db, db_len, seed, HashSize);
/* Check the label digest. */
is_valid &= IsSameBytes(label_digest, db, HashSize);
/* Skip past the label digest. */
db += HashSize;
db_len -= HashSize;
/* Verify that DB is of the form 0000...0001 < message > */
s32 msg_ofs = 0;
{
int looking_for_one = 1;
int invalid_db_padding = 0;
int is_zero;
int is_one;
for (size_t i = 0; i < db_len; /* ... */) {
is_zero = (db[i] == 0);
is_one = (db[i] == 1);
msg_ofs += (looking_for_one & is_one) * (static_cast<s32>(++i));
looking_for_one &= ~is_one;
invalid_db_padding |= (looking_for_one & ~is_zero);
}
is_valid &= (invalid_db_padding == 0);
}
/* If we're invalid, return zero size. */
const size_t valid_msg_size = db_len - msg_ofs;
const size_t msg_size = std::min(dst_size, static_cast<size_t>(is_valid) * valid_msg_size);
/* Copy to output. */
std::memcpy(dst, db + msg_ofs, msg_size);
/* Return copied size. */
return msg_size;
}
};
}

View File

@@ -1,94 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_hash_function.hpp>
namespace ams::crypto::impl {
template<HashFunction Hash>
class RsaPkcs1Impl {
NON_COPYABLE(RsaPkcs1Impl);
NON_MOVEABLE(RsaPkcs1Impl);
public:
static constexpr size_t HashSize = Hash::HashSize;
public:
RsaPkcs1Impl() { /* ... */ }
~RsaPkcs1Impl() { /* ... */ }
void BuildPad(void *out_block, size_t block_size, Hash *hash) {
AMS_ASSERT(block_size >= 2 + 1 + sizeof(Hash::Asn1Identifier) + HashSize);
u8 *dst = static_cast<u8 *>(out_block);
*(dst++) = 0x00;
*(dst++) = 0x01;
const size_t pad_len = block_size - (2 + 1 + sizeof(Hash::Asn1Identifier) + HashSize);
std::memset(dst, 0xFF, pad_len);
dst += pad_len;
*(dst++) = 0x00;
std::memcpy(dst, Hash::Asn1Identifier, sizeof(Hash::Asn1Identifier));
dst += sizeof(Hash::Asn1Identifier);
hash->GetHash(dst, HashSize);
}
bool CheckPad(const u8 *src, size_t block_size, Hash *hash) {
/* Check that block size is minimally big enough. */
if (block_size < 2 + 1 + sizeof(Hash::Asn1Identifier) + HashSize) {
return false;
}
/* Check that the padding if correctly of form 0001FF..FF00 */
if (*(src++) != 0x00) {
return false;
}
if (*(src++) != 0x01) {
return false;
}
const size_t pad_len = block_size - (2 + 1 + sizeof(Hash::Asn1Identifier) + HashSize);
for (size_t i = 0; i < pad_len; ++i) {
if (*(src++) != 0xFF) {
return false;
}
}
if (*(src++) != 0x00) {
return false;
}
/* Check that the asn1 identifier matches. */
if (std::memcmp(src, Hash::Asn1Identifier, sizeof(Hash::Asn1Identifier)) != 0) {
return false;
}
src += sizeof(Hash::Asn1Identifier);
/* Check the hash. */
u8 calc_hash[HashSize];
hash->GetHash(calc_hash, sizeof(calc_hash));
return std::memcmp(calc_hash, src, HashSize) == 0;
}
};
}

View File

@@ -1,127 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_hash_function.hpp>
namespace ams::crypto::impl {
template<HashFunction Hash>
class RsaPssImpl {
NON_COPYABLE(RsaPssImpl);
NON_MOVEABLE(RsaPssImpl);
public:
static constexpr size_t HashSize = Hash::HashSize;
private:
static constexpr u8 TailMagic = 0xBC;
private:
static void ComputeHashWithPadding(void *dst, const u8 *user_hash, size_t user_hash_size, const void *salt, size_t salt_size) {
AMS_ASSERT(user_hash_size == HashSize);
AMS_UNUSED(user_hash_size);
/* Initialize our buffer. */
u8 buf[8 + HashSize];
std::memset(buf, 0, 8);
std::memcpy(buf + 8, user_hash, HashSize);
ON_SCOPE_EXIT { ClearMemory(buf, sizeof(buf)); };
/* Calculate our hash. */
Hash hash;
hash.Initialize();
hash.Update(buf, sizeof(buf));
hash.Update(salt, salt_size);
hash.GetHash(dst, HashSize);
}
static void ApplyMGF1(u8 *dst, size_t dst_size, const void *src, size_t src_size) {
u8 buf[HashSize];
ON_SCOPE_EXIT { ClearMemory(buf, sizeof(buf)); };
const size_t required_iters = (dst_size + HashSize - 1) / HashSize;
for (size_t i = 0; i < required_iters; i++) {
Hash hash;
hash.Initialize();
hash.Update(src, src_size);
const u32 tmp = util::ConvertToBigEndian(static_cast<u32>(i));
hash.Update(std::addressof(tmp), sizeof(tmp));
hash.GetHash(buf, HashSize);
const size_t start = HashSize * i;
const size_t end = std::min(dst_size, start + HashSize);
for (size_t j = start; j < end; j++) {
dst[j] ^= buf[j - start];
}
}
}
public:
RsaPssImpl() { /* ... */ }
bool Verify(u8 *buf, size_t size, const u8 *hash, size_t hash_size) {
/* Validate sanity byte. */
bool is_valid = buf[size - 1] == TailMagic;
/* Decrypt maskedDB */
const size_t db_len = size - HashSize - 1;
u8 *db = buf;
u8 *h = db + db_len;
ApplyMGF1(db, db_len, h, HashSize);
/* Apply lmask. */
db[0] &= 0x7F;
/* Verify that DB is of the form 0000...0001 */
s32 salt_ofs = 0;
{
int looking_for_one = 1;
int invalid_db_padding = 0;
int is_zero;
int is_one;
for (size_t i = 0; i < db_len; /* ... */) {
is_zero = (db[i] == 0);
is_one = (db[i] == 1);
salt_ofs += (looking_for_one & is_one) * (static_cast<s32>(++i));
looking_for_one &= ~is_one;
invalid_db_padding |= (looking_for_one & ~is_zero);
}
is_valid &= (invalid_db_padding == 0);
}
/* Verify salt. */
const u8 *salt = db + salt_ofs;
const size_t salt_size = db_len - salt_ofs;
is_valid &= (salt_size != 0);
is_valid &= (salt_size != db_len);
/* Verify hash. */
u8 cmp_hash[HashSize];
ON_SCOPE_EXIT { ClearMemory(cmp_hash, sizeof(cmp_hash)); };
ComputeHashWithPadding(cmp_hash, hash, hash_size, salt, salt_size);
is_valid &= IsSameBytes(cmp_hash, h, HashSize);
/* Succeed if all our checks succeeded. */
return is_valid;
}
};
}

View File

@@ -1,60 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_hash_function.hpp>
#include <vapours/crypto/crypto_memory_clear.hpp>
namespace ams::crypto::impl {
class Sha1Impl {
public:
static constexpr size_t HashSize = 0x14;
static constexpr size_t BlockSize = 0x40;
private:
enum State {
State_None,
State_Initialized,
State_Done,
};
private:
u32 m_intermediate_hash[HashSize / sizeof(u32)];
u8 m_buffer[BlockSize];
size_t m_buffered_bytes;
u64 m_bits_consumed;
State m_state;
public:
Sha1Impl() : m_state(State_None) { /* ... */ }
~Sha1Impl() {
ClearMemory(this, sizeof(*this));
}
void Initialize();
void Update(const void *data, size_t size);
void GetHash(void *dst, size_t size);
private:
void ProcessBlock(const void *data);
void ProcessBlocks(const u8 *data, size_t block_count);
void ProcessLastBlock();
};
static_assert(HashFunction<Sha1Impl>);
}

View File

@@ -1,77 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_hash_function.hpp>
#include <vapours/crypto/crypto_memory_clear.hpp>
namespace ams::crypto {
struct Sha256Context;
}
namespace ams::crypto::impl {
class Sha256Impl {
public:
static constexpr size_t HashSize = 0x20;
static constexpr size_t BlockSize = 0x40;
private:
enum State {
State_None,
State_Initialized,
State_Done,
};
private:
u32 m_intermediate_hash[HashSize / sizeof(u32)];
u8 m_buffer[BlockSize];
size_t m_buffered_bytes;
u64 m_bits_consumed;
State m_state;
public:
Sha256Impl() : m_state(State_None) { /* ... */ }
~Sha256Impl() {
ClearMemory(this, sizeof(*this));
}
void Initialize();
void Update(const void *data, size_t size);
void GetHash(void *dst, size_t size);
void InitializeWithContext(const Sha256Context *context);
size_t GetContext(Sha256Context *context) const;
size_t GetBufferedDataSize() const { return m_buffered_bytes; }
void GetBufferedData(void *dst, size_t dst_size) const {
AMS_ASSERT(dst_size >= this->GetBufferedDataSize());
AMS_UNUSED(dst_size);
std::memcpy(dst, m_buffer, m_buffered_bytes);
}
private:
void ProcessBlock(const void *data);
void ProcessBlocks(const u8 *data, size_t block_count);
void ProcessLastBlock();
};
static_assert(HashFunction<Sha256Impl>);
}

View File

@@ -1,296 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
namespace ams::crypto::impl {
class Sha256CompileTimeImpl {
public:
static constexpr size_t HashSize = 0x20;
static constexpr size_t BlockSize = 0x40;
private:
enum State {
State_None,
State_Initialized,
State_Done,
};
private:
u32 m_intermediate_hash[HashSize / sizeof(u32)];
u8 m_buffer[BlockSize];
size_t m_buffered_bytes;
u64 m_bits_consumed;
State m_state;
public:
constexpr Sha256CompileTimeImpl() : m_intermediate_hash(), m_buffer(), m_buffered_bytes(), m_bits_consumed(), m_state(State_None) {
/* ... */
}
constexpr void Initialize() {
/* Reset buffered bytes/bits. */
m_buffered_bytes = 0;
m_bits_consumed = 0;
/* Set intermediate hash. */
m_intermediate_hash[0] = 0x6A09E667;
m_intermediate_hash[1] = 0xBB67AE85;
m_intermediate_hash[2] = 0x3C6EF372;
m_intermediate_hash[3] = 0xA54FF53A;
m_intermediate_hash[4] = 0x510E527F;
m_intermediate_hash[5] = 0x9B05688C;
m_intermediate_hash[6] = 0x1F83D9AB;
m_intermediate_hash[7] = 0x5BE0CD19;
/* Set state. */
m_state = State_Initialized;
}
template<typename T, typename = typename std::enable_if<std::same_as<T, u8> || std::same_as<T, s8> || std::same_as<T, char> || std::same_as<T, unsigned char>>::type>
constexpr void Update(const T *data, size_t size) {
static_assert(sizeof(T) == 1);
/* Verify we're in a state to update. */
AMS_ASSERT(m_state == State_Initialized);
/* Advance our input bit count. */
m_bits_consumed += BITSIZEOF(u8) * (((m_buffered_bytes + size) / BlockSize) * BlockSize);
/* Process anything we have buffered. */
size_t remaining = size;
if (m_buffered_bytes > 0) {
const size_t copy_size = std::min(BlockSize - m_buffered_bytes, remaining);
for (size_t i = 0; i < copy_size; ++i) {
m_buffer[m_buffered_bytes + i] = static_cast<u8>(data[i]);
}
data += copy_size;
remaining -= copy_size;
m_buffered_bytes += copy_size;
/* Process a block, if we filled one. */
if (m_buffered_bytes == BlockSize) {
this->ProcessBlock(m_buffer);
m_buffered_bytes = 0;
}
}
/* Process blocks, if we have any. */
while (remaining >= BlockSize) {
u8 block[BlockSize] = {};
for (size_t i = 0; i < BlockSize; ++i) {
block[i] = static_cast<u8>(data[i]);
}
this->ProcessBlock(block);
data += BlockSize;
remaining -= BlockSize;
}
/* Copy any leftover data to our buffer. */
if (remaining > 0) {
m_buffered_bytes = remaining;
for (size_t i = 0; i < remaining; ++i) {
m_buffer[i] = static_cast<u8>(data[i]);
}
}
}
constexpr void GetHash(u8 *dst, size_t size) {
/* Verify we're in a state to get hash. */
AMS_ASSERT(m_state == State_Initialized || m_state == State_Done);
AMS_ASSERT(size >= HashSize);
AMS_UNUSED(size);
/* If we need to, process the last block. */
if (m_state == State_Initialized) {
this->ProcessLastBlock();
m_state = State_Done;
}
/* Copy the output hash. */
for (size_t i = 0; i < HashSize / sizeof(u32); ++i) {
const u32 v = m_intermediate_hash[i];
dst[sizeof(u32) * i + 3] = static_cast<u8>(v >> (BITSIZEOF(u8) * 0));
dst[sizeof(u32) * i + 2] = static_cast<u8>(v >> (BITSIZEOF(u8) * 1));
dst[sizeof(u32) * i + 1] = static_cast<u8>(v >> (BITSIZEOF(u8) * 2));
dst[sizeof(u32) * i + 0] = static_cast<u8>(v >> (BITSIZEOF(u8) * 3));
}
}
constexpr size_t GetBufferedDataSize() const { return m_buffered_bytes; }
constexpr void GetBufferedData(u8 *dst, size_t dst_size) const {
AMS_ASSERT(dst_size >= this->GetBufferedDataSize());
AMS_UNUSED(dst_size);
for (size_t i = 0; i < m_buffered_bytes; ++i) {
dst[i] = m_buffer[i];
}
}
private:
static constexpr ALWAYS_INLINE u32 Choose(u32 x, u32 y, u32 z) {
return (x & y) ^ ((~x) & z);
}
static constexpr ALWAYS_INLINE u32 Majority(u32 x, u32 y, u32 z) {
return (x & y) ^ (x & z) ^ (y & z);
}
static constexpr ALWAYS_INLINE u32 LargeSigma0(u32 x) {
return util::RotateRight<u32>(x, 2) ^ util::RotateRight<u32>(x, 13) ^ util::RotateRight<u32>(x, 22);
}
static constexpr ALWAYS_INLINE u32 LargeSigma1(u32 x) {
return util::RotateRight<u32>(x, 6) ^ util::RotateRight<u32>(x, 11) ^ util::RotateRight<u32>(x, 25);
}
static constexpr ALWAYS_INLINE u32 SmallSigma0(u32 x) {
return util::RotateRight<u32>(x, 7) ^ util::RotateRight<u32>(x, 18) ^ (x >> 3);
}
static constexpr ALWAYS_INLINE u32 SmallSigma1(u32 x) {
return util::RotateRight<u32>(x, 17) ^ util::RotateRight<u32>(x, 19) ^ (x >> 10);
}
constexpr void ProcessBlock(const u8 *data) {
/* Load work variables. */
u32 a = m_intermediate_hash[0];
u32 b = m_intermediate_hash[1];
u32 c = m_intermediate_hash[2];
u32 d = m_intermediate_hash[3];
u32 e = m_intermediate_hash[4];
u32 f = m_intermediate_hash[5];
u32 g = m_intermediate_hash[6];
u32 h = m_intermediate_hash[7];
u32 tmp[2]{};
size_t i = 0;
/* Copy the input. */
u32 w[64]{};
for (size_t i = 0; i < BlockSize / sizeof(u32); ++i) {
u32 v = 0;
v |= static_cast<u32>(data[sizeof(u32) * i + 0]) << (BITSIZEOF(u8) * 3);
v |= static_cast<u32>(data[sizeof(u32) * i + 1]) << (BITSIZEOF(u8) * 2);
v |= static_cast<u32>(data[sizeof(u32) * i + 2]) << (BITSIZEOF(u8) * 1);
v |= static_cast<u32>(data[sizeof(u32) * i + 3]) << (BITSIZEOF(u8) * 0);
w[i] = v;
}
/* Initialize the rest of w. */
for (i = BlockSize / sizeof(u32); i < util::size(w); ++i) {
const u32 *prev = w + (i - BlockSize / sizeof(u32));
w[i] = prev[0] + SmallSigma0(prev[1]) + prev[9] + SmallSigma1(prev[14]);
}
/* Perform rounds. */
{
const u32 RoundConstants[0x40] = {
0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2,
};
for (i = 0; i < 64; ++i) {
tmp[0] = h + LargeSigma1(e) + Choose(e, f, g) + RoundConstants[i] + w[i];
tmp[1] = LargeSigma0(a) + Majority(a, b, c);
h = g;
g = f;
f = e;
e = d + tmp[0];
d = c;
c = b;
b = a;
a = tmp[0] + tmp[1];
}
}
/* Update intermediate hash. */
m_intermediate_hash[0] += a;
m_intermediate_hash[1] += b;
m_intermediate_hash[2] += c;
m_intermediate_hash[3] += d;
m_intermediate_hash[4] += e;
m_intermediate_hash[5] += f;
m_intermediate_hash[6] += g;
m_intermediate_hash[7] += h;
}
constexpr void ProcessLastBlock() {
/* Setup the final block. */
constexpr const auto BlockSizeWithoutSizeField = BlockSize - sizeof(u64);
/* Increment our bits consumed. */
m_bits_consumed += BITSIZEOF(u8) * m_buffered_bytes;
/* Add 0x80 terminator. */
m_buffer[m_buffered_bytes++] = 0x80;
/* If we can process the size field directly, do so, otherwise set up to process it. */
if (m_buffered_bytes <= BlockSizeWithoutSizeField) {
/* Clear up to size field. */
for (size_t i = 0; i < BlockSizeWithoutSizeField - m_buffered_bytes; ++i) {
m_buffer[m_buffered_bytes + i] = 0;
}
} else {
/* Consume full block */
for (size_t i = 0; i < BlockSize - m_buffered_bytes; ++i) {
m_buffer[m_buffered_bytes + i] = 0;
}
this->ProcessBlock(m_buffer);
/* Clear up to size field. */
for (size_t i = 0; i < BlockSizeWithoutSizeField; ++i) {
m_buffer[i] = 0;
}
}
/* Store the size field. */
m_buffer[BlockSizeWithoutSizeField + 0] = static_cast<u8>((m_bits_consumed >> (BITSIZEOF(u8) * 7)) & 0xFF);
m_buffer[BlockSizeWithoutSizeField + 1] = static_cast<u8>((m_bits_consumed >> (BITSIZEOF(u8) * 6)) & 0xFF);
m_buffer[BlockSizeWithoutSizeField + 2] = static_cast<u8>((m_bits_consumed >> (BITSIZEOF(u8) * 5)) & 0xFF);
m_buffer[BlockSizeWithoutSizeField + 3] = static_cast<u8>((m_bits_consumed >> (BITSIZEOF(u8) * 4)) & 0xFF);
m_buffer[BlockSizeWithoutSizeField + 4] = static_cast<u8>((m_bits_consumed >> (BITSIZEOF(u8) * 3)) & 0xFF);
m_buffer[BlockSizeWithoutSizeField + 5] = static_cast<u8>((m_bits_consumed >> (BITSIZEOF(u8) * 2)) & 0xFF);
m_buffer[BlockSizeWithoutSizeField + 6] = static_cast<u8>((m_bits_consumed >> (BITSIZEOF(u8) * 1)) & 0xFF);
m_buffer[BlockSizeWithoutSizeField + 7] = static_cast<u8>((m_bits_consumed >> (BITSIZEOF(u8) * 0)) & 0xFF);
/* Process the final block. */
this->ProcessBlock(m_buffer);
}
};
}

View File

@@ -1,70 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_hash_function.hpp>
#include <vapours/crypto/crypto_memory_clear.hpp>
namespace ams::crypto {
struct Sha3Context;
}
namespace ams::crypto::impl {
template<size_t _HashSize>
class Sha3Impl {
public:
static constexpr size_t InternalStateSize = 200;
static constexpr size_t HashSize = _HashSize;
static constexpr size_t BlockSize = InternalStateSize - 2 * HashSize;
private:
enum State {
State_None,
State_Initialized,
State_Done,
};
private:
u64 m_internal_state[InternalStateSize / sizeof(u64)];
size_t m_buffered_bytes;
State m_state;
public:
Sha3Impl() : m_state(State_None) { /* ... */ }
~Sha3Impl() {
ClearMemory(this, sizeof(*this));
}
void Initialize();
void Update(const void *data, size_t size);
void GetHash(void *dst, size_t size);
void InitializeWithContext(const Sha3Context *context);
void GetContext(Sha3Context *context) const;
private:
void ProcessBlock();
void ProcessLastBlock();
};
static_assert(HashFunction<Sha3Impl<224 / BITSIZEOF(u8)>>);
static_assert(HashFunction<Sha3Impl<256 / BITSIZEOF(u8)>>);
static_assert(HashFunction<Sha3Impl<384 / BITSIZEOF(u8)>>);
static_assert(HashFunction<Sha3Impl<512 / BITSIZEOF(u8)>>);
}

View File

@@ -1,138 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/crypto_memory_clear.hpp>
#include <vapours/crypto/crypto_aes_encryptor.hpp>
namespace ams::crypto::impl {
class XtsModeImpl {
NON_COPYABLE(XtsModeImpl);
NON_MOVEABLE(XtsModeImpl);
public:
/* TODO: More generic support. */
static constexpr size_t BlockSize = 16;
static constexpr size_t IvSize = 16;
private:
enum State {
State_None,
State_Initialized,
State_Processing,
State_Done
};
private:
u8 m_buffer[BlockSize];
u8 m_tweak[BlockSize];
u8 m_last_block[BlockSize];
size_t m_num_buffered;
const void *m_cipher_ctx;
void (*m_cipher_func)(void *dst_block, const void *src_block, const void *cipher_ctx);
State m_state;
public:
XtsModeImpl() : m_num_buffered(0), m_state(State_None) { /* ... */ }
~XtsModeImpl() {
ClearMemory(this, sizeof(*this));
}
private:
template<typename BlockCipher>
static void EncryptBlockCallback(void *dst_block, const void *src_block, const void *cipher) {
return static_cast<const BlockCipher *>(cipher)->EncryptBlock(dst_block, BlockCipher::BlockSize, src_block, BlockCipher::BlockSize);
}
template<typename BlockCipher>
static void DecryptBlockCallback(void *dst_block, const void *src_block, const void *cipher) {
return static_cast<const BlockCipher *>(cipher)->DecryptBlock(dst_block, BlockCipher::BlockSize, src_block, BlockCipher::BlockSize);
}
template<typename BlockCipher>
void Initialize(const BlockCipher *cipher, const void *tweak, size_t tweak_size) {
AMS_ASSERT(tweak_size == IvSize);
AMS_UNUSED(tweak_size);
cipher->EncryptBlock(m_tweak, IvSize, tweak, IvSize);
m_num_buffered = 0;
m_state = State_Initialized;
}
void ProcessBlock(u8 *dst, const u8 *src);
public:
template<typename BlockCipher1, typename BlockCipher2>
void InitializeEncryption(const BlockCipher1 *cipher1, const BlockCipher2 *cipher2, const void *tweak, size_t tweak_size) {
static_assert(BlockCipher1::BlockSize == BlockSize);
static_assert(BlockCipher2::BlockSize == BlockSize);
m_cipher_ctx = cipher1;
m_cipher_func = EncryptBlockCallback<BlockCipher1>;
this->Initialize(cipher2, tweak, tweak_size);
}
template<typename BlockCipher1, typename BlockCipher2>
void InitializeDecryption(const BlockCipher1 *cipher1, const BlockCipher2 *cipher2, const void *tweak, size_t tweak_size) {
static_assert(BlockCipher1::BlockSize == BlockSize);
static_assert(BlockCipher2::BlockSize == BlockSize);
m_cipher_ctx = cipher1;
m_cipher_func = DecryptBlockCallback<BlockCipher1>;
this->Initialize(cipher2, tweak, tweak_size);
}
template<typename BlockCipher>
size_t Update(void *dst, size_t dst_size, const void *src, size_t src_size) {
return this->UpdateGeneric(dst, dst_size, src, src_size);
}
template<typename BlockCipher>
size_t ProcessBlocks(u8 *dst, const u8 *src, size_t num_blocks) {
return this->ProcessBlocksGeneric(dst, src, num_blocks);
}
size_t GetBufferedDataSize() const {
return m_num_buffered;
}
constexpr size_t GetBlockSize() const {
return BlockSize;
}
size_t FinalizeEncryption(void *dst, size_t dst_size);
size_t FinalizeDecryption(void *dst, size_t dst_size);
size_t UpdateGeneric(void *dst, size_t dst_size, const void *src, size_t src_size);
size_t ProcessBlocksGeneric(u8 *dst, const u8 *src, size_t num_blocks);
size_t ProcessPartialData(u8 *dst, const u8 *src, size_t size);
size_t ProcessRemainingData(u8 *dst, const u8 *src, size_t size);
};
#if defined(ATMOSPHERE_ARCH_ARM64)
template<> size_t XtsModeImpl::Update<AesEncryptor128>(void *dst, size_t dst_size, const void *src, size_t src_size);
template<> size_t XtsModeImpl::Update<AesEncryptor192>(void *dst, size_t dst_size, const void *src, size_t src_size);
template<> size_t XtsModeImpl::Update<AesEncryptor256>(void *dst, size_t dst_size, const void *src, size_t src_size);
template<> size_t XtsModeImpl::Update<AesDecryptor128>(void *dst, size_t dst_size, const void *src, size_t src_size);
template<> size_t XtsModeImpl::Update<AesDecryptor192>(void *dst, size_t dst_size, const void *src, size_t src_size);
template<> size_t XtsModeImpl::Update<AesDecryptor256>(void *dst, size_t dst_size, const void *src, size_t src_size);
#endif
}

View File

@@ -1,24 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/results.hpp>
#include <vapours/dd/dd_common_types.hpp>
#include <vapours/dd/dd_io_mapping.hpp>
#include <vapours/dd/dd_cache.hpp>

View File

@@ -1,25 +0,0 @@
/*
* Copyright (c) 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/dd/dd_common_types.hpp>
namespace ams::dd {
void InvalidateDataCache(void *addr, size_t size);
void StoreDataCache(void *addr, size_t size);
void FlushDataCache(void *addr, size_t size);
}

View File

@@ -1,31 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/results.hpp>
namespace ams::dd {
using PhysicalAddress = u64;
using DeviceVirtualAddress = u64;
#if defined(ATMOSPHERE_OS_HORIZON)
static_assert(std::same_as<PhysicalAddress, ams::svc::PhysicalAddress>);
#endif
}

View File

@@ -1,27 +0,0 @@
/*
* Copyright (c) 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/dd/dd_common_types.hpp>
namespace ams::dd {
uintptr_t QueryIoMapping(dd::PhysicalAddress phys_addr, size_t size);
u32 ReadIoRegister(dd::PhysicalAddress phys_addr);
void WriteIoRegister(dd::PhysicalAddress phys_addr, u32 value);
u32 ReadModifyWriteIoRegister(PhysicalAddress phys_addr, u32 value, u32 mask);
}

View File

@@ -1,137 +0,0 @@
/*
* Copyright (c) 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/includes.hpp>
/* Any broadly useful language defines should go here. */
#if defined(ATMOSPHERE_OS_WINDOWS)
#if defined(ATMOSPHERE_ARCH_ARM64) || defined(ATMOSPHERE_ARCH_X64)
static_assert(sizeof(size_t) == sizeof(uint64_t));
#define PRIuZ PRIu64
#define PRIxZ PRIx64
#define PRIXZ PRIX64
#elif defined(ATMOSPHERE_ARCH_ARM) || defined(ATMOSPHERE_ARCH_X86)
static_assert(sizeof(size_t) == sizeof(uint32_t));
#define PRIuZ PRIu32
#define PRIxZ PRIx32
#define PRIXZ PRIX32
#endif
#else
#define PRIuZ "zu"
#define PRIxZ "zx"
#define PRIXZ "zX"
#endif
#if defined(__clang__)
#define ATMOSPHERE_COMPILER_CLANG
#elif defined(__GNUG__) || defined(__GNUC__)
#define ATMOSPHERE_COMPILER_GCC
#else
#error "Unknown compiler!"
#endif
#define NON_COPYABLE(cls) \
cls(const cls&) = delete; \
cls& operator=(const cls&) = delete
#define NON_MOVEABLE(cls) \
cls(cls&&) = delete; \
cls& operator=(cls&&) = delete
#define ALIGNED(algn) __attribute__((aligned(algn)))
#define NORETURN __attribute__((noreturn))
#define WEAK_SYMBOL __attribute__((weak))
#define ALWAYS_INLINE_LAMBDA __attribute__((always_inline))
#define ALWAYS_INLINE inline __attribute__((always_inline))
#define NOINLINE __attribute__((noinline))
#define CONCATENATE_IMPL(s1, s2) s1##s2
#define CONCATENATE(s1, s2) CONCATENATE_IMPL(s1, s2)
#define BITSIZEOF(x) (sizeof(x) * CHAR_BIT)
#define STRINGIZE(x) STRINGIZE_IMPL(x)
#define STRINGIZE_IMPL(x) #x
#ifndef PACKED
#define PACKED __attribute__((packed))
#endif
#ifdef __COUNTER__
#define ANONYMOUS_VARIABLE(pref) CONCATENATE(pref, __COUNTER__)
#else
#define ANONYMOUS_VARIABLE(pref) CONCATENATE(pref, __LINE__)
#endif
#define AMS_PREDICT(expr, value, _probability) __builtin_expect_with_probability(expr, value, ({ \
constexpr double probability = _probability; \
static_assert(0.0 <= probability); \
static_assert(probability <= 1.0); \
probability; \
}))
#define AMS_PREDICT_TRUE(expr, probability) AMS_PREDICT(!!(expr), 1, probability)
#define AMS_PREDICT_FALSE(expr, probability) AMS_PREDICT(!!(expr), 0, probability)
#define AMS_LIKELY(expr) AMS_PREDICT_TRUE(expr, 1.0)
#define AMS_UNLIKELY(expr) AMS_PREDICT_FALSE(expr, 1.0)
#define AMS_ASSUME(expr) do { if (!static_cast<bool>((expr))) { __builtin_unreachable(); } } while (0)
#define AMS_CURRENT_FUNCTION_NAME __FUNCTION__
#if defined(__cplusplus)
namespace ams::impl {
template<typename... ArgTypes>
constexpr ALWAYS_INLINE void UnusedImpl(ArgTypes &&... args) {
(static_cast<void>(args), ...);
}
}
#endif
#define AMS_UNUSED(...) ::ams::impl::UnusedImpl(__VA_ARGS__)
#define AMS_INFINITE_LOOP() do { __asm__ __volatile__("" ::: "memory"); } while (1)
#define AMS__NARG__(...) AMS__NARG_I_(__VA_ARGS__,AMS__RSEQ_N())
#define AMS__NARG_I_(...) AMS__ARG_N(__VA_ARGS__)
#define AMS__ARG_N( \
_1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \
_11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
_21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
_31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
_41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
_51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
_61,_62,_63,N,...) N
#define AMS__RSEQ_N() \
63,62,61,60, \
59,58,57,56,55,54,53,52,51,50, \
49,48,47,46,45,44,43,42,41,40, \
39,38,37,36,35,34,33,32,31,30, \
29,28,27,26,25,24,23,22,21,20, \
19,18,17,16,15,14,13,12,11,10, \
9,8,7,6,5,4,3,2,1,0
#define AMS__VMACRO_(name, n) name##_##n
#define AMS__VMACRO(name, n) AMS__VMACRO_(name, n)
#define AMS_VMACRO(func, ...) AMS__VMACRO(func, AMS__NARG__(__VA_ARGS__)) (__VA_ARGS__)

View File

@@ -1,49 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
namespace ams {
namespace impl {
using DeviceCodeType = u32;
}
/* TODO: Better understand device code components. */
class DeviceCode {
private:
impl::DeviceCodeType m_inner_value;
public:
constexpr DeviceCode(impl::DeviceCodeType v) : m_inner_value(v) { /* ... */ }
constexpr impl::DeviceCodeType GetInternalValue() const { return m_inner_value; }
constexpr bool operator==(const DeviceCode &rhs) const {
return this->GetInternalValue() == rhs.GetInternalValue();
}
constexpr bool operator!=(const DeviceCode &rhs) const {
return !(*this == rhs);
}
};
constexpr inline const DeviceCode InvalidDeviceCode(0);
}

View File

@@ -1,628 +0,0 @@
/* $NetBSD: tree.h,v 1.8 2004/03/28 19:38:30 provos Exp $ */
/* $OpenBSD: tree.h,v 1.7 2002/10/17 21:51:54 art Exp $ */
/* $FreeBSD$ */
/*-
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <vapours/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util/util_type_traits.hpp>
AMS_PRAGMA_BEGIN_OPTIMIZE("-O3")
/*
* This file defines data structures for red-black trees.
*
* A red-black tree is a binary search tree with the node color as an
* extra attribute. It fulfills a set of conditions:
* - every search path from the root to a leaf consists of the
* same number of black nodes,
* - each red node (except for the root) has a black parent,
* - each leaf node is black.
*
* Every operation on a red-black tree is bounded as O(lg n).
* The maximum height of a red-black tree is 2lg (n+1).
*/
namespace ams::freebsd {
enum class RBColor {
RB_BLACK = 0,
RB_RED = 1,
};
#pragma pack(push, 4)
template<typename T>
class RBEntry {
private:
T *m_rbe_left ;
T *m_rbe_right;
T *m_rbe_parent;
RBColor m_rbe_color;
public:
constexpr ALWAYS_INLINE explicit RBEntry(util::ConstantInitializeTag) : m_rbe_left(nullptr), m_rbe_right(nullptr), m_rbe_parent(nullptr), m_rbe_color(RBColor::RB_BLACK) { /* ... */ }
explicit ALWAYS_INLINE RBEntry() { /* ... */ }
[[nodiscard]] constexpr ALWAYS_INLINE T *Left() { return m_rbe_left; }
[[nodiscard]] constexpr ALWAYS_INLINE const T *Left() const { return m_rbe_left; }
constexpr ALWAYS_INLINE void SetLeft(T *e) { m_rbe_left = e; }
[[nodiscard]] constexpr ALWAYS_INLINE T *Right() { return m_rbe_right; }
[[nodiscard]] constexpr ALWAYS_INLINE const T *Right() const { return m_rbe_right; }
constexpr ALWAYS_INLINE void SetRight(T *e) { m_rbe_right = e; }
[[nodiscard]] constexpr ALWAYS_INLINE T *Parent() { return m_rbe_parent; }
[[nodiscard]] constexpr ALWAYS_INLINE const T *Parent() const { return m_rbe_parent; }
constexpr ALWAYS_INLINE void SetParent(T *e) { m_rbe_parent = e; }
[[nodiscard]] constexpr ALWAYS_INLINE bool IsBlack() const { return m_rbe_color == RBColor::RB_BLACK; }
[[nodiscard]] constexpr ALWAYS_INLINE bool IsRed() const { return m_rbe_color == RBColor::RB_RED; }
[[nodiscard]] constexpr ALWAYS_INLINE RBColor Color() const { return m_rbe_color; }
constexpr ALWAYS_INLINE void SetColor(RBColor c) { m_rbe_color = c; }
};
#pragma pack(pop)
template<typename T> struct CheckRBEntry { static constexpr bool value = false; };
template<typename T> struct CheckRBEntry<RBEntry<T>> { static constexpr bool value = true; };
template<typename T>
concept IsRBEntry = CheckRBEntry<T>::value;
template<typename T>
concept HasRBEntry = requires (T &t, const T &ct) {
{ t.GetRBEntry() } -> std::same_as< RBEntry<T> &>;
{ ct.GetRBEntry() } -> std::same_as<const RBEntry<T> &>;
};
template<typename T> requires HasRBEntry<T>
class RBHead {
private:
T *m_rbh_root = nullptr;
public:
[[nodiscard]] constexpr ALWAYS_INLINE T *Root() { return m_rbh_root; }
[[nodiscard]] constexpr ALWAYS_INLINE const T *Root() const { return m_rbh_root; }
constexpr ALWAYS_INLINE void SetRoot(T *root) { m_rbh_root = root; }
[[nodiscard]] constexpr ALWAYS_INLINE bool IsEmpty() const { return this->Root() == nullptr; }
};
template<typename T> requires HasRBEntry<T> [[nodiscard]] constexpr ALWAYS_INLINE RBEntry<T> &RB_ENTRY( T *t) { return t->GetRBEntry(); }
template<typename T> requires HasRBEntry<T> [[nodiscard]] constexpr ALWAYS_INLINE const RBEntry<T> &RB_ENTRY(const T *t) { return t->GetRBEntry(); }
template<typename T> requires HasRBEntry<T> [[nodiscard]] constexpr ALWAYS_INLINE T *RB_LEFT( T *t) { return RB_ENTRY(t).Left(); }
template<typename T> requires HasRBEntry<T> [[nodiscard]] constexpr ALWAYS_INLINE const T *RB_LEFT(const T *t) { return RB_ENTRY(t).Left(); }
template<typename T> requires HasRBEntry<T> [[nodiscard]] constexpr ALWAYS_INLINE T *RB_RIGHT( T *t) { return RB_ENTRY(t).Right(); }
template<typename T> requires HasRBEntry<T> [[nodiscard]] constexpr ALWAYS_INLINE const T *RB_RIGHT(const T *t) { return RB_ENTRY(t).Right(); }
template<typename T> requires HasRBEntry<T> [[nodiscard]] constexpr ALWAYS_INLINE T *RB_PARENT( T *t) { return RB_ENTRY(t).Parent(); }
template<typename T> requires HasRBEntry<T> [[nodiscard]] constexpr ALWAYS_INLINE const T *RB_PARENT(const T *t) { return RB_ENTRY(t).Parent(); }
template<typename T> requires HasRBEntry<T> constexpr ALWAYS_INLINE void RB_SET_LEFT(T *t, T *e) { RB_ENTRY(t).SetLeft(e); }
template<typename T> requires HasRBEntry<T> constexpr ALWAYS_INLINE void RB_SET_RIGHT(T *t, T *e) { RB_ENTRY(t).SetRight(e); }
template<typename T> requires HasRBEntry<T> constexpr ALWAYS_INLINE void RB_SET_PARENT(T *t, T *e) { RB_ENTRY(t).SetParent(e); }
template<typename T> requires HasRBEntry<T> [[nodiscard]] constexpr ALWAYS_INLINE bool RB_IS_BLACK(const T *t) { return RB_ENTRY(t).IsBlack(); }
template<typename T> requires HasRBEntry<T> [[nodiscard]] constexpr ALWAYS_INLINE bool RB_IS_RED(const T *t) { return RB_ENTRY(t).IsRed(); }
template<typename T> requires HasRBEntry<T> [[nodiscard]] constexpr ALWAYS_INLINE RBColor RB_COLOR(const T *t) { return RB_ENTRY(t).Color(); }
template<typename T> requires HasRBEntry<T> constexpr ALWAYS_INLINE void RB_SET_COLOR(T *t, RBColor c) { RB_ENTRY(t).SetColor(c); }
template<typename T> requires HasRBEntry<T>
constexpr ALWAYS_INLINE void RB_SET(T *elm, T *parent) {
auto &rb_entry = RB_ENTRY(elm);
rb_entry.SetParent(parent);
rb_entry.SetLeft(nullptr);
rb_entry.SetRight(nullptr);
rb_entry.SetColor(RBColor::RB_RED);
}
template<typename T> requires HasRBEntry<T>
constexpr ALWAYS_INLINE void RB_SET_BLACKRED(T *black, T *red) {
RB_SET_COLOR(black, RBColor::RB_BLACK);
RB_SET_COLOR(red, RBColor::RB_RED);
}
template<typename T> requires HasRBEntry<T>
constexpr ALWAYS_INLINE void RB_ROTATE_LEFT(RBHead<T> &head, T *elm, T *&tmp) {
tmp = RB_RIGHT(elm);
if (RB_SET_RIGHT(elm, RB_LEFT(tmp)); RB_RIGHT(elm) != nullptr) {
RB_SET_PARENT(RB_LEFT(tmp), elm);
}
if (RB_SET_PARENT(tmp, RB_PARENT(elm)); RB_PARENT(tmp) != nullptr) {
if (elm == RB_LEFT(RB_PARENT(elm))) {
RB_SET_LEFT(RB_PARENT(elm), tmp);
} else {
RB_SET_RIGHT(RB_PARENT(elm), tmp);
}
} else {
head.SetRoot(tmp);
}
RB_SET_LEFT(tmp, elm);
RB_SET_PARENT(elm, tmp);
}
template<typename T> requires HasRBEntry<T>
constexpr ALWAYS_INLINE void RB_ROTATE_RIGHT(RBHead<T> &head, T *elm, T *&tmp) {
tmp = RB_LEFT(elm);
if (RB_SET_LEFT(elm, RB_RIGHT(tmp)); RB_LEFT(elm) != nullptr) {
RB_SET_PARENT(RB_RIGHT(tmp), elm);
}
if (RB_SET_PARENT(tmp, RB_PARENT(elm)); RB_PARENT(tmp) != nullptr) {
if (elm == RB_LEFT(RB_PARENT(elm))) {
RB_SET_LEFT(RB_PARENT(elm), tmp);
} else {
RB_SET_RIGHT(RB_PARENT(elm), tmp);
}
} else {
head.SetRoot(tmp);
}
RB_SET_RIGHT(tmp, elm);
RB_SET_PARENT(elm, tmp);
}
template <typename T> requires HasRBEntry<T>
constexpr void RB_REMOVE_COLOR(RBHead<T> &head, T *parent, T *elm) {
T *tmp;
while ((elm == nullptr || RB_IS_BLACK(elm)) && elm != head.Root()) {
if (RB_LEFT(parent) == elm) {
tmp = RB_RIGHT(parent);
if (RB_IS_RED(tmp)) {
RB_SET_BLACKRED(tmp, parent);
RB_ROTATE_LEFT(head, parent, tmp);
tmp = RB_RIGHT(parent);
}
if ((RB_LEFT(tmp) == nullptr || RB_IS_BLACK(RB_LEFT(tmp))) &&
(RB_RIGHT(tmp) == nullptr || RB_IS_BLACK(RB_RIGHT(tmp)))) {
RB_SET_COLOR(tmp, RBColor::RB_RED);
elm = parent;
parent = RB_PARENT(elm);
} else {
if (RB_RIGHT(tmp) == nullptr || RB_IS_BLACK(RB_RIGHT(tmp))) {
T *oleft;
if ((oleft = RB_LEFT(tmp)) != nullptr) {
RB_SET_COLOR(oleft, RBColor::RB_BLACK);
}
RB_SET_COLOR(tmp, RBColor::RB_RED);
RB_ROTATE_RIGHT(head, tmp, oleft);
tmp = RB_RIGHT(parent);
}
RB_SET_COLOR(tmp, RB_COLOR(parent));
RB_SET_COLOR(parent, RBColor::RB_BLACK);
if (RB_RIGHT(tmp)) {
RB_SET_COLOR(RB_RIGHT(tmp), RBColor::RB_BLACK);
}
RB_ROTATE_LEFT(head, parent, tmp);
elm = head.Root();
break;
}
} else {
tmp = RB_LEFT(parent);
if (RB_IS_RED(tmp)) {
RB_SET_BLACKRED(tmp, parent);
RB_ROTATE_RIGHT(head, parent, tmp);
tmp = RB_LEFT(parent);
}
if ((RB_LEFT(tmp) == nullptr || RB_IS_BLACK(RB_LEFT(tmp))) &&
(RB_RIGHT(tmp) == nullptr || RB_IS_BLACK(RB_RIGHT(tmp)))) {
RB_SET_COLOR(tmp, RBColor::RB_RED);
elm = parent;
parent = RB_PARENT(elm);
} else {
if (RB_LEFT(tmp) == nullptr || RB_IS_BLACK(RB_LEFT(tmp))) {
T *oright;
if ((oright = RB_RIGHT(tmp)) != nullptr) {
RB_SET_COLOR(oright, RBColor::RB_BLACK);
}
RB_SET_COLOR(tmp, RBColor::RB_RED);
RB_ROTATE_LEFT(head, tmp, oright);
tmp = RB_LEFT(parent);
}
RB_SET_COLOR(tmp, RB_COLOR(parent));
RB_SET_COLOR(parent, RBColor::RB_BLACK);
if (RB_LEFT(tmp)) {
RB_SET_COLOR(RB_LEFT(tmp), RBColor::RB_BLACK);
}
RB_ROTATE_RIGHT(head, parent, tmp);
elm = head.Root();
break;
}
}
}
if (elm) {
RB_SET_COLOR(elm, RBColor::RB_BLACK);
}
}
template <typename T> requires HasRBEntry<T>
constexpr T *RB_REMOVE(RBHead<T> &head, T *elm) {
T *child = nullptr;
T *parent = nullptr;
T *old = elm;
RBColor color = RBColor::RB_BLACK;
if (RB_LEFT(elm) == nullptr) {
child = RB_RIGHT(elm);
} else if (RB_RIGHT(elm) == nullptr) {
child = RB_LEFT(elm);
} else {
T *left;
elm = RB_RIGHT(elm);
while ((left = RB_LEFT(elm)) != nullptr) {
elm = left;
}
child = RB_RIGHT(elm);
parent = RB_PARENT(elm);
color = RB_COLOR(elm);
if (child) {
RB_SET_PARENT(child, parent);
}
if (parent) {
if (RB_LEFT(parent) == elm) {
RB_SET_LEFT(parent, child);
} else {
RB_SET_RIGHT(parent, child);
}
} else {
head.SetRoot(child);
}
if (RB_PARENT(elm) == old) {
parent = elm;
}
elm->SetRBEntry(old->GetRBEntry());
if (RB_PARENT(old)) {
if (RB_LEFT(RB_PARENT(old)) == old) {
RB_SET_LEFT(RB_PARENT(old), elm);
} else {
RB_SET_RIGHT(RB_PARENT(old), elm);
}
} else {
head.SetRoot(elm);
}
RB_SET_PARENT(RB_LEFT(old), elm);
if (RB_RIGHT(old)) {
RB_SET_PARENT(RB_RIGHT(old), elm);
}
if (parent) {
left = parent;
}
if (color == RBColor::RB_BLACK) {
RB_REMOVE_COLOR(head, parent, child);
}
return old;
}
parent = RB_PARENT(elm);
color = RB_COLOR(elm);
if (child) {
RB_SET_PARENT(child, parent);
}
if (parent) {
if (RB_LEFT(parent) == elm) {
RB_SET_LEFT(parent, child);
} else {
RB_SET_RIGHT(parent, child);
}
} else {
head.SetRoot(child);
}
if (color == RBColor::RB_BLACK) {
RB_REMOVE_COLOR(head, parent, child);
}
return old;
}
template<typename T> requires HasRBEntry<T>
constexpr void RB_INSERT_COLOR(RBHead<T> &head, T *elm) {
T *parent = nullptr, *tmp = nullptr;
while ((parent = RB_PARENT(elm)) != nullptr && RB_IS_RED(parent)) {
T *gparent = RB_PARENT(parent);
if (parent == RB_LEFT(gparent)) {
tmp = RB_RIGHT(gparent);
if (tmp && RB_IS_RED(tmp)) {
RB_SET_COLOR(tmp, RBColor::RB_BLACK);
RB_SET_BLACKRED(parent, gparent);
elm = gparent;
continue;
}
if (RB_RIGHT(parent) == elm) {
RB_ROTATE_LEFT(head, parent, tmp);
tmp = parent;
parent = elm;
elm = tmp;
}
RB_SET_BLACKRED(parent, gparent);
RB_ROTATE_RIGHT(head, gparent, tmp);
} else {
tmp = RB_LEFT(gparent);
if (tmp && RB_IS_RED(tmp)) {
RB_SET_COLOR(tmp, RBColor::RB_BLACK);
RB_SET_BLACKRED(parent, gparent);
elm = gparent;
continue;
}
if (RB_LEFT(parent) == elm) {
RB_ROTATE_RIGHT(head, parent, tmp);
tmp = parent;
parent = elm;
elm = tmp;
}
RB_SET_BLACKRED(parent, gparent);
RB_ROTATE_LEFT(head, gparent, tmp);
}
}
RB_SET_COLOR(head.Root(), RBColor::RB_BLACK);
}
template <typename T, typename Compare> requires HasRBEntry<T>
constexpr ALWAYS_INLINE T *RB_INSERT(RBHead<T> &head, T *elm, Compare cmp) {
T *parent = nullptr;
T *tmp = head.Root();
int comp = 0;
while (tmp) {
parent = tmp;
comp = cmp(elm, parent);
if (comp < 0) {
tmp = RB_LEFT(tmp);
} else if (comp > 0) {
tmp = RB_RIGHT(tmp);
} else {
return tmp;
}
}
RB_SET(elm, parent);
if (parent != nullptr) {
if (comp < 0) {
RB_SET_LEFT(parent, elm);
} else {
RB_SET_RIGHT(parent, elm);
}
} else {
head.SetRoot(elm);
}
RB_INSERT_COLOR(head, elm);
return nullptr;
}
template<typename T, typename Compare> requires HasRBEntry<T>
constexpr ALWAYS_INLINE T *RB_FIND(RBHead<T> &head, T *elm, Compare cmp) {
T *tmp = head.Root();
while (tmp) {
const int comp = cmp(elm, tmp);
if (comp < 0) {
tmp = RB_LEFT(tmp);
} else if (comp > 0) {
tmp = RB_RIGHT(tmp);
} else {
return tmp;
}
}
return nullptr;
}
template<typename T, typename Compare> requires HasRBEntry<T>
constexpr ALWAYS_INLINE T *RB_NFIND(RBHead<T> &head, T *elm, Compare cmp) {
T *tmp = head.Root();
T* res = nullptr;
while (tmp) {
const int comp = cmp(elm, tmp);
if (comp < 0) {
res = tmp;
tmp = RB_LEFT(tmp);
} else if (comp > 0) {
tmp = RB_RIGHT(tmp);
} else {
return tmp;
}
}
return res;
}
template<typename T, typename U, typename Compare> requires HasRBEntry<T>
constexpr ALWAYS_INLINE T *RB_FIND_KEY(RBHead<T> &head, const U &key, Compare cmp) {
T *tmp = head.Root();
while (tmp) {
const int comp = cmp(key, tmp);
if (comp < 0) {
tmp = RB_LEFT(tmp);
} else if (comp > 0) {
tmp = RB_RIGHT(tmp);
} else {
return tmp;
}
}
return nullptr;
}
template<typename T, typename U, typename Compare> requires HasRBEntry<T>
constexpr ALWAYS_INLINE T *RB_NFIND_KEY(RBHead<T> &head, const U &key, Compare cmp) {
T *tmp = head.Root();
T* res = nullptr;
while (tmp) {
const int comp = cmp(key, tmp);
if (comp < 0) {
res = tmp;
tmp = RB_LEFT(tmp);
} else if (comp > 0) {
tmp = RB_RIGHT(tmp);
} else {
return tmp;
}
}
return res;
}
template<typename T, typename Compare> requires HasRBEntry<T>
constexpr ALWAYS_INLINE T *RB_FIND_EXISTING(RBHead<T> &head, T *elm, Compare cmp) {
T *tmp = head.Root();
while (true) {
const int comp = cmp(elm, tmp);
if (comp < 0) {
tmp = RB_LEFT(tmp);
} else if (comp > 0) {
tmp = RB_RIGHT(tmp);
} else {
return tmp;
}
}
}
template<typename T, typename U, typename Compare> requires HasRBEntry<T>
constexpr ALWAYS_INLINE T *RB_FIND_EXISTING_KEY(RBHead<T> &head, const U &key, Compare cmp) {
T *tmp = head.Root();
while (true) {
const int comp = cmp(key, tmp);
if (comp < 0) {
tmp = RB_LEFT(tmp);
} else if (comp > 0) {
tmp = RB_RIGHT(tmp);
} else {
return tmp;
}
}
}
template<typename T> requires HasRBEntry<T>
constexpr ALWAYS_INLINE T *RB_NEXT(T *elm) {
if (RB_RIGHT(elm)) {
elm = RB_RIGHT(elm);
while (RB_LEFT(elm)) {
elm = RB_LEFT(elm);
}
} else {
if (RB_PARENT(elm) && (elm == RB_LEFT(RB_PARENT(elm)))) {
elm = RB_PARENT(elm);
} else {
while (RB_PARENT(elm) && (elm == RB_RIGHT(RB_PARENT(elm)))) {
elm = RB_PARENT(elm);
}
elm = RB_PARENT(elm);
}
}
return elm;
}
template<typename T> requires HasRBEntry<T>
constexpr ALWAYS_INLINE T *RB_PREV(T *elm) {
if (RB_LEFT(elm)) {
elm = RB_LEFT(elm);
while (RB_RIGHT(elm)) {
elm = RB_RIGHT(elm);
}
} else {
if (RB_PARENT(elm) && (elm == RB_RIGHT(RB_PARENT(elm)))) {
elm = RB_PARENT(elm);
} else {
while (RB_PARENT(elm) && (elm == RB_LEFT(RB_PARENT(elm)))) {
elm = RB_PARENT(elm);
}
elm = RB_PARENT(elm);
}
}
return elm;
}
template<typename T> requires HasRBEntry<T>
constexpr ALWAYS_INLINE T *RB_MIN(RBHead<T> &head) {
T *tmp = head.Root();
T *parent = nullptr;
while (tmp) {
parent = tmp;
tmp = RB_LEFT(tmp);
}
return parent;
}
template<typename T> requires HasRBEntry<T>
constexpr ALWAYS_INLINE T *RB_MAX(RBHead<T> &head) {
T *tmp = head.Root();
T *parent = nullptr;
while (tmp) {
parent = tmp;
tmp = RB_RIGHT(tmp);
}
return parent;
}
}
AMS_PRAGMA_END_OPTIMIZE()

View File

@@ -1,32 +0,0 @@
/*
* Copyright (c) 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/includes.hpp>
#include <vapours/defines.hpp>
#define AMS_PRAGMA(X) \
_Pragma(#X)
#define AMS_PRAGMA_BEGIN_OPTIMIZE(X)
#define AMS_PRAGMA_END_OPTIMIZE()
#define AMS_PRAGMA_BEGIN_PACK(n) \
AMS_PRAGMA(pack(push, n))
#define AMS_PRAGMA_END_PACK() \
AMS_PRAGMA(pack(pop))
#define AMS_CONCEPTS_REQUIRES_IF_SUPPORTED(__EXPR__)

View File

@@ -1,36 +0,0 @@
/*
* Copyright (c) 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/includes.hpp>
#include <vapours/defines.hpp>
#define AMS_PRAGMA(X) \
_Pragma(#X)
#define AMS_PRAGMA_BEGIN_OPTIMIZE(X) \
AMS_PRAGMA(GCC push_options) \
AMS_PRAGMA(GCC optimize(X))
#define AMS_PRAGMA_END_OPTIMIZE() \
AMS_PRAGMA(GCC pop_options)
#define AMS_PRAGMA_BEGIN_PACK(n) \
AMS_PRAGMA(pack(push, n))
#define AMS_PRAGMA_END_PACK() \
AMS_PRAGMA(pack(pop))
#define AMS_CONCEPTS_REQUIRES_IF_SUPPORTED(__EXPR__) requires (__EXPR__)

View File

@@ -1,78 +0,0 @@
/*
* Copyright (c) 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
/* Unconditionally include type-traits as first header. */
#include <type_traits>
/* C headers. */
#include <cstdint>
#include <cstdarg>
#include <cstdlib>
#include <cstddef>
#include <cstdio>
#include <cstring>
#include <climits>
#include <cctype>
#include <cinttypes>
/* C++ headers. */
#include <concepts>
#include <algorithm>
#include <iterator>
#include <limits>
#include <random>
#include <atomic>
#include <utility>
#include <functional>
#include <tuple>
#include <array>
#include <bit>
#include <span>
/* Stratosphere/Troposphere want additional libstdc++ headers and libnx,
* others do not. */
#if defined(ATMOSPHERE_IS_STRATOSPHERE) || defined(ATMOSPHERE_IS_TROPOSPHERE)
#include <memory>
#include <mutex>
#include <shared_mutex>
#include <map>
#include <unordered_map>
#include <set>
#if defined(ATMOSPHERE_OS_HORIZON) && defined(ATMOSPHERE_BOARD_NINTENDO_NX)
/* Libnx. */
#include <switch.h>
#else
/* Non-switch code can't include libnx. */
#include "types.hpp"
#endif
#else
/* Non-EL0 code can't include libnx. */
#include "types.hpp"
#endif /* defined(ATMOSPHERE_IS_STRATOSPHERE) || defined(ATMOSPHERE_IS_TROPOSPHERE) */
/* Atmosphere meta. */
#include <vapours/ams_version.h>

View File

@@ -1,34 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
namespace ams { inline namespace literals {
constexpr ALWAYS_INLINE u64 operator ""_KB(unsigned long long n) {
return static_cast<u64>(n) * UINT64_C(1024);
}
constexpr ALWAYS_INLINE u64 operator ""_MB(unsigned long long n) {
return operator ""_KB(n) * UINT64_C(1024);
}
constexpr ALWAYS_INLINE u64 operator ""_GB(unsigned long long n) {
return operator ""_MB(n) * UINT64_C(1024);
}
} }

View File

@@ -1,261 +0,0 @@
/*
* Copyright (c) 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::reg {
template<typename T>
concept UnsignedNonConstIntegral = std::unsigned_integral<T> && !std::is_const<T>::value;
using BitsValue = std::tuple<u16, u16, u32>;
using BitsMask = std::tuple<u16, u16>;
constexpr ALWAYS_INLINE u32 GetOffset(const BitsMask v) { return static_cast<u32>(std::get<0>(v)); }
constexpr ALWAYS_INLINE u32 GetOffset(const BitsValue v) { return static_cast<u32>(std::get<0>(v)); }
constexpr ALWAYS_INLINE u32 GetWidth(const BitsMask v) { return static_cast<u32>(std::get<1>(v)); }
constexpr ALWAYS_INLINE u32 GetWidth(const BitsValue v) { return static_cast<u32>(std::get<1>(v)); }
constexpr ALWAYS_INLINE u32 GetValue(const BitsValue v) { return static_cast<u32>(std::get<2>(v)); }
constexpr ALWAYS_INLINE ::ams::reg::BitsValue GetValue(const BitsMask m, const u32 v) {
return ::ams::reg::BitsValue{GetOffset(m), GetWidth(m), v};
}
constexpr ALWAYS_INLINE u32 EncodeMask(const BitsMask v) {
return (~0u >> (BITSIZEOF(u32) - GetWidth(v))) << GetOffset(v);
}
constexpr ALWAYS_INLINE u32 EncodeMask(const BitsValue v) {
return (~0u >> (BITSIZEOF(u32) - GetWidth(v))) << GetOffset(v);
}
constexpr ALWAYS_INLINE u32 EncodeValue(const BitsValue v) {
return ((GetValue(v) << GetOffset(v)) & EncodeMask(v));
}
template<typename... Values> requires ((sizeof...(Values) > 0) && (std::is_same<Values, BitsValue>::value && ...))
constexpr ALWAYS_INLINE u32 Encode(const Values... values) {
return (EncodeValue(values) | ...);
}
template<typename... Masks> requires ((sizeof...(Masks) > 0) && (std::is_same<Masks, BitsMask>::value && ...))
constexpr ALWAYS_INLINE u32 EncodeMask(const Masks... masks) {
return (EncodeMask(masks) | ...);
}
template<typename IntType> requires UnsignedNonConstIntegral<IntType>
constexpr ALWAYS_INLINE IntType GetField(const IntType &value, const BitsMask mask) { return (value & EncodeMask(mask)) >> GetOffset(mask); }
template<typename IntType> requires UnsignedNonConstIntegral<IntType>
constexpr ALWAYS_INLINE void SetField(IntType &value, const BitsValue v) { value = (value & ~EncodeMask(v)) | EncodeValue(v); }
template<typename IntType> requires UnsignedNonConstIntegral<IntType>
ALWAYS_INLINE void Write(volatile IntType *reg, std::type_identity_t<IntType> val) { *reg = val; }
template<typename IntType> requires UnsignedNonConstIntegral<IntType>
ALWAYS_INLINE void Write(volatile IntType &reg, std::type_identity_t<IntType> val) { reg = val; }
ALWAYS_INLINE void Write(uintptr_t reg, u32 val) { Write(reinterpret_cast<volatile u32 *>(reg), val); }
template<typename IntType, typename... Values> requires UnsignedNonConstIntegral<IntType> && ((sizeof...(Values) > 0) && (std::is_same<Values, BitsValue>::value && ...))
ALWAYS_INLINE void Write(volatile IntType *reg, const Values... values) { return Write(reg, static_cast<IntType>((EncodeValue(values) | ...))); }
template<typename IntType, typename... Values> requires UnsignedNonConstIntegral<IntType> && ((sizeof...(Values) > 0) && (std::is_same<Values, BitsValue>::value && ...))
ALWAYS_INLINE void Write(volatile IntType &reg, const Values... values) { return Write(reg, static_cast<IntType>((EncodeValue(values) | ...))); }
template<typename... Values> requires ((sizeof...(Values) > 0) && (std::is_same<Values, BitsValue>::value && ...))
ALWAYS_INLINE void Write(uintptr_t reg, const Values... values) { return Write(reg, (EncodeValue(values) | ...)); }
template<typename IntType> requires UnsignedNonConstIntegral<IntType>
ALWAYS_INLINE IntType Read(volatile IntType *reg) { return *reg; }
template<typename IntType> requires UnsignedNonConstIntegral<IntType>
ALWAYS_INLINE IntType Read(volatile IntType &reg) { return reg; }
ALWAYS_INLINE u32 Read(uintptr_t reg) { return Read(reinterpret_cast<volatile u32 *>(reg)); }
template<typename IntType> requires UnsignedNonConstIntegral<IntType>
ALWAYS_INLINE IntType Read(volatile IntType *reg, std::type_identity_t<IntType> mask) { return *reg & mask; }
template<typename IntType> requires UnsignedNonConstIntegral<IntType>
ALWAYS_INLINE IntType Read(volatile IntType &reg, std::type_identity_t<IntType> mask) { return reg & mask; }
ALWAYS_INLINE u32 Read(uintptr_t reg, u32 mask) { return Read(reinterpret_cast<volatile u32 *>(reg), mask); }
template<typename IntType, typename... Masks> requires UnsignedNonConstIntegral<IntType> && ((sizeof...(Masks) > 0) && (std::is_same<Masks, BitsMask>::value && ...))
ALWAYS_INLINE IntType Read(volatile IntType *reg, const Masks... masks) { return Read(reg, static_cast<IntType>((EncodeMask(masks) | ...))); }
template<typename IntType, typename... Masks> requires UnsignedNonConstIntegral<IntType> && ((sizeof...(Masks) > 0) && (std::is_same<Masks, BitsMask>::value && ...))
ALWAYS_INLINE IntType Read(volatile IntType &reg, const Masks... masks) { return Read(reg, static_cast<IntType>((EncodeMask(masks) | ...))); }
template<typename... Masks> requires ((sizeof...(Masks) > 0) && (std::is_same<Masks, BitsMask>::value && ...))
ALWAYS_INLINE u32 Read(uintptr_t reg, const Masks... masks) { return Read(reg, (EncodeMask(masks) | ...)); }
template<typename IntType, typename... Values> requires UnsignedNonConstIntegral<IntType> && ((sizeof...(Values) > 0) && (std::is_same<Values, BitsValue>::value && ...))
ALWAYS_INLINE bool HasValue(volatile IntType *reg, const Values... values) { return Read(reg, static_cast<IntType>((EncodeMask(values) | ...))) == static_cast<IntType>(Encode(values...)); }
template<typename IntType, typename... Values> requires UnsignedNonConstIntegral<IntType> && ((sizeof...(Values) > 0) && (std::is_same<Values, BitsValue>::value && ...))
ALWAYS_INLINE bool HasValue(volatile IntType &reg, const Values... values) { return Read(reg, static_cast<IntType>((EncodeMask(values) | ...))) == static_cast<IntType>(Encode(values...)); }
template<typename... Values> requires ((sizeof...(Values) > 0) && (std::is_same<Values, BitsValue>::value && ...))
ALWAYS_INLINE bool HasValue(uintptr_t reg, const Values... values) { return Read(reg, (EncodeMask(values) | ...)) == Encode(values...); }
template<typename IntType> requires UnsignedNonConstIntegral<IntType>
ALWAYS_INLINE IntType GetValue(volatile IntType *reg, const BitsMask mask) { return Read(reg, mask) >> GetOffset(mask); }
template<typename IntType> requires UnsignedNonConstIntegral<IntType>
ALWAYS_INLINE IntType GetValue(volatile IntType &reg, const BitsMask mask) { return Read(reg, mask) >> GetOffset(mask); }
ALWAYS_INLINE u32 GetValue(uintptr_t reg, const BitsMask mask) { return Read(reg, mask) >> GetOffset(mask); }
template<typename IntType> requires UnsignedNonConstIntegral<IntType>
ALWAYS_INLINE void ReadWrite(volatile IntType *reg, std::type_identity_t<IntType> val, std::type_identity_t<IntType> mask) { *reg = (*reg & (~mask)) | (val & mask); }
template<typename IntType> requires UnsignedNonConstIntegral<IntType>
ALWAYS_INLINE void ReadWrite(volatile IntType &reg, std::type_identity_t<IntType> val, std::type_identity_t<IntType> mask) { reg = ( reg & (~mask)) | (val & mask); }
ALWAYS_INLINE void ReadWrite(uintptr_t reg, u32 val, u32 mask) { ReadWrite(reinterpret_cast<volatile u32 *>(reg), val, mask); }
template<typename IntType, typename... Values> requires UnsignedNonConstIntegral<IntType> && ((sizeof...(Values) > 0) && (std::is_same<Values, BitsValue>::value && ...))
ALWAYS_INLINE void ReadWrite(volatile IntType *reg, const Values... values) { return ReadWrite(reg, static_cast<IntType>((EncodeValue(values) | ...)), static_cast<IntType>((EncodeMask(values) | ...))); }
template<typename IntType, typename... Values> requires UnsignedNonConstIntegral<IntType> && ((sizeof...(Values) > 0) && (std::is_same<Values, BitsValue>::value && ...))
ALWAYS_INLINE void ReadWrite(volatile IntType &reg, const Values... values) { return ReadWrite(reg, static_cast<IntType>((EncodeValue(values) | ...)), static_cast<IntType>((EncodeMask(values) | ...))); }
template<typename... Values> requires ((sizeof...(Values) > 0) && (std::is_same<Values, BitsValue>::value && ...))
ALWAYS_INLINE void ReadWrite(uintptr_t reg, const Values... values) { return ReadWrite(reg, (EncodeValue(values) | ...), (EncodeMask(values) | ...)); }
template<typename IntType> requires UnsignedNonConstIntegral<IntType>
ALWAYS_INLINE void SetBits(volatile IntType *reg, std::type_identity_t<IntType> mask) { *reg = *reg | mask; }
template<typename IntType> requires UnsignedNonConstIntegral<IntType>
ALWAYS_INLINE void SetBits(volatile IntType &reg, std::type_identity_t<IntType> mask) { reg = reg | mask; }
ALWAYS_INLINE void SetBits(uintptr_t reg, u32 mask) { SetBits(reinterpret_cast<volatile u32 *>(reg), mask); }
template<typename IntType, typename... Masks> requires UnsignedNonConstIntegral<IntType> && ((sizeof...(Masks) > 0) && (std::is_same<Masks, BitsMask>::value && ...))
ALWAYS_INLINE void SetBits(volatile IntType *reg, const Masks... masks) { return SetBits(reg, static_cast<IntType>((EncodeMask(masks) | ...))); }
template<typename IntType, typename... Masks> requires UnsignedNonConstIntegral<IntType> && ((sizeof...(Masks) > 0) && (std::is_same<Masks, BitsMask>::value && ...))
ALWAYS_INLINE void SetBits(volatile IntType &reg, const Masks... masks) { return SetBits(reg, static_cast<IntType>((EncodeMask(masks) | ...))); }
template<typename... Masks> requires ((sizeof...(Masks) > 0) && (std::is_same<Masks, BitsMask>::value && ...))
ALWAYS_INLINE void SetBits(uintptr_t reg, const Masks... masks) { return SetBits(reg, (EncodeMask(masks) | ...)); }
template<typename IntType> requires UnsignedNonConstIntegral<IntType>
ALWAYS_INLINE void ClearBits(volatile IntType *reg, std::type_identity_t<IntType> mask) { *reg = *reg & ~mask; }
template<typename IntType> requires UnsignedNonConstIntegral<IntType>
ALWAYS_INLINE void ClearBits(volatile IntType &reg, std::type_identity_t<IntType> mask) { reg = reg & ~mask; }
ALWAYS_INLINE void ClearBits(uintptr_t reg, u32 mask) { ClearBits(reinterpret_cast<volatile u32 *>(reg), mask); }
template<typename IntType, typename... Masks> requires UnsignedNonConstIntegral<IntType> && ((sizeof...(Masks) > 0) && (std::is_same<Masks, BitsMask>::value && ...))
ALWAYS_INLINE void ClearBits(volatile IntType *reg, const Masks... masks) { return ClearBits(reg, static_cast<IntType>((EncodeMask(masks) | ...))); }
template<typename IntType, typename... Masks> requires UnsignedNonConstIntegral<IntType> && ((sizeof...(Masks) > 0) && (std::is_same<Masks, BitsMask>::value && ...))
ALWAYS_INLINE void ClearBits(volatile IntType &reg, const Masks... masks) { return ClearBits(reg, static_cast<IntType>((EncodeMask(masks) | ...))); }
template<typename... Masks> requires ((sizeof...(Masks) > 0) && (std::is_same<Masks, BitsMask>::value && ...))
ALWAYS_INLINE void ClearBits(uintptr_t reg, const Masks... masks) { return ClearBits(reg, (EncodeMask(masks) | ...)); }
template<typename IntType> requires UnsignedNonConstIntegral<IntType>
ALWAYS_INLINE void MaskBits(volatile IntType *reg, std::type_identity_t<IntType> mask) { *reg = *reg & mask; }
template<typename IntType> requires UnsignedNonConstIntegral<IntType>
ALWAYS_INLINE void MaskBits(volatile IntType &reg, std::type_identity_t<IntType> mask) { reg = reg & mask; }
ALWAYS_INLINE void MaskBits(uintptr_t reg, u32 mask) { MaskBits(reinterpret_cast<volatile u32 *>(reg), mask); }
template<typename IntType, typename... Masks> requires UnsignedNonConstIntegral<IntType> && ((sizeof...(Masks) > 0) && (std::is_same<Masks, BitsMask>::value && ...))
ALWAYS_INLINE void MaskBits(volatile IntType *reg, const Masks... masks) { return MaskBits(reg, static_cast<IntType>((EncodeMask(masks) | ...))); }
template<typename IntType, typename... Masks> requires UnsignedNonConstIntegral<IntType> && ((sizeof...(Masks) > 0) && (std::is_same<Masks, BitsMask>::value && ...))
ALWAYS_INLINE void MaskBits(volatile IntType &reg, const Masks... masks) { return MaskBits(reg, static_cast<IntType>((EncodeMask(masks) | ...))); }
template<typename... Masks> requires ((sizeof...(Masks) > 0) && (std::is_same<Masks, BitsMask>::value && ...))
ALWAYS_INLINE void MaskBits(uintptr_t reg, const Masks... masks) { return MaskBits(reg, (EncodeMask(masks) | ...)); }
#define REG_BITS_MASK(OFFSET, WIDTH) ::ams::reg::BitsMask{OFFSET, WIDTH}
#define REG_BITS_VALUE(OFFSET, WIDTH, VALUE) ::ams::reg::BitsValue{OFFSET, WIDTH, VALUE}
#define REG_BITS_VALUE_FROM_MASK(MASK, VALUE) ::ams::reg::GetValue(MASK, VALUE)
#define REG_NAMED_BITS_MASK(PREFIX, NAME) REG_BITS_MASK(PREFIX##_##NAME##_OFFSET, PREFIX##_##NAME##_WIDTH)
#define REG_NAMED_BITS_VALUE(PREFIX, NAME, VALUE) REG_BITS_VALUE(PREFIX##_##NAME##_OFFSET, PREFIX##_##NAME##_WIDTH, VALUE)
#define REG_NAMED_BITS_ENUM(PREFIX, NAME, ENUM) REG_BITS_VALUE(PREFIX##_##NAME##_OFFSET, PREFIX##_##NAME##_WIDTH, PREFIX##_##NAME##_##ENUM)
#define REG_NAMED_BITS_ENUM_SEL(PREFIX, NAME, __COND__, TRUE_ENUM, FALSE_ENUM) REG_BITS_VALUE(PREFIX##_##NAME##_OFFSET, PREFIX##_##NAME##_WIDTH, (__COND__) ? PREFIX##_##NAME##_##TRUE_ENUM : PREFIX##_##NAME##_##FALSE_ENUM)
#define REG_DEFINE_NAMED_REG(PREFIX, NAME, __OFFSET__, __WIDTH__) \
constexpr inline u32 PREFIX##_##NAME##_OFFSET = __OFFSET__; \
constexpr inline u32 PREFIX##_##NAME##_WIDTH = __WIDTH__
#define REG_DEFINE_NAMED_BIT_ENUM(PREFIX, NAME, __OFFSET__, ZERO, ONE) \
REG_DEFINE_NAMED_REG(PREFIX, NAME, __OFFSET__, 1); \
\
enum PREFIX##_##NAME { \
PREFIX##_##NAME##_##ZERO = 0, \
PREFIX##_##NAME##_##ONE = 1, \
};
#define REG_DEFINE_NAMED_TWO_BIT_ENUM(PREFIX, NAME, __OFFSET__, ZERO, ONE, TWO, THREE) \
REG_DEFINE_NAMED_REG(PREFIX, NAME, __OFFSET__, 2); \
\
enum PREFIX##_##NAME { \
PREFIX##_##NAME##_##ZERO = 0, \
PREFIX##_##NAME##_##ONE = 1, \
PREFIX##_##NAME##_##TWO = 2, \
PREFIX##_##NAME##_##THREE = 3, \
};
#define REG_DEFINE_NAMED_THREE_BIT_ENUM(PREFIX, NAME, __OFFSET__, ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN) \
REG_DEFINE_NAMED_REG(PREFIX, NAME, __OFFSET__, 3); \
\
enum PREFIX##_##NAME { \
PREFIX##_##NAME##_##ZERO = 0, \
PREFIX##_##NAME##_##ONE = 1, \
PREFIX##_##NAME##_##TWO = 2, \
PREFIX##_##NAME##_##THREE = 3, \
PREFIX##_##NAME##_##FOUR = 4, \
PREFIX##_##NAME##_##FIVE = 5, \
PREFIX##_##NAME##_##SIX = 6, \
PREFIX##_##NAME##_##SEVEN = 7, \
};
#define REG_DEFINE_NAMED_FOUR_BIT_ENUM(PREFIX, NAME, __OFFSET__, ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, ELEVEN, TWELVE, THIRTEEN, FOURTEEN, FIFTEEN) \
REG_DEFINE_NAMED_REG(PREFIX, NAME, __OFFSET__, 4); \
\
enum PREFIX##_##NAME { \
PREFIX##_##NAME##_##ZERO = 0, \
PREFIX##_##NAME##_##ONE = 1, \
PREFIX##_##NAME##_##TWO = 2, \
PREFIX##_##NAME##_##THREE = 3, \
PREFIX##_##NAME##_##FOUR = 4, \
PREFIX##_##NAME##_##FIVE = 5, \
PREFIX##_##NAME##_##SIX = 6, \
PREFIX##_##NAME##_##SEVEN = 7, \
PREFIX##_##NAME##_##EIGHT = 8, \
PREFIX##_##NAME##_##NINE = 9, \
PREFIX##_##NAME##_##TEN = 10, \
PREFIX##_##NAME##_##ELEVEN = 11, \
PREFIX##_##NAME##_##TWELVE = 12, \
PREFIX##_##NAME##_##THIRTEEN = 13, \
PREFIX##_##NAME##_##FOURTEEN = 14, \
PREFIX##_##NAME##_##FIFTEEN = 15, \
};
}

View File

@@ -1,77 +0,0 @@
/*
* Copyright (c) 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/common.hpp>
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
/* Utilities. */
#include <vapours/results/results_common.hpp>
/* Official. */
#include <vapours/results/cal_results.hpp>
#include <vapours/results/capsrv_results.hpp>
#include <vapours/results/creport_results.hpp>
#include <vapours/results/cs_results.hpp>
#include <vapours/results/dd_results.hpp>
#include <vapours/results/ddsf_results.hpp>
#include <vapours/results/debug_results.hpp>
#include <vapours/results/dmnt_results.hpp>
#include <vapours/results/erpt_results.hpp>
#include <vapours/results/err_results.hpp>
#include <vapours/results/fatal_results.hpp>
#include <vapours/results/fs_results.hpp>
#include <vapours/results/gpio_results.hpp>
#include <vapours/results/hipc_results.hpp>
#include <vapours/results/htc_results.hpp>
#include <vapours/results/htcfs_results.hpp>
#include <vapours/results/htclow_results.hpp>
#include <vapours/results/htcs_results.hpp>
#include <vapours/results/i2c_results.hpp>
#include <vapours/results/kvdb_results.hpp>
#include <vapours/results/loader_results.hpp>
#include <vapours/results/lr_results.hpp>
#include <vapours/results/ncm_results.hpp>
#include <vapours/results/nim_results.hpp>
#include <vapours/results/ns_results.hpp>
#include <vapours/results/os_results.hpp>
#include <vapours/results/osdbg_results.hpp>
#include <vapours/results/pcv_results.hpp>
#include <vapours/results/pgl_results.hpp>
#include <vapours/results/pm_results.hpp>
#include <vapours/results/powctl_results.hpp>
#include <vapours/results/psc_results.hpp>
#include <vapours/results/pwm_results.hpp>
#include <vapours/results/ro_results.hpp>
#include <vapours/results/scs_results.hpp>
#include <vapours/results/sdmmc_results.hpp>
#include <vapours/results/settings_results.hpp>
#include <vapours/results/sf_results.hpp>
#include <vapours/results/sm_results.hpp>
#include <vapours/results/socket_results.hpp>
#include <vapours/results/spl_results.hpp>
#include <vapours/results/sprofile_results.hpp>
#include <vapours/results/svc_results.hpp>
#include <vapours/results/time_results.hpp>
#include <vapours/results/tipc_results.hpp>
#include <vapours/results/tma_results.hpp>
#include <vapours/results/updater_results.hpp>
#include <vapours/results/usb_results.hpp>
#include <vapours/results/vi_results.hpp>
/* Unofficial. */
#include <vapours/results/exosphere_results.hpp>

View File

@@ -1,25 +0,0 @@
/*
* Copyright (c) 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/results/results_common.hpp>
#include <vapours/results/powctl_results.hpp>
namespace ams::cal {
using powctl::ResultCalibrationDataCrcError;
}

View File

@@ -1,94 +0,0 @@
/*
* Copyright (c) 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/results/results_common.hpp>
R_DEFINE_NAMESPACE_RESULT_MODULE(ams::capsrv, 206);
namespace ams::capsrv {
R_DEFINE_ERROR_RANGE(AlbumError, 2, 99);
R_DEFINE_ERROR_RESULT(AlbumWorkMemoryError, 3);
R_DEFINE_ERROR_RESULT(AlbumAlreadyOpened, 7);
R_DEFINE_ERROR_RESULT(AlbumOutOfRange, 8);
R_DEFINE_ERROR_RANGE(AlbumInvalidFileId, 10, 19);
R_DEFINE_ERROR_RESULT(AlbumInvalidApplicationId, 11);
R_DEFINE_ERROR_RESULT(AlbumInvalidTimestamp, 12);
R_DEFINE_ERROR_RESULT(AlbumInvalidStorage, 13);
R_DEFINE_ERROR_RESULT(AlbumInvalidFileContents, 14);
R_DEFINE_ERROR_RESULT(AlbumIsNotMounted, 21);
R_DEFINE_ERROR_RESULT(AlbumIsFull, 22);
R_DEFINE_ERROR_RESULT(AlbumFileNotFound, 23);
R_DEFINE_ERROR_RESULT(AlbumInvalidFileData, 24);
R_DEFINE_ERROR_RESULT(AlbumFileCountLimit, 25);
R_DEFINE_ERROR_RESULT(AlbumFileNoThumbnail, 26);
R_DEFINE_ERROR_RESULT(AlbumReadBufferShortage, 30);
R_DEFINE_ERROR_RANGE(AlbumFileSystemError, 90, 99);
R_DEFINE_ERROR_RANGE(AlbumAccessCorrupted, 94, 96);
R_DEFINE_ERROR_RESULT(AlbumDestinationAccessCorrupted, 96);
R_DEFINE_ERROR_RANGE(ControlError, 800, 899);
R_DEFINE_ERROR_RESULT(ControlResourceLimit, 820);
R_DEFINE_ERROR_RESULT(ControlNotOpened, 822);
R_DEFINE_ERROR_RESULT(NotSupported, 1023);
R_DEFINE_ERROR_RANGE(InternalError, 1024, 2047);
R_DEFINE_ERROR_RESULT(InternalJpegEncoderError, 1210);
R_DEFINE_ERROR_RESULT(InternalJpegOutBufferShortage, 1211);
R_DEFINE_ERROR_RESULT(InternalJpegWorkMemoryShortage, 1212);
R_DEFINE_ERROR_RANGE(InternalFileDataVerificationError, 1300, 1399);
R_DEFINE_ERROR_RESULT(InternalFileDataVerificationEmptyFileData, 1301);
R_DEFINE_ERROR_RESULT(InternalFileDataVerificationExifExtractionFailed, 1302);
R_DEFINE_ERROR_RESULT(InternalFileDataVerificationExifAnalyzationFailed, 1303);
R_DEFINE_ERROR_RESULT(InternalFileDataVerificationDateTimeExtractionFailed, 1304);
R_DEFINE_ERROR_RESULT(InternalFileDataVerificationInvalidDateTimeLength, 1305);
R_DEFINE_ERROR_RESULT(InternalFileDataVerificationInconsistentDateTime, 1306);
R_DEFINE_ERROR_RESULT(InternalFileDataVerificationMakerNoteExtractionFailed, 1307);
R_DEFINE_ERROR_RESULT(InternalFileDataVerificationInconsistentApplicationId, 1308);
R_DEFINE_ERROR_RESULT(InternalFileDataVerificationInconsistentSignature, 1309);
R_DEFINE_ERROR_RESULT(InternalFileDataVerificationUnsupportedOrientation, 1310);
R_DEFINE_ERROR_RESULT(InternalFileDataVerificationInvalidDataDimension, 1311);
R_DEFINE_ERROR_RESULT(InternalFileDataVerificationInconsistentOrientation, 1312);
R_DEFINE_ERROR_RANGE(InternalAlbumLimitationError, 1400, 1499);
R_DEFINE_ERROR_RESULT(InternalAlbumLimitationFileCountLimit, 1401);
R_DEFINE_ERROR_RANGE(InternalSignatureError, 1500, 1599);
R_DEFINE_ERROR_RESULT(InternalSignatureExifExtractionFailed, 1501);
R_DEFINE_ERROR_RESULT(InternalSignatureMakerNoteExtractionFailed, 1502);
R_DEFINE_ERROR_RANGE(InternalAlbumSessionError, 1700, 1799);
R_DEFINE_ERROR_RESULT(InternalAlbumLimitationSessionCountLimit, 1701);
R_DEFINE_ERROR_RANGE(InternalAlbumTemporaryFileError, 1900, 1999);
R_DEFINE_ERROR_RESULT(InternalAlbumTemporaryFileCountLimit, 1901);
R_DEFINE_ERROR_RESULT(InternalAlbumTemporaryFileCreateError, 1902);
R_DEFINE_ERROR_RESULT(InternalAlbumTemporaryFileCreateRetryCountLimit, 1903);
R_DEFINE_ERROR_RESULT(InternalAlbumTemporaryFileOpenError, 1904);
R_DEFINE_ERROR_RESULT(InternalAlbumTemporaryFileGetFileSizeError, 1905);
R_DEFINE_ERROR_RESULT(InternalAlbumTemporaryFileSetFileSizeError, 1906);
R_DEFINE_ERROR_RESULT(InternalAlbumTemporaryFileReadFileError, 1907);
R_DEFINE_ERROR_RESULT(InternalAlbumTemporaryFileWriteFileError, 1908);
}

View File

@@ -1,37 +0,0 @@
/*
* Copyright (c) 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/results/results_common.hpp>
R_DEFINE_NAMESPACE_RESULT_MODULE(ams::creport, 168);
namespace ams::creport {
R_DEFINE_ERROR_RESULT(UndefinedInstruction, 0);
R_DEFINE_ERROR_RESULT(InstructionAbort, 1);
R_DEFINE_ERROR_RESULT(DataAbort, 2);
R_DEFINE_ERROR_RESULT(AlignmentFault, 3);
R_DEFINE_ERROR_RESULT(DebuggerAttached, 4);
R_DEFINE_ERROR_RESULT(BreakPoint, 5);
R_DEFINE_ERROR_RESULT(UserBreak, 6);
R_DEFINE_ERROR_RESULT(DebuggerBreak, 7);
R_DEFINE_ERROR_RESULT(UndefinedSystemCall, 8);
R_DEFINE_ERROR_RESULT(MemorySystemError, 9);
R_DEFINE_ERROR_RESULT(IncompleteReport, 99);
}

View File

@@ -1,28 +0,0 @@
/*
* Copyright (c) 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/results/results_common.hpp>
R_DEFINE_NAMESPACE_RESULT_MODULE(ams::cs, 204);
namespace ams::cs {
R_DEFINE_ERROR_RESULT(UnknownCommand, 2);
R_DEFINE_ERROR_RESULT(OutOfResource, 4);
R_DEFINE_ERROR_RESULT(NoSocket, 7);
}

View File

@@ -1,35 +0,0 @@
/*
* Copyright (c) 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/results/results_common.hpp>
R_DEFINE_NAMESPACE_RESULT_MODULE(ams::dd, 6);
namespace ams::dd {
R_DEFINE_ERROR_RESULT(EndOfQuery, 1);
R_DEFINE_ERROR_RESULT(InvalidCurrentMemory, 2);
R_DEFINE_ERROR_RESULT(NotSingleRegion, 3);
R_DEFINE_ERROR_RESULT(InvalidMemoryState, 4);
R_DEFINE_ERROR_RESULT(OutOfMemory, 5);
R_DEFINE_ERROR_RESULT(OutOfResource, 6);
R_DEFINE_ERROR_RESULT(NotSupported, 7);
R_DEFINE_ERROR_RESULT(InvalidHandle, 8);
R_DEFINE_ERROR_RESULT(InternalError, 1023);
}

View File

@@ -1,31 +0,0 @@
/*
* Copyright (c) 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/results/results_common.hpp>
R_DEFINE_NAMESPACE_RESULT_MODULE(ams::ddsf, 30);
namespace ams::ddsf {
R_DEFINE_ERROR_RESULT(OutOfResource, 1);
R_DEFINE_ERROR_RESULT(NotSupported, 2);
R_DEFINE_ERROR_RESULT(InvalidArgument, 3);
R_DEFINE_ERROR_RESULT(PermissionDenied, 4);
R_DEFINE_ERROR_RESULT(AccessModeDenied, 5);
R_DEFINE_ERROR_RESULT(DeviceCodeNotFound, 6);
}

View File

@@ -1,28 +0,0 @@
/*
* Copyright (c) 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/results/results_common.hpp>
R_DEFINE_NAMESPACE_RESULT_MODULE(ams::dbg, 183);
namespace ams::dbg {
R_DEFINE_ERROR_RESULT(CannotDebug, 1);
R_DEFINE_ERROR_RESULT(AlreadyAttached, 2);
R_DEFINE_ERROR_RESULT(Cancelled, 3);
}

View File

@@ -1,50 +0,0 @@
/*
* Copyright (c) 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/results/results_common.hpp>
R_DEFINE_NAMESPACE_RESULT_MODULE(ams::dmnt, 13);
namespace ams::dmnt {
R_DEFINE_ERROR_RESULT(Unknown, 1);
R_DEFINE_ERROR_RESULT(DebuggingDisabled, 2);
/* Atmosphere extension. */
// namespace cheat {
R_DEFINE_ABSTRACT_ERROR_RANGE_NS(cheat, CheatError, 6500, 6599);
R_DEFINE_ERROR_RESULT_NS(cheat, CheatNotAttached, 6500);
R_DEFINE_ERROR_RESULT_NS(cheat, CheatNullBuffer, 6501);
R_DEFINE_ERROR_RESULT_NS(cheat, CheatInvalidBuffer, 6502);
R_DEFINE_ERROR_RESULT_NS(cheat, CheatUnknownId, 6503);
R_DEFINE_ERROR_RESULT_NS(cheat, CheatOutOfResource, 6504);
R_DEFINE_ERROR_RESULT_NS(cheat, CheatInvalid, 6505);
R_DEFINE_ERROR_RESULT_NS(cheat, CheatCannotDisable, 6506);
R_DEFINE_ABSTRACT_ERROR_RANGE_NS(cheat, FrozenAddressError, 6600, 6699);
R_DEFINE_ERROR_RESULT_NS(cheat, FrozenAddressInvalidWidth, 6600);
R_DEFINE_ERROR_RESULT_NS(cheat, FrozenAddressAlreadyExists, 6601);
R_DEFINE_ERROR_RESULT_NS(cheat, FrozenAddressNotFound, 6602);
R_DEFINE_ERROR_RESULT_NS(cheat, FrozenAddressOutOfResource, 6603);
R_DEFINE_ABSTRACT_ERROR_RANGE_NS(cheat, VirtualMachineError, 6700, 6799);
R_DEFINE_ERROR_RESULT_NS(cheat, VirtualMachineInvalidConditionDepth, 6700);
// }
}

View File

@@ -1,44 +0,0 @@
/*
* Copyright (c) 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/results/results_common.hpp>
R_DEFINE_NAMESPACE_RESULT_MODULE(ams::erpt, 147);
namespace ams::erpt {
R_DEFINE_ERROR_RESULT(NotInitialized, 1);
R_DEFINE_ERROR_RESULT(AlreadyInitialized, 2);
R_DEFINE_ERROR_RESULT(OutOfArraySpace, 3);
R_DEFINE_ERROR_RESULT(OutOfFieldSpace, 4);
R_DEFINE_ERROR_RESULT(OutOfMemory, 5);
R_DEFINE_ERROR_RESULT(NotSupported, 6);
R_DEFINE_ERROR_RESULT(InvalidArgument, 7);
R_DEFINE_ERROR_RESULT(NotFound, 8);
R_DEFINE_ERROR_RESULT(FieldCategoryMismatch, 9);
R_DEFINE_ERROR_RESULT(FieldTypeMismatch, 10);
R_DEFINE_ERROR_RESULT(AlreadyExists, 11);
R_DEFINE_ERROR_RESULT(CorruptJournal, 12);
R_DEFINE_ERROR_RESULT(CategoryNotFound, 13);
R_DEFINE_ERROR_RESULT(RequiredContextMissing, 14);
R_DEFINE_ERROR_RESULT(RequiredFieldMissing, 15);
R_DEFINE_ERROR_RESULT(FormatterError, 16);
R_DEFINE_ERROR_RESULT(InvalidPowerState, 17);
R_DEFINE_ERROR_RESULT(ArrayFieldTooLarge, 18);
R_DEFINE_ERROR_RESULT(AlreadyOwned, 19);
}

View File

@@ -1,29 +0,0 @@
/*
* Copyright (c) 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/results/results_common.hpp>
R_DEFINE_NAMESPACE_RESULT_MODULE(ams::err, 162);
namespace ams::err {
R_DEFINE_ERROR_RESULT(ApplicationAbort, 1);
R_DEFINE_ERROR_RESULT(SystemProgramAbort, 2);
R_DEFINE_ERROR_RESULT(ForcedShutdownDetected, 4);
}

View File

@@ -1,29 +0,0 @@
/*
* Copyright (c) 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/results/results_common.hpp>
/* Please note: These results are all custom, and not official. */
R_DEFINE_NAMESPACE_RESULT_MODULE(ams::exosphere, 444);
namespace ams::exosphere {
/* Result 1-1000 reserved for Atmosphere. */
R_DEFINE_ERROR_RESULT(NotPresent, 1);
R_DEFINE_ERROR_RESULT(VersionMismatch, 2);
}

View File

@@ -1,31 +0,0 @@
/*
* Copyright (c) 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/results/results_common.hpp>
R_DEFINE_NAMESPACE_RESULT_MODULE(ams::fatal, 163);
namespace ams::fatal {
R_DEFINE_ERROR_RESULT(AllocationFailed, 1);
R_DEFINE_ERROR_RESULT(NullGraphicsBuffer, 2);
R_DEFINE_ERROR_RESULT(AlreadyThrown, 3);
R_DEFINE_ERROR_RESULT(TooManyEvents, 4);
R_DEFINE_ERROR_RESULT(InRepairWithoutVolHeld, 5);
R_DEFINE_ERROR_RESULT(InRepairWithoutTimeReviserCartridge, 6);
}

View File

@@ -1,606 +0,0 @@
/*
* Copyright (c) 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/results/results_common.hpp>
R_DEFINE_NAMESPACE_RESULT_MODULE(ams::fs, 2);
namespace ams::fs {
R_DEFINE_ERROR_RANGE(HandledByAllProcess, 0, 999);
R_DEFINE_ERROR_RESULT(PathNotFound, 1);
R_DEFINE_ERROR_RESULT(PathAlreadyExists, 2);
R_DEFINE_ERROR_RESULT(TargetLocked, 7);
R_DEFINE_ERROR_RESULT(DirectoryNotEmpty, 8);
R_DEFINE_ERROR_RANGE (NotEnoughFreeSpace, 30, 45);
R_DEFINE_ERROR_RANGE(NotEnoughFreeSpaceBis, 34, 38);
R_DEFINE_ERROR_RESULT(NotEnoughFreeSpaceBisCalibration, 35);
R_DEFINE_ERROR_RESULT(NotEnoughFreeSpaceBisSafe, 36);
R_DEFINE_ERROR_RESULT(NotEnoughFreeSpaceBisUser, 37);
R_DEFINE_ERROR_RESULT(NotEnoughFreeSpaceBisSystem, 38);
R_DEFINE_ERROR_RESULT(NotEnoughFreeSpaceSdCard, 39);
R_DEFINE_ERROR_RESULT(UnsupportedSdkVersion, 50);
R_DEFINE_ERROR_RESULT(MountNameAlreadyExists, 60);
R_DEFINE_ERROR_RANGE(HandledBySystemProcess, 1000, 2999);
R_DEFINE_ERROR_RESULT(PartitionNotFound, 1001);
R_DEFINE_ERROR_RESULT(TargetNotFound, 1002);
R_DEFINE_ERROR_RESULT(NcaExternalKeyNotFound, 1004);
R_DEFINE_ERROR_RANGE(SdCardAccessFailed, 2000, 2499);
R_DEFINE_ERROR_RESULT(SdCardNotPresent, 2001);
R_DEFINE_ERROR_RANGE(GameCardAccessFailed, 2500, 2999);
R_DEFINE_ERROR_RESULT(GameCardPreconditionViolation, 2503);
R_DEFINE_ERROR_RANGE(GameCardCardAccessFailure, 2530, 2559);
R_DEFINE_ERROR_RANGE(CameCardWrongCard, 2543, 2546);
R_DEFINE_ERROR_RESULT(GameCardInitialDataMismatch, 2544);
R_DEFINE_ERROR_RESULT(GameCardInitialNotFilledWithZero, 2545);
R_DEFINE_ERROR_RESULT(GameCardKekIndexMismatch, 2546);
R_DEFINE_ERROR_RESULT(GameCardInvalidCardHeader, 2554);
R_DEFINE_ERROR_RESULT(GameCardInvalidT1CardCertificate, 2555);
R_DEFINE_ERROR_RESULT(GameCardInvalidCa10Certificate, 2557);
R_DEFINE_ERROR_RANGE(GameCardSplFailure, 2665, 2669);
R_DEFINE_ERROR_RESULT(GameCardSplDecryptAesKeyFailure, 2666);
R_DEFINE_ERROR_RESULT(NotImplemented, 3001);
R_DEFINE_ERROR_RESULT(UnsupportedVersion, 3002);
R_DEFINE_ERROR_RESULT(OutOfRange, 3005);
R_DEFINE_ERROR_RESULT(SystemPartitionNotReady, 3100);
R_DEFINE_ERROR_RANGE(AllocationMemoryFailed, 3200, 3499);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInFatFileSystemA, 3201);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInFatFileSystemC, 3203);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInFatFileSystemD, 3204);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInFatFileSystemE, 3205);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInFatFileSystemF, 3206);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInFatFileSystemH, 3208);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInFileSystemAccessorA, 3211);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInFileSystemAccessorB, 3212);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInApplicationA, 3213);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInBcatSaveDataA, 3214);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInBisA, 3215);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInBisB, 3216);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInBisC, 3217);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInCodeA, 3218);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInContentA, 3219);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInContentStorageA, 3220);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInContentStorageB, 3221);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInDataA, 3222);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInDataB, 3223);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInDeviceSaveDataA, 3224);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInGameCardA, 3225);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInGameCardB, 3226);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInGameCardC, 3227);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInGameCardD, 3228);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInHostA, 3229);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInHostB, 3230);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInHostC, 3231);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInImageDirectoryA, 3232);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInLogoA, 3233);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInRomA, 3234);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInRomB, 3235);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInRomC, 3236);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInRomD, 3237);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInRomE, 3238);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInRomF, 3239);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInSaveDataManagementA, 3242);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInSaveDataThumbnailA, 3243);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInSdCardA, 3244);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInSdCardB, 3245);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInSystemSaveDataA, 3246);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInRomFsFileSystemA, 3247);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInRomFsFileSystemB, 3248);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInRomFsFileSystemC, 3249);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInGuidPartitionTableA, 3251);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInDeviceDetectionEventManagerA, 3252);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInSaveDataFileSystemServiceImplA, 3253);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInFileSystemProxyCoreImplB, 3254);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInSdCardProxyFileSystemCreatorA, 3255);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInNcaFileSystemServiceImplA, 3256);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInNcaFileSystemServiceImplB, 3257);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInProgramRegistryManagerA, 3258);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInSdmmcStorageServiceA, 3259);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInBuiltInStorageCreatorA, 3260);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInBuiltInStorageCreatorB, 3261);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInBuiltInStorageCreatorC, 3262);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedFatFileSystemWithBufferA, 3264);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInFatFileSystemCreatorA, 3265);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInFatFileSystemCreatorB, 3266);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInGameCardFileSystemCreatorA, 3267);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInGameCardFileSystemCreatorB, 3268);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInGameCardFileSystemCreatorC, 3269);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInGameCardFileSystemCreatorD, 3270);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInGameCardFileSystemCreatorE, 3271);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInGameCardFileSystemCreatorF, 3272);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInGameCardManagerA, 3273);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInGameCardManagerB, 3274);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInGameCardManagerC, 3275);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInGameCardManagerD, 3276);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInGameCardManagerE, 3277);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInGameCardManagerF, 3278);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInLocalFileSystemCreatorA, 3279);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInPartitionFileSystemCreatorA, 3280);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInRomFileSystemCreatorA, 3281);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInSaveDataFileSystemCreatorA, 3282);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInSaveDataFileSystemCreatorB, 3283);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInSaveDataFileSystemCreatorC, 3284);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInSaveDataFileSystemCreatorD, 3285);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInSaveDataFileSystemCreatorE, 3286);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInStorageOnNcaCreatorA, 3288);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInStorageOnNcaCreatorB, 3289);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInSubDirectoryFileSystemCreatorA, 3290);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInTargetManagerFileSystemCreatorA, 3291);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInSaveDataIndexerA, 3292);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInSaveDataIndexerB, 3293);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInFileSystemBuddyHeapA, 3294);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInFileSystemBufferManagerA, 3295);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInBlockCacheBufferedStorageA, 3296);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInBlockCacheBufferedStorageB, 3297);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInDuplexStorageA, 3298);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInIntegrityVerificationStorageA, 3304);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInIntegrityVerificationStorageB, 3305);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInJournalStorageA, 3306);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInJournalStorageB, 3307);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInSaveDataFileSystemCoreA, 3310);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInSaveDataFileSystemCoreB, 3311);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInAesXtsFileA, 3312);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInAesXtsFileB, 3313);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInAesXtsFileC, 3314);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInAesXtsFileD, 3315);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInAesXtsFileSystemA, 3316);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInConcatenationFileSystemA, 3319);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInConcatenationFileSystemB, 3320);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInDirectorySaveDataFileSystemA, 3321);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInLocalFileSystemA, 3322);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInLocalFileSystemB, 3323);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInNcaFileSystemDriverI, 3341);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInPartitionFileSystemA, 3347);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInPartitionFileSystemB, 3348);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInPartitionFileSystemC, 3349);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInPartitionFileSystemMetaA, 3350);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInPartitionFileSystemMetaB, 3351);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInRomFsFileSystemD, 3352);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInSubdirectoryFileSystemA, 3355);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInTmFileSystemA, 3356);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInTmFileSystemB, 3357);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInProxyFileSystemA, 3359);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInProxyFileSystemB, 3360);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInSaveDataExtraDataAccessorCacheManagerA, 3362);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInNcaReaderA, 3363);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInRegisterA, 3365);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInRegisterB, 3366);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInPathNormalizer, 3367);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInDbmRomKeyValueStorage, 3375);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInDbmHierarchicalRomFileTable, 3376);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInRomFsFileSystemE, 3377);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInISaveFileSystemA, 3378);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInISaveFileSystemB, 3379);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInRomOnFileA, 3380);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInRomOnFileB, 3381);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInRomOnFileC, 3382);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInAesXtsFileE, 3383);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInAesXtsFileF, 3384);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInAesXtsFileG, 3385);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInReadOnlyFileSystemA, 3386);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInEncryptedFileSystemCreatorA, 3394);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInAesCtrCounterExtendedStorageA, 3399);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInAesCtrCounterExtendedStorageB, 3400);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInSdmmcStorageServiceB, 3406);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInFileSystemInterfaceAdapterA, 3407);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInGameCardFileSystemCreatorG, 3408);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInGameCardFileSystemCreatorH, 3409);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInAesXtsFileSystemB, 3410);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInBufferedStorageA, 3411);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInIntegrityRomFsStorageA, 3412);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInSaveDataFileSystemServiceImplB, 3416);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedNew, 3420);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInFileSystemProxyImplA, 3421);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedMakeUnique, 3422);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedAllocateShared, 3423);
R_DEFINE_ERROR_RESULT(AllocationPooledBufferNotEnoughSize, 3424);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInWriteThroughCacheStorageA, 3428);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInSaveDataTransferManagerA, 3429);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInSaveDataTransferManagerB, 3430);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInHtcFileSystemA, 3431);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInHtcFileSystemB, 3432);
R_DEFINE_ERROR_RESULT(AllocationMemoryFailedInGameCardManagerG, 3433);
R_DEFINE_ERROR_RANGE(Internal, 3000, 7999);
R_DEFINE_ERROR_RANGE(MmcAccessFailed, 3500, 3999);
R_DEFINE_ERROR_RANGE(DataCorrupted, 4000, 4999);
R_DEFINE_ERROR_RANGE(RomCorrupted, 4001, 4299);
R_DEFINE_ERROR_RESULT(UnsupportedRomVersion, 4002);
R_DEFINE_ERROR_RANGE(AesCtrCounterExtendedStorageCorrupted, 4011, 4019);
R_DEFINE_ERROR_RESULT(InvalidAesCtrCounterExtendedEntryOffset, 4012);
R_DEFINE_ERROR_RESULT(InvalidAesCtrCounterExtendedTableSize, 4013);
R_DEFINE_ERROR_RESULT(InvalidAesCtrCounterExtendedGeneration, 4014);
R_DEFINE_ERROR_RESULT(InvalidAesCtrCounterExtendedOffset, 4015);
R_DEFINE_ERROR_RANGE(IndirectStorageCorrupted, 4021, 4029);
R_DEFINE_ERROR_RESULT(InvalidIndirectEntryOffset, 4022);
R_DEFINE_ERROR_RESULT(InvalidIndirectEntryStorageIndex, 4023);
R_DEFINE_ERROR_RESULT(InvalidIndirectStorageSize, 4024);
R_DEFINE_ERROR_RESULT(InvalidIndirectVirtualOffset, 4025);
R_DEFINE_ERROR_RESULT(InvalidIndirectPhysicalOffset, 4026);
R_DEFINE_ERROR_RESULT(InvalidIndirectStorageIndex, 4027);
R_DEFINE_ERROR_RANGE(BucketTreeCorrupted, 4031, 4039);
R_DEFINE_ERROR_RESULT(InvalidBucketTreeSignature, 4032);
R_DEFINE_ERROR_RESULT(InvalidBucketTreeEntryCount, 4033);
R_DEFINE_ERROR_RESULT(InvalidBucketTreeNodeEntryCount, 4034);
R_DEFINE_ERROR_RESULT(InvalidBucketTreeNodeOffset, 4035);
R_DEFINE_ERROR_RESULT(InvalidBucketTreeEntryOffset, 4036);
R_DEFINE_ERROR_RESULT(InvalidBucketTreeEntrySetOffset, 4037);
R_DEFINE_ERROR_RESULT(InvalidBucketTreeNodeIndex, 4038);
R_DEFINE_ERROR_RESULT(InvalidBucketTreeVirtualOffset, 4039);
R_DEFINE_ERROR_RANGE(RomNcaCorrupted, 4041, 4139);
R_DEFINE_ERROR_RANGE(RomNcaFileSystemCorrupted, 4051, 4069);
R_DEFINE_ERROR_RESULT(InvalidRomNcaFileSystemType, 4052);
R_DEFINE_ERROR_RESULT(InvalidRomAcidFileSize, 4053);
R_DEFINE_ERROR_RESULT(InvalidRomAcidSize, 4054);
R_DEFINE_ERROR_RESULT(InvalidRomAcid, 4055);
R_DEFINE_ERROR_RESULT(RomAcidVerificationFailed, 4056);
R_DEFINE_ERROR_RESULT(InvalidRomNcaSignature, 4057);
R_DEFINE_ERROR_RESULT(RomNcaHeaderSignature1VerificationFailed, 4058);
R_DEFINE_ERROR_RESULT(RomNcaHeaderSignature2VerificationFailed, 4059);
R_DEFINE_ERROR_RESULT(RomNcaFsHeaderHashVerificationFailed, 4060);
R_DEFINE_ERROR_RESULT(InvalidRomNcaKeyIndex, 4061);
R_DEFINE_ERROR_RESULT(InvalidRomNcaFsHeaderHashType, 4062);
R_DEFINE_ERROR_RESULT(InvalidRomNcaFsHeaderEncryptionType, 4063);
R_DEFINE_ERROR_RANGE(RomNcaHierarchicalSha256StorageCorrupted, 4071, 4079);
R_DEFINE_ERROR_RESULT(InvalidRomHierarchicalSha256BlockSize, 4072);
R_DEFINE_ERROR_RESULT(InvalidRomHierarchicalSha256LayerCount, 4073);
R_DEFINE_ERROR_RESULT(RomHierarchicalSha256BaseStorageTooLarge, 4074);
R_DEFINE_ERROR_RESULT(RomHierarchicalSha256HashVerificationFailed, 4075);
R_DEFINE_ERROR_RESULT(RomNcaInvalidHierarchicalIntegrityVerificationLayerCount, 4081);
R_DEFINE_ERROR_RESULT(RomNcaInvalidNcaIndirectStorageOutOfRange, 4082);
R_DEFINE_ERROR_RESULT(RomNcaInvalidCompressionInfo, 4083);
R_DEFINE_ERROR_RESULT(RomNcaInvalidPatchMetaDataHashType, 4084);
R_DEFINE_ERROR_RESULT(RomNcaInvalidIntegrityLayerInfoOffset, 4085);
R_DEFINE_ERROR_RESULT(RomNcaInvalidPatchMetaDataHashDataSize, 4086);
R_DEFINE_ERROR_RESULT(RomNcaInvalidPatchMetaDataHashDataOffset, 4087);
R_DEFINE_ERROR_RESULT(RomNcaInvalidPatchMetaDataHashDataHash, 4088);
R_DEFINE_ERROR_RESULT(RomNcaInvalidSparseMetaDataHashType, 4089);
R_DEFINE_ERROR_RESULT(RomNcaInvalidSparseMetaDataHashDataSize, 4090);
R_DEFINE_ERROR_RESULT(RomNcaInvalidSparseMetaDataHashDataOffset, 4091);
R_DEFINE_ERROR_RESULT(RomNcaInvalidSparseMetaDataHashDataHash, 4092);
R_DEFINE_ERROR_RANGE(RomIntegrityVerificationStorageCorrupted, 4141, 4179);
R_DEFINE_ERROR_RESULT(IncorrectRomIntegrityVerificationMagic, 4142);
R_DEFINE_ERROR_RESULT(InvalidRomZeroHash, 4143);
R_DEFINE_ERROR_RESULT(RomNonRealDataVerificationFailed, 4144);
R_DEFINE_ERROR_RESULT(InvalidRomHierarchicalIntegrityVerificationLayerCount, 4145);
R_DEFINE_ERROR_RANGE(RomRealDataVerificationFailed, 4151, 4159);
R_DEFINE_ERROR_RESULT(ClearedRomRealDataVerificationFailed, 4152);
R_DEFINE_ERROR_RESULT(UnclearedRomRealDataVerificationFailed, 4153);
R_DEFINE_ERROR_RANGE(RomPartitionFileSystemCorrupted, 4181, 4199);
R_DEFINE_ERROR_RESULT(InvalidRomSha256PartitionHashTarget, 4182);
R_DEFINE_ERROR_RESULT(RomSha256PartitionHashVerificationFailed, 4183);
R_DEFINE_ERROR_RESULT(RomPartitionSignatureVerificationFailed, 4184);
R_DEFINE_ERROR_RESULT(RomSha256PartitionSignatureVerificationFailed, 4185);
R_DEFINE_ERROR_RESULT(InvalidRomPartitionEntryOffset, 4186);
R_DEFINE_ERROR_RESULT(InvalidRomSha256PartitionMetaDataSize, 4187);
R_DEFINE_ERROR_RANGE(RomBuiltInStorageCorrupted, 4201, 4219);
R_DEFINE_ERROR_RESULT(RomGptHeaderVerificationFailed, 4202);
R_DEFINE_ERROR_RANGE(RomHostFileSystemCorrupted, 4241, 4259);
R_DEFINE_ERROR_RESULT(RomHostEntryCorrupted, 4242);
R_DEFINE_ERROR_RESULT(RomHostFileDataCorrupted, 4243);
R_DEFINE_ERROR_RESULT(RomHostFileCorrupted, 4244);
R_DEFINE_ERROR_RESULT(InvalidRomHostHandle, 4245);
R_DEFINE_ERROR_RANGE(RomDatabaseCorrupted, 4261, 4279);
R_DEFINE_ERROR_RESULT(InvalidRomAllocationTableBlock, 4262);
R_DEFINE_ERROR_RESULT(InvalidRomKeyValueListElementIndex, 4263);
R_DEFINE_ERROR_RANGE(SaveDataCorrupted, 4301, 4499);
R_DEFINE_ERROR_RANGE(NcaCorrupted, 4501, 4599);
R_DEFINE_ERROR_RESULT(NcaBaseStorageOutOfRangeA, 4508);
R_DEFINE_ERROR_RESULT(NcaBaseStorageOutOfRangeB, 4509);
R_DEFINE_ERROR_RESULT(NcaBaseStorageOutOfRangeC, 4510);
R_DEFINE_ERROR_RESULT(NcaBaseStorageOutOfRangeD, 4511);
R_DEFINE_ERROR_RESULT_CLASS_IMPL(NcaFileSystemCorrupted, 4512, 4529);
R_DEFINE_ERROR_RESULT(InvalidNcaFileSystemType, 4512);
R_DEFINE_ERROR_RESULT(InvalidAcidFileSize, 4513);
R_DEFINE_ERROR_RESULT(InvalidAcidSize, 4514);
R_DEFINE_ERROR_RESULT(InvalidAcid, 4515);
R_DEFINE_ERROR_RESULT(AcidVerificationFailed, 4516);
R_DEFINE_ERROR_RESULT(InvalidNcaSignature, 4517);
R_DEFINE_ERROR_RESULT(NcaHeaderSignature1VerificationFailed, 4518);
R_DEFINE_ERROR_RESULT(NcaHeaderSignature2VerificationFailed, 4519);
R_DEFINE_ERROR_RESULT(NcaFsHeaderHashVerificationFailed, 4520);
R_DEFINE_ERROR_RESULT(InvalidNcaKeyIndex, 4521);
R_DEFINE_ERROR_RESULT(InvalidNcaFsHeaderHashType, 4522);
R_DEFINE_ERROR_RESULT(InvalidNcaFsHeaderEncryptionType, 4523);
R_DEFINE_ERROR_RESULT(InvalidNcaPatchInfoIndirectSize, 4524);
R_DEFINE_ERROR_RESULT(InvalidNcaPatchInfoAesCtrExSize, 4525);
R_DEFINE_ERROR_RESULT(InvalidNcaPatchInfoAesCtrExOffset, 4526);
R_DEFINE_ERROR_RESULT(InvalidNcaId, 4527);
R_DEFINE_ERROR_RESULT(InvalidNcaHeader, 4528);
R_DEFINE_ERROR_RESULT(InvalidNcaFsHeader, 4529);
R_DEFINE_ERROR_RESULT(NcaBaseStorageOutOfRangeE, 4530);
R_DEFINE_ERROR_RANGE(NcaHierarchicalSha256StorageCorrupted, 4531, 4539);
R_DEFINE_ERROR_RESULT(InvalidHierarchicalSha256BlockSize, 4532);
R_DEFINE_ERROR_RESULT(InvalidHierarchicalSha256LayerCount, 4533);
R_DEFINE_ERROR_RESULT(HierarchicalSha256BaseStorageTooLarge, 4534);
R_DEFINE_ERROR_RESULT(HierarchicalSha256HashVerificationFailed, 4535);
/* TODO: Range? */
R_DEFINE_ERROR_RESULT(InvalidNcaHierarchicalIntegrityVerificationLayerCount, 4541);
R_DEFINE_ERROR_RESULT(InvalidNcaIndirectStorageOutOfRange, 4542);
R_DEFINE_ERROR_RESULT(InvalidNcaHeader1SignatureKeyGeneration, 4543);
/* TODO: Range? */
R_DEFINE_ERROR_RESULT(InvalidCompressedStorageSize, 4547);
R_DEFINE_ERROR_RESULT(InvalidNcaMetaDataHashDataSize, 4548);
R_DEFINE_ERROR_RESULT(InvalidNcaMetaDataHashDataHash, 4549);
R_DEFINE_ERROR_RANGE(IntegrityVerificationStorageCorrupted, 4601, 4639);
R_DEFINE_ERROR_RESULT(IncorrectIntegrityVerificationMagic, 4602);
R_DEFINE_ERROR_RESULT(InvalidZeroHash, 4603);
R_DEFINE_ERROR_RESULT(NonRealDataVerificationFailed, 4604);
R_DEFINE_ERROR_RESULT(InvalidHierarchicalIntegrityVerificationLayerCount, 4605);
R_DEFINE_ERROR_RANGE(RealDataVerificationFailed, 4611, 4619);
R_DEFINE_ERROR_RESULT(ClearedRealDataVerificationFailed, 4612);
R_DEFINE_ERROR_RESULT(UnclearedRealDataVerificationFailed, 4613);
R_DEFINE_ERROR_RANGE(PartitionFileSystemCorrupted, 4641, 4659);
R_DEFINE_ERROR_RESULT(InvalidSha256PartitionHashTarget, 4642);
R_DEFINE_ERROR_RESULT(Sha256PartitionHashVerificationFailed, 4643);
R_DEFINE_ERROR_RESULT(PartitionSignatureVerificationFailed, 4644);
R_DEFINE_ERROR_RESULT(Sha256PartitionSignatureVerificationFailed, 4645);
R_DEFINE_ERROR_RESULT(InvalidPartitionEntryOffset, 4646);
R_DEFINE_ERROR_RESULT(InvalidSha256PartitionMetaDataSize, 4647);
R_DEFINE_ERROR_RANGE(BuiltInStorageCorrupted, 4661, 4679);
R_DEFINE_ERROR_RESULT(GptHeaderVerificationFailed, 4662);
R_DEFINE_ERROR_RANGE(FatFileSystemCorrupted, 4681, 4699);
R_DEFINE_ERROR_RESULT(ExFatUnavailable, 4685);
R_DEFINE_ERROR_RANGE(HostFileSystemCorrupted, 4701, 4719);
R_DEFINE_ERROR_RESULT(HostEntryCorrupted, 4702);
R_DEFINE_ERROR_RESULT(HostFileDataCorrupted, 4703);
R_DEFINE_ERROR_RESULT(HostFileCorrupted, 4704);
R_DEFINE_ERROR_RESULT(InvalidHostHandle, 4705);
R_DEFINE_ERROR_RANGE(DatabaseCorrupted, 4721, 4739);
R_DEFINE_ERROR_RESULT(InvalidAllocationTableBlock, 4722);
R_DEFINE_ERROR_RESULT(InvalidKeyValueListElementIndex, 4723);
R_DEFINE_ERROR_RANGE(AesXtsFileSystemCorrupted, 4741, 4759);
R_DEFINE_ERROR_RANGE(SaveDataTransferDataCorrupted, 4761, 4769);
R_DEFINE_ERROR_RANGE(SignedSystemPartitionDataCorrupted, 4771, 4779);
R_DEFINE_ERROR_RESULT(GameCardLogoDataCorrupted, 4781);
R_DEFINE_ERROR_RANGE(Unexpected, 5000, 5999);
R_DEFINE_ERROR_RESULT(UnexpectedInLocalFileSystemA, 5305);
R_DEFINE_ERROR_RESULT(UnexpectedInLocalFileSystemB, 5306);
R_DEFINE_ERROR_RESULT(UnexpectedInLocalFileSystemC, 5307);
R_DEFINE_ERROR_RESULT(UnexpectedInLocalFileSystemD, 5308);
R_DEFINE_ERROR_RESULT(UnexpectedInLocalFileSystemE, 5309);
R_DEFINE_ERROR_RESULT(UnexpectedInLocalFileSystemF, 5310);
R_DEFINE_ERROR_RESULT(UnexpectedInPathOnExecutionDirectoryA, 5312);
R_DEFINE_ERROR_RESULT(UnexpectedInPathOnExecutionDirectoryB, 5313);
R_DEFINE_ERROR_RESULT(UnexpectedInPathOnExecutionDirectoryC, 5314);
R_DEFINE_ERROR_RESULT(UnexpectedInAesCtrStorageA, 5315);
R_DEFINE_ERROR_RESULT(UnexpectedInAesXtsStorageA, 5316);
R_DEFINE_ERROR_RESULT(UnexpectedInFindFileSystemA, 5319);
R_DEFINE_ERROR_RESULT(UnexpectedInCompressedStorageA, 5324);
R_DEFINE_ERROR_RESULT(UnexpectedInCompressedStorageB, 5325);
R_DEFINE_ERROR_RESULT(UnexpectedInCompressedStorageC, 5326);
R_DEFINE_ERROR_RESULT(UnexpectedInCompressedStorageD, 5327);
R_DEFINE_ERROR_RESULT(UnexpectedInPathA, 5328);
R_DEFINE_ERROR_RANGE(PreconditionViolation, 6000, 6499);
R_DEFINE_ERROR_RANGE(InvalidArgument, 6001, 6199);
R_DEFINE_ERROR_RANGE(InvalidPath, 6002, 6029);
R_DEFINE_ERROR_RESULT(TooLongPath, 6003);
R_DEFINE_ERROR_RESULT(InvalidCharacter, 6004);
R_DEFINE_ERROR_RESULT(InvalidPathFormat, 6005);
R_DEFINE_ERROR_RESULT(DirectoryUnobtainable, 6006);
R_DEFINE_ERROR_RESULT(NotNormalized, 6007);
R_DEFINE_ERROR_RANGE(InvalidPathForOperation, 6030, 6059);
R_DEFINE_ERROR_RESULT(DirectoryNotDeletable, 6031);
R_DEFINE_ERROR_RESULT(DirectoryNotRenamable, 6032);
R_DEFINE_ERROR_RESULT(IncompatiblePath, 6033);
R_DEFINE_ERROR_RESULT(RenameToOtherFileSystem, 6034);
R_DEFINE_ERROR_RESULT(InvalidOffset, 6061);
R_DEFINE_ERROR_RESULT(InvalidSize, 6062);
R_DEFINE_ERROR_RESULT(NullptrArgument, 6063);
R_DEFINE_ERROR_RESULT(InvalidAlignment, 6064);
R_DEFINE_ERROR_RESULT(InvalidMountName, 6065);
R_DEFINE_ERROR_RESULT(ExtensionSizeTooLarge, 6066);
R_DEFINE_ERROR_RESULT(ExtensionSizeInvalid, 6067);
R_DEFINE_ERROR_RESULT(InvalidOpenMode, 6072);
R_DEFINE_ERROR_RESULT(TooLargeSize, 6073);
R_DEFINE_ERROR_RANGE(InvalidEnumValue, 6080, 6099);
R_DEFINE_ERROR_RESULT(InvalidSaveDataState, 6081);
R_DEFINE_ERROR_RESULT(InvalidSaveDataSpaceId, 6082);
R_DEFINE_ERROR_RANGE(InvalidOperationForOpenMode, 6200, 6299);
R_DEFINE_ERROR_RESULT(FileExtensionWithoutOpenModeAllowAppend, 6201);
R_DEFINE_ERROR_RESULT(ReadNotPermitted, 6202);
R_DEFINE_ERROR_RESULT(WriteNotPermitted, 6203);
R_DEFINE_ERROR_RANGE(UnsupportedOperation, 6300, 6399);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForNotResizableSubStorage, 6302);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForResizableSubStorage, 6303);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForMemoryStorage, 6304);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForMemoryStorage, 6305);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForFileStorage, 6306);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForFileHandleStorage, 6307);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForSwitchStorage, 6308);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForStorageServiceObjectAdapter, 6309);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForAesCtrCounterExtendedStorage, 6310);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForAesCtrCounterExtendedStorage, 6311);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForAesCtrCounterExtendedStorage, 6312);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForAesCtrStorageExternal, 6313);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForAesCtrStorageExternal, 6314);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForAesCtrStorage, 6315);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForHierarchicalIntegrityVerificationStorage, 6316);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForHierarchicalIntegrityVerificationStorage, 6317);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForIntegrityVerificationStorage, 6318);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForWritableIntegrityVerificationStorage, 6319);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForIntegrityVerificationStorage, 6320);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForBlockCacheBufferedStorage, 6321);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForWritableBlockCacheBufferedStorage, 6322);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForBlockCacheBufferedStorage, 6323);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForIndirectStorage, 6324);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForIndirectStorage, 6325);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForIndirectStorage, 6326);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForZeroStorage, 6327);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForZeroStorage, 6328);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForHierarchicalSha256Storage, 6329);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForReadOnlyBlockCacheStorage, 6330);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForReadOnlyBlockCacheStorage, 6331);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForIntegrityRomFsStorage, 6332);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForDuplexStorage, 6333);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForDuplexStorage, 6334);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForHierarchicalDuplexStorage, 6335);
R_DEFINE_ERROR_RESULT(UnsupportedGetSizeForRemapStorage, 6336);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForRemapStorage, 6337);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForRemapStorage, 6338);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForIntegritySaveDataStorage, 6339);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForIntegritySaveDataStorage, 6340);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForJournalIntegritySaveDataStorage, 6341);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForJournalIntegritySaveDataStorage, 6342);
R_DEFINE_ERROR_RESULT(UnsupportedGetSizeForJournalStorage, 6343);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForJournalStorage, 6344);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForJournalStorage, 6345);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForUnionStorage, 6346);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForAllocationTableStorage, 6347);
R_DEFINE_ERROR_RESULT(UnsupportedReadForWriteOnlyGameCardStorage, 6348);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForWriteOnlyGameCardStorage, 6349);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForReadOnlyGameCardStorage, 6350);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForReadOnlyGameCardStorage, 6351);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForReadOnlyGameCardStorage, 6352);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForSdmmcStorage, 6353);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForSdmmcStorage, 6354);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForFatFile, 6355);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForStorageFile, 6356);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForInternalStorageConcatenationFile, 6357);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForInternalStorageConcatenationFile, 6358);
R_DEFINE_ERROR_RESULT(UnsupportedQueryEntryForConcatenationFileSystem, 6359);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForConcatenationFile, 6360);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForZeroBitmapFile, 6361);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForFileServiceObjectAdapter, 6362);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForAesXtsFile, 6363);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForRomFsFileSystem, 6364);
R_DEFINE_ERROR_RESULT(UnsupportedCommitProvisionallyForRomFsFileSystem, 6365);
R_DEFINE_ERROR_RESULT(UnsupportedGetTotalSpaceSizeForRomFsFileSystem, 6366);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForRomFsFile, 6367);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForRomFsFile, 6368);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForReadOnlyFileSystem, 6369);
R_DEFINE_ERROR_RESULT(UnsupportedCommitProvisionallyForReadOnlyFileSystem, 6370);
R_DEFINE_ERROR_RESULT(UnsupportedGetTotalSpaceSizeForReadOnlyFileSystem, 6371);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForReadOnlyFile, 6372);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForReadOnlyFile, 6373);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForPartitionFileSystem, 6374);
R_DEFINE_ERROR_RESULT(UnsupportedCommitProvisionallyForPartitionFileSystem, 6375);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForPartitionFile, 6376);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForPartitionFile, 6377);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForTmFileSystemFile, 6378);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForSaveDataInternalStorageFileSystem, 6379);
R_DEFINE_ERROR_RESULT(UnsupportedCommitProvisionallyForApplicationTemporaryFileSystem, 6382);
R_DEFINE_ERROR_RESULT(UnsupportedCommitProvisionallyForSaveDataFileSystem, 6383);
R_DEFINE_ERROR_RESULT(UnsupportedCommitProvisionallyForDirectorySaveDataFileSystem, 6384);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForZeroBitmapHashStorageFile, 6385);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForZeroBitmapHashStorageFile, 6386);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForCompressedStorage, 6387);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForCompressedStorage, 6388);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForRegionSwitchStorage, 6397);
R_DEFINE_ERROR_RANGE(PermissionDenied, 6400, 6449);
R_DEFINE_ERROR_RESULT(PermissionDeniedForCreateHostFileSystem, 6403);
R_DEFINE_ERROR_RESULT(PortAcceptableCountLimited, 6450);
R_DEFINE_ERROR_RESULT(NcaExternalKeyUnregistered, 6451);
R_DEFINE_ERROR_RESULT(NcaExternalKeyInconsistent, 6452);
R_DEFINE_ERROR_RESULT(NeedFlush, 6454);
R_DEFINE_ERROR_RESULT(FileNotClosed, 6455);
R_DEFINE_ERROR_RESULT(DirectoryNotClosed, 6456);
R_DEFINE_ERROR_RESULT(WriteModeFileNotClosed, 6457);
R_DEFINE_ERROR_RESULT(AllocatorAlreadyRegistered, 6458);
R_DEFINE_ERROR_RESULT(DefaultAllocatorUsed, 6459);
R_DEFINE_ERROR_RESULT(AllocatorAlignmentViolation, 6461);
R_DEFINE_ERROR_RESULT(UserNotExist, 6465);
R_DEFINE_ERROR_RANGE(NotFound, 6600, 6699);
R_DEFINE_ERROR_RESULT(ProgramInfoNotFound, 6605);
R_DEFINE_ERROR_RANGE(OutOfResource, 6700, 6799);
R_DEFINE_ERROR_RESULT(BufferAllocationFailed, 6705);
R_DEFINE_ERROR_RESULT(MappingTableFull, 6706);
R_DEFINE_ERROR_RESULT(OpenCountLimit, 6709);
R_DEFINE_ERROR_RANGE(MappingFailed, 6800, 6899);
R_DEFINE_ERROR_RESULT(MapFull, 6811);
R_DEFINE_ERROR_RANGE(BadState, 6900, 6999);
R_DEFINE_ERROR_RESULT(NotInitialized, 6902);
R_DEFINE_ERROR_RESULT(NotMounted, 6905);
R_DEFINE_ERROR_RANGE(DbmNotFound, 7901, 7904);
R_DEFINE_ERROR_RESULT(DbmKeyNotFound, 7902);
R_DEFINE_ERROR_RESULT(DbmFileNotFound, 7903);
R_DEFINE_ERROR_RESULT(DbmDirectoryNotFound, 7904);
R_DEFINE_ERROR_RESULT(DbmAlreadyExists, 7906);
R_DEFINE_ERROR_RESULT(DbmKeyFull, 7907);
R_DEFINE_ERROR_RESULT(DbmDirectoryEntryFull, 7908);
R_DEFINE_ERROR_RESULT(DbmFileEntryFull, 7909);
R_DEFINE_ERROR_RANGE(DbmFindFinished, 7910, 7912);
R_DEFINE_ERROR_RESULT(DbmFindKeyFinished, 7911);
R_DEFINE_ERROR_RESULT(DbmIterationFinished, 7912);
R_DEFINE_ERROR_RESULT(DbmInvalidOperation, 7914);
R_DEFINE_ERROR_RESULT(DbmInvalidPathFormat, 7915);
R_DEFINE_ERROR_RESULT(DbmDirectoryNameTooLong, 7916);
R_DEFINE_ERROR_RESULT(DbmFileNameTooLong, 7917);
}

View File

@@ -1,31 +0,0 @@
/*
* Copyright (c) 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/results/results_common.hpp>
R_DEFINE_NAMESPACE_RESULT_MODULE(ams::gpio, 102);
namespace ams::gpio {
R_DEFINE_ERROR_RESULT(AlreadyBound, 1);
R_DEFINE_ERROR_RESULT(AlreadyOpen, 2);
R_DEFINE_ERROR_RESULT(DeviceNotFound, 3);
R_DEFINE_ERROR_RESULT(InvalidArgument, 4);
R_DEFINE_ERROR_RESULT(NotOpen, 6);
}

View File

@@ -1,42 +0,0 @@
/*
* Copyright (c) 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/results/results_common.hpp>
R_DEFINE_NAMESPACE_RESULT_MODULE(ams::sf::hipc, 11);
namespace ams::sf::hipc {
R_DEFINE_ABSTRACT_ERROR_RANGE(OutOfResource, 100, 299);
R_DEFINE_ERROR_RESULT(OutOfSessionMemory, 102);
R_DEFINE_ERROR_RANGE (OutOfSessions, 131, 139);
R_DEFINE_ERROR_RESULT(PointerBufferTooSmall, 141);
R_DEFINE_ERROR_RESULT(OutOfDomains, 200);
R_DEFINE_ABSTRACT_ERROR_RANGE(CommunicationError, 300, 349);
R_DEFINE_ERROR_RESULT(SessionClosed, 301);
R_DEFINE_ERROR_RESULT(InvalidRequestSize, 402);
R_DEFINE_ERROR_RESULT(UnknownCommandType, 403);
R_DEFINE_ERROR_RESULT(InvalidCmifRequest, 420);
R_DEFINE_ERROR_RESULT(TargetNotDomain, 491);
R_DEFINE_ERROR_RESULT(DomainObjectNotFound, 492);
}

View File

@@ -1,42 +0,0 @@
/*
* Copyright (c) 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/results/results_common.hpp>
R_DEFINE_NAMESPACE_RESULT_MODULE(ams::htc, 18);
namespace ams::htc {
R_DEFINE_ERROR_RESULT(ConnectionFailure, 1);
R_DEFINE_ERROR_RESULT(NotFound, 2);
R_DEFINE_ERROR_RESULT(NotEnoughBuffer, 3);
R_DEFINE_ERROR_RESULT(Cancelled, 101);
R_DEFINE_ERROR_RESULT(Unknown, 1023);
R_DEFINE_ERROR_RESULT(Unknown2001, 2001);
R_DEFINE_ERROR_RESULT(InvalidTaskId, 2003);
R_DEFINE_ERROR_RESULT(InvalidSize, 2011);
R_DEFINE_ERROR_RESULT(TaskCancelled, 2021);
R_DEFINE_ERROR_RESULT(TaskNotCompleted, 2022);
R_DEFINE_ERROR_RESULT(TaskQueueNotAvailable, 2033);
R_DEFINE_ERROR_RESULT(Unknown2101, 2101);
R_DEFINE_ERROR_RESULT(OutOfRpcTask, 2102);
R_DEFINE_ERROR_RESULT(InvalidCategory, 2123);
}

View File

@@ -1,45 +0,0 @@
/*
* Copyright (c) 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/results/results_common.hpp>
R_DEFINE_NAMESPACE_RESULT_MODULE(ams::htcfs, 31);
namespace ams::htcfs {
R_DEFINE_ERROR_RESULT(InvalidArgument, 3);
R_DEFINE_ERROR_RANGE(ConnectionFailure, 100, 199);
R_DEFINE_ERROR_RESULT(HtclowChannelClosed, 101);
R_DEFINE_ERROR_RANGE(UnexpectedResponse, 110, 119);
R_DEFINE_ERROR_RESULT(UnexpectedResponseProtocolId, 111);
R_DEFINE_ERROR_RESULT(UnexpectedResponseProtocolVersion, 112);
R_DEFINE_ERROR_RESULT(UnexpectedResponsePacketCategory, 113);
R_DEFINE_ERROR_RESULT(UnexpectedResponsePacketType, 114);
R_DEFINE_ERROR_RESULT(UnexpectedResponseBodySize, 115);
R_DEFINE_ERROR_RESULT(UnexpectedResponseBody, 116);
R_DEFINE_ERROR_RANGE(InternalError, 200, 299);
R_DEFINE_ERROR_RESULT(InvalidSize, 201);
R_DEFINE_ERROR_RESULT(UnknownError, 211);
R_DEFINE_ERROR_RESULT(UnsupportedProtocolVersion, 212);
R_DEFINE_ERROR_RESULT(InvalidRequest, 213);
R_DEFINE_ERROR_RESULT(InvalidHandle, 214);
R_DEFINE_ERROR_RESULT(OutOfHandle, 215);
}

View File

@@ -1,77 +0,0 @@
/*
* Copyright (c) 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/results/results_common.hpp>
R_DEFINE_NAMESPACE_RESULT_MODULE(ams::htclow, 29);
namespace ams::htclow {
R_DEFINE_ERROR_RESULT(ConnectionFailure, 1);
R_DEFINE_ERROR_RESULT(UnknownDriverType, 3);
R_DEFINE_ERROR_RESULT(NonBlockingReceiveFailed, 5);
R_DEFINE_ERROR_RESULT(ChannelWaitCancelled, 8);
R_DEFINE_ERROR_RESULT(ChannelAlreadyExist, 9);
R_DEFINE_ERROR_RESULT(ChannelNotExist, 10);
R_DEFINE_ERROR_RESULT(OutOfChannel, 151);
R_DEFINE_ERROR_RESULT(OutOfTask, 152);
R_DEFINE_ERROR_RESULT(InvalidChannelState, 200);
R_DEFINE_ERROR_RESULT(InvalidChannelStateDisconnected, 201);
R_DEFINE_ERROR_RANGE(InternalError, 1000, 2999);
R_DEFINE_ERROR_RESULT(Overflow, 1001);
R_DEFINE_ERROR_RESULT(OutOfMemory, 1002);
R_DEFINE_ERROR_RESULT(InvalidArgument, 1003);
R_DEFINE_ERROR_RESULT(ProtocolError, 1004);
R_DEFINE_ERROR_RESULT(Cancelled, 1005);
R_DEFINE_ERROR_RANGE(MuxError, 1100, 1199);
R_DEFINE_ERROR_RESULT(ChannelBufferOverflow, 1101);
R_DEFINE_ERROR_RESULT(ChannelBufferHasNotEnoughData, 1102);
R_DEFINE_ERROR_RESULT(ChannelVersionNotMatched, 1103);
R_DEFINE_ERROR_RESULT(ChannelStateTransitionError, 1104);
R_DEFINE_ERROR_RESULT(ChannelReceiveBufferEmpty, 1106);
R_DEFINE_ERROR_RESULT(ChannelSequenceIdNotMatched, 1107);
R_DEFINE_ERROR_RESULT(ChannelCannotDiscard, 1108);
R_DEFINE_ERROR_RANGE(DriverError, 1200, 1999);
R_DEFINE_ERROR_RESULT(DriverOpened, 1201);
R_DEFINE_ERROR_RANGE(SocketDriverError, 1300, 1399);
R_DEFINE_ERROR_RESULT(SocketSocketExemptError, 1301);
R_DEFINE_ERROR_RESULT(SocketBindError, 1302);
R_DEFINE_ERROR_RESULT(SocketListenError, 1304);
R_DEFINE_ERROR_RESULT(SocketAcceptError, 1305);
R_DEFINE_ERROR_RESULT(SocketReceiveError, 1306);
R_DEFINE_ERROR_RESULT(SocketSendError, 1307);
R_DEFINE_ERROR_RESULT(SocketReceiveFromError, 1308);
R_DEFINE_ERROR_RESULT(SocketSendToError, 1309);
R_DEFINE_ERROR_RESULT(SocketSetSockOptError, 1310);
R_DEFINE_ERROR_RESULT(SocketGetSockNameError, 1311);
R_DEFINE_ERROR_RANGE(UsbDriverError, 1400, 1499);
R_DEFINE_ERROR_RESULT(UsbDriverUnknownError, 1401);
R_DEFINE_ERROR_RESULT(UsbDriverBusyError, 1402);
R_DEFINE_ERROR_RESULT(UsbDriverReceiveError, 1403);
R_DEFINE_ERROR_RESULT(UsbDriverSendError, 1404);
R_DEFINE_ERROR_RESULT(HtcctrlError, 2000); /* TODO: Range? */
R_DEFINE_ERROR_RESULT(HtcctrlStateTransitionNotAllowed, 2001);
R_DEFINE_ERROR_RESULT(HtcctrlReceiveUnexpectedPacket, 2002);
}

View File

@@ -1,32 +0,0 @@
/*
* Copyright (c) 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/results/results_common.hpp>
R_DEFINE_NAMESPACE_RESULT_MODULE(ams::htcs, 4);
namespace ams::htcs {
R_DEFINE_ERROR_RESULT(InvalidHandle, 9);
R_DEFINE_ERROR_RESULT(InvalidArgument, 2001);
R_DEFINE_ERROR_RESULT(InvalidServerHandle, 2003);
R_DEFINE_ERROR_RESULT(InvalidSize, 2014);
R_DEFINE_ERROR_RESULT(Cancelled, 2021);
R_DEFINE_ERROR_RESULT(Completed, 2023);
R_DEFINE_ERROR_RESULT(InvalidTask, 2103);
}

Some files were not shown because too many files have changed in this diff Show More