diff options
| author | 2018-09-23 21:04:13 -0400 | |
|---|---|---|
| committer | 2018-10-07 13:15:11 -0400 | |
| commit | d041d6231c97ea0c8af788da251ae019ee560e6a (patch) | |
| tree | 1d779bb315a626d7c4e5805c466313a9f1e18980 /src/core/crypto/key_manager.h | |
| parent | key_manager: Add base key derivation (diff) | |
| download | yuzu-d041d6231c97ea0c8af788da251ae019ee560e6a.tar.gz yuzu-d041d6231c97ea0c8af788da251ae019ee560e6a.tar.xz yuzu-d041d6231c97ea0c8af788da251ae019ee560e6a.zip | |
key_manager: Add ETicket key derivation
Derives titlekeys
Diffstat (limited to 'src/core/crypto/key_manager.h')
| -rw-r--r-- | src/core/crypto/key_manager.h | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/core/crypto/key_manager.h b/src/core/crypto/key_manager.h index 8de65ec4e..58afcdcac 100644 --- a/src/core/crypto/key_manager.h +++ b/src/core/crypto/key_manager.h | |||
| @@ -5,11 +5,18 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <map> | ||
| 8 | #include <string> | 9 | #include <string> |
| 9 | #include <boost/container/flat_map.hpp> | 10 | #include <boost/container/flat_map.hpp> |
| 10 | #include <boost/optional.hpp> | 11 | #include <boost/optional.hpp> |
| 11 | #include <fmt/format.h> | 12 | #include <fmt/format.h> |
| 12 | #include "common/common_types.h" | 13 | #include "common/common_types.h" |
| 14 | #include "core/file_sys/vfs_types.h" | ||
| 15 | #include "partition_data_manager.h" | ||
| 16 | |||
| 17 | namespace FileUtil { | ||
| 18 | class IOFile; | ||
| 19 | } | ||
| 13 | 20 | ||
| 14 | namespace Loader { | 21 | namespace Loader { |
| 15 | enum class ResultStatus : u16; | 22 | enum class ResultStatus : u16; |
| @@ -22,9 +29,18 @@ constexpr u64 TICKET_FILE_TITLEKEY_OFFSET = 0x180; | |||
| 22 | using Key128 = std::array<u8, 0x10>; | 29 | using Key128 = std::array<u8, 0x10>; |
| 23 | using Key256 = std::array<u8, 0x20>; | 30 | using Key256 = std::array<u8, 0x20>; |
| 24 | using SHA256Hash = std::array<u8, 0x20>; | 31 | using SHA256Hash = std::array<u8, 0x20>; |
| 32 | using TicketRaw = std::array<u8, 0x400>; | ||
| 25 | 33 | ||
| 26 | static_assert(sizeof(Key128) == 16, "Key128 must be 128 bytes big."); | 34 | static_assert(sizeof(Key128) == 16, "Key128 must be 128 bytes big."); |
| 27 | static_assert(sizeof(Key256) == 32, "Key128 must be 128 bytes big."); | 35 | static_assert(sizeof(Key256) == 32, "Key256 must be 256 bytes big."); |
| 36 | |||
| 37 | template <size_t bit_size, size_t byte_size = (bit_size >> 3)> | ||
| 38 | struct RSAKeyPair { | ||
| 39 | std::array<u8, byte_size> encryption_key; | ||
| 40 | std::array<u8, byte_size> decryption_key; | ||
| 41 | std::array<u8, byte_size> modulus; | ||
| 42 | std::array<u8, 4> exponent; | ||
| 43 | }; | ||
| 28 | 44 | ||
| 29 | enum class KeyCategory : u8 { | 45 | enum class KeyCategory : u8 { |
| 30 | Standard, | 46 | Standard, |
| @@ -140,6 +156,8 @@ public: | |||
| 140 | 156 | ||
| 141 | bool BaseDeriveNecessary(); | 157 | bool BaseDeriveNecessary(); |
| 142 | void DeriveBase(); | 158 | void DeriveBase(); |
| 159 | void DeriveETicket(PartitionDataManager data); | ||
| 160 | |||
| 143 | private: | 161 | private: |
| 144 | std::map<KeyIndex<S128KeyType>, Key128> s128_keys; | 162 | std::map<KeyIndex<S128KeyType>, Key128> s128_keys; |
| 145 | std::map<KeyIndex<S256KeyType>, Key256> s256_keys; | 163 | std::map<KeyIndex<S256KeyType>, Key256> s256_keys; |
| @@ -166,6 +184,13 @@ Key128 GenerateKeyEncryptionKey(Key128 source, Key128 master, Key128 kek_seed, K | |||
| 166 | Key128 DeriveKeyblobKey(Key128 sbk, Key128 tsec, Key128 source); | 184 | Key128 DeriveKeyblobKey(Key128 sbk, Key128 tsec, Key128 source); |
| 167 | 185 | ||
| 168 | boost::optional<Key128> DeriveSDSeed(); | 186 | boost::optional<Key128> DeriveSDSeed(); |
| 169 | Loader::ResultStatus DeriveSDKeys(std::array<Key256, 2>& sd_keys, const KeyManager& keys); | 187 | Loader::ResultStatus DeriveSDKeys(std::array<Key256, 2>& sd_keys, KeyManager& keys); |
| 188 | |||
| 189 | std::vector<TicketRaw> GetTicketblob(const FileUtil::IOFile& ticket_save); | ||
| 190 | |||
| 191 | // Returns a pair of {rights_id, titlekey}. Fails if the ticket has no certificate authority (offset | ||
| 192 | // 0x140-0x144 is zero) | ||
| 193 | boost::optional<std::pair<Key128, Key128>> ParseTicket( | ||
| 194 | const TicketRaw& ticket, const RSAKeyPair<2048>& eticket_extended_key); | ||
| 170 | 195 | ||
| 171 | } // namespace Core::Crypto | 196 | } // namespace Core::Crypto |