diff --git a/libexosphere/include/exosphere/secmon.hpp b/libexosphere/include/exosphere/secmon.hpp index 1b476e0f..4b638386 100644 --- a/libexosphere/include/exosphere/secmon.hpp +++ b/libexosphere/include/exosphere/secmon.hpp @@ -15,6 +15,7 @@ */ #pragma once #include +#include #include #include #include \ No newline at end of file diff --git a/libexosphere/include/exosphere/secmon/secmon_volatile_context.hpp b/libexosphere/include/exosphere/secmon/secmon_volatile_context.hpp index d3940278..1695d2e2 100644 --- a/libexosphere/include/exosphere/secmon/secmon_volatile_context.hpp +++ b/libexosphere/include/exosphere/secmon/secmon_volatile_context.hpp @@ -15,6 +15,7 @@ */ #pragma once #include +#include #include namespace ams::secmon { @@ -30,10 +31,18 @@ namespace ams::secmon { u8 package2_dev_rsa_modulus[0x100]; u8 package2_prod_rsa_modulus[0x100]; u8 package2_aes_key[0x10]; - u8 padding[0xCF0]; + u8 master_key_source[0x10]; + u8 device_master_key_source_kek_source[0x10]; + u8 mariko_dev_master_kek_source[0x10]; + u8 mariko_prod_master_kek_source[0x10]; + u8 dev_master_key_vectors[pkg1::OldMasterKeyCount + 1][0x10]; + u8 prod_master_key_vectors[pkg1::OldMasterKeyCount + 1][0x10]; + u8 device_master_key_source_sources[pkg1::OldDeviceMasterKeyCount][0x10]; + u8 dev_device_master_kek_sources[pkg1::OldDeviceMasterKeyCount][0x10]; + u8 prod_device_master_kek_sources[pkg1::OldDeviceMasterKeyCount][0x10]; }; static_assert(util::is_pod::value); - static_assert(sizeof(VolatileKeys) == 0x1000); + static_assert(sizeof(VolatileKeys) <= 0x1000); /* Nintendo uses the bottom 0x740 of this as a stack for warmboot setup, and another 0x740 for the core 0/1/2 SMC stacks. */ /* This is...wasteful. The warmboot stack is not deep. We will thus save 1K+ of nonvolatile storage by keeping the random cache in here. */ @@ -86,6 +95,33 @@ namespace ams::secmon { return GetVolatileKeys().package2_aes_key; } + ALWAYS_INLINE const u8 *GetMasterKeySource() { + return GetVolatileKeys().master_key_source; + } + + ALWAYS_INLINE const u8 *GetDeviceMasterKeySourceKekSource() { + return GetVolatileKeys().device_master_key_source_kek_source; + } + + ALWAYS_INLINE const u8 *GetMarikoMasterKekSource(bool is_prod) { + auto &keys = GetVolatileKeys(); + return is_prod ? keys.mariko_prod_master_kek_source : keys.mariko_dev_master_kek_source; + } + + ALWAYS_INLINE const u8 *GetMasterKeyVector(bool is_prod, size_t i) { + auto &keys = GetVolatileKeys(); + return is_prod ? keys.prod_master_key_vectors[i] : keys.dev_master_key_vectors[i]; + } + + ALWAYS_INLINE const u8 *GetDeviceMasterKeySourceSource(size_t i) { + return GetVolatileKeys().device_master_key_source_sources[i]; + } + + ALWAYS_INLINE const u8 *GetDeviceMasterKekSource(bool is_prod, size_t i) { + auto &keys = GetVolatileKeys(); + return is_prod ? keys.prod_device_master_kek_sources[i] : keys.dev_device_master_kek_sources[i]; + } + ALWAYS_INLINE pkg2::Package2Meta &GetEphemeralPackage2Meta() { return GetVolatileData().pkg2_meta; }