diff options
| author | 2018-08-16 17:12:05 -0400 | |
|---|---|---|
| committer | 2018-08-23 11:53:30 -0400 | |
| commit | f26fc64cb4f36fbc9be05ed153f32d8f4dd3850c (patch) | |
| tree | dec1bd2e10699aba68cbc4341ef94cc014019b9c /src/core/crypto/key_manager.h | |
| parent | key_manager: Switch to boost flat_map for keys (diff) | |
| download | yuzu-f26fc64cb4f36fbc9be05ed153f32d8f4dd3850c.tar.gz yuzu-f26fc64cb4f36fbc9be05ed153f32d8f4dd3850c.tar.xz yuzu-f26fc64cb4f36fbc9be05ed153f32d8f4dd3850c.zip | |
key_manager: Add support for KEK and SD seed derivation
Diffstat (limited to 'src/core/crypto/key_manager.h')
| -rw-r--r-- | src/core/crypto/key_manager.h | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/core/crypto/key_manager.h b/src/core/crypto/key_manager.h index 33b1ad383..31040dc55 100644 --- a/src/core/crypto/key_manager.h +++ b/src/core/crypto/key_manager.h | |||
| @@ -23,9 +23,8 @@ static_assert(sizeof(Key128) == 16, "Key128 must be 128 bytes big."); | |||
| 23 | static_assert(sizeof(Key256) == 32, "Key128 must be 128 bytes big."); | 23 | static_assert(sizeof(Key256) == 32, "Key128 must be 128 bytes big."); |
| 24 | 24 | ||
| 25 | enum class S256KeyType : u64 { | 25 | enum class S256KeyType : u64 { |
| 26 | Header, // | 26 | Header, // |
| 27 | SDSave, // | 27 | SDKeySource, // f1=SDKeyType |
| 28 | SDNCA, // | ||
| 29 | }; | 28 | }; |
| 30 | 29 | ||
| 31 | enum class S128KeyType : u64 { | 30 | enum class S128KeyType : u64 { |
| @@ -37,6 +36,7 @@ enum class S128KeyType : u64 { | |||
| 37 | KeyArea, // f1=crypto revision f2=type {app, ocean, system} | 36 | KeyArea, // f1=crypto revision f2=type {app, ocean, system} |
| 38 | SDSeed, // | 37 | SDSeed, // |
| 39 | Titlekey, // f1=rights id LSB f2=rights id MSB | 38 | Titlekey, // f1=rights id LSB f2=rights id MSB |
| 39 | Source, // f1=source type, f2= sub id | ||
| 40 | }; | 40 | }; |
| 41 | 41 | ||
| 42 | enum class KeyAreaKeyType : u8 { | 42 | enum class KeyAreaKeyType : u8 { |
| @@ -45,6 +45,17 @@ enum class KeyAreaKeyType : u8 { | |||
| 45 | System, | 45 | System, |
| 46 | }; | 46 | }; |
| 47 | 47 | ||
| 48 | enum class SourceKeyType : u8 { | ||
| 49 | SDKEK, | ||
| 50 | AESKEKGeneration, | ||
| 51 | AESKeyGeneration, | ||
| 52 | }; | ||
| 53 | |||
| 54 | enum class SDKeyType : u8 { | ||
| 55 | Save, | ||
| 56 | NCA, | ||
| 57 | }; | ||
| 58 | |||
| 48 | template <typename KeyType> | 59 | template <typename KeyType> |
| 49 | struct KeyIndex { | 60 | struct KeyIndex { |
| 50 | KeyType type; | 61 | KeyType type; |
| @@ -83,6 +94,10 @@ public: | |||
| 83 | 94 | ||
| 84 | static bool KeyFileExists(bool title); | 95 | static bool KeyFileExists(bool title); |
| 85 | 96 | ||
| 97 | // Call before using the sd seed to attempt to derive it if it dosen't exist. Needs system save | ||
| 98 | // 8*43 and the private file to exist. | ||
| 99 | void DeriveSDSeedLazy(); | ||
| 100 | |||
| 86 | private: | 101 | private: |
| 87 | boost::container::flat_map<KeyIndex<S128KeyType>, Key128> s128_keys; | 102 | boost::container::flat_map<KeyIndex<S128KeyType>, Key128> s128_keys; |
| 88 | boost::container::flat_map<KeyIndex<S256KeyType>, Key256> s256_keys; | 103 | boost::container::flat_map<KeyIndex<S256KeyType>, Key256> s256_keys; |
| @@ -95,4 +110,9 @@ private: | |||
| 95 | static const boost::container::flat_map<std::string, KeyIndex<S128KeyType>> s128_file_id; | 110 | static const boost::container::flat_map<std::string, KeyIndex<S128KeyType>> s128_file_id; |
| 96 | static const boost::container::flat_map<std::string, KeyIndex<S256KeyType>> s256_file_id; | 111 | static const boost::container::flat_map<std::string, KeyIndex<S256KeyType>> s256_file_id; |
| 97 | }; | 112 | }; |
| 113 | |||
| 114 | Key128 GenerateKeyEncryptionKey(Key128 source, Key128 master, Key128 kek_seed, Key128 key_seed); | ||
| 115 | boost::optional<Key128> DeriveSDSeed(); | ||
| 116 | Loader::ResultStatus DeriveSDKeys(std::array<Key256, 2>& sd_keys, const KeyManager& keys); | ||
| 117 | |||
| 98 | } // namespace Core::Crypto | 118 | } // namespace Core::Crypto |