key_manager: Add support for KEK and SD seed derivation
This commit is contained in:
parent
cde665c565
commit
f26fc64cb4
2 changed files with 135 additions and 5 deletions
|
@ -23,9 +23,8 @@ static_assert(sizeof(Key128) == 16, "Key128 must be 128 bytes big.");
|
|||
static_assert(sizeof(Key256) == 32, "Key128 must be 128 bytes big.");
|
||||
|
||||
enum class S256KeyType : u64 {
|
||||
Header, //
|
||||
SDSave, //
|
||||
SDNCA, //
|
||||
Header, //
|
||||
SDKeySource, // f1=SDKeyType
|
||||
};
|
||||
|
||||
enum class S128KeyType : u64 {
|
||||
|
@ -37,6 +36,7 @@ enum class S128KeyType : u64 {
|
|||
KeyArea, // f1=crypto revision f2=type {app, ocean, system}
|
||||
SDSeed, //
|
||||
Titlekey, // f1=rights id LSB f2=rights id MSB
|
||||
Source, // f1=source type, f2= sub id
|
||||
};
|
||||
|
||||
enum class KeyAreaKeyType : u8 {
|
||||
|
@ -45,6 +45,17 @@ enum class KeyAreaKeyType : u8 {
|
|||
System,
|
||||
};
|
||||
|
||||
enum class SourceKeyType : u8 {
|
||||
SDKEK,
|
||||
AESKEKGeneration,
|
||||
AESKeyGeneration,
|
||||
};
|
||||
|
||||
enum class SDKeyType : u8 {
|
||||
Save,
|
||||
NCA,
|
||||
};
|
||||
|
||||
template <typename KeyType>
|
||||
struct KeyIndex {
|
||||
KeyType type;
|
||||
|
@ -83,6 +94,10 @@ public:
|
|||
|
||||
static bool KeyFileExists(bool title);
|
||||
|
||||
// Call before using the sd seed to attempt to derive it if it dosen't exist. Needs system save
|
||||
// 8*43 and the private file to exist.
|
||||
void DeriveSDSeedLazy();
|
||||
|
||||
private:
|
||||
boost::container::flat_map<KeyIndex<S128KeyType>, Key128> s128_keys;
|
||||
boost::container::flat_map<KeyIndex<S256KeyType>, Key256> s256_keys;
|
||||
|
@ -95,4 +110,9 @@ private:
|
|||
static const boost::container::flat_map<std::string, KeyIndex<S128KeyType>> s128_file_id;
|
||||
static const boost::container::flat_map<std::string, KeyIndex<S256KeyType>> s256_file_id;
|
||||
};
|
||||
|
||||
Key128 GenerateKeyEncryptionKey(Key128 source, Key128 master, Key128 kek_seed, Key128 key_seed);
|
||||
boost::optional<Key128> DeriveSDSeed();
|
||||
Loader::ResultStatus DeriveSDKeys(std::array<Key256, 2>& sd_keys, const KeyManager& keys);
|
||||
|
||||
} // namespace Core::Crypto
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue