diff --git a/libstratosphere/include/stratosphere/fssystem/fssystem_crypto_configuration.hpp b/libstratosphere/include/stratosphere/fssystem/fssystem_crypto_configuration.hpp index 4ca3316e..90f2ccdb 100644 --- a/libstratosphere/include/stratosphere/fssystem/fssystem_crypto_configuration.hpp +++ b/libstratosphere/include/stratosphere/fssystem/fssystem_crypto_configuration.hpp @@ -16,6 +16,7 @@ #pragma once #include #include +#include namespace ams::fssystem { @@ -25,10 +26,13 @@ namespace ams::fssystem { void InvalidateHardwareAesKey(); - const u8 *GetAcidSignatureKeyModulus(bool prod, size_t key_generation); + bool IsValidSignatureKeyGeneration(ldr::PlatformId platform, size_t key_generation); + + const u8 *GetAcidSignatureKeyModulus(ldr::PlatformId platform, bool prod, size_t key_generation, bool unk_unused); + size_t GetAcidSignatureKeyModulusSize(ldr::PlatformId platform, bool unk_unused); + const u8 *GetAcidSignatureKeyPublicExponent(); - constexpr inline size_t AcidSignatureKeyModulusSize = NcaCryptoConfiguration::Rsa2048KeyModulusSize; constexpr inline size_t AcidSignatureKeyPublicExponentSize = NcaCryptoConfiguration::Rsa2048KeyPublicExponentSize; } diff --git a/libstratosphere/include/stratosphere/ldr/ldr_platform_id.hpp b/libstratosphere/include/stratosphere/ldr/ldr_platform_id.hpp new file mode 100644 index 00000000..884cd094 --- /dev/null +++ b/libstratosphere/include/stratosphere/ldr/ldr_platform_id.hpp @@ -0,0 +1,27 @@ +/* + * 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 . + */ + +#pragma once +#include + +namespace ams::ldr { + + /* TODO: Is this really a FS type? What namespace does this actually live inside? */ + enum PlatformId { + PlatformId_Nx = 0, + }; + +} diff --git a/libstratosphere/include/stratosphere/ldr/ldr_types.hpp b/libstratosphere/include/stratosphere/ldr/ldr_types.hpp index 328957aa..325d2a35 100644 --- a/libstratosphere/include/stratosphere/ldr/ldr_types.hpp +++ b/libstratosphere/include/stratosphere/ldr/ldr_types.hpp @@ -19,6 +19,7 @@ #include #include #include +#include namespace ams::ldr { @@ -224,6 +225,7 @@ namespace ams::ldr { MetaFlag_OptimizeMemoryAllocation = (1 << 4), MetaFlag_DisableDeviceAddressSpaceMerge = (1 << 5), + MetaFlag_EnableAliasRegionExtraSize = (1 << 6), }; enum AddressSpaceType { diff --git a/libstratosphere/source/fssystem/fssystem_crypto_configuration.cpp b/libstratosphere/source/fssystem/fssystem_crypto_configuration.cpp index 4575a0df..dbd2f86c 100644 --- a/libstratosphere/source/fssystem/fssystem_crypto_configuration.cpp +++ b/libstratosphere/source/fssystem/fssystem_crypto_configuration.cpp @@ -22,9 +22,11 @@ namespace ams::fssystem { constexpr inline const size_t KeySize = crypto::AesDecryptor128::KeySize; - constexpr inline const size_t AcidSignatureKeyGenerationMax = 1; + constexpr inline const size_t NxAcidSignatureKeyGenerationMax = 1; - constexpr inline const u8 AcidSignatureKeyModulusDev[AcidSignatureKeyGenerationMax + 1][AcidSignatureKeyModulusSize] = { + constexpr inline const size_t NxAcidSignatureKeyModulusSize = NcaCryptoConfiguration::Rsa2048KeyModulusSize; + + constexpr inline const u8 NxAcidSignatureKeyModulusDev[NxAcidSignatureKeyGenerationMax + 1][NxAcidSignatureKeyModulusSize] = { { 0xD6, 0x34, 0xA5, 0x78, 0x6C, 0x68, 0xCE, 0x5A, 0xC2, 0x37, 0x17, 0xF3, 0x82, 0x45, 0xC6, 0x89, 0xE1, 0x2D, 0x06, 0x67, 0xBF, 0xB4, 0x06, 0x19, 0x55, 0x6B, 0x27, 0x66, 0x0C, 0xA4, 0xB5, 0x87, @@ -63,7 +65,7 @@ namespace ams::fssystem { } }; - constexpr inline const u8 AcidSignatureKeyModulusProd[AcidSignatureKeyGenerationMax + 1][AcidSignatureKeyModulusSize] = { + constexpr inline const u8 NxAcidSignatureKeyModulusProd[NxAcidSignatureKeyGenerationMax + 1][NxAcidSignatureKeyModulusSize] = { { 0xDD, 0xC8, 0xDD, 0xF2, 0x4E, 0x6D, 0xF0, 0xCA, 0x9E, 0xC7, 0x5D, 0xC7, 0x7B, 0xAD, 0xFE, 0x7D, 0x23, 0x89, 0x69, 0xB6, 0xF2, 0x06, 0xA2, 0x02, 0x88, 0xE1, 0x55, 0x91, 0xAB, 0xCB, 0x4D, 0x50, @@ -102,7 +104,7 @@ namespace ams::fssystem { } }; - static_assert(sizeof(AcidSignatureKeyModulusProd) == sizeof(AcidSignatureKeyModulusDev)); + static_assert(sizeof(NxAcidSignatureKeyModulusProd) == sizeof(NxAcidSignatureKeyModulusDev)); constexpr inline const u8 AcidSignatureKeyPublicExponent[] = { 0x01, 0x00, 0x01 @@ -295,10 +297,36 @@ namespace ams::fssystem { } } - const u8 *GetAcidSignatureKeyModulus(bool prod, size_t key_generation) { - AMS_ASSERT(key_generation <= AcidSignatureKeyGenerationMax); - const size_t used_keygen = (key_generation % (AcidSignatureKeyGenerationMax + 1)); - return prod ? AcidSignatureKeyModulusProd[used_keygen] : AcidSignatureKeyModulusDev[used_keygen]; + bool IsValidSignatureKeyGeneration(ldr::PlatformId platform, size_t key_generation) { + switch (platform) { + case ldr::PlatformId_Nx: + return key_generation <= NxAcidSignatureKeyGenerationMax; + AMS_UNREACHABLE_DEFAULT_CASE(); + } + } + + const u8 *GetAcidSignatureKeyModulus(ldr::PlatformId platform, bool prod, size_t key_generation, bool unk_unused) { + AMS_ASSERT(IsValidSignatureKeyGeneration(platform, key_generation)); + AMS_UNUSED(unk_unused); + + switch (platform) { + case ldr::PlatformId_Nx: + { + const size_t used_keygen = (key_generation % (NxAcidSignatureKeyGenerationMax + 1)); + return prod ? NxAcidSignatureKeyModulusProd[used_keygen] : NxAcidSignatureKeyModulusDev[used_keygen]; + } + AMS_UNREACHABLE_DEFAULT_CASE(); + } + } + + size_t GetAcidSignatureKeyModulusSize(ldr::PlatformId platform, bool unk_unused) { + AMS_UNUSED(unk_unused); + + switch (platform) { + case ldr::PlatformId_Nx: + return NxAcidSignatureKeyModulusSize; + AMS_UNREACHABLE_DEFAULT_CASE(); + } } const u8 *GetAcidSignatureKeyPublicExponent() { diff --git a/libvapours/include/vapours/results/loader_results.hpp b/libvapours/include/vapours/results/loader_results.hpp index 825be378..d9cfa62b 100644 --- a/libvapours/include/vapours/results/loader_results.hpp +++ b/libvapours/include/vapours/results/loader_results.hpp @@ -34,6 +34,8 @@ namespace ams::ldr { R_DEFINE_ERROR_RESULT(InvalidAcidSignature, 11); R_DEFINE_ERROR_RESULT(InvalidNcaSignature, 12); + R_DEFINE_ERROR_RESULT(InvalidPlatformId, 14); + R_DEFINE_ERROR_RESULT(OutOfAddressSpace, 51); R_DEFINE_ERROR_RESULT(InvalidNroImage, 52); R_DEFINE_ERROR_RESULT(InvalidNrrImage, 53);