exo: free space by moving keys to volatile iram, support logging under debug config

This commit is contained in:
Michael Scire 2020-11-15 02:47:44 -08:00
parent 2ef41f0027
commit a203ac3f80
8 changed files with 158 additions and 92 deletions

View file

@ -15,6 +15,7 @@
*/
#pragma once
#include <vapours.hpp>
#include <exosphere/secmon/secmon_log.hpp>
#include <exosphere/secmon/secmon_memory_layout.hpp>
#include <exosphere/secmon/secmon_configuration_context.hpp>
#include <exosphere/secmon/secmon_volatile_context.hpp>

View file

@ -15,6 +15,7 @@
*/
#pragma once
#include <vapours.hpp>
#include <exosphere/pkg1.hpp>
#include <exosphere/pkg2.hpp>
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<VolatileKeys>::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;
}